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