1 |
#!/usr/bin/perl |
2 |
|
3 |
# Drakwizard |
4 |
|
5 |
# Copyright (C) 2002, 2005 Mandrakesoft |
6 |
# |
7 |
# Authors: Arnaud Desmons <adesmons@mandrakesoft.com> |
8 |
# Florent Villard <warly@mandrakesoft.com> |
9 |
# |
10 |
# This program is free software; you can redistribute it and/or modify |
11 |
# it under the terms of the GNU General Public License as published by |
12 |
# the Free Software Foundation; either version 2, or (at your option) |
13 |
# any later version. |
14 |
# |
15 |
# This program is distributed in the hope that it will be useful, |
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
# GNU General Public License for more details. |
19 |
# |
20 |
# You should have received a copy of the GNU General Public License |
21 |
# along with this program; if not, write to the Free Software |
22 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
|
24 |
package MDK::Wizard::Apache; |
25 |
use strict; |
26 |
|
27 |
use common; |
28 |
use services; |
29 |
use MDK::Wizard::Wizcommon; |
30 |
use MDK::Wizard::Varspaceval; |
31 |
|
32 |
my $wiz = new MDK::Wizard::Wizcommon; |
33 |
my $in = interactive->vnew; |
34 |
|
35 |
my $file = "/etc/httpd/conf/httpd.conf"; |
36 |
my $root; |
37 |
|
38 |
my $config; #FIXME: unused |
39 |
my $o = { |
40 |
name => N("Web wizard"), |
41 |
var => { |
42 |
web_internal => '', |
43 |
web_external => '', |
44 |
user_mod => '', |
45 |
user_dir => '', |
46 |
shared_dir => '' |
47 |
}, |
48 |
needed_rpm => [ 'apache', 'apache-mod_userdir' ], |
49 |
defaultimage => "/usr/share/mcc/themes/default/web_server-mdk.png", |
50 |
init => sub { |
51 |
if (-f $file) { |
52 |
open my $FH, $file or die "$! ($file)"; |
53 |
local $_; |
54 |
while (<$FH>) { |
55 |
if (/^\s*#?\s*DocumentRoot\s+(.*)/) { |
56 |
close($FH); |
57 |
$root = $1; |
58 |
$root =~ s/"//g; |
59 |
last; |
60 |
} |
61 |
} |
62 |
close($FH); |
63 |
} else { |
64 |
return 0, N("%s does not exist.", $file); |
65 |
} |
66 |
1; |
67 |
} |
68 |
}; |
69 |
|
70 |
$o->{pages} = { |
71 |
welcome => { |
72 |
name => N("Web server configuration wizard") . "\n\n" . N("This wizard will help you configuring the Web server for your network."), |
73 |
post => sub { $wiz->check_dhcp }, |
74 |
no_back => 1, |
75 |
next => 'config', |
76 |
}, |
77 |
config => { |
78 |
name => N("Web server") . "\n\n" . N("Your server can act as a Web server toward your internal network (intranet) and as a Web server for the Internet.") . "\n\n" . N("Select the kind of Web service you want to activate:") . "\n\n" . N("Don't check any box if you don't want to activate your Web server."), |
79 |
pre => sub { |
80 |
$o->{var}{web_internal} = 1; |
81 |
$o->{var}{web_external} = 1; |
82 |
}, |
83 |
data => [ |
84 |
{ text => N("Enable the Web server for the intranet"), type => 'bool', val => \$o->{var}{web_internal} }, |
85 |
{ text => N("Enable the Web server for the Internet"), type => 'bool', val => \$o->{var}{web_external} }, |
86 |
], |
87 |
next => 'ask_mod', |
88 |
}, |
89 |
dhcp_warning => { |
90 |
name => N("Warning.") . "\n\n" . N("You are in dhcp, server may not work with your configuration."), |
91 |
ignore => 1, |
92 |
next => 'config', |
93 |
}, |
94 |
ask_mod => { |
95 |
name => N("Modules:") . "\n\n" . N("* User module: allows users to have a directory in their home directories available on your http server via http://www.yourserver.com/~user, you will be asked for the name of this directory afterward."), |
96 |
pre => sub { $o->{var}{user_mod} = is_last_user_mod() }, |
97 |
data => [ |
98 |
{ text => join("\n", warp_text(N("Allows users to get a directory in their home directories available on your http server via http://www.yourserver.com/~user."), 70)), type => 'bool', val => \$o->{var}{user_mod} }, |
99 |
], |
100 |
post => sub { return 'user_dir' if $o->{var}{user_mod} }, |
101 |
next => 'ask_dir', |
102 |
}, |
103 |
user_dir => { |
104 |
name => N("Type the name of the directory users should create in their homes (without ~/) to get it available via http://www.yourserver.com/~user"), |
105 |
pre => sub { |
106 |
$o->{var}{user_dir} = get_user_dir(); |
107 |
if ($o->{var}{user_dir} =~ /disabled/ || !$o->{var}{user_dir}) { |
108 |
$o->{var}{user_dir} = 'public_html'; |
109 |
} |
110 |
}, |
111 |
complete => sub { |
112 |
if (!$o->{var}{user_dir}) { |
113 |
$in->ask_warn(N("Error"), N("You must specify a user directory.")); return 1; |
114 |
} else { |
115 |
return 0; |
116 |
} |
117 |
}, |
118 |
data => [ |
119 |
{ label => N("user http sub-directory: ~/"), help => N("Type the name of the directory users should create in their homes (without ~/) to get it available via http://www.yourserver.com/~user"), val => \$o->{var}{user_dir} }, |
120 |
], |
121 |
next => 'ask_dir', |
122 |
}, |
123 |
ask_dir => { |
124 |
name => N("Type the path of the directory you want being the document root."), |
125 |
pre => sub { $o->{var}{shared_dir} ||= $root }, |
126 |
data => [ |
127 |
{ label => N("Document root:"), val => \$o->{var}{shared_dir} }, |
128 |
], |
129 |
complete => sub { |
130 |
if (! -d $o->{var}{shared_dir}) { |
131 |
$in->ask_warn(N("Error"), N("The path you entered does not exist.")); |
132 |
return 1; |
133 |
} else { |
134 |
return 0; |
135 |
} |
136 |
}, |
137 |
next => 'summary', |
138 |
}, |
139 |
summary => { |
140 |
name => N("Configuring the Web server") . "\n\n" . N("The wizard collected the following parameters needed to configure your Web server") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them."), |
141 |
pre => sub { |
142 |
$o->{var}{internal} = $o->{var}{web_internal} ? N("enabled") : N("disabled"); |
143 |
$o->{var}{external} = $o->{var}{web_external} ? N("enabled") : N("disabled"); |
144 |
}, |
145 |
data => [ |
146 |
{ label => N("Intranet web server:"), val_ref => \$o->{var}{internal} }, |
147 |
{ label => N("Internet web server:"), val_ref => \$o->{var}{external} }, |
148 |
{ label => N("Document root:"), val_ref => \$o->{var}{shared_dir} }, |
149 |
{ label => N("User directory:"), val_ref => \$o->{var}{user_dir} }, |
150 |
], |
151 |
post => \&do_it, |
152 |
next => 'end', |
153 |
}, |
154 |
end => { |
155 |
name => N("Congratulations") . "\n\n" . N("The wizard successfully configured your intranet/Internet Web server"), |
156 |
end => 1, |
157 |
}, |
158 |
error_end => { |
159 |
name => N("Failed"), |
160 |
data => [ { label => N("Relaunch drakwizard, and try to change some parameters.") } ], |
161 |
no_back => 1, |
162 |
end => 1, |
163 |
}, |
164 |
}; |
165 |
|
166 |
sub new { |
167 |
my ($class, $conf) = @_; |
168 |
$config = $conf; |
169 |
# if ($config->{ver} == 2) { |
170 |
$file = "/etc/httpd/conf/httpd.conf"; |
171 |
# $o->{needed_rpm} = [ 'apache2' ]; |
172 |
$o->{var}{servicecheck} = 'httpd'; |
173 |
# } else { |
174 |
# $file = "/etc/httpd/conf/httpd.conf"; |
175 |
# $o->{needed_rpm} = [ 'apache-1.3' ]; |
176 |
# $o->{var}{servicecheck} = 'httpd'; |
177 |
# } |
178 |
bless $o, $class; |
179 |
} |
180 |
|
181 |
sub chg_docroot { |
182 |
my $old; |
183 |
substInFile { |
184 |
s|(^\s*#?\s*DocumentRoot\s*)(\S*).*|$1$o->{var}{shared_dir}| and $old ||= $2; |
185 |
} $file; |
186 |
|
187 |
substInFile { |
188 |
s|^(\s*\|)<Directory\s*$old/?>|<Directory $o->{var}{shared_dir}>|; |
189 |
} $file if $old; |
190 |
|
191 |
substInFile { |
192 |
s|^(\s*\|)<Directory\s*.*|<Directory $o->{var}{shared_dir}>|; |
193 |
} $file; |
194 |
} |
195 |
|
196 |
sub is_user_mod { |
197 |
if ($o->{var}{user_mod}) { |
198 |
return 1; |
199 |
} |
200 |
$o->{var}{user_mod} = "disabled"; |
201 |
0; |
202 |
} |
203 |
|
204 |
sub is_last_user_mod { |
205 |
my $root = get_user_dir(); |
206 |
chomp($root); |
207 |
$root ne 'disabled'; |
208 |
} |
209 |
|
210 |
sub get_user_dir { |
211 |
my %conf = MDK::Wizard::Varspaceval->get($file); |
212 |
$conf{UserDir}; |
213 |
} |
214 |
|
215 |
sub chg_user_dir { |
216 |
# disable by default user_mod |
217 |
if (! any { /<IfModule mod_userdir.c>/ } cat_($file)) { |
218 |
append_to_file($file, <<EOF); |
219 |
# add usermod dir support |
220 |
<IfModule mod_userdir.c> |
221 |
UserDir disabled |
222 |
</IfModule> |
223 |
|
224 |
<Directory /home/*/> |
225 |
AllowOverride FileInfo AuthConfig Limit |
226 |
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec |
227 |
<Limit GET POST OPTIONS PROPFIND> |
228 |
Order allow,deny |
229 |
Allow from all |
230 |
</Limit> |
231 |
<LimitExcept GET POST OPTIONS PROPFIND> |
232 |
Order deny,allow |
233 |
Deny from all |
234 |
</LimitExcept> |
235 |
</Directory> |
236 |
EOF |
237 |
} |
238 |
|
239 |
$root = get_user_dir(); |
240 |
if ($o->{var}{user_mod}) { |
241 |
substInFile { |
242 |
s|(\s*)UserDir.*|$1UserDir $o->{var}{user_dir}|g; |
243 |
s|<Directory\s+/home/\*/.*|<Directory /home/*/$o->{var}{user_dir}>|g; |
244 |
} $file; |
245 |
} else { |
246 |
substInFile { |
247 |
s|(\s*)UserDir\s*$root|$1UserDir disabled|g; |
248 |
} $file; |
249 |
} |
250 |
} |
251 |
|
252 |
sub do_it { |
253 |
$::testing and return; |
254 |
my $in = 'interactive'->vnew('su', 'Apache'); |
255 |
check_starts_on_boot($in, 'httpd'); |
256 |
my $w = $in->wait_message(N("Apache server"), N("Configuring your system as Apache server ...")); |
257 |
|
258 |
my $that = "localhost"; |
259 |
if ($o->{var}{web_external} eq "1") { |
260 |
$that = "all"; |
261 |
} elsif ($o->{var}{web_internal} eq "1") { |
262 |
($that) = $wiz->{net}->itf_get("IPADDR") =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d{1,3}$/; |
263 |
$that .= " 127.0.0.1"; |
264 |
} |
265 |
cp_af($file, $file . ".orig"); |
266 |
substInFile { |
267 |
if (m/^\s*<Directory.*>/s...m!^\s*</Directory>!s) { |
268 |
{ s/^\s*Allow .*$/ Allow from $that\n/s } |
269 |
} |
270 |
} $file; |
271 |
chg_docroot(); |
272 |
chg_user_dir(); |
273 |
|
274 |
reload_or_restart('httpd'); |
275 |
undef $w; |
276 |
check_started($o->{var}{servicecheck}); |
277 |
} |
278 |
|
279 |
1; |