]>
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", | |
6fc15159 | 44 | 4 // "GREEN + RED + ORANGE + BLUE", |
9b040aa0 HS |
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 | ||
0db33b56 MT |
137 | strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); |
138 | if (configtype < 1 || configtype > 4) configtype = 1; | |
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 | { |
1700769c | 150 | strcpy(errormessage, ctr[TR_MISSING_GREEN_IP]); |
f93a4b4f HS |
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 | { | |
1700769c | 201 | strcpy(errormessage, ctr[TR_MISSING_DNS]); |
f93a4b4f HS |
202 | goto EXIT; |
203 | } | |
204 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
205 | if (!(strlen(temp))) | |
206 | { | |
1700769c | 207 | strcpy(errormessage, ctr[TR_MISSING_DEFAULT]); |
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]; | |
0db33b56 | 233 | char temp[STRING_SIZE] = "1"; |
069680ac MT |
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 | ||
d0f2cc42 MT |
248 | strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); |
249 | x = atol(temp); | |
250 | x--; | |
0db33b56 | 251 | if (x < 0 || x > 4) x = 0; |
069680ac | 252 | /* Format heading bit. */ |
d0f2cc42 | 253 | snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], |
069680ac MT |
254 | networkrestart); |
255 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, | |
256 | sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
257 | ||
258 | if (rc == 0 || rc == 1) | |
259 | result = choice + 1; | |
260 | else | |
261 | result = 0; | |
262 | ||
263 | return result; | |
264 | } | |
265 | ||
266 | /* Here they choose general network config, number of nics etc. */ | |
267 | int configtypemenu(void) | |
268 | { | |
269 | struct keyvalue *kv = initkeyvalues(); | |
0db33b56 | 270 | char temp[STRING_SIZE] = "1"; |
069680ac | 271 | char message[1000]; |
9b040aa0 | 272 | int choise, found; |
0db33b56 | 273 | int rc, configtype; |
9b040aa0 | 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 | 284 | findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); |
6fc15159 | 285 | choise--; |
9b040aa0 HS |
286 | |
287 | do | |
288 | { | |
289 | sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); | |
290 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, | |
291 | 6, configtypenames, &choise, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
292 | if ( configtypecards[choise] > found ) { | |
1700769c | 293 | sprintf(message, ctr[TR_NOT_ENOUGH_INTERFACES] , configtypecards[choise], found); |
9b040aa0 HS |
294 | errorbox(message); |
295 | } | |
296 | } | |
297 | while ( configtypecards[choise] > found); | |
069680ac MT |
298 | |
299 | if (rc == 0 || rc == 1) | |
300 | { | |
a358af8c | 301 | choise++; |
9b040aa0 | 302 | sprintf(temp, "%d", choise); |
069680ac | 303 | replacekeyvalue(kv, "CONFIG_TYPE", temp); |
0db33b56 MT |
304 | configtype = atol(temp); |
305 | if (!HAS_RED) | |
306 | clear_card_entry(_RED_CARD_); | |
307 | if (!HAS_ORANGE) | |
308 | clear_card_entry(_ORANGE_CARD_); | |
309 | if (!HAS_BLUE) | |
310 | clear_card_entry(_BLUE_CARD_); | |
9b040aa0 | 311 | |
069680ac MT |
312 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); |
313 | netaddresschange = 1; | |
314 | } | |
069680ac MT |
315 | freekeyvalues(kv); |
316 | ||
317 | return 0; | |
318 | } | |
319 | ||
320 | /* Driver menu. Choose drivers.. */ | |
321 | int drivermenu(void) | |
322 | { | |
323 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 | 324 | char message[STRING_SIZE]; |
0db33b56 | 325 | char temp[STRING_SIZE] = "1"; |
9c1c1c57 | 326 | |
069680ac | 327 | int configtype; |
0db33b56 | 328 | int i, rc, kcount = 0, neednics; |
069680ac MT |
329 | |
330 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
331 | { | |
332 | freekeyvalues(kv); | |
333 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
334 | return 0; | |
335 | } | |
336 | ||
4061c03f HS |
337 | if (findkey(kv, "CONFIG_TYPE", temp)) |
338 | configtype = atol(temp); | |
339 | else { | |
340 | fprintf(flog,"setting CONFIG_TYPE = %s\n",temp); | |
341 | configtype = atol(temp); | |
342 | replacekeyvalue(kv, "CONFIG_TYPE", temp); | |
343 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
344 | } | |
345 | ||
069680ac | 346 | strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); |
5057b611 | 347 | |
0db33b56 MT |
348 | kcount = 0; |
349 | neednics = 0; | |
5057b611 | 350 | if (HAS_GREEN) { |
5057b611 HS |
351 | sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); |
352 | strcat(message, temp); | |
353 | if (strlen(knics[_GREEN_CARD_].macaddr) ) { | |
354 | sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); | |
355 | strcat(message, temp); | |
356 | } | |
357 | neednics++; | |
75ae2191 | 358 | } |
5057b611 | 359 | if (HAS_RED) { |
5057b611 HS |
360 | sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); |
361 | strcat(message, temp); | |
362 | if (strlen(knics[_RED_CARD_].macaddr) ) { | |
363 | sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); | |
364 | strcat(message, temp); | |
75ae2191 | 365 | } |
5057b611 | 366 | neednics++; |
069680ac | 367 | } |
75ae2191 | 368 | if (HAS_ORANGE) { |
5057b611 HS |
369 | sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); |
370 | strcat(message, temp); | |
371 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
372 | sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); | |
373 | strcat(message, temp); | |
374 | } | |
375 | neednics++; | |
75ae2191 | 376 | } |
5057b611 | 377 | if (HAS_BLUE) { |
5057b611 HS |
378 | sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); |
379 | strcat(message, temp); | |
380 | if (strlen(knics[_BLUE_CARD_].macaddr)) { | |
381 | sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); | |
382 | strcat(message, temp); | |
75ae2191 | 383 | } |
5057b611 | 384 | neednics++; |
069680ac | 385 | } |
5057b611 | 386 | |
0db33b56 MT |
387 | for ( i=0 ; i<4; i++) |
388 | if (strcmp(knics[i].macaddr, "")) | |
389 | kcount++; | |
5057b611 | 390 | |
f93a4b4f HS |
391 | if (neednics = kcount) |
392 | { | |
5057b611 HS |
393 | strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); |
394 | rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], | |
069680ac | 395 | ctr[TR_CANCEL], message); |
5057b611 HS |
396 | if (rc == 0 || rc == 1) |
397 | { | |
5057b611 HS |
398 | changedrivers(); |
399 | } | |
400 | } else { | |
069680ac MT |
401 | changedrivers(); |
402 | } | |
069680ac MT |
403 | freekeyvalues(kv); |
404 | ||
405 | return 1; | |
406 | } | |
407 | ||
9b040aa0 HS |
408 | int set_menu_entry_for(int *nr, int *card) |
409 | { | |
410 | ||
411 | } | |
412 | ||
069680ac MT |
413 | int changedrivers(void) |
414 | { | |
415 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 | 416 | char temp[STRING_SIZE], message[STRING_SIZE]; |
069680ac | 417 | int configtype; |
75ae2191 | 418 | int green = 0, red = 0, blue = 0, orange = 0; |
5057b611 HS |
419 | char MenuInhalt[10][180]; |
420 | char *pMenuInhalt[10]; | |
421 | int count = 0, choise = 0, rc; | |
422 | int NicEntry[10]; | |
59de0b00 | 423 | |
069680ac MT |
424 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
425 | { | |
426 | freekeyvalues(kv); | |
427 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
428 | return 0; | |
429 | } | |
0db33b56 MT |
430 | if (automode == 0) |
431 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", | |
432 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
59de0b00 | 433 | |
5057b611 | 434 | findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); |
a358af8c | 435 | if (configtype == 1) |
75ae2191 | 436 | { green = 1; red = 1; } |
9b040aa0 | 437 | else if (configtype == 2) |
75ae2191 | 438 | { green = 1; red = 1; orange = 1; } |
9b040aa0 | 439 | else if (configtype == 3) |
75ae2191 | 440 | { green = 1; red = 1; blue = 1; } |
9b040aa0 HS |
441 | else if (configtype == 4) |
442 | { green = 1; red=1; orange=1; blue = 1; } | |
da6e926b CS |
443 | else if (configtype == "") |
444 | { green = 1; red = 1; } | |
5057b611 HS |
445 | |
446 | do | |
447 | { | |
448 | count = 0; | |
1700769c | 449 | strcpy(message, ctr[TR_INTERFACE_CHANGE]); |
5057b611 HS |
450 | |
451 | if (green) { | |
452 | strcpy(MenuInhalt[count], "GREEN"); | |
453 | pMenuInhalt[count] = MenuInhalt[count]; | |
454 | NicEntry[_GREEN_CARD_] = count; | |
5057b611 HS |
455 | sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); |
456 | strcat(message, temp); | |
457 | if ( strlen(knics[_GREEN_CARD_].macaddr) ) { | |
458 | sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); | |
459 | strcat(message, temp); | |
460 | } | |
461 | count++; | |
462 | } | |
463 | ||
464 | if (red) { | |
465 | strcpy(MenuInhalt[count], "RED"); | |
466 | pMenuInhalt[count] = MenuInhalt[count]; | |
467 | NicEntry[_RED_CARD_] = count; | |
5057b611 HS |
468 | sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); |
469 | strcat(message, temp); | |
470 | if ( strlen(knics[_RED_CARD_].macaddr) ) { | |
471 | sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); | |
472 | strcat(message, temp); | |
473 | } | |
474 | count++; | |
475 | } | |
476 | ||
477 | if (orange) { | |
478 | strcpy(MenuInhalt[count], "ORANGE"); | |
479 | pMenuInhalt[count] = MenuInhalt[count]; | |
480 | NicEntry[_ORANGE_CARD_] = count; | |
5057b611 HS |
481 | sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); |
482 | strcat(message, temp); | |
483 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
484 | sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); | |
485 | strcat(message, temp); | |
486 | } | |
487 | count++; | |
488 | } | |
489 | ||
490 | if (blue) { | |
491 | strcpy(MenuInhalt[count], "BLUE"); | |
492 | pMenuInhalt[count] = MenuInhalt[count]; | |
493 | NicEntry[_BLUE_CARD_] = count; | |
5057b611 HS |
494 | sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); |
495 | strcat(message, temp); | |
496 | if ( strlen(knics[_BLUE_CARD_].macaddr) ) { | |
497 | sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); | |
498 | strcat(message, temp); | |
499 | } | |
500 | count++; | |
501 | } | |
502 | pMenuInhalt[count] = NULL; | |
503 | ||
1700769c | 504 | rc = newtWinMenu( ctr[TR_NETCARD_COLOR], message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_REMOVE], ctr[TR_DONE], NULL); |
5057b611 HS |
505 | |
506 | if ( rc == 0 || rc == 1) { | |
9b040aa0 HS |
507 | if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_); |
508 | if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_); | |
509 | if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_); | |
510 | if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_); | |
eea0467a | 511 | netaddresschange = 1; |
5057b611 | 512 | } else if (rc == 2) { |
9b040aa0 HS |
513 | if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_); |
514 | if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_); | |
515 | if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_); | |
516 | if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_); | |
eea0467a | 517 | netaddresschange = 1; |
a358af8c | 518 | } |
5057b611 HS |
519 | } |
520 | while ( rc <= 2); | |
069680ac MT |
521 | |
522 | freekeyvalues(kv); | |
069680ac MT |
523 | return 1; |
524 | } | |
525 | ||
75ae2191 | 526 | // Let user change GREEN address. |
069680ac MT |
527 | int greenaddressmenu(void) |
528 | { | |
529 | struct keyvalue *kv = initkeyvalues(); | |
530 | char message[1000]; | |
531 | int rc; | |
532 | ||
533 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
534 | { | |
535 | freekeyvalues(kv); | |
536 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
537 | return 0; | |
538 | } | |
539 | ||
540 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
541 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); | |
542 | ||
543 | if (rc == 0 || rc == 1) | |
544 | { | |
545 | if (changeaddress(kv, "GREEN", 0, "")) | |
546 | { | |
547 | netaddresschange = 1; | |
548 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
549 | writehostsfiles(); | |
550 | } | |
551 | } | |
552 | ||
553 | freekeyvalues(kv); | |
554 | ||
555 | return 0; | |
556 | } | |
557 | ||
75ae2191 | 558 | // They can change BLUE, ORANGE and GREEN too :) |
069680ac MT |
559 | int addressesmenu(void) |
560 | { | |
561 | struct keyvalue *kv = initkeyvalues(); | |
562 | struct keyvalue *mainkv = initkeyvalues(); | |
563 | int rc = 0; | |
564 | char *sections[5]; | |
565 | char *green = "GREEN"; | |
566 | char *orange = "ORANGE"; | |
567 | char *blue = "BLUE"; | |
568 | char *red = "RED"; | |
569 | int c = 0; | |
570 | char greenaddress[STRING_SIZE]; | |
571 | char oldgreenaddress[STRING_SIZE]; | |
572 | char temp[STRING_SIZE]; | |
573 | char temp2[STRING_SIZE]; | |
574 | char message[1000]; | |
575 | int configtype; | |
576 | int done; | |
577 | int choice; | |
578 | char hostname[STRING_SIZE]; | |
579 | ||
580 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
581 | { | |
582 | freekeyvalues(kv); | |
583 | freekeyvalues(mainkv); | |
584 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
585 | return 0; | |
586 | } | |
587 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
588 | { | |
589 | freekeyvalues(kv); | |
590 | freekeyvalues(mainkv); | |
591 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
592 | return 0; | |
593 | } | |
594 | ||
595 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
596 | configtype = atol(temp); | |
597 | ||
598 | sections[c] = green; | |
599 | c++; | |
600 | if (HAS_BLUE) | |
601 | { | |
602 | sections[c] = blue; | |
603 | c++; | |
604 | } | |
605 | if (HAS_ORANGE) | |
606 | { | |
607 | sections[c] = orange; | |
608 | c++; | |
609 | } | |
610 | if (HAS_RED) | |
611 | { | |
612 | sections[c] = red; | |
613 | c++; | |
614 | } | |
615 | sections[c] = NULL; | |
616 | ||
617 | choice = 0; | |
618 | done = 0; | |
619 | while (!done) | |
620 | { | |
621 | rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], | |
622 | ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, | |
623 | 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
624 | ||
625 | if (rc == 0 || rc == 1) | |
626 | { | |
627 | if (strcmp(sections[choice], "GREEN") == 0) | |
628 | { | |
629 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
630 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
631 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], | |
632 | message); | |
633 | if (rc == 0 || rc == 1) | |
634 | { | |
635 | if (changeaddress(kv, "GREEN", 0, "")) | |
636 | { | |
637 | netaddresschange = 1; | |
638 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
639 | writehostsfiles(); | |
640 | findkey(kv, "GREEN_ADDRESS", greenaddress); | |
641 | snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); | |
642 | snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); | |
643 | replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); | |
644 | chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); | |
645 | } | |
646 | } | |
647 | } | |
648 | if (strcmp(sections[choice], "BLUE") == 0) | |
649 | { | |
650 | if (changeaddress(kv, "BLUE", 0, "")) | |
651 | netaddresschange = 1; | |
652 | } | |
653 | if (strcmp(sections[choice], "ORANGE") == 0) | |
654 | { | |
655 | if (changeaddress(kv, "ORANGE", 0, "")) | |
656 | netaddresschange = 1; | |
657 | } | |
658 | if (strcmp(sections[choice], "RED") == 0) | |
659 | { | |
660 | strcpy(hostname, ""); | |
661 | findkey(mainkv, "HOSTNAME", hostname); | |
662 | if (changeaddress(kv, "RED", 1, hostname)) | |
663 | netaddresschange = 1; | |
664 | } | |
665 | } | |
666 | else | |
667 | done = 1; | |
668 | } | |
669 | ||
670 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
671 | freekeyvalues(kv); | |
672 | freekeyvalues(mainkv); | |
673 | ||
674 | return 0; | |
675 | } | |
676 | ||
677 | /* DNS and default gateway.... */ | |
678 | int dnsgatewaymenu(void) | |
679 | { | |
680 | struct keyvalue *kv = initkeyvalues(); | |
681 | char message[1000]; | |
682 | char temp[STRING_SIZE] = "0"; | |
683 | struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; | |
684 | char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ | |
685 | int error; | |
686 | int configtype; | |
687 | int rc; | |
688 | ||
689 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
690 | { | |
691 | freekeyvalues(kv); | |
692 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
693 | return 0; | |
694 | } | |
695 | ||
069680ac MT |
696 | entries[DNS1].text = ctr[TR_PRIMARY_DNS]; |
697 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
698 | values[DNS1] = strdup(temp); | |
699 | entries[DNS1].value = &values[DNS1]; | |
700 | entries[DNS1].flags = 0; | |
701 | ||
702 | entries[DNS2].text = ctr[TR_SECONDARY_DNS]; | |
703 | strcpy(temp, ""); findkey(kv, "DNS2", temp); | |
704 | values[DNS2] = strdup(temp); | |
705 | entries[DNS2].value = &values[DNS2]; | |
706 | entries[DNS2].flags = 0; | |
707 | ||
708 | entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; | |
709 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
710 | values[DEFAULT_GATEWAY] = strdup(temp); | |
711 | entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; | |
712 | entries[DEFAULT_GATEWAY].flags = 0; | |
713 | ||
714 | entries[DNSGATEWAY_TOTAL].text = NULL; | |
715 | entries[DNSGATEWAY_TOTAL].value = NULL; | |
716 | entries[DNSGATEWAY_TOTAL].flags = 0; | |
717 | ||
718 | do | |
719 | { | |
720 | error = 0; | |
721 | ||
722 | rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], | |
723 | ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, | |
724 | ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
725 | if (rc == 0 || rc == 1) | |
726 | { | |
727 | strcpy(message, ctr[TR_INVALID_FIELDS]); | |
728 | if (strlen(values[DNS1])) | |
729 | { | |
730 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
731 | { | |
732 | strcat(message, ctr[TR_PRIMARY_DNS_CR]); | |
733 | error = 1; | |
734 | } | |
735 | } | |
736 | if (strlen(values[DNS2])) | |
737 | { | |
738 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
739 | { | |
740 | strcat(message, ctr[TR_SECONDARY_DNS_CR]); | |
741 | error = 1; | |
742 | } | |
743 | } | |
744 | if (strlen(values[DEFAULT_GATEWAY])) | |
745 | { | |
746 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
747 | { | |
748 | strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); | |
749 | error = 1; | |
750 | } | |
751 | } | |
752 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
753 | { | |
754 | strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); | |
755 | error = 1; | |
756 | } | |
757 | ||
758 | if (error) | |
759 | errorbox(message); | |
760 | else | |
761 | { | |
762 | replacekeyvalue(kv, "DNS1", values[DNS1]); | |
763 | replacekeyvalue(kv, "DNS2", values[DNS2]); | |
764 | replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); | |
765 | netaddresschange = 1; | |
766 | free(values[DNS1]); | |
767 | free(values[DNS2]); | |
768 | free(values[DEFAULT_GATEWAY]); | |
769 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
770 | } | |
771 | } | |
772 | } | |
773 | while (error); | |
774 | ||
775 | freekeyvalues(kv); | |
776 | ||
777 | return 1; | |
778 | } |