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