]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/setup/networking.c
setup: move gateway setting to red address setting.
[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
069680ac
MT
17extern FILE *flog;
18extern char *mylog;
19
069680ac
MT
20extern int automode;
21
5057b611 22#define HAS_GREEN 1
9b040aa0
HS
23#define HAS_RED (configtype == 1 || configtype == 2 || configtype == 3 || configtype == 4)
24#define HAS_ORANGE (configtype == 2 || configtype == 4)
25#define HAS_BLUE (configtype == 3 || configtype == 4)
26#define RED_IS_NOT_ETH (configtype == 0)
27
069680ac 28extern struct nic nics[];
5057b611 29extern struct knic knics[];
069680ac 30
a358af8c 31char *configtypenames[] = {
9b040aa0
HS
32 "GREEN + RED",
33 "GREEN + RED + ORANGE",
34 "GREEN + RED + BLUE",
35 "GREEN + RED + ORANGE + BLUE",
36 NULL };
37int configtypecards[] = {
9b040aa0
HS
38 2, // "GREEN + RED",
39 3, // "GREEN + RED + ORANGE",
40 3, // "GREEN + RED + BLUE",
6fc15159 41 4 // "GREEN + RED + ORANGE + BLUE",
9b040aa0
HS
42};
43
44
069680ac
MT
45int netaddresschange;
46
855446c6 47int oktoleave(void);
069680ac
MT
48int firstmenu(void);
49int configtypemenu(void);
50int drivermenu(void);
51int changedrivers(void);
52int greenaddressmenu(void);
53int addressesmenu(void);
069680ac
MT
54
55int handlenetworking(void)
56{
57 int done;
58 int choice;
9b040aa0 59 int found;
069680ac
MT
60
61 netaddresschange = 0;
62
9b040aa0 63 found = scan_network_cards();
9c1c1c57 64 found = init_knics();
9b040aa0 65
069680ac
MT
66 done = 0;
67 while (!done)
68 {
69 choice = firstmenu();
70
71 switch (choice)
72 {
73 case 1:
74 configtypemenu();
75 break;
76
77 case 2:
78 drivermenu();
79 break;
80
81 case 3:
82 addressesmenu();
83 break;
84
069680ac 85 case 0:
855446c6 86 if (oktoleave()) done = 1;
069680ac
MT
87 break;
88
89 default:
90 break;
91 }
92 }
93
94 if (automode == 0)
95 {
96 /* Restart networking! */
97 if (netaddresschange)
98 {
99 runcommandwithstatus("/etc/rc.d/init.d/network stop",
46b56e20 100 _("Networking"), _("Stopping network..."), NULL);
eea0467a
HS
101
102 rename_nics();
103
069680ac 104 runcommandwithstatus("/etc/rc.d/init.d/network start",
46b56e20 105 _("Networking"), _("Restarting network..."), NULL);
3a6752d9
AF
106 runcommandwithstatus("/etc/rc.d/init.d/unbound restart",
107 _("Networking"), _("Restarting unbound..."), NULL);
069680ac 108 }
a5d81233
AF
109 } else {
110 rename_nics();
069680ac 111 }
069680ac
MT
112 return 1;
113}
114
855446c6 115int oktoleave(void)
069680ac
MT
116{
117 struct keyvalue *kv = initkeyvalues();
118 char temp[STRING_SIZE];
119 int configtype;
855446c6 120 int rc;
069680ac
MT
121
122 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
123 {
124 freekeyvalues(kv);
e1457ba0 125 errorbox(_("Unable to open settings file"));
069680ac
MT
126 return 0;
127 }
128
0db33b56
MT
129 strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
130 if (configtype < 1 || configtype > 4) configtype = 1;
069680ac 131
f93a4b4f 132 if (HAS_GREEN)
069680ac 133 {
f93a4b4f 134 strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
069680ac
MT
135 if (!(strlen(temp)))
136 {
dc362263
AF
137 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
138 _("No GREEN interface assigned."));
139 if (rc == 0 || rc == 1)
140 {
141 freekeyvalues(kv);
142 return 0;
143 }
069680ac 144 }
f93a4b4f 145 if (!(interfacecheck(kv, "GREEN")))
069680ac 146 {
e1457ba0 147 errorbox(_("Missing an IP address on GREEN."));
855446c6
MT
148 freekeyvalues(kv);
149 return 0;
f93a4b4f
HS
150 }
151 }
152 if (HAS_RED)
153 {
855446c6 154
f93a4b4f
HS
155 strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
156 if (!(strlen(temp)))
157 {
e1457ba0
MT
158 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
159 _("No RED interface assigned."));
855446c6
MT
160 if (rc == 0 || rc == 1)
161 {
162 freekeyvalues(kv);
163 return 0;
164 }
f93a4b4f
HS
165 }
166 if (!(interfacecheck(kv, "RED")))
167 {
e1457ba0 168 errorbox(_("Missing an IP address on RED."));
855446c6
MT
169 freekeyvalues(kv);
170 return 0;
069680ac
MT
171 }
172 }
173 if (HAS_ORANGE)
174 {
175 strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
176 if (!(strlen(temp)))
177 {
dc362263
AF
178 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
179 _("No ORANGE interface assigned."));
180 if (rc == 0 || rc == 1)
181 {
182 freekeyvalues(kv);
183 return 0;
184 }
069680ac
MT
185 }
186 if (!(interfacecheck(kv, "ORANGE")))
187 {
e1457ba0 188 errorbox(_("Missing an IP address on ORANGE."));
855446c6
MT
189 freekeyvalues(kv);
190 return 0;
069680ac
MT
191 }
192 }
f93a4b4f 193 if (HAS_BLUE)
069680ac 194 {
f93a4b4f 195 strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
069680ac
MT
196 if (!(strlen(temp)))
197 {
dc362263
AF
198 rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
199 _("No BLUE interface assigned."));
200 if (rc == 0 || rc == 1)
201 {
202 freekeyvalues(kv);
203 return 0;
204 }
069680ac 205 }
f93a4b4f 206 if (!(interfacecheck(kv, "BLUE")))
069680ac 207 {
e1457ba0 208 errorbox(_("Missing an IP address on BLUE."));
855446c6
MT
209 freekeyvalues(kv);
210 return 0;
f93a4b4f
HS
211 }
212 }
855446c6 213 return 1;
069680ac
MT
214}
215
216
217/* Shows the main menu and a summary of the current settings. */
218int firstmenu(void)
219{
e1457ba0
MT
220 char *sections[] = {
221 _("Network configuration type"),
222 _("Drivers and card assignments"),
223 _("Address settings"),
e1457ba0
MT
224 NULL
225 };
069680ac
MT
226 int rc;
227 static int choice = 0;
228 struct keyvalue *kv = initkeyvalues();
229 char message[1000];
0db33b56 230 char temp[STRING_SIZE] = "1";
069680ac
MT
231 int x;
232 int result;
233 char networkrestart[STRING_SIZE] = "";
234
235 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
236 {
237 freekeyvalues(kv);
e1457ba0 238 errorbox(_("Unable to open settings file"));
069680ac
MT
239 return 0;
240 }
241
242 if (netaddresschange)
e1457ba0 243 strcpy(networkrestart, _("When configuration is complete, a network restart will be required."));
069680ac 244
d0f2cc42
MT
245 strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp);
246 x = atol(temp);
247 x--;
0db33b56 248 if (x < 0 || x > 4) x = 0;
069680ac 249 /* Format heading bit. */
782ae35d 250 snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart);
e1457ba0
MT
251 rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6,
252 sections, &choice, _("OK"), _("Done"), NULL);
069680ac
MT
253
254 if (rc == 0 || rc == 1)
255 result = choice + 1;
256 else
257 result = 0;
258
259 return result;
260}
261
262/* Here they choose general network config, number of nics etc. */
263int configtypemenu(void)
264{
265 struct keyvalue *kv = initkeyvalues();
0db33b56 266 char temp[STRING_SIZE] = "1";
069680ac 267 char message[1000];
9b040aa0 268 int choise, found;
0db33b56 269 int rc, configtype;
9b040aa0 270
069680ac
MT
271 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
272 {
273 freekeyvalues(kv);
e1457ba0 274 errorbox(_("Unable to open settings file"));
069680ac
MT
275 return 0;
276 }
9b040aa0
HS
277
278 found = scan_network_cards();
069680ac 279
9b040aa0 280 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
6fc15159 281 choise--;
9b040aa0 282
e1457ba0
MT
283 sprintf(message, _("Select the network configuration for %s. "
284 "The following configuration types list those interfaces which have ethernet attached. "
285 "If you change this setting, a network restart will be required, and you will have to "
286 "reconfigure the network driver assignments."), NAME);
287 rc = newtWinMenu(_("Network configuration type"), message, 50, 5, 5,
288 6, configtypenames, &choise, _("OK"), _("Cancel"), NULL);
9b040aa0 289 if ( configtypecards[choise] > found ) {
e1457ba0
MT
290 sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"),
291 configtypecards[choise], found);
9b040aa0
HS
292 errorbox(message);
293 }
069680ac
MT
294
295 if (rc == 0 || rc == 1)
296 {
a358af8c 297 choise++;
9b040aa0 298 sprintf(temp, "%d", choise);
069680ac 299 replacekeyvalue(kv, "CONFIG_TYPE", temp);
0db33b56
MT
300 configtype = atol(temp);
301 if (!HAS_RED)
302 clear_card_entry(_RED_CARD_);
303 if (!HAS_ORANGE)
304 clear_card_entry(_ORANGE_CARD_);
305 if (!HAS_BLUE)
306 clear_card_entry(_BLUE_CARD_);
9b040aa0 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
316/* Driver menu. Choose drivers.. */
317int drivermenu(void)
318{
319 struct keyvalue *kv = initkeyvalues();
5057b611 320 char message[STRING_SIZE];
0db33b56 321 char temp[STRING_SIZE] = "1";
9c1c1c57 322
069680ac 323 int configtype;
0db33b56 324 int i, rc, kcount = 0, neednics;
069680ac
MT
325
326 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
327 {
328 freekeyvalues(kv);
e1457ba0 329 errorbox(_("Unable to open settings file"));
069680ac
MT
330 return 0;
331 }
332
4061c03f
HS
333 if (findkey(kv, "CONFIG_TYPE", temp))
334 configtype = atol(temp);
335 else {
336 fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
337 configtype = atol(temp);
338 replacekeyvalue(kv, "CONFIG_TYPE", temp);
339 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
340 }
341
e1457ba0
MT
342 strcpy(message, _("Configure network drivers, and which interface each card is assigned to. "
343 "The current configuration is as follows:\n\n"));
5057b611 344
0db33b56
MT
345 kcount = 0;
346 neednics = 0;
5057b611 347 if (HAS_GREEN) {
e1457ba0 348 sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
5057b611
HS
349 strcat(message, temp);
350 if (strlen(knics[_GREEN_CARD_].macaddr) ) {
e1457ba0 351 sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
5057b611
HS
352 strcat(message, temp);
353 }
354 neednics++;
75ae2191 355 }
5057b611 356 if (HAS_RED) {
e1457ba0 357 sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
5057b611
HS
358 strcat(message, temp);
359 if (strlen(knics[_RED_CARD_].macaddr) ) {
e1457ba0 360 sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
5057b611 361 strcat(message, temp);
75ae2191 362 }
5057b611 363 neednics++;
069680ac 364 }
75ae2191 365 if (HAS_ORANGE) {
e1457ba0 366 sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
5057b611
HS
367 strcat(message, temp);
368 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
e1457ba0 369 sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
5057b611
HS
370 strcat(message, temp);
371 }
372 neednics++;
75ae2191 373 }
5057b611 374 if (HAS_BLUE) {
e1457ba0 375 sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
5057b611
HS
376 strcat(message, temp);
377 if (strlen(knics[_BLUE_CARD_].macaddr)) {
e1457ba0 378 sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
5057b611 379 strcat(message, temp);
75ae2191 380 }
5057b611 381 neednics++;
069680ac 382 }
5057b611 383
0db33b56
MT
384 for ( i=0 ; i<4; i++)
385 if (strcmp(knics[i].macaddr, ""))
386 kcount++;
5057b611 387
f93a4b4f
HS
388 if (neednics = kcount)
389 {
e1457ba0
MT
390 strcat(message, "\n");
391 strcat(message, _("Do you wish to change these settings?"));
392 rc = newtWinChoice(_("Drivers and card assignments"), _("OK"),
393 _("Cancel"), message);
5057b611
HS
394 if (rc == 0 || rc == 1)
395 {
5057b611
HS
396 changedrivers();
397 }
398 } else {
069680ac
MT
399 changedrivers();
400 }
069680ac
MT
401 freekeyvalues(kv);
402
403 return 1;
404}
405
9b040aa0
HS
406int set_menu_entry_for(int *nr, int *card)
407{
408
409}
410
069680ac
MT
411int changedrivers(void)
412{
413 struct keyvalue *kv = initkeyvalues();
5057b611 414 char temp[STRING_SIZE], message[STRING_SIZE];
069680ac 415 int configtype;
75ae2191 416 int green = 0, red = 0, blue = 0, orange = 0;
5057b611
HS
417 char MenuInhalt[10][180];
418 char *pMenuInhalt[10];
419 int count = 0, choise = 0, rc;
420 int NicEntry[10];
59de0b00 421
069680ac
MT
422 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
423 {
424 freekeyvalues(kv);
e1457ba0 425 errorbox(_("Unable to open settings file"));
069680ac
MT
426 return 0;
427 }
0db33b56
MT
428 if (automode == 0)
429 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
46b56e20 430 _("Networking"), _("Restarting non-local network..."), NULL);
59de0b00 431
5057b611 432 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
a358af8c 433 if (configtype == 1)
75ae2191 434 { green = 1; red = 1; }
9b040aa0 435 else if (configtype == 2)
75ae2191 436 { green = 1; red = 1; orange = 1; }
9b040aa0 437 else if (configtype == 3)
75ae2191 438 { green = 1; red = 1; blue = 1; }
9b040aa0
HS
439 else if (configtype == 4)
440 { green = 1; red=1; orange=1; blue = 1; }
da6e926b
CS
441 else if (configtype == "")
442 { green = 1; red = 1; }
5057b611
HS
443
444 do
445 {
446 count = 0;
e1457ba0 447 strcpy(message, _("Please choose the interface you wish to change.\n\n"));
5057b611
HS
448
449 if (green) {
450 strcpy(MenuInhalt[count], "GREEN");
451 pMenuInhalt[count] = MenuInhalt[count];
452 NicEntry[_GREEN_CARD_] = count;
e1457ba0 453 sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
5057b611
HS
454 strcat(message, temp);
455 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
e1457ba0 456 sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
5057b611
HS
457 strcat(message, temp);
458 }
459 count++;
460 }
461
462 if (red) {
463 strcpy(MenuInhalt[count], "RED");
464 pMenuInhalt[count] = MenuInhalt[count];
465 NicEntry[_RED_CARD_] = count;
e1457ba0 466 sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
5057b611
HS
467 strcat(message, temp);
468 if ( strlen(knics[_RED_CARD_].macaddr) ) {
e1457ba0 469 sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
5057b611
HS
470 strcat(message, temp);
471 }
472 count++;
473 }
474
475 if (orange) {
476 strcpy(MenuInhalt[count], "ORANGE");
477 pMenuInhalt[count] = MenuInhalt[count];
478 NicEntry[_ORANGE_CARD_] = count;
e1457ba0 479 sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
5057b611
HS
480 strcat(message, temp);
481 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
e1457ba0 482 sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
5057b611
HS
483 strcat(message, temp);
484 }
485 count++;
486 }
487
488 if (blue) {
489 strcpy(MenuInhalt[count], "BLUE");
490 pMenuInhalt[count] = MenuInhalt[count];
491 NicEntry[_BLUE_CARD_] = count;
e1457ba0 492 sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
5057b611
HS
493 strcat(message, temp);
494 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
e1457ba0 495 sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
5057b611
HS
496 strcat(message, temp);
497 }
498 count++;
499 }
500 pMenuInhalt[count] = NULL;
501
e1457ba0
MT
502 rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt,
503 &choise, _("Select"), _("Remove"), _("Done"), NULL);
5057b611
HS
504
505 if ( rc == 0 || rc == 1) {
9b040aa0
HS
506 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
507 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
508 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
509 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
eea0467a 510 netaddresschange = 1;
5057b611 511 } else if (rc == 2) {
9b040aa0
HS
512 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
513 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
514 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
515 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
eea0467a 516 netaddresschange = 1;
a358af8c 517 }
5057b611
HS
518 }
519 while ( rc <= 2);
069680ac
MT
520
521 freekeyvalues(kv);
069680ac
MT
522 return 1;
523}
524
75ae2191 525// Let user change GREEN address.
069680ac
MT
526int greenaddressmenu(void)
527{
528 struct keyvalue *kv = initkeyvalues();
529 char message[1000];
530 int rc;
531
532 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
533 {
534 freekeyvalues(kv);
e1457ba0 535 errorbox(_("Unable to open settings file"));
069680ac
MT
536 return 0;
537 }
538
e1457ba0
MT
539 sprintf(message, _("If you change this IP address, and you are logged in remotely, "
540 "your connection to the %s machine will be broken, and you will have to reconnect "
541 "on the new IP. This is a risky operation, and should only be attempted if you "
542 "have physical access to the machine, should something go wrong."), NAME);
543 rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
069680ac
MT
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
75ae2191 560// They can change BLUE, ORANGE and GREEN too :)
069680ac
MT
561int 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);
e1457ba0 586 errorbox(_("Unable to open settings file"));
069680ac
MT
587 return 0;
588 }
589 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
590 {
591 freekeyvalues(kv);
592 freekeyvalues(mainkv);
e1457ba0 593 errorbox(_("Unable to open settings file"));
069680ac
MT
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 {
e1457ba0
MT
623 rc = newtWinMenu(_("Address settings"),
624 _("Select the interface you wish to reconfigure."), 50, 5,
625 5, 6, sections, &choice, _("OK"), _("Done"), NULL);
069680ac
MT
626
627 if (rc == 0 || rc == 1)
628 {
629 if (strcmp(sections[choice], "GREEN") == 0)
630 {
631 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
e1457ba0
MT
632 sprintf(message, _("If you change this IP address, and you are logged in remotely, "
633 "your connection to the %s machine will be broken, and you will have to reconnect "
634 "on the new IP. This is a risky operation, and should only be attempted if you "
635 "have physical access to the machine, should something go wrong."), NAME);
636 rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
069680ac
MT
637 if (rc == 0 || rc == 1)
638 {
639 if (changeaddress(kv, "GREEN", 0, ""))
640 {
641 netaddresschange = 1;
642 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
643 writehostsfiles();
644 findkey(kv, "GREEN_ADDRESS", greenaddress);
645 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
646 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
647 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
648 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
649 }
650 }
651 }
652 if (strcmp(sections[choice], "BLUE") == 0)
653 {
654 if (changeaddress(kv, "BLUE", 0, ""))
655 netaddresschange = 1;
656 }
657 if (strcmp(sections[choice], "ORANGE") == 0)
658 {
659 if (changeaddress(kv, "ORANGE", 0, ""))
660 netaddresschange = 1;
661 }
662 if (strcmp(sections[choice], "RED") == 0)
663 {
664 strcpy(hostname, "");
665 findkey(mainkv, "HOSTNAME", hostname);
666 if (changeaddress(kv, "RED", 1, hostname))
667 netaddresschange = 1;
668 }
669 }
670 else
671 done = 1;
672 }
673
674 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
675 freekeyvalues(kv);
676 freekeyvalues(mainkv);
677
678 return 0;
679}