]>
Commit | Line | Data |
---|---|---|
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 | */ | |
10 | ||
11 | // Translation | |
12 | #include <libintl.h> | |
13 | #define _(x) dgettext("setup", x) | |
14 | ||
15 | #include "setup.h" | |
16 | ||
17 | #define DNS1 0 | |
18 | #define DNS2 1 | |
19 | #define DEFAULT_GATEWAY 2 | |
20 | #define DNSGATEWAY_TOTAL 3 | |
21 | ||
22 | extern FILE *flog; | |
23 | extern char *mylog; | |
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 | extern struct nic nics[]; | |
34 | extern struct knic knics[]; | |
35 | ||
36 | char *configtypenames[] = { | |
37 | "GREEN + RED", | |
38 | "GREEN + RED + ORANGE", | |
39 | "GREEN + RED + BLUE", | |
40 | "GREEN + RED + ORANGE + BLUE", | |
41 | NULL }; | |
42 | int configtypecards[] = { | |
43 | 2, // "GREEN + RED", | |
44 | 3, // "GREEN + RED + ORANGE", | |
45 | 3, // "GREEN + RED + BLUE", | |
46 | 4 // "GREEN + RED + ORANGE + BLUE", | |
47 | }; | |
48 | ||
49 | ||
50 | int netaddresschange; | |
51 | ||
52 | int oktoleave(void); | |
53 | int firstmenu(void); | |
54 | int configtypemenu(void); | |
55 | int drivermenu(void); | |
56 | int changedrivers(void); | |
57 | int greenaddressmenu(void); | |
58 | int addressesmenu(void); | |
59 | int dnsgatewaymenu(void); | |
60 | ||
61 | int handlenetworking(void) | |
62 | { | |
63 | int done; | |
64 | int choice; | |
65 | int found; | |
66 | ||
67 | netaddresschange = 0; | |
68 | ||
69 | found = scan_network_cards(); | |
70 | found = init_knics(); | |
71 | ||
72 | done = 0; | |
73 | while (!done) | |
74 | { | |
75 | choice = firstmenu(); | |
76 | ||
77 | switch (choice) | |
78 | { | |
79 | case 1: | |
80 | configtypemenu(); | |
81 | break; | |
82 | ||
83 | case 2: | |
84 | drivermenu(); | |
85 | break; | |
86 | ||
87 | case 3: | |
88 | addressesmenu(); | |
89 | break; | |
90 | ||
91 | case 4: | |
92 | dnsgatewaymenu(); | |
93 | break; | |
94 | ||
95 | case 0: | |
96 | if (oktoleave()) done = 1; | |
97 | break; | |
98 | ||
99 | default: | |
100 | break; | |
101 | } | |
102 | } | |
103 | ||
104 | if (automode == 0) | |
105 | { | |
106 | /* Restart networking! */ | |
107 | if (netaddresschange) | |
108 | { | |
109 | runcommandwithstatus("/etc/rc.d/init.d/network stop", | |
110 | _("Networking"), _("Stopping network..."), NULL); | |
111 | ||
112 | rename_nics(); | |
113 | ||
114 | runcommandwithstatus("/etc/rc.d/init.d/network start", | |
115 | _("Networking"), _("Restarting network..."), NULL); | |
116 | runcommandwithstatus("/etc/rc.d/init.d/unbound restart", | |
117 | _("Networking"), _("Restarting unbound..."), NULL); | |
118 | } | |
119 | } else { | |
120 | rename_nics(); | |
121 | } | |
122 | return 1; | |
123 | } | |
124 | ||
125 | int oktoleave(void) | |
126 | { | |
127 | struct keyvalue *kv = initkeyvalues(); | |
128 | char temp[STRING_SIZE]; | |
129 | int configtype; | |
130 | int rc; | |
131 | ||
132 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
133 | { | |
134 | freekeyvalues(kv); | |
135 | errorbox(_("Unable to open settings file")); | |
136 | return 0; | |
137 | } | |
138 | ||
139 | strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); | |
140 | if (configtype < 1 || configtype > 4) configtype = 1; | |
141 | ||
142 | if (HAS_GREEN) | |
143 | { | |
144 | strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); | |
145 | if (!(strlen(temp))) | |
146 | { | |
147 | errorbox(_("No GREEN interface assigned.")); | |
148 | freekeyvalues(kv); | |
149 | return 0; | |
150 | } | |
151 | if (!(interfacecheck(kv, "GREEN"))) | |
152 | { | |
153 | errorbox(_("Missing an IP address on GREEN.")); | |
154 | freekeyvalues(kv); | |
155 | return 0; | |
156 | } | |
157 | } | |
158 | if (HAS_RED) | |
159 | { | |
160 | ||
161 | strcpy(temp, ""); findkey(kv, "RED_DEV", temp); | |
162 | if (!(strlen(temp))) | |
163 | { | |
164 | rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"), | |
165 | _("No RED interface assigned.")); | |
166 | if (rc == 0 || rc == 1) | |
167 | { | |
168 | freekeyvalues(kv); | |
169 | return 0; | |
170 | } | |
171 | } | |
172 | if (!(interfacecheck(kv, "RED"))) | |
173 | { | |
174 | errorbox(_("Missing an IP address on RED.")); | |
175 | freekeyvalues(kv); | |
176 | return 0; | |
177 | } | |
178 | } | |
179 | if (HAS_ORANGE) | |
180 | { | |
181 | strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); | |
182 | if (!(strlen(temp))) | |
183 | { | |
184 | errorbox(_("No ORANGE interface assigned.")); | |
185 | freekeyvalues(kv); | |
186 | return 0; | |
187 | } | |
188 | if (!(interfacecheck(kv, "ORANGE"))) | |
189 | { | |
190 | errorbox(_("Missing an IP address on ORANGE.")); | |
191 | freekeyvalues(kv); | |
192 | return 0; | |
193 | } | |
194 | } | |
195 | if (HAS_BLUE) | |
196 | { | |
197 | strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); | |
198 | if (!(strlen(temp))) | |
199 | { | |
200 | errorbox(_("No BLUE interface assigned.")); | |
201 | freekeyvalues(kv); | |
202 | return 0; | |
203 | } | |
204 | if (!(interfacecheck(kv, "BLUE"))) | |
205 | { | |
206 | errorbox(_("Missing an IP address on BLUE.")); | |
207 | freekeyvalues(kv); | |
208 | return 0; | |
209 | } | |
210 | } | |
211 | ||
212 | strcpy(temp, ""); findkey(kv, "RED_TYPE", temp); | |
213 | if ((configtype == 0) || (strcmp(temp, "STATIC") == 0)) | |
214 | { | |
215 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
216 | if (!(strlen(temp))) | |
217 | { | |
218 | errorbox(_("Missing DNS.")); | |
219 | freekeyvalues(kv); | |
220 | return 0; | |
221 | } | |
222 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
223 | if (!(strlen(temp))) | |
224 | { | |
225 | errorbox(_("Missing Default Gateway.")); | |
226 | freekeyvalues(kv); | |
227 | return 0; | |
228 | } | |
229 | } | |
230 | return 1; | |
231 | } | |
232 | ||
233 | ||
234 | /* Shows the main menu and a summary of the current settings. */ | |
235 | int firstmenu(void) | |
236 | { | |
237 | char *sections[] = { | |
238 | _("Network configuration type"), | |
239 | _("Drivers and card assignments"), | |
240 | _("Address settings"), | |
241 | _("DNS and Gateway settings"), | |
242 | NULL | |
243 | }; | |
244 | int rc; | |
245 | static int choice = 0; | |
246 | struct keyvalue *kv = initkeyvalues(); | |
247 | char message[1000]; | |
248 | char temp[STRING_SIZE] = "1"; | |
249 | int x; | |
250 | int result; | |
251 | char networkrestart[STRING_SIZE] = ""; | |
252 | ||
253 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
254 | { | |
255 | freekeyvalues(kv); | |
256 | errorbox(_("Unable to open settings file")); | |
257 | return 0; | |
258 | } | |
259 | ||
260 | if (netaddresschange) | |
261 | strcpy(networkrestart, _("When configuration is complete, a network restart will be required.")); | |
262 | ||
263 | strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); | |
264 | x = atol(temp); | |
265 | x--; | |
266 | if (x < 0 || x > 4) x = 0; | |
267 | /* Format heading bit. */ | |
268 | snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart); | |
269 | rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6, | |
270 | sections, &choice, _("OK"), _("Done"), NULL); | |
271 | ||
272 | if (rc == 0 || rc == 1) | |
273 | result = choice + 1; | |
274 | else | |
275 | result = 0; | |
276 | ||
277 | return result; | |
278 | } | |
279 | ||
280 | /* Here they choose general network config, number of nics etc. */ | |
281 | int configtypemenu(void) | |
282 | { | |
283 | struct keyvalue *kv = initkeyvalues(); | |
284 | char temp[STRING_SIZE] = "1"; | |
285 | char message[1000]; | |
286 | int choise, found; | |
287 | int rc, configtype; | |
288 | ||
289 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
290 | { | |
291 | freekeyvalues(kv); | |
292 | errorbox(_("Unable to open settings file")); | |
293 | return 0; | |
294 | } | |
295 | ||
296 | found = scan_network_cards(); | |
297 | ||
298 | findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); | |
299 | choise--; | |
300 | ||
301 | sprintf(message, _("Select the network configuration for %s. " | |
302 | "The following configuration types list those interfaces which have ethernet attached. " | |
303 | "If you change this setting, a network restart will be required, and you will have to " | |
304 | "reconfigure the network driver assignments."), NAME); | |
305 | rc = newtWinMenu(_("Network configuration type"), message, 50, 5, 5, | |
306 | 6, configtypenames, &choise, _("OK"), _("Cancel"), NULL); | |
307 | if ( configtypecards[choise] > found ) { | |
308 | sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"), | |
309 | configtypecards[choise], found); | |
310 | errorbox(message); | |
311 | } | |
312 | ||
313 | if (rc == 0 || rc == 1) | |
314 | { | |
315 | choise++; | |
316 | sprintf(temp, "%d", choise); | |
317 | replacekeyvalue(kv, "CONFIG_TYPE", temp); | |
318 | configtype = atol(temp); | |
319 | if (!HAS_RED) | |
320 | clear_card_entry(_RED_CARD_); | |
321 | if (!HAS_ORANGE) | |
322 | clear_card_entry(_ORANGE_CARD_); | |
323 | if (!HAS_BLUE) | |
324 | clear_card_entry(_BLUE_CARD_); | |
325 | ||
326 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
327 | netaddresschange = 1; | |
328 | } | |
329 | freekeyvalues(kv); | |
330 | ||
331 | return 0; | |
332 | } | |
333 | ||
334 | /* Driver menu. Choose drivers.. */ | |
335 | int drivermenu(void) | |
336 | { | |
337 | struct keyvalue *kv = initkeyvalues(); | |
338 | char message[STRING_SIZE]; | |
339 | char temp[STRING_SIZE] = "1"; | |
340 | ||
341 | int configtype; | |
342 | int i, rc, kcount = 0, neednics; | |
343 | ||
344 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
345 | { | |
346 | freekeyvalues(kv); | |
347 | errorbox(_("Unable to open settings file")); | |
348 | return 0; | |
349 | } | |
350 | ||
351 | if (findkey(kv, "CONFIG_TYPE", temp)) | |
352 | configtype = atol(temp); | |
353 | else { | |
354 | fprintf(flog,"setting CONFIG_TYPE = %s\n",temp); | |
355 | configtype = atol(temp); | |
356 | replacekeyvalue(kv, "CONFIG_TYPE", temp); | |
357 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
358 | } | |
359 | ||
360 | strcpy(message, _("Configure network drivers, and which interface each card is assigned to. " | |
361 | "The current configuration is as follows:\n\n")); | |
362 | ||
363 | kcount = 0; | |
364 | neednics = 0; | |
365 | if (HAS_GREEN) { | |
366 | sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); | |
367 | strcat(message, temp); | |
368 | if (strlen(knics[_GREEN_CARD_].macaddr) ) { | |
369 | sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); | |
370 | strcat(message, temp); | |
371 | } | |
372 | neednics++; | |
373 | } | |
374 | if (HAS_RED) { | |
375 | sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); | |
376 | strcat(message, temp); | |
377 | if (strlen(knics[_RED_CARD_].macaddr) ) { | |
378 | sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); | |
379 | strcat(message, temp); | |
380 | } | |
381 | neednics++; | |
382 | } | |
383 | if (HAS_ORANGE) { | |
384 | sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); | |
385 | strcat(message, temp); | |
386 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
387 | sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); | |
388 | strcat(message, temp); | |
389 | } | |
390 | neednics++; | |
391 | } | |
392 | if (HAS_BLUE) { | |
393 | sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); | |
394 | strcat(message, temp); | |
395 | if (strlen(knics[_BLUE_CARD_].macaddr)) { | |
396 | sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); | |
397 | strcat(message, temp); | |
398 | } | |
399 | neednics++; | |
400 | } | |
401 | ||
402 | for ( i=0 ; i<4; i++) | |
403 | if (strcmp(knics[i].macaddr, "")) | |
404 | kcount++; | |
405 | ||
406 | if (neednics = kcount) | |
407 | { | |
408 | strcat(message, "\n"); | |
409 | strcat(message, _("Do you wish to change these settings?")); | |
410 | rc = newtWinChoice(_("Drivers and card assignments"), _("OK"), | |
411 | _("Cancel"), message); | |
412 | if (rc == 0 || rc == 1) | |
413 | { | |
414 | changedrivers(); | |
415 | } | |
416 | } else { | |
417 | changedrivers(); | |
418 | } | |
419 | freekeyvalues(kv); | |
420 | ||
421 | return 1; | |
422 | } | |
423 | ||
424 | int set_menu_entry_for(int *nr, int *card) | |
425 | { | |
426 | ||
427 | } | |
428 | ||
429 | int changedrivers(void) | |
430 | { | |
431 | struct keyvalue *kv = initkeyvalues(); | |
432 | char temp[STRING_SIZE], message[STRING_SIZE]; | |
433 | int configtype; | |
434 | int green = 0, red = 0, blue = 0, orange = 0; | |
435 | char MenuInhalt[10][180]; | |
436 | char *pMenuInhalt[10]; | |
437 | int count = 0, choise = 0, rc; | |
438 | int NicEntry[10]; | |
439 | ||
440 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
441 | { | |
442 | freekeyvalues(kv); | |
443 | errorbox(_("Unable to open settings file")); | |
444 | return 0; | |
445 | } | |
446 | if (automode == 0) | |
447 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", | |
448 | _("Networking"), _("Restarting non-local network..."), NULL); | |
449 | ||
450 | findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); | |
451 | if (configtype == 1) | |
452 | { green = 1; red = 1; } | |
453 | else if (configtype == 2) | |
454 | { green = 1; red = 1; orange = 1; } | |
455 | else if (configtype == 3) | |
456 | { green = 1; red = 1; blue = 1; } | |
457 | else if (configtype == 4) | |
458 | { green = 1; red=1; orange=1; blue = 1; } | |
459 | else if (configtype == "") | |
460 | { green = 1; red = 1; } | |
461 | ||
462 | do | |
463 | { | |
464 | count = 0; | |
465 | strcpy(message, _("Please choose the interface you wish to change.\n\n")); | |
466 | ||
467 | if (green) { | |
468 | strcpy(MenuInhalt[count], "GREEN"); | |
469 | pMenuInhalt[count] = MenuInhalt[count]; | |
470 | NicEntry[_GREEN_CARD_] = count; | |
471 | sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); | |
472 | strcat(message, temp); | |
473 | if ( strlen(knics[_GREEN_CARD_].macaddr) ) { | |
474 | sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); | |
475 | strcat(message, temp); | |
476 | } | |
477 | count++; | |
478 | } | |
479 | ||
480 | if (red) { | |
481 | strcpy(MenuInhalt[count], "RED"); | |
482 | pMenuInhalt[count] = MenuInhalt[count]; | |
483 | NicEntry[_RED_CARD_] = count; | |
484 | sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); | |
485 | strcat(message, temp); | |
486 | if ( strlen(knics[_RED_CARD_].macaddr) ) { | |
487 | sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); | |
488 | strcat(message, temp); | |
489 | } | |
490 | count++; | |
491 | } | |
492 | ||
493 | if (orange) { | |
494 | strcpy(MenuInhalt[count], "ORANGE"); | |
495 | pMenuInhalt[count] = MenuInhalt[count]; | |
496 | NicEntry[_ORANGE_CARD_] = count; | |
497 | sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); | |
498 | strcat(message, temp); | |
499 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
500 | sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); | |
501 | strcat(message, temp); | |
502 | } | |
503 | count++; | |
504 | } | |
505 | ||
506 | if (blue) { | |
507 | strcpy(MenuInhalt[count], "BLUE"); | |
508 | pMenuInhalt[count] = MenuInhalt[count]; | |
509 | NicEntry[_BLUE_CARD_] = count; | |
510 | sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); | |
511 | strcat(message, temp); | |
512 | if ( strlen(knics[_BLUE_CARD_].macaddr) ) { | |
513 | sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); | |
514 | strcat(message, temp); | |
515 | } | |
516 | count++; | |
517 | } | |
518 | pMenuInhalt[count] = NULL; | |
519 | ||
520 | rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt, | |
521 | &choise, _("Select"), _("Remove"), _("Done"), NULL); | |
522 | ||
523 | if ( rc == 0 || rc == 1) { | |
524 | if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_); | |
525 | if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_); | |
526 | if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_); | |
527 | if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_); | |
528 | netaddresschange = 1; | |
529 | } else if (rc == 2) { | |
530 | if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_); | |
531 | if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_); | |
532 | if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_); | |
533 | if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_); | |
534 | netaddresschange = 1; | |
535 | } | |
536 | } | |
537 | while ( rc <= 2); | |
538 | ||
539 | freekeyvalues(kv); | |
540 | return 1; | |
541 | } | |
542 | ||
543 | // Let user change GREEN address. | |
544 | int greenaddressmenu(void) | |
545 | { | |
546 | struct keyvalue *kv = initkeyvalues(); | |
547 | char message[1000]; | |
548 | int rc; | |
549 | ||
550 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
551 | { | |
552 | freekeyvalues(kv); | |
553 | errorbox(_("Unable to open settings file")); | |
554 | return 0; | |
555 | } | |
556 | ||
557 | sprintf(message, _("If you change this IP address, and you are logged in remotely, " | |
558 | "your connection to the %s machine will be broken, and you will have to reconnect " | |
559 | "on the new IP. This is a risky operation, and should only be attempted if you " | |
560 | "have physical access to the machine, should something go wrong."), NAME); | |
561 | rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message); | |
562 | ||
563 | if (rc == 0 || rc == 1) | |
564 | { | |
565 | if (changeaddress(kv, "GREEN", 0, "")) | |
566 | { | |
567 | netaddresschange = 1; | |
568 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
569 | writehostsfiles(); | |
570 | } | |
571 | } | |
572 | ||
573 | freekeyvalues(kv); | |
574 | ||
575 | return 0; | |
576 | } | |
577 | ||
578 | // They can change BLUE, ORANGE and GREEN too :) | |
579 | int addressesmenu(void) | |
580 | { | |
581 | struct keyvalue *kv = initkeyvalues(); | |
582 | struct keyvalue *mainkv = initkeyvalues(); | |
583 | int rc = 0; | |
584 | char *sections[5]; | |
585 | char *green = "GREEN"; | |
586 | char *orange = "ORANGE"; | |
587 | char *blue = "BLUE"; | |
588 | char *red = "RED"; | |
589 | int c = 0; | |
590 | char greenaddress[STRING_SIZE]; | |
591 | char oldgreenaddress[STRING_SIZE]; | |
592 | char temp[STRING_SIZE]; | |
593 | char temp2[STRING_SIZE]; | |
594 | char message[1000]; | |
595 | int configtype; | |
596 | int done; | |
597 | int choice; | |
598 | char hostname[STRING_SIZE]; | |
599 | ||
600 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
601 | { | |
602 | freekeyvalues(kv); | |
603 | freekeyvalues(mainkv); | |
604 | errorbox(_("Unable to open settings file")); | |
605 | return 0; | |
606 | } | |
607 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
608 | { | |
609 | freekeyvalues(kv); | |
610 | freekeyvalues(mainkv); | |
611 | errorbox(_("Unable to open settings file")); | |
612 | return 0; | |
613 | } | |
614 | ||
615 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
616 | configtype = atol(temp); | |
617 | ||
618 | sections[c] = green; | |
619 | c++; | |
620 | if (HAS_BLUE) | |
621 | { | |
622 | sections[c] = blue; | |
623 | c++; | |
624 | } | |
625 | if (HAS_ORANGE) | |
626 | { | |
627 | sections[c] = orange; | |
628 | c++; | |
629 | } | |
630 | if (HAS_RED) | |
631 | { | |
632 | sections[c] = red; | |
633 | c++; | |
634 | } | |
635 | sections[c] = NULL; | |
636 | ||
637 | choice = 0; | |
638 | done = 0; | |
639 | while (!done) | |
640 | { | |
641 | rc = newtWinMenu(_("Address settings"), | |
642 | _("Select the interface you wish to reconfigure."), 50, 5, | |
643 | 5, 6, sections, &choice, _("OK"), _("Done"), NULL); | |
644 | ||
645 | if (rc == 0 || rc == 1) | |
646 | { | |
647 | if (strcmp(sections[choice], "GREEN") == 0) | |
648 | { | |
649 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
650 | sprintf(message, _("If you change this IP address, and you are logged in remotely, " | |
651 | "your connection to the %s machine will be broken, and you will have to reconnect " | |
652 | "on the new IP. This is a risky operation, and should only be attempted if you " | |
653 | "have physical access to the machine, should something go wrong."), NAME); | |
654 | rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message); | |
655 | if (rc == 0 || rc == 1) | |
656 | { | |
657 | if (changeaddress(kv, "GREEN", 0, "")) | |
658 | { | |
659 | netaddresschange = 1; | |
660 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
661 | writehostsfiles(); | |
662 | findkey(kv, "GREEN_ADDRESS", greenaddress); | |
663 | snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); | |
664 | snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); | |
665 | replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); | |
666 | chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); | |
667 | } | |
668 | } | |
669 | } | |
670 | if (strcmp(sections[choice], "BLUE") == 0) | |
671 | { | |
672 | if (changeaddress(kv, "BLUE", 0, "")) | |
673 | netaddresschange = 1; | |
674 | } | |
675 | if (strcmp(sections[choice], "ORANGE") == 0) | |
676 | { | |
677 | if (changeaddress(kv, "ORANGE", 0, "")) | |
678 | netaddresschange = 1; | |
679 | } | |
680 | if (strcmp(sections[choice], "RED") == 0) | |
681 | { | |
682 | strcpy(hostname, ""); | |
683 | findkey(mainkv, "HOSTNAME", hostname); | |
684 | if (changeaddress(kv, "RED", 1, hostname)) | |
685 | netaddresschange = 1; | |
686 | } | |
687 | } | |
688 | else | |
689 | done = 1; | |
690 | } | |
691 | ||
692 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
693 | freekeyvalues(kv); | |
694 | freekeyvalues(mainkv); | |
695 | ||
696 | return 0; | |
697 | } | |
698 | ||
699 | /* DNS and default gateway.... */ | |
700 | int dnsgatewaymenu(void) | |
701 | { | |
702 | struct keyvalue *kv = initkeyvalues(); | |
703 | char message[1000]; | |
704 | char temp[STRING_SIZE] = "0"; | |
705 | struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; | |
706 | char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ | |
707 | int error; | |
708 | int configtype; | |
709 | int rc; | |
710 | ||
711 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
712 | { | |
713 | freekeyvalues(kv); | |
714 | errorbox(_("Unable to open settings file")); | |
715 | return 0; | |
716 | } | |
717 | ||
718 | entries[DNS1].text = _("Primary DNS:"); | |
719 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
720 | values[DNS1] = strdup(temp); | |
721 | entries[DNS1].value = &values[DNS1]; | |
722 | entries[DNS1].flags = 0; | |
723 | ||
724 | entries[DNS2].text = _("Secondary DNS:"); | |
725 | strcpy(temp, ""); findkey(kv, "DNS2", temp); | |
726 | values[DNS2] = strdup(temp); | |
727 | entries[DNS2].value = &values[DNS2]; | |
728 | entries[DNS2].flags = 0; | |
729 | ||
730 | entries[DEFAULT_GATEWAY].text = _("Default gateway:"); | |
731 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
732 | values[DEFAULT_GATEWAY] = strdup(temp); | |
733 | entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; | |
734 | entries[DEFAULT_GATEWAY].flags = 0; | |
735 | ||
736 | entries[DNSGATEWAY_TOTAL].text = NULL; | |
737 | entries[DNSGATEWAY_TOTAL].value = NULL; | |
738 | entries[DNSGATEWAY_TOTAL].flags = 0; | |
739 | ||
740 | do | |
741 | { | |
742 | error = 0; | |
743 | ||
744 | rc = newtWinEntries(_("DNS and Gateway settings"), | |
745 | _("Enter the DNS and gateway information. " | |
746 | "These settings are used only with Static IP (and DHCP if DNS set) on the RED interface."), | |
747 | 50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL); | |
748 | if (rc == 0 || rc == 1) | |
749 | { | |
750 | strcpy(message, _("The following fields are invalid:")); | |
751 | strcpy(message, "\n\n"); | |
752 | if (strlen(values[DNS1])) | |
753 | { | |
754 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
755 | { | |
756 | strcat(message, _("Primary DNS")); | |
757 | strcat(message, "\n"); | |
758 | error = 1; | |
759 | } | |
760 | } | |
761 | if (strlen(values[DNS2])) | |
762 | { | |
763 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
764 | { | |
765 | strcat(message, _("Secondary DNS")); | |
766 | strcat(message, "\n"); | |
767 | error = 1; | |
768 | } | |
769 | } | |
770 | if (strlen(values[DEFAULT_GATEWAY])) | |
771 | { | |
772 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
773 | { | |
774 | strcat(message, _("Default gateway")); | |
775 | strcat(message, "\n"); | |
776 | error = 1; | |
777 | } | |
778 | } | |
779 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
780 | { | |
781 | strcpy(message, _("Secondary DNS specified without a Primary DNS")); | |
782 | strcat(message, "\n"); | |
783 | error = 1; | |
784 | } | |
785 | ||
786 | if (error) | |
787 | errorbox(message); | |
788 | else | |
789 | { | |
790 | replacekeyvalue(kv, "DNS1", values[DNS1]); | |
791 | replacekeyvalue(kv, "DNS2", values[DNS2]); | |
792 | replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); | |
793 | netaddresschange = 1; | |
794 | free(values[DNS1]); | |
795 | free(values[DNS2]); | |
796 | free(values[DEFAULT_GATEWAY]); | |
797 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
798 | } | |
799 | } | |
800 | } | |
801 | while (error); | |
802 | ||
803 | freekeyvalues(kv); | |
804 | ||
805 | return 1; | |
806 | } |