-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsftpd-lib.pl
75 lines (60 loc) · 1.61 KB
/
vsftpd-lib.pl
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
BEGIN {
push(@INC, "..");
$DEBUG = 0;
if ($DEBUG) {
use warnings;
use CGI::Carp qw(carpout);
open(ERROR_LOG, ">>/tmp/webmin_vsftpd_error_log")
or die("Can't setup error log: $!\n");
carpout(\*ERROR_LOG);
}
};
use WebminCore;
init_config();
%access = get_module_acl();
sub get_vsftpd_pid() {
return find_byname($config{'vsftpd_path'});
}
sub stop() {
my $out = system_logged("$config{'vsftpd_cmd_stop'} 2>&1 </dev/null");
webmin_log("cmd", "stop", undef, undef);
return "<pre>$out</pre>" if ($?);
}
sub start() {
my $out = system_logged("$config{'vsftpd_cmd_start'} 2>&1 </dev/null");
webmin_log("cmd", "start", undef, undef);
return "<pre>$out</pre>" if ($?);
}
sub restart() {
my $out = system_logged("$config{'vsftpd_cmd_restart'} 2>&1 </dev/null");
webmin_log("cmd", "restart", undef, undef);
return "<pre>$out</pre>" if ($?);
}
sub pkill() {
# regex matches the path itself if it contains no / or the last element in a path
$config{'vsftpd_path'} =~ m!^((([^/])+)|(.*/([^/]+)))$!;
my $cmd = $2 . $5; # either one of these contains something
if ($cmd) {
system_logged('pkill', '^' . $cmd . '$');
webmin_log("cmd", "kill", undef, undef);
}
}
sub userdb_regenerate($) {
my $userdb = shift;
my $dbname = $userdb . ".db";
my $mask = umask();
umask(0077);
system_logged($config{'cmd_dbload'}, "-T", "-t", "hash", "-f",
$userdb . ".txt", $dbname);
umask($mask);
webmin_log("regenerate", "userdb", undef, undef);
}
sub version() {
if (!has_command($config{'vsftpd_path'})) {
return "x";
}
my $version = `$config{'vsftpd_path'} -v 0>&1`;
$version =~ m/version (.+)/;
return $1;
}
1;