]>
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 | * | |
069680ac | 9 | */ |
e1457ba0 MT |
10 | |
11 | // Translation | |
12 | #include <libintl.h> | |
13 | #define _(x) dgettext("setup", x) | |
14 | ||
069680ac MT |
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 | ||
069680ac MT |
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 | ||
069680ac | 33 | extern struct nic nics[]; |
5057b611 | 34 | extern struct knic knics[]; |
069680ac | 35 | |
a358af8c | 36 | char *configtypenames[] = { |
9b040aa0 HS |
37 | "GREEN + RED", |
38 | "GREEN + RED + ORANGE", | |
39 | "GREEN + RED + BLUE", | |
40 | "GREEN + RED + ORANGE + BLUE", | |
41 | NULL }; | |
42 | int configtypecards[] = { | |
9b040aa0 HS |
43 | 2, // "GREEN + RED", |
44 | 3, // "GREEN + RED + ORANGE", | |
45 | 3, // "GREEN + RED + BLUE", | |
6fc15159 | 46 | 4 // "GREEN + RED + ORANGE + BLUE", |
9b040aa0 HS |
47 | }; |
48 | ||
49 | ||
069680ac MT |
50 | int netaddresschange; |
51 | ||
855446c6 | 52 | int oktoleave(void); |
069680ac MT |
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; | |
9b040aa0 | 65 | int found; |
069680ac MT |
66 | |
67 | netaddresschange = 0; | |
68 | ||
9b040aa0 | 69 | found = scan_network_cards(); |
9c1c1c57 | 70 | found = init_knics(); |
9b040aa0 | 71 | |
069680ac MT |
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: | |
855446c6 | 96 | if (oktoleave()) done = 1; |
069680ac MT |
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", | |
46b56e20 | 110 | _("Networking"), _("Stopping network..."), NULL); |
eea0467a HS |
111 | |
112 | rename_nics(); | |
113 | ||
069680ac | 114 | runcommandwithstatus("/etc/rc.d/init.d/network start", |
46b56e20 | 115 | _("Networking"), _("Restarting network..."), NULL); |
3a6752d9 AF |
116 | runcommandwithstatus("/etc/rc.d/init.d/unbound restart", |
117 | _("Networking"), _("Restarting unbound..."), NULL); | |
069680ac | 118 | } |
a5d81233 AF |
119 | } else { |
120 | rename_nics(); | |
069680ac | 121 | } |
069680ac MT |
122 | return 1; |
123 | } | |
124 | ||
855446c6 | 125 | int oktoleave(void) |
069680ac MT |
126 | { |
127 | struct keyvalue *kv = initkeyvalues(); | |
128 | char temp[STRING_SIZE]; | |
129 | int configtype; | |
855446c6 | 130 | int rc; |
069680ac MT |
131 | |
132 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
133 | { | |
134 | freekeyvalues(kv); | |
e1457ba0 | 135 | errorbox(_("Unable to open settings file")); |
069680ac MT |
136 | return 0; |
137 | } | |
138 | ||
0db33b56 MT |
139 | strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); |
140 | if (configtype < 1 || configtype > 4) configtype = 1; | |
069680ac | 141 | |
f93a4b4f | 142 | if (HAS_GREEN) |
069680ac | 143 | { |
f93a4b4f | 144 | strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); |
069680ac MT |
145 | if (!(strlen(temp))) |
146 | { | |
e1457ba0 | 147 | errorbox(_("No GREEN interface assigned.")); |
855446c6 MT |
148 | freekeyvalues(kv); |
149 | return 0; | |
069680ac | 150 | } |
f93a4b4f | 151 | if (!(interfacecheck(kv, "GREEN"))) |
069680ac | 152 | { |
e1457ba0 | 153 | errorbox(_("Missing an IP address on GREEN.")); |
855446c6 MT |
154 | freekeyvalues(kv); |
155 | return 0; | |
f93a4b4f HS |
156 | } |
157 | } | |
158 | if (HAS_RED) | |
159 | { | |
855446c6 | 160 | |
f93a4b4f HS |
161 | strcpy(temp, ""); findkey(kv, "RED_DEV", temp); |
162 | if (!(strlen(temp))) | |
163 | { | |
e1457ba0 MT |
164 | rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"), |
165 | _("No RED interface assigned.")); | |
855446c6 MT |
166 | if (rc == 0 || rc == 1) |
167 | { | |
168 | freekeyvalues(kv); | |
169 | return 0; | |
170 | } | |
f93a4b4f HS |
171 | } |
172 | if (!(interfacecheck(kv, "RED"))) | |
173 | { | |
e1457ba0 | 174 | errorbox(_("Missing an IP address on RED.")); |
855446c6 MT |
175 | freekeyvalues(kv); |
176 | return 0; | |
069680ac MT |
177 | } |
178 | } | |
179 | if (HAS_ORANGE) | |
180 | { | |
181 | strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); | |
182 | if (!(strlen(temp))) | |
183 | { | |
e1457ba0 | 184 | errorbox(_("No ORANGE interface assigned.")); |
855446c6 MT |
185 | freekeyvalues(kv); |
186 | return 0; | |
069680ac MT |
187 | } |
188 | if (!(interfacecheck(kv, "ORANGE"))) | |
189 | { | |
e1457ba0 | 190 | errorbox(_("Missing an IP address on ORANGE.")); |
855446c6 MT |
191 | freekeyvalues(kv); |
192 | return 0; | |
069680ac MT |
193 | } |
194 | } | |
f93a4b4f | 195 | if (HAS_BLUE) |
069680ac | 196 | { |
f93a4b4f | 197 | strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); |
069680ac MT |
198 | if (!(strlen(temp))) |
199 | { | |
e1457ba0 | 200 | errorbox(_("No BLUE interface assigned.")); |
855446c6 MT |
201 | freekeyvalues(kv); |
202 | return 0; | |
069680ac | 203 | } |
f93a4b4f | 204 | if (!(interfacecheck(kv, "BLUE"))) |
069680ac | 205 | { |
e1457ba0 | 206 | errorbox(_("Missing an IP address on BLUE.")); |
855446c6 MT |
207 | freekeyvalues(kv); |
208 | return 0; | |
f93a4b4f HS |
209 | } |
210 | } | |
b3f09dd8 MT |
211 | |
212 | strcpy(temp, ""); findkey(kv, "RED_TYPE", temp); | |
213 | if ((configtype == 0) || (strcmp(temp, "STATIC") == 0)) | |
f93a4b4f HS |
214 | { |
215 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
216 | if (!(strlen(temp))) | |
217 | { | |
0a39488e | 218 | errorbox(_("Missing DNS.")); |
855446c6 MT |
219 | freekeyvalues(kv); |
220 | return 0; | |
f93a4b4f HS |
221 | } |
222 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
223 | if (!(strlen(temp))) | |
224 | { | |
e1457ba0 | 225 | errorbox(_("Missing Default Gateway.")); |
855446c6 MT |
226 | freekeyvalues(kv); |
227 | return 0; | |
069680ac MT |
228 | } |
229 | } | |
855446c6 | 230 | return 1; |
069680ac MT |
231 | } |
232 | ||
233 | ||
234 | /* Shows the main menu and a summary of the current settings. */ | |
235 | int firstmenu(void) | |
236 | { | |
e1457ba0 MT |
237 | char *sections[] = { |
238 | _("Network configuration type"), | |
239 | _("Drivers and card assignments"), | |
240 | _("Address settings"), | |
241 | _("DNS and Gateway settings"), | |
242 | NULL | |
243 | }; | |
069680ac MT |
244 | int rc; |
245 | static int choice = 0; | |
246 | struct keyvalue *kv = initkeyvalues(); | |
247 | char message[1000]; | |
0db33b56 | 248 | char temp[STRING_SIZE] = "1"; |
069680ac MT |
249 | int x; |
250 | int result; | |
251 | char networkrestart[STRING_SIZE] = ""; | |
252 | ||
253 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
254 | { | |
255 | freekeyvalues(kv); | |
e1457ba0 | 256 | errorbox(_("Unable to open settings file")); |
069680ac MT |
257 | return 0; |
258 | } | |
259 | ||
260 | if (netaddresschange) | |
e1457ba0 | 261 | strcpy(networkrestart, _("When configuration is complete, a network restart will be required.")); |
069680ac | 262 | |
d0f2cc42 MT |
263 | strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); |
264 | x = atol(temp); | |
265 | x--; | |
0db33b56 | 266 | if (x < 0 || x > 4) x = 0; |
069680ac | 267 | /* Format heading bit. */ |
782ae35d | 268 | snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart); |
e1457ba0 MT |
269 | rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6, |
270 | sections, &choice, _("OK"), _("Done"), NULL); | |
069680ac MT |
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(); | |
0db33b56 | 284 | char temp[STRING_SIZE] = "1"; |
069680ac | 285 | char message[1000]; |
9b040aa0 | 286 | int choise, found; |
0db33b56 | 287 | int rc, configtype; |
9b040aa0 | 288 | |
069680ac MT |
289 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
290 | { | |
291 | freekeyvalues(kv); | |
e1457ba0 | 292 | errorbox(_("Unable to open settings file")); |
069680ac MT |
293 | return 0; |
294 | } | |
9b040aa0 HS |
295 | |
296 | found = scan_network_cards(); | |
069680ac | 297 | |
9b040aa0 | 298 | findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); |
6fc15159 | 299 | choise--; |
9b040aa0 | 300 | |
e1457ba0 MT |
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); | |
9b040aa0 | 307 | if ( configtypecards[choise] > found ) { |
e1457ba0 MT |
308 | sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"), |
309 | configtypecards[choise], found); | |
9b040aa0 HS |
310 | errorbox(message); |
311 | } | |
069680ac MT |
312 | |
313 | if (rc == 0 || rc == 1) | |
314 | { | |
a358af8c | 315 | choise++; |
9b040aa0 | 316 | sprintf(temp, "%d", choise); |
069680ac | 317 | replacekeyvalue(kv, "CONFIG_TYPE", temp); |
0db33b56 MT |
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_); | |
9b040aa0 | 325 | |
069680ac MT |
326 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); |
327 | netaddresschange = 1; | |
328 | } | |
069680ac MT |
329 | freekeyvalues(kv); |
330 | ||
331 | return 0; | |
332 | } | |
333 | ||
334 | /* Driver menu. Choose drivers.. */ | |
335 | int drivermenu(void) | |
336 | { | |
337 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 | 338 | char message[STRING_SIZE]; |
0db33b56 | 339 | char temp[STRING_SIZE] = "1"; |
9c1c1c57 | 340 | |
069680ac | 341 | int configtype; |
0db33b56 | 342 | int i, rc, kcount = 0, neednics; |
069680ac MT |
343 | |
344 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
345 | { | |
346 | freekeyvalues(kv); | |
e1457ba0 | 347 | errorbox(_("Unable to open settings file")); |
069680ac MT |
348 | return 0; |
349 | } | |
350 | ||
4061c03f HS |
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 | ||
e1457ba0 MT |
360 | strcpy(message, _("Configure network drivers, and which interface each card is assigned to. " |
361 | "The current configuration is as follows:\n\n")); | |
5057b611 | 362 | |
0db33b56 MT |
363 | kcount = 0; |
364 | neednics = 0; | |
5057b611 | 365 | if (HAS_GREEN) { |
e1457ba0 | 366 | sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); |
5057b611 HS |
367 | strcat(message, temp); |
368 | if (strlen(knics[_GREEN_CARD_].macaddr) ) { | |
e1457ba0 | 369 | sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); |
5057b611 HS |
370 | strcat(message, temp); |
371 | } | |
372 | neednics++; | |
75ae2191 | 373 | } |
5057b611 | 374 | if (HAS_RED) { |
e1457ba0 | 375 | sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); |
5057b611 HS |
376 | strcat(message, temp); |
377 | if (strlen(knics[_RED_CARD_].macaddr) ) { | |
e1457ba0 | 378 | sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); |
5057b611 | 379 | strcat(message, temp); |
75ae2191 | 380 | } |
5057b611 | 381 | neednics++; |
069680ac | 382 | } |
75ae2191 | 383 | if (HAS_ORANGE) { |
e1457ba0 | 384 | sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); |
5057b611 HS |
385 | strcat(message, temp); |
386 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
e1457ba0 | 387 | sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); |
5057b611 HS |
388 | strcat(message, temp); |
389 | } | |
390 | neednics++; | |
75ae2191 | 391 | } |
5057b611 | 392 | if (HAS_BLUE) { |
e1457ba0 | 393 | sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); |
5057b611 HS |
394 | strcat(message, temp); |
395 | if (strlen(knics[_BLUE_CARD_].macaddr)) { | |
e1457ba0 | 396 | sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); |
5057b611 | 397 | strcat(message, temp); |
75ae2191 | 398 | } |
5057b611 | 399 | neednics++; |
069680ac | 400 | } |
5057b611 | 401 | |
0db33b56 MT |
402 | for ( i=0 ; i<4; i++) |
403 | if (strcmp(knics[i].macaddr, "")) | |
404 | kcount++; | |
5057b611 | 405 | |
f93a4b4f HS |
406 | if (neednics = kcount) |
407 | { | |
e1457ba0 MT |
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); | |
5057b611 HS |
412 | if (rc == 0 || rc == 1) |
413 | { | |
5057b611 HS |
414 | changedrivers(); |
415 | } | |
416 | } else { | |
069680ac MT |
417 | changedrivers(); |
418 | } | |
069680ac MT |
419 | freekeyvalues(kv); |
420 | ||
421 | return 1; | |
422 | } | |
423 | ||
9b040aa0 HS |
424 | int set_menu_entry_for(int *nr, int *card) |
425 | { | |
426 | ||
427 | } | |
428 | ||
069680ac MT |
429 | int changedrivers(void) |
430 | { | |
431 | struct keyvalue *kv = initkeyvalues(); | |
5057b611 | 432 | char temp[STRING_SIZE], message[STRING_SIZE]; |
069680ac | 433 | int configtype; |
75ae2191 | 434 | int green = 0, red = 0, blue = 0, orange = 0; |
5057b611 HS |
435 | char MenuInhalt[10][180]; |
436 | char *pMenuInhalt[10]; | |
437 | int count = 0, choise = 0, rc; | |
438 | int NicEntry[10]; | |
59de0b00 | 439 | |
069680ac MT |
440 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
441 | { | |
442 | freekeyvalues(kv); | |
e1457ba0 | 443 | errorbox(_("Unable to open settings file")); |
069680ac MT |
444 | return 0; |
445 | } | |
0db33b56 MT |
446 | if (automode == 0) |
447 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", | |
46b56e20 | 448 | _("Networking"), _("Restarting non-local network..."), NULL); |
59de0b00 | 449 | |
5057b611 | 450 | findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); |
a358af8c | 451 | if (configtype == 1) |
75ae2191 | 452 | { green = 1; red = 1; } |
9b040aa0 | 453 | else if (configtype == 2) |
75ae2191 | 454 | { green = 1; red = 1; orange = 1; } |
9b040aa0 | 455 | else if (configtype == 3) |
75ae2191 | 456 | { green = 1; red = 1; blue = 1; } |
9b040aa0 HS |
457 | else if (configtype == 4) |
458 | { green = 1; red=1; orange=1; blue = 1; } | |
da6e926b CS |
459 | else if (configtype == "") |
460 | { green = 1; red = 1; } | |
5057b611 HS |
461 | |
462 | do | |
463 | { | |
464 | count = 0; | |
e1457ba0 | 465 | strcpy(message, _("Please choose the interface you wish to change.\n\n")); |
5057b611 HS |
466 | |
467 | if (green) { | |
468 | strcpy(MenuInhalt[count], "GREEN"); | |
469 | pMenuInhalt[count] = MenuInhalt[count]; | |
470 | NicEntry[_GREEN_CARD_] = count; | |
e1457ba0 | 471 | sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); |
5057b611 HS |
472 | strcat(message, temp); |
473 | if ( strlen(knics[_GREEN_CARD_].macaddr) ) { | |
e1457ba0 | 474 | sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); |
5057b611 HS |
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; | |
e1457ba0 | 484 | sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); |
5057b611 HS |
485 | strcat(message, temp); |
486 | if ( strlen(knics[_RED_CARD_].macaddr) ) { | |
e1457ba0 | 487 | sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); |
5057b611 HS |
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; | |
e1457ba0 | 497 | sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); |
5057b611 HS |
498 | strcat(message, temp); |
499 | if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { | |
e1457ba0 | 500 | sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); |
5057b611 HS |
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; | |
e1457ba0 | 510 | sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); |
5057b611 HS |
511 | strcat(message, temp); |
512 | if ( strlen(knics[_BLUE_CARD_].macaddr) ) { | |
e1457ba0 | 513 | sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); |
5057b611 HS |
514 | strcat(message, temp); |
515 | } | |
516 | count++; | |
517 | } | |
518 | pMenuInhalt[count] = NULL; | |
519 | ||
e1457ba0 MT |
520 | rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt, |
521 | &choise, _("Select"), _("Remove"), _("Done"), NULL); | |
5057b611 HS |
522 | |
523 | if ( rc == 0 || rc == 1) { | |
9b040aa0 HS |
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_); | |
eea0467a | 528 | netaddresschange = 1; |
5057b611 | 529 | } else if (rc == 2) { |
9b040aa0 HS |
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_); | |
eea0467a | 534 | netaddresschange = 1; |
a358af8c | 535 | } |
5057b611 HS |
536 | } |
537 | while ( rc <= 2); | |
069680ac MT |
538 | |
539 | freekeyvalues(kv); | |
069680ac MT |
540 | return 1; |
541 | } | |
542 | ||
75ae2191 | 543 | // Let user change GREEN address. |
069680ac MT |
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); | |
e1457ba0 | 553 | errorbox(_("Unable to open settings file")); |
069680ac MT |
554 | return 0; |
555 | } | |
556 | ||
e1457ba0 MT |
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); | |
069680ac MT |
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 | ||
75ae2191 | 578 | // They can change BLUE, ORANGE and GREEN too :) |
069680ac MT |
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); | |
e1457ba0 | 604 | errorbox(_("Unable to open settings file")); |
069680ac MT |
605 | return 0; |
606 | } | |
607 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
608 | { | |
609 | freekeyvalues(kv); | |
610 | freekeyvalues(mainkv); | |
e1457ba0 | 611 | errorbox(_("Unable to open settings file")); |
069680ac MT |
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 | { | |
e1457ba0 MT |
641 | rc = newtWinMenu(_("Address settings"), |
642 | _("Select the interface you wish to reconfigure."), 50, 5, | |
643 | 5, 6, sections, &choice, _("OK"), _("Done"), NULL); | |
069680ac MT |
644 | |
645 | if (rc == 0 || rc == 1) | |
646 | { | |
647 | if (strcmp(sections[choice], "GREEN") == 0) | |
648 | { | |
649 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
e1457ba0 MT |
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); | |
069680ac MT |
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); | |
e1457ba0 | 714 | errorbox(_("Unable to open settings file")); |
069680ac MT |
715 | return 0; |
716 | } | |
717 | ||
e1457ba0 | 718 | entries[DNS1].text = _("Primary DNS:"); |
069680ac MT |
719 | strcpy(temp, ""); findkey(kv, "DNS1", temp); |
720 | values[DNS1] = strdup(temp); | |
721 | entries[DNS1].value = &values[DNS1]; | |
722 | entries[DNS1].flags = 0; | |
723 | ||
e1457ba0 | 724 | entries[DNS2].text = _("Secondary DNS:"); |
069680ac MT |
725 | strcpy(temp, ""); findkey(kv, "DNS2", temp); |
726 | values[DNS2] = strdup(temp); | |
727 | entries[DNS2].value = &values[DNS2]; | |
728 | entries[DNS2].flags = 0; | |
729 | ||
e1457ba0 | 730 | entries[DEFAULT_GATEWAY].text = _("Default gateway:"); |
069680ac MT |
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 | ||
e1457ba0 MT |
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); | |
069680ac MT |
748 | if (rc == 0 || rc == 1) |
749 | { | |
e1457ba0 MT |
750 | strcpy(message, _("The following fields are invalid:")); |
751 | strcpy(message, "\n\n"); | |
069680ac MT |
752 | if (strlen(values[DNS1])) |
753 | { | |
754 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
755 | { | |
e1457ba0 MT |
756 | strcat(message, _("Primary DNS")); |
757 | strcat(message, "\n"); | |
069680ac MT |
758 | error = 1; |
759 | } | |
760 | } | |
761 | if (strlen(values[DNS2])) | |
762 | { | |
763 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
764 | { | |
e1457ba0 MT |
765 | strcat(message, _("Secondary DNS")); |
766 | strcat(message, "\n"); | |
069680ac MT |
767 | error = 1; |
768 | } | |
769 | } | |
770 | if (strlen(values[DEFAULT_GATEWAY])) | |
771 | { | |
772 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
773 | { | |
e1457ba0 MT |
774 | strcat(message, _("Default gateway")); |
775 | strcat(message, "\n"); | |
069680ac MT |
776 | error = 1; |
777 | } | |
778 | } | |
779 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
780 | { | |
e1457ba0 MT |
781 | strcpy(message, _("Secondary DNS specified without a Primary DNS")); |
782 | strcat(message, "\n"); | |
069680ac MT |
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 | } |