1 #include "stg/tariffs.h"
4 #include "stg/user_ips.h"
5 #include "stg/common.h"
6 #include "stg/user_property.h"
7 #include "user_helper.h"
10 //------------------------------------------------------------------------------
12 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
15 std::map<std::string, xmlrpc_c::value> structVal;
17 structVal["result"] = xmlrpc_c::value_boolean(true);
18 structVal["login"] = xmlrpc_c::value_string(ptr->GetLogin());
22 structVal["password"] = xmlrpc_c::value_string(ptr->GetProperty().password.Get());
26 structVal["password"] = xmlrpc_c::value_string("++++++++");
29 structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperty().cash.Get());
30 structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperty().freeMb.Get());
31 structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperty().credit.Get());
33 if (ptr->GetProperty().nextTariff.Get() != "")
35 structVal["tariff"] = xmlrpc_c::value_string(
36 ptr->GetProperty().tariffName.Get() +
38 ptr->GetProperty().nextTariff.Get()
43 structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperty().tariffName.Get());
46 structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().note, "KOI8-RU", "UTF-8"));
48 structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().phone, "KOI8-RU", "UTF-8"));
50 structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().address, "KOI8-RU", "UTF-8"));
52 structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().email, "KOI8-RU", "UTF-8"));
54 std::vector<xmlrpc_c::value> userdata;
56 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata0.Get(), "KOI8-RU", "UTF-8")));
57 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata1.Get(), "KOI8-RU", "UTF-8")));
58 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata2.Get(), "KOI8-RU", "UTF-8")));
59 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata3.Get(), "KOI8-RU", "UTF-8")));
60 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata4.Get(), "KOI8-RU", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata5.Get(), "KOI8-RU", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata6.Get(), "KOI8-RU", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata7.Get(), "KOI8-RU", "UTF-8")));
64 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata8.Get(), "KOI8-RU", "UTF-8")));
65 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata9.Get(), "KOI8-RU", "UTF-8")));
67 structVal["userdata"] = xmlrpc_c::value_array(userdata);
69 structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().realName, "KOI8-RU", "UTF-8"));
71 structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group, "KOI8-RU", "UTF-8"));
73 structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected());
74 structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get());
75 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP()));
76 structVal["pingtime"] = xmlrpc_c::value_int(ptr->GetPingTime());
77 structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().ips.Get().GetIpStr());
79 std::map<std::string, xmlrpc_c::value> traffInfo;
80 std::vector<xmlrpc_c::value> mu(DIR_NUM);
81 std::vector<xmlrpc_c::value> md(DIR_NUM);
82 std::vector<xmlrpc_c::value> su(DIR_NUM);
83 std::vector<xmlrpc_c::value> sd(DIR_NUM);
89 download = ptr->GetProperty().down.Get();
90 upload = ptr->GetProperty().up.Get();
91 sdownload = ptr->GetSessionUpload();
92 supload = ptr->GetSessionDownload();
94 for (int j = 0; j < DIR_NUM; j++)
97 x2str(upload[j], value);
98 mu[j] = xmlrpc_c::value_string(value);
99 x2str(download[j], value);
100 md[j] = xmlrpc_c::value_string(value);
101 x2str(supload[j], value);
102 su[j] = xmlrpc_c::value_string(value);
103 x2str(sdownload[j], value);
104 sd[j] = xmlrpc_c::value_string(value);
107 traffInfo["mu"] = xmlrpc_c::value_array(mu);
108 traffInfo["md"] = xmlrpc_c::value_array(md);
109 traffInfo["su"] = xmlrpc_c::value_array(su);
110 traffInfo["sd"] = xmlrpc_c::value_array(sd);
112 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
114 structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabled.Get());
115 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get());
116 structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get());
117 structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get());
118 structVal["lasttimecash"] = xmlrpc_c::value_int(ptr->GetProperty().lastCashAddTime.Get());
119 structVal["lastactivitytime"] = xmlrpc_c::value_int(ptr->GetProperty().lastActivityTime.Get());
120 structVal["creditexpire"] = xmlrpc_c::value_int(ptr->GetProperty().creditExpire.Get());
122 *info = xmlrpc_c::value_struct(structVal);
125 //------------------------------------------------------------------------------
127 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
129 const std::string & login,
133 std::map<std::string, xmlrpc_c::value> structVal(
134 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
137 std::map<std::string, xmlrpc_c::value>::iterator it;
140 bool alwaysOnline = ptr->GetProperty().alwaysOnline;
141 if ((it = structVal.find("aonline")) != structVal.end())
144 alwaysOnline = xmlrpc_c::value_boolean(it->second);
146 bool onlyOneIP = ptr->GetProperty().ips.ConstData().OnlyOneIP();
147 if ((it = structVal.find("ips")) != structVal.end())
150 onlyOneIP = StrToIPS(xmlrpc_c::value_string(it->second)).OnlyOneIP();
153 if (check && alwaysOnline && !onlyOneIP)
155 printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
159 if ((it = structVal.find("ips")) != structVal.end())
162 ips = StrToIPS(xmlrpc_c::value_string(it->second));
163 if (!ptr->GetProperty().ips.Set(ips,
170 if ((it = structVal.find("aonline")) != structVal.end())
172 bool value(xmlrpc_c::value_boolean(it->second));
173 if (ptr->GetProperty().alwaysOnline.Get() != value)
174 if (!ptr->GetProperty().alwaysOnline.Set(value,
181 if ((it = structVal.find("password")) != structVal.end())
183 std::string value(xmlrpc_c::value_string(it->second));
184 if (ptr->GetProperty().password.Get() != value)
185 if (!ptr->GetProperty().password.Set(value,
192 if ((it = structVal.find("address")) != structVal.end())
194 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
195 if (ptr->GetProperty().address.Get() != value)
196 if (!ptr->GetProperty().address.Set(value,
203 if ((it = structVal.find("phone")) != structVal.end())
205 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
206 if (ptr->GetProperty().phone.Get() != value)
207 if (!ptr->GetProperty().phone.Set(value,
214 if ((it = structVal.find("email")) != structVal.end())
216 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
217 if (ptr->GetProperty().email.Get() != value)
218 if (!ptr->GetProperty().email.Set(value,
225 if ((it = structVal.find("cash")) != structVal.end())
227 double value(xmlrpc_c::value_double(it->second));
228 if (ptr->GetProperty().cash.Get() != value)
229 if (!ptr->GetProperty().cash.Set(value,
236 if ((it = structVal.find("creditexpire")) != structVal.end())
238 time_t value(xmlrpc_c::value_int(it->second));
239 if (ptr->GetProperty().creditExpire.Get() != value)
240 if (!ptr->GetProperty().creditExpire.Set(value,
247 if ((it = structVal.find("credit")) != structVal.end())
249 double value(xmlrpc_c::value_double(it->second));
250 if (ptr->GetProperty().credit.Get() != value)
251 if (!ptr->GetProperty().credit.Set(value,
258 if ((it = structVal.find("freemb")) != structVal.end())
260 double value(xmlrpc_c::value_double(it->second));
261 if (ptr->GetProperty().freeMb.Get() != value)
262 if (!ptr->GetProperty().freeMb.Set(value,
269 if ((it = structVal.find("down")) != structVal.end())
271 bool value(xmlrpc_c::value_boolean(it->second));
272 if (ptr->GetProperty().disabled.Get() != value)
273 if (!ptr->GetProperty().disabled.Set(value,
280 if ((it = structVal.find("passive")) != structVal.end())
282 bool value(xmlrpc_c::value_boolean(it->second));
283 if (ptr->GetProperty().passive.Get() != value)
284 if (!ptr->GetProperty().passive.Set(value,
291 if ((it = structVal.find("disableddetailstat")) != structVal.end())
293 bool value(xmlrpc_c::value_boolean(it->second));
294 if (ptr->GetProperty().disabledDetailStat.Get() != value)
295 if (!ptr->GetProperty().disabledDetailStat.Set(value,
302 if ((it = structVal.find("name")) != structVal.end())
304 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
305 if (ptr->GetProperty().realName.Get() != value)
306 if (!ptr->GetProperty().realName.Set(value,
313 if ((it = structVal.find("group")) != structVal.end())
315 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
316 if (ptr->GetProperty().group.Get() != value)
317 if (!ptr->GetProperty().group.Set(value,
324 if ((it = structVal.find("note")) != structVal.end())
326 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
327 if (ptr->GetProperty().note.Get() != value)
328 if (!ptr->GetProperty().note.Set(value,
335 if ((it = structVal.find("userdata")) != structVal.end())
337 std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
338 userdata.push_back(ptr->GetProperty().userdata0.GetPointer());
339 userdata.push_back(ptr->GetProperty().userdata1.GetPointer());
340 userdata.push_back(ptr->GetProperty().userdata2.GetPointer());
341 userdata.push_back(ptr->GetProperty().userdata3.GetPointer());
342 userdata.push_back(ptr->GetProperty().userdata4.GetPointer());
343 userdata.push_back(ptr->GetProperty().userdata5.GetPointer());
344 userdata.push_back(ptr->GetProperty().userdata6.GetPointer());
345 userdata.push_back(ptr->GetProperty().userdata7.GetPointer());
346 userdata.push_back(ptr->GetProperty().userdata8.GetPointer());
347 userdata.push_back(ptr->GetProperty().userdata9.GetPointer());
349 std::vector<xmlrpc_c::value> udata(
350 xmlrpc_c::value_array(it->second).vectorValueValue()
353 for (unsigned i = 0; i < userdata.size(); ++i)
355 std::string value(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-RU"));
356 if (userdata[i]->Get() != value)
357 if (!userdata[i]->Set(value,
365 if ((it = structVal.find("traff")) != structVal.end())
367 std::map<std::string, xmlrpc_c::value> traff(
368 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
372 dtData = ptr->GetProperty().up.Get();
373 if ((it = traff.find("mu")) != traff.end())
375 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
377 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
380 if (str2x(xmlrpc_c::value_string(data[i]), value))
381 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
385 if (!ptr->GetProperty().up.Set(dtData,
391 dtData = ptr->GetProperty().down.Get();
392 if ((it = traff.find("md")) != traff.end())
394 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
396 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
399 if (str2x(xmlrpc_c::value_string(data[i]), value))
400 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
404 if (!ptr->GetProperty().down.Set(dtData,
412 if ((it = structVal.find("tariff")) != structVal.end())
414 std::string tariff(xmlrpc_c::value_string(it->second));
415 size_t pos = tariff.find('/');
416 std::string nextTariff;
417 if (pos != std::string::npos)
419 nextTariff = tariff.substr(pos + 1);
420 tariff = tariff.substr(0, pos);
423 if (tariffs->FindByName(tariff))
424 if (ptr->GetProperty().tariffName.Get() != tariff)
425 if (!ptr->GetProperty().tariffName.Set(tariff,
431 if (nextTariff != "" &&
432 tariffs->FindByName(nextTariff))
433 if (ptr->GetProperty().nextTariff.Get() != nextTariff)
434 if (!ptr->GetProperty().nextTariff.Set(tariff,