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