1 #include "admins_methods.h"
6 //------------------------------------------------------------------------------
8 void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList,
9 xmlrpc_c::value * const retvalPtr)
11 std::string cookie = paramList.getString(0);
12 std::string login = paramList.getString(1);
13 paramList.verifyEnd(2);
15 std::map<std::string, xmlrpc_c::value> structVal;
18 if (config->GetAdminInfo(cookie, &adminInfo))
20 structVal["result"] = xmlrpc_c::value_boolean(false);
21 *retvalPtr = xmlrpc_c::value_struct(structVal);
27 if (admins->FindAdmin(login, &admin))
29 structVal["result"] = xmlrpc_c::value_boolean(false);
30 *retvalPtr = xmlrpc_c::value_struct(structVal);
34 structVal["result"] = xmlrpc_c::value_boolean(true);
35 structVal["login"] = xmlrpc_c::value_string(admin->GetLogin());
36 structVal["password"] = xmlrpc_c::value_string(admin->GetPassword());
38 const PRIV * priv = admin->GetPriv();
40 structVal["user_stat"] = xmlrpc_c::value_boolean(priv->userStat);
41 structVal["user_conf"] = xmlrpc_c::value_boolean(priv->userConf);
42 structVal["user_cash"] = xmlrpc_c::value_boolean(priv->userCash);
43 structVal["user_passwd"] = xmlrpc_c::value_boolean(priv->userPasswd);
44 structVal["user_add_del"] = xmlrpc_c::value_boolean(priv->userAddDel);
45 structVal["admin_chg"] = xmlrpc_c::value_boolean(priv->adminChg);
46 structVal["tariff_chg"] = xmlrpc_c::value_boolean(priv->tariffChg);
48 *retvalPtr = xmlrpc_c::value_struct(structVal);
51 //------------------------------------------------------------------------------
53 void METHOD_ADMIN_ADD::execute(xmlrpc_c::paramList const & paramList,
54 xmlrpc_c::value * const retvalPtr)
56 std::string cookie = paramList.getString(0);
57 std::string login = paramList.getString(1);
58 paramList.verifyEnd(2);
62 if (config->GetAdminInfo(cookie, &adminInfo))
64 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Not logged or cookie timeout'\n");
65 *retvalPtr = xmlrpc_c::value_boolean(false);
71 if (admins->FindAdmin(adminInfo.admin, &admin))
73 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Invalid admin (logged)'\n");
74 *retvalPtr = xmlrpc_c::value_boolean(false);
78 if (admins->Add(login, admin))
80 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Failed to add admin'\n");
81 *retvalPtr = xmlrpc_c::value_boolean(false);
85 *retvalPtr = xmlrpc_c::value_boolean(true);
88 //------------------------------------------------------------------------------
90 void METHOD_ADMIN_DEL::execute(xmlrpc_c::paramList const & paramList,
91 xmlrpc_c::value * const retvalPtr)
93 std::string cookie = paramList.getString(0);
94 std::string login = paramList.getString(1);
95 paramList.verifyEnd(2);
97 std::map<std::string, xmlrpc_c::value> structVal;
100 if (config->GetAdminInfo(cookie, &adminInfo))
102 *retvalPtr = xmlrpc_c::value_boolean(false);
108 if (admins->FindAdmin(adminInfo.admin, &admin))
110 *retvalPtr = xmlrpc_c::value_boolean(false);
114 if (admins->Del(login, admin))
116 *retvalPtr = xmlrpc_c::value_boolean(false);
120 *retvalPtr = xmlrpc_c::value_boolean(true);
123 //------------------------------------------------------------------------------
125 void METHOD_ADMIN_CHG::execute(xmlrpc_c::paramList const & paramList,
126 xmlrpc_c::value * const retvalPtr)
128 std::string cookie = paramList.getString(0);
129 std::string login = paramList.getString(1);
130 xmlrpc_c::value_struct info(paramList.getStruct(2));
131 paramList.verifyEnd(3);
133 ADMIN_INFO adminInfo;
135 if (config->GetAdminInfo(cookie, &adminInfo))
137 *retvalPtr = xmlrpc_c::value_boolean(false);
143 if (admins->FindAdmin(adminInfo.admin, &loggedAdmin))
145 *retvalPtr = xmlrpc_c::value_boolean(false);
151 if (admins->FindAdmin(login, &admin))
153 *retvalPtr = xmlrpc_c::value_boolean(false);
159 conf.priv = *admin->GetPriv();
160 conf.password = admin->GetPassword();
163 std::map<std::string, xmlrpc_c::value> structVal(
164 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
167 std::map<std::string, xmlrpc_c::value>::iterator it;
169 if ((it = structVal.find("password")) != structVal.end())
171 conf.password = xmlrpc_c::value_string(it->second);
174 if ((it = structVal.find("user_stat")) != structVal.end())
176 conf.priv.userStat = xmlrpc_c::value_boolean(it->second);
179 if ((it = structVal.find("user_conf")) != structVal.end())
181 conf.priv.userConf = xmlrpc_c::value_boolean(it->second);
184 if ((it = structVal.find("user_cash")) != structVal.end())
186 conf.priv.userCash = xmlrpc_c::value_boolean(it->second);
189 if ((it = structVal.find("user_passwd")) != structVal.end())
191 conf.priv.userPasswd = xmlrpc_c::value_boolean(it->second);
194 if ((it = structVal.find("user_add_del")) != structVal.end())
196 conf.priv.userAddDel = xmlrpc_c::value_boolean(it->second);
199 if ((it = structVal.find("admin_chg")) != structVal.end())
201 conf.priv.adminChg = xmlrpc_c::value_boolean(it->second);
204 if ((it = structVal.find("tariff_chg")) != structVal.end())
206 conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
209 if (admins->Change(conf, loggedAdmin))
211 *retvalPtr = xmlrpc_c::value_boolean(false);
214 *retvalPtr = xmlrpc_c::value_boolean(true);
217 //------------------------------------------------------------------------------
219 void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList,
220 xmlrpc_c::value * const retvalPtr)
222 std::string cookie = paramList.getString(0);
223 paramList.verifyEnd(1);
225 std::map<std::string, xmlrpc_c::value> structVal;
226 std::vector<xmlrpc_c::value> retval;
227 ADMIN_INFO adminInfo;
229 if (config->GetAdminInfo(cookie, &adminInfo))
231 structVal["result"] = xmlrpc_c::value_boolean(false);
232 *retvalPtr = xmlrpc_c::value_struct(structVal);
237 int h = admins->OpenSearch();
239 while (admins->SearchNext(h, &ac) == 0)
241 std::map<std::string, xmlrpc_c::value> structVal;
242 structVal["result"] = xmlrpc_c::value_boolean(true);
243 structVal["login"] = xmlrpc_c::value_string(ac.login);
244 structVal["password"] = xmlrpc_c::value_string(ac.password);
245 structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
246 structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
247 structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
248 structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
249 structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
250 structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
251 structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
253 retval.push_back(xmlrpc_c::value_struct(structVal));
256 *retvalPtr = xmlrpc_c::value_array(retval);