-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathmass_scripts.cgi
executable file
·185 lines (164 loc) · 4.67 KB
/
mass_scripts.cgi
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
#!/usr/local/bin/perl
# Upgrade some script on multiple servers at once
require './virtual-server-lib.pl';
&ReadParse();
&licence_status();
&error_setup($text{'massscript_err'});
# Parse inputs
($sname, $ver) = split(/\s+/, $in{'script'});
if ($in{'servers_def'}) {
@doms = &list_domains();
}
else {
foreach my $s (&unique(split(/\0/, $in{'servers'}))) {
push(@doms, &get_domain($s));
}
@doms || &error($text{'massscript_enone'});
}
foreach my $d (@doms) {
&can_edit_domain($d) && &can_edit_scripts() ||
&error($text{'edit_ecannot'});
}
# Work out who has it
$script = &get_script($sname);
$canupfunc = $script->{'can_upgrade_func'};
foreach my $d (@doms) {
@got = &list_domain_scripts($d);
@dsinfos = grep { $_->{'name'} eq $sname &&
&compare_versions($_->{'version'}, $ver,
$script) < 0 } @got;
push(@sinfos_anyver, grep { $_->{'name'} eq $sname } @got);
if (defined(&$canupfunc)) {
# Limit to allowable upgrades
@dsinfos = grep { &$canupfunc($_, $ver) } @dsinfos;
}
foreach $sinfo (@dsinfos) {
$sinfo->{'dom'} = $d;
}
push(@sinfos, @dsinfos);
}
@sinfos || @sinfos_anyver || &error($text{'massscript_enone2'});
@sinfos || &error($text{'massscript_enone3'});
&ui_print_unbuffered_header(undef, $text{'massscript_title'}, "");
if ($in{'confirm'}) {
# Doing the upgrade
print &text('massstart_start', $script->{'desc'},
$ver, scalar(@sinfos)),"<p>\n";
# Do each server that has it
foreach $sinfo (@sinfos) {
$d = $sinfo->{'dom'};
&$first_print(&text('massscript_doing', &show_domain_name($d),
$sinfo->{'version'}, $sinfo->{'desc'}));
&$indent_print();
# Fetch needed files
my %gotfiles;
$ferr = &fetch_script_files($script,
$sinfos[0]->{'dom'}, $ver,
$sinfos[0]->{'opts'},
$sinfos[0], \%gotfiles, 1);
if ($ferr) {
&$outdent_print();
&$second_print(&text('massscript_efetch', $ferr));
next;
}
$opts = $sinfo->{'opts'};
if (&compare_versions($sinfo->{'version'}, $ver,
$script) >= 0) {
# Already got it
&$outdent_print();
&$second_print(&text('massscript_ever',
$sinfo->{'version'}));
next;
}
# Install needed packages
&setup_script_packages($script, $d, $ver);
# Get locks
&obtain_lock_web($d);
&obtain_lock_cron($d);
# Check if we have PHP
local $phpver;
if (&indexof("php", @{$script->{'uses'}}) >= 0) {
($phpver, $phperr) = &setup_php_version(
$d, $script, $ver, $opts->{'path'});
if (!$phpver) {
&$second_print($phperr);
next;
}
}
if ($derr = &check_script_depends($script, $d, $ver, $sinfo, $phpver)) {
# Failed depends
&$second_print(&text('massscript_edep', $derr));
next;
}
# Install needed PHP/perl/ruby modules
&setup_script_requirements($d, $script, $ver, $phpver,
$opts) || next;
# Work out login and password
$domuser = $sinfo->{'user'} || $d->{'user'};
$dompass = $sinfo->{'pass'} || $d->{'pass'};
# Go ahead and do it
($ok, $msg, $desc, $url) = &{$script->{'install_func'}}(
$d, $ver, $sinfo->{'opts'}, \%gotfiles, $sinfo,
$domuser, $dompass);
print $msg,"<br>\n";
&$outdent_print();
&release_lock_web($d);
&release_lock_cron($d);
if ($ok) {
# Worked .. record it
&$second_print($text{'setup_done'});
&remove_domain_script($d, $sinfo);
&add_domain_script($d, $sname, $ver,
$sinfo->{'opts'},
$desc, $url,
$sinfo->{'user'}, $sinfo->{'pass'});
}
else {
&$second_print($text{'scripts_failed'});
last if ($in{'fail'});
}
# Clean up any temp files from this script
&cleanup_tempnames();
}
&run_post_actions();
&webmin_log("upgrade", "scripts", scalar(@sinfos));
}
else {
# Tell the user which domains will be done, and let him select
# Build table data
@table = ( );
foreach my $sinfo (@sinfos) {
$path = $sinfo->{'opts'}->{'path'};
$utype = &indexof($sinfo->{'version'},
@{$script->{'versions'}}) > 0 ?
$text{'massscript_upgrade'} : $text{'massscript_update'};
push(@table, [
{ 'type' => 'checkbox',
'name' => 'servers',
'value' => $sinfo->{'dom'}->{'id'},
'checked' => 1 },
&show_domain_name($sinfo->{'dom'}),
$sinfo->{'version'},
$sinfo->{'url'} ?
"<a href='$sinfo->{'url'}' target=_blank>$path</a>" :
$path,
$utype,
]);
}
# Output the table of scripts
print &text('massscript_rusure', $script->{'desc'}, $ver),"<p>\n";
print &ui_form_columns_table(
"mass_scripts.cgi",
[ [ "confirm", $text{'massscript_ok'} ] ],
0,
undef,
[ [ "script", $sname." ".$ver ] ],
[ "", $text{'massscript_dom'},
$text{'massscript_ver'},
$text{'massscript_path'},
$text{'massscript_utype'} ],
100,
\@table,
);
}
&ui_print_footer("", $text{'index_return'});