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.lastCash << "\n"
29 << Indent(level) << "prepaid traffic: " << info.prepaidTraff << "\n"
30 << Indent(level) << "disabled: " << (info.down ? "t" : "f") << "\n"
31 << Indent(level) << "passive: " << (info.passive ? "t" : "f") << "\n"
32 << Indent(level) << "disabled detail stat: " << (info.disableDetailStat ? "t" : "f") << "\n"
33 << Indent(level) << "connected: " << (info.connected ? "t" : "f") << "\n"
34 << Indent(level) << "always on-line: " << (info.alwaysOnline ? "t" : "f") << "\n"
35 << Indent(level) << "IP: " << inet_ntostring(info.ip) << "\n"
36 << Indent(level) << "IPs: " << info.ips << "\n"
37 << Indent(level) << "tariff: " << info.tariff << "\n"
38 << Indent(level) << "group: " << info.group << "\n"
39 << Indent(level) << "note: " << info.note << "\n"
40 << Indent(level) << "email: " << info.email << "\n"
41 << Indent(level) << "name: " << info.name << "\n"
42 << Indent(level) << "address: " << info.address << "\n"
43 << Indent(level) << "phone: " << info.phone << "\n"
44 << Indent(level) << "free mb: " << info.stat.freeMb << "\n"
45 << Indent(level) << "traffic:\n";
46 for (size_t i = 0; i < DIR_NUM; ++i)
48 std::cout << Indent(level + 1, true) << "dir: " << i << "\n"
49 << Indent(level + 1) << "session upload: " << info.stat.su[i] << "\n"
50 << Indent(level + 1) << "session download: " << info.stat.sd[i] << "\n"
51 << Indent(level + 1) << "month upload: " << info.stat.mu[i] << "\n"
52 << Indent(level + 1) << "month download: " << info.stat.md[i] << "\n";
54 std::cout << Indent(level) << "user data:\n";
55 for (size_t i = 0; i < USERDATA_NUM; ++i)
56 std::cout << Indent(level + 1, true) << "user data " << i << ": " << info.userData[i] << "\n";
59 void SimpleCallback(bool result,
60 const std::string & reason,
65 std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
68 std::cout << "Success.\n";
71 void GetUsersCallback(bool result,
72 const std::string & reason,
73 const std::vector<STG::GET_USER::INFO> & info,
78 std::cerr << "Failed to get user list. Reason: '" << reason << "'." << std::endl;
81 std::cout << "Users:\n";
82 for (size_t i = 0; i < info.size(); ++i)
83 PrintUser(info[i], 1);
86 void GetUserCallback(bool result,
87 const std::string & reason,
88 const STG::GET_USER::INFO & info,
93 std::cerr << "Failed to get user. Reason: '" << reason << "'." << std::endl;
99 } // namespace anonymous
101 bool SGCONF::GetUsersFunction(const SGCONF::CONFIG & config,
102 const std::string & /*arg*/,
103 const std::map<std::string, std::string> & /*options*/)
105 STG::SERVCONF proto(config.server.data(),
107 config.userName.data(),
108 config.userPass.data());
109 return proto.GetUsers(GetUsersCallback, NULL) == STG::st_ok;
112 bool SGCONF::GetUserFunction(const SGCONF::CONFIG & config,
113 const std::string & arg,
114 const std::map<std::string, std::string> & /*options*/)
116 STG::SERVCONF proto(config.server.data(),
118 config.userName.data(),
119 config.userPass.data());
120 return proto.GetUser(arg, GetUserCallback, NULL) == STG::st_ok;
123 bool SGCONF::DelUserFunction(const SGCONF::CONFIG & config,
124 const std::string & arg,
125 const std::map<std::string, std::string> & /*options*/)
127 STG::SERVCONF proto(config.server.data(),
129 config.userName.data(),
130 config.userPass.data());
131 return proto.DelUser(arg, SimpleCallback, NULL) == STG::st_ok;
134 bool SGCONF::AddUserFunction(const SGCONF::CONFIG & config,
135 const std::string & arg,
136 const std::map<std::string, std::string> & /*options*/)
139 std::cerr << "Unimplemented.\n";
143 bool SGCONF::ChgUserFunction(const SGCONF::CONFIG & config,
144 const std::string & arg,
145 const std::map<std::string, std::string> & options)
148 std::cerr << "Unimplemented.\n";