]>
Commit | Line | Data |
---|---|---|
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 | */ | |
10 | ||
11 | // Translation | |
12 | #include <libintl.h> | |
13 | #define _(x) dgettext("setup", x) | |
14 | ||
15 | #include "setup.h" | |
16 | ||
17 | FILE *flog = NULL; | |
18 | char *mylog; | |
19 | ||
20 | int automode = 0; | |
21 | ||
22 | struct nic nics[20] = { { "" , "" , "" , "" } }; | |
23 | struct knic knics[20] = { { "" , "" , "" , "" } }; | |
24 | ||
25 | int main(int argc, char *argv[]) | |
26 | { | |
27 | int choice; | |
28 | char *sections[8]; /* need to fill this out AFTER knowning lang */ | |
29 | int rc; | |
30 | struct keyvalue *kv; | |
31 | char lang[STRING_SIZE] = "en_US.utf8"; | |
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 | |
40 | mylog = strdup("/var/log/setup.log"); | |
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 | ||
53 | if (!setlocale(LC_CTYPE,"")) | |
54 | fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL."); | |
55 | ||
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 | } | |
62 | findkey(kv, "LANGUAGE", lang); | |
63 | ||
64 | setlocale(LC_ALL, lang); | |
65 | setenv("LANGUAGE", lang, 1); | |
66 | ||
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] = _("'root' password"); | |
73 | sections[6] = _("'admin' password"); | |
74 | sections[7] = NULL; | |
75 | ||
76 | newtInit(); | |
77 | newtCls(); | |
78 | FILE *f_title; | |
79 | if ((f_title = fopen ("/etc/issue", "r"))) | |
80 | { | |
81 | fgets (title, STRING_SIZE, f_title); | |
82 | if (title[strlen(title) - 1] == '\n') | |
83 | title[strlen(title) - 1] = '\0'; | |
84 | fclose (f_title); | |
85 | } else { | |
86 | sprintf (title, "%s - %s", NAME, SLOGAN); | |
87 | } | |
88 | newtDrawRootText(14, 0, title); | |
89 | newtPushHelpLine(_(" <Tab>/<Alt-Tab> between elements | <Space> selects")); | |
90 | ||
91 | if (automode == 0) | |
92 | { | |
93 | choice = 0; | |
94 | for (;;) | |
95 | { | |
96 | rc = newtWinMenu(_("Section menu"), | |
97 | _("Select the item you wish to configure."), 50, 5, 5, 11, | |
98 | sections, &choice, _("OK"), _("Quit"), NULL); | |
99 | ||
100 | if (rc == 2) | |
101 | break; | |
102 | ||
103 | switch (choice) | |
104 | { | |
105 | case 0: | |
106 | handlekeymap(); | |
107 | break; | |
108 | ||
109 | case 1: | |
110 | handletimezone(); | |
111 | break; | |
112 | ||
113 | case 2: | |
114 | handlehostname(); | |
115 | break; | |
116 | ||
117 | case 3: | |
118 | handledomainname(); | |
119 | break; | |
120 | ||
121 | case 4: | |
122 | handlenetworking(); | |
123 | break; | |
124 | ||
125 | case 5: | |
126 | handlerootpassword(); | |
127 | break; | |
128 | ||
129 | case 6: | |
130 | handleadminpassword(); | |
131 | break; | |
132 | ||
133 | default: | |
134 | break; | |
135 | } | |
136 | } | |
137 | } | |
138 | else | |
139 | { | |
140 | if (!(handlekeymap())) | |
141 | goto EXIT; | |
142 | if (!(handletimezone())) | |
143 | goto EXIT; | |
144 | if (!(handlehostname())) | |
145 | goto EXIT; | |
146 | if (!(handledomainname())) | |
147 | goto EXIT; | |
148 | if (!(handlerootpassword())) | |
149 | goto EXIT; | |
150 | if (!(handleadminpassword())) | |
151 | goto EXIT; | |
152 | if (!(handlenetworking())) | |
153 | goto EXIT; | |
154 | if (!(handledhcp())) | |
155 | goto EXIT; | |
156 | ||
157 | autook = 1; | |
158 | } | |
159 | ||
160 | EXIT: | |
161 | if (automode != 0) | |
162 | { | |
163 | sprintf (title, "%s - %s", NAME, SLOGAN); | |
164 | if (autook) | |
165 | newtWinMessage(title, _("OK"), _("Setup is complete.")); | |
166 | else { | |
167 | newtWinMessage(_("Warning"), _("OK"), | |
168 | _("Initial setup was not entirely complete. " | |
169 | "You must ensure that Setup is properly finished by running " | |
170 | "setup again at the shell.")); | |
171 | ||
172 | fprintf(flog, "Setup program has not finished.\n"); | |
173 | fflush(flog); | |
174 | fclose(flog); | |
175 | ||
176 | newtFinished(); | |
177 | ||
178 | return 1; | |
179 | } | |
180 | } | |
181 | ||
182 | fprintf(flog, "Setup program ended.\n"); | |
183 | fflush(flog); | |
184 | fclose(flog); | |
185 | ||
186 | newtFinished(); | |
187 | ||
188 | return 0; | |
189 | } |