X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d3b6a58593b94c9ff41c30a7517086d607f28f10..669bf62b01b121a3c9fc5092cd9d2ab3392fd92c:/projects/sgconf/admins.cpp diff --git a/projects/sgconf/admins.cpp b/projects/sgconf/admins.cpp index b560f581..7161e1ef 100644 --- a/projects/sgconf/admins.cpp +++ b/projects/sgconf/admins.cpp @@ -3,6 +3,7 @@ #include "api_action.h" #include "options.h" #include "config.h" +#include "utils.h" #include "stg/servconf.h" #include "stg/servconf_types.h" @@ -46,10 +47,28 @@ std::cout << Indent(level, true) << "login: " << info.login << "\n" std::vector GetAdminParams() { std::vector params; -params.push_back({"priv", "", "priviledges"}); +params.push_back(SGCONF::API_ACTION::PARAM("password", "", "password")); +params.push_back(SGCONF::API_ACTION::PARAM("priv", "", "priviledges")); return params; } +void ConvPriv(const std::string & value, RESETABLE & res) +{ +if (value.length() != 9) + throw SGCONF::ACTION::ERROR("Priviledges value should be a 9-digits length binary number."); +PRIV priv; +priv.corpChg = (value[0] == '0' ? 0 : 1); +priv.serviceChg = (value[1] == '0' ? 0 : 1); +priv.tariffChg = (value[2] == '0' ? 0 : 1); +priv.adminChg = (value[3] == '0' ? 0 : 1); +priv.userAddDel = (value[4] == '0' ? 0 : 1); +priv.userPasswd = (value[5] == '0' ? 0 : 1); +priv.userCash = (value[6] == '0' ? 0 : 1); +priv.userConf = (value[7] == '0' ? 0 : 1); +priv.userStat = (value[8] == '0' ? 0 : 1); +res = priv; +} + void SimpleCallback(bool result, const std::string & reason, void * /*data*/) @@ -133,20 +152,32 @@ return proto.DelAdmin(arg, SimpleCallback, NULL) == STG::st_ok; bool AddAdminFunction(const SGCONF::CONFIG & config, const std::string & arg, - const std::map & /*options*/) + const std::map & options) { -// TODO -std::cerr << "Unimplemented.\n"; -return false; +ADMIN_CONF_RES conf; +conf.login = arg; +SGCONF::MaybeSet(options, "priv", conf.priv, ConvPriv); +SGCONF::MaybeSet(options, "password", conf.password); +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.userName.data(), + config.userPass.data()); +return proto.AddAdmin(arg, conf, SimpleCallback, NULL) == STG::st_ok; } bool ChgAdminFunction(const SGCONF::CONFIG & config, const std::string & arg, const std::map & options) { -// TODO -std::cerr << "Unimplemented.\n"; -return false; +ADMIN_CONF_RES conf; +conf.login = arg; +SGCONF::MaybeSet(options, "priv", conf.priv, ConvPriv); +SGCONF::MaybeSet(options, "password", conf.password); +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.userName.data(), + config.userPass.data()); +return proto.ChgAdmin(conf, SimpleCallback, NULL) == STG::st_ok; } } // namespace anonymous