1 /**************************************************
2 OpengateM - MAC address authentication system
5 Copyright (C) 2011 Opengate Project Team
6 Written by Yoshiaki Watanabe
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 Email: watanaby@is.saga-u.ac.jp
23 **************************************************/
25 #include "opengatemmng.h"
27 /***************************************************/
28 /* main routine called as cgi from Web server */
29 /***************************************************/
30 int main(int argc, char **argv)
32 char language[WORDMAXLN]=""; /* browser prefered language(e.g.:ja,en) */
33 char userId[USERMAXLN]=""; /* user id */
34 char extraId[USERMAXLN]=""; /* extra id used as user@extra */
35 char requestStr[BUFFMAXLN]=""; /* http request string */
36 char* progName=""; /* the name of this program in argv[0] */
37 char mailDefault[BUFFMAXLN]=""; /* default mail address to get warning */
39 /* drop root privilege */
42 /* if this is executed in shell with '-v' option, show makedir */
43 /* this is prepared to show information about version */
45 if(strcmp(argv[1],"-v")==0){
46 printf("makedir: %s\n", MAKEDIR);
48 printf("This is cgi program\n");
49 printf("To show version, run this on console with '-v' option\n");
54 /* save program load path */
55 saveLoadPath(argv[0]);
56 progName = getProgramName();
58 /* prepare configuration file */
59 if(OpenConfFile()==-1){
60 PutMessageToClient("Check config file by running this cgi on console");
65 errToSyslog(atoi(GetConfValue("Syslog/Enable")));
66 openlog(progName, LOG_PID, atoi(GetConfValue("Syslog/Facility")));
68 /* initialize config */
70 if(!InitMngDb()) return 0;
71 if(!InitWorkDb()) return 0;
73 /* get language from query string */
74 GetLangFromQueryString(language);
77 GetPostData(requestStr, BUFFMAXLN);
79 /* get userid. if not get, exit */
80 if(!GetUserId(requestStr, userId, extraId, language, NORMALUSER,
81 GetConfValue("UpdateCgi"),mailDefault, "")){
86 /* if many modify requests per one day, ignore the request */
87 if(CountMacModifyPerDayInMngDb(userId,extraId)
88 > atoi(GetConfValue("MaxMacModifyPerDay"))){
89 SetMessage(ModifyCountOver);
90 PutDenyToClient(language);
95 /* check null request from client */
96 if(!isNull(requestStr)){
98 /* analize string and execute requests */
99 if(AnalyzeUpdateRequestAndExecute(requestStr, userId, extraId)){
100 SetMessage(UpdateSuccess);
104 /* prepare response and send to client */
105 PutUpdatePageToClient(language, userId, extraId, ADMIN, "");