1 #include "admins_methods.h"
4 #include "stg/common.h"
6 #include "stg/admins.h"
8 #include "stg/admin_conf.h"
10 #include <ostream> // xmlrpc-c devs have missed something :)
12 //------------------------------------------------------------------------------
14 void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList,
15 xmlrpc_c::value * const retvalPtr)
17 std::string cookie = paramList.getString(0);
18 std::string login = paramList.getString(1);
19 paramList.verifyEnd(2);
21 std::map<std::string, xmlrpc_c::value> structVal;
24 if (config->GetAdminInfo(cookie, &adminInfo))
26 structVal["result"] = xmlrpc_c::value_boolean(false);
27 *retvalPtr = xmlrpc_c::value_struct(structVal);
33 if (admins->Find(login, &admin))
35 structVal["result"] = xmlrpc_c::value_boolean(false);
36 *retvalPtr = xmlrpc_c::value_struct(structVal);
40 structVal["result"] = xmlrpc_c::value_boolean(true);
41 structVal["login"] = xmlrpc_c::value_string(admin->GetLogin());
42 structVal["password"] = xmlrpc_c::value_string(admin->GetPassword());
44 const auto priv = admin->GetPriv();
46 structVal["user_stat"] = xmlrpc_c::value_boolean(priv->userStat);
47 structVal["user_conf"] = xmlrpc_c::value_boolean(priv->userConf);
48 structVal["user_cash"] = xmlrpc_c::value_boolean(priv->userCash);
49 structVal["user_passwd"] = xmlrpc_c::value_boolean(priv->userPasswd);
50 structVal["user_add_del"] = xmlrpc_c::value_boolean(priv->userAddDel);
51 structVal["admin_chg"] = xmlrpc_c::value_boolean(priv->adminChg);
52 structVal["tariff_chg"] = xmlrpc_c::value_boolean(priv->tariffChg);
54 *retvalPtr = xmlrpc_c::value_struct(structVal);
57 //------------------------------------------------------------------------------
59 void METHOD_ADMIN_ADD::execute(xmlrpc_c::paramList const & paramList,
60 xmlrpc_c::value * const retvalPtr)
62 std::string cookie = paramList.getString(0);
63 std::string login = paramList.getString(1);
64 paramList.verifyEnd(2);
68 if (config->GetAdminInfo(cookie, &adminInfo))
70 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Not logged or cookie timeout'\n");
71 *retvalPtr = xmlrpc_c::value_boolean(false);
77 if (admins->Find(adminInfo.admin, &admin))
79 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Invalid admin (logged)'\n");
80 *retvalPtr = xmlrpc_c::value_boolean(false);
84 if (admins->Add(login, admin))
86 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Failed to add admin'\n");
87 *retvalPtr = xmlrpc_c::value_boolean(false);
91 *retvalPtr = xmlrpc_c::value_boolean(true);
94 //------------------------------------------------------------------------------
96 void METHOD_ADMIN_DEL::execute(xmlrpc_c::paramList const & paramList,
97 xmlrpc_c::value * const retvalPtr)
99 std::string cookie = paramList.getString(0);
100 std::string login = paramList.getString(1);
101 paramList.verifyEnd(2);
103 ADMIN_INFO adminInfo;
105 if (config->GetAdminInfo(cookie, &adminInfo))
107 *retvalPtr = xmlrpc_c::value_boolean(false);
113 if (admins->Find(adminInfo.admin, &admin))
115 *retvalPtr = xmlrpc_c::value_boolean(false);
119 if (admins->Del(login, admin))
121 *retvalPtr = xmlrpc_c::value_boolean(false);
125 *retvalPtr = xmlrpc_c::value_boolean(true);
128 //------------------------------------------------------------------------------
130 void METHOD_ADMIN_CHG::execute(xmlrpc_c::paramList const & paramList,
131 xmlrpc_c::value * const retvalPtr)
133 std::string cookie = paramList.getString(0);
134 std::string login = paramList.getString(1);
135 xmlrpc_c::value_struct info(paramList.getStruct(2));
136 paramList.verifyEnd(3);
138 ADMIN_INFO adminInfo;
140 if (config->GetAdminInfo(cookie, &adminInfo))
142 *retvalPtr = xmlrpc_c::value_boolean(false);
146 STG::Admin * loggedAdmin;
148 if (admins->Find(adminInfo.admin, &loggedAdmin))
150 *retvalPtr = xmlrpc_c::value_boolean(false);
156 if (admins->Find(login, &admin))
158 *retvalPtr = xmlrpc_c::value_boolean(false);
164 conf.priv = *admin->GetPriv();
165 conf.password = admin->GetPassword();
168 std::map<std::string, xmlrpc_c::value> structVal = info;
170 std::map<std::string, xmlrpc_c::value>::iterator it;
172 if ((it = structVal.find("password")) != structVal.end())
174 conf.password = xmlrpc_c::value_string(it->second);
177 if ((it = structVal.find("user_stat")) != structVal.end())
179 conf.priv.userStat = xmlrpc_c::value_boolean(it->second);
182 if ((it = structVal.find("user_conf")) != structVal.end())
184 conf.priv.userConf = xmlrpc_c::value_boolean(it->second);
187 if ((it = structVal.find("user_cash")) != structVal.end())
189 conf.priv.userCash = xmlrpc_c::value_boolean(it->second);
192 if ((it = structVal.find("user_passwd")) != structVal.end())
194 conf.priv.userPasswd = xmlrpc_c::value_boolean(it->second);
197 if ((it = structVal.find("user_add_del")) != structVal.end())
199 conf.priv.userAddDel = xmlrpc_c::value_boolean(it->second);
202 if ((it = structVal.find("admin_chg")) != structVal.end())
204 conf.priv.adminChg = xmlrpc_c::value_boolean(it->second);
207 if ((it = structVal.find("tariff_chg")) != structVal.end())
209 conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
212 if (admins->Change(conf, loggedAdmin))
214 *retvalPtr = xmlrpc_c::value_boolean(false);
217 *retvalPtr = xmlrpc_c::value_boolean(true);
220 //------------------------------------------------------------------------------
222 void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList,
223 xmlrpc_c::value * const retvalPtr)
225 std::string cookie = paramList.getString(0);
226 paramList.verifyEnd(1);
228 std::map<std::string, xmlrpc_c::value> mainStructVal;
229 std::vector<xmlrpc_c::value> retval;
230 ADMIN_INFO adminInfo;
232 if (config->GetAdminInfo(cookie, &adminInfo))
234 mainStructVal["result"] = xmlrpc_c::value_boolean(false);
235 *retvalPtr = xmlrpc_c::value_struct(mainStructVal);
240 int h = admins->OpenSearch();
242 while (admins->SearchNext(h, &ac) == 0)
244 std::map<std::string, xmlrpc_c::value> structVal;
245 structVal["result"] = xmlrpc_c::value_boolean(true);
246 structVal["login"] = xmlrpc_c::value_string(ac.login);
247 structVal["password"] = xmlrpc_c::value_string(ac.password);
248 structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
249 structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
250 structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
251 structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
252 structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
253 structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
254 structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
256 retval.push_back(xmlrpc_c::value_struct(structVal));
259 *retvalPtr = xmlrpc_c::value_array(retval);