X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/bdd487e027c6f6c752eacc71aa75055e1323cd7f..8383a049b4b6f7223dd833af18675696fc0663db:/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp?ds=sidebyside diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index 35166c81..5adbf441 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -1,16 +1,15 @@ #include -#include "users_methods.h" - -#include "users.h" -#include "admins.h" -#include "tariffs.h" +#include "stg/users.h" +#include "stg/admins.h" +#include "stg/tariffs.h" +#include "stg/user_ips.h" +#include "stg/common.h" +#include "stg/user_property.h" +#include "users_methods.h" #include "rpcconfig.h" #include "user_helper.h" -#include "user_ips.h" -#include "utils.h" -#include "common.h" //------------------------------------------------------------------------------ @@ -19,7 +18,6 @@ void METHOD_USER_GET::execute(xmlrpc_c::paramList const & paramList, { std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); -std::string enc; paramList.verifyEnd(2); std::map structVal; @@ -32,7 +30,7 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -user_iter u; +USER_PTR u; if (users->FindByName(login, &u)) { @@ -41,7 +39,7 @@ if (users->FindByName(login, &u)) return; } -USER_HELPER uhelper(u); +USER_HELPER uhelper(u, *users); if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd) { @@ -59,7 +57,6 @@ void METHOD_USER_ADD::execute(xmlrpc_c::paramList const & paramList, { std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); -std::string enc; paramList.verifyEnd(2); ADMIN_INFO adminInfo; @@ -70,15 +67,15 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN admin; +ADMIN * admin = NULL; -if (admins->FindAdmin(adminInfo.admin, &admin)) +if (admins->Find(adminInfo.admin, &admin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -user_iter u; +USER_PTR u; if (users->FindByName(login, &u)) { @@ -103,7 +100,6 @@ void METHOD_USER_DEL::execute(xmlrpc_c::paramList const & paramList, { std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); -std::string enc; paramList.verifyEnd(2); ADMIN_INFO adminInfo; @@ -114,17 +110,17 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN admin; +ADMIN * admin; -if (admins->FindAdmin(adminInfo.admin, &admin)) +if (admins->Find(adminInfo.admin, &admin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -user_iter u; +USER_PTR u; -if (users->FindByName(login, &u)) +if (!users->FindByName(login, &u)) { users->Del(login, admin); *retvalPtr = xmlrpc_c::value_boolean(true); @@ -141,7 +137,6 @@ void METHOD_USERS_GET::execute(xmlrpc_c::paramList const & paramList, xmlrpc_c::value * const retvalPtr) { std::string cookie = paramList.getString(0); -std::string enc; paramList.verifyEnd(1); std::map structVal; @@ -158,7 +153,7 @@ if (config->GetAdminInfo(cookie, &adminInfo)) bool hidePassword = !adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd; -user_iter u; +USER_PTR u; int h = users->OpenSearch(); if (!h) @@ -177,7 +172,7 @@ while (1) xmlrpc_c::value info; - USER_HELPER uhelper(u); + USER_HELPER uhelper(u, *users); uhelper.GetUserInfo(&info, hidePassword); @@ -195,7 +190,6 @@ void METHOD_USER_CHG::execute(xmlrpc_c::paramList const & paramList, std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); xmlrpc_c::value_struct info(paramList.getStruct(2)); -std::string enc; paramList.verifyEnd(3); ADMIN_INFO adminInfo; @@ -206,15 +200,15 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN admin; +ADMIN * admin; -if (admins->FindAdmin(adminInfo.admin, &admin)) +if (admins->Find(adminInfo.admin, &admin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -user_iter u; +USER_PTR u; if (users->FindByName(login, &u)) { @@ -222,7 +216,7 @@ if (users->FindByName(login, &u)) return; } -USER_HELPER uhelper(u); +USER_HELPER uhelper(u, *users); if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd) { @@ -248,7 +242,6 @@ std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); double amount = paramList.getDouble(2); std::string comment = IconvString(paramList.getString(3), "UTF-8", "KOI8-R"); -std::string enc; paramList.verifyEnd(4); ADMIN_INFO adminInfo; @@ -259,15 +252,15 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN admin; +ADMIN * admin; -if (admins->FindAdmin(adminInfo.admin, &admin)) +if (admins->Find(adminInfo.admin, &admin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -user_iter u; +USER_PTR u; if (users->FindByName(login, &u)) { @@ -275,10 +268,10 @@ if (users->FindByName(login, &u)) return; } -double cash = u->property.cash.Get(); +double cash = u->GetProperty().cash.Get(); cash += amount; -if (!u->property.cash.Set(cash, admin, login, store, comment)) +if (!u->GetProperty().cash.Set(cash, admin, login, store, comment)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; @@ -298,7 +291,6 @@ std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); double cash = paramList.getDouble(2); std::string comment = IconvString(paramList.getString(3), "UTF-8", "KOI8-R"); -std::string enc; paramList.verifyEnd(4); ADMIN_INFO adminInfo; @@ -309,15 +301,15 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN admin; +ADMIN * admin; -if (admins->FindAdmin(adminInfo.admin, &admin)) +if (admins->Find(adminInfo.admin, &admin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -user_iter u; +USER_PTR u; if (users->FindByName(login, &u)) { @@ -325,7 +317,7 @@ if (users->FindByName(login, &u)) return; } -if (!u->property.cash.Set(cash, admin, login, store, comment)) +if (!u->GetProperty().cash.Set(cash, admin, login, store, comment)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; @@ -346,7 +338,6 @@ std::string login = paramList.getString(1); std::string tariff = paramList.getString(2); bool delayed = paramList.getBoolean(3); std::string comment = IconvString(paramList.getString(4), "UTF-8", "KOI8-R"); -std::string enc; paramList.verifyEnd(5); ADMIN_INFO adminInfo; @@ -357,15 +348,15 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN admin; +ADMIN * admin; -if (admins->FindAdmin(adminInfo.admin, &admin)) +if (admins->Find(adminInfo.admin, &admin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -user_iter u; +USER_PTR u; if (users->FindByName(login, &u)) { @@ -377,10 +368,11 @@ if (tariffs->FindByName(tariff)) { if (delayed) { - if (u->property.nextTariff.Set(tariff, - admin, - login, - store)) + if (u->GetProperty().nextTariff.Set(tariff, + admin, + login, + store, + comment)) { u->WriteConf(); *retvalPtr = xmlrpc_c::value_boolean(true); @@ -389,11 +381,13 @@ if (tariffs->FindByName(tariff)) } else { - if (u->property.tariffName.Set(tariff, - admin, - login, - store)) + if (u->GetProperty().tariffName.Set(tariff, + admin, + login, + store, + comment)) { + u->ResetNextTariff(); u->WriteConf(); *retvalPtr = xmlrpc_c::value_boolean(true); return; @@ -410,14 +404,13 @@ void METHOD_GET_ONLINE_IPS::execute(xmlrpc_c::paramList const & paramList, xmlrpc_c::value * const retvalPtr) { std::string cookie = paramList.getString(0); -std::vector subnetsStr = paramList.getArray(1); +typedef std::vector ValueVector; +ValueVector subnetsStr = paramList.getArray(1); paramList.verifyEnd(2); std::vector subnets; -std::vector::iterator it; - -for (it = subnetsStr.begin(); it != subnetsStr.end(); ++it) +for (ValueVector::const_iterator it(subnetsStr.begin()); it != subnetsStr.end(); ++it) { IP_MASK ipm; if (ParseNet(xmlrpc_c::value_string(*it), ipm)) @@ -440,9 +433,9 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -std::vector ips; +ValueVector ips; -user_iter u; +USER_PTR u; int handle = users->OpenSearch(); if (!handle) @@ -463,8 +456,7 @@ while (1) { uint32_t ip = u->GetCurrIP(); - std::vector::iterator it; - for (it = subnets.begin(); it != subnets.end(); ++it) + for (std::vector::const_iterator it(subnets.begin()); it != subnets.end(); ++it) { if ((it->ip & it->mask) == (ip & it->mask)) { @@ -517,3 +509,36 @@ ipm.mask = htonl(0xffFFffFF << (32 - ipm.mask)); return false; } + +void METHOD_GET_USER_AUTH_BY::execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalPtr) +{ +std::string cookie = paramList.getString(0); +std::string login = paramList.getString(1); +paramList.verifyEnd(2); + +std::map structVal; +ADMIN_INFO adminInfo; + +if (config->GetAdminInfo(cookie, &adminInfo)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(structVal); + return; + } + +USER_PTR u; + +if (users->FindByName(login, &u)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(structVal); + return; + } + +std::vector list(u->GetAuthorizers()); +std::vector authList; +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + authList.push_back(xmlrpc_c::value_string(*it)); +*retvalPtr = xmlrpc_c::value_array(authList); +}