OSDN Git Service

modified code to prevent DB inflation
[opengatem/opengatem.git] / mngsrc / messages.c
1 /**************************************************
2 OpengateM - MAC address authentication system 
3
4  module for construction of multi-language messages
5
6  To enable the 'msgNo' message, call as 'SetMessage(msgNo)'.
7  (The msgNo and message string is in messagesInJa/messagesInEn)
8  To insert enabled messages, call as 'InsertMessageToPage("ja")'.
9  (At '%%ERRORLIST%%' in html template, 'ja' messages are inserted)
10  To disable all messages, call as 'ResetMessage()'.
11
12 Copyright (C) 2011 Opengate Project Team
13 Written by Yoshiaki Watanabe
14
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 2
18 of the License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28
29 Email: watanaby@is.saga-u.ac.jp
30
31 Programmed by Yoshiaki WATANABE
32 **************************************************/
33
34 #include        "opengatemmng.h"
35
36 int messageSet[ENDOFLIST]={0};  /* to enable a message, set the index true */
37
38 /*******************************/
39 /* set message                 */
40 /* enable the 'msgNo' message  */
41 /*******************************/
42 void setMessage(int msgNo){
43
44   if(msgNo < ENDOFLIST) messageSet[msgNo]=TRUE;
45 }
46
47 /*******************************/
48 /* reset message               */
49 /* disable all messages        */
50 /*******************************/
51 void resetMessage(void){
52   int i;
53   for(i=0;i<ENDOFLIST;i++) messageSet[i]=FALSE;
54 }
55
56 /****************************************/
57 /* insert enables messages into page    */
58 /* language is 'ja' or 'en' at now.     */
59 /* if you want to add other languages,  */
60 /* add messagesIn??, and call form this */
61 /****************************************/
62 void insertMessageToPage(char* language){
63   
64   char* (*pMessageFunc)(int msgNo);
65   int i;
66
67   /* get message in language indicated in argument */
68   if(strcmp(language, "ja")==0)      pMessageFunc=messagesInJa;
69   else if(strcmp(language, "en")==0) pMessageFunc=messagesInEn;
70
71   /* if not indicated in argument, use conf value */
72   else if(strcmp(GetConfValue("HtmlLangs"),"ja")==0) pMessageFunc=messagesInJa;
73   else if(strcmp(GetConfValue("HtmlLangs"),"en")==0) pMessageFunc=messagesInEn;
74
75   /* if no conf value, use english message */
76   else                               pMessageFunc=messagesInEn;
77
78   /* print messages that flag on */
79   for(i=0; i<ENDOFLIST; i++){
80     if(messageSet[i]) printf("%s<br>\n",(*pMessageFunc)(i));
81   }
82 }
83
84 /******************************/
85 /* message in english         */
86 /******************************/
87 char* messagesInEn(int msgNo){
88   char* messages[ENDOFLIST];
89   messages[ExistentMacAddr]="Error: Mac address is already registered. Update or delete it.";
90   messages[DeviceCountOver]="Error: Device count reachs to the limit per one user. To register new device, remove a registered device.";
91   messages[IllegalMacAddrForm]= "Error: Mac address format is illegal.";
92   messages[IllegalCharInDevice]="Error: Not permitted character is found in device name.";
93   messages[IllegalCharInMailAddr]="Error: Not permitted character is found in mail address.";
94   messages[EmptyDeviceName]="Error: Registration device name is empty.";
95   messages[SuspectNat]="Error: Mac Address cannot detect. Accessed via NAT or router.";
96   messages[NoInfoInDb]="Error: Cannot get user information.";
97   messages[IllegalUserId]="Error: Illegal userId.";
98   messages[IllegalMacAddr]="Error: Illegal MAC address.";
99   messages[NoService]="Error: Cannot serve now.";
100   messages[NoDaemon]="Error: Resident program mulfunctions. Contact to the administrator.";
101   messages[ModifyCountOver]="Error: Modification count overflows. Retry after one day.";  
102   messages[RegisterSuccess]="Registration is performed. Network is enabled.";
103   messages[UpdateSuccess]="Update is performed.";
104   messages[IllegalCookie]="Error: Cannot get correct cookie.";
105   messages[NotSetAdminCookie]="Error: Cannot found admin cookie. Enter from check page.";
106   messages[RequestAdminAuth]="Enter Administrator's userID and password.";
107   messages[UnallowableAgent]="Cannot recognize the terminal to be allowable.";
108   messages[MacBelongToOther]="Accessing terminal belongs to other user. To register the terminal, the user should delete the registration.";
109   return messages[msgNo];
110 }
111
112 /*************************************/
113 /* error message in japanese (utf-8) */
114 /*************************************/
115 char* messagesInJa(int msgNo){
116   char* messages[ENDOFLIST];
117   messages[ExistentMacAddr]= "エラー:既登録のMACアドレスです。更新または削除をしてください。";
118   messages[DeviceCountOver]= "エラー:一人当りの許容機器数に達しています。新たな機器を登録するには登録済の一つを削除してください。";
119   messages[IllegalMacAddrForm]=  "エラー:MACアドレスの形式が不正です。";
120   messages[IllegalCharInDevice]="エラー:許容されていない文字が機器名にあります。";
121   messages[IllegalCharInMailAddr]="エラー:許容されていない文字がメールアドレスにあります。";
122   messages[EmptyDeviceName]= "エラー:機器名が入力されていません。";
123   messages[SuspectNat]=  "エラー:NAT/Router経由なのでMACアドレスが取れません。";
124   messages[NoInfoInDb]="エラー:ユーザ情報を得られません。";
125   messages[IllegalUserId]="エラー:不正なユーザIDです。";
126   messages[IllegalMacAddr]="エラー:不正なMACアドレスです。";
127   messages[NoService]="エラー:サービスを提供できません。";
128   messages[NoDaemon]="エラー: 常駐プログラムが不調です。管理者に連絡下さい。";
129   messages[ModifyCountOver]="エラー: 変更回数が制限を越えました。1日経ってから実行下さい。";
130   messages[RegisterSuccess]="登録を完了しました。ネットワークを利用できます。";
131   messages[UpdateSuccess]="更新を完了しました。";
132   messages[IllegalCookie]="エラー: 正しいCookieを取得できません。";
133   messages[NotSetAdminCookie]="エラー : 管理者のCookieを取得できません。チェックページから入って下さい。";
134   messages[RequestAdminAuth]="管理者のIDとPasswordを入力してください。";
135   messages[UnallowableAgent]="登録許容端末と認識できません。";
136   messages[MacBelongToOther]="エラー : 別ユーザIDの登録端末です。再登録するには、そのユーザIDで登録を削除する必要があります。";
137 ;
138   return messages[msgNo];
139 }
140
141 /************************************/
142 /* make weekday string for language */
143 /************************************/
144 char* weekdayStr(int weekday, char* str, char* language){
145
146   char* weekdayStrEn[7]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
147   char* weekdayStrJa[7]={"月","火","水","木","金","土","日"};
148
149   if(strcmp(language, "ja")==0)      str=weekdayStrJa[weekday];
150   else if(strcmp(language, "en")==0) str=weekdayStrEn[weekday];
151   else if(strcmp(GetConfValue("HtmlLangs"),"ja")==0) str=weekdayStrJa[weekday];
152   else if(strcmp(GetConfValue("HtmlLangs"),"en")==0) str=weekdayStrEn[weekday];
153   else                               str=weekdayStrEn[weekday];
154   return str;
155 }
156
157 /**********************************
158  *********************************/
159 void SetMessage(int msgNo){
160   if(debug>1) err_msg("DEBUG:=>setMessage(%d)", msgNo);
161   setMessage(msgNo);
162   if(debug>1) err_msg("DEBUG:<=setMessage( )");
163 }
164
165 void ResetMessage(void){
166   if(debug>1) err_msg("DEBUG:=>resetMessage()");
167   resetMessage();
168   if(debug>1) err_msg("DEBUG:<=resetMessage( )");
169 }
170
171 void InsertMessageToPage(char* language){
172   if(debug>1) err_msg("DEBUG:=>insertMessageToPage(%s)",language);
173   insertMessageToPage(language);
174   if(debug>1) err_msg("DEBUG:<=insertMessageToPage( )");
175 }
176
177 char* WeekdayStr(int weekday, char* str, char* language){
178   char* ret;
179   if(debug>1) err_msg("DEBUG:=>weekdayStr(%d,,%s)",weekday,language);
180   ret=weekdayStr(weekday,str,language);
181   if(debug>1) err_msg("DEBUG:<=weekdayStr(%s)",str);
182   return ret;
183 }
184
185