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 strprintf(&s, "</user>");
290 answerList->push_back(s);
292 //-----------------------------------------------------------------------------
294 //-----------------------------------------------------------------------------
295 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
297 /*if (attr && *attr && *(attr+1))
299 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
303 printfd(__FILE__, "attr = NULL\n");
306 lastUpdateFound = false;
307 if (strcasecmp(el, "GetUsers") == 0)
309 while (attr && *attr && *(attr+1))
311 if (strcasecmp(*attr, "LastUpdate") == 0)
313 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
315 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
316 lastUpdateFound = true;
320 //printfd(__FILE__, "NO lastUserUpdateTime\n");
330 //-----------------------------------------------------------------------------
331 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
333 if (strcasecmp(el, "GetUsers") == 0)
340 //-----------------------------------------------------------------------------
341 void PARSER_GET_USERS::CreateAnswer()
343 answerList->erase(answerList->begin(), answerList->end());
346 std::string userStart;
347 std::string traffStart;
348 std::string traffMiddle;
349 std::string traffFinish;
351 std::string userFinish;
358 int h = users->OpenSearch();
361 printfd(__FILE__, "users->OpenSearch() error\n");
362 users->CloseSearch(h);
365 std::string updateTime;
366 x2str(time(NULL), updateTime);
369 answerList->push_back("<Users LastUpdate=\"" + updateTime + "\">");
371 answerList->push_back("<Users>");
375 if (users->SearchNext(h, &u))
379 userStart = "<user login=\"" + u->GetLogin() + "\">";
382 if (u->GetProperty().password.ModificationTime() > lastUserUpdateTime)
384 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
385 s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
387 s = "<password value=\"++++++\"/>";
392 if (u->GetProperty().cash.ModificationTime() > lastUserUpdateTime)
394 strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
396 //printfd(__FILE__, "cash value=\"%f\"\n", u->GetProperty().cash.Get());
400 if (u->GetProperty().freeMb.ModificationTime() > lastUserUpdateTime)
402 strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
406 if (u->GetProperty().credit.ModificationTime() > lastUserUpdateTime)
408 strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
412 if (u->GetProperty().nextTariff.Get() != "")
414 if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime
415 || u->GetProperty().nextTariff.ModificationTime() > lastUserUpdateTime)
417 strprintf(&s, "<tariff value=\"%s/%s\" />",
418 u->GetProperty().tariffName.Get().c_str(),
419 u->GetProperty().nextTariff.Get().c_str());
425 if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime)
427 strprintf(&s, "<tariff value=\"%s\" />",
428 u->GetProperty().tariffName.Get().c_str());
433 if (u->GetProperty().note.ModificationTime() > lastUserUpdateTime)
435 Encode12str(enc, u->GetProperty().note);
436 strprintf(&s, "<note value=\"%s\" />", enc.c_str());
440 if (u->GetProperty().phone.ModificationTime() > lastUserUpdateTime)
442 Encode12str(enc, u->GetProperty().phone);
443 strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
447 if (u->GetProperty().address.ModificationTime() > lastUserUpdateTime)
449 Encode12str(enc, u->GetProperty().address);
450 strprintf(&s, "<address value=\"%s\" />", enc.c_str());
454 if (u->GetProperty().email.ModificationTime() > lastUserUpdateTime)
456 Encode12str(enc, u->GetProperty().email);
457 strprintf(&s, "<email value=\"%s\" />", enc.c_str());
461 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
462 userdata.push_back(u->GetProperty().userdata0.GetPointer());
463 userdata.push_back(u->GetProperty().userdata1.GetPointer());
464 userdata.push_back(u->GetProperty().userdata2.GetPointer());
465 userdata.push_back(u->GetProperty().userdata3.GetPointer());
466 userdata.push_back(u->GetProperty().userdata4.GetPointer());
467 userdata.push_back(u->GetProperty().userdata5.GetPointer());
468 userdata.push_back(u->GetProperty().userdata6.GetPointer());
469 userdata.push_back(u->GetProperty().userdata7.GetPointer());
470 userdata.push_back(u->GetProperty().userdata8.GetPointer());
471 userdata.push_back(u->GetProperty().userdata9.GetPointer());
474 for (unsigned i = 0; i < userdata.size(); i++)
476 if (userdata[i]->ModificationTime() > lastUserUpdateTime)
478 Encode12str(enc, userdata[i]->Get());
479 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
484 if (u->GetProperty().realName.ModificationTime() > lastUserUpdateTime)
486 Encode12str(enc, u->GetProperty().realName);
487 strprintf(&s, "<name value=\"%s\" />", enc.c_str());
491 if (u->GetProperty().group.ModificationTime() > lastUserUpdateTime)
493 Encode12str(enc, u->GetProperty().group);
494 strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
498 if (u->GetProperty().alwaysOnline.ModificationTime() > lastUserUpdateTime)
500 strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
504 if (u->GetCurrIPModificationTime() > lastUserUpdateTime)
506 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
511 if (u->GetConnectedModificationTime() > lastUserUpdateTime)
513 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
517 if (u->GetPingTime() > lastUserUpdateTime)
519 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
523 if (u->GetProperty().ips.ModificationTime() > lastUserUpdateTime)
525 std::ostringstream sstr;
526 sstr << u->GetProperty().ips.Get();
527 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
532 traffStart = "<traff";
535 download = u->GetProperty().down.Get();
536 upload = u->GetProperty().up.Get();
539 if (u->GetProperty().up.ModificationTime() > lastUserUpdateTime)
541 for (int j = 0; j < DIR_NUM; j++)
545 sprintf(st, " MU%d=\"%s\" ", j, s.c_str());
550 if (u->GetProperty().down.ModificationTime() > lastUserUpdateTime)
552 for (int j = 0; j < DIR_NUM; j++)
554 x2str(download[j], s);
555 sprintf(st, " MD%d=\"%s\" ", j, s.c_str());
561 if (traffMiddle.length() > 0)
563 middle += traffStart;
564 middle += traffMiddle;
565 middle += traffFinish;
568 if (u->GetProperty().disabled.ModificationTime() > lastUserUpdateTime)
570 strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
574 if (u->GetProperty().disabledDetailStat.ModificationTime() > lastUserUpdateTime)
576 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
580 //printfd(__FILE__, ">>>>> %s\n", s.c_str());
582 if (u->GetProperty().passive.ModificationTime() > lastUserUpdateTime)
584 strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
588 if (u->GetProperty().lastCashAdd.ModificationTime() > lastUserUpdateTime)
590 strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
594 if (u->GetProperty().lastCashAddTime.ModificationTime() > lastUserUpdateTime)
596 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
601 if (u->GetProperty().lastActivityTime.ModificationTime() > lastUserUpdateTime)
603 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
607 if (u->GetProperty().creditExpire.ModificationTime() > lastUserUpdateTime)
609 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
614 userFinish = "</user>";
616 if (middle.length() > 0)
618 /*printfd(__FILE__, "login: %s\n", u->GetLogin().c_str());
619 printfd(__FILE__, "middle: %s\n", middle.c_str());*/
621 answerList->push_back(userStart);
622 answerList->push_back(middle);
623 answerList->push_back(userFinish);
627 users->CloseSearch(h);
629 //answerList->push_back("</Users>");
631 answerList->push_back("</Users>");
633 //-----------------------------------------------------------------------------
635 //-----------------------------------------------------------------------------
636 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
642 if (strcasecmp(el, "AddUser") == 0)
649 if (strcasecmp(el, "login") == 0)
657 //-----------------------------------------------------------------------------
658 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
662 if (strcasecmp(el, "AddUser") == 0)
673 //-----------------------------------------------------------------------------
674 void PARSER_ADD_USER::Reset()
676 BASE_PARSER::Reset();
679 //-----------------------------------------------------------------------------
680 void PARSER_ADD_USER::CreateAnswer()
682 //answerList->clear();
683 answerList->erase(answerList->begin(), answerList->end());
685 if (CheckUserData() == 0)
687 answerList->push_back("<AddUser result=\"ok\"/>");
691 answerList->push_back("<AddUser result=\"error\" reason=\"Access denied\"/>");
694 //-----------------------------------------------------------------------------
695 int PARSER_ADD_USER::CheckUserData()
698 if (users->FindByName(login, &u))
700 return users->Add(login, currAdmin);
704 //-----------------------------------------------------------------------------
706 //-----------------------------------------------------------------------------
707 PARSER_CHG_USER::PARSER_CHG_USER()
715 cashMustBeAdded(false),
720 //-----------------------------------------------------------------------------
721 PARSER_CHG_USER::~PARSER_CHG_USER()
728 //-----------------------------------------------------------------------------
729 void PARSER_CHG_USER::Reset()
740 usr = new USER_STAT_RES;
741 ucr = new USER_CONF_RES;
743 upr = new RESETABLE<uint64_t>[DIR_NUM];
744 downr = new RESETABLE<uint64_t>[DIR_NUM];
746 //-----------------------------------------------------------------------------
747 std::string PARSER_CHG_USER::EncChar2String(const char * strEnc)
750 Decode21str(str, strEnc);
753 //-----------------------------------------------------------------------------
754 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
760 if (strcasecmp(el, "SetUser") == 0)
767 //printfd(__FILE__, "el=%s\n", el);
768 if (strcasecmp(el, "login") == 0)
774 if (strcasecmp(el, "ip") == 0)
778 ucr->ips = StrToIPS(attr[1]);
782 printfd(__FILE__, "StrToIPS Error!\n");
786 if (strcasecmp(el, "password") == 0)
788 ucr->password = attr[1];
792 if (strcasecmp(el, "address") == 0)
794 ucr->address = EncChar2String(attr[1]);
798 if (strcasecmp(el, "aonline") == 0)
800 ucr->alwaysOnline = (*(attr[1]) != '0');
804 if (strcasecmp(el, "cash") == 0)
806 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
808 cashMsg = EncChar2String(attr[3]);
812 if (strtodouble2(attr[1], cash) == 0)
815 if (strcasecmp(attr[0], "set") == 0)
816 cashMustBeAdded = false;
818 if (strcasecmp(attr[0], "add") == 0)
819 cashMustBeAdded = true;
824 if (strcasecmp(el, "CreditExpire") == 0)
826 long int creditExpire = 0;
827 if (str2x(attr[1], creditExpire) == 0)
828 ucr->creditExpire = (time_t)creditExpire;
833 if (strcasecmp(el, "credit") == 0)
836 if (strtodouble2(attr[1], credit) == 0)
837 ucr->credit = credit;
841 if (strcasecmp(el, "freemb") == 0)
844 if (strtodouble2(attr[1], freeMb) == 0)
845 usr->freeMb = freeMb;
849 if (strcasecmp(el, "down") == 0)
852 if (str2x(attr[1], down) == 0)
853 ucr->disabled = down;
857 if (strcasecmp(el, "DisableDetailStat") == 0)
859 int disabledDetailStat = 0;
860 if (str2x(attr[1], disabledDetailStat) == 0)
861 ucr->disabledDetailStat = disabledDetailStat;
865 if (strcasecmp(el, "email") == 0)
867 ucr->email = EncChar2String(attr[1]);
871 for (int i = 0; i < USERDATA_NUM; i++)
874 sprintf(name, "userdata%d", i);
875 if (strcasecmp(el, name) == 0)
877 ucr->userdata[i] = EncChar2String(attr[1]);
882 if (strcasecmp(el, "group") == 0)
884 ucr->group = EncChar2String(attr[1]);
888 if (strcasecmp(el, "note") == 0)
890 ucr->note = EncChar2String(attr[1]);
894 if (strcasecmp(el, "passive") == 0)
897 if (str2x(attr[1], passive) == 0)
898 ucr->passive = passive;
902 if (strcasecmp(el, "phone") == 0)
904 ucr->phone = EncChar2String(attr[1]);
908 if (strcasecmp(el, "Name") == 0)
910 ucr->realName = EncChar2String(attr[1]);
914 if (strcasecmp(el, "traff") == 0)
923 dir = attr[j][2] - '0';
925 if (strncasecmp(attr[j], "md", 2) == 0)
931 if (strncasecmp(attr[j], "mu", 2) == 0)
944 if (strcasecmp(el, "tariff") == 0)
946 if (strcasecmp(attr[0], "now") == 0)
947 ucr->tariffName = attr[1];
949 if (strcasecmp(attr[0], "delayed") == 0)
950 ucr->nextTariff = attr[1];
957 //-----------------------------------------------------------------------------
958 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
962 if (strcasecmp(el, "SetUser") == 0)
974 //-----------------------------------------------------------------------------
975 void PARSER_CHG_USER::CreateAnswer()
977 //answerList->clear();
978 answerList->erase(answerList->begin(), answerList->end());
983 answerList->push_back("<SetUser result=\"ok\"/>");
986 answerList->push_back("<SetUser result=\"error\"/>");
989 answerList->push_back("<SetUser result=\"error\"/>");
992 answerList->push_back("<SetUser result=\"error\"/>");
997 //-----------------------------------------------------------------------------
998 int PARSER_CHG_USER::AplayChanges()
1000 printfd(__FILE__, "PARSER_CHG_USER::AplayChanges()\n");
1004 if (users->FindByName(login, &u))
1011 bool alwaysOnline = u->GetProperty().alwaysOnline;
1012 if (!ucr->alwaysOnline.res_empty())
1015 alwaysOnline = ucr->alwaysOnline.const_data();
1017 bool onlyOneIP = u->GetProperty().ips.ConstData().OnlyOneIP();
1018 if (!ucr->ips.res_empty())
1021 onlyOneIP = ucr->ips.const_data().OnlyOneIP();
1024 if (check && alwaysOnline && !onlyOneIP)
1026 printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
1027 GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
1031 if (!ucr->ips.res_empty())
1032 if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
1035 if (!ucr->alwaysOnline.res_empty())
1036 if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(),
1037 currAdmin, login, store))
1040 if (!ucr->address.res_empty())
1041 if (!u->GetProperty().address.Set(ucr->address.const_data(), currAdmin, login, store))
1044 if (!ucr->creditExpire.res_empty())
1045 if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(),
1046 currAdmin, login, store))
1049 if (!ucr->credit.res_empty())
1050 if (!u->GetProperty().credit.Set(ucr->credit.const_data(), currAdmin, login, store))
1053 if (!usr->freeMb.res_empty())
1054 if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
1057 if (!ucr->disabled.res_empty())
1058 if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
1061 if (!ucr->disabledDetailStat.res_empty())
1062 if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
1065 if (!ucr->email.res_empty())
1066 if (!u->GetProperty().email.Set(ucr->email.const_data(), currAdmin, login, store))
1069 if (!ucr->group.res_empty())
1070 if (!u->GetProperty().group.Set(ucr->group.const_data(), currAdmin, login, store))
1073 if (!ucr->note.res_empty())
1074 if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store))
1077 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
1078 userdata.push_back(u->GetProperty().userdata0.GetPointer());
1079 userdata.push_back(u->GetProperty().userdata1.GetPointer());
1080 userdata.push_back(u->GetProperty().userdata2.GetPointer());
1081 userdata.push_back(u->GetProperty().userdata3.GetPointer());
1082 userdata.push_back(u->GetProperty().userdata4.GetPointer());
1083 userdata.push_back(u->GetProperty().userdata5.GetPointer());
1084 userdata.push_back(u->GetProperty().userdata6.GetPointer());
1085 userdata.push_back(u->GetProperty().userdata7.GetPointer());
1086 userdata.push_back(u->GetProperty().userdata8.GetPointer());
1087 userdata.push_back(u->GetProperty().userdata9.GetPointer());
1089 for (int i = 0; i < (int)userdata.size(); i++)
1091 if (!ucr->userdata[i].res_empty())
1093 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
1098 if (!ucr->passive.res_empty())
1099 if (!u->GetProperty().passive.Set(ucr->passive.const_data(), currAdmin, login, store))
1102 if (!ucr->password.res_empty())
1103 if (!u->GetProperty().password.Set(ucr->password.const_data(), currAdmin, login, store))
1106 if (!ucr->phone.res_empty())
1107 if (!u->GetProperty().phone.Set(ucr->phone.const_data(), currAdmin, login, store))
1110 if (!ucr->realName.res_empty())
1111 if (!u->GetProperty().realName.Set(ucr->realName.const_data(), currAdmin, login, store))
1115 if (!usr->cash.res_empty())
1117 //if (*currAdmin->GetPriv()->userCash)
1119 if (cashMustBeAdded)
1121 if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash,
1130 if (!u->GetProperty().cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
1137 if (!ucr->tariffName.res_empty())
1139 if (tariffs->FindByName(ucr->tariffName.const_data()))
1141 if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
1143 u->ResetNextTariff();
1147 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1152 if (!ucr->nextTariff.res_empty())
1154 if (tariffs->FindByName(ucr->nextTariff.const_data()))
1156 if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
1161 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1166 DIR_TRAFF up = u->GetProperty().up;
1167 DIR_TRAFF down = u->GetProperty().down;
1170 for (int i = 0; i < DIR_NUM; i++)
1172 if (!upr[i].res_empty())
1177 if (!downr[i].res_empty())
1185 if (!u->GetProperty().up.Set(up, currAdmin, login, store))
1189 if (!u->GetProperty().down.Set(down, currAdmin, login, store))
1192 /*if (!usr->down.res_empty())
1194 u->GetProperty().down.Set(usr->down.const_data(), currAdmin, login, store);
1196 if (!usr->up.res_empty())
1198 u->GetProperty().up.Set(usr->up.const_data(), currAdmin, login, store);
1206 //-----------------------------------------------------------------------------
1208 //-----------------------------------------------------------------------------
1209 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
1211 if (strcasecmp(el, "Message") == 0)
1213 for (int i = 0; i < 14; i++)
1215 if (attr[i] == NULL)
1217 result = res_params_error;
1219 printfd(__FILE__, "To few parameters\n");
1224 for (int i = 0; i < 14; i+=2)
1226 if (strcasecmp(attr[i], "login") == 0)
1228 ParseLogins(attr[i+1]);
1229 /*if (users->FindByName(login, &u))
1231 result = res_unknown;
1236 if (strcasecmp(attr[i], "MsgVer") == 0)
1238 str2x(attr[i+1], msg.header.ver);
1239 if (msg.header.ver != 1)
1240 result = res_params_error;
1243 if (strcasecmp(attr[i], "MsgType") == 0)
1245 str2x(attr[i+1], msg.header.type);
1246 if (msg.header.type != 1)
1247 result = res_params_error;
1250 if (strcasecmp(attr[i], "Repeat") == 0)
1252 str2x(attr[i+1], msg.header.repeat);
1253 if (msg.header.repeat < 0)
1254 result = res_params_error;
1257 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
1259 str2x(attr[i+1], msg.header.repeatPeriod);
1262 if (strcasecmp(attr[i], "ShowTime") == 0)
1264 str2x(attr[i+1], msg.header.showTime);
1267 if (strcasecmp(attr[i], "Text") == 0)
1269 Decode21str(msg.text, attr[i+1]);
1277 //-----------------------------------------------------------------------------
1278 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
1281 if (strcasecmp(el, "Message") == 0)
1283 result = res_unknown;
1284 for (unsigned i = 0; i < logins.size(); i++)
1286 if (users->FindByName(logins[i], &u))
1288 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
1291 msg.header.creationTime = static_cast<unsigned int>(stgTime);
1292 u->AddMessage(&msg);
1295 /*if (result == res_ok)
1297 if (strcmp(login, "*") == 0)
1301 printfd(__FILE__, "SendMsg text: %s\n", text);
1302 users->GetAllUsers(SendMessageAllUsers, &msg);
1306 u->AddMessage(pri, text);
1314 //-----------------------------------------------------------------------------
1315 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1318 char * l = new char[strlen(login) + 1];
1324 logins.push_back(p);
1325 p = strtok(NULL, ":");
1331 //-----------------------------------------------------------------------------
1332 void PARSER_SEND_MESSAGE::CreateAnswer()
1334 //answerList->clear();
1335 answerList->erase(answerList->begin(), answerList->end());
1336 //answerList->push_back("<SendMessageResult value=\"ok\"/>");
1341 answerList->push_back("<SendMessageResult value=\"ok\"/>");
1343 case res_params_error:
1344 printfd(__FILE__, "res_params_error\n");
1345 answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
1348 printfd(__FILE__, "res_unknown\n");
1349 answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
1352 printfd(__FILE__, "res_default\n");
1356 //-----------------------------------------------------------------------------
1358 //-----------------------------------------------------------------------------
1359 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1362 if (strcasecmp(el, "DelUser") == 0)
1364 if (attr[0] == NULL || attr[1] == NULL)
1366 //CreateAnswer("Parameters error!");
1371 if (users->FindByName(attr[1], &u))
1382 //-----------------------------------------------------------------------------
1383 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1385 if (strcasecmp(el, "DelUser") == 0)
1388 users->Del(u->GetLogin(), currAdmin);
1394 //-----------------------------------------------------------------------------
1395 void PARSER_DEL_USER::CreateAnswer()
1398 answerList->push_back("<DelUser value=\"error\" reason=\"User not found\"/>");
1400 answerList->push_back("<DelUser value=\"ok\"/>");
1402 //-----------------------------------------------------------------------------
1403 /*void PARSERDELUSER::CreateAnswer(char * mes)
1405 //answerList->clear();
1406 answerList->erase(answerList->begin(), answerList->end());
1409 sprintf(str, "<DelUser value=\"%s\"/>", mes);
1410 answerList->push_back(str);
1412 //-----------------------------------------------------------------------------
1414 // <checkuser login="vasya" password=\"123456\"/>
1415 //-----------------------------------------------------------------------------
1416 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1420 if (strcasecmp(el, "CheckUser") == 0)
1422 if (attr[0] == NULL || attr[1] == NULL
1423 || attr[2] == NULL || attr[3] == NULL)
1427 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1432 if (users->FindByName(attr[1], &user))
1436 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1440 if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
1444 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1454 //-----------------------------------------------------------------------------
1455 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1457 if (strcasecmp(el, "CheckUser") == 0)
1463 //-----------------------------------------------------------------------------
1464 void PARSER_CHECK_USER::CreateAnswer()
1467 answerList->push_back("<CheckUser value=\"Ok\"/>");
1469 answerList->push_back("<CheckUser value=\"Err\"/>");
1471 //-----------------------------------------------------------------------------
1472 //-----------------------------------------------------------------------------
1473 //-----------------------------------------------------------------------------