]> git.stg.codes - stg.git/blobdiff - projects/sgconf/main.cpp
Small name fixes.
[stg.git] / projects / sgconf / main.cpp
index 0a2e12b4e301db9acbc8eef4c0fa88ac76bbdc16..76a47824b379472e4d1f526af01c1e2b6e4c4f24 100644 (file)
@@ -37,9 +37,9 @@
 #include <list>
 #include <sstream>
 
+#include "stg/common.h"
+#include "stg/netunit.h"
 #include "request.h"
-#include "common.h"
-#include "netunit.h"
 #include "common_sg.h"
 #include "sg_error_codes.h"
 
@@ -66,37 +66,12 @@ struct option long_options_get[] = {
 {"passive",     0, 0, 'i'},  //passive
 {"disable-stat",0, 0, 'S'},  //disable detail stat
 {"always-online",0, 0, 'O'}, //always online
-{"u0",          0, 0, 500},  //U0
-{"u1",          0, 0, 501},  //U1
-{"u2",          0, 0, 502},  //U2
-{"u3",          0, 0, 503},  //U3
-{"u4",          0, 0, 504},  //U4
-{"u5",          0, 0, 505},  //U5
-{"u6",          0, 0, 506},  //U6
-{"u7",          0, 0, 507},  //U7
-{"u8",          0, 0, 508},  //U8
-{"u9",          0, 0, 509},  //U9
-{"d0",          0, 0, 600},  //D0
-{"d1",          0, 0, 601},  //D1
-{"d2",          0, 0, 602},  //D2
-{"d3",          0, 0, 603},  //D3
-{"d4",          0, 0, 604},  //D4
-{"d5",          0, 0, 605},  //D5
-{"d6",          0, 0, 606},  //D6
-{"d7",          0, 0, 607},  //D7
-{"d8",          0, 0, 608},  //D8
-{"d9",          0, 0, 609},  //D9
-
-{"ud0",         0, 0, 700},  //UserData0
-{"ud1",         0, 0, 701},  //UserData1
-{"ud2",         0, 0, 702},  //UserData2
-{"ud3",         0, 0, 703},  //UserData3
-{"ud4",         0, 0, 704},  //UserData4
-{"ud5",         0, 0, 705},  //UserData5
-{"ud6",         0, 0, 706},  //UserData6
-{"ud7",         0, 0, 707},  //UserData7
-{"ud8",         0, 0, 708},  //UserData8
-{"ud9",         0, 0, 709},  //UserData9
+{"session-upload",   1, 0, 500},  //SU0
+{"session-download", 1, 0, 501},  //SD0
+{"month-upload",     1, 0, 502},  //MU0
+{"month-download",   1, 0, 503},  //MD0
+
+{"user-data",   1, 0, 700},  //UserData0
 
 {"prepaid",     0, 0, 'e'},  //prepaid traff
 {"create",      0, 0, 'n'},  //create
@@ -108,7 +83,8 @@ struct option long_options_get[] = {
 {"email",       0, 0, 'L'},  //emaiL
 {"phone",       0, 0, 'P'},  //phone
 {"group",       0, 0, 'G'},  //Group
-{"ip",         0, 0, 'I'},  //IP-address of user
+{"ip",          0, 0, 'I'},  //IP-address of user
+{"authorized-by",0, 0, 800}, //always online
 
 {0, 0, 0, 0}};
 
@@ -128,37 +104,12 @@ struct option long_options_set[] = {
 {"passive",     1, 0, 'i'},  //passive
 {"disable-stat",1, 0, 'S'},  //disable detail stat
 {"always-online",1, 0, 'O'},  //always online
-{"u0",          1, 0, 500},  //U0
-{"u1",          1, 0, 501},  //U1
-{"u2",          1, 0, 502},  //U2
-{"u3",          1, 0, 503},  //U3
-{"u4",          1, 0, 504},  //U4
-{"u5",          1, 0, 505},  //U5
-{"u6",          1, 0, 506},  //U6
-{"u7",          1, 0, 507},  //U7
-{"u8",          1, 0, 508},  //U8
-{"u9",          1, 0, 509},  //U9
-{"d0",          1, 0, 600},  //D0
-{"d1",          1, 0, 601},  //D1
-{"d2",          1, 0, 602},  //D2
-{"d3",          1, 0, 603},  //D3
-{"d4",          1, 0, 604},  //D4
-{"d5",          1, 0, 605},  //D5
-{"d6",          1, 0, 606},  //D6
-{"d7",          1, 0, 607},  //D7
-{"d8",          1, 0, 608},  //D8
-{"d9",          1, 0, 609},  //D9
-
-{"ud0",         1, 0, 700},  //UserData
-{"ud1",         1, 0, 701},  //UserData1
-{"ud2",         1, 0, 702},  //UserData2
-{"ud3",         1, 0, 703},  //UserData3
-{"ud4",         1, 0, 704},  //UserData4
-{"ud5",         1, 0, 705},  //UserData5
-{"ud6",         1, 0, 706},  //UserData6
-{"ud7",         1, 0, 707},  //UserData7
-{"ud8",         1, 0, 708},  //UserData8
-{"ud9",         1, 0, 709},  //UserData9
+{"session-upload",   1, 0, 500},  //U0
+{"session-download", 1, 0, 501},  //U1
+{"month-upload",     1, 0, 502},  //U2
+{"month-download",   1, 0, 503},  //U3
+
+{"user-data",        1, 0, 700},  //UserData
 
 {"prepaid",     1, 0, 'e'},  //prepaid traff
 {"create",      1, 0, 'n'},  //create
@@ -312,6 +263,22 @@ delete[] s;
 return ss;
 }
 //-----------------------------------------------------------------------------
+time_t ParseCreditExpire(const char * str)
+{
+struct tm brokenTime;
+
+brokenTime.tm_wday = 0;
+brokenTime.tm_yday = 0;
+brokenTime.tm_isdst = 0;
+brokenTime.tm_hour = 0;
+brokenTime.tm_min = 0;
+brokenTime.tm_sec = 0;
+
+stg_strptime(str, "%Y-%m-%d", &brokenTime);
+
+return stg_timegm(&brokenTime);
+}
+//-----------------------------------------------------------------------------
 void ParseAnyString(const char * c, string * msg, const char * enc)
 {
 iconv_t cd;
@@ -419,6 +386,12 @@ if (!req->credit.res_empty())
     strcat(r, str);
     }
 
+if (!req->creditExpire.res_empty())
+    {
+    sprintf(str, "<creditExpire value=\"%ld\"/>\n", req->creditExpire.const_data());
+    strcat(r, str);
+    }
+
 if (!req->prepaidTraff.res_empty())
     {
     sprintf(str, "<FreeMb value=\"%f\"/>\n", req->prepaidTraff.const_data());
@@ -681,7 +654,7 @@ REQUEST req;
 RESETABLE<string>   t1;
 int missedOptionArg = false;
 
-const char * short_options_get = "s:p:a:w:u:crtmodieNADLPGISO";
+const char * short_options_get = "s:p:a:w:u:crtmodieNADLPGISOE";
 int option_index = -1;
 
 while (1)
@@ -726,6 +699,10 @@ while (1)
             req.credit = 1;
             break;
 
+        case 'E': //credit expire
+            req.creditExpire = 1;
+            break;
+
         case 'd': //down
             req.down = 1;
             break;
@@ -765,7 +742,7 @@ while (1)
         case 'G': //Group
             req.group = " ";
             break;
-       
+
        case 'I': //IP-address of user
            req.ips = " ";
            break;
@@ -779,45 +756,29 @@ while (1)
             break;
 
         case 500: //U
+            //printf("U%d\n", c - 500);
+            req.sessionUpload[optarg] = 1;
+            break;
         case 501:
+            //printf("U%d\n", c - 500);
+            req.sessionDownload[optarg] = 1;
+            break;
         case 502:
-        case 503:
-        case 504:
-        case 505:
-        case 506:
-        case 507:
-        case 508:
-        case 509:
             //printf("U%d\n", c - 500);
-            req.u[c - 500] = 1;
+            req.monthUpload[optarg] = 1;
             break;
-
-        case 600: //D
-        case 601:
-        case 602:
-        case 603:
-        case 604:
-        case 605:
-        case 606:
-        case 607:
-        case 608:
-        case 609:
-            //printf("D%d\n", c - 600);
-            req.d[c - 600] = 1;
+        case 503:
+            //printf("U%d\n", c - 500);
+            req.monthDownload[optarg] = 1;
             break;
 
         case 700: //UserData
-        case 701:
-        case 702:
-        case 703:
-        case 704:
-        case 705:
-        case 706:
-        case 707:
-        case 708:
-        case 709:
             //printf("UD%d\n", c - 700);
-            req.ud[c - 700] = " ";
+            req.ud[optarg] = " ";
+            break;
+
+        case 800:
+            req.authBy = true;
             break;
 
         case '?':
@@ -847,7 +808,10 @@ if (missedOptionArg || !CheckParametersGet(&req))
     exit(PARAMETER_PARSING_ERR_CODE);
     }
 
-return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req);
+if (req.authBy)
+    return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, req);
+else
+    return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req);
 }
 //-----------------------------------------------------------------------------
 int mainSet(int argc, char **argv)
@@ -860,7 +824,7 @@ REQUEST req;
 
 RESETABLE<string>   t1;
 
-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:";
+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:";
 
 int missedOptionArg = false;
 
@@ -912,6 +876,10 @@ while (1)
             req.credit = ParseCredit(optarg);
             break;
 
+        case 'E': //credit expire
+            req.creditExpire = ParseCreditExpire(optarg);
+            break;
+
         case 'd': //down
             req.down = ParseDownPassive(optarg);
             break;
@@ -943,22 +911,22 @@ while (1)
             break;
 
         case 'N': //Note
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.note = str;
             break;
 
         case 'A': //nAme
-            ParseAnyString(optarg, &str, "koi8-r");
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.name = str;
             break;
 
         case 'D': //aDdress
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.address = str;
             break;
 
         case 'L': //emaiL
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.email = str;
             //printf("EMAIL=%s\n", optarg);
             break;
@@ -969,7 +937,7 @@ while (1)
             break;
 
         case 'G': //Group
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.group = str;
             break;
 
@@ -987,46 +955,26 @@ while (1)
             break;
 
         case 500: //U
+            //printf("U%d\n", c - 500);
+            req.sesionUpload[optarg] = ParseTraff(argv[optind++]);
+            break;
         case 501:
+            //printf("U%d\n", c - 500);
+            req.sessionDownload[optarg] = ParseTraff(argv[optind++]);
+            break;
         case 502:
-        case 503:
-        case 504:
-        case 505:
-        case 506:
-        case 507:
-        case 508:
-        case 509:
             //printf("U%d\n", c - 500);
-            req.u[c - 500] = ParseTraff(optarg);
+            req.monthUpload[optarg] = ParseTraff(argv[optind++]);
             break;
-
-        case 600: //D
-        case 601:
-        case 602:
-        case 603:
-        case 604:
-        case 605:
-        case 606:
-        case 607:
-        case 608:
-        case 609:
-            //printf("D%d\n", c - 600);
-            req.d[c - 600] = ParseTraff(optarg);
+        case 503:
+            //printf("U%d\n", c - 500);
+            req.monthDownload[optarg] = ParseTraff(argv[optind++]);
             break;
 
         case 700: //UserData
-        case 701:
-        case 702:
-        case 703:
-        case 704:
-        case 705:
-        case 706:
-        case 707:
-        case 708:
-        case 709:
-            ParseAnyString(optarg, &str);
+            ParseAnyString(argv[optind++], &str);
             //printf("UD%d\n", c - 700);
-            req.ud[c - 700] = str;
+            req.userData[optarg] = str;
             break;
 
         case '?':