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