]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp
Implemented parser registry.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_users.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #include "parser_users.h"
23
24 #include "stg/users.h"
25 #include "stg/tariffs.h"
26 #include "stg/user_property.h"
27 #include "stg/user_conf.h"
28 #include "stg/user_stat.h"
29 #include "stg/common.h"
30
31 #include <cstdio>
32 #include <cassert>
33
34 using STG::PARSER::GET_USERS;
35 using STG::PARSER::GET_USER;
36 using STG::PARSER::ADD_USER;
37 using STG::PARSER::DEL_USER;
38 using STG::PARSER::CHG_USER;
39 using STG::PARSER::CHECK_USER;
40
41 const char * GET_USERS::tag  = "GetUsers";
42 const char * GET_USER::tag   = "GetUser";
43 const char * ADD_USER::tag   = "AddUser";
44 const char * CHG_USER::tag   = "SetUser";
45 const char * DEL_USER::tag   = "DelUser";
46 const char * CHECK_USER::tag = "CheckUser";
47
48 namespace
49 {
50
51 std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_t lastTime = 0)
52 {
53     std::string answer;
54
55     if (loginInStart)
56         answer += "<User result=\"ok\">";
57     else
58         answer += "<User result=\"ok\" login=\"" + user.GetLogin() + "\">";
59
60     answer += "<Login value=\"" + user.GetLogin() + "\"/>";
61
62     if (user.GetProperty().password.ModificationTime() > lastTime)
63     {
64         if (showPass)
65             answer += "<Password value=\"" + user.GetProperty().password.Get() + "\" />";
66         else
67             answer += "<Password value=\"++++++\"/>";
68     }
69
70     if (user.GetProperty().cash.ModificationTime() > lastTime)
71         answer += "<Cash value=\"" + x2str(user.GetProperty().cash.Get()) + "\"/>";
72     if (user.GetProperty().freeMb.ModificationTime() > lastTime)
73         answer += "<FreeMb value=\"" + x2str(user.GetProperty().freeMb.Get()) + "\"/>";
74     if (user.GetProperty().credit.ModificationTime() > lastTime)
75         answer += "<Credit value=\"" + x2str(user.GetProperty().credit.Get()) + "\"/>";
76
77     if (user.GetProperty().nextTariff.Get() != "")
78     {
79         if (user.GetProperty().tariffName.ModificationTime() > lastTime ||
80             user.GetProperty().nextTariff.ModificationTime() > lastTime)
81             answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "/" + user.GetProperty().nextTariff.Get() + "\"/>";
82     }
83     else
84     {
85         if (user.GetProperty().tariffName.ModificationTime() > lastTime)
86             answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "\"/>";
87     }
88
89     if (user.GetProperty().note.ModificationTime() > lastTime)
90         answer += "<Note value=\"" + Encode12str(user.GetProperty().note) + "\"/>";
91     if (user.GetProperty().phone.ModificationTime() > lastTime)
92         answer += "<Phone value=\"" + Encode12str(user.GetProperty().phone) + "\"/>";
93     if (user.GetProperty().address.ModificationTime() > lastTime)
94         answer += "<Address value=\"" + Encode12str(user.GetProperty().address) + "\"/>";
95     if (user.GetProperty().email.ModificationTime() > lastTime)
96         answer += "<Email value=\"" + Encode12str(user.GetProperty().email) + "\"/>";
97
98     std::vector<const USER_PROPERTY_LOGGED<std::string> *> userdata;
99     userdata.push_back(user.GetProperty().userdata0.GetPointer());
100     userdata.push_back(user.GetProperty().userdata1.GetPointer());
101     userdata.push_back(user.GetProperty().userdata2.GetPointer());
102     userdata.push_back(user.GetProperty().userdata3.GetPointer());
103     userdata.push_back(user.GetProperty().userdata4.GetPointer());
104     userdata.push_back(user.GetProperty().userdata5.GetPointer());
105     userdata.push_back(user.GetProperty().userdata6.GetPointer());
106     userdata.push_back(user.GetProperty().userdata7.GetPointer());
107     userdata.push_back(user.GetProperty().userdata8.GetPointer());
108     userdata.push_back(user.GetProperty().userdata9.GetPointer());
109
110     for (size_t i = 0; i < userdata.size(); i++)
111         if (userdata[i]->ModificationTime() > lastTime)
112             answer += "<UserData" + x2str(i) + " value=\"" + Encode12str(userdata[i]->Get()) + "\" />";
113
114     if (user.GetProperty().realName.ModificationTime() > lastTime)
115         answer += "<Name value=\"" + Encode12str(user.GetProperty().realName) + "\"/>";
116     if (user.GetProperty().group.ModificationTime() > lastTime)
117         answer += "<Group value=\"" + Encode12str(user.GetProperty().group) + "\"/>";
118     if (user.GetConnectedModificationTime() > lastTime)
119         answer += std::string("<Status value=\"") + (user.GetConnected() ? "1" : "0") + "\"/>";
120     if (user.GetProperty().alwaysOnline.ModificationTime() > lastTime)
121         answer += std::string("<AOnline value=\"") + (user.GetProperty().alwaysOnline.Get() ? "1" : "0") + "\"/>";
122     if (user.GetCurrIPModificationTime() > lastTime)
123         answer += "<CurrIP value=\"" + inet_ntostring(user.GetCurrIP()) + "\"/>";
124     if (user.GetPingTime() > lastTime)
125         answer += "<PingTime value=\"" + x2str(user.GetPingTime()) + "\"/>";
126     if (user.GetProperty().ips.ModificationTime() > lastTime)
127         answer += "<IP value=\"" + user.GetProperty().ips.Get().GetIpStr() + "\"/>";
128
129     answer += "<Traff";
130     const DIR_TRAFF & upload(user.GetProperty().down.Get());
131     const DIR_TRAFF & download(user.GetProperty().up.Get());
132     if (user.GetProperty().up.ModificationTime() > lastTime)
133         for (size_t j = 0; j < DIR_NUM; j++)
134             answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\"";
135     if (user.GetProperty().down.ModificationTime() > lastTime)
136         for (size_t j = 0; j < DIR_NUM; j++)
137             answer += " MD" + x2str(j) + "=\"" + x2str(download[j]) + "\"";
138     if (user.GetSessionUploadModificationTime() > lastTime)
139         for (size_t j = 0; j < DIR_NUM; j++)
140             answer += " SU" + x2str(j) + "=\"" + x2str(user.GetSessionUpload()[j]) + "\"";
141     if (user.GetSessionDownloadModificationTime() > lastTime)
142         for (size_t j = 0; j < DIR_NUM; j++)
143             answer += " SD" + x2str(j) + "=\"" + x2str(user.GetSessionDownload()[j]) + "\"";
144     answer += "/>";
145
146     if (user.GetProperty().disabled.ModificationTime() > lastTime)
147         answer += std::string("<Down value=\"") + (user.GetProperty().disabled.Get() ? "1" : "0") + "\"/>";
148     if (user.GetProperty().disabledDetailStat.ModificationTime() > lastTime)
149         answer += std::string("<DisableDetailStat value=\"") + (user.GetProperty().disabledDetailStat.Get() ? "1" : "0") + "\"/>";
150     if (user.GetProperty().passive.ModificationTime() > lastTime)
151         answer += std::string("<Passive value=\"") + (user.GetProperty().passive.Get() ? "1" : "0") + "\"/>";
152     if (user.GetProperty().lastCashAdd.ModificationTime() > lastTime)
153         answer += "<LastCash value=\"" + x2str(user.GetProperty().lastCashAdd.Get()) + "\"/>";
154     if (user.GetProperty().lastCashAddTime.ModificationTime() > lastTime)
155         answer += "<LastTimeCash value=\"" + x2str(user.GetProperty().lastCashAddTime.Get()) + "\"/>";
156     if (user.GetProperty().lastActivityTime.ModificationTime() > lastTime)
157         answer += "<LastActivityTime value=\"" + x2str(user.GetProperty().lastActivityTime.Get()) + "\"/>";
158     if (user.GetProperty().creditExpire.ModificationTime() > lastTime)
159         answer += "<CreditExpire value=\"" + x2str(user.GetProperty().creditExpire.Get()) + "\"/>";
160
161     if (lastTime == 0)
162     {
163         answer += "<AuthorizedBy>";
164         std::vector<std::string> list(user.GetAuthorizers());
165         for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
166             answer += "<Auth name=\"" + *it + "\"/>";
167         answer += "</AuthorizedBy>";
168     }
169
170     answer += "</User>";
171
172     return answer;
173 }
174
175 } // namespace anonymous
176
177 int GET_USERS::Start(void *, const char * el, const char ** attr)
178 {
179     if (strcasecmp(el, m_tag.c_str()) != 0)
180         return -1;
181
182     while (attr && *attr && *(attr + 1))
183     {
184         if (strcasecmp(*attr, "LastUpdate") == 0)
185             str2x(*(attr + 1), m_lastUserUpdateTime);
186         ++attr;
187     }
188
189     return 0;
190 }
191
192 void GET_USERS::CreateAnswer()
193 {
194     int h = m_users.OpenSearch();
195     assert(h);
196
197     if (m_lastUserUpdateTime > 0)
198         m_answer = "<" + m_tag + " LastUpdate=\"" + x2str(time(NULL)) + "\">";
199     else
200         m_answer = GetOpenTag();
201
202     USER_PTR u;
203
204     while (m_users.SearchNext(h, &u) == 0)
205         m_answer += UserToXML(*u, true, m_currAdmin.GetPriv()->userConf || m_currAdmin.GetPriv()->userPasswd, m_lastUserUpdateTime);
206
207     m_users.CloseSearch(h);
208
209     m_answer += GetCloseTag();
210 }
211
212 int GET_USER::Start(void *, const char * el, const char ** attr)
213 {
214     if (strcasecmp(el, m_tag.c_str()) != 0)
215         return -1;
216
217     if (attr[1] == NULL)
218         return -1;
219
220     m_login = attr[1];
221     return 0;
222 }
223
224 void GET_USER::CreateAnswer()
225 {
226     CONST_USER_PTR u;
227
228     if (m_users.FindByName(m_login, &u))
229         m_answer = "<" + m_tag + " result=\"error\" reason=\"User not found.\"/>";
230     else
231         m_answer = UserToXML(*u, false, m_currAdmin.GetPriv()->userConf || m_currAdmin.GetPriv()->userPasswd);
232 }
233
234 int ADD_USER::Start(void *, const char * el, const char ** attr)
235 {
236     m_depth++;
237
238     if (m_depth == 1)
239     {
240         if (strcasecmp(el, m_tag.c_str()) == 0)
241             return 0;
242     }
243     else
244     {
245         if (strcasecmp(el, "login") == 0)
246         {
247             m_login = attr[1];
248             return 0;
249         }
250     }
251     return -1;
252 }
253
254 void ADD_USER::CreateAnswer()
255 {
256     if (m_users.Exists(m_login))
257         m_answer = "<" + m_tag + " result=\"error\" reason=\"User '" + m_login + "' exists.\"/>";
258     else if (m_users.Add(m_login, &m_currAdmin) == 0)
259         m_answer = "<" + m_tag + " result=\"ok\"/>";
260     else
261         m_answer = "<" + m_tag + " result=\"error\" reason=\"Access denied\"/>";
262 }
263
264 int CHG_USER::Start(void *, const char * el, const char ** attr)
265 {
266     m_depth++;
267
268     if (m_depth == 1)
269     {
270         if (strcasecmp(el, m_tag.c_str()) == 0)
271             return 0;
272     }
273     else
274     {
275         if (strcasecmp(el, "login") == 0)
276         {
277             m_login = attr[1];
278             return 0;
279         }
280
281         if (strcasecmp(el, "ip") == 0)
282         {
283             m_ucr.ips = StrToIPS(attr[1]);
284             return 0;
285         }
286
287         if (strcasecmp(el, "password") == 0)
288         {
289             m_ucr.password = attr[1];
290             return 0;
291         }
292
293         if (strcasecmp(el, "address") == 0)
294         {
295             m_ucr.address = Decode21str(attr[1]);
296             return 0;
297         }
298
299         if (strcasecmp(el, "aonline") == 0)
300         {
301             m_ucr.alwaysOnline = (*(attr[1]) != '0');
302             return 0;
303         }
304
305         if (strcasecmp(el, "cash") == 0)
306         {
307             if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
308                 m_cashMsg = Decode21str(attr[3]);
309
310             double cash = 0;
311             if (strtodouble2(attr[1], cash) == 0)
312                 m_usr.cash = cash;
313
314             m_cashMustBeAdded = (strcasecmp(attr[0], "add") == 0);
315
316             return 0;
317         }
318
319         if (strcasecmp(el, "CreditExpire") == 0)
320         {
321             long int creditExpire = 0;
322             if (str2x(attr[1], creditExpire) == 0)
323                 m_ucr.creditExpire = (time_t)creditExpire;
324
325             return 0;
326         }
327
328         if (strcasecmp(el, "credit") == 0)
329         {
330             double credit = 0;
331             if (strtodouble2(attr[1], credit) == 0)
332                 m_ucr.credit = credit;
333             return 0;
334         }
335
336         if (strcasecmp(el, "freemb") == 0)
337         {
338             double freeMb = 0;
339             if (strtodouble2(attr[1], freeMb) == 0)
340                 m_usr.freeMb = freeMb;
341             return 0;
342         }
343
344         if (strcasecmp(el, "down") == 0)
345         {
346             int down = 0;
347             if (str2x(attr[1], down) == 0)
348                 m_ucr.disabled = down;
349             return 0;
350         }
351
352         if (strcasecmp(el, "DisableDetailStat") == 0)
353         {
354             int disabledDetailStat = 0;
355             if (str2x(attr[1], disabledDetailStat) == 0)
356                 m_ucr.disabledDetailStat = disabledDetailStat;
357             return 0;
358         }
359
360         if (strcasecmp(el, "email") == 0)
361         {
362             m_ucr.email = Decode21str(attr[1]);
363             return 0;
364         }
365
366         for (int i = 0; i < USERDATA_NUM; i++)
367         {
368             char name[15];
369             sprintf(name, "userdata%d", i);
370             if (strcasecmp(el, name) == 0)
371             {
372                 m_ucr.userdata[i] = Decode21str(attr[1]);
373                 return 0;
374             }
375         }
376
377         if (strcasecmp(el, "group") == 0)
378         {
379             m_ucr.group = Decode21str(attr[1]);
380             return 0;
381         }
382
383         if (strcasecmp(el, "note") == 0)
384         {
385             m_ucr.note = Decode21str(attr[1]);
386             return 0;
387         }
388
389         if (strcasecmp(el, "passive") == 0)
390         {
391             int passive = 0;
392             if (str2x(attr[1], passive) == 0)
393                 m_ucr.passive = passive;
394             return 0;
395         }
396
397         if (strcasecmp(el, "phone") == 0)
398         {
399             m_ucr.phone = Decode21str(attr[1]);
400             return 0;
401         }
402
403         if (strcasecmp(el, "Name") == 0)
404         {
405             m_ucr.realName = Decode21str(attr[1]);
406             return 0;
407         }
408
409         if (strcasecmp(el, "traff") == 0)
410         {
411             int j = 0;
412             while (attr[j])
413             {
414                 int dir = attr[j][2] - '0';
415
416                 if (strncasecmp(attr[j], "md", 2) == 0)
417                 {
418                     uint64_t t = 0;
419                     str2x(attr[j + 1], t);
420                     m_downr[dir] = t;
421                 }
422                 if (strncasecmp(attr[j], "mu", 2) == 0)
423                 {
424                     uint64_t t = 0;
425                     str2x(attr[j + 1], t);
426                     m_upr[dir] = t;
427                 }
428                 j += 2;
429             }
430             return 0;
431         }
432
433         if (strcasecmp(el, "tariff") == 0)
434         {
435             if (strcasecmp(attr[0], "now") == 0)
436                 m_ucr.tariffName = attr[1];
437
438             if (strcasecmp(attr[0], "delayed") == 0)
439                 m_ucr.nextTariff = attr[1];
440
441             return 0;
442         }
443     }
444     return -1;
445 }
446
447 void CHG_USER::CreateAnswer()
448 {
449     if (ApplyChanges() == 0)
450         m_answer = "<" + m_tag + " result=\"ok\"/>";
451     else
452         m_answer = "<" + m_tag + " result=\"error\"/>";
453 }
454
455 int CHG_USER::ApplyChanges()
456 {
457     printfd(__FILE__, "PARSER_CHG_USER::ApplyChanges()\n");
458     USER_PTR u;
459
460     if (m_users.FindByName(m_login, &u))
461         return -1;
462
463     bool check = false;
464     bool alwaysOnline = u->GetProperty().alwaysOnline;
465     if (!m_ucr.alwaysOnline.empty())
466     {
467         check = true;
468         alwaysOnline = m_ucr.alwaysOnline.const_data();
469     }
470     bool onlyOneIP = u->GetProperty().ips.ConstData().OnlyOneIP();
471     if (!m_ucr.ips.empty())
472     {
473         check = true;
474         onlyOneIP = m_ucr.ips.const_data().OnlyOneIP();
475     }
476
477     if (check && alwaysOnline && !onlyOneIP)
478     {
479         printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
480         GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", m_currAdmin.GetLogStr().c_str());
481         return -1;
482     }
483
484     for (size_t i = 0; i < m_ucr.ips.const_data().Count(); ++i)
485     {
486         CONST_USER_PTR user;
487         uint32_t ip = m_ucr.ips.const_data().operator[](i).ip;
488         if (m_users.IsIPInUse(ip, m_login, &user))
489         {
490             printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), m_login.c_str(), user->GetLogin().c_str());
491             GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", m_currAdmin.GetLogStr().c_str(), inet_ntostring(ip).c_str(), m_login.c_str(), user->GetLogin().c_str());
492             return -1;
493         }
494     }
495
496     if (!m_ucr.ips.empty())
497         if (!u->GetProperty().ips.Set(m_ucr.ips.const_data(), &m_currAdmin, m_login, &m_store))
498             return -1;
499
500     if (!m_ucr.alwaysOnline.empty())
501         if (!u->GetProperty().alwaysOnline.Set(m_ucr.alwaysOnline.const_data(),
502                                                &m_currAdmin, m_login, &m_store))
503             return -1;
504
505     if (!m_ucr.address.empty())
506         if (!u->GetProperty().address.Set(m_ucr.address.const_data(), &m_currAdmin, m_login, &m_store))
507             return -1;
508
509     if (!m_ucr.creditExpire.empty())
510         if (!u->GetProperty().creditExpire.Set(m_ucr.creditExpire.const_data(),
511                                                &m_currAdmin, m_login, &m_store))
512             return -1;
513
514     if (!m_ucr.credit.empty())
515         if (!u->GetProperty().credit.Set(m_ucr.credit.const_data(), &m_currAdmin, m_login, &m_store))
516             return -1;
517
518     if (!m_usr.freeMb.empty())
519         if (!u->GetProperty().freeMb.Set(m_usr.freeMb.const_data(), &m_currAdmin, m_login, &m_store))
520             return -1;
521
522     if (!m_ucr.disabled.empty())
523         if (!u->GetProperty().disabled.Set(m_ucr.disabled.const_data(), &m_currAdmin, m_login, &m_store))
524             return -1;
525
526     if (!m_ucr.disabledDetailStat.empty())
527         if (!u->GetProperty().disabledDetailStat.Set(m_ucr.disabledDetailStat.const_data(), &m_currAdmin, m_login, &m_store))
528             return -1;
529
530     if (!m_ucr.email.empty())
531         if (!u->GetProperty().email.Set(m_ucr.email.const_data(), &m_currAdmin, m_login, &m_store))
532             return -1;
533
534     if (!m_ucr.group.empty())
535         if (!u->GetProperty().group.Set(m_ucr.group.const_data(), &m_currAdmin, m_login, &m_store))
536             return -1;
537
538     if (!m_ucr.note.empty())
539         if (!u->GetProperty().note.Set(m_ucr.note.const_data(), &m_currAdmin, m_login, &m_store))
540             return -1;
541
542     std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
543     userdata.push_back(u->GetProperty().userdata0.GetPointer());
544     userdata.push_back(u->GetProperty().userdata1.GetPointer());
545     userdata.push_back(u->GetProperty().userdata2.GetPointer());
546     userdata.push_back(u->GetProperty().userdata3.GetPointer());
547     userdata.push_back(u->GetProperty().userdata4.GetPointer());
548     userdata.push_back(u->GetProperty().userdata5.GetPointer());
549     userdata.push_back(u->GetProperty().userdata6.GetPointer());
550     userdata.push_back(u->GetProperty().userdata7.GetPointer());
551     userdata.push_back(u->GetProperty().userdata8.GetPointer());
552     userdata.push_back(u->GetProperty().userdata9.GetPointer());
553
554     for (int i = 0; i < (int)userdata.size(); i++)
555         if (!m_ucr.userdata[i].empty())
556             if(!userdata[i]->Set(m_ucr.userdata[i].const_data(), &m_currAdmin, m_login, &m_store))
557                 return -1;
558
559     if (!m_ucr.passive.empty())
560         if (!u->GetProperty().passive.Set(m_ucr.passive.const_data(), &m_currAdmin, m_login, &m_store))
561             return -1;
562
563     if (!m_ucr.password.empty())
564         if (!u->GetProperty().password.Set(m_ucr.password.const_data(), &m_currAdmin, m_login, &m_store))
565             return -1;
566
567     if (!m_ucr.phone.empty())
568         if (!u->GetProperty().phone.Set(m_ucr.phone.const_data(), &m_currAdmin, m_login, &m_store))
569             return -1;
570
571     if (!m_ucr.realName.empty())
572         if (!u->GetProperty().realName.Set(m_ucr.realName.const_data(), &m_currAdmin, m_login, &m_store))
573             return -1;
574
575
576     if (!m_usr.cash.empty())
577         if (m_cashMustBeAdded)
578         {
579             if (!u->GetProperty().cash.Set(m_usr.cash.const_data() + u->GetProperty().cash,
580                                            &m_currAdmin,
581                                            m_login,
582                                            &m_store,
583                                            m_cashMsg))
584                 return -1;
585             else
586                 if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &m_currAdmin, m_login, &m_store, m_cashMsg))
587                     return -1;
588         }
589
590
591     if (!m_ucr.tariffName.empty())
592     {
593         if (m_tariffs.FindByName(m_ucr.tariffName.const_data()))
594         {
595             if (!u->GetProperty().tariffName.Set(m_ucr.tariffName.const_data(), &m_currAdmin, m_login, &m_store))
596                 return -1;
597             u->ResetNextTariff();
598         }
599         else
600         {
601             //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
602             return -1;
603         }
604     }
605
606     if (!m_ucr.nextTariff.empty())
607     {
608         if (m_tariffs.FindByName(m_ucr.nextTariff.const_data()))
609         {
610             if (!u->GetProperty().nextTariff.Set(m_ucr.nextTariff.const_data(), &m_currAdmin, m_login, &m_store))
611                 return -1;
612         }
613         else
614         {
615             //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
616             return -1;
617         }
618     }
619
620     DIR_TRAFF up = u->GetProperty().up;
621     DIR_TRAFF down = u->GetProperty().down;
622     int upCount = 0;
623     int downCount = 0;
624     for (int i = 0; i < DIR_NUM; i++)
625     {
626         if (!m_upr[i].empty())
627         {
628             up[i] = m_upr[i].data();
629             upCount++;
630         }
631         if (!m_downr[i].empty())
632         {
633             down[i] = m_downr[i].data();
634             downCount++;
635         }
636     }
637
638     if (upCount)
639         if (!u->GetProperty().up.Set(up, &m_currAdmin, m_login, &m_store))
640             return -1;
641
642     if (downCount)
643         if (!u->GetProperty().down.Set(down, &m_currAdmin, m_login, &m_store))
644             return -1;
645
646     u->WriteConf();
647     u->WriteStat();
648
649     return 0;
650 }
651
652 int DEL_USER::Start(void *, const char *el, const char **attr)
653 {
654     res = 0;
655     if (strcasecmp(el, m_tag.c_str()) == 0)
656     {
657         if (attr[0] == NULL || attr[1] == NULL)
658         {
659             //CreateAnswer("Parameters error!");
660             CreateAnswer();
661             return 0;
662         }
663
664         if (m_users.FindByName(attr[1], &u))
665         {
666             res = 1;
667             CreateAnswer();
668             return 0;
669         }
670         CreateAnswer();
671         return 0;
672     }
673     return -1;
674 }
675
676 int DEL_USER::End(void *, const char *el)
677 {
678     if (strcasecmp(el, m_tag.c_str()) == 0)
679     {
680         if (!res)
681             m_users.Del(u->GetLogin(), &m_currAdmin);
682
683         return 0;
684     }
685     return -1;
686 }
687
688 void DEL_USER::CreateAnswer()
689 {
690     if (res)
691         m_answer = "<" + m_tag + " value=\"error\" reason=\"User not found\"/>";
692     else
693         m_answer = "<" + m_tag + " value=\"ok\"/>";
694 }
695
696 int CHECK_USER::Start(void *, const char *el, const char **attr)
697 {
698     if (strcasecmp(el, m_tag.c_str()) == 0)
699     {
700         if (attr[0] == NULL || attr[1] == NULL ||
701             attr[2] == NULL || attr[3] == NULL)
702         {
703             CreateAnswer("Invalid parameters.");
704             printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
705             return 0;
706         }
707
708         CONST_USER_PTR user;
709         if (m_users.FindByName(attr[1], &user))
710         {
711             CreateAnswer("User not found.");
712             printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
713             return 0;
714         }
715
716         if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
717         {
718             CreateAnswer("Wrong password.");
719             printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
720             return 0;
721         }
722
723         CreateAnswer(NULL);
724         return 0;
725     }
726     return -1;
727 }
728
729 int CHECK_USER::End(void *, const char *el)
730 {
731     if (strcasecmp(el, m_tag.c_str()) == 0)
732         return 0;
733     return -1;
734 }
735
736 void CHECK_USER::CreateAnswer(const char * error)
737 {
738     if (error)
739         m_answer = "<" + m_tag + " value=\"Err\" reason=\"" + error + "\"/>";
740     else
741         m_answer = "<" + m_tag + " value=\"Ok\"/>";
742 }