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(
169 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
172 std::map<std::string, xmlrpc_c::value>::iterator it;
174 if ((it = structVal.find("password")) != structVal.end())
176 conf.password = xmlrpc_c::value_string(it->second);
179 if ((it = structVal.find("user_stat")) != structVal.end())
181 conf.priv.userStat = xmlrpc_c::value_boolean(it->second);
184 if ((it = structVal.find("user_conf")) != structVal.end())
186 conf.priv.userConf = xmlrpc_c::value_boolean(it->second);
189 if ((it = structVal.find("user_cash")) != structVal.end())
191 conf.priv.userCash = xmlrpc_c::value_boolean(it->second);
194 if ((it = structVal.find("user_passwd")) != structVal.end())
196 conf.priv.userPasswd = xmlrpc_c::value_boolean(it->second);
199 if ((it = structVal.find("user_add_del")) != structVal.end())
201 conf.priv.userAddDel = xmlrpc_c::value_boolean(it->second);
204 if ((it = structVal.find("admin_chg")) != structVal.end())
206 conf.priv.adminChg = xmlrpc_c::value_boolean(it->second);
209 if ((it = structVal.find("tariff_chg")) != structVal.end())
211 conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
214 if (admins->Change(conf, loggedAdmin))
216 *retvalPtr = xmlrpc_c::value_boolean(false);
219 *retvalPtr = xmlrpc_c::value_boolean(true);
222 //------------------------------------------------------------------------------
224 void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList,
225 xmlrpc_c::value * const retvalPtr)
227 std::string cookie = paramList.getString(0);
228 paramList.verifyEnd(1);
230 std::map<std::string, xmlrpc_c::value> mainStructVal;
231 std::vector<xmlrpc_c::value> retval;
232 ADMIN_INFO adminInfo;
234 if (config->GetAdminInfo(cookie, &adminInfo))
236 mainStructVal["result"] = xmlrpc_c::value_boolean(false);
237 *retvalPtr = xmlrpc_c::value_struct(mainStructVal);
242 int h = admins->OpenSearch();
244 while (admins->SearchNext(h, &ac) == 0)
246 std::map<std::string, xmlrpc_c::value> structVal;
247 structVal["result"] = xmlrpc_c::value_boolean(true);
248 structVal["login"] = xmlrpc_c::value_string(ac.login);
249 structVal["password"] = xmlrpc_c::value_string(ac.password);
250 structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
251 structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
252 structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
253 structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
254 structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
255 structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
256 structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
258 retval.push_back(xmlrpc_c::value_struct(structVal));
261 *retvalPtr = xmlrpc_c::value_array(retval);