-#include "users_methods.h"
+#include <cerrno>
+
+#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"
//------------------------------------------------------------------------------
{
std::string cookie = paramList.getString(0);
std::string login = paramList.getString(1);
-std::string enc;
paramList.verifyEnd(2);
std::map<std::string, xmlrpc_c::value> structVal;
return;
}
-user_iter u;
+USER_PTR u;
if (users->FindByName(login, &u))
{
return;
}
-USER_HELPER uhelper(u);
+USER_HELPER uhelper(u, *users);
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
{
std::string cookie = paramList.getString(0);
std::string login = paramList.getString(1);
-std::string enc;
paramList.verifyEnd(2);
ADMIN_INFO 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))
{
{
std::string cookie = paramList.getString(0);
std::string login = paramList.getString(1);
-std::string enc;
paramList.verifyEnd(2);
ADMIN_INFO 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);
xmlrpc_c::value * const retvalPtr)
{
std::string cookie = paramList.getString(0);
-std::string enc;
paramList.verifyEnd(1);
std::map<std::string, xmlrpc_c::value> structVal;
bool hidePassword = !adminInfo.priviledges.userConf ||
!adminInfo.priviledges.userPasswd;
-user_iter u;
+USER_PTR u;
int h = users->OpenSearch();
if (!h)
xmlrpc_c::value info;
- USER_HELPER uhelper(u);
+ USER_HELPER uhelper(u, *users);
uhelper.GetUserInfo(&info, hidePassword);
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;
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))
{
return;
}
-USER_HELPER uhelper(u);
+USER_HELPER uhelper(u, *users);
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
- uhelper.SetUserInfo(info, admin, login, *store);
+ uhelper.SetUserInfo(info, admin, login, *store, tariffs);
}
else
{
- uhelper.SetUserInfo(info, admin, login, *store);
+ uhelper.SetUserInfo(info, admin, login, *store, tariffs);
}
u->WriteConf();
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;
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))
{
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;
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;
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))
{
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;
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;
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 (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);
return;
}
}
- if (u->property.tariffName.Set(tariff,
- admin,
- login,
- store))
+ else
{
- u->WriteConf();
- *retvalPtr = xmlrpc_c::value_boolean(true);
- return;
+ if (u->GetProperty().tariffName.Set(tariff,
+ admin,
+ login,
+ store,
+ comment))
+ {
+ u->ResetNextTariff();
+ u->WriteConf();
+ *retvalPtr = xmlrpc_c::value_boolean(true);
+ return;
+ }
}
}
xmlrpc_c::value * const retvalPtr)
{
std::string cookie = paramList.getString(0);
-std::vector<xmlrpc_c::value> subnetsStr = paramList.getArray(1);
+typedef std::vector<xmlrpc_c::value> ValueVector;
+ValueVector subnetsStr = paramList.getArray(1);
paramList.verifyEnd(2);
std::vector<IP_MASK> subnets;
-std::vector<xmlrpc_c::value>::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))
return;
}
-std::vector<xmlrpc_c::value> ips;
+ValueVector ips;
-user_iter u;
+USER_PTR u;
int handle = users->OpenSearch();
if (!handle)
{
uint32_t ip = u->GetCurrIP();
- std::vector<IP_MASK>::iterator it;
- for (it = subnets.begin(); it != subnets.end(); ++it)
+ for (std::vector<IP_MASK>::const_iterator it(subnets.begin()); it != subnets.end(); ++it)
{
if ((it->ip & it->mask) == (ip & it->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<std::string, xmlrpc_c::value> 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<std::string> list(u->GetAuthorizers());
+std::vector<xmlrpc_c::value> authList;
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+ authList.push_back(xmlrpc_c::value_string(*it));
+*retvalPtr = xmlrpc_c::value_array(authList);
+}