1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
#!/usr/bin/perl
# Drakwizard
# Copyright (C) 2003 Mandrakesoft
#
# Author: Florent Villard <warly@mandrakesoft.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package MDK::Wizard::Proftpd;
use strict;
use common;
use services;
require MDK::Wizard::Wizcommon;
my $wiz = new MDK::Wizard::Wizcommon;
my $o = {
name => 'FTP wizard',
var => {
wiz_ftp_external => '',
wiz_ftp_anon => '',
wiz_ftp_home => ''
},
needed_rpm => [ 'proftpd', 'proftpd-anonymous' ],
defaultimage => "$ENV{__WIZ_HOME__}ftp_wizard/images/FTP.png"
};
$o->{pages} = {
welcome => {
name => N('FTP Server Configuration Wizard') . "\n\n" . N('This wizard will help you configuring the FTP Server for your network.'),
no_back => 1,
post => \&check,
next => 'config'
},
config => {
name => N('FTP Server') . "\n\n" . N('Your server can act as an FTP Server toward your internal network (intranet) and as an FTP Server for the Internet.') . "\n\n" . N('Select the kind of FTP service you want to activate:') . "\n\n" . N('Don\'t check any box if you don\'t want to activate your FTP Server.'),
pre => sub {
$o->{var}{wiz_ftp_internal} ||= 1;
$o->{var}{wiz_ftp_external} ||= 0;
},
data => [
{ text => N('Enable the FTP Server for the Intranet'), type => 'bool', val => \$o->{var}{wiz_ftp_internal} },
{ text => N('Enable the FTP Server for the Internet'), type => 'bool', val => \$o->{var}{wiz_ftp_external} },
],
next => 'summary'
},
warning_dhcp => {
name => N('Warning.') . "\n\n" . N('Warning\nYou are in dhcp, server may not work with your configuration.'),
ignore => 1,
next => 'config'
},
must_be_root => {
name => N('Error.') . "\n\n" . N('Sorry, you must be root to do this...'),
ignore => 1,
next => 'config'
},
summary => {
name => N('Configuring the FTP Server') . "\n\n" . N('The wizard collected the following parameters
needed to configure your FTP Server') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them'),
pre => sub {
$o->{var}{internal} = $o->{var}{wiz_ftp_internal} ? N("enabled") : N("disabled");
$o->{var}{external} = $o->{var}{wiz_ftp_external} ? N("enabled") : N("disabled")
},
data => [
{ label => N('Intranet FTP Server:'), fixed_val => \$o->{var}{internal} },
{ label => N('Internet FTP Server:'), fixed_val => \$o->{var}{external} },
],
post => \&do_it,
next => 'end'
},
end => {
name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your Intranet/Internet FTP Server'),
end => 1,
next => 0
},
};
sub new {
my ($class, $conf) = @_;
bless {
o => $o,
}, $class;
}
sub true {
my ($val) = @_;
$val eq "1" || $val eq "\'1\'" || $val eq "\"1\"" ||
$val eq "true" || $val eq "\'true\'" || $val eq "\"true\"" and
return 1;
0
}
sub check_dir {
-d $o->{var}{wiz_dir} and return 10;
1
}
sub get_dir {
my $file = "/etc/proftpd.conf";
die "no ftp configuration file found ! warning." if (!-f $file);
open(NEW, "< $file") or die "error while opening $file: $!";
while (<NEW>) { # we need 3 elements to consider section as known
if (m/^\s*<drakwizard>/s...m/^\s*<\/drakwizard>/s ) {
if (m/^\s*<Anonymous\s*(.*)>/s ) {
return $1;
}
}
}
""
}
sub check {
$> and return 'must_be_root';
$wiz->{net}->is_dhcp() and return 'warning_dhcp';
''
}
sub print_anonymous() {
print '
#<drakwizard>
<Anonymous '.$_[0].'>
User ftp
Group ftp
UserAlias anonymous ftp
MaxClients 10
<Limit WRITE>
DenyAll
</Limit>
</Anonymous>
#</drakwizard>
';
}
sub do_it {
$::testing and return;
my $wiz_ftp_internal = $o->{var}{wiz_ftp_external} ? 1 : true $o->{var}{wiz_ftp_internal};
my $wiz_ftp_external = true $o->{var}{wiz_ftp_external};
my $file = "/etc/proftpd.conf";
die "no ftp configuration file found ! warning." if (!-f $file);
MDK::Common::cp_af($file, $file . ".orig");
open(NEW, "< $file") or die "error while opening $file: $!";
my $allow = "all";
if ($wiz_ftp_internal && !$wiz_ftp_external) {
($allow) = $wiz->{net}->itf_get("IPADDR") =~ qr/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d{1,3}$/;
$allow .= " 127.0.0.1";
}
elsif (!$wiz_ftp_external) {
$allow = "none";
}
my $file = "/etc/proftpd.conf";
open (NEW, "< $file");
my $exist = 0;
while (<NEW>) { # we need 3 elements to consider section as known
if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) {
if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) {
if (/^\s*(?!\#)\s*Order .*$/) {
$exist++;
}
if (/^\s*(?!\#)\s*Allow .*$/) {
$exist++;
}
if (/^\s*(?!\#)\s*Deny .*$/) {
$exist++;
}
}
}
}
close (NEW);
if ($exist < 3) { # Odd parameters are commented if exists to then add a known section
substInFile {
if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) {
if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) {
s/^\s*(?!\#)\s*Order .*$/\#$&\n/s;
s/^\s*(?!\#)\s*Allow .*$/\#$&\n/s;
s/^\s*(?!\#)\s*Deny .*$/\#$&\n/s;
}
}
} $file;
open (NEW, ">> $file");
print NEW '
#<drakwizard>
<Global>
<Limit LOGIN>
Order allow,deny
Allow from '.$allow.'
Deny from all
</Limit>
</Global>
#</drakwizard>
';
close NEW;
}
else { # the known section (3 parameters ) is replaced with our needs
substInFile {
if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) {
if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) {
if (/^\s*(?!\#)\s*Order .*$/i) {
if (!/\s*Order\s*allow,\s*deny\s*$/) {
s//\#$&\n Order allow,deny\n/;
}
}
if (/^\s*(?!\#)\s*Allow .*$/i) {
if (!/\s*Allow\s*from\s*$allow\s*$/) {
s//\#$&\n Allow from $allow/;
}
}
if (/^\s*(?!\#)\s*Deny .*$/i) {
if (!/\s*Deny\s*from\s*all\s*$/) {
s//\#$&\n Deny from all\n/;
}
}
}
}
} $file;
}
if (services::is_service_running('proftpd')) {
services::restart('proftpd')
} else {
services::start('proftpd')
}
}
1;
|