]> git.stg.codes - stg.git/blob - projects/sgconf/main.cpp
Implemented some service and corporation 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 "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 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, "<login>", true, SGCONF::GetUserFunction), "\tget user")
440       .Add("add-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::AddUserFunction), "\tadd user")
441       .Add("del-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::DelUserFunction), "\tdel user")
442       .Add("chg-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::ChgUserFunction), "\tchange user")
443       .Add("check-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::CheckUserFunction), "\tcheck user existance and credentials")
444       .Add("send-message", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::SendMessageFunction), "\tsend message");
445 blocks.Add("Service management options")
446       .Add("get-services", SGCONF::MakeAPIAction(commands, SGCONF::GetServicesFunction), "\tget service list")
447       .Add("get-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetServiceFunction), "\tget service")
448       .Add("add-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddServiceFunction), "\tadd service")
449       .Add("del-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelServiceFunction), "\tdel service")
450       .Add("chg-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgServiceFunction), "\tchange service");
451 blocks.Add("Corporation management options")
452       .Add("get-corps", SGCONF::MakeAPIAction(commands, SGCONF::GetCorpsFunction), "\tget corporation list")
453       .Add("get-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetCorpFunction), "\tget corporation")
454       .Add("add-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddCorpFunction), "\tadd corporation")
455       .Add("del-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelCorpFunction), "\tdel corporation")
456       .Add("chg-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgCorpFunction), "\tchange corporation");
457
458 SGCONF::PARSER_STATE state(false, argc, argv);
459
460 try
461 {
462 state = blocks.Parse(--argc, ++argv); // Skipping self name
463 }
464 catch (const SGCONF::OPTION::ERROR& ex)
465 {
466 std::cerr << ex.what() << "\n";
467 return -1;
468 }
469
470 if (state.stop)
471     return 0;
472
473 if (state.argc > 0)
474     {
475     std::cerr << "Unknown option: '" << *state.argv << "'\n";
476     return -1;
477     }
478
479 try
480 {
481 SGCONF::CONFIG configOverride(config);
482
483 if (config.configFile.empty())
484     {
485     const char * mainConfigFile = "/etc/sgconf/sgconf.conf";
486     if (access(mainConfigFile, R_OK) == 0)
487         block.ParseFile(mainConfigFile);
488     ReadUserConfigFile(block);
489     }
490 else
491     {
492     block.ParseFile(config.configFile.data());
493     }
494
495 config = configOverride;
496 }
497 catch (const std::exception& ex)
498 {
499 std::cerr << ex.what() << "\n";
500 return -1;
501 }
502
503 std::cerr << "Config: " << config.Serialize() << std::endl;
504 return commands.Execute(config) ? 0 : -1;
505
506 /*return 0;
507
508 if (argc < 2)
509     {
510     Usage();
511     return 1;
512     }
513
514 if (argc <= 2)
515     {
516     UsageConf();
517     exit(PARAMETER_PARSING_ERR_CODE);
518     }
519
520 if (strcmp(argv[1], "get") == 0)
521     {
522     //printf("get\n");
523     return mainGet(argc - 1, argv + 1);
524     }
525 else if (strcmp(argv[1], "set") == 0)
526     {
527     //printf("set\n");
528     if (mainSet(argc - 1, argv + 1) )
529         return 0;
530     return -1;
531     }
532 else
533     {
534     UsageConf();
535     exit(PARAMETER_PARSING_ERR_CODE);
536     }
537 return UNKNOWN_ERR_CODE;*/
538 }
539 //-----------------------------------------------------------------------------
540
541 namespace
542 {
543
544 void Usage()
545 {
546 UsageImpl(false);
547 }
548
549 void UsageAll()
550 {
551 UsageImpl(true);
552 }
553
554 void UsageImpl(bool full)
555 {
556 std::cout << "sgconf is the Stargazer management utility.\n\n"
557           << "Usage:\n"
558           << "\tsgconf [options]\n\n"
559           << "General options:\n"
560           << "\t-c, --config <config file>\t\toverride default config file (default: \"~/.config/stg/sgconf.conf\")\n"
561           << "\t-h, --help\t\t\t\tshow this help and exit\n"
562           << "\t--help-all\t\t\t\tshow full help and exit\n"
563           << "\t-v, --version\t\t\t\tshow version information and exit\n\n";
564 UsageConnection();
565 UsageAdmins(full);
566 UsageTariffs(full);
567 UsageUsers(full);
568 UsageServices(full);
569 UsageCorporations(full);
570 }
571 //-----------------------------------------------------------------------------
572 void UsageConnection()
573 {
574 std::cout << "Connection options:\n"
575           << "\t-s, --server <address>\t\t\thost to connect (ip or domain name, default: \"localhost\")\n"
576           << "\t-p, --port <port>\t\t\tport to connect (default: \"5555\")\n"
577           << "\t-u, --username <username>\t\tadministrative login (default: \"admin\")\n"
578           << "\t-w, --userpass <password>\t\tpassword for administrative login\n"
579           << "\t-a, --address <connection string>\tconnection params as a single string in format: <login>:<password>@<host>:<port>\n\n";
580 }
581 //-----------------------------------------------------------------------------
582 void UsageAdmins(bool full)
583 {
584 std::cout << "Admins management options:\n"
585           << "\t--get-admins\t\t\t\tget a list of admins (subsequent options will define what to show)\n";
586 if (full)
587     std::cout << "\t\t--login\t\t\t\tshow admin's login\n"
588               << "\t\t--priv\t\t\t\tshow admin's priviledges\n\n";
589 std::cout << "\t--get-admin\t\t\t\tget the information about admin\n";
590 if (full)
591     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to show\n"
592               << "\t\t--priv\t\t\t\tshow admin's priviledges\n\n";
593 std::cout << "\t--add-admin\t\t\t\tadd a new admin\n";
594 if (full)
595     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to add\n"
596               << "\t\t--password <password>\t\tpassword of the admin to add\n"
597               << "\t\t--priv <priv number>\t\tpriviledges of the admin to add\n\n";
598 std::cout << "\t--del-admin\t\t\t\tdelete an existing admin\n";
599 if (full)
600     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to delete\n\n";
601 std::cout << "\t--chg-admin\t\t\t\tchange an existing admin\n";
602 if (full)
603     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to change\n"
604               << "\t\t--priv <priv number>\t\tnew priviledges\n\n";
605 }
606 //-----------------------------------------------------------------------------
607 void UsageTariffs(bool full)
608 {
609 std::cout << "Tariffs management options:\n"
610           << "\t--get-tariffs\t\t\t\tget a list of tariffs (subsequent options will define what to show)\n";
611 if (full)
612     std::cout << "\t\t--name\t\t\t\tshow tariff's name\n"
613               << "\t\t--fee\t\t\t\tshow tariff's fee\n"
614               << "\t\t--free\t\t\t\tshow tariff's prepaid traffic in terms of cost\n"
615               << "\t\t--passive-cost\t\t\tshow tariff's cost of \"freeze\"\n"
616               << "\t\t--traff-type\t\t\tshow what type of traffix will be accounted by the tariff\n"
617               << "\t\t--dirs\t\t\t\tshow tarification rules for directions\n\n";
618 std::cout << "\t--get-tariff\t\t\t\tget the information about tariff\n";
619 if (full)
620     std::cout << "\t\t--name <name>\t\t\tname of the tariff to show\n"
621               << "\t\t--fee\t\t\t\tshow tariff's fee\n"
622               << "\t\t--free\t\t\t\tshow tariff's prepaid traffic in terms of cost\n"
623               << "\t\t--passive-cost\t\t\tshow tariff's cost of \"freeze\"\n"
624               << "\t\t--traff-type\t\t\tshow what type of traffix will be accounted by the tariff\n"
625               << "\t\t--dirs\t\t\t\tshow tarification rules for directions\n\n";
626 std::cout << "\t--add-tariff\t\t\t\tadd a new tariff\n";
627 if (full)
628     std::cout << "\t\t--name <name>\t\t\tname of the tariff to add\n"
629               << "\t\t--fee <fee>\t\t\tstariff's fee\n"
630               << "\t\t--free <free>\t\t\ttariff's prepaid traffic in terms of cost\n"
631               << "\t\t--passive-cost <cost>\t\ttariff's cost of \"freeze\"\n"
632               << "\t\t--traff-type <type>\t\twhat type of traffi will be accounted by the tariff\n"
633               << "\t\t--times <times>\t\t\tslash-separated list of \"day\" time-spans (in form \"hh:mm-hh:mm\") for each direction\n"
634               << "\t\t--prices-day-a <prices>\t\tslash-separated list of prices for \"day\" traffic before threshold for each direction\n"
635               << "\t\t--prices-night-a <prices>\tslash-separated list of prices for \"night\" traffic before threshold for each direction\n"
636               << "\t\t--prices-day-b <prices>\t\tslash-separated list of prices for \"day\" traffic after threshold for each direction\n"
637               << "\t\t--prices-night-b <prices>\tslash-separated list of prices for \"night\" traffic after threshold for each direction\n"
638               << "\t\t--single-prices <yes|no>\tslash-separated list of \"single price\" flags for each direction\n"
639               << "\t\t--no-discounts <yes|no>\t\tslash-separated list of \"no discount\" flags for each direction\n"
640               << "\t\t--thresholds <thresholds>\tslash-separated list of thresholds (in Mb) for each direction\n\n";
641 std::cout << "\t--del-tariff\t\t\t\tdelete an existing tariff\n";
642 if (full)
643     std::cout << "\t\t--name <name>\t\t\tname of the tariff to delete\n\n";
644 std::cout << "\t--chg-tariff\t\t\t\tchange an existing tariff\n";
645 if (full)
646     std::cout << "\t\t--name <name>\t\t\tname of the tariff to change\n"
647               << "\t\t--fee <fee>\t\t\tstariff's fee\n"
648               << "\t\t--free <free>\t\t\ttariff's prepaid traffic in terms of cost\n"
649               << "\t\t--passive-cost <cost>\t\ttariff's cost of \"freeze\"\n"
650               << "\t\t--traff-type <type>\t\twhat type of traffix will be accounted by the tariff\n"
651               << "\t\t--dir <N>\t\t\tnumber of direction data to change\n"
652               << "\t\t\t--time <time>\t\t\"day\" time-span (in form \"hh:mm-hh:mm\")\n"
653               << "\t\t\t--price-day-a <price>\tprice for \"day\" traffic before threshold\n"
654               << "\t\t\t--price-night-a <price>\tprice for \"night\" traffic before threshold\n"
655               << "\t\t\t--price-day-b <price>\tprice for \"day\" traffic after threshold\n"
656               << "\t\t\t--price-night-b <price>\tprice for \"night\" traffic after threshold\n"
657               << "\t\t\t--single-price <yes|no>\t\"single price\" flag\n"
658               << "\t\t\t--no-discount <yes|no>\t\"no discount\" flag\n"
659               << "\t\t\t--threshold <threshold>\tthreshold (in Mb)\n\n";
660 }
661 //-----------------------------------------------------------------------------
662 void UsageUsers(bool full)
663 {
664 std::cout << "Users management options:\n"
665           << "\t--get-users\t\t\t\tget a list of users (subsequent options will define what to show)\n";
666 if (full)
667     std::cout << "\n\n";
668 std::cout << "\t--get-user\t\t\t\tget the information about user\n";
669 if (full)
670     std::cout << "\n\n";
671 std::cout << "\t--add-user\t\t\t\tadd a new user\n";
672 if (full)
673     std::cout << "\n\n";
674 std::cout << "\t--del-user\t\t\t\tdelete an existing user\n";
675 if (full)
676     std::cout << "\n\n";
677 std::cout << "\t--chg-user\t\t\t\tchange an existing user\n";
678 if (full)
679     std::cout << "\n\n";
680 std::cout << "\t--check-user\t\t\t\tcheck credentials is valid\n";
681 if (full)
682     std::cout << "\n\n";
683 std::cout << "\t--send-message\t\t\t\tsend a message to a user\n";
684 if (full)
685     std::cout << "\n\n";
686 }
687 //-----------------------------------------------------------------------------
688 void UsageServices(bool full)
689 {
690 std::cout << "Services management options:\n"
691           << "\t--get-services\t\t\t\tget a list of services (subsequent options will define what to show)\n";
692 if (full)
693     std::cout << "\t\t--name\t\t\t\tshow service's name\n"
694               << "\t\t--comment\t\t\tshow a comment to the service\n"
695               << "\t\t--cost\t\t\t\tshow service's cost\n"
696               << "\t\t--pay-day\t\t\tshow service's pay day\n\n";
697 std::cout << "\t--get-service\t\t\t\tget the information about service\n";
698 if (full)
699     std::cout << "\t\t--name <name>\t\t\tname of the service to show\n"
700               << "\t\t--comment\t\t\tshow a comment to the service\n"
701               << "\t\t--cost\t\t\t\tshow service's cost\n"
702               << "\t\t--pay-day\t\t\tshow service's pay day\n\n";
703 std::cout << "\t--add-service\t\t\t\tadd a new service\n";
704 if (full)
705     std::cout << "\t\t--name <name>\t\t\tname of the service to add\n"
706               << "\t\t--comment <comment>\t\ta comment to the service\n"
707               << "\t\t--cost <cost>\t\t\tservice's cost\n"
708               << "\t\t--pay-day <day>\t\t\tservice's pay day\n\n";
709 std::cout << "\t--del-service\t\t\t\tdelete an existing service\n";
710 if (full)
711     std::cout << "\t\t--name <name>\t\t\tname of the service to delete\n\n";
712 std::cout << "\t--chg-service\t\t\t\tchange an existing service\n";
713 if (full)
714     std::cout << "\t\t--name <name>\t\t\tname of the service to change\n"
715               << "\t\t--comment <comment>\t\ta comment to the service\n"
716               << "\t\t--cost <cost>\t\t\tservice's cost\n"
717               << "\t\t--pay-day <day>\t\t\tservice's pay day\n\n";
718 }
719 //-----------------------------------------------------------------------------
720 void UsageCorporations(bool full)
721 {
722 std::cout << "Corporations management options:\n"
723           << "\t--get-corporations\t\t\tget a list of corporations (subsequent options will define what to show)\n";
724 if (full)
725     std::cout << "\t\t--name\t\t\t\tshow corporation's name\n"
726               << "\t\t--cash\t\t\t\tshow corporation's cash\n\n";
727 std::cout << "\t--get-corp\t\t\t\tget the information about corporation\n";
728 if (full)
729     std::cout << "\t\t--name <name>\t\t\tname of the corporation to show\n"
730               << "\t\t--cash\t\t\t\tshow corporation's cash\n\n";
731 std::cout << "\t--add-corp\t\t\t\tadd a new corporation\n";
732 if (full)
733     std::cout << "\t\t--name <name>\t\t\tname of the corporation to add\n"
734               << "\t\t--cash <cash>\t\t\tinitial corporation's cash (default: \"0\")\n\n";
735 std::cout << "\t--del-corp\t\t\t\tdelete an existing corporation\n";
736 if (full)
737     std::cout << "\t\t--name <name>\t\t\tname of the corporation to delete\n\n";
738 std::cout << "\t--chg-corp\t\t\t\tchange an existing corporation\n";
739 if (full)
740     std::cout << "\t\t--name <name>\t\t\tname of the corporation to change\n"
741               << "\t\t--add-cash <amount>[:<message>]\tadd cash to the corporation's account and optional comment message\n"
742               << "\t\t--set-cash <cash>[:<message>]\tnew corporation's cash and optional comment message\n\n";
743 }
744
745 void Version()
746 {
747 std::cout << "sgconf, version: 2.0.0-alpha.\n";
748 }
749
750 } // namespace anonymous