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