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