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