1 #include "stg/common.h"
2 #include "admins_methods.h"
5 //------------------------------------------------------------------------------
7 void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList,
8 xmlrpc_c::value * const retvalPtr)
10 std::string cookie = paramList.getString(0);
11 std::string login = paramList.getString(1);
12 paramList.verifyEnd(2);
14 std::map<std::string, xmlrpc_c::value> structVal;
17 if (config->GetAdminInfo(cookie, &adminInfo))
19 structVal["result"] = xmlrpc_c::value_boolean(false);
20 *retvalPtr = xmlrpc_c::value_struct(structVal);
26 if (admins->Find(login, &admin))
28 structVal["result"] = xmlrpc_c::value_boolean(false);
29 *retvalPtr = xmlrpc_c::value_struct(structVal);
33 structVal["result"] = xmlrpc_c::value_boolean(true);
34 structVal["login"] = xmlrpc_c::value_string(admin->GetLogin());
35 structVal["password"] = xmlrpc_c::value_string(admin->GetPassword());
37 const PRIV * priv = admin->GetPriv();
39 structVal["user_stat"] = xmlrpc_c::value_boolean(priv->userStat);
40 structVal["user_conf"] = xmlrpc_c::value_boolean(priv->userConf);
41 structVal["user_cash"] = xmlrpc_c::value_boolean(priv->userCash);
42 structVal["user_passwd"] = xmlrpc_c::value_boolean(priv->userPasswd);
43 structVal["user_add_del"] = xmlrpc_c::value_boolean(priv->userAddDel);
44 structVal["admin_chg"] = xmlrpc_c::value_boolean(priv->adminChg);
45 structVal["tariff_chg"] = xmlrpc_c::value_boolean(priv->tariffChg);
47 *retvalPtr = xmlrpc_c::value_struct(structVal);
50 //------------------------------------------------------------------------------
52 void METHOD_ADMIN_ADD::execute(xmlrpc_c::paramList const & paramList,
53 xmlrpc_c::value * const retvalPtr)
55 std::string cookie = paramList.getString(0);
56 std::string login = paramList.getString(1);
57 paramList.verifyEnd(2);
61 if (config->GetAdminInfo(cookie, &adminInfo))
63 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Not logged or cookie timeout'\n");
64 *retvalPtr = xmlrpc_c::value_boolean(false);
70 if (admins->Find(adminInfo.admin, &admin))
72 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Invalid admin (logged)'\n");
73 *retvalPtr = xmlrpc_c::value_boolean(false);
77 if (admins->Add(login, admin))
79 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Failed to add admin'\n");
80 *retvalPtr = xmlrpc_c::value_boolean(false);
84 *retvalPtr = xmlrpc_c::value_boolean(true);
87 //------------------------------------------------------------------------------
89 void METHOD_ADMIN_DEL::execute(xmlrpc_c::paramList const & paramList,
90 xmlrpc_c::value * const retvalPtr)
92 std::string cookie = paramList.getString(0);
93 std::string login = paramList.getString(1);
94 paramList.verifyEnd(2);
96 std::map<std::string, xmlrpc_c::value> structVal;
99 if (config->GetAdminInfo(cookie, &adminInfo))
101 *retvalPtr = xmlrpc_c::value_boolean(false);
107 if (admins->Find(adminInfo.admin, &admin))
109 *retvalPtr = xmlrpc_c::value_boolean(false);
113 if (admins->Del(login, admin))
115 *retvalPtr = xmlrpc_c::value_boolean(false);
119 *retvalPtr = xmlrpc_c::value_boolean(true);
122 //------------------------------------------------------------------------------
124 void METHOD_ADMIN_CHG::execute(xmlrpc_c::paramList const & paramList,
125 xmlrpc_c::value * const retvalPtr)
127 std::string cookie = paramList.getString(0);
128 std::string login = paramList.getString(1);
129 xmlrpc_c::value_struct info(paramList.getStruct(2));
130 paramList.verifyEnd(3);
132 ADMIN_INFO adminInfo;
134 if (config->GetAdminInfo(cookie, &adminInfo))
136 *retvalPtr = xmlrpc_c::value_boolean(false);
142 if (admins->Find(adminInfo.admin, &loggedAdmin))
144 *retvalPtr = xmlrpc_c::value_boolean(false);
150 if (admins->Find(login, &admin))
152 *retvalPtr = xmlrpc_c::value_boolean(false);
158 conf.priv = *admin->GetPriv();
159 conf.password = admin->GetPassword();
162 std::map<std::string, xmlrpc_c::value> structVal(
163 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
166 std::map<std::string, xmlrpc_c::value>::iterator it;
168 if ((it = structVal.find("password")) != structVal.end())
170 conf.password = xmlrpc_c::value_string(it->second);
173 if ((it = structVal.find("user_stat")) != structVal.end())
175 conf.priv.userStat = xmlrpc_c::value_boolean(it->second);
178 if ((it = structVal.find("user_conf")) != structVal.end())
180 conf.priv.userConf = xmlrpc_c::value_boolean(it->second);
183 if ((it = structVal.find("user_cash")) != structVal.end())
185 conf.priv.userCash = xmlrpc_c::value_boolean(it->second);
188 if ((it = structVal.find("user_passwd")) != structVal.end())
190 conf.priv.userPasswd = xmlrpc_c::value_boolean(it->second);
193 if ((it = structVal.find("user_add_del")) != structVal.end())
195 conf.priv.userAddDel = xmlrpc_c::value_boolean(it->second);
198 if ((it = structVal.find("admin_chg")) != structVal.end())
200 conf.priv.adminChg = xmlrpc_c::value_boolean(it->second);
203 if ((it = structVal.find("tariff_chg")) != structVal.end())
205 conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
208 if (admins->Change(conf, loggedAdmin))
210 *retvalPtr = xmlrpc_c::value_boolean(false);
213 *retvalPtr = xmlrpc_c::value_boolean(true);
216 //------------------------------------------------------------------------------
218 void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList,
219 xmlrpc_c::value * const retvalPtr)
221 std::string cookie = paramList.getString(0);
222 paramList.verifyEnd(1);
224 std::map<std::string, xmlrpc_c::value> structVal;
225 std::vector<xmlrpc_c::value> retval;
226 ADMIN_INFO adminInfo;
228 if (config->GetAdminInfo(cookie, &adminInfo))
230 structVal["result"] = xmlrpc_c::value_boolean(false);
231 *retvalPtr = xmlrpc_c::value_struct(structVal);
236 int h = admins->OpenSearch();
238 while (admins->SearchNext(h, &ac) == 0)
240 std::map<std::string, xmlrpc_c::value> structVal;
241 structVal["result"] = xmlrpc_c::value_boolean(true);
242 structVal["login"] = xmlrpc_c::value_string(ac.login);
243 structVal["password"] = xmlrpc_c::value_string(ac.password);
244 structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
245 structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
246 structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
247 structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
248 structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
249 structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
250 structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
252 retval.push_back(xmlrpc_c::value_struct(structVal));
255 *retvalPtr = xmlrpc_c::value_array(retval);