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