]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/install+setup/setup/networking.c
Translations fuer den Installer gemacht
[people/pmueller/ipfire-2.x.git] / src / install+setup / setup / networking.c
CommitLineData
069680ac
MT
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 *
069680ac
MT
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
18extern FILE *flog;
19extern char *mylog;
20
21extern char **ctr;
22
23extern int automode;
24
5057b611 25#define HAS_GREEN 1
9b040aa0
HS
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
069680ac 31extern struct nic nics[];
5057b611 32extern struct knic knics[];
069680ac 33
a358af8c 34char *configtypenames[] = {
9b040aa0
HS
35 "GREEN + RED",
36 "GREEN + RED + ORANGE",
37 "GREEN + RED + BLUE",
38 "GREEN + RED + ORANGE + BLUE",
39 NULL };
40int configtypecards[] = {
9b040aa0
HS
41 2, // "GREEN + RED",
42 3, // "GREEN + RED + ORANGE",
43 3, // "GREEN + RED + BLUE",
6fc15159 44 4 // "GREEN + RED + ORANGE + BLUE",
9b040aa0
HS
45};
46
47
069680ac
MT
48int netaddresschange;
49
50int oktoleave(char *errormessage);
51int firstmenu(void);
52int configtypemenu(void);
53int drivermenu(void);
54int changedrivers(void);
55int greenaddressmenu(void);
56int addressesmenu(void);
57int dnsgatewaymenu(void);
58
59int handlenetworking(void)
60{
61 int done;
62 int choice;
9b040aa0 63 int found;
069680ac
MT
64 char errormessage[STRING_SIZE];
65
66 netaddresschange = 0;
67
9b040aa0 68 found = scan_network_cards();
9c1c1c57 69 found = init_knics();
9b040aa0 70
069680ac
MT
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]);
eea0467a
HS
113
114 rename_nics();
115
069680ac
MT
116 runcommandwithstatus("/etc/rc.d/init.d/network start",
117 ctr[TR_PULLING_NETWORK_UP]);
069680ac
MT
118 }
119 }
84e975ba 120 create_udev();
069680ac
MT
121 return 1;
122}
123
124int 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);
de53a053 138 if (configtype < 1 || configtype > 4) configtype = 0;
069680ac 139
f93a4b4f 140 if (HAS_GREEN)
069680ac 141 {
f93a4b4f 142 strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
069680ac
MT
143 if (!(strlen(temp)))
144 {
f93a4b4f 145 strcpy(errormessage, ctr[TR_NO_GREEN_INTERFACE]);
069680ac
MT
146 goto EXIT;
147 }
f93a4b4f 148 if (!(interfacecheck(kv, "GREEN")))
069680ac 149 {
1700769c 150 strcpy(errormessage, ctr[TR_MISSING_GREEN_IP]);
f93a4b4f
HS
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]);
069680ac
MT
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 }
f93a4b4f 182 if (HAS_BLUE)
069680ac 183 {
f93a4b4f 184 strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
069680ac
MT
185 if (!(strlen(temp)))
186 {
f93a4b4f 187 strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]);
069680ac
MT
188 goto EXIT;
189 }
f93a4b4f 190 if (!(interfacecheck(kv, "BLUE")))
069680ac 191 {
f93a4b4f
HS
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 {
1700769c 201 strcpy(errormessage, ctr[TR_MISSING_DNS]);
f93a4b4f
HS
202 goto EXIT;
203 }
204 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
205 if (!(strlen(temp)))
206 {
1700769c 207 strcpy(errormessage, ctr[TR_MISSING_DEFAULT]);
069680ac
MT
208 goto EXIT;
209 }
210 }
211 strcpy(errormessage, "");
212EXIT:
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. */
223int 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);
de53a053 249 if (x < 1 || x > 4) x = 0;
069680ac
MT
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. */
265int configtypemenu(void)
266{
267 struct keyvalue *kv = initkeyvalues();
268 char temp[STRING_SIZE] = "0";
269 char message[1000];
9b040aa0 270 int choise, found;
069680ac
MT
271 int rc;
272
9b040aa0
HS
273 fprintf(flog,"Enter ConfigMenu\n");
274
069680ac
MT
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 }
9b040aa0
HS
281
282 found = scan_network_cards();
069680ac 283
9b040aa0 284 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
6fc15159 285 choise--;
9b040aa0
HS
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 ) {
1700769c 293 sprintf(message, ctr[TR_NOT_ENOUGH_INTERFACES] , configtypecards[choise], found);
9b040aa0
HS
294 errorbox(message);
295 }
296 }
297 while ( configtypecards[choise] > found);
069680ac
MT
298
299 if (rc == 0 || rc == 1)
300 {
a358af8c 301 choise++;
9b040aa0 302 sprintf(temp, "%d", choise);
069680ac 303 replacekeyvalue(kv, "CONFIG_TYPE", temp);
9b040aa0
HS
304 clear_card_entry(_RED_CARD_);
305 clear_card_entry(_ORANGE_CARD_);
306 clear_card_entry(_BLUE_CARD_);
307
069680ac
MT
308 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
309 netaddresschange = 1;
310 }
069680ac
MT
311 freekeyvalues(kv);
312
313 return 0;
314}
315
9c1c1c57
HS
316
317
069680ac
MT
318/* Driver menu. Choose drivers.. */
319int drivermenu(void)
320{
321 struct keyvalue *kv = initkeyvalues();
5057b611
HS
322 char message[STRING_SIZE];
323 char temp[STRING_SIZE];
9c1c1c57 324
069680ac 325 int configtype;
9c1c1c57 326 int i, rc, kcount = 0, neednics; //i = 0, count = 0,
069680ac
MT
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
069680ac 338 strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
5057b611 339
5057b611
HS
340 kcount = 0; // counter to find knowing nics.
341 neednics = 0; // counter to use needing nics.
342 if (HAS_GREEN) {
5057b611
HS
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++;
75ae2191 350 }
5057b611 351 if (HAS_RED) {
5057b611
HS
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);
75ae2191 357 }
5057b611 358 neednics++;
069680ac 359 }
75ae2191 360 if (HAS_ORANGE) {
5057b611
HS
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++;
75ae2191 368 }
5057b611 369 if (HAS_BLUE) {
5057b611
HS
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);
75ae2191 375 }
5057b611 376 neednics++;
069680ac 377 }
5057b611 378
9c1c1c57 379 for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++;
5057b611 380
f93a4b4f
HS
381 if (neednics = kcount)
382 {
5057b611
HS
383 strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
384 rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
069680ac 385 ctr[TR_CANCEL], message);
5057b611
HS
386 if (rc == 0 || rc == 1)
387 {
388 /* Shit, got to do something.. */
389 changedrivers();
390 }
391 } else {
069680ac
MT
392 /* Shit, got to do something.. */
393 changedrivers();
394 }
069680ac
MT
395 freekeyvalues(kv);
396
397 return 1;
398}
399
9b040aa0
HS
400int set_menu_entry_for(int *nr, int *card)
401{
402
403}
404
069680ac
MT
405int changedrivers(void)
406{
407 struct keyvalue *kv = initkeyvalues();
5057b611 408 char temp[STRING_SIZE], message[STRING_SIZE];
069680ac 409 int configtype;
75ae2191 410 int green = 0, red = 0, blue = 0, orange = 0;
5057b611
HS
411 char MenuInhalt[10][180];
412 char *pMenuInhalt[10];
413 int count = 0, choise = 0, rc;
414 int NicEntry[10];
59de0b00 415
069680ac
MT
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 }
75ae2191
MT
422 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
423 ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
59de0b00 424
5057b611 425 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
a358af8c 426 if (configtype == 1)
75ae2191 427 { green = 1; red = 1; }
9b040aa0 428 else if (configtype == 2)
75ae2191 429 { green = 1; red = 1; orange = 1; }
9b040aa0 430 else if (configtype == 3)
75ae2191 431 { green = 1; red = 1; blue = 1; }
9b040aa0
HS
432 else if (configtype == 4)
433 { green = 1; red=1; orange=1; blue = 1; }
5057b611
HS
434
435 do
436 {
437 count = 0;
1700769c 438 strcpy(message, ctr[TR_INTERFACE_CHANGE]);
5057b611
HS
439
440 if (green) {
441 strcpy(MenuInhalt[count], "GREEN");
442 pMenuInhalt[count] = MenuInhalt[count];
443 NicEntry[_GREEN_CARD_] = count;
5057b611
HS
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;
5057b611
HS
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;
5057b611
HS
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;
5057b611
HS
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
1700769c 493 rc = newtWinMenu( ctr[TR_NETCARD_COLOR], message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_REMOVE], ctr[TR_DONE], NULL);
5057b611
HS
494
495 if ( rc == 0 || rc == 1) {
9b040aa0
HS
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_);
eea0467a 500 netaddresschange = 1;
5057b611 501 } else if (rc == 2) {
9b040aa0
HS
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_);
eea0467a 506 netaddresschange = 1;
a358af8c 507 }
5057b611
HS
508 }
509 while ( rc <= 2);
069680ac
MT
510
511 freekeyvalues(kv);
069680ac
MT
512 return 1;
513}
514
75ae2191 515// Let user change GREEN address.
069680ac
MT
516int 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
75ae2191 547// They can change BLUE, ORANGE and GREEN too :)
069680ac
MT
548int 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.... */
667int 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
069680ac
MT
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}