]>
Commit | Line | Data |
---|---|---|
9607771a MT |
1 | /* SmoothWall libsmooth. |
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 | * Contains network library functions. | |
8 | * | |
9607771a MT |
9 | */ |
10 | ||
11 | #include "libsmooth.h" | |
12 | #include <signal.h> | |
13 | ||
14 | extern FILE *flog; | |
15 | extern char *mylog; | |
16 | ||
17 | extern char **ctr; | |
18 | ||
5057b611 HS |
19 | extern struct nic nics[]; |
20 | extern struct knic knics[]; | |
21 | ||
9b040aa0 HS |
22 | char *ucolourcard[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL }; |
23 | char *lcolourcard[] = { "green", "red", "orange", "blue", NULL }; | |
24 | ||
5057b611 HS |
25 | int scanned_nics_read_done = 0; |
26 | ||
9607771a MT |
27 | newtComponent networkform; |
28 | newtComponent addressentry; | |
29 | newtComponent netmaskentry; | |
30 | newtComponent statictyperadio; | |
31 | newtComponent dhcptyperadio; | |
32 | newtComponent pppoetyperadio; | |
33 | newtComponent pptptyperadio; | |
34 | newtComponent dhcphostnameentry; | |
35 | ||
36 | /* acceptable character filter for IP and netmaks entry boxes */ | |
37 | static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor) | |
38 | { | |
39 | if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '\r' || ch >= NEWT_KEY_EXTRA_BASE) | |
40 | return ch; | |
41 | return 0; | |
42 | } | |
43 | ||
44 | /* This is a groovie dialog for showing network info. Takes a keyvalue list, | |
45 | * a colour and a dhcp flag. Shows the current settings, and rewrites them | |
46 | * if necessary. DHCP flag sets wether to show the dhcp checkbox. */ | |
47 | int changeaddress(struct keyvalue *kv, char *colour, int typeflag, | |
48 | char *defaultdhcphostname) | |
49 | { | |
50 | char *addressresult; | |
51 | char *netmaskresult; | |
52 | char *dhcphostnameresult; | |
53 | struct newtExitStruct es; | |
54 | newtComponent header; | |
55 | newtComponent addresslabel; | |
56 | newtComponent netmasklabel; | |
57 | newtComponent dhcphostnamelabel; | |
58 | newtComponent ok, cancel; | |
59 | char message[1000]; | |
60 | char temp[STRING_SIZE]; | |
61 | char addressfield[STRING_SIZE]; | |
62 | char netmaskfield[STRING_SIZE]; | |
63 | char typefield[STRING_SIZE]; | |
64 | char dhcphostnamefield[STRING_SIZE]; | |
65 | int error; | |
66 | int result = 0; | |
67 | char type[STRING_SIZE]; | |
68 | int startstatictype = 0; | |
69 | int startdhcptype = 0; | |
70 | int startpppoetype = 0; | |
71 | int startpptptype = 0; | |
72 | ||
73 | /* Build some key strings. */ | |
74 | sprintf(addressfield, "%s_ADDRESS", colour); | |
75 | sprintf(netmaskfield, "%s_NETMASK", colour); | |
76 | sprintf(typefield, "%s_TYPE", colour); | |
77 | sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour); | |
78 | ||
79 | sprintf(message, ctr[TR_INTERFACE], colour); | |
80 | newtCenteredWindow(44, (typeflag ? 18 : 12), message); | |
81 | ||
82 | networkform = newtForm(NULL, NULL, 0); | |
83 | ||
84 | sprintf(message, ctr[TR_ENTER_THE_IP_ADDRESS_INFORMATION], colour); | |
85 | header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0); | |
86 | newtFormAddComponent(networkform, header); | |
87 | ||
88 | /* See if we need a dhcp checkbox. If we do, then we shift the contents | |
89 | * of the window down two rows to make room. */ | |
90 | if (typeflag) | |
91 | { | |
92 | strcpy(temp, "STATIC"); findkey(kv, typefield, temp); | |
93 | if (strcmp(temp, "STATIC") == 0) startstatictype = 1; | |
94 | if (strcmp(temp, "DHCP") == 0) startdhcptype = 1; | |
95 | if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1; | |
96 | if (strcmp(temp, "PPTP") == 0) startpptptype = 1; | |
97 | statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL); | |
98 | dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio); | |
99 | pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio); | |
100 | pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio); | |
101 | newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, | |
102 | pppoetyperadio, pptptyperadio, NULL); | |
103 | newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL); | |
104 | newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL); | |
105 | newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL); | |
106 | newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL); | |
107 | dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0); | |
108 | newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]); | |
109 | strcpy(temp, defaultdhcphostname); | |
110 | findkey(kv, dhcphostnamefield, temp); | |
111 | dhcphostnameentry = newtEntry(20, 9, temp, 20, &dhcphostnameresult, 0); | |
112 | newtFormAddComponent(networkform, dhcphostnamelabel); | |
113 | newtFormAddComponent(networkform, dhcphostnameentry); | |
114 | if (startdhcptype == 0) | |
115 | newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); | |
116 | } | |
117 | /* Address */ | |
118 | addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0); | |
119 | newtTextboxSetText(addresslabel, ctr[TR_IP_ADDRESS_PROMPT]); | |
120 | strcpy(temp, ""); | |
121 | findkey(kv, addressfield, temp); | |
122 | addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0); | |
123 | newtEntrySetFilter(addressentry, ip_input_filter, NULL); | |
124 | if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 ) | |
125 | newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); | |
126 | newtFormAddComponent(networkform, addresslabel); | |
127 | newtFormAddComponent(networkform, addressentry); | |
128 | ||
129 | /* Netmask */ | |
130 | netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0); | |
131 | newtTextboxSetText(netmasklabel, ctr[TR_NETMASK_PROMPT]); | |
132 | strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp); | |
133 | netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0); | |
134 | newtEntrySetFilter(netmaskentry, ip_input_filter, NULL); | |
135 | if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 ) | |
136 | newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); | |
137 | ||
138 | newtFormAddComponent(networkform, netmasklabel); | |
139 | newtFormAddComponent(networkform, netmaskentry); | |
140 | ||
141 | /* Buttons. */ | |
142 | ok = newtButton(8, (typeflag ? 14 : 7), ctr[TR_OK]); | |
143 | cancel = newtButton(26, (typeflag ? 14 : 7), ctr[TR_CANCEL]); | |
144 | ||
145 | newtFormAddComponents(networkform, ok, cancel, NULL); | |
146 | ||
147 | newtRefresh(); | |
148 | newtDrawForm(networkform); | |
149 | ||
150 | do | |
151 | { | |
152 | error = 0; | |
153 | newtFormRun(networkform, &es); | |
154 | ||
155 | if (es.u.co == ok) | |
156 | { | |
157 | /* OK was pressed; verify the contents of each entry. */ | |
158 | strcpy(message, ctr[TR_INVALID_FIELDS]); | |
159 | ||
160 | strcpy(type, "STATIC"); | |
161 | if (typeflag) | |
162 | gettype(type); | |
163 | if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 ) | |
164 | { | |
165 | if (inet_addr(addressresult) == INADDR_NONE) | |
166 | { | |
167 | strcat(message, ctr[TR_IP_ADDRESS_CR]); | |
168 | error = 1; | |
169 | } | |
170 | if (inet_addr(netmaskresult) == INADDR_NONE) | |
171 | { | |
172 | strcat(message, ctr[TR_NETWORK_MASK_CR]); | |
173 | error = 1; | |
174 | } | |
175 | } | |
176 | if (strcmp(type, "DHCP") == 0) | |
177 | { | |
178 | if (!strlen(dhcphostnameresult)) | |
179 | { | |
180 | strcat(message, ctr[TR_DHCP_HOSTNAME_CR]); | |
181 | error = 1; | |
182 | } | |
183 | } | |
184 | if (error) | |
185 | errorbox(message); | |
186 | else | |
187 | { | |
188 | /* No errors! Set new values, depending on dhcp flag etc. */ | |
189 | if (typeflag) | |
190 | { | |
191 | replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult); | |
192 | if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0) | |
193 | { | |
194 | replacekeyvalue(kv, addressfield, "0.0.0.0"); | |
195 | replacekeyvalue(kv, netmaskfield, "0.0.0.0"); | |
196 | } | |
197 | else | |
198 | { | |
199 | replacekeyvalue(kv, addressfield, addressresult); | |
200 | replacekeyvalue(kv, netmaskfield, netmaskresult); | |
201 | } | |
202 | replacekeyvalue(kv, typefield, type); | |
203 | } | |
204 | else | |
205 | { | |
206 | replacekeyvalue(kv, addressfield, addressresult); | |
207 | replacekeyvalue(kv, netmaskfield, netmaskresult); | |
208 | } | |
209 | ||
210 | setnetaddress(kv, colour); | |
211 | result = 1; | |
212 | } | |
213 | } | |
214 | } | |
215 | while (error); | |
216 | ||
217 | newtFormDestroy(networkform); | |
218 | newtPopWindow(); | |
219 | ||
220 | return result; | |
221 | } | |
222 | ||
223 | /* for pppoe: return string thats type STATIC, DHCP or PPPOE */ | |
224 | int gettype(char *type) | |
225 | { | |
226 | newtComponent selected = newtRadioGetCurrent(statictyperadio); | |
227 | ||
228 | if (selected == statictyperadio) | |
229 | strcpy(type, "STATIC"); | |
230 | else if (selected == dhcptyperadio) | |
231 | strcpy(type, "DHCP"); | |
232 | else if (selected == pppoetyperadio) | |
233 | strcpy(type, "PPPOE"); | |
234 | else if (selected == pptptyperadio) | |
235 | strcpy(type, "PPTP"); | |
236 | else | |
237 | strcpy(type, "ERROR"); | |
238 | ||
239 | return 0; | |
240 | } | |
241 | ||
242 | /* 0.9.9: calculates broadcast too. */ | |
243 | int setnetaddress(struct keyvalue *kv, char *colour) | |
244 | { | |
245 | char addressfield[STRING_SIZE]; | |
246 | char netaddressfield[STRING_SIZE]; | |
247 | char netmaskfield[STRING_SIZE]; | |
248 | char broadcastfield[STRING_SIZE]; | |
249 | char address[STRING_SIZE]; | |
250 | char netmask[STRING_SIZE]; | |
251 | unsigned long int intaddress; | |
252 | unsigned long int intnetaddress; | |
253 | unsigned long int intnetmask; | |
254 | unsigned long int intbroadcast; | |
255 | struct in_addr temp; | |
256 | char *netaddress; | |
257 | char *broadcast; | |
258 | ||
259 | /* Build some key strings. */ | |
260 | sprintf(addressfield, "%s_ADDRESS", colour); | |
261 | sprintf(netaddressfield, "%s_NETADDRESS", colour); | |
262 | sprintf(netmaskfield, "%s_NETMASK", colour); | |
263 | sprintf(broadcastfield, "%s_BROADCAST", colour); | |
264 | ||
265 | strcpy(address, ""); findkey(kv, addressfield, address); | |
266 | strcpy(netmask, ""); findkey(kv, netmaskfield, netmask); | |
267 | ||
268 | /* Calculate netaddress. Messy.. */ | |
269 | intaddress = inet_addr(address); | |
270 | intnetmask = inet_addr(netmask); | |
271 | ||
272 | intnetaddress = intaddress & intnetmask; | |
273 | temp.s_addr = intnetaddress; | |
274 | netaddress = inet_ntoa(temp); | |
275 | ||
276 | replacekeyvalue(kv, netaddressfield, netaddress); | |
277 | ||
278 | intbroadcast = intnetaddress | ~intnetmask; | |
279 | temp.s_addr = intbroadcast; | |
280 | broadcast = inet_ntoa(temp); | |
281 | ||
282 | replacekeyvalue(kv, broadcastfield, broadcast); | |
283 | ||
284 | return 1; | |
285 | } | |
286 | ||
287 | /* Called when dhcp flag is toggled. Toggle disabled state of other 3 | |
288 | * controls. */ | |
289 | void networkdialogcallbacktype(newtComponent cm, void *data) | |
290 | { | |
291 | char type[STRING_SIZE]; | |
292 | ||
293 | gettype(type); | |
294 | ||
295 | if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0 ) | |
296 | { | |
297 | newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); | |
298 | newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); | |
299 | } | |
300 | else | |
301 | { | |
302 | newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); | |
303 | newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); | |
304 | } | |
305 | if (strcmp(type, "DHCP") == 0) | |
306 | newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); | |
307 | else | |
308 | newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); | |
309 | ||
310 | newtRefresh(); | |
311 | newtDrawForm(networkform); | |
312 | } | |
313 | ||
314 | int interfacecheck(struct keyvalue *kv, char *colour) | |
315 | { | |
316 | char temp[STRING_SIZE]; | |
317 | char colourfields[NETCHANGE_TOTAL][STRING_SIZE]; | |
318 | int c; | |
319 | ||
320 | sprintf(colourfields[ADDRESS], "%s_ADDRESS", colour); | |
321 | sprintf(colourfields[NETADDRESS], "%s_NETADDRESS", colour); | |
322 | sprintf(colourfields[NETMASK], "%s_NETMASK", colour); | |
323 | ||
324 | for (c = 0; c < 3; c++) | |
325 | { | |
326 | strcpy(temp, ""); findkey(kv, colourfields[c], temp); | |
327 | if (!(strlen(temp))) return 0; | |
328 | } | |
329 | return 1; | |
330 | } | |
9607771a MT |
331 | |
332 | /* Funky routine for loading all drivers (cept those are already loaded.). */ | |
f9cc0d70 | 333 | int probecards(char *driver, char *driveroptions ) |
9607771a | 334 | { |
75ae2191 MT |
335 | return 0; |
336 | } | |
b4e381a8 | 337 | |
5057b611 | 338 | /* ### alter strupper ### |
75ae2191 MT |
339 | char *strupper(char *s) |
340 | { | |
341 | int n; | |
342 | for (n=0;s[n];n++) s[n]=toupper(s[n]); | |
343 | return s; | |
344 | } | |
5057b611 | 345 | */ |
b4e381a8 | 346 | |
5057b611 HS |
347 | /* neuer StringUpper, wird zur Zeit nicht benutzt da UTF-8 nicht geht. |
348 | void strupper(unsigned char *string) | |
349 | { | |
350 | unsigned char *str; | |
351 | for (str = string; *str != '\0'; str++) | |
352 | if (!(*str & 0x80) && islower(*str)) | |
353 | *str = toupper(*str); | |
354 | } | |
355 | */ | |
9607771a | 356 | |
b04331d3 | 357 | /* int ismacaddr(char *ismac) |
d10e55d1 | 358 | { |
b04331d3 HS |
359 | char *a; |
360 | fprintf(flog,"Check is MAC true\n"); // #### Debug #### | |
361 | for (a = ismac; *a; a++) { | |
362 | sprintf(flog,"%c\n", *a); // #### Debug #### | |
d10e55d1 | 363 | if (*a != ':' && !isxdigit(*a)) return 0; // is int != ':' or not hexdigit then exit |
b04331d3 | 364 | } |
d10e55d1 HS |
365 | return 1; |
366 | } | |
b04331d3 | 367 | */ |
d10e55d1 | 368 | |
f9cc0d70 | 369 | int write_configs_netudev(int card , int colour) |
75ae2191 MT |
370 | { |
371 | #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules" | |
75ae2191 MT |
372 | FILE *fp; |
373 | char commandstring[STRING_SIZE]; | |
374 | struct keyvalue *kv = initkeyvalues(); | |
375 | char temp1[STRING_SIZE], temp2[STRING_SIZE], temp3[STRING_SIZE]; | |
376 | char ucolour[STRING_SIZE]; | |
5057b611 HS |
377 | |
378 | // sprintf(ucolour, colour); | |
379 | // strupper(ucolour); | |
380 | ||
9b040aa0 | 381 | sprintf(ucolour, ucolourcard[colour]); |
f9cc0d70 HS |
382 | strcpy(knics[colour].driver, nics[card].driver); |
383 | strcpy(knics[colour].description, nics[card].description); | |
384 | strcpy(knics[colour].macaddr, nics[card].macaddr); | |
9b040aa0 | 385 | |
75ae2191 | 386 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
b4e381a8 | 387 | { |
75ae2191 MT |
388 | freekeyvalues(kv); |
389 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
390 | return 0; | |
b4e381a8 | 391 | } |
9607771a | 392 | |
75ae2191 MT |
393 | sprintf(temp1, "%s_DEV", ucolour); |
394 | sprintf(temp2, "%s_MACADDR", ucolour); | |
9b040aa0 | 395 | sprintf(temp3, "%s0", lcolourcard[colour]); |
75ae2191 | 396 | replacekeyvalue(kv, temp1, temp3); |
f9cc0d70 | 397 | replacekeyvalue(kv, temp2, nics[card].macaddr); |
5057b611 | 398 | sprintf(temp1, "%s_DESCRIPTION", ucolour); |
f9cc0d70 HS |
399 | replacekeyvalue(kv, temp1, nics[card].description); |
400 | sprintf(temp1, "%s_DRIVER", ucolour); | |
401 | replacekeyvalue(kv, temp1, nics[card].driver); | |
75ae2191 MT |
402 | |
403 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
404 | freekeyvalues(kv); | |
9607771a | 405 | |
75ae2191 MT |
406 | // Make sure that there is no conflict |
407 | snprintf(commandstring, STRING_SIZE, "/usr/bin/touch "UDEV_NET_CONF" >/dev/null 2>&1"); | |
5057b611 HS |
408 | system(commandstring); |
409 | ||
9b040aa0 HS |
410 | // snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF" | /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", macaddr); |
411 | // system(commandstring); | |
5057b611 | 412 | |
9b040aa0 | 413 | snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF" | /bin/grep -v \"%s0\" > "UDEV_NET_CONF" 2>/dev/null", lcolourcard[colour]); |
75ae2191 MT |
414 | system(commandstring); |
415 | ||
416 | if( (fp = fopen(UDEV_NET_CONF, "a")) == NULL ) | |
9607771a | 417 | { |
75ae2191 MT |
418 | fprintf(stderr,"Couldn't open" UDEV_NET_CONF); |
419 | return 1; | |
9607771a | 420 | } |
f9cc0d70 | 421 | fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", nics[card].macaddr, lcolourcard[colour], nics[card].description); |
75ae2191 | 422 | fclose(fp); |
9607771a | 423 | |
75ae2191 MT |
424 | return 0; |
425 | } | |
426 | ||
5057b611 | 427 | int scan_network_cards(void) |
75ae2191 | 428 | { |
5057b611 | 429 | FILE *fp; |
f9cc0d70 | 430 | char driver[STRING_SIZE], description[STRING_SIZE], macaddr[STRING_SIZE], temp_line[STRING_SIZE]; |
5057b611 | 431 | int count = 0; |
b04331d3 HS |
432 | const char _driver[]="driver: "; |
433 | const char _desc[]="desc: "; | |
434 | const char _network_hwaddr[]="network.hwaddr: "; | |
5057b611 HS |
435 | |
436 | if (!(scanned_nics_read_done)) | |
437 | { | |
438 | fprintf(flog,"Enter scan_network_cards\n"); // #### Debug #### | |
439 | mysystem("/bin/probenic.sh"); | |
440 | // Read our scanned nics | |
441 | if( (fp = fopen(SCANNED_NICS, "r")) == NULL ) | |
442 | { | |
443 | fprintf(stderr,"Couldn't open "SCANNED_NICS); | |
444 | return 1; | |
445 | } | |
446 | while (fgets(temp_line, STRING_SIZE, fp) != NULL) | |
447 | { | |
b04331d3 HS |
448 | temp_line[strlen(temp_line) -1] = 0; |
449 | if ( strncmp(temp_line, _driver, strlen(_driver)) == 0 ) sprintf(nics[count].driver, "%s", temp_line+strlen(_driver)); | |
450 | if ( strncmp(temp_line, _desc, strlen(_desc)) == 0 ) sprintf(nics[count].description, "%s", temp_line+strlen(_desc)); | |
451 | if ( strncmp(temp_line, _network_hwaddr, strlen(_network_hwaddr)) == 0 ) sprintf(nics[count].macaddr, "%s", temp_line+strlen(_network_hwaddr)); | |
452 | if (strlen(nics[count].macaddr) > 15 ) count++; | |
5057b611 HS |
453 | } |
454 | fclose(fp); | |
9b040aa0 HS |
455 | scanned_nics_read_done = count; |
456 | } else fprintf(flog,"Scan Networkcards does read.\n"); | |
457 | return scanned_nics_read_done; | |
5057b611 | 458 | } |
75ae2191 | 459 | |
5057b611 HS |
460 | |
461 | ||
9b040aa0 | 462 | int nicmenu(int colour) |
5057b611 HS |
463 | { |
464 | int rc, choise = 0, count = 0, kcount = 0, mcount = 0, i, j, nic_in_use; | |
465 | int found_NIC_as_Card[4]; | |
466 | char message[STRING_SIZE]; | |
467 | ||
468 | char cMenuInhalt[STRING_SIZE]; | |
469 | char MenuInhalt[20][180]; | |
470 | char *pMenuInhalt[20]; | |
471 | ||
472 | // strcpy( message , pnics[count].macaddr); | |
473 | // while (strcmp(message, "")) { | |
474 | // count++; | |
475 | // strcpy( message , pnics[count].macaddr); | |
476 | // } | |
477 | ||
478 | while (strcmp(nics[count].macaddr, "")) count++; // 2 find how many nics in system | |
479 | for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; // loop to find all knowing nics | |
480 | fprintf(flog, "Enter NicMenu\n"); // #### Debug #### | |
481 | fprintf(flog, "count nics %i\ncount knics %i\n", count, kcount); // #### Debug #### | |
482 | ||
483 | // If new nics are found... | |
484 | if (count > kcount) { | |
485 | for (i=0 ; i < count ; i++) | |
486 | { | |
487 | nic_in_use = 0; | |
488 | for (j=0 ; j <= kcount ; j++) { | |
489 | if (strcmp(nics[ i ].macaddr, knics[ j ].macaddr) == 0 ) { | |
490 | nic_in_use = 1; | |
491 | fprintf(flog,"NIC \"%s\" is in use.\n", nics[ i ].macaddr); // #### Debug #### | |
492 | break; | |
9607771a | 493 | } |
9607771a | 494 | } |
5057b611 HS |
495 | if (!(nic_in_use)) { |
496 | fprintf(flog,"NIC \"%s\" is free.\n", nics[ i ].macaddr); // #### Debug #### | |
497 | if ( strlen(nics[i].description) < 55 ) | |
498 | sprintf(MenuInhalt[mcount], "%.*s", strlen(nics[i].description)-2, nics[i].description+1); | |
499 | else { | |
d10e55d1 | 500 | fprintf(flog,"Modify string 4 display.\n"); // #### Debug #### |
5057b611 | 501 | sprintf(cMenuInhalt, "%.50s", nics[i].description + 1); |
b04331d3 | 502 | fprintf(flog,"1: %s\n"); // #### Debug #### |
d10e55d1 | 503 | // strncpy(MenuInhalt[mcount], cMenuInhalt,(strrchr(cMenuInhalt,' ') - cMenuInhalt)); |
b04331d3 HS |
504 | // sprintf(MenuInhalt[mcount], "%.*s", strlen(strrchr(cMenuInhalt,' ')), cMenuInhalt); |
505 | strrchr(cMenuInhalt,' '); | |
506 | sprintf(MenuInhalt[mcount], cMenuInhalt); | |
5057b611 | 507 | strcat (MenuInhalt[mcount], "..."); |
75ae2191 | 508 | } |
9607771a | 509 | |
b04331d3 | 510 | while ( strlen(MenuInhalt[mcount]) < 53) strcat(MenuInhalt[mcount], " "); // Fill with space. |
5057b611 HS |
511 | |
512 | strcat(MenuInhalt[mcount], " ("); | |
513 | strcat(MenuInhalt[mcount], nics[i].macaddr); | |
514 | strcat(MenuInhalt[mcount], ")"); | |
515 | pMenuInhalt[mcount] = MenuInhalt[mcount]; | |
516 | found_NIC_as_Card[mcount]=i; | |
517 | mcount++; | |
518 | } | |
75ae2191 | 519 | } |
5057b611 HS |
520 | |
521 | pMenuInhalt[mcount] = NULL; | |
522 | ||
523 | // sprintf(message, "Es wurde(n) %d freie Netzwerkkarte(n) in Ihrem System gefunden.\nBitte waehlen Sie im naechsten Dialog eine davon aus.\n", count); | |
524 | // newtWinMessage("NetcardMenu", ctr[TR_OK], message); | |
525 | ||
9b040aa0 | 526 | sprintf(message, "(TR) Bitte wählen Sie eine der untenstehenden Netzwerkkarten fuer die Schnittstelle \"%s\" aus.\n", ucolourcard[colour]); |
5057b611 HS |
527 | rc = newtWinMenu("(TR) NetcardMenu2", message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_OK], ctr[TR_SELECT], ctr[TR_CANCEL], NULL); |
528 | ||
529 | if ( rc == 0 || rc == 1) { | |
f9cc0d70 | 530 | write_configs_netudev(found_NIC_as_Card[choise], colour); |
5057b611 HS |
531 | } else if (rc == 2) { |
532 | // manualdriver("pcnet32",""); | |
533 | } | |
534 | return 0; | |
535 | } else { | |
536 | // We have to add here that you can manually add a device | |
537 | errorbox("(TR) Es wurden leider keine freien Netzwerkkarten fuer die Schnittstelle in ihrem System gefunden."); | |
538 | return 1; | |
539 | } | |
540 | } | |
541 | ||
9b040aa0 | 542 | int clear_card_entry(int card) |
5057b611 HS |
543 | { |
544 | struct keyvalue *kv = initkeyvalues(); | |
9b040aa0 | 545 | char temp[STRING_SIZE]; |
5057b611 | 546 | |
5057b611 HS |
547 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) |
548 | { | |
549 | freekeyvalues(kv); | |
550 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); | |
551 | return 0; | |
552 | } | |
553 | ||
f9cc0d70 | 554 | strcpy(knics[card].driver, ""); |
9b040aa0 HS |
555 | strcpy(knics[card].description, ctr[TR_UNSET]); |
556 | strcpy(knics[card].macaddr, ""); | |
557 | strcpy(knics[card].colour, ""); | |
f9cc0d70 HS |
558 | sprintf(temp, "%s_DRIVER", ucolourcard[card]); |
559 | replacekeyvalue(kv, temp, ""); | |
9b040aa0 HS |
560 | sprintf(temp, "%s_DEV", ucolourcard[card]); |
561 | replacekeyvalue(kv, temp, ""); | |
562 | sprintf(temp, "%s_MACADDR", ucolourcard[card]); | |
563 | replacekeyvalue(kv, temp, ""); | |
564 | sprintf(temp, "%s_DESCRIPTION", ucolourcard[card]); | |
565 | replacekeyvalue(kv, temp, ""); | |
566 | ||
567 | writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
568 | freekeyvalues(kv); | |
569 | ||
570 | fprintf(flog,"Card \"%s\" cleared\n",ucolourcard[card]); // #### Debug #### | |
571 | return 0; | |
572 | } | |
573 | ||
574 | int ask_clear_card_entry(int card) | |
575 | { | |
576 | char message[STRING_SIZE]; | |
577 | int rc; | |
5057b611 | 578 | |
9b040aa0 | 579 | sprintf(message, "(TR) Soll die Zuordnung der Netzwerkkarte \"%s\" entfernt werden ?\n", ucolourcard[card]); |
5057b611 HS |
580 | rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); |
581 | ||
582 | if ( rc = 0 || rc == 1) { | |
9b040aa0 HS |
583 | clear_card_entry(card); |
584 | // sprintf(temp1, "%s_DEV", ucolour); | |
585 | // sprintf(temp2, "%s_MACADDR", ucolour); | |
586 | // replacekeyvalue(kv, temp1, ""); | |
587 | // replacekeyvalue(kv, temp2, ""); | |
588 | // sprintf(temp1, "%s_DESCRIPTION", ucolour); | |
589 | // replacekeyvalue(kv, temp1, ""); | |
590 | ||
591 | // writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); | |
5057b611 HS |
592 | } else return 1; |
593 | ||
5057b611 | 594 | return 0; |
9607771a MT |
595 | } |
596 | ||
597 | /* Manual entry for gurus. */ | |
598 | int manualdriver(char *driver, char *driveroptions) | |
599 | { | |
600 | char *values[] = { NULL, NULL }; /* pointers for the values. */ | |
601 | struct newtWinEntry entries[] = | |
602 | { { "", &values[0], 0,}, { NULL, NULL, 0 } }; | |
603 | int rc; | |
604 | char commandstring[STRING_SIZE]; | |
605 | char *driverend; | |
606 | ||
607 | strcpy(driver, ""); | |
608 | strcpy(driveroptions, ""); | |
609 | ||
610 | rc = newtWinEntries(ctr[TR_SELECT_NETWORK_DRIVER], | |
611 | ctr[TR_MODULE_PARAMETERS], 50, 5, 5, 40, entries, | |
612 | ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
613 | if (rc == 0 || rc == 1) | |
614 | { | |
615 | if (strlen(values[0])) | |
616 | { | |
617 | sprintf(commandstring, "/sbin/modprobe %s", values[0]); | |
618 | if (runcommandwithstatus(commandstring, ctr[TR_LOADING_MODULE]) == 0) | |
619 | { | |
620 | if ((driverend = strchr(values[0], ' '))) | |
621 | { | |
622 | *driverend = '\0'; | |
623 | strcpy(driver, values[0]); | |
624 | strcpy(driveroptions, driverend + 1); | |
625 | } | |
626 | else | |
627 | { | |
628 | strcpy(driver, values[0]); | |
629 | strcpy(driveroptions, ""); | |
630 | } | |
631 | } | |
632 | else | |
633 | errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]); | |
634 | } | |
635 | else | |
636 | errorbox(ctr[TR_MODULE_NAME_CANNOT_BE_BLANK]); | |
637 | } | |
638 | free(values[0]); | |
639 | ||
640 | return 1; | |
641 | } |