OSDN Git Service

removed flag for log option
authorwatanaby <watanaby@users.osdn.jp>
Sun, 26 Jun 2016 02:31:34 +0000 (11:31 +0900)
committerwatanaby <watanaby@users.osdn.jp>
Sun, 26 Jun 2016 02:31:34 +0000 (11:31 +0900)
conf/opengatemd.conf.sample
conf/opengatemmng.conf.sample
html/en/macauthadmin.html [new file with mode: 0644]
html/en/macchk.html
html/ja/macauthadmin.html [new file with mode: 0644]
html/ja/macchk.html
mdsrc/managementdb.c
mdsrc/opengatemd.h
mngsrc/auth.c
mngsrc/managementdb.c
mngsrc/opengatemmng.h

index 754dc2c..ece5083 100644 (file)
@@ -92,9 +92,6 @@
        <!-- SQLite busy timeout (milli-seconds) -->
        <SqliteBusyTimeout>100</SqliteBusyTimeout>
 
-       <!-- Save Log of session to Management DB (1:YES/0:NO) -->
-       <SaveLogToMngDb>1</SaveLogToMngDb>
-
        <!-- SQLite database file -->
        <!-- for opengatemd work -->
        <SqliteDbMd>/tmp/opengatemd.db</SqliteDbMd>
index e6df246..35b9454 100644 (file)
        <Device>fxp0</Device> 
 
        <!-- ### MUST BE MODIFIED ## -->
-       <!-- auth server setting for administrators(watanaby,admin1,admin2) -->
+       <!-- auth server setting for Aadministrators(user1 user2) -->
        <AuthServer>
                <UserType>admin</UserType>
                <Protocol>pop3s</Protocol>
                <Address>192.168.0.2</Address>
-               <AcceptUsers>watanaby admin1 admin2</AcceptUsers>
+               <MailDomain>opengate.example.com</MailDomain>
+               <AcceptUsers>user1 user2</AcceptUsers>
        </AuthServer>
 
        <!-- ### MUST BE MODIFIED ## -->
-       <!-- auth server setting for normal(not admin) users  -->
+       <!-- auth server setting for Normal(not admin) users  -->
        <AuthServer>
                <Protocol>shibboleth</Protocol>
                <UidAttribute>uid</UidAttribute>
diff --git a/html/en/macauthadmin.html b/html/en/macauthadmin.html
new file mode 100644 (file)
index 0000000..3dc2b7a
--- /dev/null
@@ -0,0 +1,55 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title></title>
+</head>
+<body bgcolor="#EEFFEE">
+<center>
+
+<h2>Management of MAC Address Registration</h2>
+
+<p><a href="%%CGINAME%%?lang=ja&redirectedurl=%%REDIRECTEDURL%%">Japanese Page</a></p>
+
+<P><font size=+1>This is the page to manage MAC address of your
+terminals. If you register this terminal, you can use the network
+without password entry.</font></P>
+
+<P><font size=+1>To proceed, you are requested to be authenticated.
+</font></P>
+
+<P><font size=+1>You will be authenticated with your user ID and
+password.  If you do not know your user ID and/or password, please consult CNC.
+</font></P>
+
+<P>
+Please enter <font color=red>Administrator's user ID and password</font> in the box below, then press SEND.
+</P>
+
+<p><font color="red">
+%%ERRORLIST%%
+</font></p>
+
+<P>
+<form method="POST" action="%%CGINAME%%?lang=en&redirectedurl=%%REDIRECTEDURL%%">
+<INPUT TYPE="HIDDEN" NAME="redirected_url" VALUE="%%REDIRECTEDURL%%">
+
+<TABLE BORDER=0>
+<TR NOWRAP>
+<TD><strong>Administrator's User ID: </strong></TD><TD><INPUT TYPE="TEXT" SIZE=20 NAME="userid"></TD>
+</TR><TR NOWRAP>
+<TD><strong>Password: </strong></TD><TD><INPUT TYPE="PASSWORD" SIZE=20 NAME="password"></TD>
+</TR><TR NOWRAP>
+<TD></TD><TD><INPUT TYPE="SUBMIT" VALUE="  SEND  "></TD>
+</TR>
+</TABLE>
+</form>
+</P>
+
+<p><font size=+1>If you have any questions, 
+please contact network administrator.
+</center>
+
+<div align=right>Saga University</div>
+</body>
+</html>
+
index 5e1a5a9..f2007ed 100644 (file)
@@ -58,7 +58,7 @@
       try network access to confirm that the network for the terminal is closed.
     </p></li>
     <li><p>
-      Load this page. If you already loaded, reload it.
+      Reload this page.
     </p></li>
     <li><p>
       The above is the list of addresses using this access point recently.
diff --git a/html/ja/macauthadmin.html b/html/ja/macauthadmin.html
new file mode 100644 (file)
index 0000000..6e5b2dd
--- /dev/null
@@ -0,0 +1,55 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title></title>
+</head>
+<body bgcolor="#EEFFEE">
+<center>
+
+<h2>利用者端末MACアドレス登録管理</h2>
+
+<p><a href="%%CGINAME%%?lang=en&redirectedurl=%%REDIRECTEDURL%%">English Page</a></p>
+
+
+<P><font size=+1>ここは利用者端末のMACアドレスを登録管理するページです。
+端末を登録するとパスワード入力なしでネットワークを利用できます。
+</font></P>
+
+<P><font size=+1>登録管理に進むために利用資格の確認を行ってください。</font></P>
+
+<P><font size=+1>利用資格の確認には、ユーザ名とパスワードが必要です。自分のユーザ名やパスワードが解らない場合は、総合情報基盤センターに尋ねてください。</font></P>
+
+<P>
+下の入力欄に、<font color=red>管理担当者のユーザIDとパスワード</font>を入力して、「送信」ボタンを押して下さい。
+</P>
+
+
+<p><font color="red">
+%%ERRORLIST%%
+</font></p>
+
+<P>
+<form method="POST" action="%%CGINAME%%?lang=ja&redirectedurl=%%REDIRECTEDURL%%">
+<INPUT TYPE="HIDDEN" NAME="redirected_url" VALUE="%%REDIRECTEDURL%%">
+
+<TABLE BORDER=0>
+<TR NOWRAP>
+  <TD><strong>管理ユーザID:</strong></TD><TD><INPUT TYPE="TEXT" SIZE=20 NAME="userid"></TD>
+</TR><TR NOWRAP>
+<TD><strong>パスワード:</strong></TD><TD><INPUT TYPE="PASSWORD" SIZE=20 NAME="password"></TD>
+</TR><TR NOWRAP>
+<TD></TD><TD><INPUT TYPE="SUBMIT" VALUE="  送  信  "></TD>
+</TR>
+</TABLE>
+</form>
+</P>
+<p>
+<font size=+1>不明な点などがありましたら、ネットワーク管理者にお尋ねく
+ださい。</font></p>
+</center>
+
+
+<div align=right>佐賀大学</div>
+
+</body>
+</html>
index 3ee1afd..9159db4 100644 (file)
@@ -57,7 +57,7 @@
        登録を希望する端末で、この端末と同じアクセスポイントに接続して、ネットワークアクセスを試み、ネットワークが閉鎖していることを確認する。
     </p></li>
     <li><p>
-         このページを表示する。確認前に表示しているときはリロードを行う
+         このページをリロードする
     </p></li>
     <li><p>
          上記の表は、同一アクセスポイントを最近利用した端末のアドレス一覧である。リストの先頭が最も最近に検出した端末である。
index 68c1257..80828ed 100644 (file)
@@ -29,7 +29,7 @@ Email: watanaby@is.saga-u.ac.jp
 #include <mysql.h>
 
 static MYSQL mysql;
-static int saveLogToMngDb=0;
+static int isSessionTableFoundInMngDb=TRUE;
 
 /******************************************
 initialize management db
@@ -42,7 +42,6 @@ int initMngDb(void){
   char *password = GetConfValue("MySqlDb/Password");
   char *database = GetConfValue("MySqlDb/Database");
   my_bool reconnect;
-  char *confStr;
 
 /* initialize mysql */
   mysql_library_init(-1,NULL,NULL);
@@ -64,13 +63,9 @@ int initMngDb(void){
   reconnect = TRUE;
   mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
 
-  /* read logmode flag from conf file and hold in a variable */
-  confStr = GetConfValue("SaveLogToMngDb");
-  if(isNull(confStr)) saveLogToMngDb = 0;  /* no conf means no-log */
-  else                saveLogToMngDb = strtol(confStr, NULL, 2);
-
-  /* adjust relation of logmode in conf and logtable in mngdb */
-  AdjustLogModeAndLogTable();
+  /* check existence of session table in management db(not work db) */
+  /* if it is FALSE, writing/reading log is skipped */
+  isSessionTableFoundInMngDb = IsTableFoundInMngDb("sessionmd");
   
   return TRUE;
 }
@@ -137,8 +132,8 @@ int putOpenToMngDb(char* macAddress){
   char queryStr[BUFFMAXLN];
   struct utsname uts;
 
-  /* if session log table is not used, return */
-  if(!saveLogToMngDb) return FALSE;
+  /* if session log table is not found, return */
+  if(!isSessionTableFoundInMngDb) return FALSE;
   
   /* get domain name */
   uname(&uts);
@@ -167,8 +162,8 @@ int putCloseToMngDb(char* macAddress){
 
   char queryStr[BUFFMAXLN];
 
-  /* if session log table is not used, return */
-  if(!saveLogToMngDb) return FALSE;
+  /* if session log table is not found, return */
+  if(!isSessionTableFoundInMngDb) return FALSE;
 
   /* prepare query string */
   snprintf(queryStr, BUFFMAXLN, 
@@ -193,8 +188,8 @@ int delOldSessionLogInMngDb(void){
 
   char* queryStr="delete from sessionmd where closeTime>0 and closeTime<adddate(now(),interval -1 month)";
 
-  /* if session log table is not used, return */
-  if(!saveLogToMngDb) return FALSE;
+  /* if session log table is not found, return */
+  if(!isSessionTableFoundInMngDb) return FALSE;
   
   /* send SQL query */
   if (mysql_query(&mysql, queryStr)){
@@ -330,45 +325,6 @@ int isTableFoundInMngDb(char* table){
   return found;
 }
 
-/******************************************
-set closeTime to unclosed sessions in mngdb
-return value: 1=success, 0=error
-******************************************/
-int updateCloseTimeToUnclosedSessionInMngDb(void){
-  
-  char* queryStr="update sessionmd set closeTime=now() where closeTime=0";
-
-  /* send SQL query */
-  if (mysql_query(&mysql, queryStr)){
-     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
-            mysql_error(&mysql));
-     return FALSE;
-  }
-
-  return TRUE;
-}
-
-/**********************************************************
-adjust the relation of logmode(SaveLogToMngDb) in conf file 
-and logtable(sessionmd) in management db 
-***********************************************************/
-void adjustLogModeAndLogTable(void){
-
-  /* check the existence of table sessionmd in management.db */
-  int isSessionTableFoundInMngDb = IsTableFoundInMngDb("sessionmd");
-
-  /* if logmode=off and session table exists, cleanup all sessions */
-  if(!saveLogToMngDb && isSessionTableFoundInMngDb){
-    UpdateCloseTimeToUnclosedSessionInMngDb();
-  }
-
-  /* if logmode=on and session table does not exist, write error */
-  if(saveLogToMngDb && !isSessionTableFoundInMngDb){
-     err_msg("ERR at %s#%d: please create mysql table. sample script is found in archive",
-            __FILE__,__LINE__);
-  }
-}
-
 
 /********************************************
  routines for debugging 
@@ -444,16 +400,3 @@ int IsTableFoundInMngDb(char* table){
   return ret;
 }
 
-int UpdateCloseTimeToUnclosedSessionInMngDb(void){
-  int ret;
-  if(debug>1) err_msg("DEBUG:=>updateCloseTimeToUnclosedSessionInMngDb()");
-  ret = updateCloseTimeToUnclosedSessionInMngDb();
-  if(debug>1) err_msg("DEBUG:(%d)<=updateCloseTimeToUnclosedSessionInMngDb()", ret);
-  return ret;
-}
-
-void AdjustLogModeAndLogTable(void){
-  if(debug>1) err_msg("DEBUG:=>adjustLogModeAndLogTable()");
-  adjustLogModeAndLogTable();
-  if(debug>1) err_msg("DEBUG:<=adjustLogModeAndLogTable()");
-}
index 2b3a4da..d6fad78 100644 (file)
@@ -179,8 +179,6 @@ int GetNextRecordFromWatchlistTableInMngDb(char* macAddress);
 int IsAllFoundInWatchlistTable(void);
 int DelOldSessionLogInMngDb(void);
 int IsTableFoundInMngDb(char* table);
-int UpdateCloseTimeToUnclosedSessionInMngDb(void);
-void AdjustLogModeAndLogTable(void);
 
 /* workdb.c */
 int SetupSqliteBusyTimeoutValue(void);
index cd9a809..0061bbb 100644 (file)
@@ -184,7 +184,8 @@ int getUserId(char* requestStr, char* userId, char* extraId, char* language, int
 
     /* if all check is failed, put error */
     if(authResult==DENY){
-      SetMessage(NoInfoInDb); 
+      SetMessage(NoInfoInDb);
+      if(userType==ADMINUSER) SetMessage(RequestAdminAuth); 
       PutDenyToClient(language);
       err_msg("DENY: user %s", useridfull);
     }
index a14c5af..6d8153f 100644 (file)
@@ -491,7 +491,10 @@ int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* d
   /* set default values */
   macAddr[0]=deviceName[0]=openTime[0]=gatewayName[0]='\0';
 
-  /* if do not get result yet */
+  /* if session table is not found in management db, return */
+  if(!IsTableFoundInMngDb("sessionmd")) return FALSE;
+
+  /* if do not get result yet (if first call) */
   if(res==NULL){
 
     /* prepare query string */
@@ -511,7 +514,8 @@ int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* d
     if (mysql_query(&mysql, queryStr)){
 
       /* query error */
-      /* might be caused by <SaveLogToMngDb> setting in opengatemd.conf */
+      err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
+             mysql_error(&mysql));
       return FALSE; 
     }
     
@@ -815,6 +819,44 @@ int doesMacAddrBelongToUser(char* macAddr, char* userId, char* extraId){
   return exists;
 }
 
+/******************************************
+is found table in management db
+input=table name
+return value: 1=found,0=not found or error
+******************************************/
+int isTableFoundInMngDb(char* table){
+  MYSQL_RES *res;
+  MYSQL_ROW row;
+  int found=FALSE;
+  char queryStr[BUFFMAXLN];
+
+  /* if no table, return false */
+  if(isNull(table)) return FALSE;
+  
+  /* prepare query string */
+  snprintf(queryStr, BUFFMAXLN, 
+          "show tables like '%s'", table);
+
+  /* send SQL query */
+  if (mysql_query(&mysql, queryStr)){
+     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
+            mysql_error(&mysql));
+     return ERROR;
+  }
+  res = mysql_use_result(&mysql);
+  
+  /* output table row */
+  row = mysql_fetch_row(res);
+
+  /* row==NULL means getting no record */
+  if(row==NULL) found=FALSE;
+  else          found=TRUE;
+
+  mysql_free_result(res);
+  return found;
+}
+
+
 /********************************************
  routines for debugging output
 ********************************************/
@@ -990,3 +1032,12 @@ int DoesMacAddrBelongToUser(char* macAddr, char* userId, char* extraId){
   if(debug>1) err_msg("DEBUG:(%d)<=doesMacAddrBelongToUser( )",ret);
   return ret;
 }
+
+int IsTableFoundInMngDb(char* table){
+  int ret;
+  if(debug>1) err_msg("DEBUG:=>isTableFoundInMngDb(%s)", table);
+  ret = isTableFoundInMngDb(table);
+  if(debug>1) err_msg("DEBUG:(%d)<=isTableFoundInMngDb()", ret);
+  return ret;
+}
+
index 80219cf..7c14004 100644 (file)
@@ -197,6 +197,7 @@ int RenameMailAddressInMngDb(char* macAddr, char* mailStr);
 int RegOrUpNobodyMacAddr(char* macAddress);
 int IsMacAddrStatusInactiveInMngDb(char* macAddress);
 int DoesMacAddrBelongToUser(char* macAddr, char* userId, char* extraId);
+int IsTableFoundInMngDb(char* table);
 
 /* workdb.c */
 int SetupSqliteBusyTimeoutValue(void);