From 0d5de30cade2dfa9e11bd93ce159cbd8914a12d5 Mon Sep 17 00:00:00 2001 From: qtwrk Date: Tue, 14 Jun 2022 13:34:12 +0200 Subject: [PATCH 1/2] remove powertools repo remove powertools repo --- cyberpanel_upgrade.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index 1f710bae8..457d2bc28 100644 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -392,15 +392,15 @@ EOF #all pre-upgrade operation for CentOS 7 elif [[ "$Server_OS_Version" = "8" ]] ; then - cat </etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo -[powertools-for-cyberpanel] -name=CentOS Linux \$releasever - PowerTools -mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=PowerTools&infra=\$infra -baseurl=http://mirror.centos.org/\$contentdir/\$releasever/PowerTools/\$basearch/os/ -gpgcheck=1 -enabled=1 -gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial -EOF +# cat </etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo +#[powertools-for-cyberpanel] +#name=CentOS Linux \$releasever - PowerTools +#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=PowerTools&infra=\$infra +#baseurl=http://mirror.centos.org/\$contentdir/\$releasever/PowerTools/\$basearch/os/ +#gpgcheck=1 +#enabled=1 +#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial +#EOF if [[ "$Server_Country" = "CN" ]] ; then dnf --nogpg install -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm From 1b8f0e1437ce8673ed06e804eae107c187205503 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 16 Jun 2022 00:06:31 +0500 Subject: [PATCH 2/2] add base for passprotect --- plogical/vhostConfs.py | 27 ++++++++ plogical/virtualHostUtilities.py | 67 +++++++++++++++++++ .../websiteFunctions/websiteFunctions.js | 31 +++++---- .../websiteFunctions/WPsiteHome.html | 9 ++- websiteFunctions/website.py | 14 +++- 5 files changed, 129 insertions(+), 19 deletions(-) diff --git a/plogical/vhostConfs.py b/plogical/vhostConfs.py index 244ddf225..be6c3e1f9 100755 --- a/plogical/vhostConfs.py +++ b/plogical/vhostConfs.py @@ -468,3 +468,30 @@ pm.max_spare_servers = {pmMaxSpareServers} } }'""" + + OLSPPConf = """ +### PASSWORD PROTECTION CONF STARTS + +realm {{RealM_Name}} { + + userDB { + location $SERVER_ROOT/conf/vhosts/$VH_NAME/htpasswd + } +} + +context / { + location {{path}} + allowBrowse 1 + realm {{RealM_Name}} + + rewrite { + + } + addDefaultCharset off + + phpIniOverride { + + } +} +### PASSWORD PROTECTION CONF ENDS +""" diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index fb5b1c2ab..da3b4c874 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -1245,6 +1245,71 @@ class virtualHostUtilities: return DiskUsage, DiskUsagePercentage, bwInMB, bwUsage + @staticmethod + def EnableDisablePP(vhostName, username=None, password=None, path=None): + try: + confPath = f'{virtualHostUtilities.vhostConfPath}/vhosts/{vhostName}/vhost.conf' + htpassword = f'{virtualHostUtilities.vhostConfPath}/vhosts/{vhostName}/htpasswd' + + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + if os.path.exists(htpassword): + os.remove(htpassword) + removeCheck = 0 + + data = open(confPath, 'r').readlines() + writeToFile = open(confPath, 'w') + for line in data: + if line.find('PASSWORD PROTECTION CONF STARTS') > -1: + removeCheck = 1 + continue + if line.find('PASSWORD PROTECTION CONF ENDS') > -1: + removeCheck = 0 + continue + + if removeCheck == 0: + writeToFile.writelines(line) + writeToFile.close() + else: + writeToFile = open(confPath, 'a') + from vhostConfs import vhostConfs + OLSPPConf = vhostConfs.OLSPPConf + OLSPPConf = OLSPPConf.replace('{{RealM_Name}}', str(randint(1000, 9999))) + OLSPPConf = OLSPPConf.replace('{{path}}', path) + + writeToFile.write(OLSPPConf) + writeToFile.close() + + ### + import bcrypt + password = password.encode() + hashed = bcrypt.hashpw(password, bcrypt.gensalt()) + print(hashed.decode()) + UserPass = f'{username}:{hashed}:{username}' + writeToFile = open(htpassword, 'w') + writeToFile.write(UserPass) + writeToFile.close() + + os.chmod(htpassword, 0o644) + + uBuntuPath = '/etc/lsb-release' + + if os.path.exists(uBuntuPath): + group = 'nogroup' + else: + group = 'nobody' + + command = f'chown lsadm:{group} {htpassword}' + ProcessUtilities.executioner(command) + print('1,None') + + + + + except BaseException as msg: + print(f'0,{str(msg)}') + return 0,str(msg) + + def main(): parser = argparse.ArgumentParser(description='CyberPanel Installer') @@ -1412,6 +1477,8 @@ def main(): virtualHostUtilities.deleteDomain(args.virtualHostName, int(args.DeleteDocRoot)) elif args.function == 'switchServer': virtualHostUtilities.switchServer(args.virtualHostName, args.phpVersion, int(args.server), args.tempStatusPath) + elif args.function == 'EnableDisablePP': + virtualHostUtilities.EnableDisablePP(args.virtualHostName, args.username, args.password, args.path) if __name__ == "__main__": diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index ea819f119..c59807464 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -551,20 +551,26 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $scope.wordpresshomeloading = false; - var settingValue = 0; - - if ($('#' + setting).is(":checked")) { - settingValue = 1; - } var url = "/websites/UpdateWPSettings"; - var data = { - WPid: $('#WPid').html(), - setting: setting, - settingValue: settingValue - - + if (setting === "PasswordProtection") { + var data = { + WPid: $('#WPid').html(), + setting: setting, + PPUsername: $scope.PPUsername, + PPPassword: $scope.PPPassword, + } + } else { + var settingValue = 0; + if ($('#' + setting).is(":checked")) { + settingValue = 1; + } + var data = { + WPid: $('#WPid').html(), + setting: setting, + settingValue: settingValue + } } @@ -1583,7 +1589,8 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { // if (d == -1 || c == "") { // alert("Please Select Method of Backup Restore"); // } else { - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + // } diff --git a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html index 1f4dfb47c..e2c5be04e 100644 --- a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html +++ b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html @@ -135,8 +135,7 @@
Password Protection
- @@ -165,13 +164,13 @@
-
-
@@ -179,7 +178,7 @@