-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathdetect-scripts.pl
executable file
·136 lines (122 loc) · 3.59 KB
/
detect-scripts.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
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
#!/usr/local/bin/perl
=head1 detect-scripts.pl
Find scripts manually installed in some virtual server.
If you have installed supported apps like Wordpress into a Virtualmin domain
without using the built-in app installer feature, or have copied a website
from another non-Virtualmin system, this command will find those apps and
make them visible on the Manage Web Apps page.
The server to search must be set with the C<--domain> flag, and you can
optionally limit the search to a specific directory under the root with
the C<--dir> flag followed by a full path. By default any detected apps will
be immediately added to Virtualmin's database, but you can choose to just
display them instead with the C<--test> flag.
=cut
package virtual_server;
if (!$module_name) {
$main::no_acl_check++;
$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
if ($0 =~ /^(.*)\/[^\/]+$/) {
chdir($pwd = $1);
}
else {
chop($pwd = `pwd`);
}
$0 = "$pwd/detect-scripts.pl";
require './virtual-server-lib.pl';
$< == 0 || die "detect-scripts.pl must be run as root";
}
@OLDARGV = @ARGV;
&foreign_require("mailboxes");
&set_all_text_print();
# Parse command-line args
while(@ARGV > 0) {
local $a = shift(@ARGV);
if ($a eq "--domain") {
$dname = shift(@ARGV);
}
elsif ($a eq "--dir") {
$dir = shift(@ARGV);
}
elsif ($a eq "--test") {
$testmode = 1;
}
elsif ($a eq "--multiline") {
$multiline = 1;
}
elsif ($a eq "--help") {
&usage();
}
else {
&usage("Unknown parameter $a");
}
}
# Validate args
$dname || &usage("No domain specified");
$d = &get_domain_by("dom", $dname);
$d || &usage("Domain $dname does not exist!");
# Search for scripts
&$first_print("Searching for installed scripts".
($dir ? " under $dir" : "")."..");
@sinfos = &detect_installed_scripts($d, $dir);
&$second_print(".. found ",scalar(@sinfos)," scripts");
# Show what was found, and maybe save them
if (@sinfos) {
if ($multiline) {
foreach $sinfo (@sinfos) {
$script = &get_script($sinfo->{'name'});
$opts = $sinfo->{'opts'};
print "$sinfo->{'name'}:\n";
print " Description: ",$script->{'desc'},"\n";
print " Version: $sinfo->{'version'}\n";
if ($sinfo->{'url'}) {
print " URL: $sinfo->{'url'}\n";
}
if ($opts->{'dir'}) {
print " Directory: $opts->{'dir'}\n";
}
($dbtype, $dbname) = split(/_/, $opts->{'db'}, 2);
if ($dbtype) {
print " Database: $dbname ($dbtype)\n";
}
print " Detected: ",
($sinfo->{'already'} ? "Already known"
: "Newly detected"),"\n";
}
}
else {
$fmt = "%-18.18s %-10.10s %-10.10s %-35.35s\n";
printf $fmt, "Type", "Detected?", "Version", "URL path";
printf $fmt, ("-" x 18), ("-" x 10), ("-" x 10), ("-" x 35);
foreach $sinfo (@sinfos) {
$script = &get_script($sinfo->{'name'});
$path = $sinfo->{'url'};
$path =~ s/^(http|https):\/\/([^\/]+)//;
$path ||= $sinfo->{'path'};
printf $fmt, $sinfo->{'name'},
$sinfo->{'already'} ? "Existing" : "New",
$sinfo->{'version'},
$path;
}
}
}
if (!$testmode) {
foreach my $sinfo (@sinfos) {
next if ($sinfo->{'already'});
&add_domain_script($d, $sinfo->{'name'}, $sinfo->{'version'},
$sinfo->{'opts'}, $sinfo->{'desc'},
$sinfo->{'url'}, $sinfo->{'user'},
$sinfo->{'pass'});
}
&virtualmin_api_log(\@OLDARGV, $d);
}
sub usage
{
print "$_[0]\n\n" if ($_[0]);
print "Find scripts manually installed in some virtual server.\n";
print "\n";
print "virtualmin detect-scripts --domain domain.name\n";
print " [--dir directory]\n";
print " [--test]\n";
exit(1);
}