]>
Commit | Line | Data |
---|---|---|
069680ac MT |
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 | * The big one: networking. | |
8 | * | |
069680ac MT |
9 | */ |
10 | ||
11 | #include "setup.h" | |
12 | ||
13 | #define DNS1 0 | |
14 | #define DNS2 1 | |
15 | #define DEFAULT_GATEWAY 2 | |
16 | #define DNSGATEWAY_TOTAL 3 | |
17 | ||
18 | extern FILE *flog; | |
19 | extern char *mylog; | |
20 | ||
21 | extern char **ctr; | |
22 | ||
23 | extern int automode; | |
24 | ||
5057b611 | 25 | #define HAS_GREEN 1 |
9b040aa0 HS |
26 | #define HAS_RED (configtype == 1 || configtype == 2 || configtype == 3 || configtype == 4) |
27 | #define HAS_ORANGE (configtype == 2 || configtype == 4) | |
28 | #define HAS_BLUE (configtype == 3 || configtype == 4) | |
29 | #define RED_IS_NOT_ETH (configtype == 0) | |
30 | ||
069680ac | 31 | extern struct nic nics[]; |
5057b611 | 32 | extern struct knic knics[]; |
069680ac | 33 | |
a358af8c | 34 | char *configtypenames[] = { |
9b040aa0 HS |
35 | "GREEN + RED", |
36 | "GREEN + RED + ORANGE", | |
37 | "GREEN + RED + BLUE", | |
38 | "GREEN + RED + ORANGE + BLUE", | |
39 | NULL }; | |
40 | int configtypecards[] = { | |
9b040aa0 HS |
41 | 2, // "GREEN + RED", |
42 | 3, // "GREEN + RED + ORANGE", | |
43 | 3, // "GREEN + RED + BLUE", | |
44 | 4 // "GREEN + RED + ORANGE + BLUE", | |
45 | }; | |
46 | ||
47 | ||
069680ac MT |
48 | int netaddresschange; |
49 | ||
50 | int oktoleave(char *errormessage); | |
51 | int firstmenu(void); | |
52 | int configtypemenu(void); | |
53 | int drivermenu(void); | |
54 | int changedrivers(void); | |
55 | int greenaddressmenu(void); | |
56 | int addressesmenu(void); | |
57 | int dnsgatewaymenu(void); | |
58 | ||
59 | int handlenetworking(void) | |
60 | { | |
61 | int done; | |
62 | int choice; | |
9b040aa0 | 63 | int found; |
069680ac MT |
64 | char errormessage[STRING_SIZE]; |
65 | ||
66 | netaddresschange = 0; | |
67 | ||
9b040aa0 | 68 | found = scan_network_cards(); |
9c1c1c57 | 69 | found = init_knics(); |
9b040aa0 | 70 | |
069680ac MT |
71 | done = 0; |
72 | while (!done) | |
73 | { | |
74 | choice = firstmenu(); | |
75 | ||
76 | switch (choice) | |
77 | { | |
78 | case 1: | |
79 | configtypemenu(); | |
80 | break; | |
81 | ||
82 | case 2: | |
83 | drivermenu(); | |
84 | break; | |
85 | ||
86 | case 3: | |
87 | addressesmenu(); | |
88 | break; | |
89 | ||
90 | case 4: | |
91 | dnsgatewaymenu(); | |
92 | break; | |
93 | ||
94 | case 0: | |
95 | if (oktoleave(errormessage)) | |
96 | done = 1; | |
97 | else | |
98 | errorbox(errormessage); | |
99 | break; | |
100 | ||
101 | default: | |
102 | break; | |
103 | } | |
104 | } | |
105 | ||
106 | if (automode == 0) | |
107 | { | |
108 | /* Restart networking! */ | |
109 | if (netaddresschange) | |
110 | { | |
111 | runcommandwithstatus("/etc/rc.d/init.d/network stop", | |
112 | ctr[TR_PUSHING_NETWORK_DOWN]); | |
eea0467a HS |
113 | |
114 | rename_nics(); | |
115 | ||
069680ac MT |
116 | runcommandwithstatus("/etc/rc.d/init.d/network start", |
117 | ctr[TR_PULLING_NETWORK_UP]); | |
069680ac MT |
118 | } |
119 | } | |
84e975ba | 120 | create_udev(); |
069680ac MT |
121 | return 1; |
122 | } | |
123 | ||
124 | int oktoleave(char *errormessage) | |
125 | { | |
126 | struct keyvalue *kv = initkeyvalues(); | |
127 | char temp[STRING_SIZE]; | |
128 | int configtype; | |
129 | ||
130 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
131 | { | |
132 | freekeyvalues(kv); | |
133 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
134 | return 0; | |
135 | } | |
136 | ||
137 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); | |
de53a053 | 138 | if (configtype < 1 || configtype > 4) configtype = 0; |
069680ac | 139 | |
f93a4b4f | 140 | if (HAS_GREEN) |
069680ac | 141 | { |
f93a4b4f | 142 | strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); |
069680ac MT |
143 | if (!(strlen(temp))) |
144 | { | |
f93a4b4f | 145 | strcpy(errormessage, ctr[TR_NO_GREEN_INTERFACE]); |
069680ac MT |
146 | goto EXIT; |
147 | } | |
f93a4b4f | 148 | if (!(interfacecheck(kv, "GREEN"))) |
069680ac | 149 | { |
f93a4b4f HS |
150 | strcpy(errormessage, "(TR) GRÜNE IP nicht konfiguriert.\n"); //ctr[TR_MISSING_GREEN_IP]); |
151 | goto EXIT; | |
152 | } | |
153 | } | |
154 | if (HAS_RED) | |
155 | { | |
156 | strcpy(temp, ""); findkey(kv, "RED_DEV", temp); | |
157 | if (!(strlen(temp))) | |
158 | { | |
159 | strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); | |
160 | goto EXIT; | |
161 | } | |
162 | if (!(interfacecheck(kv, "RED"))) | |
163 | { | |
164 | strcpy(errormessage, ctr[TR_MISSING_RED_IP]); | |
069680ac MT |
165 | goto EXIT; |
166 | } | |
167 | } | |
168 | if (HAS_ORANGE) | |
169 | { | |
170 | strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); | |
171 | if (!(strlen(temp))) | |
172 | { | |
173 | strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]); | |
174 | goto EXIT; | |
175 | } | |
176 | if (!(interfacecheck(kv, "ORANGE"))) | |
177 | { | |
178 | strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]); | |
179 | goto EXIT; | |
180 | } | |
181 | } | |
f93a4b4f | 182 | if (HAS_BLUE) |
069680ac | 183 | { |
f93a4b4f | 184 | strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); |
069680ac MT |
185 | if (!(strlen(temp))) |
186 | { | |
f93a4b4f | 187 | strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); |
069680ac MT |
188 | goto EXIT; |
189 | } | |
f93a4b4f | 190 | if (!(interfacecheck(kv, "BLUE"))) |
069680ac | 191 | { |
f93a4b4f HS |
192 | strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); |
193 | goto EXIT; | |
194 | } | |
195 | } | |
196 | if (configtype == 0) | |
197 | { | |
198 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
199 | if (!(strlen(temp))) | |
200 | { | |
201 | strcpy(errormessage, "(TR) Kein DNS eingetragen\n"); | |
202 | goto EXIT; | |
203 | } | |
204 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
205 | if (!(strlen(temp))) | |
206 | { | |
207 | strcpy(errormessage, "(TR) Kein default Gateway eingetragen.\n"); | |
069680ac MT |
208 | goto EXIT; |
209 | } | |
210 | } | |
211 | strcpy(errormessage, ""); | |
212 | EXIT: | |
213 | freekeyvalues(kv); | |
214 | ||
215 | if (strlen(errormessage)) | |
216 | return 0; | |
217 | else | |
218 | return 1; | |
219 | } | |
220 | ||
221 | ||
222 | /* Shows the main menu and a summary of the current settings. */ | |
223 | int firstmenu(void) | |
224 | { | |
225 | char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], | |
226 | ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], | |
227 | ctr[TR_ADDRESS_SETTINGS], | |
228 | ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL }; | |
229 | int rc; | |
230 | static int choice = 0; | |
231 | struct keyvalue *kv = initkeyvalues(); | |
232 | char message[1000]; | |
233 | char temp[STRING_SIZE]; | |
234 | int x; | |
235 | int result; | |
236 | char networkrestart[STRING_SIZE] = ""; | |
237 | ||
238 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
239 | { | |
240 | freekeyvalues(kv); | |
241 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
242 | return 0; | |
243 | } | |
244 | ||
245 | if (netaddresschange) | |
246 | strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); | |
247 | ||
248 | strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); | |
de53a053 | 249 | if (x < 1 || x > 4) x = 0; |
069680ac MT |
250 | /* Format heading bit. */ |
251 | snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], | |
252 | networkrestart); | |
253 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, | |
254 | sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
255 | ||
256 | if (rc == 0 || rc == 1) | |
257 | result = choice + 1; | |
258 | else | |
259 | result = 0; | |
260 | ||
261 | return result; | |
262 | } | |
263 | ||
264 | /* Here they choose general network config, number of nics etc. */ | |
265 | int configtypemenu(void) | |
266 | { | |
267 | struct keyvalue *kv = initkeyvalues(); | |
268 | char temp[STRING_SIZE] = "0"; | |
269 | char message[1000]; | |
9b040aa0 | 270 | int choise, found; |
069680ac MT |
271 | int rc; |
272 | ||
9b040aa0 HS |
273 | fprintf(flog,"Enter ConfigMenu\n"); |
274 | ||
069680ac MT |
275 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
276 | { | |
277 | freekeyvalues(kv); | |
278 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
279 | return 0; | |
280 | } | |
9b040aa0 HS |
281 | |
282 | found = scan_network_cards(); | |
069680ac | 283 | |
9b040aa0 HS |
284 | findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); |
285 | ||
286 | do | |
287 | { | |
288 | sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); | |
289 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, | |
290 | 6, configtypenames, &choise, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
291 | if ( configtypecards[choise] > found ) { | |
292 | sprintf(message, "(TR) Nicht genuegend Netzwerkkarten fuer diese Auswahl gefunden.\n\nBenoetigt: %d\nGefunden: %d\n", configtypecards[choise], found); | |
293 | errorbox(message); | |
294 | } | |
295 | } | |
296 | while ( configtypecards[choise] > found); | |
069680ac MT |
297 | |
298 | if (rc == 0 || rc == 1) | |
299 | { | |
a358af8c | 300 | choise++; |
9b040aa0 | 301 | sprintf(temp, "%d", choise); |
069680ac | 302 | replacekeyvalue(kv, "CONFIG_TYPE", temp); |
9b040aa0 HS |
303 | clear_card_entry(_RED_CARD_); |
304 | clear_card_entry(_ORANGE_CARD_); | |
305 | clear_card_entry(_BLUE_CARD_); | |
306 | ||
069680ac MT |
307 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); |
308 | netaddresschange = 1; | |
309 | } | |
069680ac MT |
310 | freekeyvalues(kv); |
311 | ||
312 | return 0; | |
313 | } | |
314 | ||
9c1c1c57 HS |
315 | |
316 | ||
069680ac MT |
317 | /* Driver menu. Choose drivers.. */ |
318 | int drivermenu(void) | |
319 | { | |
320 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 HS |
321 | char message[STRING_SIZE]; |
322 | char temp[STRING_SIZE]; | |
9c1c1c57 | 323 | |
069680ac | 324 | int configtype; |
9c1c1c57 | 325 | int i, rc, kcount = 0, neednics; //i = 0, count = 0, |
069680ac MT |
326 | |
327 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
328 | { | |
329 | freekeyvalues(kv); | |
330 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
331 | return 0; | |
332 | } | |
333 | ||
334 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
335 | configtype = atol(temp); | |
336 | ||
069680ac | 337 | strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); |
5057b611 | 338 | |
5057b611 HS |
339 | kcount = 0; // counter to find knowing nics. |
340 | neednics = 0; // counter to use needing nics. | |
341 | if (HAS_GREEN) { | |
5057b611 HS |
342 | sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); |
343 | strcat(message, temp); | |
344 | if (strlen(knics[_GREEN_CARD_].macaddr) ) { | |
345 | sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); | |
346 | strcat(message, temp); | |
347 | } | |
348 | neednics++; | |
75ae2191 | 349 | } |
5057b611 | 350 | if (HAS_RED) { |
5057b611 HS |
351 | sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); |
352 | strcat(message, temp); | |
353 | if (strlen(knics[_RED_CARD_].macaddr) ) { | |
354 | sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); | |
355 | strcat(message, temp); | |
75ae2191 | 356 | } |
5057b611 | 357 | neednics++; |
069680ac | 358 | } |
75ae2191 | 359 | if (HAS_ORANGE) { |
5057b611 HS |
360 | sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); |
361 | strcat(message, temp); | |
362 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
363 | sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); | |
364 | strcat(message, temp); | |
365 | } | |
366 | neednics++; | |
75ae2191 | 367 | } |
5057b611 | 368 | if (HAS_BLUE) { |
5057b611 HS |
369 | sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); |
370 | strcat(message, temp); | |
371 | if (strlen(knics[_BLUE_CARD_].macaddr)) { | |
372 | sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); | |
373 | strcat(message, temp); | |
75ae2191 | 374 | } |
5057b611 | 375 | neednics++; |
069680ac | 376 | } |
5057b611 | 377 | |
9c1c1c57 | 378 | for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; |
5057b611 | 379 | |
f93a4b4f HS |
380 | if (neednics = kcount) |
381 | { | |
5057b611 HS |
382 | strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); |
383 | rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], | |
069680ac | 384 | ctr[TR_CANCEL], message); |
5057b611 HS |
385 | if (rc == 0 || rc == 1) |
386 | { | |
387 | /* Shit, got to do something.. */ | |
388 | changedrivers(); | |
389 | } | |
390 | } else { | |
069680ac MT |
391 | /* Shit, got to do something.. */ |
392 | changedrivers(); | |
393 | } | |
069680ac MT |
394 | freekeyvalues(kv); |
395 | ||
396 | return 1; | |
397 | } | |
398 | ||
9b040aa0 HS |
399 | int set_menu_entry_for(int *nr, int *card) |
400 | { | |
401 | ||
402 | } | |
403 | ||
069680ac MT |
404 | int changedrivers(void) |
405 | { | |
406 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 | 407 | char temp[STRING_SIZE], message[STRING_SIZE]; |
069680ac | 408 | int configtype; |
75ae2191 | 409 | int green = 0, red = 0, blue = 0, orange = 0; |
5057b611 HS |
410 | char MenuInhalt[10][180]; |
411 | char *pMenuInhalt[10]; | |
412 | int count = 0, choise = 0, rc; | |
413 | int NicEntry[10]; | |
59de0b00 | 414 | |
069680ac MT |
415 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
416 | { | |
417 | freekeyvalues(kv); | |
418 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
419 | return 0; | |
420 | } | |
75ae2191 MT |
421 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", |
422 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
59de0b00 | 423 | |
5057b611 | 424 | findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); |
a358af8c | 425 | if (configtype == 1) |
75ae2191 | 426 | { green = 1; red = 1; } |
9b040aa0 | 427 | else if (configtype == 2) |
75ae2191 | 428 | { green = 1; red = 1; orange = 1; } |
9b040aa0 | 429 | else if (configtype == 3) |
75ae2191 | 430 | { green = 1; red = 1; blue = 1; } |
9b040aa0 HS |
431 | else if (configtype == 4) |
432 | { green = 1; red=1; orange=1; blue = 1; } | |
5057b611 HS |
433 | |
434 | do | |
435 | { | |
436 | count = 0; | |
437 | strcpy(message, "(TR) Bitte wählen Sie das Interface aus das geaendert werden soll.\n\n"); | |
438 | ||
439 | if (green) { | |
440 | strcpy(MenuInhalt[count], "GREEN"); | |
441 | pMenuInhalt[count] = MenuInhalt[count]; | |
442 | NicEntry[_GREEN_CARD_] = count; | |
5057b611 HS |
443 | sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); |
444 | strcat(message, temp); | |
445 | if ( strlen(knics[_GREEN_CARD_].macaddr) ) { | |
446 | sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); | |
447 | strcat(message, temp); | |
448 | } | |
449 | count++; | |
450 | } | |
451 | ||
452 | if (red) { | |
453 | strcpy(MenuInhalt[count], "RED"); | |
454 | pMenuInhalt[count] = MenuInhalt[count]; | |
455 | NicEntry[_RED_CARD_] = count; | |
5057b611 HS |
456 | sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); |
457 | strcat(message, temp); | |
458 | if ( strlen(knics[_RED_CARD_].macaddr) ) { | |
459 | sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); | |
460 | strcat(message, temp); | |
461 | } | |
462 | count++; | |
463 | } | |
464 | ||
465 | if (orange) { | |
466 | strcpy(MenuInhalt[count], "ORANGE"); | |
467 | pMenuInhalt[count] = MenuInhalt[count]; | |
468 | NicEntry[_ORANGE_CARD_] = count; | |
5057b611 HS |
469 | sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); |
470 | strcat(message, temp); | |
471 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
472 | sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); | |
473 | strcat(message, temp); | |
474 | } | |
475 | count++; | |
476 | } | |
477 | ||
478 | if (blue) { | |
479 | strcpy(MenuInhalt[count], "BLUE"); | |
480 | pMenuInhalt[count] = MenuInhalt[count]; | |
481 | NicEntry[_BLUE_CARD_] = count; | |
5057b611 HS |
482 | sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); |
483 | strcat(message, temp); | |
484 | if ( strlen(knics[_BLUE_CARD_].macaddr) ) { | |
485 | sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); | |
486 | strcat(message, temp); | |
487 | } | |
488 | count++; | |
489 | } | |
490 | pMenuInhalt[count] = NULL; | |
491 | ||
492 | rc = newtWinMenu("(TR) Netcard Farbe", message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], "(TR) Entfernen" , ctr[TR_DONE], NULL); | |
493 | ||
494 | if ( rc == 0 || rc == 1) { | |
9b040aa0 HS |
495 | if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_); |
496 | if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_); | |
497 | if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_); | |
498 | if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_); | |
eea0467a | 499 | netaddresschange = 1; |
5057b611 | 500 | } else if (rc == 2) { |
9b040aa0 HS |
501 | if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_); |
502 | if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_); | |
503 | if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_); | |
504 | if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_); | |
eea0467a | 505 | netaddresschange = 1; |
a358af8c | 506 | } |
5057b611 HS |
507 | } |
508 | while ( rc <= 2); | |
069680ac MT |
509 | |
510 | freekeyvalues(kv); | |
069680ac MT |
511 | return 1; |
512 | } | |
513 | ||
75ae2191 | 514 | // Let user change GREEN address. |
069680ac MT |
515 | int greenaddressmenu(void) |
516 | { | |
517 | struct keyvalue *kv = initkeyvalues(); | |
518 | char message[1000]; | |
519 | int rc; | |
520 | ||
521 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
522 | { | |
523 | freekeyvalues(kv); | |
524 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
525 | return 0; | |
526 | } | |
527 | ||
528 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
529 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); | |
530 | ||
531 | if (rc == 0 || rc == 1) | |
532 | { | |
533 | if (changeaddress(kv, "GREEN", 0, "")) | |
534 | { | |
535 | netaddresschange = 1; | |
536 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
537 | writehostsfiles(); | |
538 | } | |
539 | } | |
540 | ||
541 | freekeyvalues(kv); | |
542 | ||
543 | return 0; | |
544 | } | |
545 | ||
75ae2191 | 546 | // They can change BLUE, ORANGE and GREEN too :) |
069680ac MT |
547 | int addressesmenu(void) |
548 | { | |
549 | struct keyvalue *kv = initkeyvalues(); | |
550 | struct keyvalue *mainkv = initkeyvalues(); | |
551 | int rc = 0; | |
552 | char *sections[5]; | |
553 | char *green = "GREEN"; | |
554 | char *orange = "ORANGE"; | |
555 | char *blue = "BLUE"; | |
556 | char *red = "RED"; | |
557 | int c = 0; | |
558 | char greenaddress[STRING_SIZE]; | |
559 | char oldgreenaddress[STRING_SIZE]; | |
560 | char temp[STRING_SIZE]; | |
561 | char temp2[STRING_SIZE]; | |
562 | char message[1000]; | |
563 | int configtype; | |
564 | int done; | |
565 | int choice; | |
566 | char hostname[STRING_SIZE]; | |
567 | ||
568 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
569 | { | |
570 | freekeyvalues(kv); | |
571 | freekeyvalues(mainkv); | |
572 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
573 | return 0; | |
574 | } | |
575 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
576 | { | |
577 | freekeyvalues(kv); | |
578 | freekeyvalues(mainkv); | |
579 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
580 | return 0; | |
581 | } | |
582 | ||
583 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
584 | configtype = atol(temp); | |
585 | ||
586 | sections[c] = green; | |
587 | c++; | |
588 | if (HAS_BLUE) | |
589 | { | |
590 | sections[c] = blue; | |
591 | c++; | |
592 | } | |
593 | if (HAS_ORANGE) | |
594 | { | |
595 | sections[c] = orange; | |
596 | c++; | |
597 | } | |
598 | if (HAS_RED) | |
599 | { | |
600 | sections[c] = red; | |
601 | c++; | |
602 | } | |
603 | sections[c] = NULL; | |
604 | ||
605 | choice = 0; | |
606 | done = 0; | |
607 | while (!done) | |
608 | { | |
609 | rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], | |
610 | ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, | |
611 | 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
612 | ||
613 | if (rc == 0 || rc == 1) | |
614 | { | |
615 | if (strcmp(sections[choice], "GREEN") == 0) | |
616 | { | |
617 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
618 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
619 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], | |
620 | message); | |
621 | if (rc == 0 || rc == 1) | |
622 | { | |
623 | if (changeaddress(kv, "GREEN", 0, "")) | |
624 | { | |
625 | netaddresschange = 1; | |
626 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
627 | writehostsfiles(); | |
628 | findkey(kv, "GREEN_ADDRESS", greenaddress); | |
629 | snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); | |
630 | snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); | |
631 | replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); | |
632 | chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); | |
633 | } | |
634 | } | |
635 | } | |
636 | if (strcmp(sections[choice], "BLUE") == 0) | |
637 | { | |
638 | if (changeaddress(kv, "BLUE", 0, "")) | |
639 | netaddresschange = 1; | |
640 | } | |
641 | if (strcmp(sections[choice], "ORANGE") == 0) | |
642 | { | |
643 | if (changeaddress(kv, "ORANGE", 0, "")) | |
644 | netaddresschange = 1; | |
645 | } | |
646 | if (strcmp(sections[choice], "RED") == 0) | |
647 | { | |
648 | strcpy(hostname, ""); | |
649 | findkey(mainkv, "HOSTNAME", hostname); | |
650 | if (changeaddress(kv, "RED", 1, hostname)) | |
651 | netaddresschange = 1; | |
652 | } | |
653 | } | |
654 | else | |
655 | done = 1; | |
656 | } | |
657 | ||
658 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
659 | freekeyvalues(kv); | |
660 | freekeyvalues(mainkv); | |
661 | ||
662 | return 0; | |
663 | } | |
664 | ||
665 | /* DNS and default gateway.... */ | |
666 | int dnsgatewaymenu(void) | |
667 | { | |
668 | struct keyvalue *kv = initkeyvalues(); | |
669 | char message[1000]; | |
670 | char temp[STRING_SIZE] = "0"; | |
671 | struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; | |
672 | char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ | |
673 | int error; | |
674 | int configtype; | |
675 | int rc; | |
676 | ||
677 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
678 | { | |
679 | freekeyvalues(kv); | |
680 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
681 | return 0; | |
682 | } | |
683 | ||
069680ac MT |
684 | entries[DNS1].text = ctr[TR_PRIMARY_DNS]; |
685 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
686 | values[DNS1] = strdup(temp); | |
687 | entries[DNS1].value = &values[DNS1]; | |
688 | entries[DNS1].flags = 0; | |
689 | ||
690 | entries[DNS2].text = ctr[TR_SECONDARY_DNS]; | |
691 | strcpy(temp, ""); findkey(kv, "DNS2", temp); | |
692 | values[DNS2] = strdup(temp); | |
693 | entries[DNS2].value = &values[DNS2]; | |
694 | entries[DNS2].flags = 0; | |
695 | ||
696 | entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; | |
697 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
698 | values[DEFAULT_GATEWAY] = strdup(temp); | |
699 | entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; | |
700 | entries[DEFAULT_GATEWAY].flags = 0; | |
701 | ||
702 | entries[DNSGATEWAY_TOTAL].text = NULL; | |
703 | entries[DNSGATEWAY_TOTAL].value = NULL; | |
704 | entries[DNSGATEWAY_TOTAL].flags = 0; | |
705 | ||
706 | do | |
707 | { | |
708 | error = 0; | |
709 | ||
710 | rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], | |
711 | ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, | |
712 | ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
713 | if (rc == 0 || rc == 1) | |
714 | { | |
715 | strcpy(message, ctr[TR_INVALID_FIELDS]); | |
716 | if (strlen(values[DNS1])) | |
717 | { | |
718 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
719 | { | |
720 | strcat(message, ctr[TR_PRIMARY_DNS_CR]); | |
721 | error = 1; | |
722 | } | |
723 | } | |
724 | if (strlen(values[DNS2])) | |
725 | { | |
726 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
727 | { | |
728 | strcat(message, ctr[TR_SECONDARY_DNS_CR]); | |
729 | error = 1; | |
730 | } | |
731 | } | |
732 | if (strlen(values[DEFAULT_GATEWAY])) | |
733 | { | |
734 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
735 | { | |
736 | strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); | |
737 | error = 1; | |
738 | } | |
739 | } | |
740 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
741 | { | |
742 | strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); | |
743 | error = 1; | |
744 | } | |
745 | ||
746 | if (error) | |
747 | errorbox(message); | |
748 | else | |
749 | { | |
750 | replacekeyvalue(kv, "DNS1", values[DNS1]); | |
751 | replacekeyvalue(kv, "DNS2", values[DNS2]); | |
752 | replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); | |
753 | netaddresschange = 1; | |
754 | free(values[DNS1]); | |
755 | free(values[DNS2]); | |
756 | free(values[DEFAULT_GATEWAY]); | |
757 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
758 | } | |
759 | } | |
760 | } | |
761 | while (error); | |
762 | ||
763 | freekeyvalues(kv); | |
764 | ||
765 | return 1; | |
766 | } |