mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 16:26:12 +01:00
update jwt secret
This commit is contained in:
@@ -2018,15 +2018,15 @@ def get_terminal_jwt(request):
|
|||||||
return JsonResponse({'status': 0, 'error_message': 'SSH user not configured for this website.'})
|
return JsonResponse({'status': 0, 'error_message': 'SSH user not configured for this website.'})
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import jwt as pyjwt
|
import jwt as pyjwt
|
||||||
# Read JWT_SECRET from fastapi_ssh_server.py
|
# Read JWT_SECRET from fastapi_ssh_server.py using ProcessUtilities
|
||||||
jwt_secret = None
|
jwt_secret = None
|
||||||
try:
|
try:
|
||||||
with open('/usr/local/CyberCP/fastapi_ssh_server.py', 'r') as f:
|
content = ProcessUtilities.outputExecutioner('cat /usr/local/CyberCP/fastapi_ssh_server.py')
|
||||||
for line in f:
|
for line in content.splitlines():
|
||||||
m = re.match(r'\s*JWT_SECRET\s*=\s*[\'"](.+)[\'"]', line)
|
m = re.match(r'\s*JWT_SECRET\s*=\s*[\'"](.+)[\'"]', line)
|
||||||
if m and m.group(1) != 'REPLACE_ME_WITH_INSTALLER':
|
if m and m.group(1) != 'REPLACE_ME_WITH_INSTALLER':
|
||||||
jwt_secret = m.group(1)
|
jwt_secret = m.group(1)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Could not read JWT_SECRET: {e}")
|
logger.error(f"Could not read JWT_SECRET: {e}")
|
||||||
if not jwt_secret:
|
if not jwt_secret:
|
||||||
|
|||||||
@@ -4989,19 +4989,20 @@ StrictHostKeyChecking no
|
|||||||
from plogical.processUtilities import ProcessUtilities
|
from plogical.processUtilities import ProcessUtilities
|
||||||
|
|
||||||
fastapi_file = '/usr/local/CyberCP/fastapi_ssh_server.py'
|
fastapi_file = '/usr/local/CyberCP/fastapi_ssh_server.py'
|
||||||
|
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter
|
||||||
try:
|
try:
|
||||||
with open(fastapi_file, 'r') as f:
|
|
||||||
content = f.read()
|
content = ProcessUtilities.outputExecutioner(f'cat {fastapi_file}')
|
||||||
m = re.search(r'JWT_SECRET\s*=\s*[\'"](.+)[\'"]', content)
|
if 'REPLACE_ME_WITH_INSTALLER' in content:
|
||||||
if m and m.group(1) in ['REPLACE_ME_WITH_INSTALLER', 'YOUR_SECRET_KEY']:
|
|
||||||
new_secret = secrets.token_urlsafe(32)
|
new_secret = secrets.token_urlsafe(32)
|
||||||
# Use sed to replace the line in-place (macOS compatible)
|
|
||||||
sed_cmd = f"sed -i '' 's|JWT_SECRET = \"{m.group(1)}\"|JWT_SECRET = \"{new_secret}\"|' '{fastapi_file}'"
|
sed_cmd = f"sed -i 's|JWT_SECRET = \"REPLACE_ME_WITH_INSTALLER\"|JWT_SECRET = \"{new_secret}\"|' '{fastapi_file}'"
|
||||||
ProcessUtilities.outputExecutioner(sed_cmd)
|
ProcessUtilities.outputExecutioner(sed_cmd)
|
||||||
|
|
||||||
command = 'systemctl restart fastapi_ssh_server'
|
command = 'systemctl restart fastapi_ssh_server'
|
||||||
ProcessUtilities.outputExecutioner(command)
|
ProcessUtilities.outputExecutioner(command)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
|
CyberCPLogFileWriter.writeLog(f"Failed to update JWT secret: {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
|||||||
Reference in New Issue
Block a user