OSDN Git Service

restored optional log table in management db
[opengatem/opengatem.git] / mngsrc / cgi.c
index 9645188..00e45fb 100644 (file)
@@ -1171,6 +1171,10 @@ int putUpdatePageToClient(char *language, char* userId, char* extraId, int ownUp
     if(strstr(buff, "%%MACLIST%%")!=NULL){
       PutMacListToClient(userId,extraId);
     }
+    else if(strstr(buff, "%%USAGELOG%%")!=NULL){
+      PutUsageLogToClient(userId, extraId, language);
+    }
+
     else if(strstr(buff, "%%ERRORLIST%%")!=NULL){
       InsertMessageToPage(language);
     }
@@ -1241,6 +1245,55 @@ void putMacListToClient(char* userId, char* extraId){
   }
 }
 
+/*********************************************/
+/* put usage log to the client            */
+/*********************************************/
+void putUsageLogToClient(char *userId, char* extraId, char* language){
+
+  char macAddr[ADDRMAXLN]="";
+  char deviceName[WORDMAXLN]="";
+  char openTime[WORDMAXLN]="";
+  char closeTime[WORDMAXLN]="";
+  char gatewayName[WORDMAXLN]="";
+  char beginTime[WORDMAXLN]="";
+  char endTime[WORDMAXLN]="";
+  int dateCount=0;
+  char* p;
+  int count=0;
+
+  /*** get usage log and insert it to html doc as JSON format */
+  /* get one log form management db */
+  while(GetNextUsageLogFromMngDb(userId,extraId,macAddr,deviceName,
+                                openTime,closeTime,gatewayName)){
+
+    /* split hostname only (opengate01.example.com -> opengate01) */
+    if((p=strchr(gatewayName,'.'))!=NULL) *p='\0';
+
+    /* put out the log as a JSON item */
+    /* table skeleton is prepared in template file */
+    printf("\t %d:{\n", count);
+    printf("\t\t macAddress: '%s',\n", macAddr);
+    printf("\t\t device: '%s',\n",deviceName);
+    printf("\t\t openTime: '%s',\n",openTime);
+    printf("\t\t closeTime: '%s',\n",closeTime);
+    printf("\t\t gateway: '%s'\n",gatewayName);
+    printf("\t },\n");
+
+    /* increment log counter */
+    count++;
+  }
+
+  /* put out the JSON item for summary info of the list */
+  GetTimeRangeToShowLog(beginTime, endTime, &dateCount);
+  printf("\t info:{\n");
+  printf("\t\t beginTime: '%s',\n", beginTime);
+  printf("\t\t endTime: '%s',\n", endTime);
+  printf("\t\t listCount: %d,\n", count);
+  printf("\t\t dateCount: %d\n", dateCount);
+  printf("\t }\n");
+}
+
+
 /********************************************************/
 /* the client is an allowable http-user-agent or not    */
 /* the allowable http-user-agent can be defined in conf */
@@ -1479,6 +1532,12 @@ void PutMacListToClient(char *userId, char* extraId){
   if(debug>1) err_msg("DEBUG:<=putMacListToClient( )");
 }
 
+void PutUsageLogToClient(char *userId, char* extraId, char* language){
+  if(debug>1) err_msg("DEBUG:=>putUsageLogToClient(%s,%s,%s)",userId,extraId,language);
+  putUsageLogToClient(userId,extraId,language);
+  if(debug>1) err_msg("DEBUG:<=putUsageLogToClient( )");
+}
+
 int IsAccessedFromAllowableAgent(void){
   int ret;
   if(debug>1) err_msg("DEBUG:=>isAccessedFromAllowableAgent( )");