OSDN Git Service

modified comments
[opengatem/opengatem.git] / mngsrc / opengatemup.c
1 /**************************************************
2 OpengateM - MAC address authentication system 
3  module for update cgi main
4
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.
9
10 Copyright (C) 2011 Opengate Project Team
11 Written by Yoshiaki Watanabe
12
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.
17
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.
22
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.
26
27 Email: watanaby@is.saga-u.ac.jp
28 **************************************************/
29
30 #include        "opengatemmng.h"
31
32 /***************************************************/
33 /*  main routine called as cgi from Web server     */
34 /***************************************************/
35 int  main(int argc, char **argv)
36 {
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 */
43
44   /* drop root privilege */
45   seteuid(getuid());
46
47   /* if this is executed in shell with '-v' option, show makedir */
48   /* this is prepared to show information about version */
49   if(argc>1){
50     if(strcmp(argv[1],"-v")==0){
51       printf("makedir: %s\n", MAKEDIR);
52     }else{
53       printf("This is cgi program\n");
54       printf("To show version, run this on console with '-v' option\n");
55     }
56     exit(0);
57   }
58
59   /* save program load path */
60   saveLoadPath(argv[0]);
61   progName = getProgramName();
62
63   /* prepare configuration file */
64   if(OpenConfFile()==-1){
65     PutMessageToClient("Check config file by running this cgi on console");
66     return 0;
67   }
68  
69   /* start log */
70   errToSyslog(atoi(GetConfValue("Syslog/Enable")));
71   openlog(progName, LOG_PID, atoi(GetConfValue("Syslog/Facility")));
72
73   /* initialize config */
74   InitConf();
75   if(!InitMngDb()) return 0;
76   if(!InitWorkDb()) return 0;
77
78   /* get language from query string */
79   GetLangFromQueryString(language);
80
81   /* get post data */
82   GetPostData(requestStr, BUFFMAXLN);
83
84   /* get userid. if not get, exit */
85   if(!GetUserId(requestStr, userId, extraId, language, NORMALUSER,
86                 GetConfValue("UpdateCgi"),mailDefault, "")){
87     CloseMngDb();
88     return 0;
89   }
90
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);
96     CloseMngDb();
97     return 0;
98   }
99
100   /* if any request is sent from client */
101   if(!isNull(requestStr)){
102     
103     /* analize string and execute requests */
104     if(AnalyzeUpdateRequestAndExecute(requestStr, userId, extraId)){
105       SetMessage(UpdateSuccess);
106     }
107   }
108
109   /* prepare response and send to client */
110   PutUpdatePageToClient(language, userId, extraId, ADMIN, "");
111
112   /* finalize */
113   CloseMngDb();
114   return 0;
115 }