]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp
При изменении пользователя через XML RPC добавлено изменение состояния
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / user_helper.cpp
1 #include "user_helper.h"
2
3 #include "user_ips.h"
4 #include "utils.h"
5
6 //------------------------------------------------------------------------------
7
8 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
9                               bool hidePassword)
10 {
11 std::string enc;
12
13 std::map<std::string, xmlrpc_c::value> structVal;
14
15 structVal["result"] = xmlrpc_c::value_boolean(true);
16 structVal["login"] = xmlrpc_c::value_string(iter->GetLogin());
17
18 if (!hidePassword)
19     {
20     structVal["password"] = xmlrpc_c::value_string(iter->property.password.Get());
21     }
22 else
23     {
24     structVal["password"] = xmlrpc_c::value_string("++++++++");
25     }
26
27 structVal["cash"] = xmlrpc_c::value_double(iter->property.cash.Get());
28 structVal["freemb"] = xmlrpc_c::value_double(iter->property.freeMb.Get());
29 structVal["credit"] = xmlrpc_c::value_double(iter->property.credit.Get());
30
31 if (iter->property.nextTariff.Get() != "")
32     {
33     structVal["tariff"] = xmlrpc_c::value_string(
34             iter->property.tariffName.Get() +
35             "/" +
36             iter->property.nextTariff.Get()
37             );
38     }
39 else
40     {
41     structVal["tariff"] = xmlrpc_c::value_string(iter->property.tariffName.Get());
42     }
43
44 structVal["note"] = xmlrpc_c::value_string(IconvString(iter->property.note, "KOI8-R", "UTF-8"));
45
46 structVal["phone"] = xmlrpc_c::value_string(IconvString(iter->property.phone, "KOI8-R", "UTF-8"));
47
48 structVal["address"] = xmlrpc_c::value_string(IconvString(iter->property.address, "KOI8-R", "UTF-8"));
49
50 structVal["email"] = xmlrpc_c::value_string(IconvString(iter->property.email, "KOI8-R", "UTF-8"));
51
52 std::vector<xmlrpc_c::value> userdata;
53
54 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata0.Get(), "KOI8-R", "UTF-8")));
55 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata1.Get(), "KOI8-R", "UTF-8")));
56 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata2.Get(), "KOI8-R", "UTF-8")));
57 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata3.Get(), "KOI8-R", "UTF-8")));
58 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata4.Get(), "KOI8-R", "UTF-8")));
59 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata5.Get(), "KOI8-R", "UTF-8")));
60 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata6.Get(), "KOI8-R", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata7.Get(), "KOI8-R", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata8.Get(), "KOI8-R", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata9.Get(), "KOI8-R", "UTF-8")));
64
65 structVal["userdata"] = xmlrpc_c::value_array(userdata);
66
67 structVal["name"] = xmlrpc_c::value_string(IconvString(iter->property.realName, "KOI8-R", "UTF-8"));
68
69 structVal["group"] = xmlrpc_c::value_string(IconvString(iter->property.group, "KOI8-R", "UTF-8"));
70
71 structVal["status"] = xmlrpc_c::value_boolean(iter->GetConnected());
72 structVal["aonline"] = xmlrpc_c::value_boolean(iter->property.alwaysOnline.Get());
73 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(iter->GetCurrIP()));
74 structVal["pingtime"] = xmlrpc_c::value_int(iter->GetPingTime());
75 structVal["ips"] = xmlrpc_c::value_string(iter->property.ips.Get().GetIpStr());
76
77 std::map<std::string, xmlrpc_c::value> traffInfo;
78 std::vector<xmlrpc_c::value> mu(DIR_NUM);
79 std::vector<xmlrpc_c::value> md(DIR_NUM);
80 std::vector<xmlrpc_c::value> su(DIR_NUM);
81 std::vector<xmlrpc_c::value> sd(DIR_NUM);
82
83 DIR_TRAFF upload;
84 DIR_TRAFF download;
85 DIR_TRAFF supload;
86 DIR_TRAFF sdownload;
87 download = iter->property.down.Get();
88 upload = iter->property.up.Get();
89 sdownload = iter->GetSessionUpload();
90 supload = iter->GetSessionDownload();
91
92 for (int j = 0; j < DIR_NUM; j++)
93     {
94     std::string value;
95     x2str(upload[j], value);
96     mu[j] = xmlrpc_c::value_string(value);
97     x2str(download[j], value);
98     md[j] = xmlrpc_c::value_string(value);
99     x2str(supload[j], value);
100     su[j] = xmlrpc_c::value_string(value);
101     x2str(sdownload[j], value);
102     sd[j] = xmlrpc_c::value_string(value);
103     }
104
105 traffInfo["mu"] = xmlrpc_c::value_array(mu);
106 traffInfo["md"] = xmlrpc_c::value_array(md);
107 traffInfo["su"] = xmlrpc_c::value_array(su);
108 traffInfo["sd"] = xmlrpc_c::value_array(sd);
109
110 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
111
112 structVal["down"] = xmlrpc_c::value_boolean(iter->property.disabled.Get());
113 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(iter->property.disabledDetailStat.Get());
114 structVal["passive"] = xmlrpc_c::value_boolean(iter->property.passive.Get());
115 structVal["lastcash"] = xmlrpc_c::value_double(iter->property.lastCashAdd.Get());
116 structVal["lasttimecash"] = xmlrpc_c::value_int(iter->property.lastCashAddTime.Get());
117 structVal["lastactivitytime"] = xmlrpc_c::value_int(iter->property.lastActivityTime.Get());
118 structVal["creditexpire"] = xmlrpc_c::value_int(iter->property.creditExpire.Get());
119
120 *info = xmlrpc_c::value_struct(structVal);
121 }
122
123 //------------------------------------------------------------------------------
124
125 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
126                               const ADMIN & admin,
127                               const std::string & login,
128                               const BASE_STORE & store)
129 {
130 std::map<std::string, xmlrpc_c::value> structVal(
131     static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
132     );
133
134 std::map<std::string, xmlrpc_c::value>::iterator it;
135
136 if ((it = structVal.find("password")) != structVal.end())
137     {
138     bool res = iter->property.password.Set(xmlrpc_c::value_string(it->second),
139                                            admin,
140                                            login,
141                                            &store);
142     if (!res)
143         {
144         return true;
145         }
146     }
147
148 if ((it = structVal.find("ips")) != structVal.end())
149     {
150     USER_IPS ips;
151     ips = StrToIPS(xmlrpc_c::value_string(it->second));
152     bool res = iter->property.ips.Set(ips,
153                                       admin,
154                                       login,
155                                       &store);
156     if (!res)
157         {
158         return true;
159         }
160     }
161
162 if ((it = structVal.find("address")) != structVal.end())
163     {
164     bool res = iter->property.address.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
165                                           admin,
166                                           login,
167                                           &store);
168     if (!res)
169         {
170         return true;
171         }
172     }
173
174 if ((it = structVal.find("phone")) != structVal.end())
175     {
176     bool res = iter->property.phone.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
177                                         admin,
178                                         login,
179                                         &store);
180     if (!res)
181         {
182         return true;
183         }
184     }
185
186 if ((it = structVal.find("email")) != structVal.end())
187     {
188     bool res = iter->property.email.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
189                                         admin,
190                                         login,
191                                         &store);
192     if (!res)
193         {
194         return true;
195         }
196     }
197
198 if ((it = structVal.find("cash")) != structVal.end())
199     {
200     bool res = iter->property.cash.Set(xmlrpc_c::value_double(it->second),
201                                        admin,
202                                        login,
203                                        &store);
204     if (!res)
205         {
206         return true;
207         }
208     }
209
210 if ((it = structVal.find("creditexpire")) != structVal.end())
211     {
212     bool res = iter->property.creditExpire.Set(xmlrpc_c::value_int(it->second),
213                                                admin,
214                                                login,
215                                                &store);
216     if (!res)
217         {
218         return true;
219         }
220     }
221
222 if ((it = structVal.find("credit")) != structVal.end())
223     {
224     bool res = iter->property.credit.Set(xmlrpc_c::value_double(it->second),
225                                          admin,
226                                          login,
227                                          &store);
228     if (!res)
229         {
230         return true;
231         }
232     }
233
234 if ((it = structVal.find("freemb")) != structVal.end())
235     {
236     bool res = iter->property.freeMb.Set(xmlrpc_c::value_double(it->second),
237                                          admin,
238                                          login,
239                                          &store);
240     if (!res)
241         {
242         return true;
243         }
244     }
245
246 if ((it = structVal.find("down")) != structVal.end())
247     {
248     bool res = iter->property.disabled.Set(xmlrpc_c::value_boolean(it->second),
249                                            admin,
250                                            login,
251                                            &store);
252     if (!res)
253         {
254         return true;
255         }
256     }
257
258 if ((it = structVal.find("passive")) != structVal.end())
259     {
260     bool res = iter->property.passive.Set(xmlrpc_c::value_boolean(it->second),
261                                           admin,
262                                           login,
263                                           &store);
264     if (!res)
265         {
266         return true;
267         }
268     }
269
270 if ((it = structVal.find("aonline")) != structVal.end())
271     {
272     bool res = iter->property.alwaysOnline.Set(xmlrpc_c::value_boolean(it->second),
273                                                admin,
274                                                login,
275                                                &store);
276     if (!res)
277         {
278         return true;
279         }
280     }
281
282 if ((it = structVal.find("disableddetailstat")) != structVal.end())
283     {
284     bool res = iter->property.disabledDetailStat.Set(xmlrpc_c::value_boolean(it->second),
285                                                      admin,
286                                                      login,
287                                                      &store);
288     if (!res)
289         {
290         return true;
291         }
292     }
293
294 if ((it = structVal.find("name")) != structVal.end())
295     {
296     bool res = iter->property.realName.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
297                                            admin,
298                                            login,
299                                            &store);
300     if (!res)
301         {
302         return true;
303         }
304     }
305
306 if ((it = structVal.find("group")) != structVal.end())
307     {
308     bool res = iter->property.group.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
309                                         admin,
310                                         login,
311                                         &store);
312     if (!res)
313         {
314         return true;
315         }
316     }
317
318 if ((it = structVal.find("note")) != structVal.end())
319     {
320     bool res = iter->property.note.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
321                                        admin,
322                                        login,
323                                        &store);
324     if (!res)
325         {
326         return true;
327         }
328     }
329
330 if ((it = structVal.find("userdata")) != structVal.end())
331     {
332     std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
333     userdata.push_back(iter->property.userdata0.GetPointer());
334     userdata.push_back(iter->property.userdata1.GetPointer());
335     userdata.push_back(iter->property.userdata2.GetPointer());
336     userdata.push_back(iter->property.userdata3.GetPointer());
337     userdata.push_back(iter->property.userdata4.GetPointer());
338     userdata.push_back(iter->property.userdata5.GetPointer());
339     userdata.push_back(iter->property.userdata6.GetPointer());
340     userdata.push_back(iter->property.userdata7.GetPointer());
341     userdata.push_back(iter->property.userdata8.GetPointer());
342     userdata.push_back(iter->property.userdata9.GetPointer());
343
344     std::vector<xmlrpc_c::value> udata(
345         xmlrpc_c::value_array(it->second).vectorValueValue()
346         );
347
348     for (unsigned i = 0; i < userdata.size(); ++i)
349         {
350         bool res = userdata[i]->Set(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-R"),
351                                     admin,
352                                     login,
353                                     &store);
354         if (!res)
355             {
356             return true;
357             }
358         }
359     }
360
361 if ((it = structVal.find("traff")) != structVal.end())
362     {
363     std::map<std::string, xmlrpc_c::value> traff(
364         static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
365         );
366
367     DIR_TRAFF dtData;
368     dtData = iter->property.up.Get();
369     if ((it = traff.find("mu")) != traff.end())
370         {
371         std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
372
373         for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
374             {
375             int64_t value;
376             if (str2x(xmlrpc_c::value_string(data[i]), value))
377                 {
378                 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
379                 }
380             else
381                 {
382                 dtData[i] = value;
383                 }
384             }
385         bool res = iter->property.up.Set(dtData,
386                                          admin,
387                                          login,
388                                          &store);
389         if (!res)
390             {
391             return true;
392             }
393         }
394     dtData = iter->property.down.Get();
395     if ((it = traff.find("md")) != traff.end())
396         {
397         std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
398
399         for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
400             {
401             int64_t value;
402             if (str2x(xmlrpc_c::value_string(data[i]), value))
403                 {
404                 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
405                 }
406             else
407                 {
408                 dtData[i] = value;
409                 }
410             }
411         bool res = iter->property.down.Set(dtData,
412                                            admin,
413                                            login,
414                                            &store);
415         if (!res)
416             {
417             return true;
418             }
419         }
420     }
421
422 return false;
423 }