]>
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; | |
782ae35d | 31 | char lang[STRING_SIZE] = "en_US.utf8"; |
8af06406 HS |
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 | ||
8af06406 HS |
56 | kv = initkeyvalues(); |
57 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) | |
58 | { | |
59 | printf("%s is not properly installed.\n", NAME); | |
60 | return 1; | |
61 | } | |
782ae35d | 62 | findkey(kv, "LANGUAGE", lang); |
8af06406 | 63 | |
782ae35d MT |
64 | setlocale(LC_ALL, lang); |
65 | setenv("LANGUAGE", lang, 1); | |
8af06406 | 66 | |
e1457ba0 MT |
67 | sections[0] = _("Keyboard mapping"); |
68 | sections[1] = _("Timezone"); | |
69 | sections[2] = _("Hostname"); | |
70 | sections[3] = _("Domain name"); | |
71 | sections[4] = _("Networking"); | |
72 | sections[5] = _("ISDN"); | |
73 | sections[6] = _("'root' password"); | |
74 | sections[7] = _("'admin' password"); | |
bba7212c | 75 | sections[8] = NULL; |
8af06406 HS |
76 | |
77 | newtInit(); | |
78 | newtCls(); | |
79 | FILE *f_title; | |
80 | if ((f_title = fopen ("/etc/issue", "r"))) | |
81 | { | |
82 | fgets (title, STRING_SIZE, f_title); | |
83 | if (title[strlen(title) - 1] == '\n') | |
84 | title[strlen(title) - 1] = '\0'; | |
85 | fclose (f_title); | |
86 | } else { | |
d1782bf0 | 87 | sprintf (title, "%s - %s", NAME, SLOGAN); |
8af06406 HS |
88 | } |
89 | newtDrawRootText(14, 0, title); | |
e1457ba0 | 90 | newtPushHelpLine(_(" <Tab>/<Alt-Tab> between elements | <Space> selects")); |
8af06406 HS |
91 | |
92 | if (automode == 0) | |
93 | { | |
94 | choice = 0; | |
95 | for (;;) | |
96 | { | |
e1457ba0 MT |
97 | rc = newtWinMenu(_("Section menu"), |
98 | _("Select the item you wish to configure."), 50, 5, 5, 11, | |
99 | sections, &choice, _("OK"), _("Quit"), NULL); | |
8af06406 HS |
100 | |
101 | if (rc == 2) | |
102 | break; | |
103 | ||
104 | switch (choice) | |
105 | { | |
106 | case 0: | |
107 | handlekeymap(); | |
108 | break; | |
109 | ||
110 | case 1: | |
111 | handletimezone(); | |
112 | break; | |
113 | ||
114 | case 2: | |
115 | handlehostname(); | |
116 | break; | |
117 | ||
118 | case 3: | |
119 | handledomainname(); | |
120 | break; | |
121 | ||
122 | case 4: | |
8af06406 HS |
123 | handlenetworking(); |
124 | break; | |
bba7212c | 125 | |
ca385da6 | 126 | case 5: |
bba7212c MT |
127 | handleisdn(); |
128 | break; | |
129 | ||
130 | case 6: | |
8af06406 HS |
131 | handlerootpassword(); |
132 | break; | |
133 | ||
bba7212c | 134 | case 7: |
8af06406 HS |
135 | handleadminpassword(); |
136 | break; | |
137 | ||
138 | default: | |
139 | break; | |
140 | } | |
141 | } | |
142 | } | |
143 | else | |
144 | { | |
145 | if (!(handlekeymap())) | |
146 | goto EXIT; | |
147 | if (!(handletimezone())) | |
148 | goto EXIT; | |
149 | if (!(handlehostname())) | |
150 | goto EXIT; | |
151 | if (!(handledomainname())) | |
152 | goto EXIT; | |
71a5950f | 153 | if (!(handlerootpassword())) |
8af06406 | 154 | goto EXIT; |
71a5950f | 155 | if (!(handleadminpassword())) |
bba7212c | 156 | goto EXIT; |
71a5950f | 157 | if (!(handleisdn())) |
8af06406 | 158 | goto EXIT; |
71a5950f | 159 | if (!(handlenetworking())) |
8af06406 | 160 | goto EXIT; |
71a5950f | 161 | if (!(handledhcp())) |
8af06406 HS |
162 | goto EXIT; |
163 | ||
164 | autook = 1; | |
165 | } | |
166 | ||
e1457ba0 | 167 | EXIT: |
8af06406 HS |
168 | if (automode != 0) |
169 | { | |
d1782bf0 | 170 | sprintf (title, "%s - %s", NAME, SLOGAN); |
8af06406 | 171 | if (autook) |
e1457ba0 MT |
172 | newtWinMessage(title, _("OK"), _("Setup is complete.")); |
173 | else { | |
174 | newtWinMessage(_("Warning"), _("OK"), | |
175 | _("Initial setup was not entirely complete. " | |
176 | "You must ensure that Setup is properly finished by running " | |
177 | "setup again at the shell.")); | |
e238e4c2 | 178 | |
20fa8ccd | 179 | fprintf(flog, "Setup program has not finished.\n"); |
e238e4c2 AF |
180 | fflush(flog); |
181 | fclose(flog); | |
182 | ||
183 | newtFinished(); | |
184 | ||
185 | return 1; | |
186 | } | |
8af06406 | 187 | } |
069680ac | 188 | |
8af06406 HS |
189 | fprintf(flog, "Setup program ended.\n"); |
190 | fflush(flog); | |
191 | fclose(flog); | |
069680ac | 192 | |
8af06406 HS |
193 | newtFinished(); |
194 | ||
195 | return 0; | |
196 | } |