5 #include "stg/servconf.h"
6 #include "stg/servconf_types.h"
7 #include "stg/common.h"
14 std::string Indent(size_t level, bool dash = false)
18 return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
21 void PrintUser(const STG::GET_USER::INFO & info, size_t level = 0)
23 std::cout << Indent(level, true) << "login: " << info.login << "\n"
24 << Indent(level) << "password: " << info.password << "\n"
25 << Indent(level) << "cash: " << info.cash << "\n"
26 << Indent(level) << "credit: " << info.credit << "\n"
27 << Indent(level) << "credit expire: " << TimeToString(info.creditExpire) << "\n"
28 << Indent(level) << "last cash add: " << info.lastCashAdd << "\n"
29 << Indent(level) << "last cash add time: " << TimeToString(info.lastCashAddTime) << "\n"
30 << Indent(level) << "prepaid traffic: " << info.prepaidTraff << "\n"
31 << Indent(level) << "disabled: " << (info.disabled ? "t" : "f") << "\n"
32 << Indent(level) << "passive: " << (info.passive ? "t" : "f") << "\n"
33 << Indent(level) << "disabled detail stat: " << (info.disableDetailStat ? "t" : "f") << "\n"
34 << Indent(level) << "connected: " << (info.connected ? "t" : "f") << "\n"
35 << Indent(level) << "always on-line: " << (info.alwaysOnline ? "t" : "f") << "\n"
36 << Indent(level) << "IP: " << inet_ntostring(info.ip) << "\n"
37 << Indent(level) << "IPs: " << info.ips << "\n"
38 << Indent(level) << "tariff: " << info.tariff << "\n"
39 << Indent(level) << "group: " << info.group << "\n"
40 << Indent(level) << "note: " << info.note << "\n"
41 << Indent(level) << "email: " << info.email << "\n"
42 << Indent(level) << "name: " << info.name << "\n"
43 << Indent(level) << "address: " << info.address << "\n"
44 << Indent(level) << "phone: " << info.phone << "\n"
45 << Indent(level) << "free mb: " << info.stat.freeMb << "\n"
46 << Indent(level) << "last ping time: " << TimeToString(info.pingTime) << "\n"
47 << Indent(level) << "last activity time: " << TimeToString(info.lastActivityTime) << "\n"
48 << Indent(level) << "traffic:\n";
49 for (size_t i = 0; i < DIR_NUM; ++i)
51 std::cout << Indent(level + 1, true) << "dir: " << i << "\n"
52 << Indent(level + 1) << "session upload: " << info.stat.su[i] << "\n"
53 << Indent(level + 1) << "session download: " << info.stat.sd[i] << "\n"
54 << Indent(level + 1) << "month upload: " << info.stat.mu[i] << "\n"
55 << Indent(level + 1) << "month download: " << info.stat.md[i] << "\n";
57 std::cout << Indent(level) << "user data:\n";
58 for (size_t i = 0; i < USERDATA_NUM; ++i)
59 std::cout << Indent(level + 1, true) << "user data " << i << ": " << info.userData[i] << "\n";
62 void SimpleCallback(bool result,
63 const std::string & reason,
68 std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
71 std::cout << "Success.\n";
74 void GetUsersCallback(bool result,
75 const std::string & reason,
76 const std::vector<STG::GET_USER::INFO> & info,
81 std::cerr << "Failed to get user list. Reason: '" << reason << "'." << std::endl;
84 std::cout << "Users:\n";
85 for (size_t i = 0; i < info.size(); ++i)
86 PrintUser(info[i], 1);
89 void GetUserCallback(bool result,
90 const std::string & reason,
91 const STG::GET_USER::INFO & info,
96 std::cerr << "Failed to get user. Reason: '" << reason << "'." << std::endl;
102 } // namespace anonymous
104 bool SGCONF::GetUsersFunction(const SGCONF::CONFIG & config,
105 const std::string & /*arg*/,
106 const std::map<std::string, std::string> & /*options*/)
108 STG::SERVCONF proto(config.server.data(),
110 config.userName.data(),
111 config.userPass.data());
112 return proto.GetUsers(GetUsersCallback, NULL) == STG::st_ok;
115 bool SGCONF::GetUserFunction(const SGCONF::CONFIG & config,
116 const std::string & arg,
117 const std::map<std::string, std::string> & /*options*/)
119 STG::SERVCONF proto(config.server.data(),
121 config.userName.data(),
122 config.userPass.data());
123 return proto.GetUser(arg, GetUserCallback, NULL) == STG::st_ok;
126 bool SGCONF::DelUserFunction(const SGCONF::CONFIG & config,
127 const std::string & arg,
128 const std::map<std::string, std::string> & /*options*/)
130 STG::SERVCONF proto(config.server.data(),
132 config.userName.data(),
133 config.userPass.data());
134 return proto.DelUser(arg, SimpleCallback, NULL) == STG::st_ok;
137 bool SGCONF::AddUserFunction(const SGCONF::CONFIG & config,
138 const std::string & arg,
139 const std::map<std::string, std::string> & /*options*/)
142 std::cerr << "Unimplemented.\n";
146 bool SGCONF::ChgUserFunction(const SGCONF::CONFIG & config,
147 const std::string & arg,
148 const std::map<std::string, std::string> & options)
151 std::cerr << "Unimplemented.\n";