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