]>
Commit | Line | Data |
---|---|---|
c78a77eb MT |
1 | /* |
2 | * This file is part of the IPFire Firewall. | |
3 | * | |
4 | * IPFire is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * IPFire is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with IPFire; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | * | |
330345c2 | 18 | * Copyright 2007: Michael Tremer for www.ipfire.org |
c78a77eb MT |
19 | * |
20 | */ | |
21 | ||
22 | #include "install.h" | |
23 | extern FILE *flog; | |
24 | ||
25 | int unattended_setup(struct keyvalue *unattendedkv) { | |
26 | ||
27 | struct keyvalue *mainsettings = initkeyvalues(); | |
28 | struct keyvalue *ethernetkv = initkeyvalues(); | |
29 | FILE *file, *hosts; | |
30 | char commandstring[STRING_SIZE]; | |
31 | ||
32 | char domainname[STRING_SIZE]; | |
33 | char hostname[STRING_SIZE]; | |
34 | char keymap[STRING_SIZE]; | |
35 | char language[STRING_SIZE]; | |
36 | char timezone[STRING_SIZE]; | |
37 | char theme[STRING_SIZE]; | |
38 | char green_address[STRING_SIZE]; | |
39 | char green_netmask[STRING_SIZE]; | |
40 | char green_netaddress[STRING_SIZE]; | |
41 | char green_broadcast[STRING_SIZE]; | |
42 | char root_password[STRING_SIZE]; | |
43 | char admin_password[STRING_SIZE]; | |
44 | ||
45 | findkey(unattendedkv, "DOMAINNAME", domainname); | |
46 | findkey(unattendedkv, "HOSTNAME", hostname); | |
47 | findkey(unattendedkv, "KEYMAP", keymap); | |
48 | findkey(unattendedkv, "LANGUAGE", language); | |
49 | findkey(unattendedkv, "TIMEZONE", timezone); | |
50 | findkey(unattendedkv, "THEME", theme); | |
51 | findkey(unattendedkv, "GREEN_ADDRESS", green_address); | |
52 | findkey(unattendedkv, "GREEN_NETMASK", green_netmask); | |
53 | findkey(unattendedkv, "GREEN_NETADDRESS", green_netaddress); | |
54 | findkey(unattendedkv, "GREEN_BROADCAST", green_broadcast); | |
55 | findkey(unattendedkv, "ROOT_PASSWORD", root_password); | |
56 | findkey(unattendedkv, "ADMIN_PASSWORD", admin_password); | |
57 | ||
58 | /* write main/settings. */ | |
59 | replacekeyvalue(mainsettings, "DOMAINNAME", domainname); | |
60 | replacekeyvalue(mainsettings, "HOSTNAME", hostname); | |
61 | replacekeyvalue(mainsettings, "KEYMAP", keymap); | |
62 | replacekeyvalue(mainsettings, "LANGUAGE", language); | |
63 | replacekeyvalue(mainsettings, "TIMEZONE", timezone); | |
64 | replacekeyvalue(mainsettings, "THEME", theme); | |
65 | writekeyvalues(mainsettings, "/harddisk" CONFIG_ROOT "/main/settings"); | |
66 | freekeyvalues(mainsettings); | |
67 | ||
68 | /* do setup stuff */ | |
69 | fprintf(flog, "unattended: Starting setup\n"); | |
70 | ||
71 | /* network */ | |
72 | fprintf(flog, "unattended: setting up network configuration\n"); | |
73 | ||
74 | (void) readkeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings"); | |
75 | replacekeyvalue(ethernetkv, "GREEN_ADDRESS", green_address); | |
76 | replacekeyvalue(ethernetkv, "GREEN_NETMASK", green_netmask); | |
77 | replacekeyvalue(ethernetkv, "GREEN_NETADDRESS", green_netaddress); | |
78 | replacekeyvalue(ethernetkv, "GREEN_BROADCAST", green_broadcast); | |
79 | replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0"); | |
80 | replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0"); | |
81 | write_ethernet_configs(ethernetkv); | |
82 | freekeyvalues(ethernetkv); | |
83 | ||
84 | /* timezone */ | |
85 | unlink("/harddisk/etc/localtime"); | |
86 | snprintf(commandstring, STRING_SIZE, "/harddisk/%s", timezone); | |
87 | link(commandstring, "/harddisk/etc/localtime"); | |
88 | ||
89 | /* hostname */ | |
90 | fprintf(flog, "unattended: writing hostname.conf\n"); | |
91 | if (!(file = fopen("/harddisk" CONFIG_ROOT "/main/hostname.conf", "w"))) | |
92 | { | |
93 | errorbox("unattended: ERROR writing hostname.conf"); | |
94 | return 0; | |
95 | } | |
96 | fprintf(file, "ServerName %s.%s\n", hostname,domainname); | |
97 | fclose(file); | |
98 | ||
99 | fprintf(flog, "unattended: writing hosts\n"); | |
100 | if (!(hosts = fopen("/harddisk/etc/hosts", "w"))) | |
101 | { | |
102 | errorbox("unattended: ERROR writing hosts"); | |
103 | return 0; | |
104 | } | |
105 | fprintf(hosts, "127.0.0.1\tlocalhost\n"); | |
106 | fprintf(hosts, "%s\t%s.%s\t%s\n", green_address, hostname, domainname, hostname); | |
107 | fclose(hosts); | |
108 | ||
109 | fprintf(flog, "unattended: writing hosts.allow\n"); | |
110 | if (!(file = fopen("/harddisk/etc/hosts.allow", "w"))) | |
111 | { | |
112 | errorbox("unattended: ERROR writing hosts.allow"); | |
113 | return 0; | |
114 | } | |
115 | fprintf(file, "sshd : ALL\n"); | |
116 | fprintf(file, "ALL : localhost\n"); | |
117 | fprintf(file, "ALL : %s/%s\n", green_netaddress, green_netmask); | |
118 | fclose(file); | |
119 | ||
120 | fprintf(flog, "unattended: writing hosts.deny\n"); | |
121 | if (!(file = fopen("/harddisk/etc/hosts.deny", "w"))) | |
122 | { | |
123 | errorbox("unattended: ERROR writing hosts.deny"); | |
124 | return 0; | |
125 | } | |
126 | fprintf(file, "ALL : ALL\n"); | |
127 | fclose(file); | |
128 | ||
129 | /* set root password */ | |
130 | fprintf(flog, "unattended: setting root password\n"); | |
131 | snprintf(commandstring, STRING_SIZE, | |
132 | "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password); | |
133 | if (mysystem(commandstring)) { | |
134 | errorbox("unattended: ERROR setting root password"); | |
135 | return 0; | |
136 | } | |
137 | ||
138 | /* set admin password */ | |
139 | fprintf(flog, "unattended: setting admin password\n"); | |
140 | snprintf(commandstring, STRING_SIZE, | |
141 | "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password); | |
142 | if (mysystem(commandstring)) { | |
143 | errorbox("unattended: ERROR setting admin password"); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | fprintf(flog, "unattended: Setup ended\n"); | |
148 | return 1; | |
149 | } |