]> git.stg.codes - stg.git/blob - projects/sgconf/main.cpp
Merge branch 'master' of gitorious.org:stg/stg
[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 "options.h"
27 #include "actions.h"
28 #include "config.h"
29
30 #include "stg/user_conf.h"
31 #include "stg/user_stat.h"
32 #include "stg/common.h"
33
34 #include <cerrno>
35 #include <clocale>
36 #include <cstdio>
37 #include <cstdlib>
38 #include <cstring>
39 #include <string>
40 #include <sstream>
41
42 #include <unistd.h>
43 #include <getopt.h>
44 #include <iconv.h>
45 #include <langinfo.h>
46
47 namespace
48 {
49
50 template <typename T>
51 struct ARRAY_TYPE
52 {
53 typedef typename T::value_type type;
54 };
55
56 template <typename T>
57 struct ARRAY_TYPE<T[]>
58 {
59 typedef T type;
60 };
61
62 template <typename T, size_t N>
63 struct ARRAY_TYPE<T[N]>
64 {
65 typedef T type;
66 };
67
68 template <typename T>
69 struct nullary_function
70 {
71 typedef T result_type;
72 };
73
74 template <typename F>
75 class binder0 : public nullary_function<typename F::result_type>
76 {
77     public:
78         binder0(const F & func, const typename F::argument_type & arg)
79             : m_func(func), m_arg(arg) {}
80         typename F::result_type operator()() const { return m_func(m_arg); }
81     private:
82         F m_func;
83         typename F::argument_type m_arg;
84 };
85
86 template <typename F>
87 inline
88 binder0<F> bind0(const F & func, const typename F::argument_type & arg)
89 {
90 return binder0<F>(func, arg);
91 }
92
93 template <typename C, typename A, typename R>
94 class METHOD1_ADAPTER : public std::unary_function<A, R>
95 {
96     public:
97         METHOD1_ADAPTER(R (C::* func)(A), C & obj) : m_func(func), m_obj(obj) {}
98         R operator()(A arg) { return (m_obj.*m_func)(arg); }
99     private:
100         R (C::* m_func)(A);
101         C & m_obj;
102 };
103
104 template <typename C, typename A, typename R>
105 class CONST_METHOD1_ADAPTER : public std::unary_function<A, R>
106 {
107     public:
108         CONST_METHOD1_ADAPTER(R (C::* func)(A) const, C & obj) : m_func(func), m_obj(obj) {}
109         R operator()(A arg) const { return (m_obj.*m_func)(arg); }
110     private:
111         R (C::* m_func)(A) const;
112         C & m_obj;
113 };
114
115 template <typename C, typename A, typename R>
116 METHOD1_ADAPTER<C, A, R> Method1Adapt(R (C::* func)(A), C & obj)
117 {
118 return METHOD1_ADAPTER<C, A, R>(func, obj);
119 }
120
121 template <typename C, typename A, typename R>
122 CONST_METHOD1_ADAPTER<C, A, R> Method1Adapt(R (C::* func)(A) const, C & obj)
123 {
124 return CONST_METHOD1_ADAPTER<C, A, R>(func, obj);
125 }
126
127 template <typename T>
128 bool SetArrayItem(T & array, const char * index, const typename ARRAY_TYPE<T>::type & value)
129 {
130 size_t pos = 0;
131 if (str2x(index, pos))
132     return false;
133 array[pos] = value;
134 return true;
135 }
136
137 void Usage();
138 void UsageAll();
139 void UsageImpl(bool full);
140 void UsageConnection();
141 void UsageAdmins(bool full);
142 void UsageTariffs(bool full);
143 void UsageUsers(bool full);
144 void UsageServices(bool full);
145 void UsageCorporations(bool full);
146
147 void Version();
148
149 } // namespace anonymous
150
151 namespace SGCONF
152 {
153
154 class CONFIG_ACTION : public ACTION
155 {
156     public:
157         CONFIG_ACTION(CONFIG & config,
158                       const std::string & paramDescription)
159             : m_config(config),
160               m_description(paramDescription)
161         {}
162
163         virtual ACTION * Clone() const { return new CONFIG_ACTION(*this); }
164
165         virtual std::string ParamDescription() const { return m_description; }
166         virtual std::string DefaultDescription() const { return ""; }
167         virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
168         virtual PARSER_STATE Parse(int argc, char ** argv);
169
170     private:
171         CONFIG & m_config;
172         std::string m_description;
173         OPTION_BLOCK m_suboptions;
174
175         void ParseCredentials(const std::string & credentials);
176         void ParseHostAndPort(const std::string & hostAndPort);
177 };
178
179 PARSER_STATE CONFIG_ACTION::Parse(int argc, char ** argv)
180 {
181 if (argc == 0 ||
182     argv == NULL ||
183     *argv == NULL)
184     throw ERROR("Missing argument.");
185 char * pos = strchr(*argv, '@');
186 if (pos != NULL)
187     {
188     ParseCredentials(std::string(*argv, pos));
189     ParseHostAndPort(std::string(pos + 1));
190     }
191 else
192     {
193     ParseHostAndPort(std::string(*argv));
194     }
195 return PARSER_STATE(false, --argc, ++argv);
196 }
197
198 void CONFIG_ACTION::ParseCredentials(const std::string & credentials)
199 {
200 std::string::size_type pos = credentials.find_first_of(':');
201 if (pos != std::string::npos)
202     {
203     m_config.userName = credentials.substr(0, pos);
204     m_config.userPass = credentials.substr(pos + 1);
205     }
206 else
207     {
208     m_config.userName = credentials;
209     }
210 }
211
212 void CONFIG_ACTION::ParseHostAndPort(const std::string & hostAndPort)
213 {
214 std::string::size_type pos = hostAndPort.find_first_of(':');
215 if (pos != std::string::npos)
216     {
217     m_config.server = hostAndPort.substr(0, pos);
218     uint16_t port = 0;
219     if (str2x(hostAndPort.substr(pos + 1), port))
220         throw ERROR("Invalid port value: '" + hostAndPort.substr(pos + 1) + "'");
221     m_config.port = port;
222     }
223 else
224     {
225     m_config.server = hostAndPort;
226     }
227 }
228
229 inline
230 CONFIG_ACTION * MakeParamAction(CONFIG & config,
231                                 const std::string & paramDescription)
232 {
233 return new CONFIG_ACTION(config, paramDescription);
234 }
235
236 } // namespace SGCONF
237
238 time_t stgTime;
239
240 struct option long_options_get[] = {
241 {"server",      1, 0, 's'},  //Server
242 {"port",        1, 0, 'p'},  //Port
243 {"admin",       1, 0, 'a'},  //Admin
244 {"admin_pass",  1, 0, 'w'},  //passWord
245 {"user",        1, 0, 'u'},  //User
246 {"addcash",     0, 0, 'c'},  //Add Cash
247 //{"setcash",     0, 0, 'v'},  //Set Cash
248 {"credit",      0, 0, 'r'},  //cRedit
249 {"tariff",      0, 0, 't'},  //Tariff
250 {"message",     0, 0, 'm'},  //message
251 {"password",    0, 0, 'o'},  //password
252 {"down",        0, 0, 'd'},  //down
253 {"passive",     0, 0, 'i'},  //passive
254 {"disable-stat",0, 0, 'S'},  //disable detail stat
255 {"always-online",0, 0, 'O'}, //always online
256 {"session-upload",   1, 0, 500},  //SU0
257 {"session-download", 1, 0, 501},  //SD0
258 {"month-upload",     1, 0, 502},  //MU0
259 {"month-download",   1, 0, 503},  //MD0
260
261 {"user-data",   1, 0, 700},  //UserData0
262
263 {"prepaid",     0, 0, 'e'},  //prepaid traff
264 {"create",      0, 0, 'n'},  //create
265 {"delete",      0, 0, 'l'},  //delete
266
267 {"note",        0, 0, 'N'},  //Note
268 {"name",        0, 0, 'A'},  //nAme
269 {"address",     0, 0, 'D'},  //aDdress
270 {"email",       0, 0, 'L'},  //emaiL
271 {"phone",       0, 0, 'P'},  //phone
272 {"group",       0, 0, 'G'},  //Group
273 {"ip",          0, 0, 'I'},  //IP-address of user
274 {"authorized-by",0, 0, 800}, //always online
275
276 {0, 0, 0, 0}};
277
278 struct option long_options_set[] = {
279 {"server",      1, 0, 's'},  //Server
280 {"port",        1, 0, 'p'},  //Port
281 {"admin",       1, 0, 'a'},  //Admin
282 {"admin_pass",  1, 0, 'w'},  //passWord
283 {"user",        1, 0, 'u'},  //User
284 {"addcash",     1, 0, 'c'},  //Add Cash
285 {"setcash",     1, 0, 'v'},  //Set Cash
286 {"credit",      1, 0, 'r'},  //cRedit
287 {"tariff",      1, 0, 't'},  //Tariff
288 {"message",     1, 0, 'm'},  //message
289 {"password",    1, 0, 'o'},  //password
290 {"down",        1, 0, 'd'},  //down
291 {"passive",     1, 0, 'i'},  //passive
292 {"disable-stat",1, 0, 'S'},  //disable detail stat
293 {"always-online",1, 0, 'O'},  //always online
294 {"session-upload",   1, 0, 500},  //U0
295 {"session-download", 1, 0, 501},  //U1
296 {"month-upload",     1, 0, 502},  //U2
297 {"month-download",   1, 0, 503},  //U3
298
299 {"user-data",        1, 0, 700},  //UserData
300
301 {"prepaid",     1, 0, 'e'},  //prepaid traff
302 {"create",      1, 0, 'n'},  //create
303 {"delete",      1, 0, 'l'},  //delete
304
305 {"note",        1, 0, 'N'},  //Note
306 {"name",        1, 0, 'A'},  //nAme
307 {"address",     1, 0, 'D'},  //aDdress
308 {"email",       1, 0, 'L'},  //emaiL
309 {"phone",       1, 0, 'P'},  //phone
310 {"group",       1, 0, 'G'},  //Group
311 {"ip",          0, 0, 'I'},  //IP-address of user
312
313 {0, 0, 0, 0}};
314
315 //-----------------------------------------------------------------------------
316 CASH_INFO ParseCash(const char * str)
317 {
318 //-c 123.45:log message
319 std::string cashString;
320 std::string message;
321 const char * pos = strchr(str, ':');
322 if (pos != NULL)
323     {
324     cashString.append(str, pos);
325     message.append(pos + 1);
326     }
327 else
328     cashString = str;
329
330 double cash = 0;
331 if (strtodouble2(cashString, cash) != 0)
332     {
333     printf("Incorrect cash value %s\n", str);
334     exit(PARAMETER_PARSING_ERR_CODE);
335     }
336
337 return CASH_INFO(cash, message);
338 }
339 //-----------------------------------------------------------------------------
340 double ParseCredit(const char * c)
341 {
342 double credit;
343 if (strtodouble2(c, credit) != 0)
344     {
345     printf("Incorrect credit value %s\n", c);
346     exit(PARAMETER_PARSING_ERR_CODE);
347     }
348
349 return credit;
350 }
351 //-----------------------------------------------------------------------------
352 double ParsePrepaidTraffic(const char * c)
353 {
354 double credit;
355 if (strtodouble2(c, credit) != 0)
356     {
357     printf("Incorrect prepaid traffic value %s\n", c);
358     exit(PARAMETER_PARSING_ERR_CODE);
359     }
360
361 return credit;
362 }
363 //-----------------------------------------------------------------------------
364 int64_t ParseTraff(const char * c)
365 {
366 int64_t traff;
367 if (str2x(c, traff) != 0)
368     {
369     printf("Incorrect credit value %s\n", c);
370     exit(PARAMETER_PARSING_ERR_CODE);
371     }
372
373 return traff;
374 }
375 //-----------------------------------------------------------------------------
376 bool ParseDownPassive(const char * dp)
377 {
378 if (!(dp[1] == 0 && (dp[0] == '1' || dp[0] == '0')))
379     {
380     printf("Incorrect value %s\n", dp);
381     exit(PARAMETER_PARSING_ERR_CODE);
382     }
383
384 return dp[0] - '0';
385 }
386 //-----------------------------------------------------------------------------
387 void ParseTariff(const char * str, RESETABLE<std::string> & tariffName, RESETABLE<std::string> & nextTariff)
388 {
389 const char * pos = strchr(str, ':');
390 if (pos != NULL)
391     {
392     std::string tariff(str, pos);
393     if (strcmp(pos + 1, "now") == 0)
394         tariffName = tariff;
395     else if (strcmp(pos + 1, "delayed") == 0)
396         nextTariff = tariff;
397     else
398         {
399         printf("Incorrect tariff value '%s'. Should be '<tariff>', '<tariff>:now' or '<tariff>:delayed'.\n", str);
400         exit(PARAMETER_PARSING_ERR_CODE);
401         }
402     }
403 else
404     tariffName = str;
405 }
406 //-----------------------------------------------------------------------------
407 time_t ParseCreditExpire(const char * str)
408 {
409 struct tm brokenTime;
410
411 brokenTime.tm_wday = 0;
412 brokenTime.tm_yday = 0;
413 brokenTime.tm_isdst = 0;
414 brokenTime.tm_hour = 0;
415 brokenTime.tm_min = 0;
416 brokenTime.tm_sec = 0;
417
418 stg_strptime(str, "%Y-%m-%d", &brokenTime);
419
420 return stg_timegm(&brokenTime);
421 }
422 //-----------------------------------------------------------------------------
423 void ParseAnyString(const char * c, string * msg, const char * enc)
424 {
425 iconv_t cd;
426 char * ob = new char[strlen(c) + 1];
427 char * ib = new char[strlen(c) + 1];
428
429 strcpy(ib, c);
430
431 char * outbuf = ob;
432 char * inbuf = ib;
433
434 setlocale(LC_ALL, "");
435
436 char charsetF[255];
437 strncpy(charsetF, nl_langinfo(CODESET), 255);
438
439 const char * charsetT = enc;
440
441 size_t nconv = 1;
442
443 size_t insize = strlen(ib);
444 size_t outsize = strlen(ib);
445
446 insize = strlen(c);
447
448 cd = iconv_open(charsetT, charsetF);
449 if (cd == (iconv_t) -1)
450     {
451     if (errno == EINVAL)
452         {
453         printf("Warning: iconv from %s to %s failed\n", charsetF, charsetT);
454         *msg = c;
455         return;
456         }
457     else
458         printf("error iconv_open\n");
459
460     exit(ICONV_ERR_CODE);
461     }
462
463 #if defined(FREE_BSD) || defined(FREE_BSD5)
464 nconv = iconv (cd, (const char**)&inbuf, &insize, &outbuf, &outsize);
465 #else
466 nconv = iconv (cd, &inbuf, &insize, &outbuf, &outsize);
467 #endif
468 //printf("nconv=%d outsize=%d\n", nconv, outsize);
469 if (nconv == (size_t) -1)
470     {
471     if (errno != EINVAL)
472         {
473         printf("iconv error\n");
474         exit(ICONV_ERR_CODE);
475         }
476     }
477
478 *outbuf = L'\0';
479
480 iconv_close(cd);
481 *msg = ob;
482
483 delete[] ob;
484 delete[] ib;
485 }
486 //-----------------------------------------------------------------------------
487 void CreateRequestSet(REQUEST * req, char * r)
488 {
489 const int strLen = 10024;
490 char str[strLen];
491 memset(str, 0, strLen);
492
493 r[0] = 0;
494
495 if (!req->usrMsg.empty())
496     {
497     string msg;
498     Encode12str(msg, req->usrMsg.data());
499     sprintf(str, "<Message login=\"%s\" msgver=\"1\" msgtype=\"1\" repeat=\"0\" repeatperiod=\"0\" showtime=\"0\" text=\"%s\"/>", req->login.const_data().c_str(), msg.c_str());
500     //sprintf(str, "<message login=\"%s\" priority=\"0\" text=\"%s\"/>\n", req->login, msg);
501     strcat(r, str);
502     return;
503     }
504
505 if (req->deleteUser)
506     {
507     sprintf(str, "<DelUser login=\"%s\"/>", req->login.const_data().c_str());
508     strcat(r, str);
509     //printf("%s\n", r);
510     return;
511     }
512
513 if (req->createUser)
514     {
515     sprintf(str, "<AddUser> <login value=\"%s\"/> </AddUser>", req->login.const_data().c_str());
516     strcat(r, str);
517     //printf("%s\n", r);
518     return;
519     }
520
521 strcat(r, "<SetUser>\n");
522 sprintf(str, "<login value=\"%s\"/>\n", req->login.const_data().c_str());
523 strcat(r, str);
524 if (!req->credit.empty())
525     {
526     sprintf(str, "<credit value=\"%f\"/>\n", req->credit.const_data());
527     strcat(r, str);
528     }
529
530 if (!req->creditExpire.empty())
531     {
532     sprintf(str, "<creditExpire value=\"%ld\"/>\n", req->creditExpire.const_data());
533     strcat(r, str);
534     }
535
536 if (!req->prepaidTraff.empty())
537     {
538     sprintf(str, "<FreeMb value=\"%f\"/>\n", req->prepaidTraff.const_data());
539     strcat(r, str);
540     }
541
542 if (!req->cash.empty())
543     {
544     string msg;
545     Encode12str(msg, req->message);
546     sprintf(str, "<cash add=\"%f\" msg=\"%s\"/>\n", req->cash.const_data(), msg.c_str());
547     strcat(r, str);
548     }
549
550 if (!req->setCash.empty())
551     {
552     string msg;
553     Encode12str(msg, req->message);
554     sprintf(str, "<cash set=\"%f\" msg=\"%s\"/>\n", req->setCash.const_data(), msg.c_str());
555     strcat(r, str);
556     }
557
558 if (!req->usrPasswd.empty())
559     {
560     sprintf(str, "<password value=\"%s\" />\n", req->usrPasswd.const_data().c_str());
561     strcat(r, str);
562     }
563
564 if (!req->down.empty())
565     {
566     sprintf(str, "<down value=\"%d\" />\n", req->down.const_data());
567     strcat(r, str);
568     }
569
570 if (!req->passive.empty())
571     {
572     sprintf(str, "<passive value=\"%d\" />\n", req->passive.const_data());
573     strcat(r, str);
574     }
575
576 if (!req->disableDetailStat.empty())
577     {
578     sprintf(str, "<disableDetailStat value=\"%d\" />\n", req->disableDetailStat.const_data());
579     strcat(r, str);
580     }
581
582 if (!req->alwaysOnline.empty())
583     {
584     sprintf(str, "<aonline value=\"%d\" />\n", req->alwaysOnline.const_data());
585     strcat(r, str);
586     }
587
588 // IP-address of user
589 if (!req->ips.empty())
590     {
591     sprintf(str, "<ip value=\"%s\" />\n", req->ips.const_data().c_str());
592     strcat(r, str);
593     }
594
595 int uPresent = false;
596 int dPresent = false;
597 for (int i = 0; i < DIR_NUM; i++)
598     {
599     if (!req->monthUpload[i].empty())
600         {
601         if (!uPresent && !dPresent)
602             {
603             sprintf(str, "<traff ");
604             strcat(r, str);
605             uPresent = true;
606             }
607
608         stringstream ss;
609         ss << req->monthUpload[i].const_data();
610         //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data());
611         sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str());
612         strcat(r, str);
613         }
614     if (!req->monthDownload[i].empty())
615         {
616         if (!uPresent && !dPresent)
617             {
618             sprintf(str, "<traff ");
619             strcat(r, str);
620             dPresent = true;
621             }
622
623         stringstream ss;
624         ss << req->monthDownload[i].const_data();
625         sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str());
626         strcat(r, str);
627         }
628     if (!req->sessionUpload[i].empty())
629         {
630         if (!uPresent && !dPresent)
631             {
632             sprintf(str, "<traff ");
633             strcat(r, str);
634             uPresent = true;
635             }
636
637         stringstream ss;
638         ss << req->sessionUpload[i].const_data();
639         //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data());
640         sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str());
641         strcat(r, str);
642         }
643     if (!req->sessionDownload[i].empty())
644         {
645         if (!uPresent && !dPresent)
646             {
647             sprintf(str, "<traff ");
648             strcat(r, str);
649             dPresent = true;
650             }
651
652         stringstream ss;
653         ss << req->sessionDownload[i].const_data();
654         sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str());
655         strcat(r, str);
656         }
657     }
658 if (uPresent || dPresent)
659     {
660     strcat(r, "/>");
661     }
662
663 //printf("%s\n", r);
664
665 if (!req->tariff.empty())
666     {
667     switch (req->chgTariff)
668         {
669         case TARIFF_NOW:
670             sprintf(str, "<tariff now=\"%s\"/>\n", req->tariff.const_data().c_str());
671             strcat(r, str);
672             break;
673         case TARIFF_REC:
674             sprintf(str, "<tariff recalc=\"%s\"/>\n", req->tariff.const_data().c_str());
675             strcat(r, str);
676             break;
677         case TARIFF_DEL:
678             sprintf(str, "<tariff delayed=\"%s\"/>\n", req->tariff.const_data().c_str());
679             strcat(r, str);
680             break;
681         }
682
683     }
684
685 if (!req->note.empty())
686     {
687     string note;
688     Encode12str(note, req->note.data());
689     sprintf(str, "<note value=\"%s\"/>", note.c_str());
690     strcat(r, str);
691     }
692
693 if (!req->name.empty())
694     {
695     string name;
696     Encode12str(name, req->name.data());
697     sprintf(str, "<name value=\"%s\"/>", name.c_str());
698     strcat(r, str);
699     }
700
701 if (!req->address.empty())
702     {
703     string address;
704     Encode12str(address, req->address.data());
705     sprintf(str, "<address value=\"%s\"/>", address.c_str());
706     strcat(r, str);
707     }
708
709 if (!req->email.empty())
710     {
711     string email;
712     Encode12str(email, req->email.data());
713     sprintf(str, "<email value=\"%s\"/>", email.c_str());
714     strcat(r, str);
715     }
716
717 if (!req->phone.empty())
718     {
719     string phone;
720     Encode12str(phone, req->phone.data());
721     sprintf(str, "<phone value=\"%s\"/>", phone.c_str());
722     strcat(r, str);
723     }
724
725 if (!req->group.empty())
726     {
727     string group;
728     Encode12str(group, req->group.data());
729     sprintf(str, "<group value=\"%s\"/>", group.c_str());
730     strcat(r, str);
731     }
732
733 for (int i = 0; i < USERDATA_NUM; i++)
734     {
735     if (!req->userData[i].empty())
736         {
737         string ud;
738         Encode12str(ud, req->userData[i].data());
739         sprintf(str, "<userdata%d value=\"%s\"/>", i, ud.c_str());
740         strcat(r, str);
741         }
742     }
743
744 strcat(r, "</SetUser>\n");
745 }
746 //-----------------------------------------------------------------------------
747 int CheckParameters(REQUEST * req)
748 {
749 bool su = false;
750 bool sd = false;
751 bool mu = false;
752 bool md = false;
753 bool ud = false;
754 bool a = !req->admLogin.empty()
755     && !req->admPasswd.empty()
756     && !req->server.empty()
757     && !req->port.empty()
758     && !req->login.empty();
759
760 bool b = !req->cash.empty()
761     || !req->setCash.empty()
762     || !req->credit.empty()
763     || !req->prepaidTraff.empty()
764     || !req->tariff.empty()
765     || !req->usrMsg.empty()
766     || !req->usrPasswd.empty()
767
768     || !req->note.empty()
769     || !req->name.empty()
770     || !req->address.empty()
771     || !req->email.empty()
772     || !req->phone.empty()
773     || !req->group.empty()
774     || !req->ips.empty() // IP-address of user
775
776     || !req->createUser
777     || !req->deleteUser;
778
779
780 for (int i = 0; i < DIR_NUM; i++)
781     {
782     if (req->sessionUpload[i].empty())
783         {
784         su = true;
785         break;
786         }
787     }
788
789 for (int i = 0; i < DIR_NUM; i++)
790     {
791     if (req->sessionDownload[i].empty())
792         {
793         sd = true;
794         break;
795         }
796     }
797
798 for (int i = 0; i < DIR_NUM; i++)
799     {
800     if (req->monthUpload[i].empty())
801         {
802         mu = true;
803         break;
804         }
805     }
806
807 for (int i = 0; i < DIR_NUM; i++)
808     {
809     if (req->monthDownload[i].empty())
810         {
811         md = true;
812         break;
813         }
814     }
815
816 for (int i = 0; i < DIR_NUM; i++)
817     {
818     if (req->userData[i].empty())
819         {
820         ud = true;
821         break;
822         }
823     }
824
825
826 //printf("a=%d, b=%d, u=%d, d=%d ud=%d\n", a, b, u, d, ud);
827 return a && (b || su || sd || mu || md || ud);
828 }
829 //-----------------------------------------------------------------------------
830 int CheckParametersGet(REQUEST * req)
831 {
832 return CheckParameters(req);
833 }
834 //-----------------------------------------------------------------------------
835 int CheckParametersSet(REQUEST * req)
836 {
837 return CheckParameters(req);
838 }
839 //-----------------------------------------------------------------------------
840 bool mainGet(int argc, char **argv)
841 {
842 int c;
843 REQUEST req;
844 RESETABLE<string>   t1;
845 int missedOptionArg = false;
846
847 const char * short_options_get = "s:p:a:w:u:crtmodieNADLPGISOE";
848 int option_index = -1;
849
850 while (1)
851     {
852     option_index = -1;
853     c = getopt_long(argc, argv, short_options_get, long_options_get, &option_index);
854     if (c == -1)
855         break;
856
857     switch (c)
858         {
859         case 's': //server
860             req.server = optarg;
861             break;
862
863         case 'p': //port
864             req.port = ParseServerPort(optarg);
865             //req.portReq = 1;
866             break;
867
868         case 'a': //admin
869             req.admLogin = ParseAdminLogin(optarg);
870             break;
871
872         case 'w': //admin password
873             req.admPasswd = ParsePassword(optarg);
874             break;
875
876         case 'o': //change user password
877             req.usrPasswd = " ";
878             break;
879
880         case 'u': //user
881             req.login = ParseUser(optarg);
882             break;
883
884         case 'c': //get cash
885             req.cash = 1;
886             break;
887
888         case 'r': //credit
889             req.credit = 1;
890             break;
891
892         case 'E': //credit expire
893             req.creditExpire = 1;
894             break;
895
896         case 'd': //down
897             req.down = 1;
898             break;
899
900         case 'i': //passive
901             req.passive = 1;
902             break;
903
904         case 't': //tariff
905             req.tariff = " ";
906             break;
907
908         case 'e': //Prepaid Traffic
909             req.prepaidTraff = 1;
910             break;
911
912         case 'N': //Note
913             req.note = " ";
914             break;
915
916         case 'A': //nAme
917             req.name = " ";
918             break;
919
920         case 'D': //aDdress
921             req.address =" ";
922             break;
923
924         case 'L': //emaiL
925             req.email = " ";
926             break;
927
928         case 'P': //phone
929             req.phone = " ";
930             break;
931
932         case 'G': //Group
933             req.group = " ";
934             break;
935
936         case 'I': //IP-address of user
937             req.ips = " ";
938             break;
939
940         case 'S': //Detail stat status
941             req.disableDetailStat = " ";
942             break;
943
944         case 'O': //Always online status
945             req.alwaysOnline = " ";
946             break;
947
948         case 500: //U
949             SetArrayItem(req.sessionUpload, optarg, 1);
950             //req.sessionUpload[optarg] = 1;
951             break;
952         case 501:
953             SetArrayItem(req.sessionDownload, optarg, 1);
954             //req.sessionDownload[optarg] = 1;
955             break;
956         case 502:
957             SetArrayItem(req.monthUpload, optarg, 1);
958             //req.monthUpload[optarg] = 1;
959             break;
960         case 503:
961             SetArrayItem(req.monthDownload, optarg, 1);
962             //req.monthDownload[optarg] = 1;
963             break;
964
965         case 700: //UserData
966             SetArrayItem(req.userData, optarg, std::string(" "));
967             //req.userData[optarg] = " ";
968             break;
969
970         case 800:
971             req.authBy = true;
972             break;
973
974         case '?':
975         case ':':
976             missedOptionArg = true;
977             break;
978
979         default:
980             printf ("?? getopt returned character code 0%o ??\n", c);
981         }
982     }
983
984 if (optind < argc)
985     {
986     printf ("non-option ARGV-elements: ");
987     while (optind < argc)
988         printf ("%s ", argv[optind++]);
989     UsageInfo();
990     exit(PARAMETER_PARSING_ERR_CODE);
991     }
992
993 if (missedOptionArg || !CheckParametersGet(&req))
994     {
995     //printf("Parameter needed\n");
996     UsageInfo();
997     exit(PARAMETER_PARSING_ERR_CODE);
998     }
999
1000 if (req.authBy)
1001     return ProcessAuthBy(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), req.login.data());
1002 else
1003     return ProcessGetUser(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), req.login.data(), req);
1004 }
1005 //-----------------------------------------------------------------------------
1006 bool mainSet(int argc, char **argv)
1007 {
1008 string str;
1009
1010 int c;
1011 bool isMessage = false;
1012 REQUEST req;
1013
1014 RESETABLE<string>   t1;
1015
1016 const char * short_options_set = "s:p:a:w:u:c:r:t:m:o:d:i:e:v:nlN:A:D:L:P:G:I:S:O:E:";
1017
1018 int missedOptionArg = false;
1019
1020 USER_CONF_RES conf;
1021 USER_STAT_RES stat;
1022 while (1)
1023     {
1024     int option_index = -1;
1025
1026     c = getopt_long(argc, argv, short_options_set, long_options_set, &option_index);
1027
1028     if (c == -1)
1029         break;
1030
1031     switch (c)
1032         {
1033         case 's': //server
1034             req.server = optarg;
1035             break;
1036
1037         case 'p': //port
1038             req.port = ParseServerPort(optarg);
1039             //req.portReq = 1;
1040             break;
1041
1042         case 'a': //admin
1043             req.admLogin = ParseAdminLogin(optarg);
1044             break;
1045
1046         case 'w': //admin password
1047             req.admPasswd = ParsePassword(optarg);
1048             break;
1049
1050         case 'o': //change user password
1051             conf.password = ParsePassword(optarg);
1052             break;
1053
1054         case 'u': //user
1055             req.login = ParseUser(optarg);
1056             break;
1057
1058         case 'c': //add cash
1059             stat.cashAdd = ParseCash(optarg);
1060             break;
1061
1062         case 'v': //set cash
1063             stat.cashSet = ParseCash(optarg);
1064             break;
1065
1066         case 'r': //credit
1067             conf.credit = ParseCredit(optarg);
1068             break;
1069
1070         case 'E': //credit expire
1071             conf.creditExpire = ParseCreditExpire(optarg);
1072             break;
1073
1074         case 'd': //down
1075             conf.disabled = ParseDownPassive(optarg);
1076             break;
1077
1078         case 'i': //passive
1079             conf.passive = ParseDownPassive(optarg);
1080             break;
1081
1082         case 't': //tariff
1083             ParseTariff(optarg, conf.tariffName, conf.nextTariff);
1084             break;
1085
1086         case 'm': //message
1087             ParseAnyString(optarg, &str);
1088             req.usrMsg = str;
1089             isMessage = true;
1090             break;
1091
1092         case 'e': //Prepaid Traffic
1093             stat.freeMb = ParsePrepaidTraffic(optarg);
1094             break;
1095
1096         case 'n': //Create User
1097             req.createUser = true;
1098             break;
1099
1100         case 'l': //Delete User
1101             req.deleteUser = true;
1102             break;
1103
1104         case 'N': //Note
1105             ParseAnyString(optarg, &str, "koi8-ru");
1106             conf.note = str;
1107             break;
1108
1109         case 'A': //nAme
1110             ParseAnyString(optarg, &str, "koi8-ru");
1111             conf.realName = str;
1112             break;
1113
1114         case 'D': //aDdress
1115             ParseAnyString(optarg, &str, "koi8-ru");
1116             conf.address = str;
1117             break;
1118
1119         case 'L': //emaiL
1120             ParseAnyString(optarg, &str, "koi8-ru");
1121             conf.email = str;
1122             break;
1123
1124         case 'P': //phone
1125             ParseAnyString(optarg, &str);
1126             conf.phone = str;
1127             break;
1128
1129         case 'G': //Group
1130             ParseAnyString(optarg, &str, "koi8-ru");
1131             conf.group = str;
1132             break;
1133
1134         case 'I': //IP-address of user
1135             ParseAnyString(optarg, &str);
1136             conf.ips = StrToIPS(str);
1137             break;
1138
1139         case 'S':
1140             conf.disabledDetailStat = ParseDownPassive(optarg);
1141             break;
1142
1143         case 'O':
1144             conf.alwaysOnline = ParseDownPassive(optarg);
1145             break;
1146
1147         case 500: //U
1148             SetArrayItem(stat.sessionUp, optarg, ParseTraff(argv[optind++]));
1149             break;
1150         case 501:
1151             SetArrayItem(stat.sessionDown, optarg, ParseTraff(argv[optind++]));
1152             break;
1153         case 502:
1154             SetArrayItem(stat.monthUp, optarg, ParseTraff(argv[optind++]));
1155             break;
1156         case 503:
1157             SetArrayItem(stat.monthDown, optarg, ParseTraff(argv[optind++]));
1158             break;
1159
1160         case 700: //UserData
1161             ParseAnyString(argv[optind++], &str);
1162             SetArrayItem(conf.userdata, optarg, str);
1163             break;
1164
1165         case '?':
1166             missedOptionArg = true;
1167             break;
1168
1169         case ':':
1170             missedOptionArg = true;
1171             break;
1172
1173         default:
1174             printf("?? getopt returned character code 0%o ??\n", c);
1175         }
1176     }
1177
1178 if (optind < argc)
1179     {
1180     printf ("non-option ARGV-elements: ");
1181     while (optind < argc)
1182         printf ("%s ", argv[optind++]);
1183     UsageConf();
1184     exit(PARAMETER_PARSING_ERR_CODE);
1185     }
1186
1187 if (missedOptionArg || !CheckParametersSet(&req))
1188     {
1189     //printf("Parameter needed\n");
1190     UsageConf();
1191     exit(PARAMETER_PARSING_ERR_CODE);
1192     }
1193
1194 const int rLen = 20000;
1195 char rstr[rLen];
1196 memset(rstr, 0, rLen);
1197
1198 if (isMessage)
1199     return ProcessSendMessage(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), req.login.data(), req.usrMsg.data());
1200
1201 return ProcessSetUser(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), req.login.data(), conf, stat);
1202 }
1203 //-----------------------------------------------------------------------------
1204 int main(int argc, char **argv)
1205 {
1206 SGCONF::CONFIG config;
1207
1208 SGCONF::OPTION_BLOCKS blocks;
1209 blocks.Add("General options")
1210       .Add("c", "config", SGCONF::MakeParamAction(config.configFile, std::string("~/.config/stg/sgconf.conf"), "<config file>"), "override default config file")
1211       .Add("h", "help", SGCONF::MakeFunc0Action(bind0(Method1Adapt(&SGCONF::OPTION_BLOCKS::Help, blocks), 0)), "\t\tshow this help and exit")
1212       .Add("help-all", SGCONF::MakeFunc0Action(UsageAll), "\t\tshow full help and exit")
1213       .Add("v", "version", SGCONF::MakeFunc0Action(Version), "\t\tshow version information and exit");
1214 blocks.Add("Connection options")
1215       .Add("s", "server", SGCONF::MakeParamAction(config.server, std::string("localhost"), "<address>"), "\t\thost to connect")
1216       .Add("p", "port", SGCONF::MakeParamAction(config.port, uint16_t(5555), "<port>"), "\t\tport to connect")
1217       .Add("u", "username", SGCONF::MakeParamAction(config.userName, std::string("admin"), "<username>"), "\tadministrative login")
1218       .Add("w", "userpass", SGCONF::MakeParamAction(config.userPass, "<password>"), "\tpassword for the administrative login")
1219       .Add("a", "address", SGCONF::MakeParamAction(config, "<connection string>"), "connection params as a single string in format: <login>:<password>@<host>:<port>");
1220
1221
1222 SGCONF::PARSER_STATE state(false, argc, argv);
1223
1224 try
1225 {
1226 state = blocks.Parse(--argc, ++argv); // Skipping self name
1227 }
1228 catch (const SGCONF::OPTION::ERROR& ex)
1229 {
1230 std::cerr << ex.what() << "\n";
1231 return -1;
1232 }
1233
1234 if (state.stop)
1235     return 0;
1236
1237 if (state.argc > 0)
1238     {
1239     std::cerr << "Unknown option: '" << *state.argv << "'\n";
1240     return -1;
1241     }
1242
1243 return 0;
1244
1245 if (argc < 2)
1246     {
1247     Usage();
1248     return 1;
1249     }
1250
1251 if (argc <= 2)
1252     {
1253     UsageConf();
1254     exit(PARAMETER_PARSING_ERR_CODE);
1255     }
1256
1257 if (strcmp(argv[1], "get") == 0)
1258     {
1259     //printf("get\n");
1260     return mainGet(argc - 1, argv + 1);
1261     }
1262 else if (strcmp(argv[1], "set") == 0)
1263     {
1264     //printf("set\n");
1265     if (mainSet(argc - 1, argv + 1) )
1266         return 0;
1267     return -1;
1268     }
1269 else
1270     {
1271     UsageConf();
1272     exit(PARAMETER_PARSING_ERR_CODE);
1273     }
1274 return UNKNOWN_ERR_CODE;
1275 }
1276 //-----------------------------------------------------------------------------
1277
1278 namespace
1279 {
1280
1281 void Usage()
1282 {
1283 UsageImpl(false);
1284 }
1285
1286 void UsageAll()
1287 {
1288 UsageImpl(true);
1289 }
1290
1291 void UsageImpl(bool full)
1292 {
1293 std::cout << "sgconf is the Stargazer management utility.\n\n"
1294           << "Usage:\n"
1295           << "\tsgconf [options]\n\n"
1296           << "General options:\n"
1297           << "\t-c, --config <config file>\t\toverride default config file (default: \"~/.config/stg/sgconf.conf\")\n"
1298           << "\t-h, --help\t\t\t\tshow this help and exit\n"
1299           << "\t--help-all\t\t\t\tshow full help and exit\n"
1300           << "\t-v, --version\t\t\t\tshow version information and exit\n\n";
1301 UsageConnection();
1302 UsageAdmins(full);
1303 UsageTariffs(full);
1304 UsageUsers(full);
1305 UsageServices(full);
1306 UsageCorporations(full);
1307 }
1308 //-----------------------------------------------------------------------------
1309 void UsageConnection()
1310 {
1311 std::cout << "Connection options:\n"
1312           << "\t-s, --server <address>\t\t\thost to connect (ip or domain name, default: \"localhost\")\n"
1313           << "\t-p, --port <port>\t\t\tport to connect (default: \"5555\")\n"
1314           << "\t-u, --username <username>\t\tadministrative login (default: \"admin\")\n"
1315           << "\t-w, --userpass <password>\t\tpassword for administrative login\n"
1316           << "\t-a, --address <connection string>\tconnection params as a single string in format: <login>:<password>@<host>:<port>\n\n";
1317 }
1318 //-----------------------------------------------------------------------------
1319 void UsageAdmins(bool full)
1320 {
1321 std::cout << "Admins management options:\n"
1322           << "\t--get-admins\t\t\t\tget a list of admins (subsequent options will define what to show)\n";
1323 if (full)
1324     std::cout << "\t\t--login\t\t\t\tshow admin's login\n"
1325               << "\t\t--priv\t\t\t\tshow admin's priviledges\n\n";
1326 std::cout << "\t--get-admin\t\t\t\tget the information about admin\n";
1327 if (full)
1328     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to show\n"
1329               << "\t\t--priv\t\t\t\tshow admin's priviledges\n\n";
1330 std::cout << "\t--add-admin\t\t\t\tadd a new admin\n";
1331 if (full)
1332     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to add\n"
1333               << "\t\t--password <password>\t\tpassword of the admin to add\n"
1334               << "\t\t--priv <priv number>\t\tpriviledges of the admin to add\n\n";
1335 std::cout << "\t--del-admin\t\t\t\tdelete an existing admin\n";
1336 if (full)
1337     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to delete\n\n";
1338 std::cout << "\t--chg-admin\t\t\t\tchange an existing admin\n";
1339 if (full)
1340     std::cout << "\t\t--login <login>\t\t\tlogin of the admin to change\n"
1341               << "\t\t--priv <priv number>\t\tnew priviledges\n\n";
1342 }
1343 //-----------------------------------------------------------------------------
1344 void UsageTariffs(bool full)
1345 {
1346 std::cout << "Tariffs management options:\n"
1347           << "\t--get-tariffs\t\t\t\tget a list of tariffs (subsequent options will define what to show)\n";
1348 if (full)
1349     std::cout << "\t\t--name\t\t\t\tshow tariff's name\n"
1350               << "\t\t--fee\t\t\t\tshow tariff's fee\n"
1351               << "\t\t--free\t\t\t\tshow tariff's prepaid traffic in terms of cost\n"
1352               << "\t\t--passive-cost\t\t\tshow tariff's cost of \"freeze\"\n"
1353               << "\t\t--traff-type\t\t\tshow what type of traffix will be accounted by the tariff\n"
1354               << "\t\t--dirs\t\t\t\tshow tarification rules for directions\n\n";
1355 std::cout << "\t--get-tariff\t\t\t\tget the information about tariff\n";
1356 if (full)
1357     std::cout << "\t\t--name <name>\t\t\tname of the tariff to show\n"
1358               << "\t\t--fee\t\t\t\tshow tariff's fee\n"
1359               << "\t\t--free\t\t\t\tshow tariff's prepaid traffic in terms of cost\n"
1360               << "\t\t--passive-cost\t\t\tshow tariff's cost of \"freeze\"\n"
1361               << "\t\t--traff-type\t\t\tshow what type of traffix will be accounted by the tariff\n"
1362               << "\t\t--dirs\t\t\t\tshow tarification rules for directions\n\n";
1363 std::cout << "\t--add-tariff\t\t\t\tadd a new tariff\n";
1364 if (full)
1365     std::cout << "\t\t--name <name>\t\t\tname of the tariff to add\n"
1366               << "\t\t--fee <fee>\t\t\tstariff's fee\n"
1367               << "\t\t--free <free>\t\t\ttariff's prepaid traffic in terms of cost\n"
1368               << "\t\t--passive-cost <cost>\t\ttariff's cost of \"freeze\"\n"
1369               << "\t\t--traff-type <type>\t\twhat type of traffi will be accounted by the tariff\n"
1370               << "\t\t--times <times>\t\t\tslash-separated list of \"day\" time-spans (in form \"hh:mm-hh:mm\") for each direction\n"
1371               << "\t\t--prices-day-a <prices>\t\tslash-separated list of prices for \"day\" traffic before threshold for each direction\n"
1372               << "\t\t--prices-night-a <prices>\tslash-separated list of prices for \"night\" traffic before threshold for each direction\n"
1373               << "\t\t--prices-day-b <prices>\t\tslash-separated list of prices for \"day\" traffic after threshold for each direction\n"
1374               << "\t\t--prices-night-b <prices>\tslash-separated list of prices for \"night\" traffic after threshold for each direction\n"
1375               << "\t\t--single-prices <yes|no>\tslash-separated list of \"single price\" flags for each direction\n"
1376               << "\t\t--no-discounts <yes|no>\t\tslash-separated list of \"no discount\" flags for each direction\n"
1377               << "\t\t--thresholds <thresholds>\tslash-separated list of thresholds (in Mb) for each direction\n\n";
1378 std::cout << "\t--del-tariff\t\t\t\tdelete an existing tariff\n";
1379 if (full)
1380     std::cout << "\t\t--name <name>\t\t\tname of the tariff to delete\n\n";
1381 std::cout << "\t--chg-tariff\t\t\t\tchange an existing tariff\n";
1382 if (full)
1383     std::cout << "\t\t--name <name>\t\t\tname of the tariff to change\n"
1384               << "\t\t--fee <fee>\t\t\tstariff's fee\n"
1385               << "\t\t--free <free>\t\t\ttariff's prepaid traffic in terms of cost\n"
1386               << "\t\t--passive-cost <cost>\t\ttariff's cost of \"freeze\"\n"
1387               << "\t\t--traff-type <type>\t\twhat type of traffix will be accounted by the tariff\n"
1388               << "\t\t--dir <N>\t\t\tnumber of direction data to change\n"
1389               << "\t\t\t--time <time>\t\t\"day\" time-span (in form \"hh:mm-hh:mm\")\n"
1390               << "\t\t\t--price-day-a <price>\tprice for \"day\" traffic before threshold\n"
1391               << "\t\t\t--price-night-a <price>\tprice for \"night\" traffic before threshold\n"
1392               << "\t\t\t--price-day-b <price>\tprice for \"day\" traffic after threshold\n"
1393               << "\t\t\t--price-night-b <price>\tprice for \"night\" traffic after threshold\n"
1394               << "\t\t\t--single-price <yes|no>\t\"single price\" flag\n"
1395               << "\t\t\t--no-discount <yes|no>\t\"no discount\" flag\n"
1396               << "\t\t\t--threshold <threshold>\tthreshold (in Mb)\n\n";
1397 }
1398 //-----------------------------------------------------------------------------
1399 void UsageUsers(bool full)
1400 {
1401 std::cout << "Users management options:\n"
1402           << "\t--get-users\t\t\t\tget a list of users (subsequent options will define what to show)\n";
1403 if (full)
1404     std::cout << "\n\n";
1405 std::cout << "\t--get-user\t\t\t\tget the information about user\n";
1406 if (full)
1407     std::cout << "\n\n";
1408 std::cout << "\t--add-user\t\t\t\tadd a new user\n";
1409 if (full)
1410     std::cout << "\n\n";
1411 std::cout << "\t--del-user\t\t\t\tdelete an existing user\n";
1412 if (full)
1413     std::cout << "\n\n";
1414 std::cout << "\t--chg-user\t\t\t\tchange an existing user\n";
1415 if (full)
1416     std::cout << "\n\n";
1417 std::cout << "\t--check-user\t\t\t\tcheck credentials is valid\n";
1418 if (full)
1419     std::cout << "\n\n";
1420 std::cout << "\t--send-message\t\t\t\tsend a message to a user\n";
1421 if (full)
1422     std::cout << "\n\n";
1423 }
1424 //-----------------------------------------------------------------------------
1425 void UsageServices(bool full)
1426 {
1427 std::cout << "Services management options:\n"
1428           << "\t--get-services\t\t\t\tget a list of services (subsequent options will define what to show)\n";
1429 if (full)
1430     std::cout << "\t\t--name\t\t\t\tshow service's name\n"
1431               << "\t\t--comment\t\t\tshow a comment to the service\n"
1432               << "\t\t--cost\t\t\t\tshow service's cost\n"
1433               << "\t\t--pay-day\t\t\tshow service's pay day\n\n";
1434 std::cout << "\t--get-service\t\t\t\tget the information about service\n";
1435 if (full)
1436     std::cout << "\t\t--name <name>\t\t\tname of the service to show\n"
1437               << "\t\t--comment\t\t\tshow a comment to the service\n"
1438               << "\t\t--cost\t\t\t\tshow service's cost\n"
1439               << "\t\t--pay-day\t\t\tshow service's pay day\n\n";
1440 std::cout << "\t--add-service\t\t\t\tadd a new service\n";
1441 if (full)
1442     std::cout << "\t\t--name <name>\t\t\tname of the service to add\n"
1443               << "\t\t--comment <comment>\t\ta comment to the service\n"
1444               << "\t\t--cost <cost>\t\t\tservice's cost\n"
1445               << "\t\t--pay-day <day>\t\t\tservice's pay day\n\n";
1446 std::cout << "\t--del-service\t\t\t\tdelete an existing service\n";
1447 if (full)
1448     std::cout << "\t\t--name <name>\t\t\tname of the service to delete\n\n";
1449 std::cout << "\t--chg-service\t\t\t\tchange an existing service\n";
1450 if (full)
1451     std::cout << "\t\t--name <name>\t\t\tname of the service to change\n"
1452               << "\t\t--comment <comment>\t\ta comment to the service\n"
1453               << "\t\t--cost <cost>\t\t\tservice's cost\n"
1454               << "\t\t--pay-day <day>\t\t\tservice's pay day\n\n";
1455 }
1456 //-----------------------------------------------------------------------------
1457 void UsageCorporations(bool full)
1458 {
1459 std::cout << "Corporations management options:\n"
1460           << "\t--get-corporations\t\t\tget a list of corporations (subsequent options will define what to show)\n";
1461 if (full)
1462     std::cout << "\t\t--name\t\t\t\tshow corporation's name\n"
1463               << "\t\t--cash\t\t\t\tshow corporation's cash\n\n";
1464 std::cout << "\t--get-corp\t\t\t\tget the information about corporation\n";
1465 if (full)
1466     std::cout << "\t\t--name <name>\t\t\tname of the corporation to show\n"
1467               << "\t\t--cash\t\t\t\tshow corporation's cash\n\n";
1468 std::cout << "\t--add-corp\t\t\t\tadd a new corporation\n";
1469 if (full)
1470     std::cout << "\t\t--name <name>\t\t\tname of the corporation to add\n"
1471               << "\t\t--cash <cash>\t\t\tinitial corporation's cash (default: \"0\")\n\n";
1472 std::cout << "\t--del-corp\t\t\t\tdelete an existing corporation\n";
1473 if (full)
1474     std::cout << "\t\t--name <name>\t\t\tname of the corporation to delete\n\n";
1475 std::cout << "\t--chg-corp\t\t\t\tchange an existing corporation\n";
1476 if (full)
1477     std::cout << "\t\t--name <name>\t\t\tname of the corporation to change\n"
1478               << "\t\t--add-cash <amount>[:<message>]\tadd cash to the corporation's account and optional comment message\n"
1479               << "\t\t--set-cash <cash>[:<message>]\tnew corporation's cash and optional comment message\n\n";
1480 }
1481
1482 void Version()
1483 {
1484 std::cout << "sgconf, version: 2.0.0-alpha.\n";
1485 }
1486
1487 } // namespace anonymous