OpengateM Source Repository
Révision | 830e46491dd03d88e9544346ae21f1811cf4fd71 (tree) |
---|---|
l'heure | 2014-02-28 15:11:17 |
Auteur | watanaby <watanaby@user...> |
Commiter | watanaby |
changed log table to chart. Added status P(=Pause).
@@ -225,6 +225,11 @@ OpengateM History</H3> | ||
225 | 225 | </DT><DD> |
226 | 226 | Modified mac cache to store not-found info (opengatemd). |
227 | 227 | </DD> |
228 | + <DT>Ver.0.9.0 at 2014.2.28 | |
229 | + </DT><DD> | |
230 | + Changed log table in the update page to chart format (opengatemup). | |
231 | + Added status='P' to represent "Pause" (opengatemup). | |
232 | + </DD> | |
228 | 233 | </DL> |
229 | 234 | |
230 | 235 | </BODY> |
@@ -2,6 +2,14 @@ | ||
2 | 2 | <head> |
3 | 3 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
4 | 4 | <title></title> |
5 | +<script type="text/javascript"> | |
6 | +<!-- | |
7 | +var loglist={ | |
8 | +%%USAGELOG%% | |
9 | +}; | |
10 | +--> | |
11 | +</script> | |
12 | +<script type="text/javascript" src="/opengate/showlog.js"></script> | |
5 | 13 | </head> |
6 | 14 | <body align="center"> |
7 | 15 |
@@ -32,17 +40,20 @@ | ||
32 | 40 | %%ERRORLIST%% |
33 | 41 | </font></p> |
34 | 42 | <p> |
43 | +<p><strong>To prevent hijacking, please confirm your usage | |
44 | +log.</strong> | |
45 | +The red border cells in the usage log include two or more records for one device. Please check carefully. | |
46 | +</p> | |
35 | 47 | |
36 | -<p>Check <strong>"Renew"</strong> to renew the registration (resume | |
48 | +<p>Select <strong>Renew</strong> to renew the registration (resume | |
37 | 49 | and extend the limit date). |
38 | -To prevent hijacking, please confirm your usage log at update. | |
39 | 50 | </p> |
40 | 51 | <p> |
41 | -<strong>"Pause"</strong> sets the limit-date to now to pause the | |
52 | +Select <strong>Pause</strong> to pause the | |
42 | 53 | usage. If you want to reuse the device, check "Renew". |
43 | 54 | </p> |
44 | 55 | <p> |
45 | -Check <strong>"Delete"</strong> to delete the registration. If you | |
56 | +Select <strong>Delete</strong> to delete the registration. If you | |
46 | 57 | may use this terminal in the future, please use "Pause". |
47 | 58 | </p> |
48 | 59 | <p> |
@@ -51,18 +62,10 @@ reason. Please contact to the administrator. | ||
51 | 62 | </p> |
52 | 63 | |
53 | 64 | <p><font size="5"> usage log </font></p> |
54 | -<p> | |
55 | -<table border="1"> | |
56 | -<tr align="middle"> | |
57 | -<td> MAC Address </td> | |
58 | -<td> Device Name </td> | |
59 | -<td> Start Time </td> | |
60 | -<td> Week </td> | |
61 | -<td> Gateway </td> | |
62 | 65 | |
63 | -</tr> | |
64 | -%%USAGELOG%% | |
65 | -</table> | |
66 | -</p> | |
66 | +<div id="usagelog"></div> | |
67 | +<div id="popup"></div> | |
68 | + | |
69 | +<p><br><br></p> | |
67 | 70 | </body> |
68 | 71 | </html> |
@@ -2,6 +2,14 @@ | ||
2 | 2 | <head> |
3 | 3 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
4 | 4 | <title></title> |
5 | +<script type="text/javascript"> | |
6 | +<!-- | |
7 | +var loglist={ | |
8 | +%%USAGELOG%% | |
9 | +}; | |
10 | +--> | |
11 | +</script> | |
12 | +<script type="text/javascript" src="/opengate/showlog.js"></script> | |
5 | 13 | </head> |
6 | 14 | <body align="center"> |
7 | 15 | <p><font size="5">MACアドレス登録更新</font></p> |
@@ -33,29 +41,23 @@ | ||
33 | 41 | %%ERRORLIST%% |
34 | 42 | </font></p> |
35 | 43 | |
36 | -<p><strong>「更新」</strong>をチェックすると、機器の登録を更新して利用 | |
37 | -期限を延長します。不正利用を防ぐため、更新時には、下の利用履歴が妥当か確認して下さい。</p> | |
44 | +<p><strong>不正利用を防ぐため、下の利用履歴が妥当か確認して下さい。 | |
45 | +</strong>利用履歴における赤枠セルは1つの機器に対する2つ以上の利用記録を含んでいます。特に注意して下さい。</p> | |
46 | + | |
47 | +<p><strong>「更新」</strong>をチェックすると、機器の登録を更新して利用期限を延長します。</p> | |
38 | 48 | |
39 | -<p><strong>「休止」</strong>をチェックすると、利用期限を早めて利用不可にします。再び利用するときには更新処理をしてください。 | |
49 | +<p><strong>「休止」</strong>をチェックすると、利用不可にします。再び利用するときには更新処理をしてください。 | |
40 | 50 | </p> |
41 | 51 | <p><strong>「削除」</strong>をチェックすると、機器の登録を削除します。 |
42 | -再び利用する可能性が有るときは、休止を利用下さい。 | |
52 | +再び利用する可能性があるときは、休止を利用下さい。 | |
43 | 53 | </p> |
44 | -<p>状態が'I'となっている機器は無効とされています。理由は管理者に問い合わせ下さい。</p> | |
54 | +<p>状態が"I"となっている機器は無効とされています。理由は管理者に問い合わせ下さい。</p> | |
45 | 55 | |
46 | 56 | |
47 | 57 | <p><font size="5">利用履歴</font></p> |
48 | -<p> | |
49 | -<table border="1"> | |
50 | - <tr align="middle"> | |
51 | - <td> MACアドレス</td> | |
52 | - <td> 機器名</td> | |
53 | - <td> 開始時間</td> | |
54 | - <td> 曜日</td> | |
55 | - <td> ゲートウェイ</td> | |
56 | - </tr> | |
57 | -%%USAGELOG%% | |
58 | -</table> | |
59 | -</p> | |
58 | + | |
59 | +<div id="usagelog"></div> | |
60 | +<div id="popup"></div> | |
61 | +<p><br><br></p> | |
60 | 62 | </body> |
61 | 63 | </html> |
@@ -1063,6 +1063,7 @@ int putUpdatePageToClient(char *language, char* userId, char* extraId, int ownUp | ||
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | while(fgets(buff,BUFFMAXLN,fp)!=NULL){ |
1066 | + | |
1066 | 1067 | HtmlReplace(buff, "%%CGINAME%%", updateCgi); |
1067 | 1068 | HtmlReplace(buff, "%%USERID%%", userId); |
1068 | 1069 | HtmlReplace(buff, "%%REDIRECTEDURL%%", redirectedUrl); |
@@ -1101,7 +1102,7 @@ void putMacListToClient(char* userId, char* extraId){ | ||
1101 | 1102 | while(GetNextMacAddrFromMngDb(userId,extraId,macAddr,deviceName, |
1102 | 1103 | entryDate,limitDate,status,mailAddress)){ |
1103 | 1104 | printf("<tr align=middle>\n"); |
1104 | - if(status[0]=='A'){ | |
1105 | + if((status[0]=='A')||(status[0]=='P')){ | |
1105 | 1106 | printf("<td><input type=radio name=%s value=extend checked></td>\n",macAddr); |
1106 | 1107 | printf("<td><input type=radio name=%s value=pause></td>\n",macAddr); |
1107 | 1108 | printf("<td><input type=radio name=%s value=delete></td>\n",macAddr); |
@@ -1124,30 +1125,45 @@ void putMacListToClient(char* userId, char* extraId){ | ||
1124 | 1125 | /*********************************************/ |
1125 | 1126 | void putUsageLogToClient(char *userId, char* extraId, char* language){ |
1126 | 1127 | |
1127 | - char macAddr[ADDRMAXLN]; | |
1128 | - char deviceName[WORDMAXLN]; | |
1129 | - char openTime[WORDMAXLN]; | |
1130 | - char gatewayName[WORDMAXLN]; | |
1131 | - int weekday; | |
1132 | - char str[WORDMAXLN]; | |
1128 | + char macAddr[ADDRMAXLN]=""; | |
1129 | + char deviceName[WORDMAXLN]=""; | |
1130 | + char openTime[WORDMAXLN]=""; | |
1131 | + char closeTime[WORDMAXLN]=""; | |
1132 | + char gatewayName[WORDMAXLN]=""; | |
1133 | + char beginTime[WORDMAXLN]=""; | |
1134 | + char endTime[WORDMAXLN]=""; | |
1135 | + int dateCount=0; | |
1133 | 1136 | char* p; |
1137 | + int count=0; | |
1134 | 1138 | |
1135 | - /* get usage log form db and insert as html table row */ | |
1139 | + /* get usage log from db and insert as JSON format */ | |
1136 | 1140 | while(GetNextUsageLogFromMngDb(userId,extraId,macAddr,deviceName, |
1137 | - openTime,gatewayName,&weekday)){ | |
1141 | + openTime,closeTime,gatewayName)){ | |
1138 | 1142 | |
1139 | 1143 | /* split hostname only */ |
1140 | 1144 | if((p=strchr(gatewayName,'.'))!=NULL) *p='\0'; |
1141 | 1145 | |
1142 | 1146 | /* put out table row */ |
1143 | - printf("<tr align=middle>\n"); | |
1144 | - printf("<td>%s</td>\n", macAddr); | |
1145 | - printf("<td>%s</td>\n",deviceName); | |
1146 | - printf("<td>%s</td>\n",openTime); | |
1147 | - printf("<td>%s</td>\n",WeekdayStr(weekday, str, language)); | |
1148 | - printf("<td>%s</td>\n",gatewayName); | |
1149 | - printf("</tr>\n"); | |
1147 | + printf("\t %d:{\n", count); | |
1148 | + printf("\t\t macAddress: '%s',\n", macAddr); | |
1149 | + printf("\t\t device: '%s',\n",deviceName); | |
1150 | + printf("\t\t openTime: '%s',\n",openTime); | |
1151 | + printf("\t\t closeTime: '%s',\n",closeTime); | |
1152 | + printf("\t\t gateway: '%s'\n",gatewayName); | |
1153 | + printf("\t },\n"); | |
1154 | + | |
1155 | + /* increment log item counter */ | |
1156 | + count++; | |
1150 | 1157 | } |
1158 | + | |
1159 | + /* put out informations for the list */ | |
1160 | + GetTimeRangeToShowLog(beginTime, endTime, &dateCount); | |
1161 | + printf("\t info:{\n"); | |
1162 | + printf("\t\t beginTime: '%s',\n", beginTime); | |
1163 | + printf("\t\t endTime: '%s',\n", endTime); | |
1164 | + printf("\t\t listCount: %d,\n", count); | |
1165 | + printf("\t\t dateCount: %d\n", dateCount); | |
1166 | + printf("\t }\n"); | |
1151 | 1167 | } |
1152 | 1168 | |
1153 | 1169 | /**********************************************/ |
@@ -28,7 +28,6 @@ Email: watanaby@is.saga-u.ac.jp | ||
28 | 28 | #include "opengatemmng.h" |
29 | 29 | #include <mysql.h> |
30 | 30 | |
31 | - | |
32 | 31 | MYSQL mysql; |
33 | 32 | |
34 | 33 | /****************************************** |
@@ -381,7 +380,7 @@ int delMacAddrFromMngDb(char* macAddr){ | ||
381 | 380 | /* don't touch device set as status=Inactive */ |
382 | 381 | snprintf(queryStr, BUFFMAXLN, |
383 | 382 | "update macaddrs set status='D',limitDate=now() " |
384 | - " where macAddress='%s' and status='A'", macAddr); | |
383 | + " where macAddress='%s' and (status='A' or status='P')", macAddr); | |
385 | 384 | }else{ |
386 | 385 | |
387 | 386 | /* prepare query string */ |
@@ -389,7 +388,7 @@ int delMacAddrFromMngDb(char* macAddr){ | ||
389 | 388 | /* don't touch device set as status=Inactive */ |
390 | 389 | snprintf(queryStr, BUFFMAXLN, |
391 | 390 | "delete from macaddrs " |
392 | - " where macAddress='%s' and status='A'", macAddr); | |
391 | + " where macAddress='%s' and (status='A' or status='P')", macAddr); | |
393 | 392 | } |
394 | 393 | |
395 | 394 | /* send SQL query */ |
@@ -412,8 +411,8 @@ int renewMacAddrInMngDb(char* macAddr){ | ||
412 | 411 | /* prepare query string */ |
413 | 412 | /* don't touch device set as inactive by admin */ |
414 | 413 | snprintf(queryStr, BUFFMAXLN, |
415 | - "update macaddrs set renewDate=now(), limitDate=%s " | |
416 | - " where status='A' and macAddress='%s'", | |
414 | + "update macaddrs set status='A', renewDate=now(), limitDate=%s " | |
415 | + " where (status='A' or status='P') and macAddress='%s'", | |
417 | 416 | GetConfValue("LimitDate"),macAddr); |
418 | 417 | |
419 | 418 | /* send SQL query */ |
@@ -428,7 +427,6 @@ int renewMacAddrInMngDb(char* macAddr){ | ||
428 | 427 | /****************************************** |
429 | 428 | pause the usage of the device for a mac address |
430 | 429 | registered in the management db |
431 | - (set the limitDate to now) | |
432 | 430 | ******************************************/ |
433 | 431 | int pauseMacAddrInMngDb(char* macAddr){ |
434 | 432 |
@@ -437,7 +435,7 @@ int pauseMacAddrInMngDb(char* macAddr){ | ||
437 | 435 | /* prepare query string */ |
438 | 436 | /* don't touch device set as inactive by admin */ |
439 | 437 | snprintf(queryStr, BUFFMAXLN, |
440 | - "update macaddrs set limitDate=now() " | |
438 | + "update macaddrs set status='P' " | |
441 | 439 | " where status='A' and macAddress='%s' and limitDate>now()", |
442 | 440 | macAddr); |
443 | 441 |
@@ -496,7 +494,7 @@ int isSessionFoundInMngDb(char* macAddr){ | ||
496 | 494 | get next next usage log from management db |
497 | 495 | if end of list, return false |
498 | 496 | *******************************************/ |
499 | -int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* gatewayName, int* weekday){ | |
497 | +int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* closeTime, char* gatewayName){ | |
500 | 498 | static MYSQL_RES *res=NULL; |
501 | 499 | MYSQL_ROW row; |
502 | 500 | char queryStr[BUFFMAXLN]; |
@@ -509,15 +507,15 @@ int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* d | ||
509 | 507 | |
510 | 508 | /* prepare query string */ |
511 | 509 | /* get log where addr.entry < session.open < addr.limit */ |
510 | + /* (the same device may be registered by other users in old days) */ | |
512 | 511 | snprintf(queryStr, BUFFMAXLN, |
513 | - "select macaddrs.macAddress as mac, device, openTime, " | |
514 | - " gatewayName, weekday(openTime), date(openTime) as dt " | |
512 | + "select macaddrs.macAddress, device, openTime, closeTime, " | |
513 | + " gatewayName " | |
515 | 514 | " from macaddrs, sessionmd " |
516 | 515 | " where macaddrs.macAddress=sessionmd.macAddress " |
517 | 516 | " and entryDate < openTime and openTime < limitDate " |
518 | - " and %s < openTime " | |
519 | - " and userId='%s' and extraId='%s'" | |
520 | - " group by dt,mac order by openTime desc", | |
517 | + " and (%s<closeTime or closeTime=0) " | |
518 | + " and userId='%s' and extraId='%s'", | |
521 | 519 | GetConfValue("ShowLogAfter"), userId, extraId); |
522 | 520 | |
523 | 521 | /* send SQL query */ |
@@ -539,8 +537,8 @@ int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* d | ||
539 | 537 | strncpy(macAddr, row[0],ADDRMAXLN); |
540 | 538 | strncpy(deviceName,row[1],WORDMAXLN); |
541 | 539 | strncpy(openTime,row[2],WORDMAXLN); |
542 | - strncpy(gatewayName,row[3],WORDMAXLN); | |
543 | - *weekday=atoi(row[4]); | |
540 | + strncpy(closeTime,row[3],WORDMAXLN); | |
541 | + strncpy(gatewayName,row[4],WORDMAXLN); | |
544 | 542 | return TRUE; |
545 | 543 | } |
546 | 544 | /* if not found, free memory area */ |
@@ -550,6 +548,7 @@ int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* d | ||
550 | 548 | } |
551 | 549 | } |
552 | 550 | |
551 | + | |
553 | 552 | /******************************************* |
554 | 553 | get next mail address near limit date |
555 | 554 | from management db |
@@ -575,10 +574,11 @@ int getNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char* device | ||
575 | 574 | /* [select mailAddress,limitDate,device from macaddrs |
576 | 575 | where ( date(now())=date(adddate(limitDate, interval -1 day)) |
577 | 576 | OR date(now())=date(adddate(limitDate, interval -7 day)) ) |
578 | - AND status='A'] */ | |
577 | + AND (status='A' OR status='P')] */ | |
579 | 578 | snprintf(queryStr, BUFFMAXLN, |
580 | 579 | "select mailAddress,limitDate,device from macaddrs " |
581 | - " where (%s) and status='A'", mailTiming); | |
580 | + " where (%s) and (status='A' or status='P')", mailTiming); | |
581 | + /* mailTiming is a condition string defined in conf file */ | |
582 | 582 | |
583 | 583 | /* send SQL query */ |
584 | 584 | if (mysql_query(&mysql, queryStr)){ |
@@ -608,6 +608,66 @@ int getNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char* device | ||
608 | 608 | } |
609 | 609 | } |
610 | 610 | |
611 | +/******************************************* | |
612 | + get the date corresponding to ShowLogAfter in conf file | |
613 | +*******************************************/ | |
614 | +int getTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount){ | |
615 | + | |
616 | + static MYSQL_RES *res=NULL; | |
617 | + MYSQL_ROW row; | |
618 | + char queryStr[BUFFMAXLN]; | |
619 | + char* showLogAfter; | |
620 | + char countStr[WORDMAXLN]; | |
621 | + | |
622 | + /* get conf value for beginning day for listing */ | |
623 | + showLogAfter=GetConfValue("ShowLogAfter"); | |
624 | + if(isNull(showLogAfter)) return FALSE; | |
625 | + | |
626 | + /* set default values */ | |
627 | + beginTime[0]='\0'; | |
628 | + endTime[0]='\0'; | |
629 | + *dateCount=0; | |
630 | + | |
631 | + /* if do not get result yet */ | |
632 | + if(res==NULL){ | |
633 | + | |
634 | + /* prepare query string */ | |
635 | + /* select (adddate(now(), interval -1 month)), | |
636 | + now(), | |
637 | + datediff(now(),(adddate(now(), interval -1 month))) + 1; */ | |
638 | + snprintf(queryStr, BUFFMAXLN, | |
639 | + "select (%s), now(), datediff(now(),(%s)) + 1", | |
640 | + showLogAfter, showLogAfter); | |
641 | + | |
642 | + /* send SQL query */ | |
643 | + if (mysql_query(&mysql, queryStr)){ | |
644 | + err_msg("ERR at %s#%d: mysql query[%s]: %s",__FILE__,__LINE__,queryStr, | |
645 | + mysql_error(&mysql)); | |
646 | + return FALSE; | |
647 | + } | |
648 | + | |
649 | + /* store result */ | |
650 | + res = mysql_store_result(&mysql); | |
651 | + } | |
652 | + | |
653 | + /* output table name */ | |
654 | + row = mysql_fetch_row(res); | |
655 | + | |
656 | + /* if found, return values */ | |
657 | + if(row!=NULL){ | |
658 | + strncpy(beginTime, row[0], WORDMAXLN); | |
659 | + strncpy(endTime, row[1], WORDMAXLN); | |
660 | + strncpy(countStr, row[2], WORDMAXLN); | |
661 | + *dateCount=atoi(countStr); | |
662 | + return TRUE; | |
663 | + } | |
664 | + /* if not found, free memory area */ | |
665 | + else{ | |
666 | + mysql_free_result(res); | |
667 | + return FALSE; | |
668 | + } | |
669 | +} | |
670 | + | |
611 | 671 | /******************************************** |
612 | 672 | routines for debugging output |
613 | 673 | ********************************************/ |
@@ -721,13 +781,14 @@ int IsSessionFoundInMngDb(char* macAddr){ | ||
721 | 781 | return ret; |
722 | 782 | } |
723 | 783 | |
724 | -int GetNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* gatewayName, int* weekday){ | |
784 | +int GetNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, | |
785 | + char* deviceName, char* openTime, char* closeTime, char* gatewayName){ | |
725 | 786 | int ret; |
726 | 787 | if(debug>1) err_msg("DEBUG:=>getNextUsageLogFromMngDb(%s,%s)",userId,extraId); |
727 | 788 | ret=getNextUsageLogFromMngDb(userId,extraId,macAddr,deviceName, |
728 | - openTime,gatewayName,weekday); | |
729 | - if(debug>1) err_msg("DEBUG:(%d)<=getNextUsageLogFromMngDb(,,%s,%s,%s,%s,%d)", | |
730 | - ret,macAddr,deviceName,openTime,gatewayName,*weekday); | |
789 | + openTime,closeTime,gatewayName); | |
790 | + if(debug>1) err_msg("DEBUG:(%d)<=getNextUsageLogFromMngDb(,,%s,%s,%s,%s,%s)", | |
791 | + ret,macAddr,deviceName,openTime,closeTime,gatewayName); | |
731 | 792 | return ret; |
732 | 793 | } |
733 | 794 |
@@ -739,3 +800,12 @@ int GetNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char*device) | ||
739 | 800 | ret,mailAddress,limitDate,device); |
740 | 801 | return ret; |
741 | 802 | } |
803 | + | |
804 | +int GetTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount){ | |
805 | + int ret; | |
806 | + if(debug>1) err_msg("DEBUG:=>getTimeRangeToShowLog( )"); | |
807 | + ret=getTimeRangeToShowLog(beginTime, endTime, dateCount); | |
808 | + if(debug>1) err_msg("DEBUG:(%d)<=getTimeRangeToShowLog(%s,%s,%d)", | |
809 | + ret,beginTime,endTime,*dateCount); | |
810 | + return ret; | |
811 | +} |
@@ -189,8 +189,9 @@ int DelMacAddrFromMngDb(char* macAddr); | ||
189 | 189 | int RenewMacAddrInMngDb(char* macAddr); |
190 | 190 | int PauseMacAddrInMngDb(char* macAddr); |
191 | 191 | int IsSessionFoundInMngDb(char* macAddr); |
192 | -int GetNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* gatewayName, int* weekday); | |
192 | +int GetNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* closeTime, char* gatewayName); | |
193 | 193 | int GetNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char*device); |
194 | +int GetTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount); | |
194 | 195 | |
195 | 196 | /* workdb.c */ |
196 | 197 | int SetupSqliteBusyTimeoutValue(void); |