X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/4271ab433cd55bbd2612292bcf39e4dc3d7274f1..0907aa4037b12b6b88ee24495d4577a064d4f8db:/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp?ds=inline diff --git a/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp new file mode 100644 index 00000000..e0c371cd --- /dev/null +++ b/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp @@ -0,0 +1,92 @@ +#include "info_methods.h" +#include "rpcconfig.h" + +#include "stg/users.h" +#include "stg/tariffs.h" +#include "stg/version.h" +#include "stg/common.h" +#include "stg/const.h" + +#include // xmlrpc-c devs have missed something :) + +#include + +void METHOD_INFO::execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalPtr) +{ +paramList.verifyEnd(0); +std::map structVal; + +std::string un; +struct utsname utsn; + +uname(&utsn); +un[0] = 0; + +un += utsn.sysname; +un += " "; +un += utsn.release; +un += " "; +un += utsn.machine; +un += " "; +un += utsn.nodename; + +structVal["version"] = xmlrpc_c::value_string(SERVER_VERSION); +structVal["tariff_num"] = xmlrpc_c::value_int(static_cast(tariffs->Count())); +structVal["tariff"] = xmlrpc_c::value_int(2); +structVal["users_num"] = xmlrpc_c::value_int(static_cast(users->Count())); +structVal["uname"] = xmlrpc_c::value_string(un); +structVal["dir_num"] = xmlrpc_c::value_int(DIR_NUM); +structVal["day_fee"] = xmlrpc_c::value_int(static_cast(dayFee)); + +std::vector dirnameVal; + +for (int i = 0; i< DIR_NUM; i++) + { + dirnameVal.push_back(xmlrpc_c::value_string(IconvString(dirNames[i], "KOI8-RU", "UTF-8"))); + } + +structVal["dir_names"] = xmlrpc_c::value_array(dirnameVal); + +*retvalPtr = xmlrpc_c::value_struct(structVal); +} + +void METHOD_LOGIN::execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalPtr) +{ +std::string login = paramList.getString(0); +std::string password = paramList.getString(1); +paramList.verifyEnd(2); + +std::map structVal; + +std::string cookie; +if (config->CheckAdmin(login, password, &cookie)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + structVal["cookie"] = xmlrpc_c::value_string(""); + } +else + { + structVal["result"] = xmlrpc_c::value_boolean(true); + structVal["cookie"] = xmlrpc_c::value_string(cookie); + } + +*retvalPtr = xmlrpc_c::value_struct(structVal); +} + +void METHOD_LOGOUT::execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalPtr) +{ +std::string cookie = paramList.getString(0); +paramList.verifyEnd(1); + +if (config->LogoutAdmin(cookie)) + { + *retvalPtr = xmlrpc_c::value_boolean(false); + } +else + { + *retvalPtr = xmlrpc_c::value_boolean(true); + } +}