]>
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 | ||
27 | #define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7) | |
28 | #define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7) | |
29 | #define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7) | |
30 | #define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5) | |
31 | ||
32 | extern struct nic nics[]; | |
33 | ||
34 | char *configtypenames[] = { | |
35 | "GREEN (RED is modem/ISDN)", | |
36 | "GREEN + ORANGE (RED is modem/ISDN)", | |
37 | "GREEN + RED", | |
38 | "GREEN + ORANGE + RED", | |
39 | "GREEN + BLUE (RED is modem/ISDN) ", | |
40 | "GREEN + ORANGE + BLUE (RED is modem/ISDN)", | |
41 | "GREEN + BLUE + RED", | |
42 | "GREEN + ORANGE + BLUE + RED", | |
43 | NULL }; | |
44 | int netaddresschange; | |
45 | ||
46 | int oktoleave(char *errormessage); | |
47 | int firstmenu(void); | |
48 | int configtypemenu(void); | |
49 | int drivermenu(void); | |
50 | int changedrivers(void); | |
51 | int greenaddressmenu(void); | |
52 | int addressesmenu(void); | |
53 | int dnsgatewaymenu(void); | |
54 | ||
55 | int handlenetworking(void) | |
56 | { | |
57 | int done; | |
58 | int choice; | |
59 | char errormessage[STRING_SIZE]; | |
60 | ||
61 | netaddresschange = 0; | |
62 | ||
63 | done = 0; | |
64 | while (!done) | |
65 | { | |
66 | choice = firstmenu(); | |
67 | ||
68 | switch (choice) | |
69 | { | |
70 | case 1: | |
71 | configtypemenu(); | |
72 | break; | |
73 | ||
74 | case 2: | |
75 | drivermenu(); | |
76 | break; | |
77 | ||
78 | case 3: | |
79 | addressesmenu(); | |
80 | break; | |
81 | ||
82 | case 4: | |
83 | dnsgatewaymenu(); | |
84 | break; | |
85 | ||
86 | case 0: | |
87 | if (oktoleave(errormessage)) | |
88 | done = 1; | |
89 | else | |
90 | errorbox(errormessage); | |
91 | break; | |
92 | ||
93 | default: | |
94 | break; | |
95 | } | |
96 | } | |
97 | ||
98 | if (automode == 0) | |
99 | { | |
100 | /* Restart networking! */ | |
101 | if (netaddresschange) | |
102 | { | |
103 | runcommandwithstatus("/etc/rc.d/init.d/network stop", | |
104 | ctr[TR_PUSHING_NETWORK_DOWN]); | |
105 | runcommandwithstatus("/etc/rc.d/init.d/network start", | |
106 | ctr[TR_PULLING_NETWORK_UP]); | |
107 | // mysystem("/etc/rc.d/rc.pcmcia start"); | |
108 | } | |
109 | } | |
110 | ||
111 | return 1; | |
112 | } | |
113 | ||
114 | int oktoleave(char *errormessage) | |
115 | { | |
116 | struct keyvalue *kv = initkeyvalues(); | |
117 | char temp[STRING_SIZE]; | |
118 | int configtype; | |
119 | ||
120 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
121 | { | |
122 | freekeyvalues(kv); | |
123 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
124 | return 0; | |
125 | } | |
126 | ||
127 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); | |
128 | if (configtype < 0 || configtype > 7) configtype = 0; | |
129 | ||
130 | if (HAS_BLUE) | |
131 | { | |
132 | strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); | |
133 | if (!(strlen(temp))) | |
134 | { | |
135 | strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); | |
136 | goto EXIT; | |
137 | } | |
138 | if (!(interfacecheck(kv, "BLUE"))) | |
139 | { | |
140 | strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); | |
141 | goto EXIT; | |
142 | } | |
143 | } | |
144 | if (HAS_ORANGE) | |
145 | { | |
146 | strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); | |
147 | if (!(strlen(temp))) | |
148 | { | |
149 | strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]); | |
150 | goto EXIT; | |
151 | } | |
152 | if (!(interfacecheck(kv, "ORANGE"))) | |
153 | { | |
154 | strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]); | |
155 | goto EXIT; | |
156 | } | |
157 | } | |
158 | if (HAS_RED) | |
159 | { | |
160 | strcpy(temp, ""); findkey(kv, "RED_DEV", temp); | |
161 | if (!(strlen(temp))) | |
162 | { | |
163 | strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); | |
164 | goto EXIT; | |
165 | } | |
166 | if (!(interfacecheck(kv, "RED"))) | |
167 | { | |
168 | strcpy(errormessage, ctr[TR_MISSING_RED_IP]); | |
169 | goto EXIT; | |
170 | } | |
171 | } | |
172 | strcpy(errormessage, ""); | |
173 | EXIT: | |
174 | freekeyvalues(kv); | |
175 | ||
176 | if (strlen(errormessage)) | |
177 | return 0; | |
178 | else | |
179 | return 1; | |
180 | } | |
181 | ||
182 | ||
183 | /* Shows the main menu and a summary of the current settings. */ | |
184 | int firstmenu(void) | |
185 | { | |
186 | char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], | |
187 | ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], | |
188 | ctr[TR_ADDRESS_SETTINGS], | |
189 | ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL }; | |
190 | int rc; | |
191 | static int choice = 0; | |
192 | struct keyvalue *kv = initkeyvalues(); | |
193 | char message[1000]; | |
194 | char temp[STRING_SIZE]; | |
195 | int x; | |
196 | int result; | |
197 | char networkrestart[STRING_SIZE] = ""; | |
198 | ||
199 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
200 | { | |
201 | freekeyvalues(kv); | |
202 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
203 | return 0; | |
204 | } | |
205 | ||
206 | if (netaddresschange) | |
207 | strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); | |
208 | ||
209 | strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); | |
210 | if (x < 0 || x > 7) x = 0; | |
211 | /* Format heading bit. */ | |
212 | snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], | |
213 | networkrestart); | |
214 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, | |
215 | sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
216 | ||
217 | if (rc == 0 || rc == 1) | |
218 | result = choice + 1; | |
219 | else | |
220 | result = 0; | |
221 | ||
222 | return result; | |
223 | } | |
224 | ||
225 | /* Here they choose general network config, number of nics etc. */ | |
226 | int configtypemenu(void) | |
227 | { | |
228 | struct keyvalue *kv = initkeyvalues(); | |
229 | char temp[STRING_SIZE] = "0"; | |
230 | char message[1000]; | |
231 | int choice; | |
232 | int rc; | |
233 | ||
234 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
235 | { | |
236 | freekeyvalues(kv); | |
237 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
238 | return 0; | |
239 | } | |
240 | ||
241 | findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); | |
242 | sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); | |
243 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, | |
244 | 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
245 | ||
246 | if (rc == 0 || rc == 1) | |
247 | { | |
248 | runcommandwithstatus("/etc/rc.d/init.d/network red down", | |
249 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
250 | runcommandwithstatus("/etc/rc.d/init.d/network blue down", | |
251 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
252 | runcommandwithstatus("/etc/rc.d/init.d/network orange down", | |
253 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
254 | ||
255 | sprintf(temp, "%d", choice); | |
256 | replacekeyvalue(kv, "CONFIG_TYPE", temp); | |
257 | replacekeyvalue(kv, "ORANGE_DEV", ""); | |
258 | replacekeyvalue(kv, "BLUE_DEV", ""); | |
259 | replacekeyvalue(kv, "RED_DEV", ""); | |
260 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
261 | netaddresschange = 1; | |
262 | } | |
263 | ||
264 | freekeyvalues(kv); | |
265 | ||
266 | return 0; | |
267 | } | |
268 | ||
269 | /* Driver menu. Choose drivers.. */ | |
270 | int drivermenu(void) | |
271 | { | |
272 | struct keyvalue *kv = initkeyvalues(); | |
273 | char message[1000]; | |
274 | char temp[STRING_SIZE], temp1[STRING_SIZE]; | |
275 | char driver[STRING_SIZE], dev[STRING_SIZE]; | |
276 | int configtype; | |
277 | int rc; | |
278 | ||
279 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
280 | { | |
281 | freekeyvalues(kv); | |
282 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
283 | return 0; | |
284 | } | |
285 | ||
286 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
287 | configtype = atol(temp); | |
288 | ||
289 | if (configtype == 0) | |
290 | { | |
291 | freekeyvalues(kv); | |
292 | errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]); | |
293 | return 0; | |
294 | } | |
295 | ||
296 | strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); | |
297 | ||
298 | /* This horrible big formats the heading :( */ | |
299 | strcpy(driver, ""); findkey(kv, "GREEN_DISPLAYDRIVER", driver); | |
300 | findnicdescription(driver, temp); | |
301 | strcpy(dev, ctr[TR_UNSET]); findkey(kv, "GREEN_DEV", dev); | |
302 | if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); | |
303 | sprintf(temp1, "GREEN: %s (%s)\n", temp, dev); | |
304 | strcat(message, temp1); | |
305 | if (HAS_BLUE) | |
306 | { | |
307 | strcpy(driver, ""); findkey(kv, "BLUE_DISPLAYDRIVER", driver); | |
308 | findnicdescription(driver, temp); | |
309 | strcpy(dev, ctr[TR_UNSET]); findkey(kv, "BLUE_DEV", dev); | |
310 | if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); | |
311 | sprintf(temp1, "BLUE: %s (%s)\n", temp, dev); | |
312 | strcat(message, temp1); | |
313 | } | |
314 | if (HAS_ORANGE) | |
315 | { | |
316 | strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver); | |
317 | findnicdescription(driver, temp); | |
318 | strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev); | |
319 | if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); | |
320 | sprintf(temp1, "ORANGE: %s (%s)\n", temp, dev); | |
321 | strcat(message, temp1); | |
322 | } | |
323 | if (HAS_RED) | |
324 | { | |
325 | strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver); | |
326 | findnicdescription(driver, temp); | |
327 | strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev); | |
328 | if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); | |
329 | sprintf(temp1, "RED: %s (%s)\n", temp, dev); | |
330 | strcat(message, temp1); | |
331 | } | |
332 | strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); | |
333 | rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], | |
334 | ctr[TR_CANCEL], message); | |
335 | if (rc == 0 || rc == 1) | |
336 | { | |
337 | /* Shit, got to do something.. */ | |
338 | changedrivers(); | |
339 | } | |
340 | ||
341 | freekeyvalues(kv); | |
342 | ||
343 | return 1; | |
344 | } | |
345 | ||
346 | int changedrivers(void) | |
347 | { | |
348 | struct keyvalue *kv = initkeyvalues(); | |
349 | char message[1000]; | |
350 | char temp[STRING_SIZE]; | |
351 | char driver[STRING_SIZE]; | |
352 | int configtype; | |
353 | int rc; | |
354 | int c; | |
355 | int needcards, sofarallocated, countofcards, toallocate; | |
356 | char *orange = "ORANGE"; | |
357 | char *blue = "BLUE"; | |
358 | char *red = "RED"; | |
359 | char *sections[4]; | |
360 | int choice; | |
361 | char nexteth[STRING_SIZE]; | |
362 | int abort; | |
363 | char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE]; | |
364 | char displaydriver[STRING_SIZE]; | |
365 | struct stat st; | |
366 | ||
367 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
368 | { | |
369 | freekeyvalues(kv); | |
370 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
371 | return 0; | |
372 | } | |
373 | ||
374 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
375 | configtype = atol(temp); | |
376 | ||
377 | runcommandwithstatus("/etc/rc.d/init.d/network red down", | |
378 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
379 | runcommandwithstatus("/etc/rc.d/init.d/network blue down", | |
380 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
381 | runcommandwithstatus("/etc/rc.d/init.d/network orange down", | |
382 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
383 | ||
384 | /* Remove all modules not needed for green networking. */ | |
385 | c = 0; | |
386 | strcpy(driver, ""); findkey(kv, "GREEN_DRIVER", driver); | |
387 | if (strcmp(driver, "pcmcia") != 0) { | |
388 | stat("/proc/bus/pccard", &st); | |
389 | mysystem("/etc/rc.d/rc.pcmcia stop"); | |
390 | if (S_ISDIR(st.st_mode)) { | |
391 | mysystem("/sbin/modprobe pcmcia_core"); | |
392 | mysystem("/sbin/modprobe pcmcia-controller"); | |
393 | mysystem("/sbin/modprobe ds"); | |
394 | } | |
395 | } | |
396 | while (nics[c].modulename) | |
397 | { | |
398 | if (strcmp(nics[c].modulename, driver) != 0) | |
399 | { | |
400 | if (checkformodule(nics[c].modulename)) | |
401 | { | |
402 | sprintf(temp, "/sbin/rmmod %s", nics[c].modulename); | |
403 | mysystem(temp); | |
404 | } | |
405 | } | |
406 | c++; | |
407 | } | |
408 | ||
409 | /* Blank them so the rc.netaddress.up does not get confused. */ | |
410 | replacekeyvalue(kv, "ORANGE_DEV", ""); | |
411 | replacekeyvalue(kv, "BLUE_DEV", ""); | |
412 | replacekeyvalue(kv, "RED_DEV", ""); | |
413 | ||
414 | if (configtype == 0) | |
415 | needcards = 1; | |
416 | else if (configtype == 1 || configtype == 2 || configtype == 4) | |
417 | needcards = 2; | |
418 | else if (configtype == 7) | |
419 | needcards = 4; | |
420 | else | |
421 | needcards = 3; | |
422 | ||
423 | /* This is the green card. */ | |
424 | sofarallocated = 1; | |
425 | ||
426 | findkey(kv, "GREEN_DRIVER", currentdriver); | |
427 | findkey(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions); | |
428 | strcpy(displaydriver, currentdriver); | |
429 | ||
430 | if (countcards() > 1) | |
431 | strcpy(currentdriver, ""); | |
432 | ||
433 | abort = 0; | |
434 | /* Keep going till all cards are got, or they give up. */ | |
435 | while (sofarallocated < needcards && !abort) | |
436 | { | |
437 | countofcards = countcards(); | |
438 | ||
439 | /* This is how many cards were added by the last module. */ | |
440 | toallocate = countofcards - sofarallocated; | |
441 | while (toallocate > 0 && sofarallocated < needcards) | |
442 | { | |
443 | findnicdescription(displaydriver, temp); | |
444 | sprintf(message, ctr[TR_UNCLAIMED_DRIVER], temp); | |
445 | c = 0; choice = 0; | |
446 | strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); | |
447 | if (HAS_BLUE && !strlen(temp)) | |
448 | { | |
449 | sections[c] = blue; | |
450 | c++; | |
451 | } | |
452 | strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); | |
453 | if (HAS_ORANGE && !strlen(temp)) | |
454 | { | |
455 | sections[c] = orange; | |
456 | c++; | |
457 | } | |
458 | strcpy(temp, ""); findkey(kv, "RED_DEV", temp); | |
459 | if (HAS_RED && !strlen(temp)) | |
460 | { | |
461 | sections[c] = red; | |
462 | c++; | |
463 | } | |
464 | sections[c] = NULL; | |
465 | rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT], | |
466 | message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], | |
467 | ctr[TR_CANCEL], NULL); | |
468 | if (rc == 0 || rc == 1) | |
469 | { | |
470 | /* Now we see which iface needs its settings changed. */ | |
471 | sprintf(nexteth, "eth%d", sofarallocated); | |
472 | if (strcmp(sections[choice], blue) == 0) | |
473 | { | |
474 | replacekeyvalue(kv, "BLUE_DEV", nexteth); | |
475 | replacekeyvalue(kv, "BLUE_DRIVER", currentdriver); | |
476 | replacekeyvalue(kv, "BLUE_DRIVER_OPTIONS", currentdriveroptions); | |
477 | replacekeyvalue(kv, "BLUE_DISPLAYDRIVER", displaydriver); | |
478 | sofarallocated++; | |
479 | toallocate--; | |
480 | strcpy(currentdriver, ""); | |
481 | strcpy(currentdriveroptions, ""); | |
482 | } | |
483 | if (strcmp(sections[choice], orange) == 0) | |
484 | { | |
485 | replacekeyvalue(kv, "ORANGE_DEV", nexteth); | |
486 | replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver); | |
487 | replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions); | |
488 | replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver); | |
489 | sofarallocated++; | |
490 | toallocate--; | |
491 | strcpy(currentdriver, ""); | |
492 | strcpy(currentdriveroptions, ""); | |
493 | } | |
494 | if (strcmp(sections[choice], red) == 0) | |
495 | { | |
496 | replacekeyvalue(kv, "RED_DEV", nexteth); | |
497 | replacekeyvalue(kv, "RED_DRIVER", currentdriver); | |
498 | replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions); | |
499 | replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver); | |
500 | sofarallocated++; | |
501 | toallocate--; | |
502 | strcpy(currentdriver, ""); | |
503 | strcpy(currentdriveroptions, ""); | |
504 | } | |
505 | } | |
506 | else | |
507 | { | |
508 | break; | |
509 | } | |
510 | } | |
511 | ||
512 | /* Need another module! The nitty gritty code is in libsmooth. */ | |
513 | if (sofarallocated < needcards) | |
514 | { | |
515 | rc = newtWinTernary(ctr[TR_CARD_ASSIGNMENT], ctr[TR_PROBE], | |
516 | ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_NO_UNALLOCATED_CARDS]); | |
517 | ||
518 | if (rc == 0 || rc == 1) | |
519 | { | |
520 | probecards(currentdriver, currentdriveroptions); | |
521 | if (!strlen(currentdriver)) | |
522 | errorbox(ctr[TR_PROBE_FAILED]); | |
523 | } | |
524 | else if (rc == 2) | |
525 | choosecards(currentdriver, currentdriveroptions); | |
526 | else | |
527 | abort = 1; | |
528 | ||
529 | strcpy(displaydriver, currentdriver); | |
530 | } | |
531 | } | |
532 | ||
533 | countofcards = countcards(); | |
534 | ||
535 | if (countofcards >= needcards) | |
536 | { | |
537 | newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK], | |
538 | ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]); | |
539 | } | |
540 | else | |
541 | errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]); | |
542 | ||
543 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
544 | ||
545 | freekeyvalues(kv); | |
546 | ||
547 | netaddresschange = 1; | |
548 | ||
549 | return 1; | |
550 | } | |
551 | ||
552 | /* Let user change GREEN address. */ | |
553 | int greenaddressmenu(void) | |
554 | { | |
555 | struct keyvalue *kv = initkeyvalues(); | |
556 | char message[1000]; | |
557 | int rc; | |
558 | ||
559 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
560 | { | |
561 | freekeyvalues(kv); | |
562 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
563 | return 0; | |
564 | } | |
565 | ||
566 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
567 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); | |
568 | ||
569 | if (rc == 0 || rc == 1) | |
570 | { | |
571 | if (changeaddress(kv, "GREEN", 0, "")) | |
572 | { | |
573 | netaddresschange = 1; | |
574 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
575 | writehostsfiles(); | |
576 | } | |
577 | } | |
578 | ||
579 | freekeyvalues(kv); | |
580 | ||
581 | return 0; | |
582 | } | |
583 | ||
584 | /* They can change BLUE, ORANGE and GREEN too :) */ | |
585 | int addressesmenu(void) | |
586 | { | |
587 | struct keyvalue *kv = initkeyvalues(); | |
588 | struct keyvalue *mainkv = initkeyvalues(); | |
589 | int rc = 0; | |
590 | char *sections[5]; | |
591 | char *green = "GREEN"; | |
592 | char *orange = "ORANGE"; | |
593 | char *blue = "BLUE"; | |
594 | char *red = "RED"; | |
595 | int c = 0; | |
596 | char greenaddress[STRING_SIZE]; | |
597 | char oldgreenaddress[STRING_SIZE]; | |
598 | char temp[STRING_SIZE]; | |
599 | char temp2[STRING_SIZE]; | |
600 | char message[1000]; | |
601 | int configtype; | |
602 | int done; | |
603 | int choice; | |
604 | char hostname[STRING_SIZE]; | |
605 | ||
606 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
607 | { | |
608 | freekeyvalues(kv); | |
609 | freekeyvalues(mainkv); | |
610 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
611 | return 0; | |
612 | } | |
613 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
614 | { | |
615 | freekeyvalues(kv); | |
616 | freekeyvalues(mainkv); | |
617 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
618 | return 0; | |
619 | } | |
620 | ||
621 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
622 | configtype = atol(temp); | |
623 | ||
624 | sections[c] = green; | |
625 | c++; | |
626 | if (HAS_BLUE) | |
627 | { | |
628 | sections[c] = blue; | |
629 | c++; | |
630 | } | |
631 | if (HAS_ORANGE) | |
632 | { | |
633 | sections[c] = orange; | |
634 | c++; | |
635 | } | |
636 | if (HAS_RED) | |
637 | { | |
638 | sections[c] = red; | |
639 | c++; | |
640 | } | |
641 | sections[c] = NULL; | |
642 | ||
643 | choice = 0; | |
644 | done = 0; | |
645 | while (!done) | |
646 | { | |
647 | rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], | |
648 | ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, | |
649 | 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
650 | ||
651 | if (rc == 0 || rc == 1) | |
652 | { | |
653 | if (strcmp(sections[choice], "GREEN") == 0) | |
654 | { | |
655 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
656 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
657 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], | |
658 | message); | |
659 | if (rc == 0 || rc == 1) | |
660 | { | |
661 | if (changeaddress(kv, "GREEN", 0, "")) | |
662 | { | |
663 | netaddresschange = 1; | |
664 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
665 | writehostsfiles(); | |
666 | findkey(kv, "GREEN_ADDRESS", greenaddress); | |
667 | snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); | |
668 | snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); | |
669 | replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); | |
670 | chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); | |
671 | } | |
672 | } | |
673 | } | |
674 | if (strcmp(sections[choice], "BLUE") == 0) | |
675 | { | |
676 | if (changeaddress(kv, "BLUE", 0, "")) | |
677 | netaddresschange = 1; | |
678 | } | |
679 | if (strcmp(sections[choice], "ORANGE") == 0) | |
680 | { | |
681 | if (changeaddress(kv, "ORANGE", 0, "")) | |
682 | netaddresschange = 1; | |
683 | } | |
684 | if (strcmp(sections[choice], "RED") == 0) | |
685 | { | |
686 | strcpy(hostname, ""); | |
687 | findkey(mainkv, "HOSTNAME", hostname); | |
688 | if (changeaddress(kv, "RED", 1, hostname)) | |
689 | netaddresschange = 1; | |
690 | } | |
691 | } | |
692 | else | |
693 | done = 1; | |
694 | } | |
695 | ||
696 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
697 | freekeyvalues(kv); | |
698 | freekeyvalues(mainkv); | |
699 | ||
700 | return 0; | |
701 | } | |
702 | ||
703 | /* DNS and default gateway.... */ | |
704 | int dnsgatewaymenu(void) | |
705 | { | |
706 | struct keyvalue *kv = initkeyvalues(); | |
707 | char message[1000]; | |
708 | char temp[STRING_SIZE] = "0"; | |
709 | struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; | |
710 | char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ | |
711 | int error; | |
712 | int configtype; | |
713 | int rc; | |
714 | ||
715 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
716 | { | |
717 | freekeyvalues(kv); | |
718 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
719 | return 0; | |
720 | } | |
721 | ||
722 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
723 | configtype = atol(temp); | |
724 | ||
725 | if (RED_IS_NOT_ETH) | |
726 | { | |
727 | freekeyvalues(kv); | |
728 | errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); | |
729 | return 0; | |
730 | } | |
731 | ||
732 | entries[DNS1].text = ctr[TR_PRIMARY_DNS]; | |
733 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
734 | values[DNS1] = strdup(temp); | |
735 | entries[DNS1].value = &values[DNS1]; | |
736 | entries[DNS1].flags = 0; | |
737 | ||
738 | entries[DNS2].text = ctr[TR_SECONDARY_DNS]; | |
739 | strcpy(temp, ""); findkey(kv, "DNS2", temp); | |
740 | values[DNS2] = strdup(temp); | |
741 | entries[DNS2].value = &values[DNS2]; | |
742 | entries[DNS2].flags = 0; | |
743 | ||
744 | entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; | |
745 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
746 | values[DEFAULT_GATEWAY] = strdup(temp); | |
747 | entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; | |
748 | entries[DEFAULT_GATEWAY].flags = 0; | |
749 | ||
750 | entries[DNSGATEWAY_TOTAL].text = NULL; | |
751 | entries[DNSGATEWAY_TOTAL].value = NULL; | |
752 | entries[DNSGATEWAY_TOTAL].flags = 0; | |
753 | ||
754 | do | |
755 | { | |
756 | error = 0; | |
757 | ||
758 | rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], | |
759 | ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, | |
760 | ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
761 | if (rc == 0 || rc == 1) | |
762 | { | |
763 | strcpy(message, ctr[TR_INVALID_FIELDS]); | |
764 | if (strlen(values[DNS1])) | |
765 | { | |
766 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
767 | { | |
768 | strcat(message, ctr[TR_PRIMARY_DNS_CR]); | |
769 | error = 1; | |
770 | } | |
771 | } | |
772 | if (strlen(values[DNS2])) | |
773 | { | |
774 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
775 | { | |
776 | strcat(message, ctr[TR_SECONDARY_DNS_CR]); | |
777 | error = 1; | |
778 | } | |
779 | } | |
780 | if (strlen(values[DEFAULT_GATEWAY])) | |
781 | { | |
782 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
783 | { | |
784 | strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); | |
785 | error = 1; | |
786 | } | |
787 | } | |
788 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
789 | { | |
790 | strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); | |
791 | error = 1; | |
792 | } | |
793 | ||
794 | if (error) | |
795 | errorbox(message); | |
796 | else | |
797 | { | |
798 | replacekeyvalue(kv, "DNS1", values[DNS1]); | |
799 | replacekeyvalue(kv, "DNS2", values[DNS2]); | |
800 | replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); | |
801 | netaddresschange = 1; | |
802 | free(values[DNS1]); | |
803 | free(values[DNS2]); | |
804 | free(values[DEFAULT_GATEWAY]); | |
805 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
806 | } | |
807 | } | |
808 | } | |
809 | while (error); | |
810 | ||
811 | freekeyvalues(kv); | |
812 | ||
813 | return 1; | |
814 | } |