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