]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/install+setup/setup/networking.c
httpscert: Increase size of the RSA key to 4096.
[people/teissler/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(void);
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
65 netaddresschange = 0;
66
67 found = scan_network_cards();
68 found = init_knics();
69
70 done = 0;
71 while (!done)
72 {
73 choice = firstmenu();
74
75 switch (choice)
76 {
77 case 1:
78 configtypemenu();
79 break;
80
81 case 2:
82 drivermenu();
83 break;
84
85 case 3:
86 addressesmenu();
87 break;
88
89 case 4:
90 dnsgatewaymenu();
91 break;
92
93 case 0:
94 if (oktoleave()) done = 1;
95 break;
96
97 default:
98 break;
99 }
100 }
101
102 if (automode == 0)
103 {
104 /* Restart networking! */
105 if (netaddresschange)
106 {
107 runcommandwithstatus("/etc/rc.d/init.d/network stop",
108 ctr[TR_PUSHING_NETWORK_DOWN]);
109
110 rename_nics();
111
112 runcommandwithstatus("/etc/rc.d/init.d/network start",
113 ctr[TR_PULLING_NETWORK_UP]);
114 }
115 }
116 create_udev();
117 return 1;
118 }
119
120 int oktoleave(void)
121 {
122 struct keyvalue *kv = initkeyvalues();
123 char temp[STRING_SIZE];
124 int configtype;
125 int rc;
126
127 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
128 {
129 freekeyvalues(kv);
130 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
131 return 0;
132 }
133
134 strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
135 if (configtype < 1 || configtype > 4) configtype = 1;
136
137 if (HAS_GREEN)
138 {
139 strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
140 if (!(strlen(temp)))
141 {
142 errorbox(ctr[TR_NO_GREEN_INTERFACE]);
143 freekeyvalues(kv);
144 return 0;
145 }
146 if (!(interfacecheck(kv, "GREEN")))
147 {
148 errorbox(ctr[TR_MISSING_GREEN_IP]);
149 freekeyvalues(kv);
150 return 0;
151 }
152 }
153 if (HAS_RED)
154 {
155
156 strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
157 if (!(strlen(temp)))
158 {
159 rc = newtWinChoice(ctr[TR_ERROR], ctr[TR_OK], ctr[TR_IGNORE], ctr[TR_NO_RED_INTERFACE]);
160 if (rc == 0 || rc == 1)
161 {
162 freekeyvalues(kv);
163 return 0;
164 }
165 }
166 if (!(interfacecheck(kv, "RED")))
167 {
168 errorbox(ctr[TR_MISSING_RED_IP]);
169 freekeyvalues(kv);
170 return 0;
171 }
172 }
173 if (HAS_ORANGE)
174 {
175 strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
176 if (!(strlen(temp)))
177 {
178 errorbox(ctr[TR_NO_ORANGE_INTERFACE]);
179 freekeyvalues(kv);
180 return 0;
181 }
182 if (!(interfacecheck(kv, "ORANGE")))
183 {
184 errorbox(ctr[TR_MISSING_ORANGE_IP]);
185 freekeyvalues(kv);
186 return 0;
187 }
188 }
189 if (HAS_BLUE)
190 {
191 strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
192 if (!(strlen(temp)))
193 {
194 errorbox(ctr[TR_NO_BLUE_INTERFACE]);
195 freekeyvalues(kv);
196 return 0;
197 }
198 if (!(interfacecheck(kv, "BLUE")))
199 {
200 errorbox(ctr[TR_MISSING_BLUE_IP]);
201 freekeyvalues(kv);
202 return 0;
203 }
204 }
205
206 strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
207 if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
208 {
209 strcpy(temp, ""); findkey(kv, "DNS1", temp);
210 if (!(strlen(temp)))
211 {
212 errorbox(ctr[TR_MISSING_DNS]);
213 freekeyvalues(kv);
214 return 0;
215 }
216 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
217 if (!(strlen(temp)))
218 {
219 errorbox(ctr[TR_MISSING_DEFAULT]);
220 freekeyvalues(kv);
221 return 0;
222 }
223 }
224 return 1;
225 }
226
227
228 /* Shows the main menu and a summary of the current settings. */
229 int firstmenu(void)
230 {
231 char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE],
232 ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS],
233 ctr[TR_ADDRESS_SETTINGS],
234 ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL };
235 int rc;
236 static int choice = 0;
237 struct keyvalue *kv = initkeyvalues();
238 char message[1000];
239 char temp[STRING_SIZE] = "1";
240 int x;
241 int result;
242 char networkrestart[STRING_SIZE] = "";
243
244 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
245 {
246 freekeyvalues(kv);
247 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
248 return 0;
249 }
250
251 if (netaddresschange)
252 strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]);
253
254 strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp);
255 x = atol(temp);
256 x--;
257 if (x < 0 || x > 4) x = 0;
258 /* Format heading bit. */
259 snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x],
260 networkrestart);
261 rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6,
262 sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
263
264 if (rc == 0 || rc == 1)
265 result = choice + 1;
266 else
267 result = 0;
268
269 return result;
270 }
271
272 /* Here they choose general network config, number of nics etc. */
273 int configtypemenu(void)
274 {
275 struct keyvalue *kv = initkeyvalues();
276 char temp[STRING_SIZE] = "1";
277 char message[1000];
278 int choise, found;
279 int rc, configtype;
280
281 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
282 {
283 freekeyvalues(kv);
284 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
285 return 0;
286 }
287
288 found = scan_network_cards();
289
290 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
291 choise--;
292
293 sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME);
294 rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5,
295 6, configtypenames, &choise, ctr[TR_OK], ctr[TR_CANCEL], NULL);
296 if ( configtypecards[choise] > found ) {
297 sprintf(message, ctr[TR_NOT_ENOUGH_INTERFACES] , configtypecards[choise], found);
298 errorbox(message);
299 }
300
301 if (rc == 0 || rc == 1)
302 {
303 choise++;
304 sprintf(temp, "%d", choise);
305 replacekeyvalue(kv, "CONFIG_TYPE", temp);
306 configtype = atol(temp);
307 if (!HAS_RED)
308 clear_card_entry(_RED_CARD_);
309 if (!HAS_ORANGE)
310 clear_card_entry(_ORANGE_CARD_);
311 if (!HAS_BLUE)
312 clear_card_entry(_BLUE_CARD_);
313
314 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
315 netaddresschange = 1;
316 }
317 freekeyvalues(kv);
318
319 return 0;
320 }
321
322 /* Driver menu. Choose drivers.. */
323 int drivermenu(void)
324 {
325 struct keyvalue *kv = initkeyvalues();
326 char message[STRING_SIZE];
327 char temp[STRING_SIZE] = "1";
328
329 int configtype;
330 int i, rc, kcount = 0, neednics;
331
332 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
333 {
334 freekeyvalues(kv);
335 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
336 return 0;
337 }
338
339 if (findkey(kv, "CONFIG_TYPE", temp))
340 configtype = atol(temp);
341 else {
342 fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
343 configtype = atol(temp);
344 replacekeyvalue(kv, "CONFIG_TYPE", temp);
345 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
346 }
347
348 strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
349
350 kcount = 0;
351 neednics = 0;
352 if (HAS_GREEN) {
353 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
354 strcat(message, temp);
355 if (strlen(knics[_GREEN_CARD_].macaddr) ) {
356 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
357 strcat(message, temp);
358 }
359 neednics++;
360 }
361 if (HAS_RED) {
362 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
363 strcat(message, temp);
364 if (strlen(knics[_RED_CARD_].macaddr) ) {
365 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
366 strcat(message, temp);
367 }
368 neednics++;
369 }
370 if (HAS_ORANGE) {
371 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
372 strcat(message, temp);
373 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
374 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
375 strcat(message, temp);
376 }
377 neednics++;
378 }
379 if (HAS_BLUE) {
380 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
381 strcat(message, temp);
382 if (strlen(knics[_BLUE_CARD_].macaddr)) {
383 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
384 strcat(message, temp);
385 }
386 neednics++;
387 }
388
389 for ( i=0 ; i<4; i++)
390 if (strcmp(knics[i].macaddr, ""))
391 kcount++;
392
393 if (neednics = kcount)
394 {
395 strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
396 rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
397 ctr[TR_CANCEL], message);
398 if (rc == 0 || rc == 1)
399 {
400 changedrivers();
401 }
402 } else {
403 changedrivers();
404 }
405 freekeyvalues(kv);
406
407 return 1;
408 }
409
410 int set_menu_entry_for(int *nr, int *card)
411 {
412
413 }
414
415 int changedrivers(void)
416 {
417 struct keyvalue *kv = initkeyvalues();
418 char temp[STRING_SIZE], message[STRING_SIZE];
419 int configtype;
420 int green = 0, red = 0, blue = 0, orange = 0;
421 char MenuInhalt[10][180];
422 char *pMenuInhalt[10];
423 int count = 0, choise = 0, rc;
424 int NicEntry[10];
425
426 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
427 {
428 freekeyvalues(kv);
429 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
430 return 0;
431 }
432 if (automode == 0)
433 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
434 ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
435
436 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
437 if (configtype == 1)
438 { green = 1; red = 1; }
439 else if (configtype == 2)
440 { green = 1; red = 1; orange = 1; }
441 else if (configtype == 3)
442 { green = 1; red = 1; blue = 1; }
443 else if (configtype == 4)
444 { green = 1; red=1; orange=1; blue = 1; }
445 else if (configtype == "")
446 { green = 1; red = 1; }
447
448 do
449 {
450 count = 0;
451 strcpy(message, ctr[TR_INTERFACE_CHANGE]);
452
453 if (green) {
454 strcpy(MenuInhalt[count], "GREEN");
455 pMenuInhalt[count] = MenuInhalt[count];
456 NicEntry[_GREEN_CARD_] = count;
457 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
458 strcat(message, temp);
459 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
460 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
461 strcat(message, temp);
462 }
463 count++;
464 }
465
466 if (red) {
467 strcpy(MenuInhalt[count], "RED");
468 pMenuInhalt[count] = MenuInhalt[count];
469 NicEntry[_RED_CARD_] = count;
470 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
471 strcat(message, temp);
472 if ( strlen(knics[_RED_CARD_].macaddr) ) {
473 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
474 strcat(message, temp);
475 }
476 count++;
477 }
478
479 if (orange) {
480 strcpy(MenuInhalt[count], "ORANGE");
481 pMenuInhalt[count] = MenuInhalt[count];
482 NicEntry[_ORANGE_CARD_] = count;
483 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
484 strcat(message, temp);
485 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
486 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
487 strcat(message, temp);
488 }
489 count++;
490 }
491
492 if (blue) {
493 strcpy(MenuInhalt[count], "BLUE");
494 pMenuInhalt[count] = MenuInhalt[count];
495 NicEntry[_BLUE_CARD_] = count;
496 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
497 strcat(message, temp);
498 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
499 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
500 strcat(message, temp);
501 }
502 count++;
503 }
504 pMenuInhalt[count] = NULL;
505
506 rc = newtWinMenu( ctr[TR_NETCARD_COLOR], message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_REMOVE], ctr[TR_DONE], NULL);
507
508 if ( rc == 0 || rc == 1) {
509 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
510 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
511 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
512 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
513 netaddresschange = 1;
514 } else if (rc == 2) {
515 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
516 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
517 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
518 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
519 netaddresschange = 1;
520 }
521 }
522 while ( rc <= 2);
523
524 freekeyvalues(kv);
525 return 1;
526 }
527
528 // Let user change GREEN address.
529 int greenaddressmenu(void)
530 {
531 struct keyvalue *kv = initkeyvalues();
532 char message[1000];
533 int rc;
534
535 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
536 {
537 freekeyvalues(kv);
538 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
539 return 0;
540 }
541
542 sprintf(message, ctr[TR_WARNING_LONG], NAME);
543 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
544
545 if (rc == 0 || rc == 1)
546 {
547 if (changeaddress(kv, "GREEN", 0, ""))
548 {
549 netaddresschange = 1;
550 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
551 writehostsfiles();
552 }
553 }
554
555 freekeyvalues(kv);
556
557 return 0;
558 }
559
560 // They can change BLUE, ORANGE and GREEN too :)
561 int addressesmenu(void)
562 {
563 struct keyvalue *kv = initkeyvalues();
564 struct keyvalue *mainkv = initkeyvalues();
565 int rc = 0;
566 char *sections[5];
567 char *green = "GREEN";
568 char *orange = "ORANGE";
569 char *blue = "BLUE";
570 char *red = "RED";
571 int c = 0;
572 char greenaddress[STRING_SIZE];
573 char oldgreenaddress[STRING_SIZE];
574 char temp[STRING_SIZE];
575 char temp2[STRING_SIZE];
576 char message[1000];
577 int configtype;
578 int done;
579 int choice;
580 char hostname[STRING_SIZE];
581
582 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
583 {
584 freekeyvalues(kv);
585 freekeyvalues(mainkv);
586 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
587 return 0;
588 }
589 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
590 {
591 freekeyvalues(kv);
592 freekeyvalues(mainkv);
593 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
594 return 0;
595 }
596
597 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
598 configtype = atol(temp);
599
600 sections[c] = green;
601 c++;
602 if (HAS_BLUE)
603 {
604 sections[c] = blue;
605 c++;
606 }
607 if (HAS_ORANGE)
608 {
609 sections[c] = orange;
610 c++;
611 }
612 if (HAS_RED)
613 {
614 sections[c] = red;
615 c++;
616 }
617 sections[c] = NULL;
618
619 choice = 0;
620 done = 0;
621 while (!done)
622 {
623 rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
624 ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
625 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
626
627 if (rc == 0 || rc == 1)
628 {
629 if (strcmp(sections[choice], "GREEN") == 0)
630 {
631 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
632 sprintf(message, ctr[TR_WARNING_LONG], NAME);
633 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
634 message);
635 if (rc == 0 || rc == 1)
636 {
637 if (changeaddress(kv, "GREEN", 0, ""))
638 {
639 netaddresschange = 1;
640 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
641 writehostsfiles();
642 findkey(kv, "GREEN_ADDRESS", greenaddress);
643 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
644 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
645 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
646 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
647 }
648 }
649 }
650 if (strcmp(sections[choice], "BLUE") == 0)
651 {
652 if (changeaddress(kv, "BLUE", 0, ""))
653 netaddresschange = 1;
654 }
655 if (strcmp(sections[choice], "ORANGE") == 0)
656 {
657 if (changeaddress(kv, "ORANGE", 0, ""))
658 netaddresschange = 1;
659 }
660 if (strcmp(sections[choice], "RED") == 0)
661 {
662 strcpy(hostname, "");
663 findkey(mainkv, "HOSTNAME", hostname);
664 if (changeaddress(kv, "RED", 1, hostname))
665 netaddresschange = 1;
666 }
667 }
668 else
669 done = 1;
670 }
671
672 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
673 freekeyvalues(kv);
674 freekeyvalues(mainkv);
675
676 return 0;
677 }
678
679 /* DNS and default gateway.... */
680 int dnsgatewaymenu(void)
681 {
682 struct keyvalue *kv = initkeyvalues();
683 char message[1000];
684 char temp[STRING_SIZE] = "0";
685 struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
686 char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
687 int error;
688 int configtype;
689 int rc;
690
691 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
692 {
693 freekeyvalues(kv);
694 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
695 return 0;
696 }
697
698 entries[DNS1].text = ctr[TR_PRIMARY_DNS];
699 strcpy(temp, ""); findkey(kv, "DNS1", temp);
700 values[DNS1] = strdup(temp);
701 entries[DNS1].value = &values[DNS1];
702 entries[DNS1].flags = 0;
703
704 entries[DNS2].text = ctr[TR_SECONDARY_DNS];
705 strcpy(temp, ""); findkey(kv, "DNS2", temp);
706 values[DNS2] = strdup(temp);
707 entries[DNS2].value = &values[DNS2];
708 entries[DNS2].flags = 0;
709
710 entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY];
711 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
712 values[DEFAULT_GATEWAY] = strdup(temp);
713 entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
714 entries[DEFAULT_GATEWAY].flags = 0;
715
716 entries[DNSGATEWAY_TOTAL].text = NULL;
717 entries[DNSGATEWAY_TOTAL].value = NULL;
718 entries[DNSGATEWAY_TOTAL].flags = 0;
719
720 do
721 {
722 error = 0;
723
724 rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS],
725 ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries,
726 ctr[TR_OK], ctr[TR_CANCEL], NULL);
727 if (rc == 0 || rc == 1)
728 {
729 strcpy(message, ctr[TR_INVALID_FIELDS]);
730 if (strlen(values[DNS1]))
731 {
732 if (inet_addr(values[DNS1]) == INADDR_NONE)
733 {
734 strcat(message, ctr[TR_PRIMARY_DNS_CR]);
735 error = 1;
736 }
737 }
738 if (strlen(values[DNS2]))
739 {
740 if (inet_addr(values[DNS2]) == INADDR_NONE)
741 {
742 strcat(message, ctr[TR_SECONDARY_DNS_CR]);
743 error = 1;
744 }
745 }
746 if (strlen(values[DEFAULT_GATEWAY]))
747 {
748 if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
749 {
750 strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]);
751 error = 1;
752 }
753 }
754 if (!strlen(values[DNS1]) && strlen(values[DNS2]))
755 {
756 strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]);
757 error = 1;
758 }
759
760 if (error)
761 errorbox(message);
762 else
763 {
764 replacekeyvalue(kv, "DNS1", values[DNS1]);
765 replacekeyvalue(kv, "DNS2", values[DNS2]);
766 replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
767 netaddresschange = 1;
768 free(values[DNS1]);
769 free(values[DNS2]);
770 free(values[DEFAULT_GATEWAY]);
771 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
772 }
773 }
774 }
775 while (error);
776
777 freekeyvalues(kv);
778
779 return 1;
780 }