]>
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]; | |
b5cf9717 | 44 | char restore_file[STRING_SIZE]; |
c78a77eb MT |
45 | |
46 | findkey(unattendedkv, "DOMAINNAME", domainname); | |
47 | findkey(unattendedkv, "HOSTNAME", hostname); | |
48 | findkey(unattendedkv, "KEYMAP", keymap); | |
49 | findkey(unattendedkv, "LANGUAGE", language); | |
50 | findkey(unattendedkv, "TIMEZONE", timezone); | |
51 | findkey(unattendedkv, "THEME", theme); | |
52 | findkey(unattendedkv, "GREEN_ADDRESS", green_address); | |
53 | findkey(unattendedkv, "GREEN_NETMASK", green_netmask); | |
54 | findkey(unattendedkv, "GREEN_NETADDRESS", green_netaddress); | |
55 | findkey(unattendedkv, "GREEN_BROADCAST", green_broadcast); | |
56 | findkey(unattendedkv, "ROOT_PASSWORD", root_password); | |
57 | findkey(unattendedkv, "ADMIN_PASSWORD", admin_password); | |
b5cf9717 | 58 | findkey(unattendedkv, "RESTORE_FILE", restore_file); |
c78a77eb MT |
59 | |
60 | /* write main/settings. */ | |
61 | replacekeyvalue(mainsettings, "DOMAINNAME", domainname); | |
62 | replacekeyvalue(mainsettings, "HOSTNAME", hostname); | |
63 | replacekeyvalue(mainsettings, "KEYMAP", keymap); | |
64 | replacekeyvalue(mainsettings, "LANGUAGE", language); | |
65 | replacekeyvalue(mainsettings, "TIMEZONE", timezone); | |
66 | replacekeyvalue(mainsettings, "THEME", theme); | |
67 | writekeyvalues(mainsettings, "/harddisk" CONFIG_ROOT "/main/settings"); | |
68 | freekeyvalues(mainsettings); | |
69 | ||
70 | /* do setup stuff */ | |
71 | fprintf(flog, "unattended: Starting setup\n"); | |
72 | ||
73 | /* network */ | |
74 | fprintf(flog, "unattended: setting up network configuration\n"); | |
75 | ||
76 | (void) readkeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings"); | |
77 | replacekeyvalue(ethernetkv, "GREEN_ADDRESS", green_address); | |
78 | replacekeyvalue(ethernetkv, "GREEN_NETMASK", green_netmask); | |
79 | replacekeyvalue(ethernetkv, "GREEN_NETADDRESS", green_netaddress); | |
80 | replacekeyvalue(ethernetkv, "GREEN_BROADCAST", green_broadcast); | |
81 | replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0"); | |
82 | replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0"); | |
83 | write_ethernet_configs(ethernetkv); | |
84 | freekeyvalues(ethernetkv); | |
85 | ||
86 | /* timezone */ | |
87 | unlink("/harddisk/etc/localtime"); | |
88 | snprintf(commandstring, STRING_SIZE, "/harddisk/%s", timezone); | |
89 | link(commandstring, "/harddisk/etc/localtime"); | |
90 | ||
91 | /* hostname */ | |
92 | fprintf(flog, "unattended: writing hostname.conf\n"); | |
93 | if (!(file = fopen("/harddisk" CONFIG_ROOT "/main/hostname.conf", "w"))) | |
94 | { | |
95 | errorbox("unattended: ERROR writing hostname.conf"); | |
96 | return 0; | |
97 | } | |
98 | fprintf(file, "ServerName %s.%s\n", hostname,domainname); | |
99 | fclose(file); | |
100 | ||
101 | fprintf(flog, "unattended: writing hosts\n"); | |
102 | if (!(hosts = fopen("/harddisk/etc/hosts", "w"))) | |
103 | { | |
104 | errorbox("unattended: ERROR writing hosts"); | |
105 | return 0; | |
106 | } | |
107 | fprintf(hosts, "127.0.0.1\tlocalhost\n"); | |
108 | fprintf(hosts, "%s\t%s.%s\t%s\n", green_address, hostname, domainname, hostname); | |
109 | fclose(hosts); | |
110 | ||
111 | fprintf(flog, "unattended: writing hosts.allow\n"); | |
112 | if (!(file = fopen("/harddisk/etc/hosts.allow", "w"))) | |
113 | { | |
114 | errorbox("unattended: ERROR writing hosts.allow"); | |
115 | return 0; | |
116 | } | |
117 | fprintf(file, "sshd : ALL\n"); | |
118 | fprintf(file, "ALL : localhost\n"); | |
119 | fprintf(file, "ALL : %s/%s\n", green_netaddress, green_netmask); | |
120 | fclose(file); | |
121 | ||
122 | fprintf(flog, "unattended: writing hosts.deny\n"); | |
123 | if (!(file = fopen("/harddisk/etc/hosts.deny", "w"))) | |
124 | { | |
125 | errorbox("unattended: ERROR writing hosts.deny"); | |
126 | return 0; | |
127 | } | |
128 | fprintf(file, "ALL : ALL\n"); | |
129 | fclose(file); | |
130 | ||
131 | /* set root password */ | |
132 | fprintf(flog, "unattended: setting root password\n"); | |
133 | snprintf(commandstring, STRING_SIZE, | |
134 | "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password); | |
135 | if (mysystem(commandstring)) { | |
136 | errorbox("unattended: ERROR setting root password"); | |
137 | return 0; | |
138 | } | |
139 | ||
140 | /* set admin password */ | |
141 | fprintf(flog, "unattended: setting admin password\n"); | |
142 | snprintf(commandstring, STRING_SIZE, | |
143 | "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password); | |
144 | if (mysystem(commandstring)) { | |
145 | errorbox("unattended: ERROR setting admin password"); | |
146 | return 0; | |
147 | } | |
148 | ||
b5cf9717 | 149 | /* restore backup */ |
7062cecd | 150 | if (strlen(restore_file) > 0) { |
b5cf9717 DG |
151 | fprintf(flog, "unattended: Restoring Backup\n"); |
152 | snprintf(commandstring, STRING_SIZE, | |
c25a0343 | 153 | "cd /harddisk && /bin/tar -xvz --preserve -f /harddisk/var/ipfire/%s", restore_file); |
b5cf9717 | 154 | if (mysystem(commandstring)) { |
c25a0343 | 155 | errorbox("unattended: ERROR restoring backup"); |
ac52a0f4 | 156 | } |
b5cf9717 DG |
157 | } |
158 | ||
c78a77eb MT |
159 | fprintf(flog, "unattended: Setup ended\n"); |
160 | return 1; | |
161 | } |