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";
60 if (!info.authBy.empty())
62 std::cout << Indent(level) << "auth by:\n";
63 for (size_t i = 0; i < info.authBy.size(); ++i)
64 std::cout << Indent(level + 1, true) << info.authBy[i] << "\n";
68 void SimpleCallback(bool result,
69 const std::string & reason,
74 std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
77 std::cout << "Success.\n";
80 void GetUsersCallback(bool result,
81 const std::string & reason,
82 const std::vector<STG::GET_USER::INFO> & info,
87 std::cerr << "Failed to get user list. Reason: '" << reason << "'." << std::endl;
90 std::cout << "Users:\n";
91 for (size_t i = 0; i < info.size(); ++i)
92 PrintUser(info[i], 1);
95 void GetUserCallback(bool result,
96 const std::string & reason,
97 const STG::GET_USER::INFO & info,
102 std::cerr << "Failed to get user. Reason: '" << reason << "'." << std::endl;
108 } // namespace anonymous
110 bool SGCONF::GetUsersFunction(const SGCONF::CONFIG & config,
111 const std::string & /*arg*/,
112 const std::map<std::string, std::string> & /*options*/)
114 STG::SERVCONF proto(config.server.data(),
116 config.userName.data(),
117 config.userPass.data());
118 return proto.GetUsers(GetUsersCallback, NULL) == STG::st_ok;
121 bool SGCONF::GetUserFunction(const SGCONF::CONFIG & config,
122 const std::string & arg,
123 const std::map<std::string, std::string> & /*options*/)
125 STG::SERVCONF proto(config.server.data(),
127 config.userName.data(),
128 config.userPass.data());
129 return proto.GetUser(arg, GetUserCallback, NULL) == STG::st_ok;
132 bool SGCONF::DelUserFunction(const SGCONF::CONFIG & config,
133 const std::string & arg,
134 const std::map<std::string, std::string> & /*options*/)
136 STG::SERVCONF proto(config.server.data(),
138 config.userName.data(),
139 config.userPass.data());
140 return proto.DelUser(arg, SimpleCallback, NULL) == STG::st_ok;
143 bool SGCONF::AddUserFunction(const SGCONF::CONFIG & config,
144 const std::string & arg,
145 const std::map<std::string, std::string> & /*options*/)
148 std::cerr << "Unimplemented.\n";
152 bool SGCONF::ChgUserFunction(const SGCONF::CONFIG & config,
153 const std::string & arg,
154 const std::map<std::string, std::string> & options)
157 std::cerr << "Unimplemented.\n";
161 bool SGCONF::CheckUserFunction(const SGCONF::CONFIG & config,
162 const std::string & arg,
163 const std::map<std::string, std::string> & options)
166 std::cerr << "Unimplemented.\n";
170 bool SGCONF::SendMessageFunction(const SGCONF::CONFIG & config,
171 const std::string & arg,
172 const std::map<std::string, std::string> & options)
175 std::cerr << "Unimplemented.\n";