1 /**************************************************
2 OpengateM - MAC address authentication system
4 module for construction of multi-language messages
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()'.
12 Copyright (C) 2011 Opengate Project Team
13 Written by Yoshiaki Watanabe
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.
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.
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.
29 Email: watanaby@is.saga-u.ac.jp
31 Programmed by Yoshiaki WATANABE
32 **************************************************/
34 #include "opengatemmng.h"
36 int messageSet[ENDOFLIST]={0}; /* to enable a message, set the index true */
38 /*******************************/
40 /* enable the 'msgNo' message */
41 /*******************************/
42 void setMessage(int msgNo){
44 if(msgNo < ENDOFLIST) messageSet[msgNo]=TRUE;
47 /*******************************/
49 /* disable all messages */
50 /*******************************/
51 void resetMessage(void){
53 for(i=0;i<ENDOFLIST;i++) messageSet[i]=FALSE;
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){
64 char* (*pMessageFunc)(int msgNo);
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;
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;
75 /* if no conf value, use english message */
76 else pMessageFunc=messagesInEn;
78 /* print messages that flag on */
79 for(i=0; i<ENDOFLIST; i++){
80 if(messageSet[i]) printf("%s<br>\n",(*pMessageFunc)(i));
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];
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で登録を削除する必要があります。";
138 return messages[msgNo];
141 /************************************/
142 /* make weekday string for language */
143 /************************************/
144 char* weekdayStr(int weekday, char* str, char* language){
146 char* weekdayStrEn[7]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
147 char* weekdayStrJa[7]={"月","火","水","木","金","土","日"};
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];
157 /**********************************
158 *********************************/
159 void SetMessage(int msgNo){
160 if(debug>1) err_msg("DEBUG:=>setMessage(%d)", msgNo);
162 if(debug>1) err_msg("DEBUG:<=setMessage( )");
165 void ResetMessage(void){
166 if(debug>1) err_msg("DEBUG:=>resetMessage()");
168 if(debug>1) err_msg("DEBUG:<=resetMessage( )");
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( )");
177 char* WeekdayStr(int weekday, char* str, char* language){
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);