1 /**************************************************
2 OpengateM - MAC address authentication system
4 module to control management database that includes following tables
5 list of mac addresses and their owners
7 this database is implemented with MySql
9 Copyright (C) 2011 Opengate Project Team
10 Written by Yoshiaki Watanabe
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 Email: watanaby@is.saga-u.ac.jp
27 **************************************************/
28 #include "opengatemmng.h"
33 /*****************************/
34 /* initialize management db */
35 /*****************************/
38 /* set parameters read from conf file */
39 char *server = GetConfValue("MySqlDb/Server");
40 char *user = GetConfValue("MySqlDb/User");
41 char *password = GetConfValue("MySqlDb/Password");
42 char *database = GetConfValue("MySqlDb/Database");
45 /* initialize mysql */
46 mysql_library_init(-1,NULL,NULL);
47 if(mysql_init(&mysql)==NULL){
48 err_msg("ERR at %s#%d: mysql init: %s",__FILE__,__LINE__,
53 /* Connect to database */
54 if (!mysql_real_connect(&mysql, server,
55 user, password, database, 0, NULL, 0)) {
56 err_msg("ERR at %s#%d: mysql connect: %s",__FILE__,__LINE__,
61 /* set auto-reconnect true */
63 mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
68 /**********************************/
69 /*close management db */
70 /**********************************/
71 void closeMngDb(void){
77 /*********************************************************/
78 /* get nic vendor from table nicvendors in management db */
79 /* macAddress:(in),vendor:(out),bufferLength:(in) */
80 /*********************************************************/
81 int getNicVendorFromMngDb(char* macAddress, char* vendor, int bufferLength){
86 char queryStr[BUFFMAXLN];
87 char macHeader[ADDRMAXLN];
89 /* set default values (="?") */
93 /* prepare query string */
94 /* macHeader is first 3 bytes of macAddess that represents vender code */
95 /* macAddress="11:22:33:44:55:66" -> macHeader="11:22:33" */
96 strlcpy(macHeader, macAddress, ADDRMAXLN);
98 snprintf(queryStr, BUFFMAXLN,
99 "select org from nicvendors where oui='%s'",
103 if (mysql_query(&mysql, queryStr)){
104 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
105 mysql_error(&mysql));
108 res = mysql_use_result(&mysql);
110 /* get a row from query result */
111 row = mysql_fetch_row(res);
113 /* if not found, return false */
114 if(row==NULL) found=FALSE;
116 /* if found, get the vendor name */
118 strlcpy(vendor, row[0], bufferLength);
122 /* free memory area */
123 mysql_free_result(res);
127 /*************************************************/
128 /* The macAddr is already registered or not */
129 /* the row having status="D"(deleted) is ignored */
130 /* macAddr:(input) */
131 /*************************************************/
132 int isMacAddrFoundInMngDb(char* macAddr){
136 char queryStr[BUFFMAXLN];
139 /* prepare query string */
140 snprintf(queryStr, BUFFMAXLN,
141 "select * from macaddrs "
142 " where macAddress='%s' and status!='D'",
146 if (mysql_query(&mysql, queryStr)){
147 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
148 mysql_error(&mysql));
152 /* store query result */
153 res = mysql_store_result(&mysql);
155 /* get a row from query result */
156 row = mysql_fetch_row(res);
158 /* if found, return true */
159 if(row!=NULL) ret=TRUE;
161 /* if not found, return false */
164 /* free memory area */
165 mysql_free_result(res);
170 /******************************************************/
171 /* The count of registered mac addresses for the user */
172 /* the row having status="D"(deleted) is ignored */
173 /* all-args:(input) */
174 /******************************************************/
175 int countMacAddrsForUserInMngDb(char* userId, char* extraId){
179 char queryStr[BUFFMAXLN];
180 char countStr[WORDMAXLN];
183 /* prepare query string */
184 snprintf(queryStr, BUFFMAXLN,
185 "select count(*) from macaddrs "
186 " where userId='%s' and extraId='%s' and status!='D'",
190 if (mysql_query(&mysql, queryStr)){
191 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
192 mysql_error(&mysql));
196 /* store query result */
197 res = mysql_store_result(&mysql);
199 /* get a row from query result */
200 row = mysql_fetch_row(res);
202 /* if found, return the count */
204 strlcpy(countStr, row[0], WORDMAXLN);
205 count=atoi(countStr);
208 /* free memory area */
209 mysql_free_result(res);
214 /***********************************************************/
215 /* register mac address and the owner to the management db */
216 /* all-args:(input) */
217 /***********************************************************/
218 int registMacAddrToMngDb(char* macAddr, char* deviceName, char* userId, char* extraId, char* mailAddr){
220 char queryStr[BUFFMAXLN];
223 /* if alreay registered, return false */
224 if(IsMacAddrFoundInMngDb(macAddr)){
225 SetMessage(ExistentMacAddr);
229 /* if the count of devices for a user exceeds the limit(in conf), return false */
230 count=CountMacAddrsForUserInMngDb(userId,extraId);
231 if(count >= atoi(GetConfValue("MaxDevices"))){
232 SetMessage(DeviceCountOver);
236 /* prepare query string */
237 snprintf(queryStr, BUFFMAXLN,
238 "insert into macaddrs "
239 "(macAddress, status, device, userId, extraId, "
240 " entryDate, renewDate, limitDate, mailAddress) "
241 "values ('%s','A','%s', '%s', '%s', "
242 " now(), now(), %s, '%s')",
243 macAddr, deviceName, userId, extraId,
244 GetConfValue("LimitDate"), mailAddr);
247 if (mysql_query(&mysql, queryStr)){
248 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
249 mysql_error(&mysql));
256 /********************************************************/
257 /* get next mac address for the user from management db */
258 /* at first call, execute query and return first row */
259 /* from second call, return next row of previous query */
260 /* repeat until return=false (end of list, clear work) */
261 /* userId,extraId:(input), others:(output) */
262 /********************************************************/
263 int getNextMacAddrFromMngDb(char* userId, char* extraId, char* macAddress, char* deviceName, char* entryDate, char* limitDate, char* status, char* mailAddress){
265 static MYSQL_RES *res=NULL;
267 char queryStr[BUFFMAXLN];
269 /* set default values */
270 macAddress[0]=deviceName[0]=entryDate[0]=limitDate[0]='\0';
272 /* if do not get result yet */
275 /* prepare query string */
276 snprintf(queryStr, BUFFMAXLN,
277 "select macAddress, device, entryDate, limitDate, status, mailAddress "
278 "from macaddrs where userId='%s' and extraId='%s' and status!='D'",
282 if (mysql_query(&mysql, queryStr)){
283 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
284 mysql_error(&mysql));
289 res = mysql_store_result(&mysql);
292 /* output table name */
293 row = mysql_fetch_row(res);
295 /* if found, return values */
297 strlcpy(macAddress, row[0],ADDRMAXLN);
298 strlcpy(deviceName,row[1],WORDMAXLN);
299 strlcpy(entryDate,row[2],WORDMAXLN);
300 strlcpy(limitDate,row[3],WORDMAXLN);
301 strlcpy(status,row[4],WORDMAXLN);
302 strlcpy(mailAddress,row[5],BUFFMAXLN);
305 /* if not found, free memory area */
307 mysql_free_result(res);
313 /***************************************************/
314 /* write mac modification log to the management db */
315 /* all-args:(input) */
316 /***************************************************/
317 int putMacModifyLogToMngDb(char* userId, char* extraId, char* macAddr, char modifyType){
319 char queryStr[BUFFMAXLN];
321 /* prepare query string */
322 snprintf(queryStr, BUFFMAXLN,
323 "insert into macmodify "
324 "(userId, extraId, macAddress, modifyType, modifyDate) "
325 "values ('%s', '%s', '%s', '%c', now())",
326 userId, extraId, macAddr, modifyType);
329 if (mysql_query(&mysql, queryStr)){
330 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
331 mysql_error(&mysql));
338 /************************************************************/
339 /* The count of mac address modification in last 24 hours */
340 /* (the modification count is checked to cope with abuse) */
341 /* all-args:(input) */
342 /* indicate either of userID&extraId or macAddress to count */
343 /************************************************************/
344 int countMacModifyPerDayInMngDb(char* userId, char* extraId, char* macAddress){
348 char queryStr[BUFFMAXLN];
349 char countStr[WORDMAXLN];
352 /* prepare query string */
353 /* count for one macAddress if not null, elsecount for one userID)*/
354 if(!isNull(macAddress)){
355 snprintf(queryStr, BUFFMAXLN,
356 "select count(*) from macmodify "
357 " where macAddress='%s' and "
358 " modifyDate > adddate(now(), interval -1 day) ",
361 snprintf(queryStr, BUFFMAXLN,
362 "select count(*) from macmodify "
363 " where userId='%s' and extraId='%s' and "
364 " modifyDate > adddate(now(), interval -1 day) ",
369 if (mysql_query(&mysql, queryStr)){
370 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
371 mysql_error(&mysql));
375 /* store query result */
376 res = mysql_store_result(&mysql);
378 /* get a row from query result */
379 row = mysql_fetch_row(res);
381 /* if found, return count (if not, return large value for safe) */
383 strlcpy(countStr, row[0], WORDMAXLN);
384 count=atoi(countStr);
387 /* free memory area */
388 mysql_free_result(res);
393 /*********************************************************/
394 /* delete a mac address registered in the management db */
395 /* in actuality, not delete row, but set the status="D" */
396 /* when usage log for the address is found in log table */
397 /* macAddr:(input) */
398 /*********************************************************/
399 int delMacAddrFromMngDb(char* macAddr){
401 char queryStr[BUFFMAXLN];
403 /* if the mac is found in the past session log, */
404 /* the owner info is needed for the log inspection */
405 /* thus the info is not deleted, but set as status="D" */
406 if(IsSessionFoundInMngDb(macAddr)){
408 /* prepare query string */
409 /* don't touch device of status="I"(set Inactive by admin) */
410 snprintf(queryStr, BUFFMAXLN,
411 "update macaddrs set status='D',limitDate=now() "
412 " where macAddress='%s' and (status='A' or status='P')", macAddr);
415 /* if mac is not found in past session log, the row is removed */
418 /* prepare query string */
419 /* don't touch device of status="I"(set Inactive by admin) */
420 snprintf(queryStr, BUFFMAXLN,
421 "delete from macaddrs "
422 " where macAddress='%s' and (status='A' or status='P')", macAddr);
426 if (mysql_query(&mysql, queryStr)){
427 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
428 mysql_error(&mysql));
434 /******************************************/
435 /* renew the limit date for a mac address */
436 /* in the management db */
437 /* macAddr:(input) */
438 /* LimitDate in conf file is a SQL string */
439 /* to make a future date */
440 /* eg, "adddate(now(),interval 1 month)" */
441 /******************************************/
442 int renewMacAddrInMngDb(char* macAddr){
444 char queryStr[BUFFMAXLN];
446 /* prepare query string */
447 /* don't touch device set as inactive by admin */
448 snprintf(queryStr, BUFFMAXLN,
449 "update macaddrs set status='A', renewDate=now(), limitDate=%s "
450 " where (status='A' or status='P') and macAddress='%s'",
451 GetConfValue("LimitDate"),macAddr);
454 if (mysql_query(&mysql, queryStr)){
455 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
456 mysql_error(&mysql));
462 /******************************************
463 pause the usage of the device for a mac address
464 registered in the management db
465 ******************************************/
466 int pauseMacAddrInMngDb(char* macAddr){
468 char queryStr[BUFFMAXLN];
470 /* prepare query string */
471 /* don't touch device set as inactive by admin */
472 snprintf(queryStr, BUFFMAXLN,
473 "update macaddrs set status='P' "
474 " where status='A' and macAddress='%s' and limitDate>now()",
478 if (mysql_query(&mysql, queryStr)){
479 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
480 mysql_error(&mysql));
486 /******************************************
487 is the mac address used in session log
488 ******************************************/
489 int isSessionFoundInMngDb(char* macAddr){
493 char queryStr[BUFFMAXLN];
496 /* prepare query string */
497 /* get row for addr.entry<session.open<addr.limit */
498 snprintf(queryStr, BUFFMAXLN,
499 "select * from macaddrs, sessionmd "
500 " where macaddrs.macAddress=sessionmd.macAddress and "
501 " macaddrs.macAddress='%s' and "
502 " entryDate<openTime and openTime<limitDate",
506 if (mysql_query(&mysql, queryStr)){
507 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
508 mysql_error(&mysql));
513 res = mysql_store_result(&mysql);
515 /* output table name */
516 row = mysql_fetch_row(res);
518 /* if found, return true */
519 if(row!=NULL) ret=TRUE;
521 /* if not found, return false */
524 mysql_free_result(res);
528 /*******************************************
529 get next next usage log from management db
530 if end of list, return false
531 *******************************************/
532 int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* closeTime, char* gatewayName){
533 static MYSQL_RES *res=NULL;
535 char queryStr[BUFFMAXLN];
537 /* set default values */
538 macAddr[0]=deviceName[0]=openTime[0]=gatewayName[0]='\0';
540 /* if do not get result yet */
543 /* prepare query string */
544 /* get log where addr.entry < session.open < addr.limit */
545 /* (the same device may be registered by other users in old days) */
546 snprintf(queryStr, BUFFMAXLN,
547 "select macaddrs.macAddress, device, openTime, closeTime, "
549 " from macaddrs, sessionmd "
550 " where macaddrs.macAddress=sessionmd.macAddress "
551 " and entryDate < openTime and openTime < limitDate "
552 " and (%s<closeTime or closeTime=0) "
553 " and userId='%s' and extraId='%s'",
554 GetConfValue("ShowLogAfter"), userId, extraId);
557 if (mysql_query(&mysql, queryStr)){
558 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
559 mysql_error(&mysql));
564 res = mysql_store_result(&mysql);
567 /* output table name */
568 row = mysql_fetch_row(res);
570 /* if found, return values */
572 strlcpy(macAddr, row[0],ADDRMAXLN);
573 strlcpy(deviceName,row[1],WORDMAXLN);
574 strlcpy(openTime,row[2],WORDMAXLN);
575 strlcpy(closeTime,row[3],WORDMAXLN);
576 strlcpy(gatewayName,row[4],WORDMAXLN);
579 /* if not found, free memory area */
581 mysql_free_result(res);
587 /*******************************************
588 get next mail address near limit date
590 *******************************************/
591 int getNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char* device){
593 static MYSQL_RES *res=NULL;
595 char queryStr[BUFFMAXLN];
596 char* mailTiming=NULL;
598 /* set default values */
599 mailAddress[0]=limitDate[0]='\0';
601 /* if do not get result yet */
604 /* get mail send timing from conf file */
605 mailTiming = GetConfValue("Mail/Timing");
606 if(isNull(mailTiming)) return FALSE;
608 /* prepare query string */
609 /* [select mailAddress,limitDate,device from macaddrs
610 where ( date(now())=date(adddate(limitDate, interval -1 day))
611 OR date(now())=date(adddate(limitDate, interval -7 day)) )
612 AND (status='A' OR status='P') order by mailAddress,limitDate] */
613 snprintf(queryStr, BUFFMAXLN,
614 "select mailAddress,limitDate,device from macaddrs "
615 " where (%s) and (status='A' or status='P') "
616 " order by mailAddress,limitDate", mailTiming);
617 /* mailTiming is a condition string defined in conf file */
620 if (mysql_query(&mysql, queryStr)){
621 err_msg("ERR at %s#%d: mysql query[%s]: %s",__FILE__,__LINE__,queryStr,
622 mysql_error(&mysql));
627 res = mysql_store_result(&mysql);
630 /* output table name */
631 row = mysql_fetch_row(res);
633 /* if found, return values */
635 strlcpy(mailAddress, row[0], BUFFMAXLN);
636 strlcpy(limitDate, row[1], WORDMAXLN);
637 strlcpy(device, row[2], WORDMAXLN);
640 /* if not found, free memory area */
642 mysql_free_result(res);
647 /*******************************************
648 get the date corresponding to ShowLogAfter in conf file
649 *******************************************/
650 int getTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount){
652 static MYSQL_RES *res=NULL;
654 char queryStr[BUFFMAXLN];
656 char countStr[WORDMAXLN];
658 /* get conf value for beginning day for listing */
659 showLogAfter=GetConfValue("ShowLogAfter");
660 if(isNull(showLogAfter)) return FALSE;
662 /* set default values */
667 /* if do not get result yet */
670 /* prepare query string */
671 /* select (adddate(now(), interval -1 month)),
673 datediff(now(),(adddate(now(), interval -1 month))) + 1; */
674 snprintf(queryStr, BUFFMAXLN,
675 "select (%s), now(), datediff(now(),(%s)) + 1",
676 showLogAfter, showLogAfter);
679 if (mysql_query(&mysql, queryStr)){
680 err_msg("ERR at %s#%d: mysql query[%s]: %s",__FILE__,__LINE__,queryStr,
681 mysql_error(&mysql));
686 res = mysql_store_result(&mysql);
689 /* output table name */
690 row = mysql_fetch_row(res);
692 /* if found, return values */
694 strlcpy(beginTime, row[0], WORDMAXLN);
695 strlcpy(endTime, row[1], WORDMAXLN);
696 strlcpy(countStr, row[2], WORDMAXLN);
697 *dateCount=atoi(countStr);
700 /* if not found, free memory area */
702 mysql_free_result(res);
707 /********************************************
708 rename the device name for indicated mac address
709 ********************************************/
710 int renameDeviceNameInMngDb(char* macAddr, char* nameStr){
712 char queryStr[BUFFMAXLN];
714 /* prepare query string */
715 snprintf(queryStr, BUFFMAXLN,
716 "update macaddrs set device='%s' "
717 " where (status='A' or status='P') and macAddress='%s'",
721 if (mysql_query(&mysql, queryStr)){
722 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
723 mysql_error(&mysql));
729 /********************************************
730 rename the mail address for indicated mac address
731 ********************************************/
732 int renameMailAddressInMngDb(char* macAddr, char* mailStr){
734 char queryStr[BUFFMAXLN];
736 /* prepare query string */
737 snprintf(queryStr, BUFFMAXLN,
738 "update macaddrs set mailAddress='%s' "
739 " where (status='A' or status='P') and macAddress='%s'",
743 if (mysql_query(&mysql, queryStr)){
744 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
745 mysql_error(&mysql));
751 /********************************************
752 Register or Update MacAddress which is unlinked to user
753 ********************************************/
754 int regOrUpNobodyMacAddr(char* macAddress){
758 /* macAddress in inactive status cannot be modified */
759 if(IsMacAddrStatusInactiveInMngDb(macAddress)) return FALSE;
761 /* if mac is already registered, update it */
762 if(IsMacAddrFoundInMngDb(macAddress)){
763 if(RenewMacAddrInMngDb(macAddress)){
764 PutMacModifyLogToMngDb("?", "", macAddress, 'E'); /*(userId,extraId,.)*/
769 /* if mac is not yet registered, register it */
771 if(RegistMacAddrToMngDb(macAddress,"?","?","","")){ /*(dev,user,ext,mail) */
772 PutMacModifyLogToMngDb("?","", macAddress, 'R'); /* (userId,extraId,.) */
779 /******************************************
780 Is the macAddr in INACTIVE('I') status
781 ******************************************/
782 int isMacAddrStatusInactiveInMngDb(char* macAddr){
786 char queryStr[BUFFMAXLN];
789 /* prepare query string */
790 snprintf(queryStr, BUFFMAXLN,
791 "select * from macaddrs "
792 " where macAddress='%s' and status='I'",
796 if (mysql_query(&mysql, queryStr)){
797 err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
798 mysql_error(&mysql));
803 res = mysql_store_result(&mysql);
805 /* output table name */
806 row = mysql_fetch_row(res);
808 /* if found, return true */
809 if(row!=NULL) ret=TRUE;
811 /* if not found, return false */
814 mysql_free_result(res);
818 /********************************************
819 routines for debugging output
820 ********************************************/
824 if(debug>1) err_msg("DEBUG:=>initMngDb()");
826 if(debug>1) err_msg("DEBUG:(%d)<=initMngDb()",ret);
829 void CloseMngDb(void){
830 if(debug>1) err_msg("DEBUG:=>closeMngDb()");
832 if(debug>1) err_msg("DEBUG:<=closeMngDb()");
835 int GetNextMacAddrFromMngDb(char* userId, char* extraId, char* macAddress, char* deviceName, char* entryDate, char* limitDate, char* status, char* mailAddress){
837 if(debug>1) err_msg("DEBUG:=>getNextMacAddrFromMngDb(%s,%s)",userId,extraId);
838 ret=getNextMacAddrFromMngDb(userId,extraId,macAddress,deviceName,
839 entryDate,limitDate, status,mailAddress);
840 if(debug>1) err_msg("DEBUG:(%d)<=getNextMacAddrFromMngDb(,,%s,%s,%s,%s,%s,%s)",
841 ret,macAddress,deviceName,entryDate,limitDate,status,mailAddress);
845 int RegistMacAddrToMngDb(char* macAddr, char* deviceName, char* userId, char* extraId, char* mailAddress){
847 if(debug>1) err_msg("DEBUG:=>registMacAddrToMngDb(%s,%s,%s,%s,%s)",
848 macAddr,deviceName,userId,extraId,mailAddress);
849 ret=registMacAddrToMngDb(macAddr,deviceName,userId,extraId, mailAddress);
850 if(debug>1) err_msg("DEBUG:(%d)<=registMacAddrToMngDb( )",ret);
854 int IsMacAddrFoundInMngDb(char* macAddr){
856 if(debug>1) err_msg("DEBUG:=>isMacAddrFoundInMngDb(%s)", macAddr);
857 ret=isMacAddrFoundInMngDb(macAddr);
858 if(debug>1) err_msg("DEBUG:(%d)<=isMacAddrFoundInMngDb( )",ret);
862 int CountMacAddrsForUserInMngDb(char* userId, char* extraId){
864 if(debug>1) err_msg("DEBUG:=>countMacAddrsForUserInMngDb(%s,%s)",
866 ret=countMacAddrsForUserInMngDb(userId,extraId);
867 if(debug>1) err_msg("DEBUG:(%d)<=countMacAddrsForUserInMngDb( )",ret);
871 int PutMacModifyLogToMngDb(char* userId, char* extraId, char* macAddr, char modifyType){
873 if(debug>1) err_msg("DEBUG:=>putMacModifyLogToMngDb(%s,%s,%s,%c)",
874 userId,extraId,macAddr,modifyType);
875 ret=putMacModifyLogToMngDb(userId,extraId,macAddr,modifyType);
876 if(debug>1) err_msg("DEBUG:(%d)<=putMacModifyLogToMngDb( )",ret);
880 int GetNicVendorFromMngDb(char* macAddress, char* vendor, int bufferLength){
882 if(debug>1) err_msg("DEBUG:=>getNicVendorFromMngDb(%s,,%d)",
883 macAddress, bufferLength);
884 ret=getNicVendorFromMngDb(macAddress, vendor, bufferLength);
885 if(debug>1) err_msg("DEBUG:(%d)<=getNicVendorFromMngDb(%s)",ret, vendor);
890 int CountMacModifyPerDayInMngDb(char* userId, char* extraId, char* macAddress){
892 if(debug>1) err_msg("DEBUG:=>countMacModifyPerDayInMngDb(%s,%s,%s)",
893 userId,extraId,macAddress);
894 ret=countMacModifyPerDayInMngDb(userId,extraId,macAddress);
895 if(debug>1) err_msg("DEBUG:(%d)<=countMacModifyPerDayInMngDb( )",ret);
899 int DelMacAddrFromMngDb(char* macAddr){
901 if(debug>1) err_msg("DEBUG:=>delMacAddrFromMngDb(%s)",macAddr);
902 ret=delMacAddrFromMngDb(macAddr);
903 if(debug>1) err_msg("DEBUG:(%d)<=delMacAddrFromMngDb( )",ret);
907 int RenewMacAddrInMngDb(char* macAddr){
909 if(debug>1) err_msg("DEBUG:=>renewMacAddrInMngDb(%s)",macAddr);
910 ret=renewMacAddrInMngDb(macAddr);
911 if(debug>1) err_msg("DEBUG:(%d)<=renewMacAddrinMngDb( )",ret);
915 int PauseMacAddrInMngDb(char* macAddr){
917 if(debug>1) err_msg("DEBUG:=>pauseMacAddrInMngDb(%s)",macAddr);
918 ret=pauseMacAddrInMngDb(macAddr);
919 if(debug>1) err_msg("DEBUG:(%d)<=pauseMacAddrinMngDb( )",ret);
923 int IsSessionFoundInMngDb(char* macAddr){
925 if(debug>1) err_msg("DEBUG:=>isSessionFoundInMngDb(%s)",macAddr);
926 ret=isSessionFoundInMngDb(macAddr);
927 if(debug>1) err_msg("DEBUG:(%d)<=isSessionFoundInMngDb( )",ret);
931 int GetNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr,
932 char* deviceName, char* openTime, char* closeTime, char* gatewayName){
934 if(debug>1) err_msg("DEBUG:=>getNextUsageLogFromMngDb(%s,%s)",userId,extraId);
935 ret=getNextUsageLogFromMngDb(userId,extraId,macAddr,deviceName,
936 openTime,closeTime,gatewayName);
937 if(debug>1) err_msg("DEBUG:(%d)<=getNextUsageLogFromMngDb(,,%s,%s,%s,%s,%s)",
938 ret,macAddr,deviceName,openTime,closeTime,gatewayName);
942 int GetNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char*device){
944 if(debug>1) err_msg("DEBUG:=>getnextMailAddressFromMngDb( )");
945 ret=getNextMailAddressFromMngDb(mailAddress, limitDate, device);
946 if(debug>1) err_msg("DEBUG:(%d)<=getNextMailAddressFromMngDb(%s,%s,%s)",
947 ret,mailAddress,limitDate,device);
951 int GetTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount){
953 if(debug>1) err_msg("DEBUG:=>getTimeRangeToShowLog( )");
954 ret=getTimeRangeToShowLog(beginTime, endTime, dateCount);
955 if(debug>1) err_msg("DEBUG:(%d)<=getTimeRangeToShowLog(%s,%s,%d)",
956 ret,beginTime,endTime,*dateCount);
960 int RenameDeviceNameInMngDb(char* macAddr, char* nameStr){
962 if(debug>1) err_msg("DEBUG:=>renameDevideNameInMngDb(%s,%s)",macAddr,nameStr);
963 ret=renameDeviceNameInMngDb(macAddr, nameStr);
964 if(debug>1) err_msg("DEBUG:(%d)<=renameDeviceNameInMngDb()",ret);
968 int RenameMailAddressInMngDb(char* macAddr, char* mailStr){
970 if(debug>1) err_msg("DEBUG:=>renameMailAddressInMngDb(%s,%s)",macAddr,mailStr);
971 ret=renameMailAddressInMngDb(macAddr, mailStr);
972 if(debug>1) err_msg("DEBUG:(%d)<=renameMailAddressInMngDb()",ret);
976 int RegOrUpNobodyMacAddr(char* macAddress){
978 if(debug>1) err_msg("DEBUG:=>regOrUpNobodyMacAddr(%s)",macAddress);
979 ret=regOrUpNobodyMacAddr(macAddress);
980 if(debug>1) err_msg("DEBUG:(%d)<=regOrUpNobodyMacAddr()",ret);
985 int IsMacAddrStatusInactiveInMngDb(char* macAddress){
987 if(debug>1) err_msg("DEBUG:=>isMacAddrStatusInactiveInMngDb(%s)",macAddress);
988 ret=isMacAddrStatusInactiveInMngDb(macAddress);
989 if(debug>1) err_msg("DEBUG:(%d)<=isMacAddrStatusInactiveInMngDb()",ret);