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