scripts/cl-common000064400000010342150043173220010037 0ustar00#!/bin/bash # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2018 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT ################################################## # Common functions # ################################################## VERSION="2.0" common_current_date=`date +%Y-%m-%d` function getLogFile(){ #1 - common path if [ ! -e "$1/logs" ];then mkdir -p "$1/logs" fi current_date_time=`date +"%Y-%m-%d %k:%M:%S"` echo "$1/logs/$common_current_date.log" } function writeToLog(){ #1 - message #2 - common path if [ ! -e "$2/logs" ];then mkdir -p "$2/logs" fi current_date_time=`date +"%Y-%m-%d %k:%M:%S"` prg=`basename "$0"` echo "[$current_date_time from $prg] $1" >> "$2/logs/$common_current_date.log" } function writeFileToLog(){ #1 - file path #2 - common path if [ ! -e "$2/logs" ];then mkdir -p "$2/logs" fi current_date_time=`date +"%Y-%m-%d %k:%M:%S"` prg=`basename "$0"` echo "[$current_date_time from $prg] ----------------File Content $1 BEG---------------" >> "$2/logs/$common_current_date.log" if [ -e "$1" ];then cat $1 >> "$2/logs/$common_current_date.log" fi echo "[$current_date_time from $prg] ----------------File Content $1 End---------------" >> "$2/logs/$common_current_date.log" } function removeEmptyStringsFromFile(){ filename="$1" res=`sed -e '/^$/d' $filename` echo "$res" > $filename } function deleteAllExcept(){ #1 - hook #2 - tmp name #3 - pattern #4 - common path if [ ! -e "$4/tmp" ]; then mkdir -p "$4/tmp" fi if [ -e "$1" ];then cat "$1" | sed -n "$3" > "$4/tmp/$2.tmp.$$" echo "#!/bin/bash" > "$1" cat "$4/tmp/$2.tmp.$$" >> "$1" rm -f "$4/tmp/$2.tmp.$$" fi } function deleteAllInclude(){ #1 - hook #2 - tmp name #3 - pattern #4 - common path if [ ! -e "$4/tmp" ]; then mkdir -p "$4/tmp" fi if [ -e "$1" ];then cat "$1" | sed "$3" > "$4/tmp/$2.tmp.$$" cat "$4/tmp/$2.tmp.$$" > "$1" rm -f "$4/tmp/$2.tmp.$$" fi } function showBar { nmb=$(cat $0 | grep showBar | wc -l) let "nmb = $nmb" let "prct = $1 * 30 / $nmb" let "prct_n = $1 * 100 / $nmb" prg=`basename "$0"` echo -n "$prg: [" >&2 for bar in {1..30} do if [ $bar -le $prct ];then echo -n "#" >&2 else echo -n " " >&2 fi done echo -ne "] ($prct_n%)\r" >&2 } function get_command(){ command=$(which $1) if [ $? != 0 ]; then writeToLog "Can't execute command $1..." exit 1; fi echo $command } function createHookHeader(){ #1 - hook name #2 - modificator #3 - common path if [ ! -e "$3/tmp" ]; then mkdir -p "$3/tmp" fi if [ ! -e "$1" ]; then echo "#!/bin/bash" > "$1" chmod 755 "$1" else chmod 755 "$1" tmp=`/bin/sed -n '/#\!\/bin\/\(ba\)\?sh/p' "$1"` if [ -z "$tmp" ];then /bin/grep -q "$1.$2.bak" "$1" if [ $? = 1 ];then mv -f "$1" "$1.$2.bak" echo "#!/bin/bash" > "$1" echo "$1.$2.bak"' "$@"' >> "$1" chmod 755 "$1" chmod 755 "$1.$2.bak" fi fi fi } function checkHookString(){ #1 - hook name #2 - pattern string #3 - comment srting if [ -e "$1" ];then tmp=`cat "$1" | grep "$2"` if [ -z "$tmp" ];then echo "$2 #$3" >> $1 fi fi } function addHookStringFirst(){ #1 - hook name #2 - pattern string #3 - comment srting #4 - short hook name #5 - common path if [ -e "$1" ];then cat $1 | sed /$4/d | sed 1a"$2 #$3" > "$5/tmp/future_hook.tmp.$$" cat "$5/tmp/future_hook.tmp.$$" > "$1" rm -f "$5/tmp/future_hook.tmp.$$" fi } function getEasyApacheDir(){ if [ -e /usr/home/cpeasyapache ]; then echo "/usr/home/cpeasyapache" elif [ -e /home/cpeasyapache ]; then echo "/home/cpeasyapache" else echo "/var/cpanel/cpeasyapache" fi } function is_ea4(){ if [ -e '/etc/cpanel/ea4/is_ea4' ]; then return 0 else return 1 fi } scripts/cl_sysctl000064400000011014150043173220010147 0ustar00#!/opt/cloudlinux/venv/bin/python3 -bb # coding: utf-8 # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2018 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT import fcntl import sys import time import os from argparse import ArgumentParser from clcommon.sysctl import SysCtlConf, SysCtlMigrate, SYSCTL_CL_CONF_FILE, SYSCTL_FILE SELF_LOCK_FILE = '/var/log/cl_sysctl.lock' def create_parser(): config_help = 'Path to sysctl config file. It\'s %(default)s by default' config_path = SYSCTL_CL_CONF_FILE parser = ArgumentParser(description='Utility for working with sysctl configs. INTERNAL USAGE ONLY!') subparsers = parser.add_subparsers(dest='command') subparser_set = subparsers.add_parser(name='set', help='Set or add the the sysctl parameter to the sysctl config') subparser_set.add_argument('-P', '--parameter', action='store', required=True, help='Name of the sysctl parameter') subparser_set.add_argument('-V', '--value', action='store', required=True, help='Value of the sysctl parameter') subparser_set.add_argument('-C', '--config', action='store', help=config_help, default=config_path) subparser_get = subparsers.add_parser(name='get', help='Get the sysctl parameter') subparser_get.add_argument('-P', '--parameter', action='store', required=True, help='Name of the sysctl parameter') subparser_get.add_argument('-C', '--config', action='store', help=config_help, default=config_path) subparser_remove = subparsers.add_parser(name='remove', help='Remove the sysctl parameter from the sysctl config') subparser_remove.add_argument('-P', '--parameter', action='store', required=True, help='Name of the sysctl parameter') subparser_remove.add_argument('-C', '--config', action='store', help=config_help, default=config_path) subparsers_migrate = subparsers.add_parser(name='migrate', help='Migrate sysctl param from {} to {}'.format( SYSCTL_FILE, SYSCTL_CL_CONF_FILE, )) subparsers_migrate.add_argument('-P', '--parameter', action='store', required=True, help='Name of the sysctl parameter') subparsers_migrate.add_argument('-dV', '--default-value', action='store', help='Default value of sysctl parameter if it is absent in source file') return parser def _parse_args(argv): parser = create_parser() params = parser.parse_args(argv) return params def main_(args): params = _parse_args(args) command = params.command if command == 'set': config_file = params.config sysctl = SysCtlConf(config_file=config_file) sysctl.set(name=params.parameter, value=params.value) elif command == 'get': config_file = params.config sysctl = SysCtlConf(config_file=config_file) value = sysctl.get(name=params.parameter) print(value) elif command == 'remove': config_file = params.config sysctl = SysCtlConf(config_file=config_file) sysctl.remove(name=params.parameter) elif command == 'migrate': sysctl_migrate = SysCtlMigrate() sysctl_migrate.migrate( param_name=params.parameter, default_value=params.default_value, ) def main(): with open(SELF_LOCK_FILE, 'w') as lock_file: lock_file_is_locked = True for _ in range(20): try: fcntl.flock(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB) lock_file_is_locked = False break except IOError: print('Another app is currently holding the cl_sysctl lock; waiting for it to exit.') time.sleep(5) if lock_file_is_locked: print('Another app is still holding the cl_sysctl lock after 20 attempts. Please, try again later.') exit(1) else: main_(sys.argv[1:]) try: os.remove(SELF_LOCK_FILE) except (IOError, OSError): pass if __name__ == '__main__': main() scripts/cpanel-dbmapping000075500000007525150043173220011370 0ustar00#!/bin/bash # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2018 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;' if 0; #!/usr/bin/perl #BEGIN { unshift @INC, '/scripts'; } BEGIN { unshift @INC, '/usr/local/cpanel', '/scripts'; } my $pckg_name = 'Cpanel'; use strict; use warnings; eval "use " .$pckg_name . "::Config::Users ();"; if ($@){ $pckg_name = 'cPScript'; eval "use " .$pckg_name . "::Config::Users ();"; } #eval "use " .$pckg_name . "::Config::Users ();"; eval "use " .$pckg_name . "::DB::Map ();"; eval "use " .$pckg_name . "::DB ();"; use Data::Dumper; my @old = (); my @new = (); my @copy_new = (); my $noSystemUsers = ($#ARGV >= 0 && $ARGV[0] eq "--nosys"); if ($noSystemUsers) { shift @ARGV; } my $numArgs = $#ARGV + 1; if($numArgs>0){ foreach my $mb (@ARGV) { if($mb>0){ my $uname_1 = getpwuid($mb); @new = get_map_list_user_($uname_1); foreach my $item (@new){ my $fnd = 0; foreach my $item2 (@old){ if (($$item[0] eq $$item2[0]) && ($$item[1] eq $$item2[1])){ $fnd = 1; last; } } if($fnd==0){ push @old, $item; } } } } foreach my $item (@old){ print $$item[0], " ", $$item[1], " ", $$item[2], "\n"; } } else { @new = get_map_list_(); @copy_new = map { [@$_] } @new; my @del_list = (); my @del_list2 = (); my $i=0; my $j=0; foreach my $item (@new){ $j=0; my $del = 0; foreach my $item2 (@old){ if (($$item[0] eq $$item2[0]) && ($$item[1] eq $$item2[1])){ push @del_list, $j; $del = 1; } $j++; } if($del==1){ push @del_list2, $i; } $i++; } foreach my $item (@del_list){ delete $old[$item]; } foreach my $item (@del_list2){ delete $new[$item]; } @old = grep {$_} @old; @new = grep {$_} @new; my $cnt_old = @old; my $cnt_new = @new; if($cnt_old>0 || $cnt_new>0){ foreach my $item (@copy_new){ print $$item[0], " ", $$item[1], " ", $$item[2], "\n"; } } } sub get_map_list_ { my @arr = (); my @users =Cpanel::Config::Users::getcpusers(); foreach my $user (@users) { my $user_map1 = Cpanel::DB::get_map ( {'cpuser' => $user} ); my $name=""; my $uid= -1; my $dummy; ($name, $dummy, $uid, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy) = getpwnam($user); if ($uid>=0 && !$noSystemUsers){ push @arr, [ $user, $user, "$uid" ]; } if ($uid>=0 && exists($$user_map1{'stash'}{'MYSQL'}{'dbusers'})){ for my $key (keys %{$$user_map1{'stash'}{'MYSQL'}{'dbusers'}}) { push @arr, [ $key, $user, "$uid" ]; } } } return @arr; } sub get_map_list_user_ { my @arr = (); my $user = shift; my $user_map1 = Cpanel::DB::get_map ( {'cpuser' => $user} ); my $name = ""; my $uid = -1; my $dummy; ($name, $dummy, $uid, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy) = getpwnam($user); if ($uid>=0 && !$noSystemUsers){ push @arr, [ $user, $user, "$uid" ]; } if ($uid>=0 && exists($$user_map1{'stash'}{'MYSQL'}{'dbusers'})){ for my $key (keys %{$$user_map1{'stash'}{'MYSQL'}{'dbusers'}}) { push @arr, [ $key, $user, "$uid" ]; } } return @arr; } scripts/da_suid_caller.py000064400000001256150043173220011540 0ustar00# coding: utf-8 # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT import sys import json import pwd import traceback from clcommon.cpapi.plugins.directadmin import userdomains from clcommon.cpapi.cpapiexceptions import NoPanelUser try: uid = int(sys.argv[1]) user_name = pwd.getpwuid(uid).pw_name res = userdomains(user_name, as_root=True) print(json.dumps(res)) sys.exit(0) except (NoPanelUser, KeyError): print(json.dumps({})) sys.exit(11) except Exception: print(json.dumps(traceback.format_exc())) sys.exit(10) scripts/getpaneluserscount000064400000001342150043173220012105 0ustar00#!/opt/cloudlinux/venv/bin/python3 -bb # -*- coding: utf-8 -*- # Utility to get panel users. This utility will be run by cron # # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENCE.TXT import os from clcommon.cpapi import count_hosting_accounts from clcommon.cpapi.GeneralPanel.general_panel import PANEL_USERS_COUNT_FILE from secureio import write_file_via_tempfile if __name__ == '__main__': os.makedirs(os.path.dirname(PANEL_USERS_COUNT_FILE), exist_ok=True) write_file_via_tempfile( content=str(count_hosting_accounts()), dest_path=PANEL_USERS_COUNT_FILE, perm=0o644, ) scripts/plesk_suid_caller.py000064400000001611150043173220012265 0ustar00# coding: utf-8 # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT import sys import json import traceback from clcommon import ClPwd from clcommon.cpapi.plugins.plesk import userdomains from clcommon.cpapi.cpapiexceptions import NoPanelUser try: uid = int(sys.argv[1]) _clpwd = ClPwd() pwd_list = _clpwd.get_pw_by_uid(uid) for user_pwd in pwd_list: username = user_pwd.pw_name try: res = userdomains(username, as_root=True) print(json.dumps(res)) sys.exit(0) except NoPanelUser: pass print(json.dumps({})) sys.exit(0) except (NoPanelUser, KeyError): print(json.dumps({})) sys.exit(11) except Exception: print(json.dumps(traceback.format_exc())) sys.exit(10)