This commit is contained in:
cutemeli
2025-12-22 10:35:30 +00:00
parent 0bfc6c8425
commit 5ce7ca2c5d
38927 changed files with 0 additions and 4594700 deletions

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/action-log.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/admin.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/admin_alias.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/anonftp.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/apache.php

View File

@@ -1,229 +0,0 @@
#!/bin/bash
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
PRODUCT_NAME="psa"
PRODUCT_ROOT_D="/opt/psa"
PRODUCT_RC_D="/etc/init.d"
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export PATH
LD_LIBRARY_PATH=/usr/local/lib:/opt/psa/lib; export LD_LIBRARY_PATH
LANG=C; export LANG
umask 022
# check for root
case "$EUID" in
"0")
;;
*)
echo " $0: This script must be run as root"
echo " Log in as root then run this script again."
echo
exit 1
;;
esac
# library functions
get_pid()
{
local proc_name proc_basename
proc_name="$1"
proc_basename=`basename "$proc_name"`
PID=`ps axww | awk '($5 ~ "('"$proc_name"'|[[(]'"$proc_basename"'[)\\\\]])$") && ($1 > 0) {print $1}'`
echo $PID
}
get_pid_withowner()
{
local proc_name proc_basename owner
proc_name="$1"
owner="$2"
proc_basename=`basename "$proc_name"`
PID=`ps axuww | awk '{if (($1 ~ "$owner") && ($11 ~ "('"$proc_name"'|[[(]'"$proc_basename"'[)\\\\]])$") && ($1 > 0)) {print $2}}'`
echo $PID
}
status()
{
local proc_name="$1"
local pid
pid=`get_pid ${proc_name}`
if [ "X$pid" != "X" ] ; then
echo "${proc_name} (pid $pid) is running..."
return 0
fi
echo "${proc_name} is stopped"
return 1
}
wait_after_stop()
{
PIDS=`echo "$1" | tr ' ' ,`
count=${2:-50}
while [ 0$count -gt 0 ]
do
ps -p $PIDS > /dev/null 2>&1 || break
sleep 1
count=`expr $count - 1`
done
if [ 0$count -eq 0 ]; then
echo "kill remaining processes:"
ps w -p $PIDS 2>/dev/null
kill -9 $1 > /dev/null 2>&1
cleanup_shared_memory
fi
return 0
}
# Remove all semaphores owned by users listed in parameters
cleanup_semaphores()
{
local i n id_n owner_n cmd
# Parse the header and find out on which positions do the owner
# and id appear in ipcs output
n=1
for i in `ipcs -s | awk '$0 !~ /^----/ {s=tolower($0); if (index(s, "id")>0) { print s; exit 0; }}'`; do
if [ "$i" = "id" -o "$i" = "semid" ]; then
id_n='$'$n
fi
if [ "$i" = "owner" ]; then
owner_n='$'$n
fi
n=$(($n+1))
done
if [ "X$id_n" = "X" -o "X$owner_n" = "X" ]; then
echo "WARNING:"
echo "cannot parse ipcs output"
return 1
fi
# Use the parsing results to extract the information with awk and
# remove the selected semaphores
for i in "$@"; do
cmd="`ipcs -s | awk "$owner_n==\\\"$i\\\" { print \\\"-s \\\"$id_n }"`"
if [ -n "$cmd" ]; then
ipcrm $cmd > /dev/null
fi
done
}
# Remove all unused shared memory (whose CPID and LPID are orphaned)
# projects to be excluded are passed as parameters
cleanup_shared_memory()
{
local i n id_n cpid_n lpid_n id cpid lpid exclude_projects exclude_id filter
# Parse the header and find out on which positions do the owner
# and id appear in ipcs output
n=1
for i in `ipcs -m -p | awk '$0 !~ /^----/ {s=tolower($0); if (index(s, "id")>0) { print s; exit 0; } }'`; do
if [ "$i" = "id" -o "$i" = "shmid" ]; then
id_n='$'$n
fi
if [ "$i" = "cpid" ]; then
cpid_n='$'$n
fi
if [ "$i" = "lpid" ]; then
lpid_n='$'$n
fi
n=$(($n+1))
done
if [ "X$id_n" = "X" -o "X$cpid_n" = "X" -o "X$lpid_n" = "X" ]; then
echo "WARNING:"
echo "cannot parse ipcs output"
return 1
fi
# Use the parsing results to extract the information with awk and
# drop the orphaned shared memory resources
if [ $# -ne 0 ]; then
exclude_projects=`echo $* | sed -e 's/ /|^/'`
exclude_id=`ipcs -m | awk 'BEGIN{s=""}END{if(s!="")print s}/^'"$exclude_projects"'/{if(s!="")s=s"|"$2;else s=$2}'`
[ -n "$exclude_id" ] && filter="\$1 !~ /${exclude_id}/ && "
fi
ipcs -m -p | awk "$filter \$3 ~ /[0-9]+/ {print \$1, \$3, \$4}" | while read id cpid lpid; do
if [ ! -d /proc/"$cpid" -a ! -d /proc/"$lpid" ]; then
ipcrm -m "$id" > /dev/null
fi
done
}
cleanup_orphaned_php_fcgi()
{
ps -eo ppid,pid,command | grep -P '^( )+1( )+\d+ .*php.ini$' | awk '{s="kill -9 " $2; system(s);}'
}
warning()
{
file="$1"
service="$2"
echo "WARNING:"
echo "something wrong with file $file"
echo "can't handle $service"
}
stp()
{
service="$1"
echo "$PRODUCT_NAME: $service has been stopped"
}
f_stp()
{
service="$1"
echo "$PRODUCT_NAME: failed to stop $service -- may be it's not running?"
}
rst()
{
service="$1"
echo "$PRODUCT_NAME: $service has been restarted"
}
f_rst()
{
service="$1"
echo "$PRODUCT_NAME: failed to restart $service"
}
strt()
{
service="$1"
echo "$PRODUCT_NAME: $service has been started"
}
f_strt()
{
service="$1"
echo "$PRODUCT_NAME: failed to start $service"
}
grcf()
{
service="$1"
echo "$PRODUCT_NAME: $service has been graceful restarted"
}
f_grcf()
{
service="$1"
echo "$PRODUCT_NAME: failed to graceful restart $service -- may be it's not running?"
}
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
cleanup_semaphores www-data
cleanup_shared_memory 0x62
cleanup_orphaned_php_fcgi

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/aps.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/autoresponder.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/backup-storage.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/branding.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/branding_theme.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/certificate.php

View File

@@ -1 +0,0 @@
../admin/sbin/cfgmon

Binary file not shown.

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/client.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/client_pref.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/cloning.php

View File

@@ -1,6 +0,0 @@
#!/bin/sh
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
# vim:ft=sh
# print coma-separated list of cpu model names.
perl -W -nale '/^model name\s*: (.*)$/i and $p{$1} = 1 and $cnt++ } { print %p ? (join ", ", sort keys %p) . " ($cnt core(s))" : "Unknown"' /proc/cpuinfo

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/crontab_shell.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/cu_plesk_get_menu.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/custom_plan_items.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/custombutton.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/client.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/database.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/database-server.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/dns.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_addon_service_plan.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_pref.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_restriction.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domalias.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/event_handler.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/extension.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/ftpsubaccount.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/grey_listing.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/hotlink_protection.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/http2_pref.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/http3_pref.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/init_conf.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/interface_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/ip_ban.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/ip_pool.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/ipmanage.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/keyinfo.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/license.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/locales.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/mail.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/maillist.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/mailserver.php

View File

@@ -1,38 +0,0 @@
#!/bin/bash -e
### Copyright 1999-2023. Plesk International GmbH. All rights reserved.
# pm_Hook_ApiCli doesn't support short options, this wrapper emulates old behavior
OPTS=()
IS_VALUE_EXPECTED=
for opt in "$@"; do
if [ -n "$IS_VALUE_EXPECTED" ]; then
OPTS+=("$opt")
IS_VALUE_EXPECTED=
continue
fi
case "$opt" in
-a) OPTS+=(--apply) ;;
-c) OPTS+=(--confirm) ;;
-d) OPTS+=(--disable) ;;
-e) OPTS+=(--enable) ;;
-r) OPTS+=(--reset) ;;
-s) OPTS+=(--set-rule) ;;
-h) OPTS+=(--help) ;;
-n) OPTS+=(-name); IS_VALUE_EXPECTED="yes" ;;
-p) OPTS+=(-ports); IS_VALUE_EXPECTED="yes" ;;
*)
OPTS+=("$opt")
case "$opt" in
--remove-rules)
IS_VALUE_EXPECTED="yes" ;;
-id|-name|-direction|-action|-ports|-remote-addresses|-from|-to|-ids|-config)
IS_VALUE_EXPECTED="yes" ;;
esac
;;
esac
done
exec /usr/sbin/plesk ext firewall "${OPTS[@]}"

View File

@@ -1 +0,0 @@
../admin/sbin/mysqldump.sh

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/nginx.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/notification.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/optimization_settings.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/interface_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/passwords.php

View File

@@ -1 +0,0 @@
/usr/bin/php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/php_handler.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/php_settings.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/pleskbackup.php

View File

@@ -1 +0,0 @@
../admin/plib/backup/pleskrestore.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/poweruser.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/product_info.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/protdir.php

Binary file not shown.

View File

@@ -1,41 +0,0 @@
#!/usr/bin/env bash
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
PN=$(basename "$0")
help()
{
cat << EOF
Plesk reconfigurator - utility to change IP addresses used by Plesk
Usage: $PN { <map_file> | --autoconfigure | --remap-ips | --help }
If <map_file> doesn't exists - template will be created, otherwise it will be used to map IP addresses.
--autoconfigure option will attempt to create and process IP mapping automatically. Any new excessive
or old unmapped IP addresses will retain their status and would need to be handled manually either by
rereading IP addresses or by passing a correct map file to this utility.
--remap-ips is an alias for --autoconfigure option.
--help option displays this help page.
EOF
}
main()
{
# shellcheck disable=SC2016
echo '`plesk bin ipmanage` should be used instead of this utility' >&2
if [ "$1" = "--autoconfigure" ] || [ "$1" = "--remap-ips" ]; then
"/opt/psa/bin/ipmanage" --auto-remap
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
help
exit 1
else
"/opt/psa/bin/ipmanage" --remap "$@"
fi
exit $?
}
main "$@"

View File

@@ -1 +0,0 @@
reconfigurator

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/repair.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/report.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/reseller.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/reseller_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/reseller_pref.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/reseller_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/reseller_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/role.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/scheduled-backup.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/scheduler.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/secret_key.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/server_dns.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/server_pref.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/service.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/service_node.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_template.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_addon_service_plan.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/settings.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/site.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/skeleton.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/spamassassin.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/subdomain.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/subscription.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/domain_pref.php

Binary file not shown.

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/task-manager.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/traffic.php

View File

@@ -1,555 +0,0 @@
#!/usr/bin/perl
# Copyright 1999-2025. WebPros International GmbH. All rights reserved.
#########################################################################################################################
# #
# transvhost.pl - Utility change HTTPD_VHOSTS_D psa.conf value: moves content and corrects database and config files. #
# #
#########################################################################################################################
use strict;
use warnings;
use File::Find ();
use File::Temp qw(tempfile);
use IO::File;
use JSON::XS;
use vars qw($newVhostsPath $oldVhostsPath %config %domainHash %statHash %logRotHash);
$ENV{"LC_ALL"}="C";
my %arg_opts = ('--help|-h'=>'',
'--dest-dir|-d'=>'s',
'--correct-scripts'=>'',
);
my $ptrArgs = getArguments(\@ARGV,\%arg_opts);
if (exists $ptrArgs->{'help'}){
printHelp($0);
exit(0);
}
if (!exists $ptrArgs->{'dest-dir'}) {
printf ("You should specify destination directory.\n");
printHelp($0);
exit(2);
}
read_config();
$oldVhostsPath = $config{HTTPD_VHOSTS_D};
$newVhostsPath = $ptrArgs->{'dest-dir'};
if ($newVhostsPath =~ m/\/$/){
# remove slash at the end of path
($newVhostsPath) = $newVhostsPath =~ m/^(.*)\/$/;
}
my $getenforce = '/usr/sbin/getenforce';
if (-x $getenforce and `$getenforce` =~ /Enforcing/i) {
print STDERR "Before transferring virtual hosts' content, disable SELinux " .
"or set it to permissive mode and keep it that way to avoid breaking your websites.\n";
print STDERR "Read more: " .
"https://support.plesk.com/hc/en-us/articles/12377953257111-How-to-change-virtual-hosts-location-in-Plesk-for-Linux\n";
exit(1);
}
detectFileSystem();
correctPhpFpmPools();
fail2BanInstalled() and corrertFail2BanApacheJails();
correctDb();
reconfigureAps();
if(system($config{WEBSERV} . " --reconfigure-all > /dev/null") !=0) {
printf("Can`t reconfigure web server \n");
}
if(system($config{FTPSERV} . " --reconfigure-all > /dev/null") !=0) {
printf("Can`t reconfigure ftp server \n");
}
createDomainHash();
createLogRotHash();
correctPhpIniFiles();
foreach my $domain (keys %statHash) {
system($config{WEBSTAT}. " --unset-configs --stat-prog=$statHash{$domain} --domain-name=$domain");
system($config{WEBSTAT}. " --set-configs --stat-prog=$statHash{$domain} --domain-name=$domain < /dev/null");
}
foreach my $domain (keys %logRotHash) {
system($config{LOGROT}. " $domain off $logRotHash{$domain}");
system($config{LOGROT}. " $domain on $logRotHash{$domain}");
}
if (exists $ptrArgs->{'correct-scripts'}) {
if (correctScripts()!=0){
exit -1;
}
exit 0;
}
exit 0;
sub read_config {
open FCONF, "< /etc/psa/psa.conf"
or die "Can't open Plesk configurational file\n";
while (<FCONF>) {
s/\#.*$//;
m/^\s*(\w+)\s+(.+?)\s*$/;
next unless $1;
$config{$1} = $2;
}
close FCONF;
# prepare temporary file with mysql login and password
# that will be kept until the finish of the util execution
my ($myExtFH, $myExtFN) = tempfile(UNLINK => 1);
print $myExtFH "[client]\n";
print $myExtFH "user=admin\n";
print $myExtFH "password=";
close $myExtFH;
0 == system("cat /etc/psa/.psa.shadow >> \"$myExtFN\"")
or die "Can't get Plesk administrator's password\n";
if (-x $config{MYSQL_BIN_D}.'/mariadb') {
$config{MYSQL} = $config{MYSQL_BIN_D}."/mariadb --defaults-extra-file=\"$myExtFN\" -s -N -Dpsa";
} else {
$config{MYSQL} = $config{MYSQL_BIN_D}."/mysql --defaults-extra-file=\"$myExtFN\" -s -N -Dpsa";
}
if (-e '/etc/SuSE-release' or -e '/etc/debian_version') {
$config{MYSQL_SCRIPT} = $config{PRODUCT_RC_D} . '/mysql';
} else {
$config{MYSQL_SCRIPT} = $config{PRODUCT_RC_D} . '/mysqld';
}
$config{WEBSERV} = $config{PRODUCT_ROOT_D}.'/admin/bin/httpdmng';
$config{FTPSERV} = $config{PRODUCT_ROOT_D}.'/admin/bin/ftpmng';
$config{WEBSTAT} = $config{PRODUCT_ROOT_D}.'/admin/bin/webstatmng';
$config{LOGROT} = $config{PRODUCT_ROOT_D}.'/admin/bin/logrot_mng';
return 0;
}
sub find(&@) { &File::Find::find }
sub correctFileSystem{
if ($newVhostsPath eq $oldVhostsPath) {
print "Server is already configured.\n";
exit 0;
}
print "Moving files to new directory...\n";
my $mkdir = `mkdir -p $newVhostsPath` if (! -d '$newVhostsPath');
system("mv $oldVhostsPath/* $oldVhostsPath/\.* $newVhostsPath 2>/dev/null");
#correct psa.conf
my $psaSed = "-e \"s|$oldVhostsPath|$newVhostsPath|g\"";
print "Correct psa configuration file...\n";
system("sed $psaSed /etc/psa/psa.conf > /etc/psa/psa.conf.new");
system("cp /etc/psa/psa.conf.new /etc/psa/psa.conf");
if ($? == 0) {
unlink "/etc/psa/psa.conf.new";
}
#correct /etc/passwd
print "Correct passwd file...\n";
system("sed $psaSed /etc/passwd > /etc/passwd.new");
system("cp /etc/passwd.new /etc/passwd");
if ($? == 0) {
unlink "/etc/passwd.new";
}
setDirtyFlag();
return 0;
}
sub createLogRotHash {
my $query = "select d.name, l.turned_on, l.period_type, l.period, l.max_number_of_logfiles, l.compress_enable, l.email from domains d, hosting h, log_rotation l, dom_param dp where d.htype='vrt_hst' and d.id=dp.dom_id and dp.val=l.id";
my $state;
my $command = $config{MYSQL}." -e \"$query\"";
open (QUERY, "$command |");
while (<QUERY>){
if (m/([\S]+)\s([\S]+)\s([\S]+)\s([\S]+)\s([\S]+)\s([\S]+)\s(.*)/){
next if ($2 eq 'false');
$logRotHash{$1} = join(" ", $3, $4, $5, $6, $7);
}
}
close (QUERY);
}
sub createDomainHash {
my $query = "SELECT d.id, d.name, h.webstat FROM domains d LEFT JOIN hosting h ON d.id=h.dom_id WHERE d.htype='vrt_hst'";
my $command = $config{MYSQL}." -e \"$query\"";
open (QUERY, "$command |");
while (<QUERY>){
if (m/([\S]+)\s([\S]+)\s([\S]+)/){
$domainHash{$2} = $1;
next if $3 eq 'none';
$statHash{$2} = $3;
}
}
close (QUERY);
}
sub correctDb {
my ($query, $command);
print "Correct database...\n";
print "Update hosting settings...\n";
$query = "UPDATE hosting SET www_root = REPLACE(www_root, '$oldVhostsPath', '$newVhostsPath')";
$command = $config{MYSQL}." -e \"$query\"";
system($command);
print "done\n";
print "Update subdomains settings...\n";
$query = "UPDATE subdomains SET www_root = REPLACE(www_root, '$oldVhostsPath', '$newVhostsPath')";
$command = $config{MYSQL}." -e \"$query\"";
system($command);
print "done\n";
print "Update system users settings...\n";
$query = "UPDATE sys_users SET home = REPLACE(home, '$oldVhostsPath', '$newVhostsPath')";
$command = $config{MYSQL}." -e \"$query\"";
system($command);
print "done\n";
print "Update aps resources parameters...\n";
$query = "UPDATE apsResourcesParameters SET value = REPLACE(value, '$oldVhostsPath', '$newVhostsPath')";
$command = $config{MYSQL}." -e \"$query\"";
system($command);
print "done\n";
$command = $config{PRODUCT_ROOT_D}."/bin/sw-engine-pleskrun ".$config{PRODUCT_ROOT_D}."/admin/plib/api-cli/service_node.php --update local";
system($command);
}
sub reconfigureAps{
print "Reconfigure aps applications...\n";
my $command = $config{PRODUCT_ROOT_D}."/bin/sw-engine-pleskrun ".$config{PRODUCT_ROOT_D}."/admin/plib/api-cli/aps.php --reconfigure-all";
system($command);
print "done\n";
}
sub check_mysql() {
printf("Attempting to connect to MySQL: ");
my $res = system($config{MYSQL} . " -e '' 2> /dev/null");
printf("%s\n", ($res ? "failed" : "ok"));
return $res;
}
sub correctFile($) {
my $file = shift;
open(my $fh, "+<$file") or die "Cannot open file: $! : $file .\n";
my $out = '';
while (<$fh>) {
s/$oldVhostsPath(?![\w\.])/$newVhostsPath/g;
$out .= $_;
}
seek($fh, 0, 0);
print $fh $out;
truncate($fh, tell($fh));
close($fh);
}
sub correctScripts{
unless (-d $newVhostsPath){
print "Directory $newVhostsPath does not exist.\n";
return -1;
}
print "Correct user scripts...\n";
my @skip_dirs = qw/bin dev lib usr/;
foreach my $domain (keys(%domainHash), "default") {
my @files;
if (-e "$newVhostsPath/$domain"){
find { push @files, $File::Find::name if -e } "$newVhostsPath/$domain";
FILE: foreach my $file (@files) {
next FILE if (-d $file or # Skip directories
-S $file or # and sockets (e.g. .plesk/php-fpm.sock)
-B $file or # and binary files.
-l $file); # I'm not sure that I want to follow symlinks.
# Also skip httpd autogenerated configs except vhost.conf and vhost_ssl.conf
next FILE if ( $file =~ m{^$newVhostsPath/$domain/.plesk/conf/}
and $file !~ m{^$newVhostsPath/$domain/.plesk/conf/(vhost|vhost_ssl)\.conf$} );
foreach my $skip_d (@skip_dirs) {
next FILE if $file =~ m{^$newVhostsPath/$domain/$skip_d/};
}
correctFile($file);
}
}
}
return 0;
}
sub correctPhpFpmPools {
print "Correct php-fpm pools configuration...\n";
my $cmd = $config{PRODUCT_ROOT_D} . "/admin/sbin/php_handlers_control --list-json";
my $php_handlers_json = qx{$cmd};
if ($?) {
print STDERR "Failed to read list of php handlers ($?). Continue.";
return;
}
my $handlers_data_ref = decode_json $php_handlers_json;
unless($handlers_data_ref) {
print STDERR "Failed to parse json data: $php_handlers_json. Continue.";
return;
}
my @fpms = grep {$_->{type} eq "fpm" } @{$handlers_data_ref->{php}};
for my $fpm(@fpms) {
correctPhpFpm($fpm->{service}, $fpm->{poold});
}
}
sub correctPhpFpm {
my ($service, @pool_dirs) = @_;
my $configuration_changed = 0;
for my $fpm_dir(@pool_dirs) {
next unless -d $fpm_dir;
opendir(my $dh, $fpm_dir) or die "Cannot open directory: $! : $fpm_dir .\n";
while (defined( my $file = readdir($dh) )) {
next unless $file =~ /(?<!^www)\.conf$/;
correctFile("$fpm_dir/$file");
$configuration_changed = 1;
}
closedir($dh);
}
if ($configuration_changed) {
my $fpm_service_name = $service || "php-fpm";
print "Restart $fpm_service_name service...\n";
my $command = $config{PRODUCT_ROOT_D}."/admin/sbin/pleskrc \"$service\" try-reload";
system($command);
}
}
sub correctPhpIniFiles {
foreach my $domain (keys %statHash) {
my $phpIniFile = $newVhostsPath."/system/".$domain."/etc/php.ini";
next unless -f $phpIniFile;
correctFile($phpIniFile);
}
}
sub setDirtyFlag {
my $packagemng = $config{PRODUCT_ROOT_D} . "/admin/sbin/packagemng";
system("$packagemng --set-dirty-flag");
}
sub fail2BanInstalled {
my $packagemng = $config{PRODUCT_ROOT_D} . "/admin/sbin/packagemng";
my @f2b_status = grep { /^fail2ban:\S+\s*$/ } `$packagemng --list`;
return scalar(@f2b_status) > 0;
}
sub corrertFail2BanApacheJails {
print "Correct Fail2Ban jails configuration...\n";
my $f2bmng = $config{PRODUCT_ROOT_D} . "/admin/sbin/f2bmng";
my @jails = ('plesk-apache', 'plesk-apache-badbot');
JAIL: for my $jail ( @jails ) {
open my $f2b_get, "$f2bmng --get-jail=$jail |" or do {
print "Unable to get jail $jail configuration: $!";
next JAIL
};
my $jail_config = <$f2b_get>;
close $f2b_get;
$jail_config =~ s#(\s"|\\n)\Q$oldVhostsPath\E/#$1$newVhostsPath/#g;
open my $f2b_set, "| $f2bmng --set-jail=$jail" or do {
print "Unable to set jail $jail configuration: $!";
next JAIL
};
print $f2b_set $jail_config;
close $f2b_set;
}
}
sub detectFileSystem {
my %pseudofs = ('autofs' => 1,
'binfmt_misc' => 1,
'cd9660' => 1,
'devfs' => 1,
'devpts' => 1,
'fdescfs' => 1,
'iso9660' => 1,
'linprocfs' => 1,
'proc' => 1,
'procfs' => 1,
'romfs' => 1,
'sysfs' => 1,
'tmpfs' => 1,
'usbdevfs' => 1,
'usbfs' => 1,
'rpc_pipefs' => 1,
);
my $mkdir = `mkdir -p $newVhostsPath` if (! -d "$newVhostsPath");
my %partitions;
foreach my $mountinfo (`mount`) {
chomp $mountinfo;
#unable to use 'undef' here - perl 5.004 compatibility
my ($device, $undef, $mountpoint, $undef1, $type, $options) = split /\s+/, $mountinfo;
my $mode = 'rw';
$mode = 'ro' if ($options =~ /[(,]ro[,)]/);
unless (defined $pseudofs{$type}) {
$partitions{$mountpoint} = ();
$partitions{$mountpoint}->{'device'} = $device;
$partitions{$mountpoint}->{'mode'} = $mode;
$partitions{$mountpoint}->{'type'} = $type;
}
}
foreach my $dfinfo (`LANG=C POSIXLY_CORRECT= df -Pk | tail -n +2`) {
chomp $dfinfo;
#unable to use 'undef' here - perl 5.004 compatibility
my ($undef, $size, $undef1, $free, $undef2, $mountpoint) = split /\s+/, $dfinfo;
if (exists $partitions{$mountpoint}) {
# for brain-dead NFS shares:
$free = $size if $free > $size;
$partitions{$mountpoint}->{'size'} = $size;
$partitions{$mountpoint}->{'free'} = $free;
}
}
my $buf = `LANG=C POSIXLY_CORRECT= df -P $oldVhostsPath | tail -n +2`;
my ($undef, $oldmountpoint, $newmountpoint);
($undef, $undef, $undef, $undef, $undef, $oldmountpoint) = split /\s+/, $buf;
$buf = `LANG=C POSIXLY_CORRECT= df -P $newVhostsPath | tail -n +2`;
($undef, $undef, $undef, $undef, $undef, $newmountpoint) = split /\s+/, $buf;
if ($oldmountpoint ne $newmountpoint){
my $du = `du -k $oldVhostsPath | tail -n 1`;
chomp $du;
my ($oldSize,$undef) = split /\s+/,$du;
if (!exists $partitions{$newmountpoint}) {
print "Partition $newmountpoint uses unsupported filesystem.\n";
exit 1;
} elsif ($oldSize < $partitions{$newmountpoint}->{'free'}) {
correctFileSystem();
}else{
print "Partition $newmountpoint has not enough free space.\n";
exit 1;
}
}else{
correctFileSystem();
}
}
sub getArguments {
my ($ptrArgv,$ptrOpts) = @_;
my (@keys,$firstKey,%prepKeys,$key,$value,$ptrArr,$arg,$state);
my (%retHash,$pat,$found,$used,@rest,$fullArg,$prevKey);
while (($key,$value)=each(%{$ptrOpts})){
@keys = split(/\|/,$key);
$firstKey = $keys[0];
$firstKey =~s/^-*//;
push @{$prepKeys{$firstKey}},[@keys];
push @{$prepKeys{$firstKey}},$value;
}
$state =0;
foreach $arg (@{$ptrArgv}){
$used = 0;
if($state==1){
if ($arg =~ /^-/){
$state=0;
}else{
$used = 1;
$retHash{$prevKey}=$arg;
next;
}
}
if ($state == 2){
$retHash{$prevKey}=$arg;
$state = 0;
$used = 1;
}else{
$fullArg = $arg;
if ($arg =~ /^(-\S+)=(.+)/s){
$arg = $1;
$value = $2;
}else{
$value = undef;
}
foreach $key (keys %prepKeys){
$ptrArr = $prepKeys{$key};
$found = 0;
foreach $pat (@{$ptrArr->[0]}){
if ($pat eq $arg){
$found = 1;
last;
}
}
if($found){
$used = 1;
if(defined($value)){
$retHash{$key}=$value;
}else{
if($ptrArr->[1]){
if($ptrArr->[1] =~ /\?$/){
$state = 1;
}else{
$state = 2;
}
$prevKey = $key;
}else{
$retHash{$key}=undef;
}
}
last;
}
}
}
unless($used){
if($value){
push @rest,$fullArg;
}else{
push @rest,$arg;
}
}
}
@{$ptrArgv}=@rest;
return \%retHash;
}
sub printHelp {
my ($progname)=@_;
my $help = <<HELP;
Utility to transfer vhosts content from HTTPD_VHOSTS_D directory to new place.
Usage:
--dest-dir <path> Destination path. Path to new vhosts directory.
Example: /path/to/new/vhosts.
If directory does not exist it will be created.
--correct-scripts Changes user scripts.
Old vhost path is replaced to new path in content of all files.
HELP
printf($help);
}
# vim:set et ts=4 sts=4 sw=4:

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/turboaddr.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/user.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/virtdir.php

View File

@@ -1 +0,0 @@
../admin/plib/api-cli/webstat.php

Some files were not shown because too many files have changed in this diff Show More