]>
Commit | Line | Data |
---|---|---|
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 | ||
20 | extern FILE *flog; | |
21 | extern char *mylog; | |
22 | ||
23 | extern char **ctr; | |
24 | ||
25 | extern 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 | |
38 | extern struct nic nics[]; | |
5057b611 | 39 | extern 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 | */ |
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 | ||
069680ac MT |
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; | |
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 | } | |
139 | ||
140 | return 1; | |
141 | } | |
142 | ||
143 | int 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); | |
157 | if (configtype < 0 || configtype > 7) configtype = 0; | |
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, ""); | |
202 | EXIT: | |
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. */ | |
213 | int 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); | |
239 | if (x < 0 || x > 7) x = 0; | |
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. */ | |
255 | int 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.. */ | |
308 | int 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); | |
351 | kcount++; | |
352 | } else { | |
353 | strcpy(knics[_GREEN_CARD_].description, ctr[TR_UNSET]); | |
354 | } | |
355 | sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); | |
356 | strcat(message, temp); | |
357 | if (strlen(knics[_GREEN_CARD_].macaddr) ) { | |
358 | sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); | |
359 | strcat(message, temp); | |
360 | } | |
361 | neednics++; | |
75ae2191 | 362 | } |
5057b611 HS |
363 | if (HAS_RED) { |
364 | strcpy(temp, ""); findkey(kv, "RED_MACADDR", temp); | |
365 | if (strlen(temp)) { | |
366 | strcpy(knics[_RED_CARD_].macaddr, temp); | |
367 | strcpy(knics[_RED_CARD_].colour, "RED"); | |
368 | findkey(kv, "RED_DESCRIPTION", temp); | |
369 | strcpy(knics[_RED_CARD_].description, temp); | |
370 | kcount++; | |
371 | } else { | |
372 | strcpy(knics[_RED_CARD_].description, ctr[TR_UNSET]); | |
373 | } | |
374 | sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); | |
375 | strcat(message, temp); | |
376 | if (strlen(knics[_RED_CARD_].macaddr) ) { | |
377 | sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); | |
378 | strcat(message, temp); | |
75ae2191 | 379 | } |
5057b611 | 380 | neednics++; |
069680ac | 381 | } |
75ae2191 | 382 | if (HAS_ORANGE) { |
5057b611 HS |
383 | strcpy(temp, ""); findkey(kv, "ORANGE_MACADDR", temp); |
384 | if (strlen(temp)) { | |
385 | strcpy(knics[_ORANGE_CARD_].macaddr, temp); | |
386 | strcpy(knics[_ORANGE_CARD_].colour, "ORANGE"); | |
387 | findkey(kv, "ORANGE_DESCRIPTION", temp ); | |
388 | strcpy(knics[_ORANGE_CARD_].description, temp ); | |
389 | kcount++; | |
390 | } else { | |
391 | strcpy(knics[_ORANGE_CARD_].description, ctr[TR_UNSET]); | |
75ae2191 | 392 | } |
5057b611 HS |
393 | sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); |
394 | strcat(message, temp); | |
395 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
396 | sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); | |
397 | strcat(message, temp); | |
398 | } | |
399 | neednics++; | |
75ae2191 | 400 | } |
5057b611 HS |
401 | if (HAS_BLUE) { |
402 | strcpy(temp, ""); findkey(kv, "BLUE_MACADDR", temp); | |
403 | if (strlen(temp)) { | |
404 | strcpy(knics[_BLUE_CARD_].macaddr, temp); | |
405 | strcpy(knics[_BLUE_CARD_].colour, "BLUE"); | |
406 | findkey(kv, "BLUE_DESCRIPTION", temp ); | |
407 | strcpy(knics[_BLUE_CARD_].description, temp); | |
408 | kcount++; | |
409 | } else { | |
410 | strcpy(knics[_BLUE_CARD_].description, ctr[TR_UNSET]); | |
411 | } | |
412 | sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); | |
413 | strcat(message, temp); | |
414 | if (strlen(knics[_BLUE_CARD_].macaddr)) { | |
415 | sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); | |
416 | strcat(message, temp); | |
75ae2191 | 417 | } |
5057b611 | 418 | neednics++; |
069680ac | 419 | } |
5057b611 HS |
420 | |
421 | fprintf(flog,"found %d knowing Card\'s\n", kcount); // #### DEBUG #### | |
422 | ||
423 | if (neednics = kcount) { | |
424 | strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); | |
425 | rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], | |
069680ac | 426 | ctr[TR_CANCEL], message); |
5057b611 HS |
427 | if (rc == 0 || rc == 1) |
428 | { | |
429 | /* Shit, got to do something.. */ | |
430 | changedrivers(); | |
431 | } | |
432 | } else { | |
433 | strcat(message, "\nEs wurden noch nicht alle Netzwerkkarten konfiguriert.\n"); | |
434 | newtWinMessage(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], message); | |
069680ac MT |
435 | /* Shit, got to do something.. */ |
436 | changedrivers(); | |
437 | } | |
069680ac MT |
438 | freekeyvalues(kv); |
439 | ||
440 | return 1; | |
441 | } | |
442 | ||
75ae2191 MT |
443 | int cardassigned(char *colour) |
444 | { | |
445 | char command[STRING_SIZE]; | |
5057b611 | 446 | fprintf(flog,"cardassigned - %s\n", colour); |
75ae2191 MT |
447 | sprintf(command, "grep -q %s < /etc/udev/rules.d/30-persistent-network.rules 2>/dev/null", colour); |
448 | if (system(command)) | |
449 | return 0; | |
450 | else | |
451 | return 1; | |
452 | } | |
453 | ||
9b040aa0 HS |
454 | int set_menu_entry_for(int *nr, int *card) |
455 | { | |
456 | ||
457 | } | |
458 | ||
069680ac MT |
459 | int changedrivers(void) |
460 | { | |
461 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 | 462 | char temp[STRING_SIZE], message[STRING_SIZE]; |
069680ac | 463 | int configtype; |
75ae2191 | 464 | int green = 0, red = 0, blue = 0, orange = 0; |
5057b611 HS |
465 | char MenuInhalt[10][180]; |
466 | char *pMenuInhalt[10]; | |
467 | int count = 0, choise = 0, rc; | |
468 | int NicEntry[10]; | |
59de0b00 | 469 | |
069680ac MT |
470 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
471 | { | |
472 | freekeyvalues(kv); | |
473 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
474 | return 0; | |
475 | } | |
5057b611 | 476 | fprintf(flog,"stop network on red, blue and orange\n"); // #### Debug #### |
75ae2191 MT |
477 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", |
478 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
59de0b00 | 479 | |
5057b611 | 480 | findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); |
069680ac | 481 | if (configtype == 0) |
75ae2191 MT |
482 | { green = 1; } |
483 | else if (configtype == 1) | |
75ae2191 | 484 | { green = 1; red = 1; } |
9b040aa0 | 485 | else if (configtype == 2) |
75ae2191 | 486 | { green = 1; red = 1; orange = 1; } |
9b040aa0 | 487 | else if (configtype == 3) |
75ae2191 | 488 | { green = 1; red = 1; blue = 1; } |
9b040aa0 HS |
489 | else if (configtype == 4) |
490 | { green = 1; red=1; orange=1; blue = 1; } | |
491 | // else if (configtype == 5) | |
492 | // { green = 1; blue = 1; orange = 1; } | |
493 | // else if (configtype == 6) | |
494 | // { green = 1; red = 1; blue = 1; } | |
495 | // else if (configtype == 7) | |
496 | // { green = 1; red = 1; blue = 1; orange = 1; } | |
5057b611 HS |
497 | |
498 | fprintf(flog,"found: g=%d r=%d o=%d b=%d\n",green, red, orange, blue); // #### Debug #### | |
499 | ||
500 | do | |
501 | { | |
502 | count = 0; | |
503 | strcpy(message, "(TR) Bitte wählen Sie das Interface aus das geaendert werden soll.\n\n"); | |
504 | ||
505 | if (green) { | |
506 | strcpy(MenuInhalt[count], "GREEN"); | |
507 | pMenuInhalt[count] = MenuInhalt[count]; | |
508 | NicEntry[_GREEN_CARD_] = count; | |
5057b611 HS |
509 | sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); |
510 | strcat(message, temp); | |
511 | if ( strlen(knics[_GREEN_CARD_].macaddr) ) { | |
512 | sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); | |
513 | strcat(message, temp); | |
514 | } | |
515 | count++; | |
516 | } | |
517 | ||
518 | if (red) { | |
519 | strcpy(MenuInhalt[count], "RED"); | |
520 | pMenuInhalt[count] = MenuInhalt[count]; | |
521 | NicEntry[_RED_CARD_] = count; | |
522 | // fprintf(flog,"found: %s as entry %d\n", MenuInhalt[count], NicEntry[count]); // #### Debug #### | |
523 | sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); | |
524 | strcat(message, temp); | |
525 | if ( strlen(knics[_RED_CARD_].macaddr) ) { | |
526 | sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); | |
527 | strcat(message, temp); | |
528 | } | |
529 | count++; | |
530 | } | |
531 | ||
532 | if (orange) { | |
533 | strcpy(MenuInhalt[count], "ORANGE"); | |
534 | pMenuInhalt[count] = MenuInhalt[count]; | |
535 | NicEntry[_ORANGE_CARD_] = count; | |
536 | // fprintf(flog,"found: %s as entry %d\n", MenuInhalt[count], NicEntry[count]); // #### Debug #### | |
537 | sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); | |
538 | strcat(message, temp); | |
539 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
540 | sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); | |
541 | strcat(message, temp); | |
542 | } | |
543 | count++; | |
544 | } | |
545 | ||
546 | if (blue) { | |
547 | strcpy(MenuInhalt[count], "BLUE"); | |
548 | pMenuInhalt[count] = MenuInhalt[count]; | |
549 | NicEntry[_BLUE_CARD_] = count; | |
550 | // fprintf(flog,"found: %s as entry %d\n", MenuInhalt[count], NicEntry[count]); // #### Debug #### | |
551 | sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); | |
552 | strcat(message, temp); | |
553 | if ( strlen(knics[_BLUE_CARD_].macaddr) ) { | |
554 | sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); | |
555 | strcat(message, temp); | |
556 | } | |
557 | count++; | |
558 | } | |
559 | pMenuInhalt[count] = NULL; | |
560 | ||
561 | rc = newtWinMenu("(TR) Netcard Farbe", message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], "(TR) Entfernen" , ctr[TR_DONE], NULL); | |
562 | ||
563 | if ( rc == 0 || rc == 1) { | |
564 | // write_configs_netudev(pnics[choise].description, pnics[choise].macaddr, colour); | |
565 | // insert nic to colourcard | |
9b040aa0 HS |
566 | if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_); |
567 | if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_); | |
568 | if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_); | |
569 | if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_); | |
5057b611 | 570 | } else if (rc == 2) { |
9b040aa0 HS |
571 | if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_); |
572 | if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_); | |
573 | if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_); | |
574 | if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_); | |
5057b611 HS |
575 | } |
576 | // else { | |
577 | // errorbox("Sie haben keine Netzwerkkarte ausgewaehlt.\n"); | |
578 | // return 1; | |
579 | // } | |
580 | } | |
581 | while ( rc <= 2); | |
069680ac | 582 | |
75ae2191 | 583 | // writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); |
069680ac MT |
584 | |
585 | freekeyvalues(kv); | |
069680ac MT |
586 | return 1; |
587 | } | |
588 | ||
75ae2191 | 589 | // Let user change GREEN address. |
069680ac MT |
590 | int greenaddressmenu(void) |
591 | { | |
592 | struct keyvalue *kv = initkeyvalues(); | |
593 | char message[1000]; | |
594 | int rc; | |
595 | ||
596 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
597 | { | |
598 | freekeyvalues(kv); | |
599 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
600 | return 0; | |
601 | } | |
602 | ||
603 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
604 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); | |
605 | ||
606 | if (rc == 0 || rc == 1) | |
607 | { | |
608 | if (changeaddress(kv, "GREEN", 0, "")) | |
609 | { | |
610 | netaddresschange = 1; | |
611 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
612 | writehostsfiles(); | |
613 | } | |
614 | } | |
615 | ||
616 | freekeyvalues(kv); | |
617 | ||
618 | return 0; | |
619 | } | |
620 | ||
75ae2191 | 621 | // They can change BLUE, ORANGE and GREEN too :) |
069680ac MT |
622 | int addressesmenu(void) |
623 | { | |
624 | struct keyvalue *kv = initkeyvalues(); | |
625 | struct keyvalue *mainkv = initkeyvalues(); | |
626 | int rc = 0; | |
627 | char *sections[5]; | |
628 | char *green = "GREEN"; | |
629 | char *orange = "ORANGE"; | |
630 | char *blue = "BLUE"; | |
631 | char *red = "RED"; | |
632 | int c = 0; | |
633 | char greenaddress[STRING_SIZE]; | |
634 | char oldgreenaddress[STRING_SIZE]; | |
635 | char temp[STRING_SIZE]; | |
636 | char temp2[STRING_SIZE]; | |
637 | char message[1000]; | |
638 | int configtype; | |
639 | int done; | |
640 | int choice; | |
641 | char hostname[STRING_SIZE]; | |
642 | ||
643 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
644 | { | |
645 | freekeyvalues(kv); | |
646 | freekeyvalues(mainkv); | |
647 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
648 | return 0; | |
649 | } | |
650 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
651 | { | |
652 | freekeyvalues(kv); | |
653 | freekeyvalues(mainkv); | |
654 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
655 | return 0; | |
656 | } | |
657 | ||
658 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
659 | configtype = atol(temp); | |
660 | ||
661 | sections[c] = green; | |
662 | c++; | |
663 | if (HAS_BLUE) | |
664 | { | |
665 | sections[c] = blue; | |
666 | c++; | |
667 | } | |
668 | if (HAS_ORANGE) | |
669 | { | |
670 | sections[c] = orange; | |
671 | c++; | |
672 | } | |
673 | if (HAS_RED) | |
674 | { | |
675 | sections[c] = red; | |
676 | c++; | |
677 | } | |
678 | sections[c] = NULL; | |
679 | ||
680 | choice = 0; | |
681 | done = 0; | |
682 | while (!done) | |
683 | { | |
684 | rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], | |
685 | ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, | |
686 | 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
687 | ||
688 | if (rc == 0 || rc == 1) | |
689 | { | |
690 | if (strcmp(sections[choice], "GREEN") == 0) | |
691 | { | |
692 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
693 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
694 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], | |
695 | message); | |
696 | if (rc == 0 || rc == 1) | |
697 | { | |
698 | if (changeaddress(kv, "GREEN", 0, "")) | |
699 | { | |
700 | netaddresschange = 1; | |
701 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
702 | writehostsfiles(); | |
703 | findkey(kv, "GREEN_ADDRESS", greenaddress); | |
704 | snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); | |
705 | snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); | |
706 | replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); | |
707 | chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); | |
708 | } | |
709 | } | |
710 | } | |
711 | if (strcmp(sections[choice], "BLUE") == 0) | |
712 | { | |
713 | if (changeaddress(kv, "BLUE", 0, "")) | |
714 | netaddresschange = 1; | |
715 | } | |
716 | if (strcmp(sections[choice], "ORANGE") == 0) | |
717 | { | |
718 | if (changeaddress(kv, "ORANGE", 0, "")) | |
719 | netaddresschange = 1; | |
720 | } | |
721 | if (strcmp(sections[choice], "RED") == 0) | |
722 | { | |
723 | strcpy(hostname, ""); | |
724 | findkey(mainkv, "HOSTNAME", hostname); | |
725 | if (changeaddress(kv, "RED", 1, hostname)) | |
726 | netaddresschange = 1; | |
727 | } | |
728 | } | |
729 | else | |
730 | done = 1; | |
731 | } | |
732 | ||
733 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
734 | freekeyvalues(kv); | |
735 | freekeyvalues(mainkv); | |
736 | ||
737 | return 0; | |
738 | } | |
739 | ||
740 | /* DNS and default gateway.... */ | |
741 | int dnsgatewaymenu(void) | |
742 | { | |
743 | struct keyvalue *kv = initkeyvalues(); | |
744 | char message[1000]; | |
745 | char temp[STRING_SIZE] = "0"; | |
746 | struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; | |
747 | char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ | |
748 | int error; | |
749 | int configtype; | |
750 | int rc; | |
751 | ||
752 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
753 | { | |
754 | freekeyvalues(kv); | |
755 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
756 | return 0; | |
757 | } | |
758 | ||
759 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
760 | configtype = atol(temp); | |
761 | ||
762 | if (RED_IS_NOT_ETH) | |
763 | { | |
764 | freekeyvalues(kv); | |
765 | errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); | |
766 | return 0; | |
767 | } | |
768 | ||
769 | entries[DNS1].text = ctr[TR_PRIMARY_DNS]; | |
770 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
771 | values[DNS1] = strdup(temp); | |
772 | entries[DNS1].value = &values[DNS1]; | |
773 | entries[DNS1].flags = 0; | |
774 | ||
775 | entries[DNS2].text = ctr[TR_SECONDARY_DNS]; | |
776 | strcpy(temp, ""); findkey(kv, "DNS2", temp); | |
777 | values[DNS2] = strdup(temp); | |
778 | entries[DNS2].value = &values[DNS2]; | |
779 | entries[DNS2].flags = 0; | |
780 | ||
781 | entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; | |
782 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
783 | values[DEFAULT_GATEWAY] = strdup(temp); | |
784 | entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; | |
785 | entries[DEFAULT_GATEWAY].flags = 0; | |
786 | ||
787 | entries[DNSGATEWAY_TOTAL].text = NULL; | |
788 | entries[DNSGATEWAY_TOTAL].value = NULL; | |
789 | entries[DNSGATEWAY_TOTAL].flags = 0; | |
790 | ||
791 | do | |
792 | { | |
793 | error = 0; | |
794 | ||
795 | rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], | |
796 | ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, | |
797 | ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
798 | if (rc == 0 || rc == 1) | |
799 | { | |
800 | strcpy(message, ctr[TR_INVALID_FIELDS]); | |
801 | if (strlen(values[DNS1])) | |
802 | { | |
803 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
804 | { | |
805 | strcat(message, ctr[TR_PRIMARY_DNS_CR]); | |
806 | error = 1; | |
807 | } | |
808 | } | |
809 | if (strlen(values[DNS2])) | |
810 | { | |
811 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
812 | { | |
813 | strcat(message, ctr[TR_SECONDARY_DNS_CR]); | |
814 | error = 1; | |
815 | } | |
816 | } | |
817 | if (strlen(values[DEFAULT_GATEWAY])) | |
818 | { | |
819 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
820 | { | |
821 | strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); | |
822 | error = 1; | |
823 | } | |
824 | } | |
825 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
826 | { | |
827 | strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); | |
828 | error = 1; | |
829 | } | |
830 | ||
831 | if (error) | |
832 | errorbox(message); | |
833 | else | |
834 | { | |
835 | replacekeyvalue(kv, "DNS1", values[DNS1]); | |
836 | replacekeyvalue(kv, "DNS2", values[DNS2]); | |
837 | replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); | |
838 | netaddresschange = 1; | |
839 | free(values[DNS1]); | |
840 | free(values[DNS2]); | |
841 | free(values[DEFAULT_GATEWAY]); | |
842 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
843 | } | |
844 | } | |
845 | } | |
846 | while (error); | |
847 | ||
848 | freekeyvalues(kv); | |
849 | ||
850 | return 1; | |
851 | } |