From 2e0855111923f0359bd0bfb570080219dffffec0 Mon Sep 17 00:00:00 2001 From: WhatTheServer Date: Tue, 20 Apr 2021 19:49:51 -0400 Subject: [PATCH 01/72] Update cyberpanel.sh --- cyberpanel.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cyberpanel.sh b/cyberpanel.sh index bee93ea7a..3807901dc 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -5,7 +5,7 @@ #set -u -#CyberPanel installer script for CentOS 7.X, CentOS 8.X, CloudLinux 7.X, Ubuntu 18.04 and Ubuntu 20.04 +#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 #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 @@ -17,10 +17,10 @@ #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_Virualization() ---> check for virtualizaon , LXC not suppoed , some edit needed on OVZ +#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 -#Check_Provider() ---> check the provider, certain provider like Alibaba or tencent yun may need some special change +#Check_Process() ---> check no other process like Apache is running +#Check_Provider() ---> check the provider, certain provider like Alibaba or Tencent Yun may need some special change #Check_Argument() ---> parse argument and go to Argument_Mode() or Interactive_Mode() respectively #Pre_Install_Setup_Repository() ---> setup/install repositories for centos system. #go to Pre_Install_Setup_CN_Repository() if server is within China. @@ -255,7 +255,6 @@ 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 - Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | cut -c1-1) 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 @@ -267,15 +266,16 @@ fi } -Check_Virualization() { +Check_Virtualization() { echo -e "Checking virtualization type..." -if hostnamectl | grep -q "Virtualization: lxc"; then - echo -e "\nLXC detected..." - echo -e "CyberPanel does not support LXC" - echo -e "Exiting..." - Debug_Log2 "CyberPanel does not support LXC.. [404]" - exit -fi +#if hostnamectl | grep -q "Virtualization: lxc"; then +# echo -e "\nLXC detected..." +# echo -e "CyberPanel does not support LXC" +# echo -e "Exiting..." +# Debug_Log2 "CyberPanel does not support LXC.. [404]" +# exit +#fi +#remove per https://github.com/usmannasir/cyberpanel/issues/589 if hostnamectl | grep -q "Virtualization: openvz"; then echo -e "OpenVZ detected...\n" @@ -816,6 +816,7 @@ if [[ $Server_OS = "CentOS" ]] ; then if [[ "$Server_OS_Version" = "8" ]]; then + rpm --import https://cyberpanel.sh/www.centos.org/keys/RPM-GPG-KEY-CentOS-Official rpm --import https://cyberpanel.sh/dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8 yum install -y https://cyberpanel.sh/dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm Check_Return "yum repo" "no_exit" @@ -965,7 +966,7 @@ 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" - DEBIAN_FRONTEND=noninteracitve apt install -y dnsutils 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 + 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 DEBIAN_FRONTEND=noninteractive apt install -y python3-pip @@ -1814,7 +1815,7 @@ Check_Server_IP "$@" Check_OS -Check_Virualization +Check_Virtualization Check_Panel From c166da2a69b4b197d40174d92b95f8d2ce402e77 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 21 Apr 2021 22:51:44 +0500 Subject: [PATCH 02/72] remove sieve configurations from mailscanner install --- CPScripts/mailscannerinstaller.sh | 494 ++++++++++++++-------------- CPScripts/mailscanneruninstaller.sh | 26 +- plogical/ClusterManager.py | 1 + 3 files changed, 254 insertions(+), 267 deletions(-) diff --git a/CPScripts/mailscannerinstaller.sh b/CPScripts/mailscannerinstaller.sh index da9a2490d..4a4f4e26e 100644 --- a/CPScripts/mailscannerinstaller.sh +++ b/CPScripts/mailscannerinstaller.sh @@ -2,22 +2,21 @@ #systemctl stop firewalld check_return() { -#check previous command result , 0 = ok , non-0 = something wrong. -if [[ $? -eq "0" ]] ; then - : -else - echo -e "\ncommand failed, exiting..." - exit -fi + #check previous command result , 0 = ok , non-0 = something wrong. + if [[ $? -eq "0" ]]; then + : + else + echo -e "\ncommand failed, exiting..." + exit + fi } -echo 'backup configs'; -cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); -cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); -cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); +echo 'backup configs' +cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S') +cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S') +cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S') cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext-bak_$(date '+%Y-%m-%d_%H_%M:%S') - ZONE=$(firewall-cmd --get-default-zone) firewall-cmd --zone=$ZONE --add-port=4190/tcp --permanent systemctl stop firewalld @@ -27,167 +26,158 @@ csf -x MAILSCANNER=/etc/MailScanner -if [ -d $MAILSCANNER ];then - -echo "MailScanner found. If you wish to reinstall then remove the package and revert" -echo "Postfix back to its original config at /etc/postfix/main.cf and remove" -echo "/etc/MailScanner and /usr/share/MailScanner directories" -exit +if [ -d $MAILSCANNER ]; then + echo "MailScanner found. If you wish to reinstall then remove the package and revert" + echo "Postfix back to its original config at /etc/postfix/main.cf and remove" + echo "/etc/MailScanner and /usr/share/MailScanner directories" + exit fi -if [ -f /etc/os-release ];then -OS=$(head -1 /etc/os-release) -UBUNTUVERSION=$(sed '6q;d' /etc/os-release) -CENTOSVERSION=$(sed '5q;d' /etc/os-release) -CLNVERSION=$(sed '3q;d' /etc/os-release) +if [ -f /etc/os-release ]; then + OS=$(head -1 /etc/os-release) + UBUNTUVERSION=$(sed '6q;d' /etc/os-release) + CENTOSVERSION=$(sed '5q;d' /etc/os-release) + CLNVERSION=$(sed '3q;d' /etc/os-release) fi -if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ];then +if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ]; then -setenforce 0 -yum install -y perl yum-utils perl-CPAN -yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" + setenforce 0 + yum install -y perl yum-utils perl-CPAN + yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" -rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm -export PERL_MM_USE_DEFAULT=1 -curl -L https://cpanmin.us | perl - App::cpanminus -perl -MCPAN -e 'install Encoding::FixLatin' -perl -MCPAN -e 'install Digest::SHA1' -perl -MCPAN -e 'install Geo::IP' -perl -MCPAN -e 'install Razor2::Client::Agent' -perl -MCPAN -e 'install Net::Patricia' + rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm + export PERL_MM_USE_DEFAULT=1 + curl -L https://cpanmin.us | perl - App::cpanminus + perl -MCPAN -e 'install Encoding::FixLatin' + perl -MCPAN -e 'install Digest::SHA1' + perl -MCPAN -e 'install Geo::IP' + perl -MCPAN -e 'install Razor2::Client::Agent' + perl -MCPAN -e 'install Net::Patricia' -freshclam -v -DIR=/etc/mail/spamassassin + freshclam -v + DIR=/etc/mail/spamassassin -if [ -d "$DIR" ]; then -sa-update + if [ -d "$DIR" ]; then + sa-update + else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit + fi -else +elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ]; then -echo "Please install spamassassin through the CyberPanel interface before proceeding" + setenforce 0 + yum install -y perl yum-utils perl-CPAN + dnf --enablerepo=powertools install -y perl-IO-stringy + dnf --enablerepo=PowerTools install -y perl-IO-stringy + yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav clamav-update "perl(DBD::mysql)" -exit -fi + rpm -Uvh https://forensics.cert.org/centos/cert/8/x86_64/unrar-5.4.0-1.el8.x86_64.rpm -elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ];then + export PERL_MM_USE_DEFAULT=1 + curl -L https://cpanmin.us | perl - App::cpanminus -setenforce 0 -yum install -y perl yum-utils perl-CPAN -dnf --enablerepo=powertools install -y perl-IO-stringy -dnf --enablerepo=PowerTools install -y perl-IO-stringy -yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav clamav-update "perl(DBD::mysql)" + perl -MCPAN -e 'install Encoding::FixLatin' + perl -MCPAN -e 'install Digest::SHA1' + perl -MCPAN -e 'install Geo::IP' + perl -MCPAN -e 'install Razor2::Client::Agent' + perl -MCPAN -e 'install Sys::Hostname::Long' + perl -MCPAN -e 'install Sys::SigAction' -rpm -Uvh https://forensics.cert.org/centos/cert/8/x86_64/unrar-5.4.0-1.el8.x86_64.rpm + freshclam -v -export PERL_MM_USE_DEFAULT=1 -curl -L https://cpanmin.us | perl - App::cpanminus + DIR=/etc/mail/spamassassin -perl -MCPAN -e 'install Encoding::FixLatin' -perl -MCPAN -e 'install Digest::SHA1' -perl -MCPAN -e 'install Geo::IP' -perl -MCPAN -e 'install Razor2::Client::Agent' -perl -MCPAN -e 'install Sys::Hostname::Long' -perl -MCPAN -e 'install Sys::SigAction' + if [ -d "$DIR" ]; then + sa-update + else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit + fi +elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then + setenforce 0 + yum install -y perl yum-utils perl-CPAN + yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" -freshclam -v + rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm + export PERL_MM_USE_DEFAULT=1 + curl -L https://cpanmin.us | perl - App::cpanminus + perl -MCPAN -e 'install Encoding::FixLatin' + perl -MCPAN -e 'install Digest::SHA1' + perl -MCPAN -e 'install Geo::IP' + perl -MCPAN -e 'install Razor2::Client::Agent' + perl -MCPAN -e 'install Net::Patricia' -DIR=/etc/mail/spamassassin + freshclam -v + DIR=/etc/mail/spamassassin -if [ -d "$DIR" ]; then -sa-update + if [ -d "$DIR" ]; then + sa-update -else + else -echo "Please install spamassassin through the CyberPanel interface before proceeding" + echo "Please install spamassassin through the CyberPanel interface before proceeding" -exit -fi + exit + fi -elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ];then +elif [ "$OS" = "NAME=\"Ubuntu\"" ]; then -setenforce 0 -yum install -y perl yum-utils perl-CPAN -yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" + apt-get install -y libmysqlclient-dev -rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm -export PERL_MM_USE_DEFAULT=1 -curl -L https://cpanmin.us | perl - App::cpanminus -perl -MCPAN -e 'install Encoding::FixLatin' -perl -MCPAN -e 'install Digest::SHA1' -perl -MCPAN -e 'install Geo::IP' -perl -MCPAN -e 'install Razor2::Client::Agent' -perl -MCPAN -e 'install Net::Patricia' + apt-get install -y cpanminus gcc perl bzip2 zip make patch automake rpm libarchive-zip-perl libfilesys-df-perl libole-storage-lite-perl libsys-hostname-long-perl libsys-sigaction-perl libregexp-common-net-cidr-perl libmime-tools-perl libdbd-sqlite3-perl binutils build-essential libfilesys-df-perl zlib1g unzip mlocate clamav libdbd-mysql-perl unrar libclamav-dev libclamav-client-perl libclamunrar9 -freshclam -v -DIR=/etc/mail/spamassassin + cpanm Encoding::FixLatin + cpanm Digest::SHA1 + cpanm Geo::IP + cpanm Razor2::Client::Agent + cpanm Net::Patricia + cpanm Net::CIDR -if [ -d "$DIR" ]; then -sa-update + sudo systemctl stop clamav-freshclam.service -else + freshclam -echo "Please install spamassassin through the CyberPanel interface before proceeding" + sudo systemctl start clamav-freshclam.service -exit -fi + DIR=/etc/spamassassin + if [ -d "$DIR" ]; then -elif [ "$OS" = "NAME=\"Ubuntu\"" ];then - - apt-get install -y libmysqlclient-dev - - apt-get install -y cpanminus gcc perl bzip2 zip make patch automake rpm libarchive-zip-perl libfilesys-df-perl libole-storage-lite-perl libsys-hostname-long-perl libsys-sigaction-perl libregexp-common-net-cidr-perl libmime-tools-perl libdbd-sqlite3-perl binutils build-essential libfilesys-df-perl zlib1g unzip mlocate clamav libdbd-mysql-perl unrar libclamav-dev libclamav-client-perl libclamunrar9 - -cpanm Encoding::FixLatin -cpanm Digest::SHA1 -cpanm Geo::IP -cpanm Razor2::Client::Agent -cpanm Net::Patricia -cpanm Net::CIDR - -sudo systemctl stop clamav-freshclam.service - -freshclam - -sudo systemctl start clamav-freshclam.service - -DIR=/etc/spamassassin -if [ -d "$DIR" ]; then - -apt-get -y install razor pyzor libencode-detect-perl libgeo-ip-perl libnet-patricia-perl -sa-update -else -echo "Please install spamassassin through the CyberPanel interface before proceeding" -exit -fi + apt-get -y install razor pyzor libencode-detect-perl libgeo-ip-perl libnet-patricia-perl + sa-update + else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit + fi fi -echo "header_checks = regexp:/etc/postfix/header_checks" >> /etc/postfix/main.cf -echo "/^Received:/ HOLD" >> /etc/postfix/header_checks +echo "header_checks = regexp:/etc/postfix/header_checks" >>/etc/postfix/main.cf +echo "/^Received:/ HOLD" >>/etc/postfix/header_checks systemctl restart postfix -if [ "$OS" = "NAME=\"Ubuntu\"" ];then -wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.noarch.deb -dpkg -i *.noarch.deb +if [ "$OS" = "NAME=\"Ubuntu\"" ]; then + wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.noarch.deb + dpkg -i *.noarch.deb -mkdir /var/run/MailScanner -mkdir /var/lock/subsys -mkdir /var/lock/subsys/MailScanner -chown -R postfix:postfix /var/run/MailScanner -chown -R postfix:postfix /var/lock/subsys/MailScanner -chown -R postfix:postfix /var/spool/MailScanner + mkdir /var/run/MailScanner + mkdir /var/lock/subsys + mkdir /var/lock/subsys/MailScanner + chown -R postfix:postfix /var/run/MailScanner + chown -R postfix:postfix /var/lock/subsys/MailScanner + chown -R postfix:postfix /var/spool/MailScanner -elif [ "$OS" = "NAME=\"CentOS Linux\"" ];then -wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm -rpm -Uvh *.rhel.noarch.rpm +elif [ "$OS" = "NAME=\"CentOS Linux\"" ]; then + wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm + rpm -Uvh *.rhel.noarch.rpm -elif [ "$OS" = "NAME=\"CloudLinux\"" ];then -wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm -rpm -Uvh *.rhel.noarch.rpm +elif [ "$OS" = "NAME=\"CloudLinux\"" ]; then + wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm + rpm -Uvh *.rhel.noarch.rpm fi mkdir /var/spool/MailScanner/spamassassin @@ -234,8 +224,8 @@ PASSWORD=$(cat /etc/cyberpanel/mysqlPassword) USER=root DATABASE=mailscanner ADMINPASS=$(cat /etc/cyberpanel/adminPass) -mysql -u${USER} -p${PASSWORD} < "/usr/local/CyberCP/public/mailwatch/create.sql" -mysql -u${USER} -p${PASSWORD} -e "use mailscanner"; +mysql -u${USER} -p${PASSWORD} <"/usr/local/CyberCP/public/mailwatch/create.sql" +mysql -u${USER} -p${PASSWORD} -e "use mailscanner" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "GRANT ALL ON mailscanner.* TO root@localhost IDENTIFIED BY '${PASSWORD}';" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "FLUSH PRIVILEGES;" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "INSERT INTO mailscanner.users SET username = 'admin', password = MD5('${ADMINPASS}'), fullname = 'admin', type = 'A';" @@ -247,11 +237,11 @@ sed -i "s/^define('DB_PASS',.*/define('DB_PASS','${PASSWORD}');/" /usr/local/Cyb sed -i "s/^define('MAILWATCH_HOME',.*/define(\'MAILWATCH_HOME\', \'\/usr\/local\/CyberCP\/public\/mailwatch\/mailscanner');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php MSDEFAULT=/etc/MailScanner/defaults -if [ -f "$MSDEFAULT" ];then -sed -i 's/^run_mailscanner=.*/run_mailscanner=1/' /etc/MailScanner/defaults -elif [ ! -f "$MSDEFAULT" ];then -touch /etc/MailScanner/defaults -echo "run_mailscanner=1" >> /etc/MailScanner/defaults +if [ -f "$MSDEFAULT" ]; then + sed -i 's/^run_mailscanner=.*/run_mailscanner=1/' /etc/MailScanner/defaults +elif [ ! -f "$MSDEFAULT" ]; then + touch /etc/MailScanner/defaults + echo "run_mailscanner=1" >>/etc/MailScanner/defaults fi cp /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/MailWatchConf.pm /usr/share/MailScanner/perl/custom/ @@ -268,125 +258,121 @@ systemctl restart mailscanner IPADDRESS=$(cat /etc/cyberpanel/machineIP) +### Furhter onwards is sieve configurations -echo 'Setting up spamassassin and sieve to deliver spam to Junk folder by default' -#echo "If you wish mailscanner/spamassassin to send spam email to a spam folder please follow the tutorial on the Cyberpanel Website" -echo 'Fix protocols' -sed -i 's/^protocols =.*/protocols = imap pop3 lmtp sieve/g' /etc/dovecot/dovecot.conf - - -sed -i "s|^user_query.*|user_query = SELECT '5000' as uid, '5000' as gid, '/home/vmail/%d/%n' as home,mail FROM e_users WHERE email='%u';|g" /etc/dovecot/dovecot-sql.conf.ext - -if [ "$OS" = "NAME=\"Ubuntu\"" ];then -if [ "$UBUNTUVERSION" = "VERSION_ID=\"18.04\"" ];then - apt-get install -y dovecot-managesieved dovecot-sieve dovecot-lmtpd net-tools pflogsumm -elif [ "$UBUNTUVERSION" = "VERSION_ID=\"20.04\"" ];then - apt-get install -y libmysqlclient-dev - sed -e '/deb/ s/^#*/#/' -i /etc/apt/sources.list.d/dovecot.list - apt install -y dovecot-lmtpd dovecot-managesieved dovecot-sieve net-tools pflogsumm -fi - -elif [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ];then - - yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts - -elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ];then - - rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm - dnf --enablerepo=gf-plus upgrade -y dovecot23* - dnf --enablerepo=gf-plus install -y dovecot23-pigeonhole - dnf install -y net-tools postfix-perl-scripts - -elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ];then - - yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts -fi - - -# Create Sieve files -mkdir -p /etc/dovecot/sieve/global -touch /var/log/{dovecot-lda-errors.log,dovecot-lda.log} -touch /var/log/{dovecot-sieve-errors.log,dovecot-sieve.log} -touch /var/log/{dovecot-lmtp-errors.log,dovecot-lmtp.log} -touch /etc/dovecot/sieve/default.sieve -chown vmail: -R /etc/dovecot/sieve -chown vmail:mail /var/log/dovecot-* - -echo 'Create Sieve Default spam to Junk rule' -cat >> /etc/dovecot/sieve/default.sieve <> /etc/dovecot/dovecot.conf <>/etc/dovecot/sieve/default.sieve <>/etc/dovecot/dovecot.conf < Date: Wed, 21 Apr 2021 23:28:15 +0500 Subject: [PATCH 03/72] bring spamassasin check on top --- CPScripts/mailscannerinstaller.sh | 49 +++++++------------------------ 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/CPScripts/mailscannerinstaller.sh b/CPScripts/mailscannerinstaller.sh index 4a4f4e26e..e1dd71a5d 100644 --- a/CPScripts/mailscannerinstaller.sh +++ b/CPScripts/mailscannerinstaller.sh @@ -33,6 +33,17 @@ if [ -d $MAILSCANNER ]; then exit fi +### Check SpamAssasin before moving forward + +DIR=/etc/mail/spamassassin + +if [ -d "$DIR" ]; then + sa-update +else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit +fi + if [ -f /etc/os-release ]; then OS=$(head -1 /etc/os-release) UBUNTUVERSION=$(sed '6q;d' /etc/os-release) @@ -56,14 +67,6 @@ if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ]; then perl -MCPAN -e 'install Net::Patricia' freshclam -v - DIR=/etc/mail/spamassassin - - if [ -d "$DIR" ]; then - sa-update - else - echo "Please install spamassassin through the CyberPanel interface before proceeding" - exit - fi elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ]; then @@ -87,15 +90,6 @@ elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ]; then freshclam -v - DIR=/etc/mail/spamassassin - - if [ -d "$DIR" ]; then - sa-update - else - echo "Please install spamassassin through the CyberPanel interface before proceeding" - exit - fi - elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then setenforce 0 @@ -112,17 +106,6 @@ elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then perl -MCPAN -e 'install Net::Patricia' freshclam -v - DIR=/etc/mail/spamassassin - - if [ -d "$DIR" ]; then - sa-update - - else - - echo "Please install spamassassin through the CyberPanel interface before proceeding" - - exit - fi elif [ "$OS" = "NAME=\"Ubuntu\"" ]; then @@ -143,16 +126,6 @@ elif [ "$OS" = "NAME=\"Ubuntu\"" ]; then sudo systemctl start clamav-freshclam.service - DIR=/etc/spamassassin - if [ -d "$DIR" ]; then - - apt-get -y install razor pyzor libencode-detect-perl libgeo-ip-perl libnet-patricia-perl - sa-update - else - echo "Please install spamassassin through the CyberPanel interface before proceeding" - exit - fi - fi echo "header_checks = regexp:/etc/postfix/header_checks" >>/etc/postfix/main.cf From 7550b2417c6b952f90a93c8b875ae44b9ea4d370 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 22 Apr 2021 00:09:40 +0500 Subject: [PATCH 04/72] fix a bug in mailwatch sql file --- CPScripts/mailscannerinstaller.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CPScripts/mailscannerinstaller.sh b/CPScripts/mailscannerinstaller.sh index e1dd71a5d..6e324a22b 100644 --- a/CPScripts/mailscannerinstaller.sh +++ b/CPScripts/mailscannerinstaller.sh @@ -197,6 +197,13 @@ PASSWORD=$(cat /etc/cyberpanel/mysqlPassword) USER=root DATABASE=mailscanner ADMINPASS=$(cat /etc/cyberpanel/adminPass) + +### Fix a bug in MailWatch SQL File + +sed -i 's/char(512)/char(255)/g' /usr/local/CyberCP/public/mailwatch/create.sql + +## + mysql -u${USER} -p${PASSWORD} <"/usr/local/CyberCP/public/mailwatch/create.sql" mysql -u${USER} -p${PASSWORD} -e "use mailscanner" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "GRANT ALL ON mailscanner.* TO root@localhost IDENTIFIED BY '${PASSWORD}';" From e76484832ac1ffc2a4380de2e070f2e9c7002aee Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 22 Apr 2021 00:13:04 +0500 Subject: [PATCH 05/72] add selinux check before mailscanner install --- emailPremium/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/emailPremium/views.py b/emailPremium/views.py index 47299efe9..7b018e90a 100755 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -1129,6 +1129,15 @@ def installMailScanner(request): return ACLManager.loadErrorJson() try: + ### Check selinux + + command = 'sestatus' + result = ProcessUtilities.outputExecutioner(command) + + if result.find('disabled') == -1: + final_json = json.dumps({'status': 0, 'error_message': "Disable selinux before installing MailScanner."}) + return HttpResponse(final_json) + execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py" execPath = execPath + " installMailScanner" ProcessUtilities.popenExecutioner(execPath) From 720f51d6f22f4a83be67e990107fc176e4ed03a3 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 22 Apr 2021 01:37:59 +0500 Subject: [PATCH 06/72] selinux should be for centos --- emailPremium/views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/emailPremium/views.py b/emailPremium/views.py index 7b018e90a..535c438c5 100755 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -1131,12 +1131,13 @@ def installMailScanner(request): ### Check selinux - command = 'sestatus' - result = ProcessUtilities.outputExecutioner(command) + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + command = 'sestatus' + result = ProcessUtilities.outputExecutioner(command) - if result.find('disabled') == -1: - final_json = json.dumps({'status': 0, 'error_message': "Disable selinux before installing MailScanner."}) - return HttpResponse(final_json) + if result.find('disabled') == -1: + final_json = json.dumps({'status': 0, 'error_message': "Disable selinux before installing MailScanner."}) + return HttpResponse(final_json) execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py" execPath = execPath + " installMailScanner" From 963a49e7714d57fd3950ec72e1172438c8116c64 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 22 Apr 2021 17:46:18 +0500 Subject: [PATCH 07/72] full path to adduser --- plogical/vhost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plogical/vhost.py b/plogical/vhost.py index 7a9c4fbb5..4bf45dd18 100755 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -50,7 +50,7 @@ class vhost: if os.path.exists("/etc/lsb-release"): command = '/usr/sbin/adduser --no-create-home --home ' + path + ' --disabled-login --gecos "" ' + virtualHostUser else: - command = "adduser " + virtualHostUser + " -M -d " + path + command = "/usr/sbin/adduser " + virtualHostUser + " -M -d " + path ProcessUtilities.executioner(command) From aa697332c5f4a2ae51f94afce68ccc808f585153 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 24 Apr 2021 03:42:05 +0500 Subject: [PATCH 08/72] bug fix: email configs reset --- cloudAPI/cloudManager.py | 2 +- mailServer/mailserverManager.py | 4 - plogical/mailUtilities.py | 890 +++++++++++++++++++++++++++++++- 3 files changed, 890 insertions(+), 6 deletions(-) diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 3f51e466d..25f5c766b 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -1492,7 +1492,7 @@ class CloudManager: writeToFile.write('Starting..,0') writeToFile.close() - execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/mailServer/mailserverManager.py" + execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py" execPath = execPath + ' ResetEmailConfigurations --tempStatusPath %s' % (tempStatusPath) ProcessUtilities.popenExecutioner(execPath) diff --git a/mailServer/mailserverManager.py b/mailServer/mailserverManager.py index 927a8f43d..bbcc58d46 100755 --- a/mailServer/mailserverManager.py +++ b/mailServer/mailserverManager.py @@ -3,13 +3,10 @@ import os.path import sys import django - from plogical.httpProc import httpProc - sys.path.append('/usr/local/CyberCP') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") django.setup() -from django.shortcuts import render,redirect from django.http import HttpResponse try: from .models import Domains,EUsers @@ -62,7 +59,6 @@ class MailServerManager(multi.Thread): None, 'createEmail') return proc.render() - def createEmailAccount(self): userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 543274e5f..e4644023e 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -1,4 +1,8 @@ +import json import os,sys + +from django.http import HttpResponse + sys.path.append('/usr/local/CyberCP') import django os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") @@ -17,6 +21,8 @@ import os import bcrypt import getpass import smtplib +import threading as multi +import socket try: from mailServer.models import Domains, EUsers @@ -734,6 +740,883 @@ milter_default_action = accept str(msg) + " [checkIfMailScannerInstalled]") return 0 + ####### Imported below functions from mailserver/mailservermanager, need to refactor later + +class MailServerManagerUtils(multi.Thread): + + def __init__(self, request=None, function=None, extraArgs=None): + multi.Thread.__init__(self) + self.request = request + self.function = function + self.extraArgs = extraArgs + + def checkIfMailServerSSLIssued(self): + + postfixPath = '/etc/postfix/main.cf' + + postFixData = ProcessUtilities.outputExecutioner('cat %s' % (postfixPath)) + + if postFixData.find('myhostname = server.example.com') > -1: + return 0 + else: + try: + + postFixLines = ProcessUtilities.outputExecutioner('cat %s' % (postfixPath)).splitlines() + + for items in postFixLines: + if items.find('myhostname') > -1 and items[0] != '#': + self.mailHostName = items.split('=')[1].strip(' ') + self.MailSSL = 1 + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile('%s. [checkIfMailServerSSLIssued:864]' % (str(msg))) + + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddress = ipData.split('\n', 1)[0] + + command = 'openssl s_client -connect %s:465' % (ipAddress) + result = ProcessUtilities.outputExecutioner(command) + + if result.find('18 (self signed certificate)') > -1: + return 0 + else: + return 1 + + def RunServerLevelEmailChecks(self): + try: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Checking if MailServer SSL issued..,10') + + reportFile = self.extraArgs['reportFile'] + + report = {} + report['MailSSL'] = self.checkIfMailServerSSLIssued() + + writeToFile = open(reportFile, 'w') + writeToFile.write(json.dumps(report)) + writeToFile.close() + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].') + + except BaseException as msg: + final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def install_postfix_dovecot(self): + try: + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + command = 'yum remove postfix -y' + ProcessUtilities.executioner(command) + elif ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + command = 'apt-get -y remove postfix' + ProcessUtilities.executioner(command) + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing postfix..,10') + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos: + command = 'yum install --enablerepo=gf-plus -y postfix3 postfix3-ldap postfix3-mysql postfix3-pcre' + elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + + command = 'dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm' + ProcessUtilities.executioner(command) + + command = 'dnf install --enablerepo=gf-plus postfix3 postfix3-mysql -y' + ProcessUtilities.executioner(command) + else: + command = 'apt-get install -y debconf-utils' + ProcessUtilities.executioner(command) + file_name = 'pf.unattend.text' + pf = open(file_name, 'w') + pf.write('postfix postfix/mailname string ' + str(socket.getfqdn() + '\n')) + pf.write('postfix postfix/main_mailer_type string "Internet Site"\n') + pf.close() + command = 'debconf-set-selections ' + file_name + ProcessUtilities.executioner(command) + + command = 'apt-get -y install postfix' + # os.remove(file_name) + + ProcessUtilities.executioner(command) + + import socket + # We are going to leverage postconfig -e to edit the settings for hostname + command = '"postconf -e "myhostname = %s"' % (str(socket.getfqdn())) + ProcessUtilities.executioner(command) + command = '"postconf -e "myhostname = %s"' % (str(socket.getfqdn())) + ProcessUtilities.executioner(command) + + # We are explicitly going to use sed to set the hostname default from "myhostname = server.example.com" + # to the fqdn from socket if the default is still found + postfix_main = '/etc/postfix/main.cf' + command = "sed -i 's|server.example.com|%s|g' %s" % (str(socket.getfqdn()), postfix_main) + ProcessUtilities.executioner(command) + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing Dovecot..,15') + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + pass + else: + command = 'apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql' + + ProcessUtilities.executioner(command) + + ## + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos: + command = 'yum --enablerepo=gf-plus -y install dovecot23 dovecot23-mysql' + elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + command = 'dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y' + else: + command = 'apt-get -y install dovecot-mysql' + + ProcessUtilities.executioner(command) + + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + + command = 'curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import' + subprocess.call(command, shell=True) + + command = 'gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg' + subprocess.call(command, shell=True) + + debPath = '/etc/apt/sources.list.d/dovecot.list' + writeToFile = open(debPath, 'w') + writeToFile.write('deb https://repo.dovecot.org/ce-2.3-latest/ubuntu/bionic bionic main\n') + writeToFile.close() + + try: + command = 'apt update -y' + subprocess.call(command, shell=True) + except: + pass + + try: + command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y' + subprocess.call(command, shell=True) + + command = 'dpkg --configure -a' + subprocess.call(command, shell=True) + + command = 'apt --fix-broken install -y' + subprocess.call(command, shell=True) + + command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y' + subprocess.call(command, shell=True) + except: + pass + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Postfix/dovecot reinstalled.,40') + + except BaseException as msg: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + '%s [install_postfix_dovecot][404]' % (str(msg)), 10) + return 0 + + return 1 + + def setup_email_Passwords(self, mysqlPassword): + try: + + mysql_virtual_domains = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_domains.cf" + mysql_virtual_forwardings = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_forwardings.cf" + mysql_virtual_mailboxes = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_mailboxes.cf" + mysql_virtual_email2email = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_email2email.cf" + dovecotmysql = "/usr/local/CyberCP/install/email-configs-one/dovecot-sql.conf.ext" + + ### update password: + + data = open(dovecotmysql, "r").readlines() + + writeDataToFile = open(dovecotmysql, "w") + + dataWritten = "connect = host=localhost dbname=cyberpanel user=cyberpanel password=" + mysqlPassword + " port=3306\n" + + for items in data: + if items.find("connect") > -1: + writeDataToFile.writelines(dataWritten) + else: + writeDataToFile.writelines(items) + + # if self.distro == ubuntu: + # os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) + + writeDataToFile.close() + + ### update password: + + data = open(mysql_virtual_domains, "r").readlines() + + writeDataToFile = open(mysql_virtual_domains, "w") + + dataWritten = "password = " + mysqlPassword + "\n" + + for items in data: + if items.find("password") > -1: + writeDataToFile.writelines(dataWritten) + else: + writeDataToFile.writelines(items) + + # if self.distro == ubuntu: + # os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) + + writeDataToFile.close() + + ### update password: + + data = open(mysql_virtual_forwardings, "r").readlines() + + writeDataToFile = open(mysql_virtual_forwardings, "w") + + dataWritten = "password = " + mysqlPassword + "\n" + + for items in data: + if items.find("password") > -1: + writeDataToFile.writelines(dataWritten) + else: + writeDataToFile.writelines(items) + + # if self.distro == ubuntu: + # os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) + + writeDataToFile.close() + + ### update password: + + data = open(mysql_virtual_mailboxes, "r").readlines() + + writeDataToFile = open(mysql_virtual_mailboxes, "w") + + dataWritten = "password = " + mysqlPassword + "\n" + + for items in data: + if items.find("password") > -1: + writeDataToFile.writelines(dataWritten) + else: + writeDataToFile.writelines(items) + + # if self.distro == ubuntu: + # os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) + + writeDataToFile.close() + + ### update password: + + data = open(mysql_virtual_email2email, "r").readlines() + + writeDataToFile = open(mysql_virtual_email2email, "w") + + dataWritten = "password = " + mysqlPassword + "\n" + + for items in data: + if items.find("password") > -1: + writeDataToFile.writelines(dataWritten) + else: + writeDataToFile.writelines(items) + + # if self.distro == ubuntu: + # os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR) + + writeDataToFile.close() + + if self.remotemysql == 'ON': + command = "sed -i 's|host=localhost|host=%s|g' %s" % (self.mysqlhost, dovecotmysql) + ProcessUtilities.executioner(command) + + command = "sed -i 's|port=3306|port=%s|g' %s" % (self.mysqlport, dovecotmysql) + ProcessUtilities.executioner(command) + + ## + + command = "sed -i 's|localhost|%s:%s|g' %s" % (self.mysqlhost, self.mysqlport, mysql_virtual_domains) + ProcessUtilities.executioner(command) + + command = "sed -i 's|localhost|%s:%s|g' %s" % ( + self.mysqlhost, self.mysqlport, mysql_virtual_forwardings) + ProcessUtilities.executioner(command) + + command = "sed -i 's|localhost|%s:%s|g' %s" % ( + self.mysqlhost, self.mysqlport, mysql_virtual_mailboxes) + ProcessUtilities.executioner(command) + + command = "sed -i 's|localhost|%s:%s|g' %s" % ( + self.mysqlhost, self.mysqlport, mysql_virtual_email2email) + ProcessUtilities.executioner(command) + except BaseException as msg: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + '%s [setup_email_Passwords][404]' % (str(msg)), 10) + return 0 + + return 1 + + def centos_lib_dir_to_ubuntu(self, filename, old, new): + try: + fd = open(filename, 'r') + lines = fd.readlines() + fd.close() + fd = open(filename, 'w') + centos_prefix = old + ubuntu_prefix = new + for line in lines: + index = line.find(centos_prefix) + if index != -1: + line = line[:index] + ubuntu_prefix + line[index + len(centos_prefix):] + fd.write(line) + fd.close() + except BaseException as msg: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + '%s [centos_lib_dir_to_ubuntu][404]' % (str(msg)), 10) + + def setup_postfix_dovecot_config(self): + try: + + mysql_virtual_domains = "/etc/postfix/mysql-virtual_domains.cf" + mysql_virtual_forwardings = "/etc/postfix/mysql-virtual_forwardings.cf" + mysql_virtual_mailboxes = "/etc/postfix/mysql-virtual_mailboxes.cf" + mysql_virtual_email2email = "/etc/postfix/mysql-virtual_email2email.cf" + main = "/etc/postfix/main.cf" + master = "/etc/postfix/master.cf" + dovecot = "/etc/dovecot/dovecot.conf" + dovecotmysql = "/etc/dovecot/dovecot-sql.conf.ext" + + if os.path.exists(mysql_virtual_domains): + os.remove(mysql_virtual_domains) + + if os.path.exists(mysql_virtual_forwardings): + os.remove(mysql_virtual_forwardings) + + if os.path.exists(mysql_virtual_mailboxes): + os.remove(mysql_virtual_mailboxes) + + if os.path.exists(mysql_virtual_email2email): + os.remove(mysql_virtual_email2email) + + if os.path.exists(main): + os.remove(main) + + if os.path.exists(master): + os.remove(master) + + if os.path.exists(dovecot): + os.remove(dovecot) + + if os.path.exists(dovecotmysql): + os.remove(dovecotmysql) + + ###############Getting SSL + + command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/postfix/key.pem -out /etc/postfix/cert.pem' + ProcessUtilities.executioner(command) + + ## + + command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/dovecot/key.pem -out /etc/dovecot/cert.pem' + ProcessUtilities.executioner(command) + + # Cleanup config files for ubuntu + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + self.centos_lib_dir_to_ubuntu("/usr/local/CyberCP/install/email-configs-one/master.cf", "/usr/libexec/", + "/usr/lib/") + self.centos_lib_dir_to_ubuntu("/usr/local/CyberCP/install/email-configs-one/main.cf", + "/usr/libexec/postfix", + "/usr/lib/postfix/sbin") + + ########### Copy config files + import shutil + + shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_domains.cf", + "/etc/postfix/mysql-virtual_domains.cf") + shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_forwardings.cf", + "/etc/postfix/mysql-virtual_forwardings.cf") + shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_mailboxes.cf", + "/etc/postfix/mysql-virtual_mailboxes.cf") + shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_email2email.cf", + "/etc/postfix/mysql-virtual_email2email.cf") + shutil.copy("/usr/local/CyberCP/install/email-configs-one/main.cf", main) + shutil.copy("/usr/local/CyberCP/install/email-configs-one/master.cf", master) + shutil.copy("/usr/local/CyberCP/install/email-configs-one/dovecot.conf", dovecot) + shutil.copy("/usr/local/CyberCP/install/email-configs-one/dovecot-sql.conf.ext", dovecotmysql) + + ######################################## Permissions + + command = 'chmod o= /etc/postfix/mysql-virtual_domains.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chmod o= /etc/postfix/mysql-virtual_forwardings.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chmod o= /etc/postfix/mysql-virtual_mailboxes.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chmod o= /etc/postfix/mysql-virtual_email2email.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chmod o= ' + main + ProcessUtilities.executioner(command) + + ## + + command = 'chmod o= ' + master + ProcessUtilities.executioner(command) + + ####################################### + + command = 'chgrp postfix /etc/postfix/mysql-virtual_domains.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chgrp postfix /etc/postfix/mysql-virtual_forwardings.cf' + ProcessUtilities.executioner(command) + ## + + command = 'chgrp postfix /etc/postfix/mysql-virtual_mailboxes.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chgrp postfix /etc/postfix/mysql-virtual_email2email.cf' + ProcessUtilities.executioner(command) + + ## + + command = 'chgrp postfix ' + main + ProcessUtilities.executioner(command) + + ## + + command = 'chgrp postfix ' + master + ProcessUtilities.executioner(command) + + ######################################## users and groups + + command = 'groupadd -g 5000 vmail' + ProcessUtilities.executioner(command) + + ## + + command = 'useradd -g vmail -u 5000 vmail -d /home/vmail -m' + ProcessUtilities.executioner(command) + + ######################################## Further configurations + + # hostname = socket.gethostname() + + ################################### Restart postix + + command = 'systemctl enable postfix.service' + ProcessUtilities.executioner(command) + + ## + + command = 'systemctl start postfix.service' + ProcessUtilities.executioner(command) + + ######################################## Permissions + + command = 'chgrp dovecot /etc/dovecot/dovecot-sql.conf.ext' + ProcessUtilities.executioner(command) + + ## + + command = 'chmod o= /etc/dovecot/dovecot-sql.conf.ext' + ProcessUtilities.executioner(command) + + ################################### Restart dovecot + + command = 'systemctl enable dovecot.service' + ProcessUtilities.executioner(command) + + ## + + command = 'systemctl start dovecot.service' + ProcessUtilities.executioner(command) + + ## + + command = 'systemctl restart postfix.service' + ProcessUtilities.executioner(command) + + ## changing permissions for main.cf + + command = "chmod 755 " + main + ProcessUtilities.executioner(command) + + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + command = "mkdir -p /etc/pki/dovecot/private/" + ProcessUtilities.executioner(command) + + command = "mkdir -p /etc/pki/dovecot/certs/" + ProcessUtilities.executioner(command) + + command = "mkdir -p /etc/opendkim/keys/" + ProcessUtilities.executioner(command) + + command = "sed -i 's/auth_mechanisms = plain/#auth_mechanisms = plain/g' /etc/dovecot/conf.d/10-auth.conf" + ProcessUtilities.executioner(command) + + ## Ubuntu 18.10 ssl_dh for dovecot 2.3.2.1 + + if ProcessUtilities.ubuntu: + dovecotConf = '/etc/dovecot/dovecot.conf' + + data = open(dovecotConf, 'r').readlines() + writeToFile = open(dovecotConf, 'w') + for items in data: + if items.find('ssl_key = -1: + writeToFile.writelines(items) + writeToFile.writelines('ssl_dh = -1: + self.RDS = 1 + + ## Also set localhost to this server + + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddressLocal = ipData.split('\n', 1)[0] + + self.LOCALHOST = ipAddressLocal + except BaseException as msg: + self.remotemysql = 'OFF' + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile('%s. [setupConnection:75]' % (str(msg))) + + ### + + self.checkIfMailServerSSLIssued() + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Removing and re-installing postfix/dovecot..,5') + + if self.install_postfix_dovecot() == 0: + return 0 + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Resetting configurations..,40') + + import sys + sys.path.append('/usr/local/CyberCP') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") + from CyberCP import settings + + if self.setup_email_Passwords(settings.DATABASES['default']['PASSWORD']) == 0: + return 0 + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Configurations reset..,70') + + if self.setup_postfix_dovecot_config() == 0: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'setup_postfix_dovecot_config failed. [404].') + return 0 + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Restoreing OpenDKIM configurations..,70') + + if self.configureOpenDKIM() == 0: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'configureOpenDKIM failed. [404].') + return 0 + + if self.MailSSL: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Setting up Mail Server SSL if any..,75') + from plogical.virtualHostUtilities import virtualHostUtilities + virtualHostUtilities.issueSSLForMailServer(self.mailHostName, + '/home/%s/public_html' % (self.mailHostName)) + + from websiteFunctions.models import ChildDomains + from plogical.virtualHostUtilities import virtualHostUtilities + for websites in Websites.objects.all(): + try: + child = ChildDomains.objects.get(domain='mail.%s' % (websites.domain)) + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Creating mail domain for %s..,80' % (websites.domain)) + virtualHostUtilities.setupAutoDiscover(1, '/dev/null', websites.domain, websites.admin) + except: + pass + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Fixing permissions..,90') + + self.fixCyberPanelPermissions() + + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].') + + except BaseException as msg: + final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def configureOpenDKIM(self): + try: + + ## Configure OpenDKIM specific settings + + openDKIMConfigurePath = "/etc/opendkim.conf" + + configData = """ +Mode sv +Canonicalization relaxed/simple +KeyTable refile:/etc/opendkim/KeyTable +SigningTable refile:/etc/opendkim/SigningTable +ExternalIgnoreList refile:/etc/opendkim/TrustedHosts +InternalHosts refile:/etc/opendkim/TrustedHosts +""" + + writeToFile = open(openDKIMConfigurePath, 'a') + writeToFile.write(configData) + writeToFile.close() + + ## Configure postfix specific settings + + postfixFilePath = "/etc/postfix/main.cf" + + configData = """ +smtpd_milters = inet:127.0.0.1:8891 +non_smtpd_milters = $smtpd_milters +milter_default_action = accept +""" + + writeToFile = open(postfixFilePath, 'a') + writeToFile.write(configData) + writeToFile.close() + + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + data = open(openDKIMConfigurePath, 'r').readlines() + writeToFile = open(openDKIMConfigurePath, 'w') + for items in data: + if items.find('Socket') > -1 and items.find('local:') and items[0] != '#': + writeToFile.writelines('Socket inet:8891@localhost\n') + else: + writeToFile.writelines(items) + writeToFile.close() + + #### Restarting Postfix and OpenDKIM + + command = "systemctl start opendkim" + ProcessUtilities.executioner(command) + + command = "systemctl enable opendkim" + ProcessUtilities.executioner(command) + + ## + + command = "systemctl restart postfix" + ProcessUtilities.executioner(command) + + return 1 + + except BaseException as msg: + return 0 + + def debugEmailForSite(self, websiteName): + + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddress = ipData.split('\n', 1)[0] + + try: + import socket + siteIPAddr = socket.gethostbyname('mail.%s' % (websiteName)) + + if siteIPAddr != ipAddress: + return 0, 'mail.%s does not point to %s.' % (websiteName, ipAddress) + except: + return 0, 'mail.%s does not point to %s.' % (websiteName, ipAddress) + + command = 'openssl s_client -connect mail.%s:993' % (websiteName) + result = ProcessUtilities.outputExecutioner(command) + + if result.find('18 (self signed certificate)') > -1: + return 0, 'No valid SSL on port 993.' + else: + return 1, 'All checks are OK.' + + def main(): @@ -744,6 +1627,7 @@ def main(): parser.add_argument('--password', help='Email password!') parser.add_argument('--tempConfigPath', help='Temporary Configuration Path!') parser.add_argument('--install', help='Enable/Disable Policy Server!') + parser.add_argument('--tempStatusPath', help='Path of temporary status file.') @@ -767,6 +1651,10 @@ def main(): mailUtilities.installMailScanner("install", "installMailScanner") elif args.function == 'AfterEffects': mailUtilities.AfterEffects(args.domain) + elif args.function == "ResetEmailConfigurations": + extraArgs = {'tempStatusPath': args.tempStatusPath} + background = MailServerManagerUtils(None, 'ResetEmailConfigurations', extraArgs) + background.ResetEmailConfigurations() if __name__ == "__main__": - main() \ No newline at end of file + main() From 4db90f0b9897d54fa3d0bb48ad67c82dd04a34cd Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 24 Apr 2021 04:57:15 +0500 Subject: [PATCH 09/72] bug fix: email debugger --- install/install.py | 33 --------------------------------- plogical/mailUtilities.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/install/install.py b/install/install.py index 46e596624..7bb2b6975 100755 --- a/install/install.py +++ b/install/install.py @@ -815,39 +815,6 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - # if self.distro != centos: - # command = 'curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import' - # subprocess.call(command, shell=True) - # - # command = 'gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg' - # subprocess.call(command, shell=True) - # - # debPath = '/etc/apt/sources.list.d/dovecot.list' - # writeToFile = open(debPath, 'w') - # writeToFile.write('deb https://repo.dovecot.org/ce-2.3-latest/ubuntu/bionic bionic main\n') - # writeToFile.close() - # - # try: - # command = 'apt update -y' - # subprocess.call(command, shell=True) - # except: - # pass - # - # try: - # command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y' - # subprocess.call(command, shell=True) - # - # command = 'dpkg --configure -a' - # subprocess.call(command, shell=True) - # - # command = 'apt --fix-broken install -y' - # subprocess.call(command, shell=True) - # - # command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y' - # subprocess.call(command, shell=True) - # except: - # pass - except BaseException as msg: logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_postfix_dovecot]") return 0 diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index e4644023e..af64af646 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -22,7 +22,6 @@ import bcrypt import getpass import smtplib import threading as multi -import socket try: from mailServer.models import Domains, EUsers @@ -757,6 +756,7 @@ class MailServerManagerUtils(multi.Thread): postFixData = ProcessUtilities.outputExecutioner('cat %s' % (postfixPath)) if postFixData.find('myhostname = server.example.com') > -1: + self.MailSSL = 0 return 0 else: try: @@ -768,6 +768,7 @@ class MailServerManagerUtils(multi.Thread): self.mailHostName = items.split('=')[1].strip(' ') self.MailSSL = 1 except BaseException as msg: + self.MailSSL = 0 logging.CyberCPLogFileWriter.writeToFile('%s. [checkIfMailServerSSLIssued:864]' % (str(msg))) ipFile = "/etc/cyberpanel/machineIP" @@ -825,6 +826,7 @@ class MailServerManagerUtils(multi.Thread): command = 'dnf install --enablerepo=gf-plus postfix3 postfix3-mysql -y' ProcessUtilities.executioner(command) else: + import socket command = 'apt-get install -y debconf-utils' ProcessUtilities.executioner(command) file_name = 'pf.unattend.text' @@ -1494,7 +1496,7 @@ class MailServerManagerUtils(multi.Thread): return 0 logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], - 'Restoreing OpenDKIM configurations..,70') + 'Restoring OpenDKIM configurations..,70') if self.configureOpenDKIM() == 0: logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], @@ -1526,9 +1528,8 @@ class MailServerManagerUtils(multi.Thread): logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].') except BaseException as msg: - final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)} - final_json = json.dumps(final_dic) - return HttpResponse(final_json) + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'Failed. Error %s [404].' % str(msg)) def configureOpenDKIM(self): try: @@ -1590,6 +1591,8 @@ milter_default_action = accept return 1 except BaseException as msg: + logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], + 'configureOpenDKIM failed. Error %s [404].' % str(msg)) return 0 def debugEmailForSite(self, websiteName): From 1d6a189947ed4a8b5086a3e22f1c08d7c2584204 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 24 Apr 2021 04:57:38 +0500 Subject: [PATCH 10/72] remove hostname creation until fixed --- cyberpanel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyberpanel.sh b/cyberpanel.sh index 3807901dc..75e4205d3 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -1785,7 +1785,7 @@ Post_Install_CN_Replacement fi # If valid hostname that resolves where we can issue an ssl we will create the hostname as a website so we can issue the SSL and do our first login without SSL warnings or exceptions needed. -HostName=$(hostname --fqdn); [ -z "$(dig +short "$HostName")" ] && echo "$HostName resolves to valid IP. Setting up hostname SSL" && cyberpanel createWebsite --package Default --owner admin --domainName $(hostname --fqdn) --email root@localhost --php 7.4 && cyberpanel hostNameSSL --domainName $(hostname --fqdn) +#HostName=$(hostname --fqdn); [ -z "$(dig +short "$HostName")" ] && echo "$HostName resolves to valid IP. Setting up hostname SSL" && cyberpanel createWebsite --package Default --owner admin --domainName $(hostname --fqdn) --email root@localhost --php 7.4 && cyberpanel hostNameSSL --domainName $(hostname --fqdn) } From d07bed5d59c72511a698ff491526f896174dbcb1 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 24 Apr 2021 21:42:04 +0500 Subject: [PATCH 11/72] bug fix: mail reset --- plogical/mailUtilities.py | 58 ++------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index af64af646..58d19726d 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -837,33 +837,13 @@ class MailServerManagerUtils(multi.Thread): command = 'debconf-set-selections ' + file_name ProcessUtilities.executioner(command) - command = 'apt-get -y install postfix' + command = 'apt-get -y install postfix postfix-mysql' # os.remove(file_name) ProcessUtilities.executioner(command) - import socket - # We are going to leverage postconfig -e to edit the settings for hostname - command = '"postconf -e "myhostname = %s"' % (str(socket.getfqdn())) - ProcessUtilities.executioner(command) - command = '"postconf -e "myhostname = %s"' % (str(socket.getfqdn())) - ProcessUtilities.executioner(command) - - # We are explicitly going to use sed to set the hostname default from "myhostname = server.example.com" - # to the fqdn from socket if the default is still found - postfix_main = '/etc/postfix/main.cf' - command = "sed -i 's|server.example.com|%s|g' %s" % (str(socket.getfqdn()), postfix_main) - ProcessUtilities.executioner(command) - logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing Dovecot..,15') - if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: - pass - else: - command = 'apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql' - - ProcessUtilities.executioner(command) - ## if ProcessUtilities.decideDistro() == ProcessUtilities.centos: @@ -871,44 +851,10 @@ class MailServerManagerUtils(multi.Thread): elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8: command = 'dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y' else: - command = 'apt-get -y install dovecot-mysql' + command = 'apt-get -y install dovecot-mysql dovecot-imapd dovecot-pop3d' ProcessUtilities.executioner(command) - if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: - - command = 'curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import' - subprocess.call(command, shell=True) - - command = 'gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg' - subprocess.call(command, shell=True) - - debPath = '/etc/apt/sources.list.d/dovecot.list' - writeToFile = open(debPath, 'w') - writeToFile.write('deb https://repo.dovecot.org/ce-2.3-latest/ubuntu/bionic bionic main\n') - writeToFile.close() - - try: - command = 'apt update -y' - subprocess.call(command, shell=True) - except: - pass - - try: - command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y' - subprocess.call(command, shell=True) - - command = 'dpkg --configure -a' - subprocess.call(command, shell=True) - - command = 'apt --fix-broken install -y' - subprocess.call(command, shell=True) - - command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y' - subprocess.call(command, shell=True) - except: - pass - logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Postfix/dovecot reinstalled.,40') From b6bb770ff53a8dd1b2847627c306021ac33e86a8 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 24 Apr 2021 22:39:55 +0500 Subject: [PATCH 12/72] enable gf repo on cent7 --- plogical/mailUtilities.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 58d19726d..636ff3e48 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -817,6 +817,10 @@ class MailServerManagerUtils(multi.Thread): logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing postfix..,10') if ProcessUtilities.decideDistro() == ProcessUtilities.centos: + + command = 'yum --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm -y' + ProcessUtilities.executioner(command) + command = 'yum install --enablerepo=gf-plus -y postfix3 postfix3-ldap postfix3-mysql postfix3-pcre' elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8: From a56401bc20b715fae33598637f471871dcc82dea Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 24 Apr 2021 23:17:32 +0500 Subject: [PATCH 13/72] enable gf repo on cent7 --- plogical/mailUtilities.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 636ff3e48..e79f5871d 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -748,6 +748,7 @@ class MailServerManagerUtils(multi.Thread): self.request = request self.function = function self.extraArgs = extraArgs + self.MailSSL = 0 def checkIfMailServerSSLIssued(self): From ae5eafff8e1747804fbc5fbb91e60822daebff1d Mon Sep 17 00:00:00 2001 From: WhatTheServer Date: Sat, 24 Apr 2021 19:21:23 -0400 Subject: [PATCH 14/72] Update cyberpanel.sh fix inversed conditional and additional check to ensure resolving is done externally --- cyberpanel.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cyberpanel.sh b/cyberpanel.sh index 75e4205d3..135e07ab3 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -1784,9 +1784,8 @@ if [[ "$Server_Country" = "CN" ]] ; then Post_Install_CN_Replacement fi -# If valid hostname that resolves where we can issue an ssl we will create the hostname as a website so we can issue the SSL and do our first login without SSL warnings or exceptions needed. -#HostName=$(hostname --fqdn); [ -z "$(dig +short "$HostName")" ] && echo "$HostName resolves to valid IP. Setting up hostname SSL" && cyberpanel createWebsite --package Default --owner admin --domainName $(hostname --fqdn) --email root@localhost --php 7.4 && cyberpanel hostNameSSL --domainName $(hostname --fqdn) - +# If valid hostname is set that resolves externally we can issue an ssl. This will create the hostname as a website so we can issue the SSL and do our first login without SSL warnings or exceptions needed. +HostName=$(hostname --fqdn); [ -n "$(dig @1.1.1.1 +short "$HostName")" ] && echo "$HostName resolves to valid IP. Setting up hostname SSL" && cyberpanel createWebsite --package Default --owner admin --domainName $(hostname --fqdn) --email root@localhost --php 7.4 && cyberpanel hostNameSSL --domainName $(hostname --fqdn) } From ec535d09611b4c11b22bb4ea73e826c03b61f68d Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 28 Apr 2021 01:04:29 +0500 Subject: [PATCH 15/72] bug fix: https://github.com/usmannasir/cyberpanel/issues/590 --- cloudAPI/cloudManager.py | 6 ++++++ mailServer/mailserverManager.py | 7 +++++++ plogical/IncScheduler.py | 1 + plogical/dnsUtilities.py | 6 ++++++ plogical/mailUtilities.py | 3 +++ 5 files changed, 23 insertions(+) diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 25f5c766b..84e36e4e5 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -2843,6 +2843,9 @@ class CloudManager: zones = cf.zones.get(params = {'per_page':100}) + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + for website in Websites.objects.all(): import tldextract extractDomain = tldextract.extract(website.domain) @@ -2882,6 +2885,9 @@ class CloudManager: ### For child domainsa + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + from websiteFunctions.models import ChildDomains for website in ChildDomains.objects.all(): diff --git a/mailServer/mailserverManager.py b/mailServer/mailserverManager.py index bbcc58d46..5a8f0b316 100755 --- a/mailServer/mailserverManager.py +++ b/mailServer/mailserverManager.py @@ -659,6 +659,9 @@ class MailServerManager(multi.Thread): try: + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + import tldextract extractDomain = tldextract.extract(domainName) @@ -717,6 +720,10 @@ class MailServerManager(multi.Thread): DNS.dnsTemplate(domainName, admin) if output.find("1,None") > -1: + + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + import tldextract extractDomain = tldextract.extract(domainName) diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index d3a9eea45..eac84a643 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -348,6 +348,7 @@ class IncScheduler(): @staticmethod def startNormalBackups(type): + from plogical.processUtilities import ProcessUtilities from plogical.backupSchedule import backupSchedule import socket diff --git a/plogical/dnsUtilities.py b/plogical/dnsUtilities.py index 401394dae..17bb25620 100755 --- a/plogical/dnsUtilities.py +++ b/plogical/dnsUtilities.py @@ -114,6 +114,9 @@ class DNS: ipData = f.read() ipAddress = ipData.split('\n', 1)[0] + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + import tldextract extractDomain = tldextract.extract(domain) @@ -515,6 +518,9 @@ class DNS: def createDKIMRecords(domain): try: + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + import tldextract extractDomain = tldextract.extract(domain) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index e79f5871d..747a3a179 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -218,6 +218,9 @@ class mailUtilities: try: ## Generate DKIM Keys + command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache' + ProcessUtilities.executioner(command) + import tldextract actualDomain = virtualHostName From 8b7a4d039e6a20fe3dbe794a070105ab30777993 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 28 Apr 2021 03:44:57 +0500 Subject: [PATCH 16/72] enhance: https://github.com/usmannasir/cyberpanel/issues/594 --- .../templates/baseTemplate/index.html | 2 +- static/userManagment/userManagment.js | 11 ++++- .../static/userManagment/userManagment.js | 11 ++++- .../templates/userManagment/listUsers.html | 41 +++++++++++++++++-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 12bdef14e..70f655dfb 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -76,7 +76,7 @@ - {% with version="2.1.1.1" %} + {% with version="2.1.2" %} diff --git a/static/userManagment/userManagment.js b/static/userManagment/userManagment.js index 2e6b3d189..f706d487f 100644 --- a/static/userManagment/userManagment.js +++ b/static/userManagment/userManagment.js @@ -1494,6 +1494,8 @@ app.controller('listTableUsers', function ($scope, $http) { $scope.cyberpanelLoading = true; + var UserToDelete; + $scope.populateCurrentRecords = function () { $scope.cyberpanelLoading = false; @@ -1547,13 +1549,18 @@ app.controller('listTableUsers', function ($scope, $http) { $scope.populateCurrentRecords(); - $scope.deleteUserFinal = function (name) { + $scope.deleteUserInitial = function (name){ + UserToDelete = name; + $scope.UserToDelete = name; + }; + + $scope.deleteUserFinal = function () { $scope.cyberpanelLoading = false; var url = "/users/submitUserDeletion"; var data = { - accountUsername: name, + accountUsername: UserToDelete, }; var config = { diff --git a/userManagment/static/userManagment/userManagment.js b/userManagment/static/userManagment/userManagment.js index 2e6b3d189..f706d487f 100755 --- a/userManagment/static/userManagment/userManagment.js +++ b/userManagment/static/userManagment/userManagment.js @@ -1494,6 +1494,8 @@ app.controller('listTableUsers', function ($scope, $http) { $scope.cyberpanelLoading = true; + var UserToDelete; + $scope.populateCurrentRecords = function () { $scope.cyberpanelLoading = false; @@ -1547,13 +1549,18 @@ app.controller('listTableUsers', function ($scope, $http) { $scope.populateCurrentRecords(); - $scope.deleteUserFinal = function (name) { + $scope.deleteUserInitial = function (name){ + UserToDelete = name; + $scope.UserToDelete = name; + }; + + $scope.deleteUserFinal = function () { $scope.cyberpanelLoading = false; var url = "/users/submitUserDeletion"; var data = { - accountUsername: name, + accountUsername: UserToDelete, }; var config = { diff --git a/userManagment/templates/userManagment/listUsers.html b/userManagment/templates/userManagment/listUsers.html index 0d8c0a591..d617d73a9 100755 --- a/userManagment/templates/userManagment/listUsers.html +++ b/userManagment/templates/userManagment/listUsers.html @@ -51,18 +51,53 @@ {% trans 'Suspend' %} + ng-click="controlUserState(record.name, 'SUSPEND')" + title="">{% trans 'Suspend' %} {% trans 'Activate' %} + ng-click="controlUserState(record.name, 'ACTIVATE')" + title="">{% trans 'Activate' %} {% trans 'Edit' %} - {% trans 'Delete' %} + + + +