]>
Commit | Line | Data |
---|---|---|
8af06406 HS |
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 | * Contains main entry point, and misc functions. | |
8af06406 HS |
8 | * |
9 | */ | |
10 | ||
11 | #include "setup.h" | |
12 | ||
13 | FILE *flog = NULL; | |
14 | char *mylog; | |
15 | ||
16 | char **ctr = NULL; | |
17 | ||
18 | int automode = 0; | |
19 | ||
96ed9998 | 20 | struct nic nics[20] = { { "" , "" , "" , "" } }; |
f9cc0d70 | 21 | struct knic knics[20] = { { "" , "" , "" , "" } }; |
5057b611 | 22 | |
8af06406 | 23 | extern char *en_tr[]; |
8af06406 | 24 | extern char *de_tr[]; |
462515e4 | 25 | extern char *fr_tr[]; |
38a76ff4 | 26 | extern char *es_tr[]; |
b6c9668f | 27 | extern char *pl_tr[]; |
2bb7b134 | 28 | extern char *ru_tr[]; |
8af06406 HS |
29 | |
30 | int main(int argc, char *argv[]) | |
31 | { | |
32 | #ifdef LANG_EN_ONLY | |
33 | char *shortlangnames[] = { "en", NULL }; | |
34 | char **langtrs[] = { en_tr, NULL }; | |
8af06406 | 35 | #else |
2bb7b134 AF |
36 | char *shortlangnames[] = { "de", "en", "fr", "es", "pl", "ru", NULL }; |
37 | char **langtrs[] = { de_tr, en_tr, fr_tr, es_tr, pl_tr, ru_tr, NULL }; | |
8af06406 HS |
38 | #endif |
39 | int choice; | |
40 | char *sections[11]; /* need to fill this out AFTER knowning lang */ | |
41 | int rc; | |
42 | struct keyvalue *kv; | |
43 | char selectedshortlang[STRING_SIZE] = "en"; | |
44 | char title[STRING_SIZE]; | |
45 | int langcounter; | |
46 | int autook = 0; | |
47 | ||
48 | /* Log file/terminal stuff. */ | |
49 | if (argc >= 2) | |
50 | mylog = argv[1]; | |
51 | else | |
069680ac | 52 | mylog = strdup("/var/log/setup.log"); |
8af06406 HS |
53 | |
54 | if (!(flog = fopen(mylog, "w+"))) | |
55 | { | |
56 | printf("Couldn't open log terminal\n"); | |
57 | return 1; | |
58 | } | |
59 | ||
60 | if (argc >= 3) | |
61 | automode = 1; | |
62 | ||
63 | fprintf(flog, "Setup program started.\n"); | |
64 | ||
9b040aa0 HS |
65 | if (!setlocale(LC_CTYPE,"")) |
66 | fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL."); | |
67 | ||
8af06406 HS |
68 | kv = initkeyvalues(); |
69 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) | |
70 | { | |
71 | printf("%s is not properly installed.\n", NAME); | |
72 | return 1; | |
73 | } | |
74 | findkey(kv, "LANGUAGE", selectedshortlang); | |
75 | ||
76 | for (langcounter = 0; langtrs[langcounter]; langcounter++) | |
77 | { | |
78 | if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0) | |
79 | { | |
80 | ctr = langtrs[langcounter]; | |
81 | break; | |
82 | } | |
83 | } | |
84 | ||
85 | if (!ctr) | |
86 | { | |
8af06406 HS |
87 | for (choice = 0; shortlangnames[choice]; choice++) |
88 | { | |
89 | if (strcmp(shortlangnames[choice], "en") == 0) | |
90 | break; | |
91 | } | |
92 | if (!shortlangnames[choice]) | |
93 | goto EXIT; | |
94 | ctr = langtrs[choice]; | |
95 | } | |
96 | ||
97 | sections[0] = ctr[TR_KEYBOARD_MAPPING]; | |
98 | sections[1] = ctr[TR_TIMEZONE]; | |
99 | sections[2] = ctr[TR_HOSTNAME]; | |
100 | sections[3] = ctr[TR_DOMAINNAME]; | |
ca385da6 | 101 | sections[4] = ctr[TR_NETWORKING]; |
bba7212c MT |
102 | sections[5] = ctr[TR_ISDN]; |
103 | sections[6] = ctr[TR_ROOT_PASSWORD]; | |
104 | sections[7] = ctr[TR_ADMIN_PASSWORD]; | |
105 | sections[8] = NULL; | |
8af06406 HS |
106 | |
107 | newtInit(); | |
108 | newtCls(); | |
109 | FILE *f_title; | |
110 | if ((f_title = fopen ("/etc/issue", "r"))) | |
111 | { | |
112 | fgets (title, STRING_SIZE, f_title); | |
113 | if (title[strlen(title) - 1] == '\n') | |
114 | title[strlen(title) - 1] = '\0'; | |
115 | fclose (f_title); | |
116 | } else { | |
069680ac | 117 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); |
8af06406 HS |
118 | } |
119 | newtDrawRootText(14, 0, title); | |
120 | newtPushHelpLine(ctr[TR_HELPLINE]); | |
121 | ||
122 | if (automode == 0) | |
123 | { | |
124 | choice = 0; | |
125 | for (;;) | |
126 | { | |
127 | rc = newtWinMenu(ctr[TR_SECTION_MENU], | |
128 | ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11, | |
129 | sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL); | |
130 | ||
131 | if (rc == 2) | |
132 | break; | |
133 | ||
134 | switch (choice) | |
135 | { | |
136 | case 0: | |
137 | handlekeymap(); | |
138 | break; | |
139 | ||
140 | case 1: | |
141 | handletimezone(); | |
142 | break; | |
143 | ||
144 | case 2: | |
145 | handlehostname(); | |
146 | break; | |
147 | ||
148 | case 3: | |
149 | handledomainname(); | |
150 | break; | |
151 | ||
152 | case 4: | |
8af06406 HS |
153 | handlenetworking(); |
154 | break; | |
bba7212c | 155 | |
ca385da6 | 156 | case 5: |
bba7212c MT |
157 | handleisdn(); |
158 | break; | |
159 | ||
160 | case 6: | |
8af06406 HS |
161 | handlerootpassword(); |
162 | break; | |
163 | ||
bba7212c | 164 | case 7: |
8af06406 HS |
165 | handleadminpassword(); |
166 | break; | |
167 | ||
168 | default: | |
169 | break; | |
170 | } | |
171 | } | |
172 | } | |
173 | else | |
174 | { | |
175 | if (!(handlekeymap())) | |
176 | goto EXIT; | |
177 | if (!(handletimezone())) | |
178 | goto EXIT; | |
179 | if (!(handlehostname())) | |
180 | goto EXIT; | |
181 | if (!(handledomainname())) | |
182 | goto EXIT; | |
71a5950f | 183 | if (!(handlerootpassword())) |
8af06406 | 184 | goto EXIT; |
71a5950f | 185 | if (!(handleadminpassword())) |
bba7212c | 186 | goto EXIT; |
71a5950f | 187 | if (!(handleisdn())) |
8af06406 | 188 | goto EXIT; |
71a5950f | 189 | if (!(handlenetworking())) |
8af06406 | 190 | goto EXIT; |
71a5950f | 191 | if (!(handledhcp())) |
8af06406 HS |
192 | goto EXIT; |
193 | ||
194 | autook = 1; | |
195 | } | |
196 | ||
197 | EXIT: | |
198 | if (automode != 0) | |
199 | { | |
069680ac | 200 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); |
8af06406 HS |
201 | if (autook) |
202 | newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]); | |
203 | else | |
e238e4c2 | 204 | { |
8af06406 | 205 | newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]); |
e238e4c2 | 206 | |
20fa8ccd | 207 | fprintf(flog, "Setup program has not finished.\n"); |
e238e4c2 AF |
208 | fflush(flog); |
209 | fclose(flog); | |
210 | ||
211 | newtFinished(); | |
212 | ||
213 | return 1; | |
214 | } | |
8af06406 | 215 | } |
069680ac | 216 | |
8af06406 HS |
217 | fprintf(flog, "Setup program ended.\n"); |
218 | fflush(flog); | |
219 | fclose(flog); | |
069680ac | 220 | |
8af06406 HS |
221 | newtFinished(); |
222 | ||
223 | return 0; | |
224 | } |