2 #include <sys/utsname.h>
4 #include <sys/socket.h>
5 #include <netinet/in.h>
12 #include "stg/version.h"
13 #include "stg/tariffs.h"
14 #include "stg/user_property.h"
15 #include "stg/settings.h"
16 #include "stg/logger.h"
19 #define UNAME_LEN (256)
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
23 int PARSER_GET_SERVER_INFO::ParseStart(void *, const char *el, const char **)
25 answerList->erase(answerList->begin(), answerList->end());
26 if (strcasecmp(el, "GetServerInfo") == 0)
32 //-----------------------------------------------------------------------------
33 int PARSER_GET_SERVER_INFO::ParseEnd(void *, const char *el)
35 if (strcasecmp(el, "GetServerInfo") == 0)
42 //-----------------------------------------------------------------------------
43 void PARSER_GET_SERVER_INFO::CreateAnswer()
45 char s[UNAME_LEN + 128];
52 strcat(un, utsn.sysname);
54 strcat(un, utsn.release);
56 strcat(un, utsn.machine);
58 strcat(un, utsn.nodename);
60 //answerList->clear();
61 answerList->erase(answerList->begin(), answerList->end());
62 answerList->push_back("<ServerInfo>");
64 sprintf(s, "<version value=\"%s\"/>", SERVER_VERSION);
65 answerList->push_back(s);
67 sprintf(s, "<tariff_num value=\"%llu\"/>", static_cast<unsigned long long>(tariffs->Count()));
68 answerList->push_back(s);
70 sprintf(s, "<tariff value=\"%d\"/>", 2);
71 answerList->push_back(s);
73 sprintf(s, "<users_num value=\"%llu\"/>", static_cast<unsigned long long>(users->Count()));
74 answerList->push_back(s);
76 sprintf(s, "<uname value=\"%s\"/>", un);
77 answerList->push_back(s);
79 sprintf(s, "<dir_num value=\"%d\"/>", DIR_NUM);
80 answerList->push_back(s);
82 sprintf(s, "<day_fee value=\"%d\"/>", settings->GetDayFee());
83 answerList->push_back(s);
85 for (int i = 0; i< DIR_NUM; i++)
88 Encode12str(dn2e, settings->GetDirName(i));
89 sprintf(s, "<dir_name_%d value=\"%s\"/>", i, dn2e.c_str());
90 answerList->push_back(s);
93 answerList->push_back("</ServerInfo>");
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
98 int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
100 if (strcasecmp(el, "GetUser") == 0)
102 if (attr[0] && attr[1])
107 login.erase(login.begin(), login.end());
114 //-----------------------------------------------------------------------------
115 int PARSER_GET_USER::ParseEnd(void *, const char *el)
117 if (strcasecmp(el, "GetUser") == 0)
124 //-----------------------------------------------------------------------------
125 void PARSER_GET_USER::CreateAnswer()
132 answerList->erase(answerList->begin(), answerList->end());
134 if (users->FindByName(login, &u))
136 s = "<user result=\"error\"/>";
137 answerList->push_back(s);
141 s = "<user result=\"ok\">";
142 answerList->push_back(s);
144 s = "<login value=\"" + u->GetLogin() + "\"/>";
145 answerList->push_back(s);
147 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
148 s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
150 s = "<password value=\"++++++\"/>";
151 answerList->push_back(s);
153 strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
154 answerList->push_back(s);
156 strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
157 answerList->push_back(s);
159 strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
160 answerList->push_back(s);
162 if (u->GetProperty().nextTariff.Get() != "")
164 strprintf(&s, "<tariff value=\"%s/%s\" />",
165 u->GetProperty().tariffName.Get().c_str(),
166 u->GetProperty().nextTariff.Get().c_str());
170 strprintf(&s, "<tariff value=\"%s\" />",
171 u->GetProperty().tariffName.Get().c_str());
174 answerList->push_back(s);
176 Encode12str(enc, u->GetProperty().note);
177 s = "<note value=\"" + enc + "\" />";
178 answerList->push_back(s);
180 Encode12str(enc, u->GetProperty().phone);
181 s = "<phone value=\"" + enc + "\" />";
182 answerList->push_back(s);
184 Encode12str(enc, u->GetProperty().address);
185 s = "<address value=\"" + enc + "\" />";
186 answerList->push_back(s);
188 Encode12str(enc, u->GetProperty().email);
189 s = "<email value=\"" + enc + "\" />";
190 answerList->push_back(s);
193 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
194 userdata.push_back(u->GetProperty().userdata0.GetPointer());
195 userdata.push_back(u->GetProperty().userdata1.GetPointer());
196 userdata.push_back(u->GetProperty().userdata2.GetPointer());
197 userdata.push_back(u->GetProperty().userdata3.GetPointer());
198 userdata.push_back(u->GetProperty().userdata4.GetPointer());
199 userdata.push_back(u->GetProperty().userdata5.GetPointer());
200 userdata.push_back(u->GetProperty().userdata6.GetPointer());
201 userdata.push_back(u->GetProperty().userdata7.GetPointer());
202 userdata.push_back(u->GetProperty().userdata8.GetPointer());
203 userdata.push_back(u->GetProperty().userdata9.GetPointer());
206 for (unsigned i = 0; i < userdata.size(); i++)
208 Encode12str(enc, userdata[i]->Get());
209 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
210 answerList->push_back(s);
213 Encode12str(enc, u->GetProperty().realName);
214 s = "<name value=\"" + enc + "\" />";
215 answerList->push_back(s);
217 Encode12str(enc, u->GetProperty().group);
218 s = "<GROUP value=\"" + enc + "\" />";
219 answerList->push_back(s);
221 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
222 answerList->push_back(s);
224 strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
225 answerList->push_back(s);
227 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
228 answerList->push_back(s);
230 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
231 answerList->push_back(s);
233 std::ostringstream sstr;
234 sstr << u->GetProperty().ips.Get();
235 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
236 answerList->push_back(s);
239 ss = new char[DIR_NUM*25*4 + 50];
241 sprintf(ss, "<traff");
244 download = u->GetProperty().down.Get();
245 upload = u->GetProperty().up.Get();
247 for (int j = 0; j < DIR_NUM; j++)
251 sprintf(st, " MU%d=\"%s\"", j, s.c_str());
254 x2str(download[j], s);
255 sprintf(st, " MD%d=\"%s\"", j, s.c_str());
258 sprintf(st, " SU%d=\"0\"", j);
261 sprintf(st, " SD%d=\"0\"", j);
265 answerList->push_back(ss);
268 strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
269 answerList->push_back(s);
271 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
272 answerList->push_back(s);
274 strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
275 answerList->push_back(s);
277 strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
278 answerList->push_back(s);
280 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
281 answerList->push_back(s);
283 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
284 answerList->push_back(s);
286 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
287 answerList->push_back(s);
289 s = "<AuthorizedBy>";
290 std::vector<std::string> list(u->GetAuthorizers());
291 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
292 s += "<Auth name=\"" + *it + "\">";
293 s += "</AuthorizedBy>";
294 answerList->push_back(s);
296 strprintf(&s, "</user>");
297 answerList->push_back(s);
299 //-----------------------------------------------------------------------------
301 //-----------------------------------------------------------------------------
302 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
304 /*if (attr && *attr && *(attr+1))
306 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
310 printfd(__FILE__, "attr = NULL\n");
313 lastUpdateFound = false;
314 if (strcasecmp(el, "GetUsers") == 0)
316 while (attr && *attr && *(attr+1))
318 if (strcasecmp(*attr, "LastUpdate") == 0)
320 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
322 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
323 lastUpdateFound = true;
327 //printfd(__FILE__, "NO lastUserUpdateTime\n");
337 //-----------------------------------------------------------------------------
338 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
340 if (strcasecmp(el, "GetUsers") == 0)
347 //-----------------------------------------------------------------------------
348 void PARSER_GET_USERS::CreateAnswer()
350 answerList->erase(answerList->begin(), answerList->end());
353 std::string userStart;
354 std::string traffStart;
355 std::string traffMiddle;
356 std::string traffFinish;
358 std::string userFinish;
365 int h = users->OpenSearch();
368 printfd(__FILE__, "users->OpenSearch() error\n");
369 users->CloseSearch(h);
372 std::string updateTime;
373 x2str(time(NULL), updateTime);
376 answerList->push_back("<Users LastUpdate=\"" + updateTime + "\">");
378 answerList->push_back("<Users>");
382 if (users->SearchNext(h, &u))
386 userStart = "<user login=\"" + u->GetLogin() + "\">";
389 if (u->GetProperty().password.ModificationTime() > lastUserUpdateTime)
391 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
392 s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
394 s = "<password value=\"++++++\"/>";
399 if (u->GetProperty().cash.ModificationTime() > lastUserUpdateTime)
401 strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
403 //printfd(__FILE__, "cash value=\"%f\"\n", u->GetProperty().cash.Get());
407 if (u->GetProperty().freeMb.ModificationTime() > lastUserUpdateTime)
409 strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
413 if (u->GetProperty().credit.ModificationTime() > lastUserUpdateTime)
415 strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
419 if (u->GetProperty().nextTariff.Get() != "")
421 if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime
422 || u->GetProperty().nextTariff.ModificationTime() > lastUserUpdateTime)
424 strprintf(&s, "<tariff value=\"%s/%s\" />",
425 u->GetProperty().tariffName.Get().c_str(),
426 u->GetProperty().nextTariff.Get().c_str());
432 if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime)
434 strprintf(&s, "<tariff value=\"%s\" />",
435 u->GetProperty().tariffName.Get().c_str());
440 if (u->GetProperty().note.ModificationTime() > lastUserUpdateTime)
442 Encode12str(enc, u->GetProperty().note);
443 strprintf(&s, "<note value=\"%s\" />", enc.c_str());
447 if (u->GetProperty().phone.ModificationTime() > lastUserUpdateTime)
449 Encode12str(enc, u->GetProperty().phone);
450 strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
454 if (u->GetProperty().address.ModificationTime() > lastUserUpdateTime)
456 Encode12str(enc, u->GetProperty().address);
457 strprintf(&s, "<address value=\"%s\" />", enc.c_str());
461 if (u->GetProperty().email.ModificationTime() > lastUserUpdateTime)
463 Encode12str(enc, u->GetProperty().email);
464 strprintf(&s, "<email value=\"%s\" />", enc.c_str());
468 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
469 userdata.push_back(u->GetProperty().userdata0.GetPointer());
470 userdata.push_back(u->GetProperty().userdata1.GetPointer());
471 userdata.push_back(u->GetProperty().userdata2.GetPointer());
472 userdata.push_back(u->GetProperty().userdata3.GetPointer());
473 userdata.push_back(u->GetProperty().userdata4.GetPointer());
474 userdata.push_back(u->GetProperty().userdata5.GetPointer());
475 userdata.push_back(u->GetProperty().userdata6.GetPointer());
476 userdata.push_back(u->GetProperty().userdata7.GetPointer());
477 userdata.push_back(u->GetProperty().userdata8.GetPointer());
478 userdata.push_back(u->GetProperty().userdata9.GetPointer());
481 for (unsigned i = 0; i < userdata.size(); i++)
483 if (userdata[i]->ModificationTime() > lastUserUpdateTime)
485 Encode12str(enc, userdata[i]->Get());
486 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
491 if (u->GetProperty().realName.ModificationTime() > lastUserUpdateTime)
493 Encode12str(enc, u->GetProperty().realName);
494 strprintf(&s, "<name value=\"%s\" />", enc.c_str());
498 if (u->GetProperty().group.ModificationTime() > lastUserUpdateTime)
500 Encode12str(enc, u->GetProperty().group);
501 strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
505 if (u->GetProperty().alwaysOnline.ModificationTime() > lastUserUpdateTime)
507 strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
511 if (u->GetCurrIPModificationTime() > lastUserUpdateTime)
513 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
518 if (u->GetConnectedModificationTime() > lastUserUpdateTime)
520 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
524 if (u->GetPingTime() > lastUserUpdateTime)
526 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
530 if (u->GetProperty().ips.ModificationTime() > lastUserUpdateTime)
532 std::ostringstream sstr;
533 sstr << u->GetProperty().ips.Get();
534 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
539 traffStart = "<traff";
542 download = u->GetProperty().down.Get();
543 upload = u->GetProperty().up.Get();
546 if (u->GetProperty().up.ModificationTime() > lastUserUpdateTime)
548 for (int j = 0; j < DIR_NUM; j++)
552 sprintf(st, " MU%d=\"%s\" ", j, s.c_str());
557 if (u->GetProperty().down.ModificationTime() > lastUserUpdateTime)
559 for (int j = 0; j < DIR_NUM; j++)
561 x2str(download[j], s);
562 sprintf(st, " MD%d=\"%s\" ", j, s.c_str());
568 if (traffMiddle.length() > 0)
570 middle += traffStart;
571 middle += traffMiddle;
572 middle += traffFinish;
575 if (u->GetProperty().disabled.ModificationTime() > lastUserUpdateTime)
577 strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
581 if (u->GetProperty().disabledDetailStat.ModificationTime() > lastUserUpdateTime)
583 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
587 //printfd(__FILE__, ">>>>> %s\n", s.c_str());
589 if (u->GetProperty().passive.ModificationTime() > lastUserUpdateTime)
591 strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
595 if (u->GetProperty().lastCashAdd.ModificationTime() > lastUserUpdateTime)
597 strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
601 if (u->GetProperty().lastCashAddTime.ModificationTime() > lastUserUpdateTime)
603 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
608 if (u->GetProperty().lastActivityTime.ModificationTime() > lastUserUpdateTime)
610 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
614 if (u->GetProperty().creditExpire.ModificationTime() > lastUserUpdateTime)
616 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
621 userFinish = "</user>";
623 if (middle.length() > 0)
625 /*printfd(__FILE__, "login: %s\n", u->GetLogin().c_str());
626 printfd(__FILE__, "middle: %s\n", middle.c_str());*/
628 answerList->push_back(userStart);
629 answerList->push_back(middle);
630 answerList->push_back(userFinish);
634 users->CloseSearch(h);
636 //answerList->push_back("</Users>");
638 answerList->push_back("</Users>");
640 //-----------------------------------------------------------------------------
642 //-----------------------------------------------------------------------------
643 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
649 if (strcasecmp(el, "AddUser") == 0)
656 if (strcasecmp(el, "login") == 0)
664 //-----------------------------------------------------------------------------
665 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
669 if (strcasecmp(el, "AddUser") == 0)
680 //-----------------------------------------------------------------------------
681 void PARSER_ADD_USER::Reset()
683 BASE_PARSER::Reset();
686 //-----------------------------------------------------------------------------
687 void PARSER_ADD_USER::CreateAnswer()
689 //answerList->clear();
690 answerList->erase(answerList->begin(), answerList->end());
692 if (CheckUserData() == 0)
694 answerList->push_back("<AddUser result=\"ok\"/>");
698 answerList->push_back("<AddUser result=\"error\" reason=\"Access denied\"/>");
701 //-----------------------------------------------------------------------------
702 int PARSER_ADD_USER::CheckUserData()
705 if (users->FindByName(login, &u))
707 return users->Add(login, currAdmin);
711 //-----------------------------------------------------------------------------
713 //-----------------------------------------------------------------------------
714 PARSER_CHG_USER::PARSER_CHG_USER()
722 cashMustBeAdded(false),
727 //-----------------------------------------------------------------------------
728 PARSER_CHG_USER::~PARSER_CHG_USER()
735 //-----------------------------------------------------------------------------
736 void PARSER_CHG_USER::Reset()
747 usr = new USER_STAT_RES;
748 ucr = new USER_CONF_RES;
750 upr = new RESETABLE<uint64_t>[DIR_NUM];
751 downr = new RESETABLE<uint64_t>[DIR_NUM];
753 //-----------------------------------------------------------------------------
754 std::string PARSER_CHG_USER::EncChar2String(const char * strEnc)
757 Decode21str(str, strEnc);
760 //-----------------------------------------------------------------------------
761 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
767 if (strcasecmp(el, "SetUser") == 0)
774 //printfd(__FILE__, "el=%s\n", el);
775 if (strcasecmp(el, "login") == 0)
781 if (strcasecmp(el, "ip") == 0)
785 ucr->ips = StrToIPS(attr[1]);
789 printfd(__FILE__, "StrToIPS Error!\n");
793 if (strcasecmp(el, "password") == 0)
795 ucr->password = attr[1];
799 if (strcasecmp(el, "address") == 0)
801 ucr->address = EncChar2String(attr[1]);
805 if (strcasecmp(el, "aonline") == 0)
807 ucr->alwaysOnline = (*(attr[1]) != '0');
811 if (strcasecmp(el, "cash") == 0)
813 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
815 cashMsg = EncChar2String(attr[3]);
819 if (strtodouble2(attr[1], cash) == 0)
822 if (strcasecmp(attr[0], "set") == 0)
823 cashMustBeAdded = false;
825 if (strcasecmp(attr[0], "add") == 0)
826 cashMustBeAdded = true;
831 if (strcasecmp(el, "CreditExpire") == 0)
833 long int creditExpire = 0;
834 if (str2x(attr[1], creditExpire) == 0)
835 ucr->creditExpire = (time_t)creditExpire;
840 if (strcasecmp(el, "credit") == 0)
843 if (strtodouble2(attr[1], credit) == 0)
844 ucr->credit = credit;
848 if (strcasecmp(el, "freemb") == 0)
851 if (strtodouble2(attr[1], freeMb) == 0)
852 usr->freeMb = freeMb;
856 if (strcasecmp(el, "down") == 0)
859 if (str2x(attr[1], down) == 0)
860 ucr->disabled = down;
864 if (strcasecmp(el, "DisableDetailStat") == 0)
866 int disabledDetailStat = 0;
867 if (str2x(attr[1], disabledDetailStat) == 0)
868 ucr->disabledDetailStat = disabledDetailStat;
872 if (strcasecmp(el, "email") == 0)
874 ucr->email = EncChar2String(attr[1]);
878 for (int i = 0; i < USERDATA_NUM; i++)
881 sprintf(name, "userdata%d", i);
882 if (strcasecmp(el, name) == 0)
884 ucr->userdata[i] = EncChar2String(attr[1]);
889 if (strcasecmp(el, "group") == 0)
891 ucr->group = EncChar2String(attr[1]);
895 if (strcasecmp(el, "note") == 0)
897 ucr->note = EncChar2String(attr[1]);
901 if (strcasecmp(el, "passive") == 0)
904 if (str2x(attr[1], passive) == 0)
905 ucr->passive = passive;
909 if (strcasecmp(el, "phone") == 0)
911 ucr->phone = EncChar2String(attr[1]);
915 if (strcasecmp(el, "Name") == 0)
917 ucr->realName = EncChar2String(attr[1]);
921 if (strcasecmp(el, "traff") == 0)
930 dir = attr[j][2] - '0';
932 if (strncasecmp(attr[j], "md", 2) == 0)
938 if (strncasecmp(attr[j], "mu", 2) == 0)
951 if (strcasecmp(el, "tariff") == 0)
953 if (strcasecmp(attr[0], "now") == 0)
954 ucr->tariffName = attr[1];
956 if (strcasecmp(attr[0], "delayed") == 0)
957 ucr->nextTariff = attr[1];
964 //-----------------------------------------------------------------------------
965 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
969 if (strcasecmp(el, "SetUser") == 0)
981 //-----------------------------------------------------------------------------
982 void PARSER_CHG_USER::CreateAnswer()
984 //answerList->clear();
985 answerList->erase(answerList->begin(), answerList->end());
990 answerList->push_back("<SetUser result=\"ok\"/>");
993 answerList->push_back("<SetUser result=\"error\"/>");
996 answerList->push_back("<SetUser result=\"error\"/>");
999 answerList->push_back("<SetUser result=\"error\"/>");
1004 //-----------------------------------------------------------------------------
1005 int PARSER_CHG_USER::AplayChanges()
1007 printfd(__FILE__, "PARSER_CHG_USER::AplayChanges()\n");
1011 if (users->FindByName(login, &u))
1018 bool alwaysOnline = u->GetProperty().alwaysOnline;
1019 if (!ucr->alwaysOnline.res_empty())
1022 alwaysOnline = ucr->alwaysOnline.const_data();
1024 bool onlyOneIP = u->GetProperty().ips.ConstData().OnlyOneIP();
1025 if (!ucr->ips.res_empty())
1028 onlyOneIP = ucr->ips.const_data().OnlyOneIP();
1031 if (check && alwaysOnline && !onlyOneIP)
1033 printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
1034 GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
1039 for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i)
1041 CONST_USER_PTR user;
1042 uint32_t ip = ucr->ips.const_data().operator[](i).ip;
1043 if (users->IsIPInUse(ip, login, &user))
1045 printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
1046 GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", currAdmin->GetLogStr().c_str(), inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
1052 if (!ucr->ips.res_empty())
1053 if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
1056 if (!ucr->alwaysOnline.res_empty())
1057 if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(),
1058 currAdmin, login, store))
1061 if (!ucr->address.res_empty())
1062 if (!u->GetProperty().address.Set(ucr->address.const_data(), currAdmin, login, store))
1065 if (!ucr->creditExpire.res_empty())
1066 if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(),
1067 currAdmin, login, store))
1070 if (!ucr->credit.res_empty())
1071 if (!u->GetProperty().credit.Set(ucr->credit.const_data(), currAdmin, login, store))
1074 if (!usr->freeMb.res_empty())
1075 if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
1078 if (!ucr->disabled.res_empty())
1079 if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
1082 if (!ucr->disabledDetailStat.res_empty())
1083 if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
1086 if (!ucr->email.res_empty())
1087 if (!u->GetProperty().email.Set(ucr->email.const_data(), currAdmin, login, store))
1090 if (!ucr->group.res_empty())
1091 if (!u->GetProperty().group.Set(ucr->group.const_data(), currAdmin, login, store))
1094 if (!ucr->note.res_empty())
1095 if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store))
1098 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
1099 userdata.push_back(u->GetProperty().userdata0.GetPointer());
1100 userdata.push_back(u->GetProperty().userdata1.GetPointer());
1101 userdata.push_back(u->GetProperty().userdata2.GetPointer());
1102 userdata.push_back(u->GetProperty().userdata3.GetPointer());
1103 userdata.push_back(u->GetProperty().userdata4.GetPointer());
1104 userdata.push_back(u->GetProperty().userdata5.GetPointer());
1105 userdata.push_back(u->GetProperty().userdata6.GetPointer());
1106 userdata.push_back(u->GetProperty().userdata7.GetPointer());
1107 userdata.push_back(u->GetProperty().userdata8.GetPointer());
1108 userdata.push_back(u->GetProperty().userdata9.GetPointer());
1110 for (int i = 0; i < (int)userdata.size(); i++)
1112 if (!ucr->userdata[i].res_empty())
1114 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
1119 if (!ucr->passive.res_empty())
1120 if (!u->GetProperty().passive.Set(ucr->passive.const_data(), currAdmin, login, store))
1123 if (!ucr->password.res_empty())
1124 if (!u->GetProperty().password.Set(ucr->password.const_data(), currAdmin, login, store))
1127 if (!ucr->phone.res_empty())
1128 if (!u->GetProperty().phone.Set(ucr->phone.const_data(), currAdmin, login, store))
1131 if (!ucr->realName.res_empty())
1132 if (!u->GetProperty().realName.Set(ucr->realName.const_data(), currAdmin, login, store))
1136 if (!usr->cash.res_empty())
1138 //if (*currAdmin->GetPriv()->userCash)
1140 if (cashMustBeAdded)
1142 if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash,
1151 if (!u->GetProperty().cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
1158 if (!ucr->tariffName.res_empty())
1160 if (tariffs->FindByName(ucr->tariffName.const_data()))
1162 if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
1164 u->ResetNextTariff();
1168 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1173 if (!ucr->nextTariff.res_empty())
1175 if (tariffs->FindByName(ucr->nextTariff.const_data()))
1177 if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
1182 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1187 DIR_TRAFF up = u->GetProperty().up;
1188 DIR_TRAFF down = u->GetProperty().down;
1191 for (int i = 0; i < DIR_NUM; i++)
1193 if (!upr[i].res_empty())
1198 if (!downr[i].res_empty())
1206 if (!u->GetProperty().up.Set(up, currAdmin, login, store))
1210 if (!u->GetProperty().down.Set(down, currAdmin, login, store))
1213 /*if (!usr->down.res_empty())
1215 u->GetProperty().down.Set(usr->down.const_data(), currAdmin, login, store);
1217 if (!usr->up.res_empty())
1219 u->GetProperty().up.Set(usr->up.const_data(), currAdmin, login, store);
1227 //-----------------------------------------------------------------------------
1229 //-----------------------------------------------------------------------------
1230 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
1232 if (strcasecmp(el, "Message") == 0)
1234 for (int i = 0; i < 14; i++)
1236 if (attr[i] == NULL)
1238 result = res_params_error;
1240 printfd(__FILE__, "To few parameters\n");
1245 for (int i = 0; i < 14; i+=2)
1247 if (strcasecmp(attr[i], "login") == 0)
1249 ParseLogins(attr[i+1]);
1250 /*if (users->FindByName(login, &u))
1252 result = res_unknown;
1257 if (strcasecmp(attr[i], "MsgVer") == 0)
1259 str2x(attr[i+1], msg.header.ver);
1260 if (msg.header.ver != 1)
1261 result = res_params_error;
1264 if (strcasecmp(attr[i], "MsgType") == 0)
1266 str2x(attr[i+1], msg.header.type);
1267 if (msg.header.type != 1)
1268 result = res_params_error;
1271 if (strcasecmp(attr[i], "Repeat") == 0)
1273 str2x(attr[i+1], msg.header.repeat);
1274 if (msg.header.repeat < 0)
1275 result = res_params_error;
1278 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
1280 str2x(attr[i+1], msg.header.repeatPeriod);
1283 if (strcasecmp(attr[i], "ShowTime") == 0)
1285 str2x(attr[i+1], msg.header.showTime);
1288 if (strcasecmp(attr[i], "Text") == 0)
1290 Decode21str(msg.text, attr[i+1]);
1298 //-----------------------------------------------------------------------------
1299 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
1302 if (strcasecmp(el, "Message") == 0)
1304 result = res_unknown;
1305 for (unsigned i = 0; i < logins.size(); i++)
1307 if (users->FindByName(logins[i], &u))
1309 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
1312 msg.header.creationTime = static_cast<unsigned int>(stgTime);
1313 u->AddMessage(&msg);
1316 /*if (result == res_ok)
1318 if (strcmp(login, "*") == 0)
1322 printfd(__FILE__, "SendMsg text: %s\n", text);
1323 users->GetAllUsers(SendMessageAllUsers, &msg);
1327 u->AddMessage(pri, text);
1335 //-----------------------------------------------------------------------------
1336 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1339 char * l = new char[strlen(login) + 1];
1345 logins.push_back(p);
1346 p = strtok(NULL, ":");
1352 //-----------------------------------------------------------------------------
1353 void PARSER_SEND_MESSAGE::CreateAnswer()
1355 //answerList->clear();
1356 answerList->erase(answerList->begin(), answerList->end());
1357 //answerList->push_back("<SendMessageResult value=\"ok\"/>");
1362 answerList->push_back("<SendMessageResult value=\"ok\"/>");
1364 case res_params_error:
1365 printfd(__FILE__, "res_params_error\n");
1366 answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
1369 printfd(__FILE__, "res_unknown\n");
1370 answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
1373 printfd(__FILE__, "res_default\n");
1377 //-----------------------------------------------------------------------------
1379 //-----------------------------------------------------------------------------
1380 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1383 if (strcasecmp(el, "DelUser") == 0)
1385 if (attr[0] == NULL || attr[1] == NULL)
1387 //CreateAnswer("Parameters error!");
1392 if (users->FindByName(attr[1], &u))
1403 //-----------------------------------------------------------------------------
1404 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1406 if (strcasecmp(el, "DelUser") == 0)
1409 users->Del(u->GetLogin(), currAdmin);
1415 //-----------------------------------------------------------------------------
1416 void PARSER_DEL_USER::CreateAnswer()
1419 answerList->push_back("<DelUser value=\"error\" reason=\"User not found\"/>");
1421 answerList->push_back("<DelUser value=\"ok\"/>");
1423 //-----------------------------------------------------------------------------
1424 /*void PARSERDELUSER::CreateAnswer(char * mes)
1426 //answerList->clear();
1427 answerList->erase(answerList->begin(), answerList->end());
1430 sprintf(str, "<DelUser value=\"%s\"/>", mes);
1431 answerList->push_back(str);
1433 //-----------------------------------------------------------------------------
1435 // <checkuser login="vasya" password=\"123456\"/>
1436 //-----------------------------------------------------------------------------
1437 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1441 if (strcasecmp(el, "CheckUser") == 0)
1443 if (attr[0] == NULL || attr[1] == NULL
1444 || attr[2] == NULL || attr[3] == NULL)
1448 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1453 if (users->FindByName(attr[1], &user))
1457 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1461 if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
1465 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1475 //-----------------------------------------------------------------------------
1476 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1478 if (strcasecmp(el, "CheckUser") == 0)
1484 //-----------------------------------------------------------------------------
1485 void PARSER_CHECK_USER::CreateAnswer()
1488 answerList->push_back("<CheckUser value=\"Ok\"/>");
1490 answerList->push_back("<CheckUser value=\"Err\"/>");
1492 //-----------------------------------------------------------------------------
1493 //-----------------------------------------------------------------------------
1494 //-----------------------------------------------------------------------------