OSDN Git Service

cvs reset
[opengate/opengate.git] / opengate / opengatesrv / main.c
index 728a517..b2e8f5e 100644 (file)
@@ -40,12 +40,16 @@ char useridshort[USERMAXLN];/* userID before @ mark(cut off extraID) */
 char extraId[USERMAXLN];
 char userProperty[BUFFMAXLN];
 time_t timeIn, timeOut;
+int ipStatus;              /* flag for IPV4ONLY,IPV6ONLY or IPV46DUAL */
 int connectionMode;   /* client connect mode */
+/* variable to measuring processing time (in msec) */
+struct timeval timeBeginCgi, timeBeginWait, timeConnect, timeDisconnect;
+
 char sessionId[BUFFMAXLN];    /* session ID */
 
 void PutCloseMsg(time_t timeOut, time_t timeIn);
 void SetProcessTitle(char *useridshort, char *clientAddr4, char * ruleNumber4, char *clientAddr6, char * ruleNumber6, int ipStatus);
-void logConnectMode(char *userid);
+void logConnectMode();
 void closeExit(int signo);
 
 /***************************************************/
@@ -59,9 +63,11 @@ int  main(int argc, char **argv)
   int pid;
   int parentpid;
   int duration;     /* requested usage duration */
+  int durationEntered; /* the duration value is entered or not */
   int authResult;
-  int ipStatus;              /* flag for IPv4 or IPv6 */
-  char watchMode[WORDMAXLN];  /* client watch mode Http or Java or Timeout */
+
+  /* get time at the cgi starting (in msec) */
+  gettimeofday(&timeBeginCgi, NULL) ;
 
   /* prepare config file */
   if(OpenConfFile()==-1) return 0;
@@ -83,7 +89,7 @@ int  main(int argc, char **argv)
   }
 
   /* get POST data */
-  if(GetPostData(userid, password, clientAddr4, &duration, watchMode)==FALSE){
+  if(GetPostData(userid, password, clientAddr4, &duration, &durationEntered)==FALSE){
     PutClientRetry(language);
     return 0;
   }
@@ -163,7 +169,7 @@ int  main(int argc, char **argv)
   if(pid!=0){
     /** parent process **/
     /* send accept page with java */
-    PutClientAccept(userid, sessionId, port, pid, clientAddr4, clientAddr6, ipStatus, duration, watchMode);
+    PutClientAccept(userid, sessionId, port, pid, clientAddr4, clientAddr6, ipStatus, duration, durationEntered);
 
     /* detach from Web server */
     return 0;
@@ -177,11 +183,17 @@ int  main(int argc, char **argv)
 
   Pipe(dummyfd);      /* connect dummy pipe for stdin and out */
 
+  /* get time at the client wait start (in msec) */
+  gettimeofday(&timeBeginWait, NULL) ;
+
   /* wait connection from the client */
   /* if no connection, close gate when duration is passed */
   /* or ipaddr for the macAddr4 is changed */
   connectionMode=WaitClientConnect(userid, userProperty, sessionId, clientAddr4, clientAddr6, duration, macAddr4, macAddr6, ipStatus, pClientAddr, language, port, parentpid);
 
+  /* get time at the client connection (in msec) */
+  gettimeofday(&timeConnect, NULL) ;
+
   if(connectionMode==JAVACONNECT){
 
     /* wait until the java applet quit */
@@ -192,7 +204,7 @@ int  main(int argc, char **argv)
   else if(connectionMode==HTTPCONNECT){
 
     /* wait until the http keep alive is closed */
-    WaitHttpClose(pClientAddr, userid, userProperty, macAddr4, macAddr6, ipStatus);
+    WaitHttpClose(pClientAddr, userid, userProperty, macAddr4, macAddr6, ipStatus, sessionId, port);
   }
 
   /* close firewall and exit */
@@ -225,7 +237,7 @@ void putCloseMsg(time_t timeOut, time_t timeIn)
 void closeExit(int signo)
 {
   /* save the connect mode */
-  logConnectMode(userid);
+  logConnectMode();
 
   /* signal is disabled */
   Signal(SIGTERM, SIG_DFL);
@@ -275,15 +287,49 @@ void setProcessTitle(char *useridshort, char *clientAddr4, char * ruleNumber4, c
 }
 
 
-/************************************/
-/* save connectMode to syslog       */
-/************************************/
-void logConnectMode(char *userid)
+/*****************************************/
+/* save connectMode and others to syslog */
+/*****************************************/
+void logConnectMode()
 {
   char *mode[4]={"NONE","JAVA","HTTP","TIME"};
+  long time1sec,time2sec,time3sec;
+  long time1usec,time2usec,time3usec;
+
+  /* set value on failure */
+  if(connectionMode<0 || connectionMode>3) connectionMode=NOCONNECT;
+  if(connectionMode==NOCONNECT){
+    gettimeofday(&timeBeginWait, NULL) ;
+    gettimeofday(&timeConnect, NULL) ;
+  }
+
+  /* get time at the end of connection (in msec) */
+  gettimeofday(&timeDisconnect, NULL) ;
+
+  /* calc time difference (seconds(sec) and micro-seconds(usec)) */
+  time1sec=(timeBeginWait.tv_sec - timeBeginCgi.tv_sec);
+  time1usec=(timeBeginWait.tv_usec - timeBeginCgi.tv_usec);
+  /* if microsec diff is minus, bolow from sec diff */
+  if(time1usec<0){ 
+    time1usec += 1000000; time1sec--;
+  }
+  time2sec=(timeConnect.tv_sec - timeBeginWait.tv_sec);
+  time2usec=(timeConnect.tv_usec - timeBeginWait.tv_usec);
+  if(time2usec<0){
+    time2usec += 1000000; time2sec--;
+  }
+  time3sec=(timeDisconnect.tv_sec - timeConnect.tv_sec);
+  time3usec=(timeDisconnect.tv_usec - timeConnect.tv_usec);
+  if(time3usec<0){
+    time3usec += 1000000; time3sec--;
+  }
 
-  if(connectionMode<0 || connectionMode>3) connectionMode=0;
-  if(debug>0) err_msg("INFO: user %s is watched by [%s]",userid, mode[connectionMode]);
+  if(debug>0) err_msg("INFO: user=%s watchmode=%s procsec=%ld.%06ld,%ld.%06ld,%ld.%06ld ipversion=%d useragent=%s",
+                     userid, mode[connectionMode], 
+                     time1sec,time1usec,
+                     time2sec,time2usec,
+                     time3sec,time3usec,
+                     ipStatus, getenv("HTTP_USER_AGENT"));
 }