]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/setup/networking.c
Merge branch 'kernel-test' into seventeen
[people/pmueller/ipfire-2.x.git] / src / 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 9 */
e1457ba0
MT
10
11// Translation
12#include <libintl.h>
13#define _(x) dgettext("setup", x)
14
069680ac
MT
15#include "setup.h"
16
17#define DNS1 0
18#define DNS2 1
19#define DEFAULT_GATEWAY 2
20#define DNSGATEWAY_TOTAL 3
21
22extern FILE *flog;
23extern char *mylog;
24
069680ac
MT
25extern int automode;
26
5057b611 27#define HAS_GREEN 1
9b040aa0
HS
28#define HAS_RED (configtype == 1 || configtype == 2 || configtype == 3 || configtype == 4)
29#define HAS_ORANGE (configtype == 2 || configtype == 4)
30#define HAS_BLUE (configtype == 3 || configtype == 4)
31#define RED_IS_NOT_ETH (configtype == 0)
32
069680ac 33extern struct nic nics[];
5057b611 34extern struct knic knics[];
069680ac 35
a358af8c 36char *configtypenames[] = {
9b040aa0
HS
37 "GREEN + RED",
38 "GREEN + RED + ORANGE",
39 "GREEN + RED + BLUE",
40 "GREEN + RED + ORANGE + BLUE",
41 NULL };
42int configtypecards[] = {
9b040aa0
HS
43 2, // "GREEN + RED",
44 3, // "GREEN + RED + ORANGE",
45 3, // "GREEN + RED + BLUE",
6fc15159 46 4 // "GREEN + RED + ORANGE + BLUE",
9b040aa0
HS
47};
48
49
069680ac
MT
50int netaddresschange;
51
855446c6 52int oktoleave(void);
069680ac
MT
53int firstmenu(void);
54int configtypemenu(void);
55int drivermenu(void);
56int changedrivers(void);
57int greenaddressmenu(void);
58int addressesmenu(void);
59int dnsgatewaymenu(void);
60
61int handlenetworking(void)
62{
63 int done;
64 int choice;
9b040aa0 65 int found;
069680ac
MT
66
67 netaddresschange = 0;
68
9b040aa0 69 found = scan_network_cards();
9c1c1c57 70 found = init_knics();
9b040aa0 71
069680ac
MT
72 done = 0;
73 while (!done)
74 {
75 choice = firstmenu();
76
77 switch (choice)
78 {
79 case 1:
80 configtypemenu();
81 break;
82
83 case 2:
84 drivermenu();
85 break;
86
87 case 3:
88 addressesmenu();
89 break;
90
91 case 4:
92 dnsgatewaymenu();
93 break;
94
95 case 0:
855446c6 96 if (oktoleave()) done = 1;
069680ac
MT
97 break;
98
99 default:
100 break;
101 }
102 }
103
104 if (automode == 0)
105 {
106 /* Restart networking! */
107 if (netaddresschange)
108 {
109 runcommandwithstatus("/etc/rc.d/init.d/network stop",
46b56e20 110 _("Networking"), _("Stopping network..."), NULL);
eea0467a
HS
111
112 rename_nics();
113
069680ac 114 runcommandwithstatus("/etc/rc.d/init.d/network start",
46b56e20 115 _("Networking"), _("Restarting network..."), NULL);
069680ac 116 }
a5d81233
AF
117 } else {
118 rename_nics();
069680ac 119 }
84e975ba 120 create_udev();
069680ac
MT
121 return 1;
122}
123
855446c6 124int oktoleave(void)
069680ac
MT
125{
126 struct keyvalue *kv = initkeyvalues();
127 char temp[STRING_SIZE];
128 int configtype;
855446c6 129 int rc;
069680ac
MT
130
131 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
132 {
133 freekeyvalues(kv);
e1457ba0 134 errorbox(_("Unable to open settings file"));
069680ac
MT
135 return 0;
136 }
137
0db33b56
MT
138 strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
139 if (configtype < 1 || configtype > 4) configtype = 1;
069680ac 140
f93a4b4f 141 if (HAS_GREEN)
069680ac 142 {
f93a4b4f 143 strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
069680ac
MT
144 if (!(strlen(temp)))
145 {
e1457ba0 146 errorbox(_("No GREEN interface assigned."));
855446c6
MT
147 freekeyvalues(kv);
148 return 0;
069680ac 149 }
f93a4b4f 150 if (!(interfacecheck(kv, "GREEN")))
069680ac 151 {
e1457ba0 152 errorbox(_("Missing an IP address on GREEN."));
855446c6
MT
153 freekeyvalues(kv);
154 return 0;
f93a4b4f
HS
155 }
156 }
157 if (HAS_RED)
158 {
855446c6 159
f93a4b4f
HS
160 strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
161 if (!(strlen(temp)))
162 {
e1457ba0
MT
163 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
164 _("No RED interface assigned."));
855446c6
MT
165 if (rc == 0 || rc == 1)
166 {
167 freekeyvalues(kv);
168 return 0;
169 }
f93a4b4f
HS
170 }
171 if (!(interfacecheck(kv, "RED")))
172 {
e1457ba0 173 errorbox(_("Missing an IP address on RED."));
855446c6
MT
174 freekeyvalues(kv);
175 return 0;
069680ac
MT
176 }
177 }
178 if (HAS_ORANGE)
179 {
180 strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
181 if (!(strlen(temp)))
182 {
e1457ba0 183 errorbox(_("No ORANGE interface assigned."));
855446c6
MT
184 freekeyvalues(kv);
185 return 0;
069680ac
MT
186 }
187 if (!(interfacecheck(kv, "ORANGE")))
188 {
e1457ba0 189 errorbox(_("Missing an IP address on ORANGE."));
855446c6
MT
190 freekeyvalues(kv);
191 return 0;
069680ac
MT
192 }
193 }
f93a4b4f 194 if (HAS_BLUE)
069680ac 195 {
f93a4b4f 196 strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
069680ac
MT
197 if (!(strlen(temp)))
198 {
e1457ba0 199 errorbox(_("No BLUE interface assigned."));
855446c6
MT
200 freekeyvalues(kv);
201 return 0;
069680ac 202 }
f93a4b4f 203 if (!(interfacecheck(kv, "BLUE")))
069680ac 204 {
e1457ba0 205 errorbox(_("Missing an IP address on BLUE."));
855446c6
MT
206 freekeyvalues(kv);
207 return 0;
f93a4b4f
HS
208 }
209 }
b3f09dd8
MT
210
211 strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
212 if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
f93a4b4f
HS
213 {
214 strcpy(temp, ""); findkey(kv, "DNS1", temp);
215 if (!(strlen(temp)))
216 {
e1457ba0 217 errorbox(_("Misssing DNS."));
855446c6
MT
218 freekeyvalues(kv);
219 return 0;
f93a4b4f
HS
220 }
221 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
222 if (!(strlen(temp)))
223 {
e1457ba0 224 errorbox(_("Missing Default Gateway."));
855446c6
MT
225 freekeyvalues(kv);
226 return 0;
069680ac
MT
227 }
228 }
855446c6 229 return 1;
069680ac
MT
230}
231
232
233/* Shows the main menu and a summary of the current settings. */
234int firstmenu(void)
235{
e1457ba0
MT
236 char *sections[] = {
237 _("Network configuration type"),
238 _("Drivers and card assignments"),
239 _("Address settings"),
240 _("DNS and Gateway settings"),
241 NULL
242 };
069680ac
MT
243 int rc;
244 static int choice = 0;
245 struct keyvalue *kv = initkeyvalues();
246 char message[1000];
0db33b56 247 char temp[STRING_SIZE] = "1";
069680ac
MT
248 int x;
249 int result;
250 char networkrestart[STRING_SIZE] = "";
251
252 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
253 {
254 freekeyvalues(kv);
e1457ba0 255 errorbox(_("Unable to open settings file"));
069680ac
MT
256 return 0;
257 }
258
259 if (netaddresschange)
e1457ba0 260 strcpy(networkrestart, _("When configuration is complete, a network restart will be required."));
069680ac 261
d0f2cc42
MT
262 strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp);
263 x = atol(temp);
264 x--;
0db33b56 265 if (x < 0 || x > 4) x = 0;
069680ac 266 /* Format heading bit. */
782ae35d 267 snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart);
e1457ba0
MT
268 rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6,
269 sections, &choice, _("OK"), _("Done"), NULL);
069680ac
MT
270
271 if (rc == 0 || rc == 1)
272 result = choice + 1;
273 else
274 result = 0;
275
276 return result;
277}
278
279/* Here they choose general network config, number of nics etc. */
280int configtypemenu(void)
281{
282 struct keyvalue *kv = initkeyvalues();
0db33b56 283 char temp[STRING_SIZE] = "1";
069680ac 284 char message[1000];
9b040aa0 285 int choise, found;
0db33b56 286 int rc, configtype;
9b040aa0 287
069680ac
MT
288 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
289 {
290 freekeyvalues(kv);
e1457ba0 291 errorbox(_("Unable to open settings file"));
069680ac
MT
292 return 0;
293 }
9b040aa0
HS
294
295 found = scan_network_cards();
069680ac 296
9b040aa0 297 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
6fc15159 298 choise--;
9b040aa0 299
e1457ba0
MT
300 sprintf(message, _("Select the network configuration for %s. "
301 "The following configuration types list those interfaces which have ethernet attached. "
302 "If you change this setting, a network restart will be required, and you will have to "
303 "reconfigure the network driver assignments."), NAME);
304 rc = newtWinMenu(_("Network configuration type"), message, 50, 5, 5,
305 6, configtypenames, &choise, _("OK"), _("Cancel"), NULL);
9b040aa0 306 if ( configtypecards[choise] > found ) {
e1457ba0
MT
307 sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"),
308 configtypecards[choise], found);
9b040aa0
HS
309 errorbox(message);
310 }
069680ac
MT
311
312 if (rc == 0 || rc == 1)
313 {
a358af8c 314 choise++;
9b040aa0 315 sprintf(temp, "%d", choise);
069680ac 316 replacekeyvalue(kv, "CONFIG_TYPE", temp);
0db33b56
MT
317 configtype = atol(temp);
318 if (!HAS_RED)
319 clear_card_entry(_RED_CARD_);
320 if (!HAS_ORANGE)
321 clear_card_entry(_ORANGE_CARD_);
322 if (!HAS_BLUE)
323 clear_card_entry(_BLUE_CARD_);
9b040aa0 324
069680ac
MT
325 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
326 netaddresschange = 1;
327 }
069680ac
MT
328 freekeyvalues(kv);
329
330 return 0;
331}
332
333/* Driver menu. Choose drivers.. */
334int drivermenu(void)
335{
336 struct keyvalue *kv = initkeyvalues();
5057b611 337 char message[STRING_SIZE];
0db33b56 338 char temp[STRING_SIZE] = "1";
9c1c1c57 339
069680ac 340 int configtype;
0db33b56 341 int i, rc, kcount = 0, neednics;
069680ac
MT
342
343 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
344 {
345 freekeyvalues(kv);
e1457ba0 346 errorbox(_("Unable to open settings file"));
069680ac
MT
347 return 0;
348 }
349
4061c03f
HS
350 if (findkey(kv, "CONFIG_TYPE", temp))
351 configtype = atol(temp);
352 else {
353 fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
354 configtype = atol(temp);
355 replacekeyvalue(kv, "CONFIG_TYPE", temp);
356 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
357 }
358
e1457ba0
MT
359 strcpy(message, _("Configure network drivers, and which interface each card is assigned to. "
360 "The current configuration is as follows:\n\n"));
5057b611 361
0db33b56
MT
362 kcount = 0;
363 neednics = 0;
5057b611 364 if (HAS_GREEN) {
e1457ba0 365 sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
5057b611
HS
366 strcat(message, temp);
367 if (strlen(knics[_GREEN_CARD_].macaddr) ) {
e1457ba0 368 sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
5057b611
HS
369 strcat(message, temp);
370 }
371 neednics++;
75ae2191 372 }
5057b611 373 if (HAS_RED) {
e1457ba0 374 sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
5057b611
HS
375 strcat(message, temp);
376 if (strlen(knics[_RED_CARD_].macaddr) ) {
e1457ba0 377 sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
5057b611 378 strcat(message, temp);
75ae2191 379 }
5057b611 380 neednics++;
069680ac 381 }
75ae2191 382 if (HAS_ORANGE) {
e1457ba0 383 sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
5057b611
HS
384 strcat(message, temp);
385 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
e1457ba0 386 sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
5057b611
HS
387 strcat(message, temp);
388 }
389 neednics++;
75ae2191 390 }
5057b611 391 if (HAS_BLUE) {
e1457ba0 392 sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
5057b611
HS
393 strcat(message, temp);
394 if (strlen(knics[_BLUE_CARD_].macaddr)) {
e1457ba0 395 sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
5057b611 396 strcat(message, temp);
75ae2191 397 }
5057b611 398 neednics++;
069680ac 399 }
5057b611 400
0db33b56
MT
401 for ( i=0 ; i<4; i++)
402 if (strcmp(knics[i].macaddr, ""))
403 kcount++;
5057b611 404
f93a4b4f
HS
405 if (neednics = kcount)
406 {
e1457ba0
MT
407 strcat(message, "\n");
408 strcat(message, _("Do you wish to change these settings?"));
409 rc = newtWinChoice(_("Drivers and card assignments"), _("OK"),
410 _("Cancel"), message);
5057b611
HS
411 if (rc == 0 || rc == 1)
412 {
5057b611
HS
413 changedrivers();
414 }
415 } else {
069680ac
MT
416 changedrivers();
417 }
069680ac
MT
418 freekeyvalues(kv);
419
420 return 1;
421}
422
9b040aa0
HS
423int set_menu_entry_for(int *nr, int *card)
424{
425
426}
427
069680ac
MT
428int changedrivers(void)
429{
430 struct keyvalue *kv = initkeyvalues();
5057b611 431 char temp[STRING_SIZE], message[STRING_SIZE];
069680ac 432 int configtype;
75ae2191 433 int green = 0, red = 0, blue = 0, orange = 0;
5057b611
HS
434 char MenuInhalt[10][180];
435 char *pMenuInhalt[10];
436 int count = 0, choise = 0, rc;
437 int NicEntry[10];
59de0b00 438
069680ac
MT
439 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
440 {
441 freekeyvalues(kv);
e1457ba0 442 errorbox(_("Unable to open settings file"));
069680ac
MT
443 return 0;
444 }
0db33b56
MT
445 if (automode == 0)
446 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
46b56e20 447 _("Networking"), _("Restarting non-local network..."), NULL);
59de0b00 448
5057b611 449 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
a358af8c 450 if (configtype == 1)
75ae2191 451 { green = 1; red = 1; }
9b040aa0 452 else if (configtype == 2)
75ae2191 453 { green = 1; red = 1; orange = 1; }
9b040aa0 454 else if (configtype == 3)
75ae2191 455 { green = 1; red = 1; blue = 1; }
9b040aa0
HS
456 else if (configtype == 4)
457 { green = 1; red=1; orange=1; blue = 1; }
da6e926b
CS
458 else if (configtype == "")
459 { green = 1; red = 1; }
5057b611
HS
460
461 do
462 {
463 count = 0;
e1457ba0 464 strcpy(message, _("Please choose the interface you wish to change.\n\n"));
5057b611
HS
465
466 if (green) {
467 strcpy(MenuInhalt[count], "GREEN");
468 pMenuInhalt[count] = MenuInhalt[count];
469 NicEntry[_GREEN_CARD_] = count;
e1457ba0 470 sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
5057b611
HS
471 strcat(message, temp);
472 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
e1457ba0 473 sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
5057b611
HS
474 strcat(message, temp);
475 }
476 count++;
477 }
478
479 if (red) {
480 strcpy(MenuInhalt[count], "RED");
481 pMenuInhalt[count] = MenuInhalt[count];
482 NicEntry[_RED_CARD_] = count;
e1457ba0 483 sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
5057b611
HS
484 strcat(message, temp);
485 if ( strlen(knics[_RED_CARD_].macaddr) ) {
e1457ba0 486 sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
5057b611
HS
487 strcat(message, temp);
488 }
489 count++;
490 }
491
492 if (orange) {
493 strcpy(MenuInhalt[count], "ORANGE");
494 pMenuInhalt[count] = MenuInhalt[count];
495 NicEntry[_ORANGE_CARD_] = count;
e1457ba0 496 sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
5057b611
HS
497 strcat(message, temp);
498 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
e1457ba0 499 sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
5057b611
HS
500 strcat(message, temp);
501 }
502 count++;
503 }
504
505 if (blue) {
506 strcpy(MenuInhalt[count], "BLUE");
507 pMenuInhalt[count] = MenuInhalt[count];
508 NicEntry[_BLUE_CARD_] = count;
e1457ba0 509 sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
5057b611
HS
510 strcat(message, temp);
511 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
e1457ba0 512 sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
5057b611
HS
513 strcat(message, temp);
514 }
515 count++;
516 }
517 pMenuInhalt[count] = NULL;
518
e1457ba0
MT
519 rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt,
520 &choise, _("Select"), _("Remove"), _("Done"), NULL);
5057b611
HS
521
522 if ( rc == 0 || rc == 1) {
9b040aa0
HS
523 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
524 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
525 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
526 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
eea0467a 527 netaddresschange = 1;
5057b611 528 } else if (rc == 2) {
9b040aa0
HS
529 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
530 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
531 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
532 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
eea0467a 533 netaddresschange = 1;
a358af8c 534 }
5057b611
HS
535 }
536 while ( rc <= 2);
069680ac
MT
537
538 freekeyvalues(kv);
069680ac
MT
539 return 1;
540}
541
75ae2191 542// Let user change GREEN address.
069680ac
MT
543int greenaddressmenu(void)
544{
545 struct keyvalue *kv = initkeyvalues();
546 char message[1000];
547 int rc;
548
549 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
550 {
551 freekeyvalues(kv);
e1457ba0 552 errorbox(_("Unable to open settings file"));
069680ac
MT
553 return 0;
554 }
555
e1457ba0
MT
556 sprintf(message, _("If you change this IP address, and you are logged in remotely, "
557 "your connection to the %s machine will be broken, and you will have to reconnect "
558 "on the new IP. This is a risky operation, and should only be attempted if you "
559 "have physical access to the machine, should something go wrong."), NAME);
560 rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
069680ac
MT
561
562 if (rc == 0 || rc == 1)
563 {
564 if (changeaddress(kv, "GREEN", 0, ""))
565 {
566 netaddresschange = 1;
567 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
568 writehostsfiles();
569 }
570 }
571
572 freekeyvalues(kv);
573
574 return 0;
575}
576
75ae2191 577// They can change BLUE, ORANGE and GREEN too :)
069680ac
MT
578int addressesmenu(void)
579{
580 struct keyvalue *kv = initkeyvalues();
581 struct keyvalue *mainkv = initkeyvalues();
582 int rc = 0;
583 char *sections[5];
584 char *green = "GREEN";
585 char *orange = "ORANGE";
586 char *blue = "BLUE";
587 char *red = "RED";
588 int c = 0;
589 char greenaddress[STRING_SIZE];
590 char oldgreenaddress[STRING_SIZE];
591 char temp[STRING_SIZE];
592 char temp2[STRING_SIZE];
593 char message[1000];
594 int configtype;
595 int done;
596 int choice;
597 char hostname[STRING_SIZE];
598
599 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
600 {
601 freekeyvalues(kv);
602 freekeyvalues(mainkv);
e1457ba0 603 errorbox(_("Unable to open settings file"));
069680ac
MT
604 return 0;
605 }
606 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
607 {
608 freekeyvalues(kv);
609 freekeyvalues(mainkv);
e1457ba0 610 errorbox(_("Unable to open settings file"));
069680ac
MT
611 return 0;
612 }
613
614 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
615 configtype = atol(temp);
616
617 sections[c] = green;
618 c++;
619 if (HAS_BLUE)
620 {
621 sections[c] = blue;
622 c++;
623 }
624 if (HAS_ORANGE)
625 {
626 sections[c] = orange;
627 c++;
628 }
629 if (HAS_RED)
630 {
631 sections[c] = red;
632 c++;
633 }
634 sections[c] = NULL;
635
636 choice = 0;
637 done = 0;
638 while (!done)
639 {
e1457ba0
MT
640 rc = newtWinMenu(_("Address settings"),
641 _("Select the interface you wish to reconfigure."), 50, 5,
642 5, 6, sections, &choice, _("OK"), _("Done"), NULL);
069680ac
MT
643
644 if (rc == 0 || rc == 1)
645 {
646 if (strcmp(sections[choice], "GREEN") == 0)
647 {
648 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
e1457ba0
MT
649 sprintf(message, _("If you change this IP address, and you are logged in remotely, "
650 "your connection to the %s machine will be broken, and you will have to reconnect "
651 "on the new IP. This is a risky operation, and should only be attempted if you "
652 "have physical access to the machine, should something go wrong."), NAME);
653 rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
069680ac
MT
654 if (rc == 0 || rc == 1)
655 {
656 if (changeaddress(kv, "GREEN", 0, ""))
657 {
658 netaddresschange = 1;
659 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
660 writehostsfiles();
661 findkey(kv, "GREEN_ADDRESS", greenaddress);
662 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
663 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
664 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
665 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
666 }
667 }
668 }
669 if (strcmp(sections[choice], "BLUE") == 0)
670 {
671 if (changeaddress(kv, "BLUE", 0, ""))
672 netaddresschange = 1;
673 }
674 if (strcmp(sections[choice], "ORANGE") == 0)
675 {
676 if (changeaddress(kv, "ORANGE", 0, ""))
677 netaddresschange = 1;
678 }
679 if (strcmp(sections[choice], "RED") == 0)
680 {
681 strcpy(hostname, "");
682 findkey(mainkv, "HOSTNAME", hostname);
683 if (changeaddress(kv, "RED", 1, hostname))
684 netaddresschange = 1;
685 }
686 }
687 else
688 done = 1;
689 }
690
691 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
692 freekeyvalues(kv);
693 freekeyvalues(mainkv);
694
695 return 0;
696}
697
698/* DNS and default gateway.... */
699int dnsgatewaymenu(void)
700{
701 struct keyvalue *kv = initkeyvalues();
702 char message[1000];
703 char temp[STRING_SIZE] = "0";
704 struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
705 char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
706 int error;
707 int configtype;
708 int rc;
709
710 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
711 {
712 freekeyvalues(kv);
e1457ba0 713 errorbox(_("Unable to open settings file"));
069680ac
MT
714 return 0;
715 }
716
e1457ba0 717 entries[DNS1].text = _("Primary DNS:");
069680ac
MT
718 strcpy(temp, ""); findkey(kv, "DNS1", temp);
719 values[DNS1] = strdup(temp);
720 entries[DNS1].value = &values[DNS1];
721 entries[DNS1].flags = 0;
722
e1457ba0 723 entries[DNS2].text = _("Secondary DNS:");
069680ac
MT
724 strcpy(temp, ""); findkey(kv, "DNS2", temp);
725 values[DNS2] = strdup(temp);
726 entries[DNS2].value = &values[DNS2];
727 entries[DNS2].flags = 0;
728
e1457ba0 729 entries[DEFAULT_GATEWAY].text = _("Default gateway:");
069680ac
MT
730 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
731 values[DEFAULT_GATEWAY] = strdup(temp);
732 entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
733 entries[DEFAULT_GATEWAY].flags = 0;
734
735 entries[DNSGATEWAY_TOTAL].text = NULL;
736 entries[DNSGATEWAY_TOTAL].value = NULL;
737 entries[DNSGATEWAY_TOTAL].flags = 0;
738
739 do
740 {
741 error = 0;
742
e1457ba0
MT
743 rc = newtWinEntries(_("DNS and Gateway settings"),
744 _("Enter the DNS and gateway information. "
745 "These settings are used only with Static IP (and DHCP if DNS set) on the RED interface."),
746 50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL);
069680ac
MT
747 if (rc == 0 || rc == 1)
748 {
e1457ba0
MT
749 strcpy(message, _("The following fields are invalid:"));
750 strcpy(message, "\n\n");
069680ac
MT
751 if (strlen(values[DNS1]))
752 {
753 if (inet_addr(values[DNS1]) == INADDR_NONE)
754 {
e1457ba0
MT
755 strcat(message, _("Primary DNS"));
756 strcat(message, "\n");
069680ac
MT
757 error = 1;
758 }
759 }
760 if (strlen(values[DNS2]))
761 {
762 if (inet_addr(values[DNS2]) == INADDR_NONE)
763 {
e1457ba0
MT
764 strcat(message, _("Secondary DNS"));
765 strcat(message, "\n");
069680ac
MT
766 error = 1;
767 }
768 }
769 if (strlen(values[DEFAULT_GATEWAY]))
770 {
771 if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
772 {
e1457ba0
MT
773 strcat(message, _("Default gateway"));
774 strcat(message, "\n");
069680ac
MT
775 error = 1;
776 }
777 }
778 if (!strlen(values[DNS1]) && strlen(values[DNS2]))
779 {
e1457ba0
MT
780 strcpy(message, _("Secondary DNS specified without a Primary DNS"));
781 strcat(message, "\n");
069680ac
MT
782 error = 1;
783 }
784
785 if (error)
786 errorbox(message);
787 else
788 {
789 replacekeyvalue(kv, "DNS1", values[DNS1]);
790 replacekeyvalue(kv, "DNS2", values[DNS2]);
791 replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
792 netaddresschange = 1;
793 free(values[DNS1]);
794 free(values[DNS2]);
795 free(values[DEFAULT_GATEWAY]);
796 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
797 }
798 }
799 }
800 while (error);
801
802 freekeyvalues(kv);
803
804 return 1;
805}