]>
Commit | Line | Data |
---|---|---|
d6aaa55d MT |
1 | /* SmoothWall install 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 | * Contains stuff related to firing up the network card, including a crude | |
8 | * autodector. | |
9 | * | |
d6aaa55d MT |
10 | */ |
11 | ||
12 | #include "install.h" | |
13 | ||
14 | #include <sys/socket.h> | |
15 | #include <netinet/in.h> | |
16 | #include <arpa/inet.h> | |
17 | ||
18 | extern FILE *flog; | |
19 | extern char *mylog; | |
10bc6f06 | 20 | |
d6aaa55d | 21 | extern char **ctr; |
10bc6f06 | 22 | |
d6aaa55d MT |
23 | extern struct nic nics[]; |
24 | ||
25 | int networkmenu(struct keyvalue *ethernetkv) | |
26 | { | |
33634aa8 MT |
27 | int i; |
28 | int count; | |
29 | char nics; | |
30 | char number; | |
31 | char cbValue; | |
d6aaa55d MT |
32 | char driver[STRING_SIZE] = ""; |
33 | char driveroptions[STRING_SIZE] = ""; | |
10bc6f06 | 34 | struct keyvalue *kv = initkeyvalues(); |
d6aaa55d MT |
35 | int result = 0; |
36 | char commandstring[STRING_SIZE]; | |
37 | char address[STRING_SIZE], netmask[STRING_SIZE]; | |
02c629b9 | 38 | FILE *handle; |
d6aaa55d MT |
39 | char description[1000]; |
40 | char message[1000]; | |
41 | char title[STRING_SIZE]; | |
d6aaa55d | 42 | |
33634aa8 MT |
43 | /* Detect and count nics */ |
44 | count = mysystem("/bin/probenic.sh count"); | |
45 | fprintf(flog, "Number of detected nics: %s\n", count); | |
46 | ||
47 | /* sprintf(commandstring, "/bin/probenic.sh"); | |
48 | sprintf(message, ctr[TR_PROBING_FOR_NICS]); | |
49 | runcommandwithstatus(commandstring, message); */ | |
50 | ||
51 | /* handle = fopen("/nicdriver", "r"); | |
52 | fgets(nics, STRING_SIZE, handle); | |
53 | fclose(handle); */ | |
54 | ||
55 | /* fprintf(flog, "Detected NIC drivers: %s\n",driver); */ | |
56 | ||
57 | /* sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
58 | sprintf(message, ctr[TR_FOUND_NIC], NAME, description); | |
59 | newtWinMessage(title, ctr[TR_OK], message); */ | |
60 | ||
61 | newtComponent form, checkbox, rb[count], button; | |
62 | newtOpenWindow(10, 5, 60, 11, "Checkboxes and Radio buttons"); | |
63 | ||
64 | for (i = 1; i <= 2; i++) | |
d6aaa55d | 65 | { |
33634aa8 MT |
66 | fprintf(flog, "Scan: %d\n", i); |
67 | snprintf(commandstring, STRING_SIZE, "/bin/probenic.sh %i", i); | |
68 | mysystem(commandstring); | |
69 | if ((handle = fopen("/nicdriver", "r")) == NULL) { | |
70 | errorbox(ctr[TR_ERROR]); | |
71 | goto EXIT; | |
02c629b9 | 72 | } |
33634aa8 MT |
73 | fgets(driver, STRING_SIZE, handle); |
74 | fclose(handle); | |
75 | findnicdescription(driver, description); | |
76 | if ( i == 0 ) | |
77 | rb[i] = newtRadiobutton(1, i+2, description, 1, NULL); | |
d6aaa55d | 78 | else |
33634aa8 MT |
79 | rb[i] = newtRadiobutton(1, i+2, description, 0, rb[i-1]); |
80 | } | |
81 | ||
82 | button = newtButton(1, count+3, "OK"); | |
83 | ||
84 | form = newtForm(NULL, NULL, 0); | |
85 | newtFormAddComponent(form, checkbox); | |
86 | for (i = 1; i <= 2; i++) { | |
87 | fprintf(flog, "Add: %d\n", i); | |
88 | newtFormAddComponent(form, rb[i]); | |
89 | } | |
90 | newtFormAddComponent(form, button); | |
91 | ||
92 | newtRunForm(form); | |
93 | newtFinished(); | |
94 | ||
95 | for (i = 1; i <= 2; i++) | |
96 | if (newtRadioGetCurrent(rb[0]) == rb[i]) | |
97 | printf("radio button picked: %d\n", i); | |
98 | newtFormDestroy(form); | |
99 | ||
100 | ||
101 | /* snprintf(commandstring, STRING_SIZE, "/bin/probenic.sh 1"); | |
102 | mysystem(commandstring); | |
103 | if ((handle = fopen("/nicdriver", "r")) == NULL) { | |
104 | errorbox(ctr[TR_ERROR]); | |
105 | goto EXIT; | |
d6aaa55d | 106 | } |
33634aa8 MT |
107 | fgets(driver, STRING_SIZE, handle); |
108 | fprintf(flog, "Green nic driver: %s\n", driver); | |
109 | fclose(handle); */ | |
d6aaa55d MT |
110 | |
111 | /* Default is a GREEN nic only. */ | |
112 | /* Smoothie is not untarred yet, so we have to delay actually writing the | |
113 | * settings till later. */ | |
114 | replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0"); | |
115 | replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver); | |
116 | replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions); | |
117 | replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0"); | |
118 | replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver); | |
119 | ||
120 | if (!(changeaddress(ethernetkv, "GREEN", 0, ""))) | |
121 | goto EXIT; | |
122 | ||
123 | strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address); | |
124 | strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask); | |
125 | ||
126 | snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up", | |
127 | address, netmask); | |
128 | if (mysystem(commandstring)) | |
129 | { | |
130 | errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]); | |
131 | goto EXIT; | |
132 | } | |
133 | ||
134 | result = 1; | |
135 | ||
136 | EXIT: | |
10bc6f06 | 137 | freekeyvalues(kv); |
d6aaa55d MT |
138 | |
139 | return result; | |
140 | } | |
141 |