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