1 /**************************************************
2 OpengateM - MAC address authentication system
3 module for update cgi main
5 This is used for updating the mac registration.
6 When accessing this, the list of registration address is shown
7 and update/delete/pause of the mac can be selected in the list.
8 the device name and mail address can also be edited.
10 Copyright (C) 2011 Opengate Project Team
11 Written by Yoshiaki Watanabe
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 Email: watanaby@is.saga-u.ac.jp
28 **************************************************/
30 #include "opengatemmng.h"
32 /***************************************************/
33 /* main routine called as cgi from Web server */
34 /***************************************************/
35 int main(int argc, char **argv)
37 char language[WORDMAXLN]=""; /* browser prefered language(e.g.:ja,en) */
38 char userId[USERMAXLN]=""; /* user id */
39 char extraId[USERMAXLN]=""; /* extra id used as user@extra */
40 char requestStr[BUFFMAXLN]=""; /* http request string */
41 char* progName=""; /* the name of this program in argv[0] */
42 char mailDefault[BUFFMAXLN]=""; /* default mail address to get warning */
44 /* drop root privilege */
47 /* if this is executed in shell with '-v' option, show makedir */
48 /* this is prepared to show information about version */
50 if(strcmp(argv[1],"-v")==0){
51 printf("makedir: %s\n", MAKEDIR);
53 printf("This is cgi program\n");
54 printf("To show version, run this on console with '-v' option\n");
59 /* save program load path */
60 saveLoadPath(argv[0]);
61 progName = getProgramName();
63 /* prepare configuration file */
64 if(OpenConfFile()==-1){
65 PutMessageToClient("Check config file by running this cgi on console");
70 errToSyslog(atoi(GetConfValue("Syslog/Enable")));
71 openlog(progName, LOG_PID, atoi(GetConfValue("Syslog/Facility")));
73 /* initialize config */
75 if(!InitMngDb()) return 0;
76 if(!InitWorkDb()) return 0;
78 /* get language from query string */
79 GetLangFromQueryString(language);
82 GetPostData(requestStr, BUFFMAXLN);
84 /* get userid. if not get, exit */
85 if(!GetUserId(requestStr, userId, extraId, language, NORMALUSER,
86 GetConfValue("UpdateCgi"),mailDefault, "")){
91 /* if many modify requests from the user per one day, ignore the request */
92 if(CountMacModifyPerDayInMngDb(userId, extraId, "")
93 > atoi(GetConfValue("MaxMacModifyPerDay"))){
94 SetMessage(ModifyCountOver);
95 PutDenyToClient(language);
100 /* if any request is sent from client */
101 if(!isNull(requestStr)){
103 /* analize string and execute requests */
104 if(AnalyzeUpdateRequestAndExecute(requestStr, userId, extraId)){
105 SetMessage(UpdateSuccess);
109 /* prepare response and send to client */
110 PutUpdatePageToClient(language, userId, extraId, ADMIN, "");