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