]> git.stg.codes - stg.git/blob - projects/sgconf/main.cpp
Fixed version info.
[stg.git] / projects / sgconf / main.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #include "xml.h"
23 #include "admins.h"
24 #include "tariffs.h"
25 #include "users.h"
26 #include "services.h"
27 #include "corps.h"
28
29 #include "options.h"
30 #include "actions.h"
31 #include "config.h"
32
33 #include "stg/servconf.h"
34 #include "stg/user_conf.h"
35 #include "stg/user_stat.h"
36 #include "stg/common.h"
37
38 #include <cerrno>
39 #include <clocale>
40 #include <cstdio>
41 #include <cstdlib>
42 #include <cstring>
43 #include <string>
44 #include <sstream>
45
46 #include <unistd.h>
47 #include <getopt.h>
48 #include <iconv.h>
49 #include <langinfo.h>
50
51 namespace
52 {
53
54 template <typename T>
55 struct ARRAY_TYPE
56 {
57 typedef typename T::value_type type;
58 };
59
60 template <typename T>
61 struct ARRAY_TYPE<T[]>
62 {
63 typedef T type;
64 };
65
66 template <typename T, size_t N>
67 struct ARRAY_TYPE<T[N]>
68 {
69 typedef T type;
70 };
71
72 template <typename T>
73 struct nullary_function
74 {
75 typedef T result_type;
76 };
77
78 template <typename F>
79 class binder0 : public nullary_function<typename F::result_type>
80 {
81     public:
82         binder0(const F & func, const typename F::argument_type & arg)
83             : m_func(func), m_arg(arg) {}
84         typename F::result_type operator()() const { return m_func(m_arg); }
85     private:
86         F m_func;
87         typename F::argument_type m_arg;
88 };
89
90 template <typename F>
91 inline
92 binder0<F> bind0(const F & func, const typename F::argument_type & arg)
93 {
94 return binder0<F>(func, arg);
95 }
96
97 template <typename A, typename R>
98 class FUNC1_ADAPTER : public std::unary_function<A, R>
99 {
100     public:
101         FUNC1_ADAPTER(R (*func)(A)) : m_func(func) {}
102         const R operator()(A arg) const { return (m_func)(arg); }
103     private:
104         R (*m_func)(A);
105 };
106
107 template <typename C, typename A, typename R>
108 class METHOD1_ADAPTER : public std::unary_function<A, R>
109 {
110     public:
111         METHOD1_ADAPTER(R (C::* func)(A), C & obj) : m_func(func), m_obj(obj) {}
112         R operator()(A arg) { return (m_obj.*m_func)(arg); }
113     private:
114         R (C::* m_func)(A);
115         C & m_obj;
116 };
117
118 template <typename C, typename A, typename R>
119 class CONST_METHOD1_ADAPTER : public std::unary_function<A, R>
120 {
121     public:
122         CONST_METHOD1_ADAPTER(R (C::* func)(A) const, C & obj) : m_func(func), m_obj(obj) {}
123         R operator()(A arg) const { return (m_obj.*m_func)(arg); }
124     private:
125         R (C::* m_func)(A) const;
126         C & m_obj;
127 };
128
129 template <typename A, typename R>
130 FUNC1_ADAPTER<A, R> Func1Adapt(R (func)(A))
131 {
132 return FUNC1_ADAPTER<A, R>(func);
133 }
134
135 template <typename C, typename A, typename R>
136 METHOD1_ADAPTER<C, A, R> Method1Adapt(R (C::* func)(A), C & obj)
137 {
138 return METHOD1_ADAPTER<C, A, R>(func, obj);
139 }
140
141 template <typename C, typename A, typename R>
142 CONST_METHOD1_ADAPTER<C, A, R> Method1Adapt(R (C::* func)(A) const, C & obj)
143 {
144 return CONST_METHOD1_ADAPTER<C, A, R>(func, obj);
145 }
146
147 template <typename T>
148 bool SetArrayItem(T & array, const char * index, const typename ARRAY_TYPE<T>::type & value)
149 {
150 size_t pos = 0;
151 if (str2x(index, pos))
152     return false;
153 array[pos] = value;
154 return true;
155 }
156
157 void RawXMLCallback(bool result, const std::string & reason, const std::string & response, void * /*data*/)
158 {
159 if (!result)
160     {
161     std::cerr << "Failed to get raw XML response. Reason: '" << reason << "'." << std::endl;
162     return;
163     }
164 SGCONF::PrintXML(response);
165 }
166
167 void Version(const std::string & self)
168 {
169 std::cout << self << ", version: 2.0.0-alpha.\n";
170 }
171
172 void ReadUserConfigFile(SGCONF::OPTION_BLOCK & block)
173 {
174 std::vector<std::string> paths;
175 const char * configHome = getenv("XDG_CONFIG_HOME");
176 if (configHome == NULL)
177     {
178     const char * home = getenv("HOME");
179     if (home == NULL)
180         return;
181     paths.push_back(std::string(home) + "/.config/sgconf/sgconf.conf");
182     paths.push_back(std::string(home) + "/.sgconf/sgconf.conf");
183     }
184 else
185     paths.push_back(std::string(configHome) + "/sgconf/sgconf.conf");
186 for (std::vector<std::string>::const_iterator it = paths.begin(); it != paths.end(); ++it)
187     if (access(it->c_str(), R_OK) == 0)
188         {
189         block.ParseFile(*it);
190         return;
191         }
192 }
193
194 } // namespace anonymous
195
196 namespace SGCONF
197 {
198
199 class CONFIG_ACTION : public ACTION
200 {
201     public:
202         CONFIG_ACTION(SGCONF::CONFIG & config,
203                       const std::string & paramDescription)
204             : m_config(config),
205               m_description(paramDescription)
206         {}
207
208         virtual ACTION * Clone() const { return new CONFIG_ACTION(*this); }
209
210         virtual std::string ParamDescription() const { return m_description; }
211         virtual std::string DefaultDescription() const { return ""; }
212         virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
213         virtual PARSER_STATE Parse(int argc, char ** argv);
214
215     private:
216         SGCONF::CONFIG & m_config;
217         std::string m_description;
218         OPTION_BLOCK m_suboptions;
219
220         void ParseCredentials(const std::string & credentials);
221         void ParseHostAndPort(const std::string & hostAndPort);
222 };
223
224 typedef bool (* API_FUNCTION) (const SGCONF::CONFIG &,
225                                const std::string &,
226                                const std::map<std::string, std::string> &);
227
228 class COMMAND
229 {
230     public:
231         COMMAND(API_FUNCTION funPtr,
232                 const std::string & arg,
233                 const std::map<std::string, std::string> & options)
234             : m_funPtr(funPtr),
235               m_arg(arg),
236               m_options(options)
237         {}
238         bool Execute(const SGCONF::CONFIG & config) const
239         {
240             return m_funPtr(config, m_arg, m_options);
241         }
242
243     private:
244         API_FUNCTION m_funPtr;
245         std::string m_arg;
246         std::map<std::string, std::string> m_options;
247 };
248
249 class COMMANDS
250 {
251     public:
252         void Add(API_FUNCTION funPtr,
253                  const std::string & arg,
254                  const std::map<std::string, std::string> & options) { m_commands.push_back(COMMAND(funPtr, arg, options)); }
255         bool Execute(const SGCONF::CONFIG & config) const
256         {
257             std::list<COMMAND>::const_iterator it(m_commands.begin());
258             bool res = true;
259             while (it != m_commands.end() && res)
260             {
261                 res = res && it->Execute(config);
262                 ++it;
263             }
264             return res;
265         }
266     private:
267         std::list<COMMAND> m_commands;
268 };
269
270 class API_ACTION : public ACTION
271 {
272     public:
273         API_ACTION(COMMANDS & commands,
274                    const std::string & paramDescription,
275                    bool needArgument,
276                    const OPTION_BLOCK& suboptions,
277                    API_FUNCTION funPtr)
278             : m_commands(commands),
279               m_description(paramDescription),
280               m_argument(needArgument ? "1" : ""), // Hack
281               m_suboptions(suboptions),
282               m_funPtr(funPtr)
283         {}
284         API_ACTION(COMMANDS & commands,
285                    const std::string & paramDescription,
286                    bool needArgument,
287                    API_FUNCTION funPtr)
288             : m_commands(commands),
289               m_description(paramDescription),
290               m_argument(needArgument ? "1" : ""), // Hack
291               m_funPtr(funPtr)
292         {}
293
294         virtual ACTION * Clone() const { return new API_ACTION(*this); }
295
296         virtual std::string ParamDescription() const { return m_description; }
297         virtual std::string DefaultDescription() const { return ""; }
298         virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
299         virtual PARSER_STATE Parse(int argc, char ** argv)
300         {
301         PARSER_STATE state(false, argc, argv);
302         if (!m_argument.empty())
303             {
304             if (argc == 0 ||
305                 argv == NULL ||
306                 *argv == NULL)
307                 throw ERROR("Missing argument.");
308             m_argument = *argv;
309             --state.argc;
310             ++state.argv;
311             }
312         m_suboptions.Parse(state.argc, state.argv);
313         m_commands.Add(m_funPtr, m_argument, m_params);
314         return state;
315         }
316
317     private:
318         COMMANDS & m_commands;
319         std::string m_description;
320         std::string m_argument;
321         OPTION_BLOCK m_suboptions;
322         std::map<std::string, std::string> m_params;
323         API_FUNCTION m_funPtr;
324 };
325
326 PARSER_STATE CONFIG_ACTION::Parse(int argc, char ** argv)
327 {
328 if (argc == 0 ||
329     argv == NULL ||
330     *argv == NULL)
331     throw ERROR("Missing argument.");
332 char * pos = strchr(*argv, '@');
333 if (pos != NULL)
334     {
335     ParseCredentials(std::string(*argv, pos));
336     ParseHostAndPort(std::string(pos + 1));
337     }
338 else
339     {
340     ParseHostAndPort(std::string(*argv));
341     }
342 return PARSER_STATE(false, --argc, ++argv);
343 }
344
345 void CONFIG_ACTION::ParseCredentials(const std::string & credentials)
346 {
347 std::string::size_type pos = credentials.find_first_of(':');
348 if (pos != std::string::npos)
349     {
350     m_config.userName = credentials.substr(0, pos);
351     m_config.userPass = credentials.substr(pos + 1);
352     }
353 else
354     {
355     m_config.userName = credentials;
356     }
357 }
358
359 void CONFIG_ACTION::ParseHostAndPort(const std::string & hostAndPort)
360 {
361 std::string::size_type pos = hostAndPort.find_first_of(':');
362 if (pos != std::string::npos)
363     {
364     m_config.server = hostAndPort.substr(0, pos);
365     uint16_t port = 0;
366     if (str2x(hostAndPort.substr(pos + 1), port))
367         throw ERROR("Invalid port value: '" + hostAndPort.substr(pos + 1) + "'");
368     m_config.port = port;
369     }
370 else
371     {
372     m_config.server = hostAndPort;
373     }
374 }
375
376 inline
377 CONFIG_ACTION * MakeParamAction(SGCONF::CONFIG & config,
378                                 const std::string & paramDescription)
379 {
380 return new CONFIG_ACTION(config, paramDescription);
381 }
382
383 inline
384 ACTION * MakeAPIAction(COMMANDS & commands,
385                        const std::string & paramDescription,
386                        bool needArgument,
387                        API_FUNCTION funPtr)
388 {
389 return new API_ACTION(commands, paramDescription, needArgument, funPtr);
390 }
391
392 inline
393 ACTION * MakeAPIAction(COMMANDS & commands,
394                        API_FUNCTION funPtr)
395 {
396 return new API_ACTION(commands, "", false, funPtr);
397 }
398
399 bool RawXMLFunction(const SGCONF::CONFIG & config,
400                     const std::string & arg,
401                     const std::map<std::string, std::string> & /*options*/)
402 {
403     STG::SERVCONF proto(config.server.data(),
404                         config.port.data(),
405                         config.userName.data(),
406                         config.userPass.data());
407     return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok;
408 }
409
410 } // namespace SGCONF
411
412 time_t stgTime;
413
414 //-----------------------------------------------------------------------------
415 int main(int argc, char **argv)
416 {
417 std::string self(basename(argv[0]));
418 SGCONF::CONFIG config;
419 SGCONF::COMMANDS commands;
420
421 SGCONF::OPTION_BLOCKS blocks;
422 blocks.Add("General options")
423       .Add("c", "config", SGCONF::MakeParamAction(config.configFile, std::string("~/.config/stg/sgconf.conf"), "<config file>"), "override default config file")
424       .Add("h", "help", SGCONF::MakeFunc0Action(bind0(Method1Adapt(&SGCONF::OPTION_BLOCKS::Help, blocks), 0)), "\t\tshow this help and exit")
425       //.Add("help-all", SGCONF::MakeFunc0Action(UsageAll), "\t\tshow full help and exit")
426       .Add("v", "version", SGCONF::MakeFunc0Action(bind0(Func1Adapt(Version), self)), "\t\tshow version information and exit");
427 SGCONF::OPTION_BLOCK & block = blocks.Add("Connection options")
428       .Add("s", "server", SGCONF::MakeParamAction(config.server, std::string("localhost"), "<address>"), "\t\thost to connect")
429       .Add("p", "port", SGCONF::MakeParamAction(config.port, uint16_t(5555), "<port>"), "\t\tport to connect")
430       .Add("u", "username", SGCONF::MakeParamAction(config.userName, std::string("admin"), "<username>"), "\tadministrative login")
431       .Add("w", "userpass", SGCONF::MakeParamAction(config.userPass, "<password>"), "\tpassword for the administrative login")
432       .Add("a", "address", SGCONF::MakeParamAction(config, "<connection string>"), "connection params as a single string in format: <login>:<password>@<host>:<port>");
433 blocks.Add("Raw XML")
434       .Add("r", "raw", SGCONF::MakeAPIAction(commands, "<xml>", true, SGCONF::RawXMLFunction), "\tmake raw XML request");
435 blocks.Add("Admin management options")
436       .Add("get-admins", SGCONF::MakeAPIAction(commands, SGCONF::GetAdminsFunction), "\tget admin list")
437       .Add("get-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::GetAdminFunction), "get admin")
438       .Add("add-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::AddAdminFunction), "add admin")
439       .Add("del-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::DelAdminFunction), "del admin")
440       .Add("chg-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::ChgAdminFunction), "change admin");
441 blocks.Add("Tariff management options")
442       .Add("get-tariffs", SGCONF::MakeAPIAction(commands, SGCONF::GetTariffsFunction), "\tget tariff list")
443       .Add("get-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetTariffFunction), "get tariff")
444       .Add("add-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddTariffFunction), "add tariff")
445       .Add("del-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelTariffFunction), "del tariff")
446       .Add("chg-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgTariffFunction), "change tariff");
447 blocks.Add("User management options")
448       .Add("get-users", SGCONF::MakeAPIAction(commands, SGCONF::GetUsersFunction), "\tget user list")
449       .Add("get-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::GetUserFunction), "get user")
450       .Add("add-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::AddUserFunction), "add user")
451       .Add("del-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::DelUserFunction), "del user")
452       .Add("chg-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::ChgUserFunction), "change user")
453       .Add("check-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::CheckUserFunction), "check user existance and credentials")
454       .Add("send-message", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::SendMessageFunction), "send message");
455 blocks.Add("Service management options")
456       .Add("get-services", SGCONF::MakeAPIAction(commands, SGCONF::GetServicesFunction), "\tget service list")
457       .Add("get-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetServiceFunction), "get service")
458       .Add("add-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddServiceFunction), "add service")
459       .Add("del-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelServiceFunction), "del service")
460       .Add("chg-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgServiceFunction), "change service");
461 blocks.Add("Corporation management options")
462       .Add("get-corps", SGCONF::MakeAPIAction(commands, SGCONF::GetCorpsFunction), "\tget corporation list")
463       .Add("get-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetCorpFunction), "get corporation")
464       .Add("add-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddCorpFunction), "add corporation")
465       .Add("del-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelCorpFunction), "del corporation")
466       .Add("chg-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgCorpFunction), "change corporation");
467
468 SGCONF::PARSER_STATE state(false, argc, argv);
469
470 try
471 {
472 state = blocks.Parse(--argc, ++argv); // Skipping self name
473 }
474 catch (const SGCONF::OPTION::ERROR& ex)
475 {
476 std::cerr << ex.what() << "\n";
477 return -1;
478 }
479
480 if (state.stop)
481     return 0;
482
483 if (state.argc > 0)
484     {
485     std::cerr << "Unknown option: '" << *state.argv << "'\n";
486     return -1;
487     }
488
489 try
490 {
491 SGCONF::CONFIG configOverride(config);
492
493 if (config.configFile.empty())
494     {
495     const char * mainConfigFile = "/etc/sgconf/sgconf.conf";
496     if (access(mainConfigFile, R_OK) == 0)
497         block.ParseFile(mainConfigFile);
498     ReadUserConfigFile(block);
499     }
500 else
501     {
502     block.ParseFile(config.configFile.data());
503     }
504
505 config = configOverride;
506 }
507 catch (const std::exception& ex)
508 {
509 std::cerr << ex.what() << "\n";
510 return -1;
511 }
512
513 std::cerr << "Config: " << config.Serialize() << std::endl;
514 return commands.Execute(config) ? 0 : -1;
515 }
516 //-----------------------------------------------------------------------------
517
518 namespace
519 {
520
521 /*void UsageTariffs(bool full)
522 {
523 std::cout << "Tariffs management options:\n"
524           << "\t--get-tariffs\t\t\t\tget a list of tariffs (subsequent options will define what to show)\n";
525 if (full)
526     std::cout << "\t\t--name\t\t\t\tshow tariff's name\n"
527               << "\t\t--fee\t\t\t\tshow tariff's fee\n"
528               << "\t\t--free\t\t\t\tshow tariff's prepaid traffic in terms of cost\n"
529               << "\t\t--passive-cost\t\t\tshow tariff's cost of \"freeze\"\n"
530               << "\t\t--traff-type\t\t\tshow what type of traffix will be accounted by the tariff\n"
531               << "\t\t--dirs\t\t\t\tshow tarification rules for directions\n\n";
532 std::cout << "\t--get-tariff\t\t\t\tget the information about tariff\n";
533 if (full)
534     std::cout << "\t\t--name <name>\t\t\tname of the tariff to show\n"
535               << "\t\t--fee\t\t\t\tshow tariff's fee\n"
536               << "\t\t--free\t\t\t\tshow tariff's prepaid traffic in terms of cost\n"
537               << "\t\t--passive-cost\t\t\tshow tariff's cost of \"freeze\"\n"
538               << "\t\t--traff-type\t\t\tshow what type of traffix will be accounted by the tariff\n"
539               << "\t\t--dirs\t\t\t\tshow tarification rules for directions\n\n";
540 std::cout << "\t--add-tariff\t\t\t\tadd a new tariff\n";
541 if (full)
542     std::cout << "\t\t--name <name>\t\t\tname of the tariff to add\n"
543               << "\t\t--fee <fee>\t\t\tstariff's fee\n"
544               << "\t\t--free <free>\t\t\ttariff's prepaid traffic in terms of cost\n"
545               << "\t\t--passive-cost <cost>\t\ttariff's cost of \"freeze\"\n"
546               << "\t\t--traff-type <type>\t\twhat type of traffi will be accounted by the tariff\n"
547               << "\t\t--times <times>\t\t\tslash-separated list of \"day\" time-spans (in form \"hh:mm-hh:mm\") for each direction\n"
548               << "\t\t--prices-day-a <prices>\t\tslash-separated list of prices for \"day\" traffic before threshold for each direction\n"
549               << "\t\t--prices-night-a <prices>\tslash-separated list of prices for \"night\" traffic before threshold for each direction\n"
550               << "\t\t--prices-day-b <prices>\t\tslash-separated list of prices for \"day\" traffic after threshold for each direction\n"
551               << "\t\t--prices-night-b <prices>\tslash-separated list of prices for \"night\" traffic after threshold for each direction\n"
552               << "\t\t--single-prices <yes|no>\tslash-separated list of \"single price\" flags for each direction\n"
553               << "\t\t--no-discounts <yes|no>\t\tslash-separated list of \"no discount\" flags for each direction\n"
554               << "\t\t--thresholds <thresholds>\tslash-separated list of thresholds (in Mb) for each direction\n\n";
555 std::cout << "\t--del-tariff\t\t\t\tdelete an existing tariff\n";
556 if (full)
557     std::cout << "\t\t--name <name>\t\t\tname of the tariff to delete\n\n";
558 std::cout << "\t--chg-tariff\t\t\t\tchange an existing tariff\n";
559 if (full)
560     std::cout << "\t\t--name <name>\t\t\tname of the tariff to change\n"
561               << "\t\t--fee <fee>\t\t\tstariff's fee\n"
562               << "\t\t--free <free>\t\t\ttariff's prepaid traffic in terms of cost\n"
563               << "\t\t--passive-cost <cost>\t\ttariff's cost of \"freeze\"\n"
564               << "\t\t--traff-type <type>\t\twhat type of traffix will be accounted by the tariff\n"
565               << "\t\t--dir <N>\t\t\tnumber of direction data to change\n"
566               << "\t\t\t--time <time>\t\t\"day\" time-span (in form \"hh:mm-hh:mm\")\n"
567               << "\t\t\t--price-day-a <price>\tprice for \"day\" traffic before threshold\n"
568               << "\t\t\t--price-night-a <price>\tprice for \"night\" traffic before threshold\n"
569               << "\t\t\t--price-day-b <price>\tprice for \"day\" traffic after threshold\n"
570               << "\t\t\t--price-night-b <price>\tprice for \"night\" traffic after threshold\n"
571               << "\t\t\t--single-price <yes|no>\t\"single price\" flag\n"
572               << "\t\t\t--no-discount <yes|no>\t\"no discount\" flag\n"
573               << "\t\t\t--threshold <threshold>\tthreshold (in Mb)\n\n";
574 }
575 //-----------------------------------------------------------------------------
576 void UsageUsers(bool full)
577 {
578 std::cout << "Users management options:\n"
579           << "\t--get-users\t\t\t\tget a list of users (subsequent options will define what to show)\n";
580 if (full)
581     std::cout << "\n\n";
582 std::cout << "\t--get-user\t\t\t\tget the information about user\n";
583 if (full)
584     std::cout << "\n\n";
585 std::cout << "\t--add-user\t\t\t\tadd a new user\n";
586 if (full)
587     std::cout << "\n\n";
588 std::cout << "\t--del-user\t\t\t\tdelete an existing user\n";
589 if (full)
590     std::cout << "\n\n";
591 std::cout << "\t--chg-user\t\t\t\tchange an existing user\n";
592 if (full)
593     std::cout << "\n\n";
594 std::cout << "\t--check-user\t\t\t\tcheck credentials is valid\n";
595 if (full)
596     std::cout << "\n\n";
597 std::cout << "\t--send-message\t\t\t\tsend a message to a user\n";
598 if (full)
599     std::cout << "\n\n";
600 }
601 //-----------------------------------------------------------------------------
602 void UsageServices(bool full)
603 {
604 std::cout << "Services management options:\n"
605           << "\t--get-services\t\t\t\tget a list of services (subsequent options will define what to show)\n";
606 if (full)
607     std::cout << "\t\t--name\t\t\t\tshow service's name\n"
608               << "\t\t--comment\t\t\tshow a comment to the service\n"
609               << "\t\t--cost\t\t\t\tshow service's cost\n"
610               << "\t\t--pay-day\t\t\tshow service's pay day\n\n";
611 std::cout << "\t--get-service\t\t\t\tget the information about service\n";
612 if (full)
613     std::cout << "\t\t--name <name>\t\t\tname of the service to show\n"
614               << "\t\t--comment\t\t\tshow a comment to the service\n"
615               << "\t\t--cost\t\t\t\tshow service's cost\n"
616               << "\t\t--pay-day\t\t\tshow service's pay day\n\n";
617 std::cout << "\t--add-service\t\t\t\tadd a new service\n";
618 if (full)
619     std::cout << "\t\t--name <name>\t\t\tname of the service to add\n"
620               << "\t\t--comment <comment>\t\ta comment to the service\n"
621               << "\t\t--cost <cost>\t\t\tservice's cost\n"
622               << "\t\t--pay-day <day>\t\t\tservice's pay day\n\n";
623 std::cout << "\t--del-service\t\t\t\tdelete an existing service\n";
624 if (full)
625     std::cout << "\t\t--name <name>\t\t\tname of the service to delete\n\n";
626 std::cout << "\t--chg-service\t\t\t\tchange an existing service\n";
627 if (full)
628     std::cout << "\t\t--name <name>\t\t\tname of the service to change\n"
629               << "\t\t--comment <comment>\t\ta comment to the service\n"
630               << "\t\t--cost <cost>\t\t\tservice's cost\n"
631               << "\t\t--pay-day <day>\t\t\tservice's pay day\n\n";
632 }
633 //-----------------------------------------------------------------------------
634 void UsageCorporations(bool full)
635 {
636 std::cout << "Corporations management options:\n"
637           << "\t--get-corporations\t\t\tget a list of corporations (subsequent options will define what to show)\n";
638 if (full)
639     std::cout << "\t\t--name\t\t\t\tshow corporation's name\n"
640               << "\t\t--cash\t\t\t\tshow corporation's cash\n\n";
641 std::cout << "\t--get-corp\t\t\t\tget the information about corporation\n";
642 if (full)
643     std::cout << "\t\t--name <name>\t\t\tname of the corporation to show\n"
644               << "\t\t--cash\t\t\t\tshow corporation's cash\n\n";
645 std::cout << "\t--add-corp\t\t\t\tadd a new corporation\n";
646 if (full)
647     std::cout << "\t\t--name <name>\t\t\tname of the corporation to add\n"
648               << "\t\t--cash <cash>\t\t\tinitial corporation's cash (default: \"0\")\n\n";
649 std::cout << "\t--del-corp\t\t\t\tdelete an existing corporation\n";
650 if (full)
651     std::cout << "\t\t--name <name>\t\t\tname of the corporation to delete\n\n";
652 std::cout << "\t--chg-corp\t\t\t\tchange an existing corporation\n";
653 if (full)
654     std::cout << "\t\t--name <name>\t\t\tname of the corporation to change\n"
655               << "\t\t--add-cash <amount>[:<message>]\tadd cash to the corporation's account and optional comment message\n"
656               << "\t\t--set-cash <cash>[:<message>]\tnew corporation's cash and optional comment message\n\n";
657 }*/
658
659 } // namespace anonymous