]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp
Добавлено игнорирование файлов deps
[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("creditexpire")) != structVal.end())
199     {
200     bool res = iter->property.creditExpire.Set(xmlrpc_c::value_int(it->second),
201                                                admin,
202                                                login,
203                                                &store);
204     if (!res)
205         {
206         return true;
207         }
208     }
209
210 if ((it = structVal.find("credit")) != structVal.end())
211     {
212     bool res = iter->property.credit.Set(xmlrpc_c::value_double(it->second),
213                                          admin,
214                                          login,
215                                          &store);
216     if (!res)
217         {
218         return true;
219         }
220     }
221
222 if ((it = structVal.find("freemb")) != structVal.end())
223     {
224     bool res = iter->property.freeMb.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("disabled")) != structVal.end())
235     {
236     bool res = iter->property.disabled.Set(xmlrpc_c::value_boolean(it->second),
237                                            admin,
238                                            login,
239                                            &store);
240     if (!res)
241         {
242         return true;
243         }
244     }
245
246 if ((it = structVal.find("passive")) != structVal.end())
247     {
248     bool res = iter->property.passive.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("aonline")) != structVal.end())
259     {
260     bool res = iter->property.alwaysOnline.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("disableddetailstat")) != structVal.end())
271     {
272     bool res = iter->property.disabledDetailStat.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("name")) != structVal.end())
283     {
284     bool res = iter->property.realName.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
285                                            admin,
286                                            login,
287                                            &store);
288     if (!res)
289         {
290         return true;
291         }
292     }
293
294 if ((it = structVal.find("group")) != structVal.end())
295     {
296     bool res = iter->property.group.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("note")) != structVal.end())
307     {
308     bool res = iter->property.note.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("userdata")) != structVal.end())
319     {
320     std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
321     userdata.push_back(iter->property.userdata0.GetPointer());
322     userdata.push_back(iter->property.userdata1.GetPointer());
323     userdata.push_back(iter->property.userdata2.GetPointer());
324     userdata.push_back(iter->property.userdata3.GetPointer());
325     userdata.push_back(iter->property.userdata4.GetPointer());
326     userdata.push_back(iter->property.userdata5.GetPointer());
327     userdata.push_back(iter->property.userdata6.GetPointer());
328     userdata.push_back(iter->property.userdata7.GetPointer());
329     userdata.push_back(iter->property.userdata8.GetPointer());
330     userdata.push_back(iter->property.userdata9.GetPointer());
331
332     std::vector<xmlrpc_c::value> udata(
333         xmlrpc_c::value_array(it->second).vectorValueValue()
334         );
335
336     for (unsigned i = 0; i < userdata.size(); ++i)
337         {
338         bool res = userdata[i]->Set(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-R"),
339                                     admin,
340                                     login,
341                                     &store);
342         if (!res)
343             {
344             return true;
345             }
346         }
347     }
348
349 if ((it = structVal.find("traff")) != structVal.end())
350     {
351     std::map<std::string, xmlrpc_c::value> traff(
352         static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
353         );
354
355     std::vector<xmlrpc_c::value> data;
356     DIR_TRAFF dtData;
357     dtData = iter->property.up.Get();
358     if ((it = traff.find("mu")) != traff.end())
359         {
360         data = xmlrpc_c::value_array(it->second).vectorValueValue();
361
362         for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
363             {
364             int64_t value;
365             if (str2x(xmlrpc_c::value_string(data[i]), value))
366                 {
367                 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
368                 }
369             else
370                 {
371                 dtData[i] = value;
372                 }
373             }
374         bool res = iter->property.up.Set(dtData,
375                                          admin,
376                                          login,
377                                          &store);
378         if (!res)
379             {
380             return true;
381             }
382         }
383     dtData = iter->property.down.Get();
384     if ((it = traff.find("md")) != traff.end())
385         {
386         data = xmlrpc_c::value_array(it->second).vectorValueValue();
387
388         for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
389             {
390             int64_t value;
391             if (str2x(xmlrpc_c::value_string(data[i]), value))
392                 {
393                 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
394                 }
395             else
396                 {
397                 dtData[i] = value;
398                 }
399             }
400         bool res = iter->property.down.Set(dtData,
401                                            admin,
402                                            login,
403                                            &store);
404         if (!res)
405             {
406             return true;
407             }
408         }
409     }
410
411 return false;
412 }