]>
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]); | |
069680ac MT |
107 | } |
108 | } | |
109 | ||
110 | return 1; | |
111 | } | |
112 | ||
113 | int oktoleave(char *errormessage) | |
114 | { | |
115 | struct keyvalue *kv = initkeyvalues(); | |
116 | char temp[STRING_SIZE]; | |
117 | int configtype; | |
118 | ||
119 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
120 | { | |
121 | freekeyvalues(kv); | |
122 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
123 | return 0; | |
124 | } | |
125 | ||
126 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); | |
127 | if (configtype < 0 || configtype > 7) configtype = 0; | |
128 | ||
129 | if (HAS_BLUE) | |
130 | { | |
131 | strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); | |
132 | if (!(strlen(temp))) | |
133 | { | |
134 | strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); | |
135 | goto EXIT; | |
136 | } | |
137 | if (!(interfacecheck(kv, "BLUE"))) | |
138 | { | |
139 | strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); | |
140 | goto EXIT; | |
141 | } | |
142 | } | |
143 | if (HAS_ORANGE) | |
144 | { | |
145 | strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); | |
146 | if (!(strlen(temp))) | |
147 | { | |
148 | strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]); | |
149 | goto EXIT; | |
150 | } | |
151 | if (!(interfacecheck(kv, "ORANGE"))) | |
152 | { | |
153 | strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]); | |
154 | goto EXIT; | |
155 | } | |
156 | } | |
157 | if (HAS_RED) | |
158 | { | |
159 | strcpy(temp, ""); findkey(kv, "RED_DEV", temp); | |
160 | if (!(strlen(temp))) | |
161 | { | |
162 | strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); | |
163 | goto EXIT; | |
164 | } | |
165 | if (!(interfacecheck(kv, "RED"))) | |
166 | { | |
167 | strcpy(errormessage, ctr[TR_MISSING_RED_IP]); | |
168 | goto EXIT; | |
169 | } | |
170 | } | |
171 | strcpy(errormessage, ""); | |
172 | EXIT: | |
173 | freekeyvalues(kv); | |
174 | ||
175 | if (strlen(errormessage)) | |
176 | return 0; | |
177 | else | |
178 | return 1; | |
179 | } | |
180 | ||
181 | ||
182 | /* Shows the main menu and a summary of the current settings. */ | |
183 | int firstmenu(void) | |
184 | { | |
185 | char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], | |
186 | ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], | |
187 | ctr[TR_ADDRESS_SETTINGS], | |
188 | ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL }; | |
189 | int rc; | |
190 | static int choice = 0; | |
191 | struct keyvalue *kv = initkeyvalues(); | |
192 | char message[1000]; | |
193 | char temp[STRING_SIZE]; | |
194 | int x; | |
195 | int result; | |
196 | char networkrestart[STRING_SIZE] = ""; | |
197 | ||
198 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
199 | { | |
200 | freekeyvalues(kv); | |
201 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
202 | return 0; | |
203 | } | |
204 | ||
205 | if (netaddresschange) | |
206 | strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); | |
207 | ||
208 | strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); | |
209 | if (x < 0 || x > 7) x = 0; | |
210 | /* Format heading bit. */ | |
211 | snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], | |
212 | networkrestart); | |
213 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, | |
214 | sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
215 | ||
216 | if (rc == 0 || rc == 1) | |
217 | result = choice + 1; | |
218 | else | |
219 | result = 0; | |
220 | ||
221 | return result; | |
222 | } | |
223 | ||
224 | /* Here they choose general network config, number of nics etc. */ | |
225 | int configtypemenu(void) | |
226 | { | |
227 | struct keyvalue *kv = initkeyvalues(); | |
228 | char temp[STRING_SIZE] = "0"; | |
229 | char message[1000]; | |
230 | int choice; | |
231 | int rc; | |
232 | ||
233 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
234 | { | |
235 | freekeyvalues(kv); | |
236 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
237 | return 0; | |
238 | } | |
239 | ||
240 | findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); | |
241 | sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); | |
242 | rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, | |
243 | 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
244 | ||
245 | if (rc == 0 || rc == 1) | |
246 | { | |
75ae2191 | 247 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", |
069680ac MT |
248 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); |
249 | ||
250 | sprintf(temp, "%d", choice); | |
251 | replacekeyvalue(kv, "CONFIG_TYPE", temp); | |
252 | replacekeyvalue(kv, "ORANGE_DEV", ""); | |
253 | replacekeyvalue(kv, "BLUE_DEV", ""); | |
254 | replacekeyvalue(kv, "RED_DEV", ""); | |
255 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
256 | netaddresschange = 1; | |
257 | } | |
258 | ||
259 | freekeyvalues(kv); | |
260 | ||
261 | return 0; | |
262 | } | |
263 | ||
264 | /* Driver menu. Choose drivers.. */ | |
265 | int drivermenu(void) | |
266 | { | |
75ae2191 | 267 | FILE *fp; |
069680ac | 268 | struct keyvalue *kv = initkeyvalues(); |
75ae2191 MT |
269 | char message[1000], macaddr[STRING_SIZE]; |
270 | char temp_line[STRING_SIZE]; | |
069680ac | 271 | char temp[STRING_SIZE], temp1[STRING_SIZE]; |
75ae2191 MT |
272 | struct knic knics[20], *pknics; |
273 | pknics = knics; | |
069680ac | 274 | int configtype; |
75ae2191 | 275 | int rc, i = 0, kcount = 0; |
069680ac MT |
276 | |
277 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
278 | { | |
279 | freekeyvalues(kv); | |
280 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
281 | return 0; | |
282 | } | |
283 | ||
284 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
285 | configtype = atol(temp); | |
286 | ||
287 | if (configtype == 0) | |
288 | { | |
289 | freekeyvalues(kv); | |
290 | errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]); | |
291 | return 0; | |
292 | } | |
293 | ||
294 | strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); | |
295 | ||
75ae2191 | 296 | if( (fp = fopen(KNOWN_NICS, "r")) == NULL ) |
069680ac | 297 | { |
75ae2191 MT |
298 | fprintf(flog,"Couldn't open " KNOWN_NICS); |
299 | return 1; | |
069680ac | 300 | } |
75ae2191 | 301 | while (fgets(temp_line, STRING_SIZE, fp) != NULL) |
069680ac | 302 | { |
75ae2191 MT |
303 | strcpy(knics[kcount].description, strtok(temp_line,";")); |
304 | strcpy(knics[kcount].macaddr , strtok(NULL,";")); | |
305 | if (strlen(knics[kcount].macaddr) > 5 ) kcount++; | |
306 | } | |
307 | fclose(fp); | |
308 | ||
309 | strcpy(macaddr, ctr[TR_UNSET]); | |
310 | findkey(kv, "GREEN_MACADDR", macaddr); | |
311 | for (i=0; i < kcount; i++) | |
312 | { // Check if the nic is already in use | |
313 | if (strcmp(pknics[i].macaddr, macaddr) == NULL ) | |
314 | break; | |
315 | } | |
316 | sprintf(temp1, "GREEN: %s (%s / green0)\n", pknics[i].description, pknics[i].macaddr); | |
317 | strcat(message, temp1); | |
318 | ||
319 | if (HAS_BLUE) { | |
320 | strcpy(macaddr, ctr[TR_UNSET]); | |
321 | findkey(kv, "BLUE_MACADDR", macaddr); | |
322 | for (i=0; i < kcount; i++) | |
323 | { // Check if the nic is already in use | |
324 | if (strcmp(pknics[i].macaddr, macaddr) == NULL ) | |
325 | break; | |
326 | } | |
327 | sprintf(temp1, "BLUE: %s (%s / blue0)\n", pknics[i].description, pknics[i].macaddr); | |
069680ac MT |
328 | strcat(message, temp1); |
329 | } | |
75ae2191 MT |
330 | if (HAS_ORANGE) { |
331 | strcpy(macaddr, ctr[TR_UNSET]); | |
332 | findkey(kv, "ORANGE_MACADDR", macaddr); | |
333 | for (i=0; i < kcount; i++) | |
334 | { // Check if the nic is already in use | |
335 | if (strcmp(pknics[i].macaddr, macaddr) == NULL ) | |
336 | break; | |
337 | } | |
338 | sprintf(temp1, "ORANGE: %s (%s / orange0)\n", pknics[i].description, pknics[i].macaddr); | |
339 | strcat(message, temp1); | |
340 | } | |
341 | if (HAS_RED) { | |
342 | strcpy(macaddr, ctr[TR_UNSET]); | |
343 | findkey(kv, "RED_MACADDR", macaddr); | |
344 | for (i=0; i < kcount; i++) | |
345 | { // Check if the nic is already in use | |
346 | if (strcmp(pknics[i].macaddr, macaddr) == NULL ) | |
347 | break; | |
348 | } | |
349 | sprintf(temp1, "RED: %s (%s / red0)\n", pknics[i].description, pknics[i].macaddr); | |
069680ac MT |
350 | strcat(message, temp1); |
351 | } | |
352 | strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); | |
353 | rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], | |
354 | ctr[TR_CANCEL], message); | |
355 | if (rc == 0 || rc == 1) | |
356 | { | |
357 | /* Shit, got to do something.. */ | |
358 | changedrivers(); | |
359 | } | |
360 | ||
361 | freekeyvalues(kv); | |
362 | ||
363 | return 1; | |
364 | } | |
365 | ||
75ae2191 MT |
366 | int cardassigned(char *colour) |
367 | { | |
368 | char command[STRING_SIZE]; | |
369 | sprintf(command, "grep -q %s < /etc/udev/rules.d/30-persistent-network.rules 2>/dev/null", colour); | |
370 | if (system(command)) | |
371 | return 0; | |
372 | else | |
373 | return 1; | |
374 | } | |
375 | ||
069680ac MT |
376 | int changedrivers(void) |
377 | { | |
378 | struct keyvalue *kv = initkeyvalues(); | |
069680ac | 379 | char temp[STRING_SIZE]; |
069680ac | 380 | int configtype; |
75ae2191 | 381 | int green = 0, red = 0, blue = 0, orange = 0; |
069680ac MT |
382 | |
383 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
384 | { | |
385 | freekeyvalues(kv); | |
386 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
387 | return 0; | |
388 | } | |
75ae2191 | 389 | |
069680ac MT |
390 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); |
391 | configtype = atol(temp); | |
069680ac | 392 | |
75ae2191 MT |
393 | runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", |
394 | ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); | |
395 | ||
069680ac | 396 | if (configtype == 0) |
75ae2191 MT |
397 | { green = 1; } |
398 | else if (configtype == 1) | |
399 | { green = 1; orange = 1; } | |
400 | else if (configtype == 2) | |
401 | { green = 1; red = 1; } | |
402 | else if (configtype == 3) | |
403 | { green = 1; red = 1; orange = 1; } | |
404 | else if (configtype == 4) | |
405 | { green = 1; blue = 1; } | |
406 | else if (configtype == 5) | |
407 | { green = 1; blue = 1; orange = 1; } | |
408 | else if (configtype == 6) | |
409 | { green = 1; red = 1; blue = 1; } | |
069680ac | 410 | else if (configtype == 7) |
75ae2191 | 411 | { green = 1; red = 1; blue = 1; orange = 1;} |
069680ac | 412 | |
75ae2191 MT |
413 | if (green && !cardassigned("green")) |
414 | nicmenu("green"); | |
415 | if (red && !cardassigned("red")) | |
416 | nicmenu("red"); | |
417 | if (blue && !cardassigned("blue")) | |
418 | nicmenu("blue"); | |
419 | if (orange && !cardassigned("orange")) | |
420 | nicmenu("orange"); | |
069680ac | 421 | |
75ae2191 | 422 | // writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); |
069680ac MT |
423 | |
424 | freekeyvalues(kv); | |
069680ac MT |
425 | return 1; |
426 | } | |
427 | ||
75ae2191 | 428 | // Let user change GREEN address. |
069680ac MT |
429 | int greenaddressmenu(void) |
430 | { | |
431 | struct keyvalue *kv = initkeyvalues(); | |
432 | char message[1000]; | |
433 | int rc; | |
434 | ||
435 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
436 | { | |
437 | freekeyvalues(kv); | |
438 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
439 | return 0; | |
440 | } | |
441 | ||
442 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
443 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); | |
444 | ||
445 | if (rc == 0 || rc == 1) | |
446 | { | |
447 | if (changeaddress(kv, "GREEN", 0, "")) | |
448 | { | |
449 | netaddresschange = 1; | |
450 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
451 | writehostsfiles(); | |
452 | } | |
453 | } | |
454 | ||
455 | freekeyvalues(kv); | |
456 | ||
457 | return 0; | |
458 | } | |
459 | ||
75ae2191 | 460 | // They can change BLUE, ORANGE and GREEN too :) |
069680ac MT |
461 | int addressesmenu(void) |
462 | { | |
463 | struct keyvalue *kv = initkeyvalues(); | |
464 | struct keyvalue *mainkv = initkeyvalues(); | |
465 | int rc = 0; | |
466 | char *sections[5]; | |
467 | char *green = "GREEN"; | |
468 | char *orange = "ORANGE"; | |
469 | char *blue = "BLUE"; | |
470 | char *red = "RED"; | |
471 | int c = 0; | |
472 | char greenaddress[STRING_SIZE]; | |
473 | char oldgreenaddress[STRING_SIZE]; | |
474 | char temp[STRING_SIZE]; | |
475 | char temp2[STRING_SIZE]; | |
476 | char message[1000]; | |
477 | int configtype; | |
478 | int done; | |
479 | int choice; | |
480 | char hostname[STRING_SIZE]; | |
481 | ||
482 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
483 | { | |
484 | freekeyvalues(kv); | |
485 | freekeyvalues(mainkv); | |
486 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
487 | return 0; | |
488 | } | |
489 | if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) | |
490 | { | |
491 | freekeyvalues(kv); | |
492 | freekeyvalues(mainkv); | |
493 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
494 | return 0; | |
495 | } | |
496 | ||
497 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
498 | configtype = atol(temp); | |
499 | ||
500 | sections[c] = green; | |
501 | c++; | |
502 | if (HAS_BLUE) | |
503 | { | |
504 | sections[c] = blue; | |
505 | c++; | |
506 | } | |
507 | if (HAS_ORANGE) | |
508 | { | |
509 | sections[c] = orange; | |
510 | c++; | |
511 | } | |
512 | if (HAS_RED) | |
513 | { | |
514 | sections[c] = red; | |
515 | c++; | |
516 | } | |
517 | sections[c] = NULL; | |
518 | ||
519 | choice = 0; | |
520 | done = 0; | |
521 | while (!done) | |
522 | { | |
523 | rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], | |
524 | ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, | |
525 | 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); | |
526 | ||
527 | if (rc == 0 || rc == 1) | |
528 | { | |
529 | if (strcmp(sections[choice], "GREEN") == 0) | |
530 | { | |
531 | findkey(kv, "GREEN_ADDRESS", oldgreenaddress); | |
532 | sprintf(message, ctr[TR_WARNING_LONG], NAME); | |
533 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], | |
534 | message); | |
535 | if (rc == 0 || rc == 1) | |
536 | { | |
537 | if (changeaddress(kv, "GREEN", 0, "")) | |
538 | { | |
539 | netaddresschange = 1; | |
540 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
541 | writehostsfiles(); | |
542 | findkey(kv, "GREEN_ADDRESS", greenaddress); | |
543 | snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); | |
544 | snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); | |
545 | replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); | |
546 | chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); | |
547 | } | |
548 | } | |
549 | } | |
550 | if (strcmp(sections[choice], "BLUE") == 0) | |
551 | { | |
552 | if (changeaddress(kv, "BLUE", 0, "")) | |
553 | netaddresschange = 1; | |
554 | } | |
555 | if (strcmp(sections[choice], "ORANGE") == 0) | |
556 | { | |
557 | if (changeaddress(kv, "ORANGE", 0, "")) | |
558 | netaddresschange = 1; | |
559 | } | |
560 | if (strcmp(sections[choice], "RED") == 0) | |
561 | { | |
562 | strcpy(hostname, ""); | |
563 | findkey(mainkv, "HOSTNAME", hostname); | |
564 | if (changeaddress(kv, "RED", 1, hostname)) | |
565 | netaddresschange = 1; | |
566 | } | |
567 | } | |
568 | else | |
569 | done = 1; | |
570 | } | |
571 | ||
572 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
573 | freekeyvalues(kv); | |
574 | freekeyvalues(mainkv); | |
575 | ||
576 | return 0; | |
577 | } | |
578 | ||
579 | /* DNS and default gateway.... */ | |
580 | int dnsgatewaymenu(void) | |
581 | { | |
582 | struct keyvalue *kv = initkeyvalues(); | |
583 | char message[1000]; | |
584 | char temp[STRING_SIZE] = "0"; | |
585 | struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; | |
586 | char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ | |
587 | int error; | |
588 | int configtype; | |
589 | int rc; | |
590 | ||
591 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
592 | { | |
593 | freekeyvalues(kv); | |
594 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
595 | return 0; | |
596 | } | |
597 | ||
598 | strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); | |
599 | configtype = atol(temp); | |
600 | ||
601 | if (RED_IS_NOT_ETH) | |
602 | { | |
603 | freekeyvalues(kv); | |
604 | errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); | |
605 | return 0; | |
606 | } | |
607 | ||
608 | entries[DNS1].text = ctr[TR_PRIMARY_DNS]; | |
609 | strcpy(temp, ""); findkey(kv, "DNS1", temp); | |
610 | values[DNS1] = strdup(temp); | |
611 | entries[DNS1].value = &values[DNS1]; | |
612 | entries[DNS1].flags = 0; | |
613 | ||
614 | entries[DNS2].text = ctr[TR_SECONDARY_DNS]; | |
615 | strcpy(temp, ""); findkey(kv, "DNS2", temp); | |
616 | values[DNS2] = strdup(temp); | |
617 | entries[DNS2].value = &values[DNS2]; | |
618 | entries[DNS2].flags = 0; | |
619 | ||
620 | entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; | |
621 | strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); | |
622 | values[DEFAULT_GATEWAY] = strdup(temp); | |
623 | entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; | |
624 | entries[DEFAULT_GATEWAY].flags = 0; | |
625 | ||
626 | entries[DNSGATEWAY_TOTAL].text = NULL; | |
627 | entries[DNSGATEWAY_TOTAL].value = NULL; | |
628 | entries[DNSGATEWAY_TOTAL].flags = 0; | |
629 | ||
630 | do | |
631 | { | |
632 | error = 0; | |
633 | ||
634 | rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], | |
635 | ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, | |
636 | ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
637 | if (rc == 0 || rc == 1) | |
638 | { | |
639 | strcpy(message, ctr[TR_INVALID_FIELDS]); | |
640 | if (strlen(values[DNS1])) | |
641 | { | |
642 | if (inet_addr(values[DNS1]) == INADDR_NONE) | |
643 | { | |
644 | strcat(message, ctr[TR_PRIMARY_DNS_CR]); | |
645 | error = 1; | |
646 | } | |
647 | } | |
648 | if (strlen(values[DNS2])) | |
649 | { | |
650 | if (inet_addr(values[DNS2]) == INADDR_NONE) | |
651 | { | |
652 | strcat(message, ctr[TR_SECONDARY_DNS_CR]); | |
653 | error = 1; | |
654 | } | |
655 | } | |
656 | if (strlen(values[DEFAULT_GATEWAY])) | |
657 | { | |
658 | if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) | |
659 | { | |
660 | strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); | |
661 | error = 1; | |
662 | } | |
663 | } | |
664 | if (!strlen(values[DNS1]) && strlen(values[DNS2])) | |
665 | { | |
666 | strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); | |
667 | error = 1; | |
668 | } | |
669 | ||
670 | if (error) | |
671 | errorbox(message); | |
672 | else | |
673 | { | |
674 | replacekeyvalue(kv, "DNS1", values[DNS1]); | |
675 | replacekeyvalue(kv, "DNS2", values[DNS2]); | |
676 | replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); | |
677 | netaddresschange = 1; | |
678 | free(values[DNS1]); | |
679 | free(values[DNS2]); | |
680 | free(values[DEFAULT_GATEWAY]); | |
681 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
682 | } | |
683 | } | |
684 | } | |
685 | while (error); | |
686 | ||
687 | freekeyvalues(kv); | |
688 | ||
689 | return 1; | |
690 | } |