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