]> git.stg.codes - stg.git/blobdiff - projects/sgconf/main.cpp
Added stream encryption/decryption.
[stg.git] / projects / sgconf / main.cpp
index 0a2e12b4e301db9acbc8eef4c0fa88ac76bbdc16..2c02be27488c8b7c53ac0819847684696616d66d 100644 (file)
@@ -37,9 +37,9 @@
 #include <list>
 #include <sstream>
 
 #include <list>
 #include <sstream>
 
+#include "stg/common.h"
+#include "stg/netunit.h"
 #include "request.h"
 #include "request.h"
-#include "common.h"
-#include "netunit.h"
 #include "common_sg.h"
 #include "sg_error_codes.h"
 
 #include "common_sg.h"
 #include "sg_error_codes.h"
 
@@ -108,7 +108,8 @@ struct option long_options_get[] = {
 {"email",       0, 0, 'L'},  //emaiL
 {"phone",       0, 0, 'P'},  //phone
 {"group",       0, 0, 'G'},  //Group
 {"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}};
 
 
 {0, 0, 0, 0}};
 
@@ -312,6 +313,22 @@ delete[] s;
 return ss;
 }
 //-----------------------------------------------------------------------------
 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;
 void ParseAnyString(const char * c, string * msg, const char * enc)
 {
 iconv_t cd;
@@ -419,6 +436,12 @@ if (!req->credit.res_empty())
     strcat(r, str);
     }
 
     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());
 if (!req->prepaidTraff.res_empty())
     {
     sprintf(str, "<FreeMb value=\"%f\"/>\n", req->prepaidTraff.const_data());
@@ -681,7 +704,7 @@ REQUEST req;
 RESETABLE<string>   t1;
 int missedOptionArg = false;
 
 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)
 int option_index = -1;
 
 while (1)
@@ -726,6 +749,10 @@ while (1)
             req.credit = 1;
             break;
 
             req.credit = 1;
             break;
 
+        case 'E': //credit expire
+            req.creditExpire = 1;
+            break;
+
         case 'd': //down
             req.down = 1;
             break;
         case 'd': //down
             req.down = 1;
             break;
@@ -820,6 +847,10 @@ while (1)
             req.ud[c - 700] = " ";
             break;
 
             req.ud[c - 700] = " ";
             break;
 
+        case 800:
+            req.authBy = true;
+            break;
+
         case '?':
         case ':':
             //printf ("Unknown option \n");
         case '?':
         case ':':
             //printf ("Unknown option \n");
@@ -847,7 +878,10 @@ if (missedOptionArg || !CheckParametersGet(&req))
     exit(PARAMETER_PARSING_ERR_CODE);
     }
 
     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)
 }
 //-----------------------------------------------------------------------------
 int mainSet(int argc, char **argv)
@@ -860,7 +894,7 @@ REQUEST req;
 
 RESETABLE<string>   t1;
 
 
 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;
 
 
 int missedOptionArg = false;
 
@@ -912,6 +946,10 @@ while (1)
             req.credit = ParseCredit(optarg);
             break;
 
             req.credit = ParseCredit(optarg);
             break;
 
+        case 'E': //credit expire
+            req.creditExpire = ParseCreditExpire(optarg);
+            break;
+
         case 'd': //down
             req.down = ParseDownPassive(optarg);
             break;
         case 'd': //down
             req.down = ParseDownPassive(optarg);
             break;
@@ -943,22 +981,22 @@ while (1)
             break;
 
         case 'N': //Note
             break;
 
         case 'N': //Note
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.note = str;
             break;
 
         case 'A': //nAme
             req.note = str;
             break;
 
         case 'A': //nAme
-            ParseAnyString(optarg, &str, "koi8-r");
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.name = str;
             break;
 
         case 'D': //aDdress
             req.name = str;
             break;
 
         case 'D': //aDdress
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.address = str;
             break;
 
         case 'L': //emaiL
             req.address = str;
             break;
 
         case 'L': //emaiL
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.email = str;
             //printf("EMAIL=%s\n", optarg);
             break;
             req.email = str;
             //printf("EMAIL=%s\n", optarg);
             break;
@@ -969,7 +1007,7 @@ while (1)
             break;
 
         case 'G': //Group
             break;
 
         case 'G': //Group
-            ParseAnyString(optarg, &str);
+            ParseAnyString(optarg, &str, "koi8-ru");
             req.group = str;
             break;
 
             req.group = str;
             break;