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