]> git.ipfire.org Git - ipfire-2.x.git/blob - src/install+setup/setup/networking.c
Setup SegFault-Fix.
[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, 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];
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 < 1 || x > 4) x = 1;
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] = "0";
271 char message[1000];
272 int choise, found;
273 int rc;
274
275 fprintf(flog,"Enter ConfigMenu\n");
276
277 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
278 {
279 freekeyvalues(kv);
280 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
281 return 0;
282 }
283
284 found = scan_network_cards();
285
286 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
287 choise--;
288
289 do
290 {
291 sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME);
292 rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5,
293 6, configtypenames, &choise, ctr[TR_OK], ctr[TR_CANCEL], NULL);
294 if ( configtypecards[choise] > found ) {
295 sprintf(message, ctr[TR_NOT_ENOUGH_INTERFACES] , configtypecards[choise], found);
296 errorbox(message);
297 }
298 }
299 while ( configtypecards[choise] > found);
300
301 if (rc == 0 || rc == 1)
302 {
303 choise++;
304 sprintf(temp, "%d", choise);
305 replacekeyvalue(kv, "CONFIG_TYPE", temp);
306 clear_card_entry(_RED_CARD_);
307 clear_card_entry(_ORANGE_CARD_);
308 clear_card_entry(_BLUE_CARD_);
309
310 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
311 netaddresschange = 1;
312 }
313 freekeyvalues(kv);
314
315 return 0;
316 }
317
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];
326
327 int configtype;
328 int i, rc, kcount = 0, neednics; //i = 0, count = 0,
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 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
338 configtype = atol(temp);
339
340 strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
341
342 kcount = 0; // counter to find knowing nics.
343 neednics = 0; // counter to use needing nics.
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++) if (strcmp(knics[i].macaddr, "")) kcount++;
382
383 if (neednics = kcount)
384 {
385 strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
386 rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
387 ctr[TR_CANCEL], message);
388 if (rc == 0 || rc == 1)
389 {
390 /* Shit, got to do something.. */
391 changedrivers();
392 }
393 } else {
394 /* Shit, got to do something.. */
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 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
425 ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
426
427 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
428 if (configtype == 1)
429 { green = 1; red = 1; }
430 else if (configtype == 2)
431 { green = 1; red = 1; orange = 1; }
432 else if (configtype == 3)
433 { green = 1; red = 1; blue = 1; }
434 else if (configtype == 4)
435 { green = 1; red=1; orange=1; blue = 1; }
436
437 do
438 {
439 count = 0;
440 strcpy(message, ctr[TR_INTERFACE_CHANGE]);
441
442 if (green) {
443 strcpy(MenuInhalt[count], "GREEN");
444 pMenuInhalt[count] = MenuInhalt[count];
445 NicEntry[_GREEN_CARD_] = count;
446 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
447 strcat(message, temp);
448 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
449 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
450 strcat(message, temp);
451 }
452 count++;
453 }
454
455 if (red) {
456 strcpy(MenuInhalt[count], "RED");
457 pMenuInhalt[count] = MenuInhalt[count];
458 NicEntry[_RED_CARD_] = count;
459 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
460 strcat(message, temp);
461 if ( strlen(knics[_RED_CARD_].macaddr) ) {
462 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
463 strcat(message, temp);
464 }
465 count++;
466 }
467
468 if (orange) {
469 strcpy(MenuInhalt[count], "ORANGE");
470 pMenuInhalt[count] = MenuInhalt[count];
471 NicEntry[_ORANGE_CARD_] = count;
472 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
473 strcat(message, temp);
474 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
475 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
476 strcat(message, temp);
477 }
478 count++;
479 }
480
481 if (blue) {
482 strcpy(MenuInhalt[count], "BLUE");
483 pMenuInhalt[count] = MenuInhalt[count];
484 NicEntry[_BLUE_CARD_] = count;
485 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
486 strcat(message, temp);
487 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
488 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
489 strcat(message, temp);
490 }
491 count++;
492 }
493 pMenuInhalt[count] = NULL;
494
495 rc = newtWinMenu( ctr[TR_NETCARD_COLOR], message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_REMOVE], ctr[TR_DONE], NULL);
496
497 if ( rc == 0 || rc == 1) {
498 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
499 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
500 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
501 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
502 netaddresschange = 1;
503 } else if (rc == 2) {
504 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
505 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
506 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
507 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
508 netaddresschange = 1;
509 }
510 }
511 while ( rc <= 2);
512
513 freekeyvalues(kv);
514 return 1;
515 }
516
517 // Let user change GREEN address.
518 int greenaddressmenu(void)
519 {
520 struct keyvalue *kv = initkeyvalues();
521 char message[1000];
522 int rc;
523
524 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
525 {
526 freekeyvalues(kv);
527 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
528 return 0;
529 }
530
531 sprintf(message, ctr[TR_WARNING_LONG], NAME);
532 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
533
534 if (rc == 0 || rc == 1)
535 {
536 if (changeaddress(kv, "GREEN", 0, ""))
537 {
538 netaddresschange = 1;
539 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
540 writehostsfiles();
541 }
542 }
543
544 freekeyvalues(kv);
545
546 return 0;
547 }
548
549 // They can change BLUE, ORANGE and GREEN too :)
550 int addressesmenu(void)
551 {
552 struct keyvalue *kv = initkeyvalues();
553 struct keyvalue *mainkv = initkeyvalues();
554 int rc = 0;
555 char *sections[5];
556 char *green = "GREEN";
557 char *orange = "ORANGE";
558 char *blue = "BLUE";
559 char *red = "RED";
560 int c = 0;
561 char greenaddress[STRING_SIZE];
562 char oldgreenaddress[STRING_SIZE];
563 char temp[STRING_SIZE];
564 char temp2[STRING_SIZE];
565 char message[1000];
566 int configtype;
567 int done;
568 int choice;
569 char hostname[STRING_SIZE];
570
571 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
572 {
573 freekeyvalues(kv);
574 freekeyvalues(mainkv);
575 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
576 return 0;
577 }
578 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
579 {
580 freekeyvalues(kv);
581 freekeyvalues(mainkv);
582 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
583 return 0;
584 }
585
586 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
587 configtype = atol(temp);
588
589 sections[c] = green;
590 c++;
591 if (HAS_BLUE)
592 {
593 sections[c] = blue;
594 c++;
595 }
596 if (HAS_ORANGE)
597 {
598 sections[c] = orange;
599 c++;
600 }
601 if (HAS_RED)
602 {
603 sections[c] = red;
604 c++;
605 }
606 sections[c] = NULL;
607
608 choice = 0;
609 done = 0;
610 while (!done)
611 {
612 rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
613 ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
614 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
615
616 if (rc == 0 || rc == 1)
617 {
618 if (strcmp(sections[choice], "GREEN") == 0)
619 {
620 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
621 sprintf(message, ctr[TR_WARNING_LONG], NAME);
622 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
623 message);
624 if (rc == 0 || rc == 1)
625 {
626 if (changeaddress(kv, "GREEN", 0, ""))
627 {
628 netaddresschange = 1;
629 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
630 writehostsfiles();
631 findkey(kv, "GREEN_ADDRESS", greenaddress);
632 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
633 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
634 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
635 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
636 }
637 }
638 }
639 if (strcmp(sections[choice], "BLUE") == 0)
640 {
641 if (changeaddress(kv, "BLUE", 0, ""))
642 netaddresschange = 1;
643 }
644 if (strcmp(sections[choice], "ORANGE") == 0)
645 {
646 if (changeaddress(kv, "ORANGE", 0, ""))
647 netaddresschange = 1;
648 }
649 if (strcmp(sections[choice], "RED") == 0)
650 {
651 strcpy(hostname, "");
652 findkey(mainkv, "HOSTNAME", hostname);
653 if (changeaddress(kv, "RED", 1, hostname))
654 netaddresschange = 1;
655 }
656 }
657 else
658 done = 1;
659 }
660
661 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
662 freekeyvalues(kv);
663 freekeyvalues(mainkv);
664
665 return 0;
666 }
667
668 /* DNS and default gateway.... */
669 int dnsgatewaymenu(void)
670 {
671 struct keyvalue *kv = initkeyvalues();
672 char message[1000];
673 char temp[STRING_SIZE] = "0";
674 struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
675 char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
676 int error;
677 int configtype;
678 int rc;
679
680 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
681 {
682 freekeyvalues(kv);
683 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
684 return 0;
685 }
686
687 entries[DNS1].text = ctr[TR_PRIMARY_DNS];
688 strcpy(temp, ""); findkey(kv, "DNS1", temp);
689 values[DNS1] = strdup(temp);
690 entries[DNS1].value = &values[DNS1];
691 entries[DNS1].flags = 0;
692
693 entries[DNS2].text = ctr[TR_SECONDARY_DNS];
694 strcpy(temp, ""); findkey(kv, "DNS2", temp);
695 values[DNS2] = strdup(temp);
696 entries[DNS2].value = &values[DNS2];
697 entries[DNS2].flags = 0;
698
699 entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY];
700 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
701 values[DEFAULT_GATEWAY] = strdup(temp);
702 entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
703 entries[DEFAULT_GATEWAY].flags = 0;
704
705 entries[DNSGATEWAY_TOTAL].text = NULL;
706 entries[DNSGATEWAY_TOTAL].value = NULL;
707 entries[DNSGATEWAY_TOTAL].flags = 0;
708
709 do
710 {
711 error = 0;
712
713 rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS],
714 ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries,
715 ctr[TR_OK], ctr[TR_CANCEL], NULL);
716 if (rc == 0 || rc == 1)
717 {
718 strcpy(message, ctr[TR_INVALID_FIELDS]);
719 if (strlen(values[DNS1]))
720 {
721 if (inet_addr(values[DNS1]) == INADDR_NONE)
722 {
723 strcat(message, ctr[TR_PRIMARY_DNS_CR]);
724 error = 1;
725 }
726 }
727 if (strlen(values[DNS2]))
728 {
729 if (inet_addr(values[DNS2]) == INADDR_NONE)
730 {
731 strcat(message, ctr[TR_SECONDARY_DNS_CR]);
732 error = 1;
733 }
734 }
735 if (strlen(values[DEFAULT_GATEWAY]))
736 {
737 if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
738 {
739 strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]);
740 error = 1;
741 }
742 }
743 if (!strlen(values[DNS1]) && strlen(values[DNS2]))
744 {
745 strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]);
746 error = 1;
747 }
748
749 if (error)
750 errorbox(message);
751 else
752 {
753 replacekeyvalue(kv, "DNS1", values[DNS1]);
754 replacekeyvalue(kv, "DNS2", values[DNS2]);
755 replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
756 netaddresschange = 1;
757 free(values[DNS1]);
758 free(values[DNS2]);
759 free(values[DEFAULT_GATEWAY]);
760 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
761 }
762 }
763 }
764 while (error);
765
766 freekeyvalues(kv);
767
768 return 1;
769 }