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