]> git.ipfire.org Git - ipfire-2.x.git/blob - src/setup/networking.c
d6cd30cff0219b7b92958174ce286e2afeaf004d
[ipfire-2.x.git] / src / 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 */
10
11 // Translation
12 #include <libintl.h>
13 #define _(x) dgettext("setup", x)
14
15 #include "setup.h"
16
17 #define DNS1 0
18 #define DNS2 1
19 #define DEFAULT_GATEWAY 2
20 #define DNSGATEWAY_TOTAL 3
21
22 extern FILE *flog;
23 extern char *mylog;
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 extern struct nic nics[];
34 extern struct knic knics[];
35
36 char *configtypenames[] = {
37 "GREEN + RED",
38 "GREEN + RED + ORANGE",
39 "GREEN + RED + BLUE",
40 "GREEN + RED + ORANGE + BLUE",
41 NULL };
42 int configtypecards[] = {
43 2, // "GREEN + RED",
44 3, // "GREEN + RED + ORANGE",
45 3, // "GREEN + RED + BLUE",
46 4 // "GREEN + RED + ORANGE + BLUE",
47 };
48
49
50 int netaddresschange;
51
52 int oktoleave(void);
53 int firstmenu(void);
54 int configtypemenu(void);
55 int drivermenu(void);
56 int changedrivers(void);
57 int greenaddressmenu(void);
58 int addressesmenu(void);
59 int dnsgatewaymenu(void);
60
61 int handlenetworking(void)
62 {
63 int done;
64 int choice;
65 int found;
66
67 netaddresschange = 0;
68
69 found = scan_network_cards();
70 found = init_knics();
71
72 done = 0;
73 while (!done)
74 {
75 choice = firstmenu();
76
77 switch (choice)
78 {
79 case 1:
80 configtypemenu();
81 break;
82
83 case 2:
84 drivermenu();
85 break;
86
87 case 3:
88 addressesmenu();
89 break;
90
91 case 4:
92 dnsgatewaymenu();
93 break;
94
95 case 0:
96 if (oktoleave()) done = 1;
97 break;
98
99 default:
100 break;
101 }
102 }
103
104 if (automode == 0)
105 {
106 /* Restart networking! */
107 if (netaddresschange)
108 {
109 runcommandwithstatus("/etc/rc.d/init.d/network stop",
110 _("Networking"), _("Stopping network..."), NULL);
111
112 rename_nics();
113
114 runcommandwithstatus("/etc/rc.d/init.d/network start",
115 _("Networking"), _("Restarting network..."), NULL);
116 runcommandwithstatus("/etc/rc.d/init.d/unbound restart",
117 _("Networking"), _("Restarting unbound..."), NULL);
118 }
119 } else {
120 rename_nics();
121 }
122 return 1;
123 }
124
125 int oktoleave(void)
126 {
127 struct keyvalue *kv = initkeyvalues();
128 char temp[STRING_SIZE];
129 int configtype;
130 int rc;
131
132 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
133 {
134 freekeyvalues(kv);
135 errorbox(_("Unable to open settings file"));
136 return 0;
137 }
138
139 strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
140 if (configtype < 1 || configtype > 4) configtype = 1;
141
142 if (HAS_GREEN)
143 {
144 strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
145 if (!(strlen(temp)))
146 {
147 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
148 _("No GREEN interface assigned."));
149 if (rc == 0 || rc == 1)
150 {
151 freekeyvalues(kv);
152 return 0;
153 }
154 }
155 if (!(interfacecheck(kv, "GREEN")))
156 {
157 errorbox(_("Missing an IP address on GREEN."));
158 freekeyvalues(kv);
159 return 0;
160 }
161 }
162 if (HAS_RED)
163 {
164
165 strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
166 if (!(strlen(temp)))
167 {
168 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
169 _("No RED interface assigned."));
170 if (rc == 0 || rc == 1)
171 {
172 freekeyvalues(kv);
173 return 0;
174 }
175 }
176 if (!(interfacecheck(kv, "RED")))
177 {
178 errorbox(_("Missing an IP address on RED."));
179 freekeyvalues(kv);
180 return 0;
181 }
182 }
183 if (HAS_ORANGE)
184 {
185 strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
186 if (!(strlen(temp)))
187 {
188 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
189 _("No ORANGE interface assigned."));
190 if (rc == 0 || rc == 1)
191 {
192 freekeyvalues(kv);
193 return 0;
194 }
195 }
196 if (!(interfacecheck(kv, "ORANGE")))
197 {
198 errorbox(_("Missing an IP address on ORANGE."));
199 freekeyvalues(kv);
200 return 0;
201 }
202 }
203 if (HAS_BLUE)
204 {
205 strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
206 if (!(strlen(temp)))
207 {
208 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
209 _("No BLUE interface assigned."));
210 if (rc == 0 || rc == 1)
211 {
212 freekeyvalues(kv);
213 return 0;
214 }
215 }
216 if (!(interfacecheck(kv, "BLUE")))
217 {
218 errorbox(_("Missing an IP address on BLUE."));
219 freekeyvalues(kv);
220 return 0;
221 }
222 }
223
224 strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
225 if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
226 {
227 strcpy(temp, ""); findkey(kv, "DNS1", temp);
228 if (!(strlen(temp)))
229 {
230 errorbox(_("Missing DNS."));
231 freekeyvalues(kv);
232 return 0;
233 }
234 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
235 if (!(strlen(temp)))
236 {
237 errorbox(_("Missing Default Gateway."));
238 freekeyvalues(kv);
239 return 0;
240 }
241 }
242 return 1;
243 }
244
245
246 /* Shows the main menu and a summary of the current settings. */
247 int firstmenu(void)
248 {
249 char *sections[] = {
250 _("Network configuration type"),
251 _("Drivers and card assignments"),
252 _("Address settings"),
253 _("DNS and Gateway settings"),
254 NULL
255 };
256 int rc;
257 static int choice = 0;
258 struct keyvalue *kv = initkeyvalues();
259 char message[1000];
260 char temp[STRING_SIZE] = "1";
261 int x;
262 int result;
263 char networkrestart[STRING_SIZE] = "";
264
265 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
266 {
267 freekeyvalues(kv);
268 errorbox(_("Unable to open settings file"));
269 return 0;
270 }
271
272 if (netaddresschange)
273 strcpy(networkrestart, _("When configuration is complete, a network restart will be required."));
274
275 strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp);
276 x = atol(temp);
277 x--;
278 if (x < 0 || x > 4) x = 0;
279 /* Format heading bit. */
280 snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart);
281 rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6,
282 sections, &choice, _("OK"), _("Done"), NULL);
283
284 if (rc == 0 || rc == 1)
285 result = choice + 1;
286 else
287 result = 0;
288
289 return result;
290 }
291
292 /* Here they choose general network config, number of nics etc. */
293 int configtypemenu(void)
294 {
295 struct keyvalue *kv = initkeyvalues();
296 char temp[STRING_SIZE] = "1";
297 char message[1000];
298 int choise, found;
299 int rc, configtype;
300
301 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
302 {
303 freekeyvalues(kv);
304 errorbox(_("Unable to open settings file"));
305 return 0;
306 }
307
308 found = scan_network_cards();
309
310 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
311 choise--;
312
313 sprintf(message, _("Select the network configuration for %s. "
314 "The following configuration types list those interfaces which have ethernet attached. "
315 "If you change this setting, a network restart will be required, and you will have to "
316 "reconfigure the network driver assignments."), NAME);
317 rc = newtWinMenu(_("Network configuration type"), message, 50, 5, 5,
318 6, configtypenames, &choise, _("OK"), _("Cancel"), NULL);
319 if ( configtypecards[choise] > found ) {
320 sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"),
321 configtypecards[choise], found);
322 errorbox(message);
323 }
324
325 if (rc == 0 || rc == 1)
326 {
327 choise++;
328 sprintf(temp, "%d", choise);
329 replacekeyvalue(kv, "CONFIG_TYPE", temp);
330 configtype = atol(temp);
331 if (!HAS_RED)
332 clear_card_entry(_RED_CARD_);
333 if (!HAS_ORANGE)
334 clear_card_entry(_ORANGE_CARD_);
335 if (!HAS_BLUE)
336 clear_card_entry(_BLUE_CARD_);
337
338 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
339 netaddresschange = 1;
340 }
341 freekeyvalues(kv);
342
343 return 0;
344 }
345
346 /* Driver menu. Choose drivers.. */
347 int drivermenu(void)
348 {
349 struct keyvalue *kv = initkeyvalues();
350 char message[STRING_SIZE];
351 char temp[STRING_SIZE] = "1";
352
353 int configtype;
354 int i, rc, kcount = 0, neednics;
355
356 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
357 {
358 freekeyvalues(kv);
359 errorbox(_("Unable to open settings file"));
360 return 0;
361 }
362
363 if (findkey(kv, "CONFIG_TYPE", temp))
364 configtype = atol(temp);
365 else {
366 fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
367 configtype = atol(temp);
368 replacekeyvalue(kv, "CONFIG_TYPE", temp);
369 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
370 }
371
372 strcpy(message, _("Configure network drivers, and which interface each card is assigned to. "
373 "The current configuration is as follows:\n\n"));
374
375 kcount = 0;
376 neednics = 0;
377 if (HAS_GREEN) {
378 sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
379 strcat(message, temp);
380 if (strlen(knics[_GREEN_CARD_].macaddr) ) {
381 sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
382 strcat(message, temp);
383 }
384 neednics++;
385 }
386 if (HAS_RED) {
387 sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
388 strcat(message, temp);
389 if (strlen(knics[_RED_CARD_].macaddr) ) {
390 sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
391 strcat(message, temp);
392 }
393 neednics++;
394 }
395 if (HAS_ORANGE) {
396 sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
397 strcat(message, temp);
398 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
399 sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
400 strcat(message, temp);
401 }
402 neednics++;
403 }
404 if (HAS_BLUE) {
405 sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
406 strcat(message, temp);
407 if (strlen(knics[_BLUE_CARD_].macaddr)) {
408 sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
409 strcat(message, temp);
410 }
411 neednics++;
412 }
413
414 for ( i=0 ; i<4; i++)
415 if (strcmp(knics[i].macaddr, ""))
416 kcount++;
417
418 if (neednics = kcount)
419 {
420 strcat(message, "\n");
421 strcat(message, _("Do you wish to change these settings?"));
422 rc = newtWinChoice(_("Drivers and card assignments"), _("OK"),
423 _("Cancel"), message);
424 if (rc == 0 || rc == 1)
425 {
426 changedrivers();
427 }
428 } else {
429 changedrivers();
430 }
431 freekeyvalues(kv);
432
433 return 1;
434 }
435
436 int set_menu_entry_for(int *nr, int *card)
437 {
438
439 }
440
441 int changedrivers(void)
442 {
443 struct keyvalue *kv = initkeyvalues();
444 char temp[STRING_SIZE], message[STRING_SIZE];
445 int configtype;
446 int green = 0, red = 0, blue = 0, orange = 0;
447 char MenuInhalt[10][180];
448 char *pMenuInhalt[10];
449 int count = 0, choise = 0, rc;
450 int NicEntry[10];
451
452 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
453 {
454 freekeyvalues(kv);
455 errorbox(_("Unable to open settings file"));
456 return 0;
457 }
458 if (automode == 0)
459 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
460 _("Networking"), _("Restarting non-local network..."), NULL);
461
462 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
463 if (configtype == 1)
464 { green = 1; red = 1; }
465 else if (configtype == 2)
466 { green = 1; red = 1; orange = 1; }
467 else if (configtype == 3)
468 { green = 1; red = 1; blue = 1; }
469 else if (configtype == 4)
470 { green = 1; red=1; orange=1; blue = 1; }
471 else if (configtype == "")
472 { green = 1; red = 1; }
473
474 do
475 {
476 count = 0;
477 strcpy(message, _("Please choose the interface you wish to change.\n\n"));
478
479 if (green) {
480 strcpy(MenuInhalt[count], "GREEN");
481 pMenuInhalt[count] = MenuInhalt[count];
482 NicEntry[_GREEN_CARD_] = count;
483 sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
484 strcat(message, temp);
485 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
486 sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
487 strcat(message, temp);
488 }
489 count++;
490 }
491
492 if (red) {
493 strcpy(MenuInhalt[count], "RED");
494 pMenuInhalt[count] = MenuInhalt[count];
495 NicEntry[_RED_CARD_] = count;
496 sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
497 strcat(message, temp);
498 if ( strlen(knics[_RED_CARD_].macaddr) ) {
499 sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
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 sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
510 strcat(message, temp);
511 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
512 sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
513 strcat(message, temp);
514 }
515 count++;
516 }
517
518 if (blue) {
519 strcpy(MenuInhalt[count], "BLUE");
520 pMenuInhalt[count] = MenuInhalt[count];
521 NicEntry[_BLUE_CARD_] = count;
522 sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
523 strcat(message, temp);
524 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
525 sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
526 strcat(message, temp);
527 }
528 count++;
529 }
530 pMenuInhalt[count] = NULL;
531
532 rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt,
533 &choise, _("Select"), _("Remove"), _("Done"), NULL);
534
535 if ( rc == 0 || rc == 1) {
536 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
537 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
538 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
539 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
540 netaddresschange = 1;
541 } else if (rc == 2) {
542 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
543 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
544 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
545 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
546 netaddresschange = 1;
547 }
548 }
549 while ( rc <= 2);
550
551 freekeyvalues(kv);
552 return 1;
553 }
554
555 // Let user change GREEN address.
556 int greenaddressmenu(void)
557 {
558 struct keyvalue *kv = initkeyvalues();
559 char message[1000];
560 int rc;
561
562 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
563 {
564 freekeyvalues(kv);
565 errorbox(_("Unable to open settings file"));
566 return 0;
567 }
568
569 sprintf(message, _("If you change this IP address, and you are logged in remotely, "
570 "your connection to the %s machine will be broken, and you will have to reconnect "
571 "on the new IP. This is a risky operation, and should only be attempted if you "
572 "have physical access to the machine, should something go wrong."), NAME);
573 rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
574
575 if (rc == 0 || rc == 1)
576 {
577 if (changeaddress(kv, "GREEN", 0, ""))
578 {
579 netaddresschange = 1;
580 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
581 writehostsfiles();
582 }
583 }
584
585 freekeyvalues(kv);
586
587 return 0;
588 }
589
590 // They can change BLUE, ORANGE and GREEN too :)
591 int addressesmenu(void)
592 {
593 struct keyvalue *kv = initkeyvalues();
594 struct keyvalue *mainkv = initkeyvalues();
595 int rc = 0;
596 char *sections[5];
597 char *green = "GREEN";
598 char *orange = "ORANGE";
599 char *blue = "BLUE";
600 char *red = "RED";
601 int c = 0;
602 char greenaddress[STRING_SIZE];
603 char oldgreenaddress[STRING_SIZE];
604 char temp[STRING_SIZE];
605 char temp2[STRING_SIZE];
606 char message[1000];
607 int configtype;
608 int done;
609 int choice;
610 char hostname[STRING_SIZE];
611
612 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
613 {
614 freekeyvalues(kv);
615 freekeyvalues(mainkv);
616 errorbox(_("Unable to open settings file"));
617 return 0;
618 }
619 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
620 {
621 freekeyvalues(kv);
622 freekeyvalues(mainkv);
623 errorbox(_("Unable to open settings file"));
624 return 0;
625 }
626
627 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
628 configtype = atol(temp);
629
630 sections[c] = green;
631 c++;
632 if (HAS_BLUE)
633 {
634 sections[c] = blue;
635 c++;
636 }
637 if (HAS_ORANGE)
638 {
639 sections[c] = orange;
640 c++;
641 }
642 if (HAS_RED)
643 {
644 sections[c] = red;
645 c++;
646 }
647 sections[c] = NULL;
648
649 choice = 0;
650 done = 0;
651 while (!done)
652 {
653 rc = newtWinMenu(_("Address settings"),
654 _("Select the interface you wish to reconfigure."), 50, 5,
655 5, 6, sections, &choice, _("OK"), _("Done"), NULL);
656
657 if (rc == 0 || rc == 1)
658 {
659 if (strcmp(sections[choice], "GREEN") == 0)
660 {
661 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
662 sprintf(message, _("If you change this IP address, and you are logged in remotely, "
663 "your connection to the %s machine will be broken, and you will have to reconnect "
664 "on the new IP. This is a risky operation, and should only be attempted if you "
665 "have physical access to the machine, should something go wrong."), NAME);
666 rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
667 if (rc == 0 || rc == 1)
668 {
669 if (changeaddress(kv, "GREEN", 0, ""))
670 {
671 netaddresschange = 1;
672 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
673 writehostsfiles();
674 findkey(kv, "GREEN_ADDRESS", greenaddress);
675 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
676 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
677 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
678 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
679 }
680 }
681 }
682 if (strcmp(sections[choice], "BLUE") == 0)
683 {
684 if (changeaddress(kv, "BLUE", 0, ""))
685 netaddresschange = 1;
686 }
687 if (strcmp(sections[choice], "ORANGE") == 0)
688 {
689 if (changeaddress(kv, "ORANGE", 0, ""))
690 netaddresschange = 1;
691 }
692 if (strcmp(sections[choice], "RED") == 0)
693 {
694 strcpy(hostname, "");
695 findkey(mainkv, "HOSTNAME", hostname);
696 if (changeaddress(kv, "RED", 1, hostname))
697 netaddresschange = 1;
698 }
699 }
700 else
701 done = 1;
702 }
703
704 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
705 freekeyvalues(kv);
706 freekeyvalues(mainkv);
707
708 return 0;
709 }
710
711 /* DNS and default gateway.... */
712 int dnsgatewaymenu(void)
713 {
714 struct keyvalue *kv = initkeyvalues();
715 char message[1000];
716 char temp[STRING_SIZE] = "0";
717 struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
718 char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
719 int error;
720 int configtype;
721 int rc;
722
723 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
724 {
725 freekeyvalues(kv);
726 errorbox(_("Unable to open settings file"));
727 return 0;
728 }
729
730 entries[DNS1].text = _("Primary DNS:");
731 strcpy(temp, ""); findkey(kv, "DNS1", temp);
732 values[DNS1] = strdup(temp);
733 entries[DNS1].value = &values[DNS1];
734 entries[DNS1].flags = 0;
735
736 entries[DNS2].text = _("Secondary DNS:");
737 strcpy(temp, ""); findkey(kv, "DNS2", temp);
738 values[DNS2] = strdup(temp);
739 entries[DNS2].value = &values[DNS2];
740 entries[DNS2].flags = 0;
741
742 entries[DEFAULT_GATEWAY].text = _("Default gateway:");
743 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
744 values[DEFAULT_GATEWAY] = strdup(temp);
745 entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
746 entries[DEFAULT_GATEWAY].flags = 0;
747
748 entries[DNSGATEWAY_TOTAL].text = NULL;
749 entries[DNSGATEWAY_TOTAL].value = NULL;
750 entries[DNSGATEWAY_TOTAL].flags = 0;
751
752 do
753 {
754 error = 0;
755
756 rc = newtWinEntries(_("DNS and Gateway settings"),
757 _("Enter the DNS and gateway information. "
758 "These settings are used only with Static IP (and DHCP if DNS set) on the RED interface."),
759 50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL);
760 if (rc == 0 || rc == 1)
761 {
762 strcpy(message, _("The following fields are invalid:"));
763 strcpy(message, "\n\n");
764 if (strlen(values[DNS1]))
765 {
766 if (inet_addr(values[DNS1]) == INADDR_NONE)
767 {
768 strcat(message, _("Primary DNS"));
769 strcat(message, "\n");
770 error = 1;
771 }
772 }
773 if (strlen(values[DNS2]))
774 {
775 if (inet_addr(values[DNS2]) == INADDR_NONE)
776 {
777 strcat(message, _("Secondary DNS"));
778 strcat(message, "\n");
779 error = 1;
780 }
781 }
782 if (strlen(values[DEFAULT_GATEWAY]))
783 {
784 if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
785 {
786 strcat(message, _("Default gateway"));
787 strcat(message, "\n");
788 error = 1;
789 }
790 }
791 if (!strlen(values[DNS1]) && strlen(values[DNS2]))
792 {
793 strcpy(message, _("Secondary DNS specified without a Primary DNS"));
794 strcat(message, "\n");
795 error = 1;
796 }
797
798 if (error)
799 errorbox(message);
800 else
801 {
802 replacekeyvalue(kv, "DNS1", values[DNS1]);
803 replacekeyvalue(kv, "DNS2", values[DNS2]);
804 replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
805 netaddresschange = 1;
806 free(values[DNS1]);
807 free(values[DNS2]);
808 free(values[DEFAULT_GATEWAY]);
809 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
810 }
811 }
812 }
813 while (error);
814
815 freekeyvalues(kv);
816
817 return 1;
818 }