]>
Commit | Line | Data |
---|---|---|
8af06406 HS |
1 | /* SmoothWall setup program. |
2 | * | |
3 | * This program is distributed under the terms of the GNU General Public | |
4 | * Licence. See the file COPYING for details. | |
5 | * | |
6 | * (c) Lawrence Manning, 2001 | |
7 | * Contains main entry point, and misc functions. | |
8 | * | |
9 | * modified 16/11/2002 eoberlander - French language added | |
10 | * | |
11 | * $Id: main.c,v 1.4.2.7 2005/12/01 20:13:08 eoberlander Exp $ | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "setup.h" | |
16 | ||
17 | FILE *flog = NULL; | |
18 | char *mylog; | |
19 | ||
20 | char **ctr = NULL; | |
21 | ||
22 | int automode = 0; | |
23 | ||
24 | extern char *bz_tr[]; | |
25 | extern char *cs_tr[]; | |
26 | extern char *da_tr[]; | |
27 | extern char *en_tr[]; | |
28 | extern char *es_tr[]; | |
29 | extern char *fi_tr[]; | |
30 | extern char *fr_tr[]; | |
31 | extern char *hu_tr[]; | |
32 | extern char *la_tr[]; | |
33 | extern char *nl_tr[]; | |
34 | extern char *de_tr[]; | |
35 | extern char *tr_tr[]; | |
36 | extern char *it_tr[]; | |
37 | extern char *el_tr[]; | |
38 | extern char *sk_tr[]; | |
39 | extern char *so_tr[]; | |
40 | extern char *sv_tr[]; | |
41 | extern char *no_tr[]; | |
42 | extern char *pl_tr[]; | |
43 | extern char *pt_tr[]; | |
44 | extern char *vi_tr[]; | |
45 | ||
46 | int main(int argc, char *argv[]) | |
47 | { | |
48 | #ifdef LANG_EN_ONLY | |
49 | char *shortlangnames[] = { "en", NULL }; | |
50 | char **langtrs[] = { en_tr, NULL }; | |
51 | #elifdef LANG_ALL | |
52 | char *shortlangnames[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "sk", "so", "fi", "sv", "tr", "vi", NULL }; | |
53 | char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL }; | |
54 | #else | |
55 | char *shortlangnames[] = { "de", "en", NULL }; | |
56 | char **langtrs[] = { de_tr, en_tr, NULL }; | |
57 | #endif | |
58 | int choice; | |
59 | char *sections[11]; /* need to fill this out AFTER knowning lang */ | |
60 | int rc; | |
61 | struct keyvalue *kv; | |
62 | char selectedshortlang[STRING_SIZE] = "en"; | |
63 | char title[STRING_SIZE]; | |
64 | int langcounter; | |
65 | int autook = 0; | |
66 | ||
67 | /* Log file/terminal stuff. */ | |
68 | if (argc >= 2) | |
69 | mylog = argv[1]; | |
70 | else | |
71 | mylog = strdup("/root/setup.log"); | |
72 | ||
73 | if (!(flog = fopen(mylog, "w+"))) | |
74 | { | |
75 | printf("Couldn't open log terminal\n"); | |
76 | return 1; | |
77 | } | |
78 | ||
79 | if (argc >= 3) | |
80 | automode = 1; | |
81 | ||
82 | fprintf(flog, "Setup program started.\n"); | |
83 | ||
84 | kv = initkeyvalues(); | |
85 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) | |
86 | { | |
87 | printf("%s is not properly installed.\n", NAME); | |
88 | return 1; | |
89 | } | |
90 | findkey(kv, "LANGUAGE", selectedshortlang); | |
91 | ||
92 | for (langcounter = 0; langtrs[langcounter]; langcounter++) | |
93 | { | |
94 | if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0) | |
95 | { | |
96 | ctr = langtrs[langcounter]; | |
97 | break; | |
98 | } | |
99 | } | |
100 | ||
101 | if (!ctr) | |
102 | { | |
103 | /* zh,lt,ro,ru,th languages not available in setup, so use English */ | |
104 | for (choice = 0; shortlangnames[choice]; choice++) | |
105 | { | |
106 | if (strcmp(shortlangnames[choice], "en") == 0) | |
107 | break; | |
108 | } | |
109 | if (!shortlangnames[choice]) | |
110 | goto EXIT; | |
111 | ctr = langtrs[choice]; | |
112 | } | |
113 | ||
114 | sections[0] = ctr[TR_KEYBOARD_MAPPING]; | |
115 | sections[1] = ctr[TR_TIMEZONE]; | |
116 | sections[2] = ctr[TR_HOSTNAME]; | |
117 | sections[3] = ctr[TR_DOMAINNAME]; | |
118 | sections[4] = ctr[TR_ISDN_CONFIGURATION]; | |
119 | sections[5] = ctr[TR_NETWORKING]; | |
120 | sections[6] = ctr[TR_ROOT_PASSWORD]; | |
121 | sections[7] = ctr[TR_ADMIN_PASSWORD]; | |
122 | sections[8] = NULL; | |
123 | ||
124 | newtInit(); | |
125 | newtCls(); | |
126 | FILE *f_title; | |
127 | if ((f_title = fopen ("/etc/issue", "r"))) | |
128 | { | |
129 | fgets (title, STRING_SIZE, f_title); | |
130 | if (title[strlen(title) - 1] == '\n') | |
131 | title[strlen(title) - 1] = '\0'; | |
132 | fclose (f_title); | |
133 | } else { | |
134 | sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); | |
135 | } | |
136 | newtDrawRootText(14, 0, title); | |
137 | newtPushHelpLine(ctr[TR_HELPLINE]); | |
138 | ||
139 | if (automode == 0) | |
140 | { | |
141 | choice = 0; | |
142 | for (;;) | |
143 | { | |
144 | rc = newtWinMenu(ctr[TR_SECTION_MENU], | |
145 | ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11, | |
146 | sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL); | |
147 | ||
148 | if (rc == 2) | |
149 | break; | |
150 | ||
151 | switch (choice) | |
152 | { | |
153 | case 0: | |
154 | handlekeymap(); | |
155 | break; | |
156 | ||
157 | case 1: | |
158 | handletimezone(); | |
159 | break; | |
160 | ||
161 | case 2: | |
162 | handlehostname(); | |
163 | break; | |
164 | ||
165 | case 3: | |
166 | handledomainname(); | |
167 | break; | |
168 | ||
169 | case 4: | |
170 | handleisdn(); | |
171 | break; | |
172 | ||
173 | case 5: | |
174 | handlenetworking(); | |
175 | break; | |
176 | ||
177 | case 6: | |
178 | handlerootpassword(); | |
179 | break; | |
180 | ||
181 | case 7: | |
182 | handleadminpassword(); | |
183 | break; | |
184 | ||
185 | default: | |
186 | break; | |
187 | } | |
188 | } | |
189 | } | |
190 | else | |
191 | { | |
192 | if (!(handlekeymap())) | |
193 | goto EXIT; | |
194 | if (!(handletimezone())) | |
195 | goto EXIT; | |
196 | if (!(handlehostname())) | |
197 | goto EXIT; | |
198 | if (!(handledomainname())) | |
199 | goto EXIT; | |
200 | if (!(handleisdn())) | |
201 | goto EXIT; | |
202 | if (!(handlenetworking())) | |
203 | goto EXIT; | |
204 | if (!(handledhcp())) | |
205 | goto EXIT; | |
206 | if (!(handlerootpassword())) | |
207 | goto EXIT; | |
208 | if (!(handleadminpassword())) | |
209 | goto EXIT; | |
210 | ||
211 | autook = 1; | |
212 | } | |
213 | ||
214 | EXIT: | |
215 | if (automode != 0) | |
216 | { | |
217 | sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); | |
218 | if (autook) | |
219 | newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]); | |
220 | else | |
221 | newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]); | |
222 | } | |
223 | ||
224 | fprintf(flog, "Setup program ended.\n"); | |
225 | fflush(flog); | |
226 | fclose(flog); | |
227 | ||
228 | newtFinished(); | |
229 | ||
230 | return 0; | |
231 | } | |
232 |