]>
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 | ||
e1457ba0 MT |
11 | // Translation |
12 | #include <libintl.h> | |
13 | #define _(x) dgettext("setup", x) | |
14 | ||
8af06406 HS |
15 | #include "setup.h" |
16 | ||
17 | FILE *flog = NULL; | |
18 | char *mylog; | |
19 | ||
8af06406 HS |
20 | int automode = 0; |
21 | ||
96ed9998 | 22 | struct nic nics[20] = { { "" , "" , "" , "" } }; |
f9cc0d70 | 23 | struct knic knics[20] = { { "" , "" , "" , "" } }; |
5057b611 | 24 | |
8af06406 HS |
25 | int main(int argc, char *argv[]) |
26 | { | |
8af06406 HS |
27 | int choice; |
28 | char *sections[11]; /* need to fill this out AFTER knowning lang */ | |
29 | int rc; | |
30 | struct keyvalue *kv; | |
31 | char selectedshortlang[STRING_SIZE] = "en"; | |
32 | char title[STRING_SIZE]; | |
33 | int langcounter; | |
34 | int autook = 0; | |
35 | ||
36 | /* Log file/terminal stuff. */ | |
37 | if (argc >= 2) | |
38 | mylog = argv[1]; | |
39 | else | |
069680ac | 40 | mylog = strdup("/var/log/setup.log"); |
8af06406 HS |
41 | |
42 | if (!(flog = fopen(mylog, "w+"))) | |
43 | { | |
44 | printf("Couldn't open log terminal\n"); | |
45 | return 1; | |
46 | } | |
47 | ||
48 | if (argc >= 3) | |
49 | automode = 1; | |
50 | ||
51 | fprintf(flog, "Setup program started.\n"); | |
52 | ||
9b040aa0 HS |
53 | if (!setlocale(LC_CTYPE,"")) |
54 | fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL."); | |
55 | ||
e1457ba0 | 56 | #if 0 |
8af06406 HS |
57 | kv = initkeyvalues(); |
58 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) | |
59 | { | |
60 | printf("%s is not properly installed.\n", NAME); | |
61 | return 1; | |
62 | } | |
63 | findkey(kv, "LANGUAGE", selectedshortlang); | |
64 | ||
65 | for (langcounter = 0; langtrs[langcounter]; langcounter++) | |
66 | { | |
67 | if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0) | |
68 | { | |
69 | ctr = langtrs[langcounter]; | |
70 | break; | |
71 | } | |
72 | } | |
73 | ||
74 | if (!ctr) | |
75 | { | |
8af06406 HS |
76 | for (choice = 0; shortlangnames[choice]; choice++) |
77 | { | |
78 | if (strcmp(shortlangnames[choice], "en") == 0) | |
79 | break; | |
80 | } | |
81 | if (!shortlangnames[choice]) | |
82 | goto EXIT; | |
83 | ctr = langtrs[choice]; | |
84 | } | |
e1457ba0 | 85 | #endif |
8af06406 | 86 | |
e1457ba0 MT |
87 | sections[0] = _("Keyboard mapping"); |
88 | sections[1] = _("Timezone"); | |
89 | sections[2] = _("Hostname"); | |
90 | sections[3] = _("Domain name"); | |
91 | sections[4] = _("Networking"); | |
92 | sections[5] = _("ISDN"); | |
93 | sections[6] = _("'root' password"); | |
94 | sections[7] = _("'admin' password"); | |
bba7212c | 95 | sections[8] = NULL; |
8af06406 HS |
96 | |
97 | newtInit(); | |
98 | newtCls(); | |
99 | FILE *f_title; | |
100 | if ((f_title = fopen ("/etc/issue", "r"))) | |
101 | { | |
102 | fgets (title, STRING_SIZE, f_title); | |
103 | if (title[strlen(title) - 1] == '\n') | |
104 | title[strlen(title) - 1] = '\0'; | |
105 | fclose (f_title); | |
106 | } else { | |
d1782bf0 | 107 | sprintf (title, "%s - %s", NAME, SLOGAN); |
8af06406 HS |
108 | } |
109 | newtDrawRootText(14, 0, title); | |
e1457ba0 | 110 | newtPushHelpLine(_(" <Tab>/<Alt-Tab> between elements | <Space> selects")); |
8af06406 HS |
111 | |
112 | if (automode == 0) | |
113 | { | |
114 | choice = 0; | |
115 | for (;;) | |
116 | { | |
e1457ba0 MT |
117 | rc = newtWinMenu(_("Section menu"), |
118 | _("Select the item you wish to configure."), 50, 5, 5, 11, | |
119 | sections, &choice, _("OK"), _("Quit"), NULL); | |
8af06406 HS |
120 | |
121 | if (rc == 2) | |
122 | break; | |
123 | ||
124 | switch (choice) | |
125 | { | |
126 | case 0: | |
127 | handlekeymap(); | |
128 | break; | |
129 | ||
130 | case 1: | |
131 | handletimezone(); | |
132 | break; | |
133 | ||
134 | case 2: | |
135 | handlehostname(); | |
136 | break; | |
137 | ||
138 | case 3: | |
139 | handledomainname(); | |
140 | break; | |
141 | ||
142 | case 4: | |
8af06406 HS |
143 | handlenetworking(); |
144 | break; | |
bba7212c | 145 | |
ca385da6 | 146 | case 5: |
bba7212c MT |
147 | handleisdn(); |
148 | break; | |
149 | ||
150 | case 6: | |
8af06406 HS |
151 | handlerootpassword(); |
152 | break; | |
153 | ||
bba7212c | 154 | case 7: |
8af06406 HS |
155 | handleadminpassword(); |
156 | break; | |
157 | ||
158 | default: | |
159 | break; | |
160 | } | |
161 | } | |
162 | } | |
163 | else | |
164 | { | |
165 | if (!(handlekeymap())) | |
166 | goto EXIT; | |
167 | if (!(handletimezone())) | |
168 | goto EXIT; | |
169 | if (!(handlehostname())) | |
170 | goto EXIT; | |
171 | if (!(handledomainname())) | |
172 | goto EXIT; | |
71a5950f | 173 | if (!(handlerootpassword())) |
8af06406 | 174 | goto EXIT; |
71a5950f | 175 | if (!(handleadminpassword())) |
bba7212c | 176 | goto EXIT; |
71a5950f | 177 | if (!(handleisdn())) |
8af06406 | 178 | goto EXIT; |
71a5950f | 179 | if (!(handlenetworking())) |
8af06406 | 180 | goto EXIT; |
71a5950f | 181 | if (!(handledhcp())) |
8af06406 HS |
182 | goto EXIT; |
183 | ||
184 | autook = 1; | |
185 | } | |
186 | ||
e1457ba0 | 187 | EXIT: |
8af06406 HS |
188 | if (automode != 0) |
189 | { | |
d1782bf0 | 190 | sprintf (title, "%s - %s", NAME, SLOGAN); |
8af06406 | 191 | if (autook) |
e1457ba0 MT |
192 | newtWinMessage(title, _("OK"), _("Setup is complete.")); |
193 | else { | |
194 | newtWinMessage(_("Warning"), _("OK"), | |
195 | _("Initial setup was not entirely complete. " | |
196 | "You must ensure that Setup is properly finished by running " | |
197 | "setup again at the shell.")); | |
e238e4c2 | 198 | |
20fa8ccd | 199 | fprintf(flog, "Setup program has not finished.\n"); |
e238e4c2 AF |
200 | fflush(flog); |
201 | fclose(flog); | |
202 | ||
203 | newtFinished(); | |
204 | ||
205 | return 1; | |
206 | } | |
8af06406 | 207 | } |
069680ac | 208 | |
8af06406 HS |
209 | fprintf(flog, "Setup program ended.\n"); |
210 | fflush(flog); | |
211 | fclose(flog); | |
069680ac | 212 | |
8af06406 HS |
213 | newtFinished(); |
214 | ||
215 | return 0; | |
216 | } |