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 answerList->push_back("<user result=\"error\" reason=\"User not found.\"/>");
140 s = "<user result=\"ok\">";
141 answerList->push_back(s);
143 s = "<login value=\"" + u->GetLogin() + "\"/>";
144 answerList->push_back(s);
146 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
147 s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
149 s = "<password value=\"++++++\"/>";
150 answerList->push_back(s);
152 strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
153 answerList->push_back(s);
155 strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
156 answerList->push_back(s);
158 strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
159 answerList->push_back(s);
161 if (u->GetProperty().nextTariff.Get() != "")
163 strprintf(&s, "<tariff value=\"%s/%s\" />",
164 u->GetProperty().tariffName.Get().c_str(),
165 u->GetProperty().nextTariff.Get().c_str());
169 strprintf(&s, "<tariff value=\"%s\" />",
170 u->GetProperty().tariffName.Get().c_str());
173 answerList->push_back(s);
175 Encode12str(enc, u->GetProperty().note);
176 s = "<note value=\"" + enc + "\" />";
177 answerList->push_back(s);
179 Encode12str(enc, u->GetProperty().phone);
180 s = "<phone value=\"" + enc + "\" />";
181 answerList->push_back(s);
183 Encode12str(enc, u->GetProperty().address);
184 s = "<address value=\"" + enc + "\" />";
185 answerList->push_back(s);
187 Encode12str(enc, u->GetProperty().email);
188 s = "<email value=\"" + enc + "\" />";
189 answerList->push_back(s);
192 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
193 userdata.push_back(u->GetProperty().userdata0.GetPointer());
194 userdata.push_back(u->GetProperty().userdata1.GetPointer());
195 userdata.push_back(u->GetProperty().userdata2.GetPointer());
196 userdata.push_back(u->GetProperty().userdata3.GetPointer());
197 userdata.push_back(u->GetProperty().userdata4.GetPointer());
198 userdata.push_back(u->GetProperty().userdata5.GetPointer());
199 userdata.push_back(u->GetProperty().userdata6.GetPointer());
200 userdata.push_back(u->GetProperty().userdata7.GetPointer());
201 userdata.push_back(u->GetProperty().userdata8.GetPointer());
202 userdata.push_back(u->GetProperty().userdata9.GetPointer());
205 for (unsigned i = 0; i < userdata.size(); i++)
207 Encode12str(enc, userdata[i]->Get());
208 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
209 answerList->push_back(s);
212 Encode12str(enc, u->GetProperty().realName);
213 s = "<name value=\"" + enc + "\" />";
214 answerList->push_back(s);
216 Encode12str(enc, u->GetProperty().group);
217 s = "<GROUP value=\"" + enc + "\" />";
218 answerList->push_back(s);
220 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
221 answerList->push_back(s);
223 strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
224 answerList->push_back(s);
226 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
227 answerList->push_back(s);
229 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
230 answerList->push_back(s);
232 std::ostringstream sstr;
233 sstr << u->GetProperty().ips.Get();
234 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
235 answerList->push_back(s);
238 ss = new char[DIR_NUM*25*4 + 50];
240 sprintf(ss, "<traff");
243 download = u->GetProperty().down.Get();
244 upload = u->GetProperty().up.Get();
246 for (int j = 0; j < DIR_NUM; j++)
250 sprintf(st, " MU%d=\"%s\"", j, s.c_str());
253 x2str(download[j], s);
254 sprintf(st, " MD%d=\"%s\"", j, s.c_str());
257 sprintf(st, " SU%d=\"0\"", j);
260 sprintf(st, " SD%d=\"0\"", j);
264 answerList->push_back(ss);
267 strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
268 answerList->push_back(s);
270 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
271 answerList->push_back(s);
273 strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
274 answerList->push_back(s);
276 strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
277 answerList->push_back(s);
279 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
280 answerList->push_back(s);
282 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
283 answerList->push_back(s);
285 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
286 answerList->push_back(s);
288 s = "<AuthorizedBy>";
289 std::vector<std::string> list(u->GetAuthorizers());
290 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
291 s += "<Auth name=\"" + *it + "\"/>";
292 s += "</AuthorizedBy>";
293 answerList->push_back(s);
295 strprintf(&s, "</user>");
296 answerList->push_back(s);
298 //-----------------------------------------------------------------------------
300 //-----------------------------------------------------------------------------
301 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
303 /*if (attr && *attr && *(attr+1))
305 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
309 printfd(__FILE__, "attr = NULL\n");
312 lastUpdateFound = false;
313 if (strcasecmp(el, "GetUsers") == 0)
315 while (attr && *attr && *(attr+1))
317 if (strcasecmp(*attr, "LastUpdate") == 0)
319 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
321 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
322 lastUpdateFound = true;
326 //printfd(__FILE__, "NO lastUserUpdateTime\n");
336 //-----------------------------------------------------------------------------
337 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
339 if (strcasecmp(el, "GetUsers") == 0)
346 //-----------------------------------------------------------------------------
347 void PARSER_GET_USERS::CreateAnswer()
349 answerList->erase(answerList->begin(), answerList->end());
352 std::string userStart;
353 std::string traffStart;
354 std::string traffMiddle;
355 std::string traffFinish;
357 std::string userFinish;
364 int h = users->OpenSearch();
367 printfd(__FILE__, "users->OpenSearch() error\n");
368 users->CloseSearch(h);
371 std::string updateTime;
372 x2str(time(NULL), updateTime);
375 answerList->push_back("<Users LastUpdate=\"" + updateTime + "\">");
377 answerList->push_back("<Users>");
381 if (users->SearchNext(h, &u))
385 userStart = "<user login=\"" + u->GetLogin() + "\">";
388 if (u->GetProperty().password.ModificationTime() > lastUserUpdateTime)
390 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
391 s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
393 s = "<password value=\"++++++\"/>";
398 if (u->GetProperty().cash.ModificationTime() > lastUserUpdateTime)
400 strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
402 //printfd(__FILE__, "cash value=\"%f\"\n", u->GetProperty().cash.Get());
406 if (u->GetProperty().freeMb.ModificationTime() > lastUserUpdateTime)
408 strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
412 if (u->GetProperty().credit.ModificationTime() > lastUserUpdateTime)
414 strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
418 if (u->GetProperty().nextTariff.Get() != "")
420 if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime
421 || u->GetProperty().nextTariff.ModificationTime() > lastUserUpdateTime)
423 strprintf(&s, "<tariff value=\"%s/%s\" />",
424 u->GetProperty().tariffName.Get().c_str(),
425 u->GetProperty().nextTariff.Get().c_str());
431 if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime)
433 strprintf(&s, "<tariff value=\"%s\" />",
434 u->GetProperty().tariffName.Get().c_str());
439 if (u->GetProperty().note.ModificationTime() > lastUserUpdateTime)
441 Encode12str(enc, u->GetProperty().note);
442 strprintf(&s, "<note value=\"%s\" />", enc.c_str());
446 if (u->GetProperty().phone.ModificationTime() > lastUserUpdateTime)
448 Encode12str(enc, u->GetProperty().phone);
449 strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
453 if (u->GetProperty().address.ModificationTime() > lastUserUpdateTime)
455 Encode12str(enc, u->GetProperty().address);
456 strprintf(&s, "<address value=\"%s\" />", enc.c_str());
460 if (u->GetProperty().email.ModificationTime() > lastUserUpdateTime)
462 Encode12str(enc, u->GetProperty().email);
463 strprintf(&s, "<email value=\"%s\" />", enc.c_str());
467 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
468 userdata.push_back(u->GetProperty().userdata0.GetPointer());
469 userdata.push_back(u->GetProperty().userdata1.GetPointer());
470 userdata.push_back(u->GetProperty().userdata2.GetPointer());
471 userdata.push_back(u->GetProperty().userdata3.GetPointer());
472 userdata.push_back(u->GetProperty().userdata4.GetPointer());
473 userdata.push_back(u->GetProperty().userdata5.GetPointer());
474 userdata.push_back(u->GetProperty().userdata6.GetPointer());
475 userdata.push_back(u->GetProperty().userdata7.GetPointer());
476 userdata.push_back(u->GetProperty().userdata8.GetPointer());
477 userdata.push_back(u->GetProperty().userdata9.GetPointer());
480 for (unsigned i = 0; i < userdata.size(); i++)
482 if (userdata[i]->ModificationTime() > lastUserUpdateTime)
484 Encode12str(enc, userdata[i]->Get());
485 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
490 if (u->GetProperty().realName.ModificationTime() > lastUserUpdateTime)
492 Encode12str(enc, u->GetProperty().realName);
493 strprintf(&s, "<name value=\"%s\" />", enc.c_str());
497 if (u->GetProperty().group.ModificationTime() > lastUserUpdateTime)
499 Encode12str(enc, u->GetProperty().group);
500 strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
504 if (u->GetProperty().alwaysOnline.ModificationTime() > lastUserUpdateTime)
506 strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
510 if (u->GetCurrIPModificationTime() > lastUserUpdateTime)
512 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
517 if (u->GetConnectedModificationTime() > lastUserUpdateTime)
519 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
523 if (u->GetPingTime() > lastUserUpdateTime)
525 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
529 if (u->GetProperty().ips.ModificationTime() > lastUserUpdateTime)
531 std::ostringstream sstr;
532 sstr << u->GetProperty().ips.Get();
533 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
538 traffStart = "<traff";
541 download = u->GetProperty().down.Get();
542 upload = u->GetProperty().up.Get();
545 if (u->GetProperty().up.ModificationTime() > lastUserUpdateTime)
547 for (int j = 0; j < DIR_NUM; j++)
551 sprintf(st, " MU%d=\"%s\" ", j, s.c_str());
556 if (u->GetProperty().down.ModificationTime() > lastUserUpdateTime)
558 for (int j = 0; j < DIR_NUM; j++)
560 x2str(download[j], s);
561 sprintf(st, " MD%d=\"%s\" ", j, s.c_str());
567 if (traffMiddle.length() > 0)
569 middle += traffStart;
570 middle += traffMiddle;
571 middle += traffFinish;
574 if (u->GetProperty().disabled.ModificationTime() > lastUserUpdateTime)
576 strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
580 if (u->GetProperty().disabledDetailStat.ModificationTime() > lastUserUpdateTime)
582 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
586 //printfd(__FILE__, ">>>>> %s\n", s.c_str());
588 if (u->GetProperty().passive.ModificationTime() > lastUserUpdateTime)
590 strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
594 if (u->GetProperty().lastCashAdd.ModificationTime() > lastUserUpdateTime)
596 strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
600 if (u->GetProperty().lastCashAddTime.ModificationTime() > lastUserUpdateTime)
602 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
607 if (u->GetProperty().lastActivityTime.ModificationTime() > lastUserUpdateTime)
609 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
613 if (u->GetProperty().creditExpire.ModificationTime() > lastUserUpdateTime)
615 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
620 userFinish = "</user>";
622 if (middle.length() > 0)
624 /*printfd(__FILE__, "login: %s\n", u->GetLogin().c_str());
625 printfd(__FILE__, "middle: %s\n", middle.c_str());*/
627 answerList->push_back(userStart);
628 answerList->push_back(middle);
629 answerList->push_back(userFinish);
633 users->CloseSearch(h);
635 //answerList->push_back("</Users>");
637 answerList->push_back("</Users>");
639 //-----------------------------------------------------------------------------
641 //-----------------------------------------------------------------------------
642 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
648 if (strcasecmp(el, "AddUser") == 0)
655 if (strcasecmp(el, "login") == 0)
663 //-----------------------------------------------------------------------------
664 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
668 if (strcasecmp(el, "AddUser") == 0)
679 //-----------------------------------------------------------------------------
680 void PARSER_ADD_USER::Reset()
682 BASE_PARSER::Reset();
685 //-----------------------------------------------------------------------------
686 void PARSER_ADD_USER::CreateAnswer()
688 //answerList->clear();
689 answerList->erase(answerList->begin(), answerList->end());
691 if (CheckUserData() == 0)
693 answerList->push_back("<AddUser result=\"ok\"/>");
697 answerList->push_back("<AddUser result=\"error\" reason=\"Access denied\"/>");
700 //-----------------------------------------------------------------------------
701 int PARSER_ADD_USER::CheckUserData()
704 if (users->FindByName(login, &u))
706 return users->Add(login, currAdmin);
710 //-----------------------------------------------------------------------------
712 //-----------------------------------------------------------------------------
713 PARSER_CHG_USER::PARSER_CHG_USER()
721 cashMustBeAdded(false),
726 //-----------------------------------------------------------------------------
727 PARSER_CHG_USER::~PARSER_CHG_USER()
734 //-----------------------------------------------------------------------------
735 void PARSER_CHG_USER::Reset()
746 usr = new USER_STAT_RES;
747 ucr = new USER_CONF_RES;
749 upr = new RESETABLE<uint64_t>[DIR_NUM];
750 downr = new RESETABLE<uint64_t>[DIR_NUM];
752 //-----------------------------------------------------------------------------
753 std::string PARSER_CHG_USER::EncChar2String(const char * strEnc)
756 Decode21str(str, strEnc);
759 //-----------------------------------------------------------------------------
760 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
766 if (strcasecmp(el, "SetUser") == 0)
773 //printfd(__FILE__, "el=%s\n", el);
774 if (strcasecmp(el, "login") == 0)
780 if (strcasecmp(el, "ip") == 0)
784 ucr->ips = StrToIPS(attr[1]);
788 printfd(__FILE__, "StrToIPS Error!\n");
792 if (strcasecmp(el, "password") == 0)
794 ucr->password = attr[1];
798 if (strcasecmp(el, "address") == 0)
800 ucr->address = EncChar2String(attr[1]);
804 if (strcasecmp(el, "aonline") == 0)
806 ucr->alwaysOnline = (*(attr[1]) != '0');
810 if (strcasecmp(el, "cash") == 0)
812 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
814 cashMsg = EncChar2String(attr[3]);
818 if (strtodouble2(attr[1], cash) == 0)
821 if (strcasecmp(attr[0], "set") == 0)
822 cashMustBeAdded = false;
824 if (strcasecmp(attr[0], "add") == 0)
825 cashMustBeAdded = true;
830 if (strcasecmp(el, "CreditExpire") == 0)
832 long int creditExpire = 0;
833 if (str2x(attr[1], creditExpire) == 0)
834 ucr->creditExpire = (time_t)creditExpire;
839 if (strcasecmp(el, "credit") == 0)
842 if (strtodouble2(attr[1], credit) == 0)
843 ucr->credit = credit;
847 if (strcasecmp(el, "freemb") == 0)
850 if (strtodouble2(attr[1], freeMb) == 0)
851 usr->freeMb = freeMb;
855 if (strcasecmp(el, "down") == 0)
858 if (str2x(attr[1], down) == 0)
859 ucr->disabled = down;
863 if (strcasecmp(el, "DisableDetailStat") == 0)
865 int disabledDetailStat = 0;
866 if (str2x(attr[1], disabledDetailStat) == 0)
867 ucr->disabledDetailStat = disabledDetailStat;
871 if (strcasecmp(el, "email") == 0)
873 ucr->email = EncChar2String(attr[1]);
877 for (int i = 0; i < USERDATA_NUM; i++)
880 sprintf(name, "userdata%d", i);
881 if (strcasecmp(el, name) == 0)
883 ucr->userdata[i] = EncChar2String(attr[1]);
888 if (strcasecmp(el, "group") == 0)
890 ucr->group = EncChar2String(attr[1]);
894 if (strcasecmp(el, "note") == 0)
896 ucr->note = EncChar2String(attr[1]);
900 if (strcasecmp(el, "passive") == 0)
903 if (str2x(attr[1], passive) == 0)
904 ucr->passive = passive;
908 if (strcasecmp(el, "phone") == 0)
910 ucr->phone = EncChar2String(attr[1]);
914 if (strcasecmp(el, "Name") == 0)
916 ucr->realName = EncChar2String(attr[1]);
920 if (strcasecmp(el, "traff") == 0)
929 dir = attr[j][2] - '0';
931 if (strncasecmp(attr[j], "md", 2) == 0)
937 if (strncasecmp(attr[j], "mu", 2) == 0)
950 if (strcasecmp(el, "tariff") == 0)
952 if (strcasecmp(attr[0], "now") == 0)
953 ucr->tariffName = attr[1];
955 if (strcasecmp(attr[0], "delayed") == 0)
956 ucr->nextTariff = attr[1];
963 //-----------------------------------------------------------------------------
964 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
968 if (strcasecmp(el, "SetUser") == 0)
980 //-----------------------------------------------------------------------------
981 void PARSER_CHG_USER::CreateAnswer()
983 //answerList->clear();
984 answerList->erase(answerList->begin(), answerList->end());
989 answerList->push_back("<SetUser result=\"ok\"/>");
992 answerList->push_back("<SetUser result=\"error\"/>");
995 answerList->push_back("<SetUser result=\"error\"/>");
998 answerList->push_back("<SetUser result=\"error\"/>");
1003 //-----------------------------------------------------------------------------
1004 int PARSER_CHG_USER::AplayChanges()
1006 printfd(__FILE__, "PARSER_CHG_USER::AplayChanges()\n");
1010 if (users->FindByName(login, &u))
1017 bool alwaysOnline = u->GetProperty().alwaysOnline;
1018 if (!ucr->alwaysOnline.res_empty())
1021 alwaysOnline = ucr->alwaysOnline.const_data();
1023 bool onlyOneIP = u->GetProperty().ips.ConstData().OnlyOneIP();
1024 if (!ucr->ips.res_empty())
1027 onlyOneIP = ucr->ips.const_data().OnlyOneIP();
1030 if (check && alwaysOnline && !onlyOneIP)
1032 printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
1033 GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
1038 for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i)
1040 CONST_USER_PTR user;
1041 uint32_t ip = ucr->ips.const_data().operator[](i).ip;
1042 if (users->IsIPInUse(ip, login, &user))
1044 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());
1045 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());
1051 if (!ucr->ips.res_empty())
1052 if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
1055 if (!ucr->alwaysOnline.res_empty())
1056 if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(),
1057 currAdmin, login, store))
1060 if (!ucr->address.res_empty())
1061 if (!u->GetProperty().address.Set(ucr->address.const_data(), currAdmin, login, store))
1064 if (!ucr->creditExpire.res_empty())
1065 if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(),
1066 currAdmin, login, store))
1069 if (!ucr->credit.res_empty())
1070 if (!u->GetProperty().credit.Set(ucr->credit.const_data(), currAdmin, login, store))
1073 if (!usr->freeMb.res_empty())
1074 if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
1077 if (!ucr->disabled.res_empty())
1078 if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
1081 if (!ucr->disabledDetailStat.res_empty())
1082 if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
1085 if (!ucr->email.res_empty())
1086 if (!u->GetProperty().email.Set(ucr->email.const_data(), currAdmin, login, store))
1089 if (!ucr->group.res_empty())
1090 if (!u->GetProperty().group.Set(ucr->group.const_data(), currAdmin, login, store))
1093 if (!ucr->note.res_empty())
1094 if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store))
1097 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
1098 userdata.push_back(u->GetProperty().userdata0.GetPointer());
1099 userdata.push_back(u->GetProperty().userdata1.GetPointer());
1100 userdata.push_back(u->GetProperty().userdata2.GetPointer());
1101 userdata.push_back(u->GetProperty().userdata3.GetPointer());
1102 userdata.push_back(u->GetProperty().userdata4.GetPointer());
1103 userdata.push_back(u->GetProperty().userdata5.GetPointer());
1104 userdata.push_back(u->GetProperty().userdata6.GetPointer());
1105 userdata.push_back(u->GetProperty().userdata7.GetPointer());
1106 userdata.push_back(u->GetProperty().userdata8.GetPointer());
1107 userdata.push_back(u->GetProperty().userdata9.GetPointer());
1109 for (int i = 0; i < (int)userdata.size(); i++)
1111 if (!ucr->userdata[i].res_empty())
1113 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
1118 if (!ucr->passive.res_empty())
1119 if (!u->GetProperty().passive.Set(ucr->passive.const_data(), currAdmin, login, store))
1122 if (!ucr->password.res_empty())
1123 if (!u->GetProperty().password.Set(ucr->password.const_data(), currAdmin, login, store))
1126 if (!ucr->phone.res_empty())
1127 if (!u->GetProperty().phone.Set(ucr->phone.const_data(), currAdmin, login, store))
1130 if (!ucr->realName.res_empty())
1131 if (!u->GetProperty().realName.Set(ucr->realName.const_data(), currAdmin, login, store))
1135 if (!usr->cash.res_empty())
1137 //if (*currAdmin->GetPriv()->userCash)
1139 if (cashMustBeAdded)
1141 if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash,
1150 if (!u->GetProperty().cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
1157 if (!ucr->tariffName.res_empty())
1159 if (tariffs->FindByName(ucr->tariffName.const_data()))
1161 if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
1163 u->ResetNextTariff();
1167 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1172 if (!ucr->nextTariff.res_empty())
1174 if (tariffs->FindByName(ucr->nextTariff.const_data()))
1176 if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
1181 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1186 DIR_TRAFF up = u->GetProperty().up;
1187 DIR_TRAFF down = u->GetProperty().down;
1190 for (int i = 0; i < DIR_NUM; i++)
1192 if (!upr[i].res_empty())
1197 if (!downr[i].res_empty())
1205 if (!u->GetProperty().up.Set(up, currAdmin, login, store))
1209 if (!u->GetProperty().down.Set(down, currAdmin, login, store))
1212 /*if (!usr->down.res_empty())
1214 u->GetProperty().down.Set(usr->down.const_data(), currAdmin, login, store);
1216 if (!usr->up.res_empty())
1218 u->GetProperty().up.Set(usr->up.const_data(), currAdmin, login, store);
1226 //-----------------------------------------------------------------------------
1228 //-----------------------------------------------------------------------------
1229 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
1231 if (strcasecmp(el, "Message") == 0)
1233 for (int i = 0; i < 14; i++)
1235 if (attr[i] == NULL)
1237 result = res_params_error;
1239 printfd(__FILE__, "To few parameters\n");
1244 for (int i = 0; i < 14; i+=2)
1246 if (strcasecmp(attr[i], "login") == 0)
1248 ParseLogins(attr[i+1]);
1249 /*if (users->FindByName(login, &u))
1251 result = res_unknown;
1256 if (strcasecmp(attr[i], "MsgVer") == 0)
1258 str2x(attr[i+1], msg.header.ver);
1259 if (msg.header.ver != 1)
1260 result = res_params_error;
1263 if (strcasecmp(attr[i], "MsgType") == 0)
1265 str2x(attr[i+1], msg.header.type);
1266 if (msg.header.type != 1)
1267 result = res_params_error;
1270 if (strcasecmp(attr[i], "Repeat") == 0)
1272 str2x(attr[i+1], msg.header.repeat);
1273 if (msg.header.repeat < 0)
1274 result = res_params_error;
1277 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
1279 str2x(attr[i+1], msg.header.repeatPeriod);
1282 if (strcasecmp(attr[i], "ShowTime") == 0)
1284 str2x(attr[i+1], msg.header.showTime);
1287 if (strcasecmp(attr[i], "Text") == 0)
1289 Decode21str(msg.text, attr[i+1]);
1297 //-----------------------------------------------------------------------------
1298 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
1301 if (strcasecmp(el, "Message") == 0)
1303 result = res_unknown;
1304 for (unsigned i = 0; i < logins.size(); i++)
1306 if (users->FindByName(logins[i], &u))
1308 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
1311 msg.header.creationTime = static_cast<unsigned int>(stgTime);
1312 u->AddMessage(&msg);
1315 /*if (result == res_ok)
1317 if (strcmp(login, "*") == 0)
1321 printfd(__FILE__, "SendMsg text: %s\n", text);
1322 users->GetAllUsers(SendMessageAllUsers, &msg);
1326 u->AddMessage(pri, text);
1334 //-----------------------------------------------------------------------------
1335 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1338 char * l = new char[strlen(login) + 1];
1344 logins.push_back(p);
1345 p = strtok(NULL, ":");
1351 //-----------------------------------------------------------------------------
1352 void PARSER_SEND_MESSAGE::CreateAnswer()
1354 //answerList->clear();
1355 answerList->erase(answerList->begin(), answerList->end());
1356 //answerList->push_back("<SendMessageResult value=\"ok\"/>");
1361 answerList->push_back("<SendMessageResult value=\"ok\"/>");
1363 case res_params_error:
1364 printfd(__FILE__, "res_params_error\n");
1365 answerList->push_back("<SendMessageResult value=\"Parameters error.\"/>");
1368 printfd(__FILE__, "res_unknown\n");
1369 answerList->push_back("<SendMessageResult value=\"Unknown user.\"/>");
1372 printfd(__FILE__, "res_default\n");
1376 //-----------------------------------------------------------------------------
1378 //-----------------------------------------------------------------------------
1379 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1382 if (strcasecmp(el, "DelUser") == 0)
1384 if (attr[0] == NULL || attr[1] == NULL)
1386 //CreateAnswer("Parameters error!");
1391 if (users->FindByName(attr[1], &u))
1402 //-----------------------------------------------------------------------------
1403 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1405 if (strcasecmp(el, "DelUser") == 0)
1408 users->Del(u->GetLogin(), currAdmin);
1414 //-----------------------------------------------------------------------------
1415 void PARSER_DEL_USER::CreateAnswer()
1418 answerList->push_back("<DelUser value=\"error\" reason=\"User not found\"/>");
1420 answerList->push_back("<DelUser value=\"ok\"/>");
1422 //-----------------------------------------------------------------------------
1424 // <checkuser login="vasya" password=\"123456\"/>
1425 //-----------------------------------------------------------------------------
1426 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1428 if (strcasecmp(el, "CheckUser") == 0)
1430 if (attr[0] == NULL || attr[1] == NULL
1431 || attr[2] == NULL || attr[3] == NULL)
1433 CreateAnswer("Invalid parameters.");
1434 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1439 if (users->FindByName(attr[1], &user))
1441 CreateAnswer("User not found.");
1442 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1446 if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
1448 CreateAnswer("Wrong password.");
1449 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1458 //-----------------------------------------------------------------------------
1459 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1461 if (strcasecmp(el, "CheckUser") == 0)
1467 //-----------------------------------------------------------------------------
1468 void PARSER_CHECK_USER::CreateAnswer(const char * error)
1471 answerList->push_back(std::string("<CheckUser value=\"Err\" reason=\"") + error + "\"/>");
1473 answerList->push_back("<CheckUser value=\"Ok\"/>");
1475 //-----------------------------------------------------------------------------
1476 //-----------------------------------------------------------------------------
1477 //-----------------------------------------------------------------------------