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