mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
fix password protection backend
This commit is contained in:
@@ -1990,31 +1990,55 @@ class WebsiteManager:
|
|||||||
path = f'{vhostPassDir}/{siteId}'
|
path = f'{vhostPassDir}/{siteId}'
|
||||||
if value:
|
if value:
|
||||||
# Enable password protection
|
# Enable password protection
|
||||||
if not os.path.exists(path):
|
tempPath = f'/home/cyberpanel/{str(randint(1000, 9999))}'
|
||||||
os.makedirs(path)
|
os.makedirs(tempPath)
|
||||||
htpasswd = f'{path}/.htpasswd'
|
|
||||||
htaccess = f'{wpsite.path}/.htaccess'
|
# Create temporary .htpasswd file
|
||||||
|
htpasswd = f'{tempPath}/.htpasswd'
|
||||||
|
htaccess = f'{tempPath}/.htaccess'
|
||||||
password = randomPassword.generate_pass(12)
|
password = randomPassword.generate_pass(12)
|
||||||
|
|
||||||
# Create .htpasswd file
|
# Create .htpasswd file
|
||||||
command = f"htpasswd -cb {htpasswd} admin {password}"
|
command = f"htpasswd -cb {htpasswd} admin {password}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
# Create .htaccess file
|
# Create .htaccess file content
|
||||||
htaccess_content = f"""AuthType Basic
|
htaccess_content = f"""
|
||||||
|
AuthType Basic
|
||||||
AuthName "Restricted Access"
|
AuthName "Restricted Access"
|
||||||
AuthUserFile {htpasswd}
|
AuthUserFile {path}/.htpasswd
|
||||||
Require valid-user"""
|
Require valid-user
|
||||||
|
"""
|
||||||
|
|
||||||
with open(htaccess, 'w') as f:
|
with open(htaccess, 'w') as f:
|
||||||
f.write(htaccess_content)
|
f.write(htaccess_content)
|
||||||
|
|
||||||
|
# Create final directory and move files
|
||||||
|
command = f"mkdir -p {path}"
|
||||||
|
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
|
||||||
|
|
||||||
|
# Move files to final location
|
||||||
|
command = f"mv {htpasswd} {path}/.htpasswd"
|
||||||
|
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
|
||||||
|
|
||||||
|
command = f"mv {htaccess} {wpsite.path}/.htaccess"
|
||||||
|
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
|
||||||
|
|
||||||
|
# Cleanup temp directory
|
||||||
|
command = f"rm -rf {tempPath}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Disable password protection
|
# Disable password protection
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
import shutil
|
command = f"rm -rf {path}"
|
||||||
shutil.rmtree(path)
|
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
|
||||||
|
|
||||||
htaccess = f'{wpsite.path}/.htaccess'
|
htaccess = f'{wpsite.path}/.htaccess'
|
||||||
if os.path.exists(htaccess):
|
if os.path.exists(htaccess):
|
||||||
os.remove(htaccess)
|
command = f"rm -f {htaccess}"
|
||||||
|
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
|
||||||
|
|
||||||
return JsonResponse({'status': 1, 'error_message': 'None'})
|
return JsonResponse({'status': 1, 'error_message': 'None'})
|
||||||
elif setting == 'maintenance-mode':
|
elif setting == 'maintenance-mode':
|
||||||
if value:
|
if value:
|
||||||
@@ -2033,6 +2057,9 @@ Require valid-user"""
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
return JsonResponse({'status': 0, 'error_message': str(msg)})
|
return JsonResponse({'status': 0, 'error_message': str(msg)})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def submitWorpressCreation(self, userID=None, data=None):
|
def submitWorpressCreation(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|||||||
Reference in New Issue
Block a user