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