Buildfix
[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 */
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, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
138 if (configtype < 1 || configtype > 4) configtype = 0;
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, "(TR) GRÜNE IP nicht konfiguriert.\n"); //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, "(TR) Kein DNS eingetragen\n");
202 goto EXIT;
203 }
204 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
205 if (!(strlen(temp)))
206 {
207 strcpy(errormessage, "(TR) Kein default Gateway eingetragen.\n");
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];
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); x = atol(temp);
249 if (x < 1 || x > 4) x = 0;
250 /* Format heading bit. */
251 snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x],
252 networkrestart);
253 rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6,
254 sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
255
256 if (rc == 0 || rc == 1)
257 result = choice + 1;
258 else
259 result = 0;
260
261 return result;
262 }
263
264 /* Here they choose general network config, number of nics etc. */
265 int configtypemenu(void)
266 {
267 struct keyvalue *kv = initkeyvalues();
268 char temp[STRING_SIZE] = "0";
269 char message[1000];
270 int choise, found;
271 int rc;
272
273 fprintf(flog,"Enter ConfigMenu\n");
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, "(TR) Nicht genuegend Netzwerkkarten fuer diese Auswahl gefunden.\n\nBenoetigt: %d\nGefunden: %d\n", 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 clear_card_entry(_RED_CARD_);
305 clear_card_entry(_ORANGE_CARD_);
306 clear_card_entry(_BLUE_CARD_);
307
308 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
309 netaddresschange = 1;
310 }
311 freekeyvalues(kv);
312
313 return 0;
314 }
315
316
317
318 /* Driver menu. Choose drivers.. */
319 int drivermenu(void)
320 {
321 struct keyvalue *kv = initkeyvalues();
322 char message[STRING_SIZE];
323 char temp[STRING_SIZE];
324
325 int configtype;
326 int i, rc, kcount = 0, neednics; //i = 0, count = 0,
327
328 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
329 {
330 freekeyvalues(kv);
331 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
332 return 0;
333 }
334
335 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
336 configtype = atol(temp);
337
338 strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
339
340 kcount = 0; // counter to find knowing nics.
341 neednics = 0; // counter to use needing nics.
342 if (HAS_GREEN) {
343 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
344 strcat(message, temp);
345 if (strlen(knics[_GREEN_CARD_].macaddr) ) {
346 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
347 strcat(message, temp);
348 }
349 neednics++;
350 }
351 if (HAS_RED) {
352 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
353 strcat(message, temp);
354 if (strlen(knics[_RED_CARD_].macaddr) ) {
355 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
356 strcat(message, temp);
357 }
358 neednics++;
359 }
360 if (HAS_ORANGE) {
361 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
362 strcat(message, temp);
363 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
364 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
365 strcat(message, temp);
366 }
367 neednics++;
368 }
369 if (HAS_BLUE) {
370 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
371 strcat(message, temp);
372 if (strlen(knics[_BLUE_CARD_].macaddr)) {
373 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
374 strcat(message, temp);
375 }
376 neednics++;
377 }
378
379 for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++;
380
381 if (neednics = kcount)
382 {
383 strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
384 rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
385 ctr[TR_CANCEL], message);
386 if (rc == 0 || rc == 1)
387 {
388 /* Shit, got to do something.. */
389 changedrivers();
390 }
391 } else {
392 /* Shit, got to do something.. */
393 changedrivers();
394 }
395 freekeyvalues(kv);
396
397 return 1;
398 }
399
400 int set_menu_entry_for(int *nr, int *card)
401 {
402
403 }
404
405 int changedrivers(void)
406 {
407 struct keyvalue *kv = initkeyvalues();
408 char temp[STRING_SIZE], message[STRING_SIZE];
409 int configtype;
410 int green = 0, red = 0, blue = 0, orange = 0;
411 char MenuInhalt[10][180];
412 char *pMenuInhalt[10];
413 int count = 0, choise = 0, rc;
414 int NicEntry[10];
415
416 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
417 {
418 freekeyvalues(kv);
419 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
420 return 0;
421 }
422 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
423 ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
424
425 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
426 if (configtype == 1)
427 { green = 1; red = 1; }
428 else if (configtype == 2)
429 { green = 1; red = 1; orange = 1; }
430 else if (configtype == 3)
431 { green = 1; red = 1; blue = 1; }
432 else if (configtype == 4)
433 { green = 1; red=1; orange=1; blue = 1; }
434
435 do
436 {
437 count = 0;
438 strcpy(message, "(TR) Bitte wählen Sie das Interface aus das geaendert werden soll.\n\n");
439
440 if (green) {
441 strcpy(MenuInhalt[count], "GREEN");
442 pMenuInhalt[count] = MenuInhalt[count];
443 NicEntry[_GREEN_CARD_] = count;
444 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
445 strcat(message, temp);
446 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
447 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
448 strcat(message, temp);
449 }
450 count++;
451 }
452
453 if (red) {
454 strcpy(MenuInhalt[count], "RED");
455 pMenuInhalt[count] = MenuInhalt[count];
456 NicEntry[_RED_CARD_] = count;
457 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
458 strcat(message, temp);
459 if ( strlen(knics[_RED_CARD_].macaddr) ) {
460 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
461 strcat(message, temp);
462 }
463 count++;
464 }
465
466 if (orange) {
467 strcpy(MenuInhalt[count], "ORANGE");
468 pMenuInhalt[count] = MenuInhalt[count];
469 NicEntry[_ORANGE_CARD_] = count;
470 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
471 strcat(message, temp);
472 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
473 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
474 strcat(message, temp);
475 }
476 count++;
477 }
478
479 if (blue) {
480 strcpy(MenuInhalt[count], "BLUE");
481 pMenuInhalt[count] = MenuInhalt[count];
482 NicEntry[_BLUE_CARD_] = count;
483 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
484 strcat(message, temp);
485 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
486 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
487 strcat(message, temp);
488 }
489 count++;
490 }
491 pMenuInhalt[count] = NULL;
492
493 rc = newtWinMenu("(TR) Netcard Farbe", message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], "(TR) Entfernen" , ctr[TR_DONE], NULL);
494
495 if ( rc == 0 || rc == 1) {
496 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
497 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
498 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
499 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
500 netaddresschange = 1;
501 } else if (rc == 2) {
502 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
503 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
504 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
505 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
506 netaddresschange = 1;
507 }
508 }
509 while ( rc <= 2);
510
511 freekeyvalues(kv);
512 return 1;
513 }
514
515 // Let user change GREEN address.
516 int greenaddressmenu(void)
517 {
518 struct keyvalue *kv = initkeyvalues();
519 char message[1000];
520 int rc;
521
522 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
523 {
524 freekeyvalues(kv);
525 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
526 return 0;
527 }
528
529 sprintf(message, ctr[TR_WARNING_LONG], NAME);
530 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
531
532 if (rc == 0 || rc == 1)
533 {
534 if (changeaddress(kv, "GREEN", 0, ""))
535 {
536 netaddresschange = 1;
537 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
538 writehostsfiles();
539 }
540 }
541
542 freekeyvalues(kv);
543
544 return 0;
545 }
546
547 // They can change BLUE, ORANGE and GREEN too :)
548 int addressesmenu(void)
549 {
550 struct keyvalue *kv = initkeyvalues();
551 struct keyvalue *mainkv = initkeyvalues();
552 int rc = 0;
553 char *sections[5];
554 char *green = "GREEN";
555 char *orange = "ORANGE";
556 char *blue = "BLUE";
557 char *red = "RED";
558 int c = 0;
559 char greenaddress[STRING_SIZE];
560 char oldgreenaddress[STRING_SIZE];
561 char temp[STRING_SIZE];
562 char temp2[STRING_SIZE];
563 char message[1000];
564 int configtype;
565 int done;
566 int choice;
567 char hostname[STRING_SIZE];
568
569 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
570 {
571 freekeyvalues(kv);
572 freekeyvalues(mainkv);
573 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
574 return 0;
575 }
576 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
577 {
578 freekeyvalues(kv);
579 freekeyvalues(mainkv);
580 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
581 return 0;
582 }
583
584 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
585 configtype = atol(temp);
586
587 sections[c] = green;
588 c++;
589 if (HAS_BLUE)
590 {
591 sections[c] = blue;
592 c++;
593 }
594 if (HAS_ORANGE)
595 {
596 sections[c] = orange;
597 c++;
598 }
599 if (HAS_RED)
600 {
601 sections[c] = red;
602 c++;
603 }
604 sections[c] = NULL;
605
606 choice = 0;
607 done = 0;
608 while (!done)
609 {
610 rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
611 ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
612 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
613
614 if (rc == 0 || rc == 1)
615 {
616 if (strcmp(sections[choice], "GREEN") == 0)
617 {
618 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
619 sprintf(message, ctr[TR_WARNING_LONG], NAME);
620 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
621 message);
622 if (rc == 0 || rc == 1)
623 {
624 if (changeaddress(kv, "GREEN", 0, ""))
625 {
626 netaddresschange = 1;
627 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
628 writehostsfiles();
629 findkey(kv, "GREEN_ADDRESS", greenaddress);
630 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
631 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
632 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
633 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
634 }
635 }
636 }
637 if (strcmp(sections[choice], "BLUE") == 0)
638 {
639 if (changeaddress(kv, "BLUE", 0, ""))
640 netaddresschange = 1;
641 }
642 if (strcmp(sections[choice], "ORANGE") == 0)
643 {
644 if (changeaddress(kv, "ORANGE", 0, ""))
645 netaddresschange = 1;
646 }
647 if (strcmp(sections[choice], "RED") == 0)
648 {
649 strcpy(hostname, "");
650 findkey(mainkv, "HOSTNAME", hostname);
651 if (changeaddress(kv, "RED", 1, hostname))
652 netaddresschange = 1;
653 }
654 }
655 else
656 done = 1;
657 }
658
659 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
660 freekeyvalues(kv);
661 freekeyvalues(mainkv);
662
663 return 0;
664 }
665
666 /* DNS and default gateway.... */
667 int dnsgatewaymenu(void)
668 {
669 struct keyvalue *kv = initkeyvalues();
670 char message[1000];
671 char temp[STRING_SIZE] = "0";
672 struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
673 char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
674 int error;
675 int configtype;
676 int rc;
677
678 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
679 {
680 freekeyvalues(kv);
681 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
682 return 0;
683 }
684
685 entries[DNS1].text = ctr[TR_PRIMARY_DNS];
686 strcpy(temp, ""); findkey(kv, "DNS1", temp);
687 values[DNS1] = strdup(temp);
688 entries[DNS1].value = &values[DNS1];
689 entries[DNS1].flags = 0;
690
691 entries[DNS2].text = ctr[TR_SECONDARY_DNS];
692 strcpy(temp, ""); findkey(kv, "DNS2", temp);
693 values[DNS2] = strdup(temp);
694 entries[DNS2].value = &values[DNS2];
695 entries[DNS2].flags = 0;
696
697 entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY];
698 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
699 values[DEFAULT_GATEWAY] = strdup(temp);
700 entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
701 entries[DEFAULT_GATEWAY].flags = 0;
702
703 entries[DNSGATEWAY_TOTAL].text = NULL;
704 entries[DNSGATEWAY_TOTAL].value = NULL;
705 entries[DNSGATEWAY_TOTAL].flags = 0;
706
707 do
708 {
709 error = 0;
710
711 rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS],
712 ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries,
713 ctr[TR_OK], ctr[TR_CANCEL], NULL);
714 if (rc == 0 || rc == 1)
715 {
716 strcpy(message, ctr[TR_INVALID_FIELDS]);
717 if (strlen(values[DNS1]))
718 {
719 if (inet_addr(values[DNS1]) == INADDR_NONE)
720 {
721 strcat(message, ctr[TR_PRIMARY_DNS_CR]);
722 error = 1;
723 }
724 }
725 if (strlen(values[DNS2]))
726 {
727 if (inet_addr(values[DNS2]) == INADDR_NONE)
728 {
729 strcat(message, ctr[TR_SECONDARY_DNS_CR]);
730 error = 1;
731 }
732 }
733 if (strlen(values[DEFAULT_GATEWAY]))
734 {
735 if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
736 {
737 strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]);
738 error = 1;
739 }
740 }
741 if (!strlen(values[DNS1]) && strlen(values[DNS2]))
742 {
743 strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]);
744 error = 1;
745 }
746
747 if (error)
748 errorbox(message);
749 else
750 {
751 replacekeyvalue(kv, "DNS1", values[DNS1]);
752 replacekeyvalue(kv, "DNS2", values[DNS2]);
753 replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
754 netaddresschange = 1;
755 free(values[DNS1]);
756 free(values[DNS2]);
757 free(values[DEFAULT_GATEWAY]);
758 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
759 }
760 }
761 }
762 while (error);
763
764 freekeyvalues(kv);
765
766 return 1;
767 }