mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-06-27 16:49:05 +02:00
Merge branch 'stable' of https://github.com/usmannasir/cyberpanel into stable
This commit is contained in:
@@ -194,7 +194,7 @@ fixperms_cyberpanel () {
|
||||
echo "Fixing public_html...."
|
||||
tput sgr0
|
||||
#Fix perms of public_html itself
|
||||
chown "$verbose" "$account":"$account" "$HOMEDIR"/public_html
|
||||
chown "$verbose" "$account":nobody "$HOMEDIR"/public_html
|
||||
chmod "$verbose" 755 "$HOMEDIR"/public_html
|
||||
|
||||
tput bold
|
||||
|
||||
102
cyberpanel.sh
102
cyberpanel.sh
@@ -5,7 +5,7 @@
|
||||
#set -u
|
||||
|
||||
|
||||
#CyberPanel installer script for CentOS 7.X, CentOS 8.X, CloudLinux 7.X, Ubuntu 18.04, Ubuntu 20.04 , Ubuntu 20.10 and AlmaLinux 8.X
|
||||
#CyberPanel installer script for CentOS 7.X, CentOS 8.X, CloudLinux 7.X, RockyLinux 8.X, Ubuntu 18.04, Ubuntu 20.04 , Ubuntu 20.10 and AlmaLinux 8.X
|
||||
#For whoever may edit this script, please follow :
|
||||
#Please use Pre_Install_xxx() and Post_Install_xxx() if you want to something respectively before or after the panel installation
|
||||
#and update below accordingly
|
||||
@@ -16,7 +16,7 @@
|
||||
#Set_Default_Variables() ---> set some default variable for later use
|
||||
#Check_Root() ---> check for root
|
||||
#Check_Server_IP() ---> check for server IP and geolocation at country level
|
||||
#Check_OS() ---> check system , support on centos7/8 ubutnu18/20 and cloudlinux 7 , 8 is untested.
|
||||
#Check_OS() ---> check system , support on centos7/8, rockylinux 8.x , almalinux 8.x ubutnu18/20 and cloudlinux 7 , 8 is untested.
|
||||
#Check_Virtualization() ---> check for virtualizaon , #LXC not supported# , some edit needed on OVZ
|
||||
#Check_Panel() ---> check to make sure no other panel is installed
|
||||
#Check_Process() ---> check no other process like Apache is running
|
||||
@@ -113,7 +113,7 @@ echo -e "\n${1}=${2}\n" >> /tmp/cyberpanel_debug.log
|
||||
Debug_Log2() {
|
||||
Check_Server_IP "$@" >/dev/null 2>&1
|
||||
echo -e "\n${1}" >> /var/log/installLogs.txt
|
||||
curl -d '{"ipAddress": "'"$Server_IP"'", "InstallCyberPanelStatus": "'"$1"'"}' -H "Content-Type: application/json" -X POST https://cloud.cyberpanel.net/servers/RecvData >/dev/null 2>&1
|
||||
curl --max-time 20 -d '{"ipAddress": "'"$Server_IP"'", "InstallCyberPanelStatus": "'"$1"'"}' -H "Content-Type: application/json" -X POST https://cloud.cyberpanel.net/servers/RecvData >/dev/null 2>&1
|
||||
}
|
||||
|
||||
Branch_Check() {
|
||||
@@ -174,7 +174,12 @@ Retry_Command() {
|
||||
# shellcheck disable=SC2034
|
||||
for i in {1..50};
|
||||
do
|
||||
$1 && break || echo -e "\n$1 has failed for $i times\nWait for 3 seconds and try again...\n"; sleep 3;
|
||||
if [[ "$i" = "50" ]] ; then
|
||||
echo "command $1 failed for 50 times, exit..."
|
||||
exit 2
|
||||
else
|
||||
$1 && break || echo -e "\n$1 has failed for $i times\nWait for 3 seconds and try again...\n"; sleep 3;
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -238,6 +243,16 @@ if [[ ! -f /etc/os-release ]] ; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Reference: https://unix.stackexchange.com/questions/116539/how-to-detect-the-desktop-environment-in-a-bash-script
|
||||
if [ -z "$XDG_CURRENT_DESKTOP" ]; then
|
||||
echo -e "Desktop OS not detected. Proceeding\n"
|
||||
else
|
||||
echo "$XDG_CURRENT_DESKTOP defined appears to be a desktop OS. Bailing as CyberPanel is incompatible."
|
||||
echo -e "\nCyberPanel is supported on server OS types only. Such as Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, Ubuntu 20.10 x86_64, CentOS 7.x, CentOS 8.x, AlmaLinux 8.x and CloudLinux 7.x...\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
if ! uname -m | grep -q 64 ; then
|
||||
echo -e "x64 system is required...\n"
|
||||
exit
|
||||
@@ -251,10 +266,12 @@ elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then
|
||||
Server_OS="CloudLinux"
|
||||
elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10" /etc/os-release ; then
|
||||
Server_OS="Ubuntu"
|
||||
elif grep -q -E "Rocky Linux" /etc/os-release ; then
|
||||
Server_OS="RockyLinux"
|
||||
else
|
||||
echo -e "Unable to detect your system..."
|
||||
echo -e "\nCyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, Ubuntu 20.10 x86_64, CentOS 7.x, CentOS 8.x, AlmaLinux 8.x and CloudLinux 7.x...\n"
|
||||
Debug_Log2 "CyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, Ubuntu 20.10 x86_64, CentOS 7.x, CentOS 8.x, AlmaLinux 8.x and CloudLinux 7.x... [404]"
|
||||
echo -e "\nCyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, Ubuntu 20.10 x86_64, CentOS 7.x, CentOS 8.x, AlmaLinux 8.x, RockyLinux 8.x, CloudLinux 7.x, CloudLinux 8.x...\n"
|
||||
Debug_Log2 "CyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, Ubuntu 20.10 x86_64, CentOS 7.x, CentOS 8.x, AlmaLinux 8.x, RockyLinux 8.x, CloudLinux 7.x, CloudLinux 8.x... [404]"
|
||||
exit
|
||||
fi
|
||||
|
||||
@@ -263,10 +280,10 @@ Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' |
|
||||
|
||||
echo -e "System: $Server_OS $Server_OS_Version detected...\n"
|
||||
|
||||
if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] ; then
|
||||
if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] ; then
|
||||
Server_OS="CentOS"
|
||||
#CloudLinux gives version id like 7.8 , 7.9 , so cut it to show first number only
|
||||
#treat CL and Alma as CentOS
|
||||
#treat CL , Rocky and Alma as CentOS
|
||||
fi
|
||||
|
||||
if [[ "$Debug" = "On" ]] ; then
|
||||
@@ -416,7 +433,7 @@ echo -e "\nThis will install LiteSpeed Enterise , replace LICENSE_KEY to actual
|
||||
|
||||
Check_Argument() {
|
||||
if [[ "$#" = "0" ]] || [[ "$#" = "1" && "$1" = "--debug" ]] || [[ "$#" = "1" && "$1" = "--mirror" ]]; then
|
||||
echo -e "\nInitializing...\n"
|
||||
echo -e "\nInitialized...\n"
|
||||
else
|
||||
if [[ $1 = "help" ]]; then
|
||||
Show_Help
|
||||
@@ -464,7 +481,7 @@ else
|
||||
Admin_Pass="1234567"
|
||||
else
|
||||
if [[ ${#1} -lt 8 ]]; then
|
||||
echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n"
|
||||
echo -e "\nPassword length less than 8 digital, please choose a more complicated password.\n"
|
||||
exit
|
||||
fi
|
||||
Admin_Pass="${1}"
|
||||
@@ -563,25 +580,20 @@ echo -e " CyberPanel Installer v$Panel_Version.$Panel_Build
|
||||
|
||||
1. Install CyberPanel.
|
||||
|
||||
2. Addons and Miscellaneous
|
||||
|
||||
3. Exit.
|
||||
2. Exit.
|
||||
|
||||
"
|
||||
read -r -p " Please enter the number[1-3]: " Input_Number
|
||||
read -r -p " Please enter the number[1-2]: " Input_Number
|
||||
echo ""
|
||||
case "$Input_Number" in
|
||||
1)
|
||||
Interactive_Mode_Set_Parameter
|
||||
;;
|
||||
2)
|
||||
Interactive_Mode_Addon
|
||||
;;
|
||||
3)
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
echo -e " Please enter the right number [1-3]\n"
|
||||
echo -e " Please enter the right number [1-2]\n"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
@@ -722,7 +734,7 @@ elif [[ $Tmp_Input =~ ^(s|S) ]]; then
|
||||
exit
|
||||
fi
|
||||
if [[ ${#Tmp_Input} -lt 8 ]]; then
|
||||
echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n"
|
||||
echo -e "\nPassword length less than 8 digital, please choose a more complicated password.\n"
|
||||
exit
|
||||
fi
|
||||
Tmp_Input1=$Tmp_Input
|
||||
@@ -966,7 +978,7 @@ if [[ "$Server_OS" = "CentOS" ]] ; then
|
||||
yum -y groupinstall development
|
||||
Check_Return
|
||||
elif [[ "$Server_OS_Version" = "8" ]] ; then
|
||||
dnf install -y zip wget strace net-tools curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel mariadb-devel curl-devel git platform-python-devel tar socat python3 zip unzip bind-utils
|
||||
dnf install -y libnsl zip wget strace net-tools curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel mariadb-devel curl-devel git platform-python-devel tar socat python3 zip unzip bind-utils
|
||||
Check_Return
|
||||
dnf install -y gpgme-devel
|
||||
Check_Return
|
||||
@@ -975,6 +987,9 @@ if [[ "$Server_OS" = "CentOS" ]] ; then
|
||||
else
|
||||
apt update -y
|
||||
DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
|
||||
if [[ "$Server_Provider" = "Alibaba Cloud" ]] ; then
|
||||
apt install -y --allow-downgrades libgnutls30=3.6.13-2ubuntu1.3
|
||||
fi
|
||||
DEBIAN_FRONTEND=noninteracitve apt install -y dnsutils net-tools htop telnet libcurl4-gnutls-dev libgnutls28-dev libgcrypt20-dev libattr1 libattr1-dev liblzma-dev libgpgme-dev libmariadbclient-dev libcurl4-gnutls-dev libssl-dev nghttp2 libnghttp2-dev idn2 libidn2-dev libidn2-0-dev librtmp-dev libpsl-dev nettle-dev libgnutls28-dev libldap2-dev libgssapi-krb5-2 libk5crypto3 libkrb5-dev libcomerr2 libldap2-dev virtualenv git socat vim unzip zip
|
||||
Check_Return
|
||||
|
||||
@@ -994,7 +1009,7 @@ else
|
||||
update-locale LC_ALL="en_US.UTF-8"
|
||||
fi
|
||||
|
||||
Debug_Log2 "Installing required virtual enviroment,3"
|
||||
Debug_Log2 "Installing required virtual environment,3"
|
||||
|
||||
export LC_CTYPE=en_US.UTF-8
|
||||
export LC_ALL=en_US.UTF-8
|
||||
@@ -1041,7 +1056,7 @@ Debug_Log2 "Necessary components installed..,5"
|
||||
}
|
||||
|
||||
Pre_Install_System_Tweak() {
|
||||
Debug_Log2 "Setting up sytem tweak...,20"
|
||||
Debug_Log2 "Setting up system tweak...,20"
|
||||
Line_Number=$(grep -n "127.0.0.1" /etc/hosts | cut -d: -f 1)
|
||||
My_Hostname=$(hostname)
|
||||
|
||||
@@ -1068,7 +1083,13 @@ if [[ "$Server_OS" = "CentOS" ]] ; then
|
||||
fi
|
||||
#CentOS 7 specific change
|
||||
if [[ "$Server_OS_Version" = "8" ]] ; then
|
||||
:
|
||||
if grep -q -E "Rocky Linux" /etc/os-release ; then
|
||||
if [[ "$Server_Country" = "CN" ]] ; then
|
||||
sed -i 's|rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el8.noarch.rpm|curl -o /etc/yum.repos.d/litespeed.repo https://cyberpanel.sh/litespeed/litespeed_cn.repo|g' install.py
|
||||
else
|
||||
sed -i 's|rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el8.noarch.rpm|curl -o /etc/yum.repos.d/litespeed.repo https://cyberpanel.sh/litespeed/litespeed.repo|g' install.py
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
#CentOS 8 specific change
|
||||
|
||||
@@ -1093,6 +1114,12 @@ if ! grep -q "pid_max" /etc/rc.local 2>/dev/null ; then
|
||||
echo "echo 1000000 > /proc/sys/kernel/pid_max
|
||||
echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.local
|
||||
chmod +x /etc/rc.local
|
||||
fi
|
||||
if grep -q "nf_conntrack_max" /etc/sysctl.conf ; then
|
||||
sysctl -w net.netfilter.nf_conntrack_max=2097152 > /dev/null
|
||||
sysctl -w net.nf_conntrack_max=2097152 > /dev/null
|
||||
echo "net.netfilter.nf_conntrack_max=2097152" >> /etc/sysctl.conf
|
||||
echo "net.nf_conntrack_max=2097152" >> /etc/sysctl.conf
|
||||
fi
|
||||
echo "fs.file-max = 65535" >>/etc/sysctl.conf
|
||||
sysctl -p >/dev/null
|
||||
@@ -1201,8 +1228,8 @@ else
|
||||
fi
|
||||
|
||||
if ./lshttpd -V |& grep "ERROR" || ./lshttpd -V |& grep "expire in 0 days" ; then
|
||||
echo -e "\n\nIt apeears to have some issue with license , please check above result..."
|
||||
Debug_Log2 "It appears to have some issue with LiteSpeed License, make sure you are using correct serial key. [404]"
|
||||
echo -e "\n\nThere appears to be an issue with license , please check above result..."
|
||||
Debug_Log2 "There appears to be an issue with LiteSpeed License, make sure you are using correct serial key. [404]"
|
||||
exit
|
||||
fi
|
||||
|
||||
@@ -1438,6 +1465,7 @@ fi
|
||||
|
||||
if pgrep "redis" ; then
|
||||
echo -e "\n\nRedis installed and running..."
|
||||
touch /home/cyberpanel/redis
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1742,7 +1770,29 @@ if [[ "$Server_OS" = "CentOS" ]] ; then
|
||||
|
||||
if [[ "$Server_OS_Version" = "7" ]] ; then
|
||||
#all centos 7 specific post change goes here
|
||||
:
|
||||
if ! yum list installed lsphp74-devel ; then
|
||||
yum install -y lsphp74-devel
|
||||
fi
|
||||
if [[ ! -f /usr/local/lsws/lsphp74/lib64/php/modules/zip.so ]] ; then
|
||||
if yum list installed libzip-devel >/dev/null 2>&1 ; then
|
||||
yum remove -y libzip-devel
|
||||
fi
|
||||
yum install -y https://cyberpanel.sh/misc/libzip-0.11.2-6.el7.psychotic.x86_64.rpm
|
||||
yum install -y https://cyberpanel.sh/misc/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm
|
||||
yum install lsphp74-devel
|
||||
if [[ ! -d /usr/local/lsws/lsphp74/tmp ]]; then
|
||||
mkdir /usr/local/lsws/lsphp74/tmp
|
||||
fi
|
||||
/usr/local/lsws/lsphp74/bin/pecl channel-update pecl.php.net
|
||||
/usr/local/lsws/lsphp74/bin/pear config-set temp_dir /usr/local/lsws/lsphp74/tmp
|
||||
if /usr/local/lsws/lsphp74/bin/pecl install zip ; then
|
||||
echo "extension=zip.so" >/usr/local/lsws/lsphp74/etc/php.d/20-zip.ini
|
||||
chmod 755 /usr/local/lsws/lsphp74/lib64/php/modules/zip.so
|
||||
else
|
||||
echo -e "\nlsphp74-zip compilation failed..."
|
||||
fi
|
||||
#fix compile lsphp74-zip on centos 7
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$Server_OS_Version" = "8" ]] ; then
|
||||
|
||||
190
install/filesPermsUtilities.py
Normal file
190
install/filesPermsUtilities.py
Normal file
@@ -0,0 +1,190 @@
|
||||
import os
|
||||
import shutil
|
||||
import pathlib
|
||||
import stat
|
||||
|
||||
|
||||
def mkdir_p(path, exist_ok=True):
|
||||
"""
|
||||
Creates the directory and paths leading up to it like unix mkdir -p .
|
||||
Defaults to exist_ok so if it exists were not throwing fatal errors
|
||||
https://docs.python.org/3.7/library/os.html#os.makedirs
|
||||
"""
|
||||
if not os.path.exists(path):
|
||||
print('creating directory: ' + path)
|
||||
os.makedirs(path, exist_ok)
|
||||
|
||||
|
||||
def chmod_digit(file_path, perms):
|
||||
"""
|
||||
Helper function to chmod like you would in unix without having to preface 0o or converting to octal yourself.
|
||||
Credits: https://stackoverflow.com/a/60052847/1621381
|
||||
"""
|
||||
try:
|
||||
os.chmod(file_path, int(str(perms), base=8))
|
||||
except:
|
||||
print(f'Could not chmod : {file_path} to {perms}')
|
||||
pass
|
||||
|
||||
|
||||
def touch(filepath: str, exist_ok=True):
|
||||
"""
|
||||
Touches a file like unix `touch somefile` would.
|
||||
"""
|
||||
try:
|
||||
pathlib.Path(filepath).touch(exist_ok)
|
||||
except FileExistsError:
|
||||
print('Could touch : ' + filepath)
|
||||
pass
|
||||
|
||||
|
||||
def symlink(src, dst):
|
||||
"""
|
||||
Symlink a path to another if the src exists.
|
||||
"""
|
||||
try:
|
||||
if os.access(src, os.R_OK):
|
||||
os.symlink(src, dst)
|
||||
except:
|
||||
print(f'Could not symlink Source: {src} > Destination: {dst}')
|
||||
pass
|
||||
|
||||
|
||||
def chown(path, user, group=-1):
|
||||
"""
|
||||
Chown file/path to user/group provided. Passing -1 to user or group will leave it unchanged.
|
||||
Useful if just changing user or group vs both.
|
||||
"""
|
||||
try:
|
||||
shutil.chown(path, user, group)
|
||||
except PermissionError:
|
||||
print(f'Could not change permissions for: {path} to {user}:{group}')
|
||||
pass
|
||||
|
||||
|
||||
def recursive_chown(path, owner, group=-1):
|
||||
"""
|
||||
Recursively chown a path and contents to owner.
|
||||
https://docs.python.org/3/library/shutil.html
|
||||
"""
|
||||
for dirpath, dirnames, filenames in os.walk(path):
|
||||
try:
|
||||
shutil.chown(dirpath, owner, group)
|
||||
except PermissionError:
|
||||
print('Could not change permissions for: ' + dirpath + ' to: ' + owner)
|
||||
pass
|
||||
for filename in filenames:
|
||||
try:
|
||||
shutil.chown(os.path.join(dirpath, filename), owner, group)
|
||||
except PermissionError:
|
||||
print('Could not change permissions for: ' + os.path.join(dirpath, filename) + ' to: ' + owner)
|
||||
pass
|
||||
|
||||
|
||||
def recursive_permissions(path, dir_mode=755, file_mode=644, topdir=True):
|
||||
"""
|
||||
Recursively chmod a path and contents to mode.
|
||||
Defaults to chmod top level directory but can be optionally
|
||||
toggled off when you want to chmod only contents of like a user's homedir vs homedir itself
|
||||
https://docs.python.org/3.6/library/os.html#os.walk
|
||||
"""
|
||||
|
||||
# Here we are converting the integers to string and then to octal.
|
||||
# so this function doesn't need to be called with 0o prefixed for the file and dir mode
|
||||
dir_mode = int(str(dir_mode), base=8)
|
||||
file_mode = int(str(file_mode), base=8)
|
||||
|
||||
if topdir:
|
||||
# Set chmod on top level path
|
||||
try:
|
||||
os.chmod(path, dir_mode)
|
||||
except:
|
||||
print('Could not chmod :' + path + ' to ' + str(dir_mode))
|
||||
for root, dirs, files in os.walk(path):
|
||||
for d in dirs:
|
||||
try:
|
||||
os.chmod(os.path.join(root, d), dir_mode)
|
||||
except:
|
||||
print('Could not chmod :' + os.path.join(root, d) + ' to ' + str(dir_mode))
|
||||
pass
|
||||
for f in files:
|
||||
try:
|
||||
os.chmod(os.path.join(root, f), file_mode)
|
||||
except:
|
||||
print('Could not chmod :' + path + ' to ' + str(file_mode))
|
||||
pass
|
||||
|
||||
|
||||
# Left intentionally here for reference.
|
||||
# Set recursive chown for a path
|
||||
# recursive_chown(my_path, 'root', 'root')
|
||||
# for changing group recursively without affecting user
|
||||
# recursive_chown('/usr/local/lscp/cyberpanel/rainloop/data', -1, 'lscpd')
|
||||
|
||||
# explicitly set permissions for directories/folders to 0755 and files to 0644
|
||||
# recursive_permissions(my_path, 755, 644)
|
||||
|
||||
# Fix permissions and use default values
|
||||
# recursive_permissions(my_path)
|
||||
# =========================================================
|
||||
# Below is a helper class for getting and working with permissions
|
||||
# Original credits to : https://github.com/keysemble/perfm
|
||||
|
||||
def perm_octal_digit(rwx):
|
||||
digit = 0
|
||||
if rwx[0] == 'r':
|
||||
digit += 4
|
||||
if rwx[1] == 'w':
|
||||
digit += 2
|
||||
if rwx[2] == 'x':
|
||||
digit += 1
|
||||
return digit
|
||||
|
||||
|
||||
class FilePerm:
|
||||
def __init__(self, filepath):
|
||||
filemode = stat.filemode(os.stat(filepath).st_mode)
|
||||
permissions = [filemode[-9:][i:i + 3] for i in range(0, len(filemode[-9:]), 3)]
|
||||
self.filepath = filepath
|
||||
self.access_dict = dict(zip(['user', 'group', 'other'], [list(perm) for perm in permissions]))
|
||||
|
||||
def mode(self):
|
||||
mode = 0
|
||||
for shift, digit in enumerate(self.octal()[::-1]):
|
||||
mode += digit << (shift * 3)
|
||||
return mode
|
||||
|
||||
def digits(self):
|
||||
"""Get the octal chmod equivalent value 755 in single string"""
|
||||
return "".join(map(str, self.octal()))
|
||||
|
||||
def octal(self):
|
||||
"""Get the octal value in a list [7, 5, 5]"""
|
||||
return [perm_octal_digit(p) for p in self.access_dict.values()]
|
||||
|
||||
def access_bits(self, access):
|
||||
if access in self.access_dict.keys():
|
||||
r, w, x = self.access_dict[access]
|
||||
return [r == 'r', w == 'w', x == 'x']
|
||||
|
||||
def update_bitwise(self, settings):
|
||||
def perm_list(read=False, write=False, execute=False):
|
||||
pl = ['-', '-', '-']
|
||||
if read:
|
||||
pl[0] = 'r'
|
||||
if write:
|
||||
pl[1] = 'w'
|
||||
if execute:
|
||||
pl[2] = 'x'
|
||||
return pl
|
||||
|
||||
self.access_dict = dict(
|
||||
[(access, perm_list(read=r, write=w, execute=x)) for access, [r, w, x] in settings.items()])
|
||||
os.chmod(self.filepath, self.mode())
|
||||
|
||||
# project_directory = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
# home_directory = os.path.expanduser('~')
|
||||
# print(f'Path: {home_directory} Mode: {FilePerm(home_directory).mode()} Octal: {FilePerm(home_directory).octal()} '
|
||||
# f'Digits: {FilePerm(home_directory).digits()}')
|
||||
# Example: Output
|
||||
# Path: /home/cooluser Mode: 493 Octal: [7, 5, 5] Digits: 755
|
||||
@@ -58,6 +58,8 @@ def get_distro():
|
||||
return cent8
|
||||
if data.find('AlmaLinux release 8') > -1:
|
||||
return cent8
|
||||
if data.find('Rocky Linux release 8') > -1:
|
||||
return cent8
|
||||
|
||||
else:
|
||||
logging.InstallLog.writeToFile("Can't find linux release file - fatal error")
|
||||
@@ -1714,7 +1716,7 @@ imap_folder_list_limit = 0
|
||||
0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/upgradeCritical.py >/dev/null 2>&1
|
||||
0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/renew.py >/dev/null 2>&1
|
||||
7 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
|
||||
0 12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Daily
|
||||
0 0 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Daily
|
||||
0 0 * * 0 /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Weekly
|
||||
*/3 * * * * if ! find /home/*/public_html/ -maxdepth 2 -type f -newer /usr/local/lsws/cgid -name '.htaccess' -exec false {} +; then /usr/local/lsws/bin/lswsctrl restart; fi
|
||||
"""
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
locale/cn/LC_MESSAGES/django.mo
Executable file → Normal file
BIN
locale/cn/LC_MESSAGES/django.mo
Executable file → Normal file
Binary file not shown.
14139
locale/cn/LC_MESSAGES/django.po
Executable file → Normal file
14139
locale/cn/LC_MESSAGES/django.po
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
BIN
locale/rs/LC_MESSAGES/django.mo
Normal file
BIN
locale/rs/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
7049
locale/rs/LC_MESSAGES/django.po
Normal file
7049
locale/rs/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
@@ -65,7 +65,7 @@ msgstr "Создать пакет"
|
||||
#: websiteFunctions/templates/websiteFunctions/createWebsite.html:29
|
||||
#: websiteFunctions/templates/websiteFunctions/modifyWebsite.html:45
|
||||
msgid "Select Package"
|
||||
msgstr "Вибрать пакет"
|
||||
msgstr "Выбрать пакет"
|
||||
|
||||
#: CLManager/templates/CLManager/createPackage.html:40
|
||||
#: packages/templates/packages/createPackage.html:27
|
||||
|
||||
190
plogical/filesPermsUtilities.py
Normal file
190
plogical/filesPermsUtilities.py
Normal file
@@ -0,0 +1,190 @@
|
||||
import os
|
||||
import shutil
|
||||
import pathlib
|
||||
import stat
|
||||
|
||||
|
||||
def mkdir_p(path, exist_ok=True):
|
||||
"""
|
||||
Creates the directory and paths leading up to it like unix mkdir -p .
|
||||
Defaults to exist_ok so if it exists were not throwing fatal errors
|
||||
https://docs.python.org/3.7/library/os.html#os.makedirs
|
||||
"""
|
||||
if not os.path.exists(path):
|
||||
print('creating directory: ' + path)
|
||||
os.makedirs(path, exist_ok)
|
||||
|
||||
|
||||
def chmod_digit(file_path, perms):
|
||||
"""
|
||||
Helper function to chmod like you would in unix without having to preface 0o or converting to octal yourself.
|
||||
Credits: https://stackoverflow.com/a/60052847/1621381
|
||||
"""
|
||||
try:
|
||||
os.chmod(file_path, int(str(perms), base=8))
|
||||
except:
|
||||
print(f'Could not chmod : {file_path} to {perms}')
|
||||
pass
|
||||
|
||||
|
||||
def touch(filepath: str, exist_ok=True):
|
||||
"""
|
||||
Touches a file like unix `touch somefile` would.
|
||||
"""
|
||||
try:
|
||||
pathlib.Path(filepath).touch(exist_ok)
|
||||
except FileExistsError:
|
||||
print('Could touch : ' + filepath)
|
||||
pass
|
||||
|
||||
|
||||
def symlink(src, dst):
|
||||
"""
|
||||
Symlink a path to another if the src exists.
|
||||
"""
|
||||
try:
|
||||
if os.access(src, os.R_OK):
|
||||
os.symlink(src, dst)
|
||||
except:
|
||||
print(f'Could not symlink Source: {src} > Destination: {dst}')
|
||||
pass
|
||||
|
||||
|
||||
def chown(path, user, group=-1):
|
||||
"""
|
||||
Chown file/path to user/group provided. Passing -1 to user or group will leave it unchanged.
|
||||
Useful if just changing user or group vs both.
|
||||
"""
|
||||
try:
|
||||
shutil.chown(path, user, group)
|
||||
except PermissionError:
|
||||
print(f'Could not change permissions for: {path} to {user}:{group}')
|
||||
pass
|
||||
|
||||
|
||||
def recursive_chown(path, owner, group=-1):
|
||||
"""
|
||||
Recursively chown a path and contents to owner.
|
||||
https://docs.python.org/3/library/shutil.html
|
||||
"""
|
||||
for dirpath, dirnames, filenames in os.walk(path):
|
||||
try:
|
||||
shutil.chown(dirpath, owner, group)
|
||||
except PermissionError:
|
||||
print('Could not change permissions for: ' + dirpath + ' to: ' + owner)
|
||||
pass
|
||||
for filename in filenames:
|
||||
try:
|
||||
shutil.chown(os.path.join(dirpath, filename), owner, group)
|
||||
except PermissionError:
|
||||
print('Could not change permissions for: ' + os.path.join(dirpath, filename) + ' to: ' + owner)
|
||||
pass
|
||||
|
||||
|
||||
def recursive_permissions(path, dir_mode=755, file_mode=644, topdir=True):
|
||||
"""
|
||||
Recursively chmod a path and contents to mode.
|
||||
Defaults to chmod top level directory but can be optionally
|
||||
toggled off when you want to chmod only contents of like a user's homedir vs homedir itself
|
||||
https://docs.python.org/3.6/library/os.html#os.walk
|
||||
"""
|
||||
|
||||
# Here we are converting the integers to string and then to octal.
|
||||
# so this function doesn't need to be called with 0o prefixed for the file and dir mode
|
||||
dir_mode = int(str(dir_mode), base=8)
|
||||
file_mode = int(str(file_mode), base=8)
|
||||
|
||||
if topdir:
|
||||
# Set chmod on top level path
|
||||
try:
|
||||
os.chmod(path, dir_mode)
|
||||
except:
|
||||
print('Could not chmod :' + path + ' to ' + str(dir_mode))
|
||||
for root, dirs, files in os.walk(path):
|
||||
for d in dirs:
|
||||
try:
|
||||
os.chmod(os.path.join(root, d), dir_mode)
|
||||
except:
|
||||
print('Could not chmod :' + os.path.join(root, d) + ' to ' + str(dir_mode))
|
||||
pass
|
||||
for f in files:
|
||||
try:
|
||||
os.chmod(os.path.join(root, f), file_mode)
|
||||
except:
|
||||
print('Could not chmod :' + path + ' to ' + str(file_mode))
|
||||
pass
|
||||
|
||||
|
||||
# Left intentionally here for reference.
|
||||
# Set recursive chown for a path
|
||||
# recursive_chown(my_path, 'root', 'root')
|
||||
# for changing group recursively without affecting user
|
||||
# recursive_chown('/usr/local/lscp/cyberpanel/rainloop/data', -1, 'lscpd')
|
||||
|
||||
# explicitly set permissions for directories/folders to 0755 and files to 0644
|
||||
# recursive_permissions(my_path, 755, 644)
|
||||
|
||||
# Fix permissions and use default values
|
||||
# recursive_permissions(my_path)
|
||||
# =========================================================
|
||||
# Below is a helper class for getting and working with permissions
|
||||
# Original credits to : https://github.com/keysemble/perfm
|
||||
|
||||
def perm_octal_digit(rwx):
|
||||
digit = 0
|
||||
if rwx[0] == 'r':
|
||||
digit += 4
|
||||
if rwx[1] == 'w':
|
||||
digit += 2
|
||||
if rwx[2] == 'x':
|
||||
digit += 1
|
||||
return digit
|
||||
|
||||
|
||||
class FilePerm:
|
||||
def __init__(self, filepath):
|
||||
filemode = stat.filemode(os.stat(filepath).st_mode)
|
||||
permissions = [filemode[-9:][i:i + 3] for i in range(0, len(filemode[-9:]), 3)]
|
||||
self.filepath = filepath
|
||||
self.access_dict = dict(zip(['user', 'group', 'other'], [list(perm) for perm in permissions]))
|
||||
|
||||
def mode(self):
|
||||
mode = 0
|
||||
for shift, digit in enumerate(self.octal()[::-1]):
|
||||
mode += digit << (shift * 3)
|
||||
return mode
|
||||
|
||||
def digits(self):
|
||||
"""Get the octal chmod equivalent value 755 in single string"""
|
||||
return "".join(map(str, self.octal()))
|
||||
|
||||
def octal(self):
|
||||
"""Get the octal value in a list [7, 5, 5]"""
|
||||
return [perm_octal_digit(p) for p in self.access_dict.values()]
|
||||
|
||||
def access_bits(self, access):
|
||||
if access in self.access_dict.keys():
|
||||
r, w, x = self.access_dict[access]
|
||||
return [r == 'r', w == 'w', x == 'x']
|
||||
|
||||
def update_bitwise(self, settings):
|
||||
def perm_list(read=False, write=False, execute=False):
|
||||
pl = ['-', '-', '-']
|
||||
if read:
|
||||
pl[0] = 'r'
|
||||
if write:
|
||||
pl[1] = 'w'
|
||||
if execute:
|
||||
pl[2] = 'x'
|
||||
return pl
|
||||
|
||||
self.access_dict = dict(
|
||||
[(access, perm_list(read=r, write=w, execute=x)) for access, [r, w, x] in settings.items()])
|
||||
os.chmod(self.filepath, self.mode())
|
||||
|
||||
# project_directory = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
# home_directory = os.path.expanduser('~')
|
||||
# print(f'Path: {home_directory} Mode: {FilePerm(home_directory).mode()} Octal: {FilePerm(home_directory).octal()} '
|
||||
# f'Digits: {FilePerm(home_directory).digits()}')
|
||||
# Example: Output
|
||||
# Path: /home/cooluser Mode: 493 Octal: [7, 5, 5] Digits: 755
|
||||
@@ -2399,7 +2399,7 @@ vmail
|
||||
0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/upgradeCritical.py >/dev/null 2>&1
|
||||
0 2 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/renew.py >/dev/null 2>&1
|
||||
7 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
|
||||
0 12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Daily
|
||||
0 0 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Daily
|
||||
0 0 * * 0 /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py Weekly
|
||||
"""
|
||||
writeToFile = open(cronPath, 'w')
|
||||
|
||||
@@ -2717,6 +2717,15 @@ RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
|
||||
|
||||
### End CyberPanel Generated Rules.
|
||||
|
||||
`;
|
||||
const WWWToNonWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP_HOST} ^www\.(.*)$
|
||||
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
|
||||
|
||||
### End CyberPanel Generated Rules.
|
||||
|
||||
`;
|
||||
|
||||
const nonWWWToWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator
|
||||
@@ -2736,6 +2745,9 @@ RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
|
||||
} else if ($scope.rewriteTemplate === "Force NON-WWW -> WWW") {
|
||||
$scope.rewriteRules = nonWWWToWWW + $scope.rewriteRules;
|
||||
}
|
||||
else if ($scope.rewriteTemplate === "Force WWW -> NON-WWW") {
|
||||
$scope.rewriteRules = WWWToNonWWW + $scope.rewriteRules;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2717,6 +2717,16 @@ RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
|
||||
|
||||
### End CyberPanel Generated Rules.
|
||||
|
||||
`;
|
||||
|
||||
const WWWToNonWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP_HOST} ^www\.(.*)$
|
||||
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
|
||||
|
||||
### End CyberPanel Generated Rules.
|
||||
|
||||
`;
|
||||
|
||||
const nonWWWToWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator
|
||||
@@ -2736,6 +2746,9 @@ RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
|
||||
} else if ($scope.rewriteTemplate === "Force NON-WWW -> WWW") {
|
||||
$scope.rewriteRules = nonWWWToWWW + $scope.rewriteRules;
|
||||
}
|
||||
else if ($scope.rewriteTemplate === "Force WWW -> NON-WWW") {
|
||||
$scope.rewriteRules = WWWToNonWWW + $scope.rewriteRules;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@
|
||||
<h2 style="display: inline; color: #414C59;" ng-bind="web.domain"></h2>
|
||||
</a>
|
||||
<a target="_self" href="/filemanager/{$ web.domain $}" title="Open File Manager"> --
|
||||
File Manager</a>
|
||||
{% trans "File Manager" %}</a>
|
||||
</div>
|
||||
<div class="col-md-2 content-box-header" style="text-transform: none;">
|
||||
<a href="/websites/{$ web.domain $}" target="_self" title="Manage Website">
|
||||
<i class="p fa fa-external-link btn-icon"> </i>
|
||||
<span>Manage</span>
|
||||
<span>{% trans "Manage" %}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -83,7 +83,7 @@
|
||||
<i class="p fa fa-lock btn-icon text-muted" data-toggle="tooltip" data-placement="right"
|
||||
title="SSL"> </i>
|
||||
<span><a ng-click="issueSSL(web.domain)" href=""
|
||||
style="text-transform: none">Issue SSL</a></span>
|
||||
style="text-transform: none">{% trans "Issue SSL" %}</a></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
|
||||
@@ -692,6 +692,7 @@
|
||||
<select ng-change="applyRewriteTemplate()" ng-model="rewriteTemplate"
|
||||
class="form-control">
|
||||
<option>Force HTTP -> HTTPS</option>
|
||||
<option>Force WWW -> NON-WWW</option>
|
||||
<option>Force NON-WWW -> WWW</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -1079,4 +1080,4 @@
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user