add warning for terminal ssl

This commit is contained in:
usmannasir
2025-05-19 13:27:16 +05:00
parent 731914d9f7
commit 4ade411285
3 changed files with 47 additions and 1 deletions

View File

@@ -209,6 +209,13 @@
</div> </div>
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% if accessed_via_ip %}
<div class="alert alert-danger ssh-access-warning">
<strong>Notice:</strong> You are accessing CyberPanel via an <b>IP address</b>.<br>
The Web Terminal will not work when accessed via IP. Please issue a <b>hostname SSL</b> and access the panel using your hostname (with valid SSL) to enable the terminal.<br>
<a href="{{ ssl_issue_link }}" target="_blank" class="btn btn-warning" style="margin-top:10px;">Issue Hostname SSL</a>
</div>
{% endif %}
{% if is_selfsigned_ssl %} {% if is_selfsigned_ssl %}
<div class="alert alert-warning ssh-access-warning"> <div class="alert alert-warning ssh-access-warning">
<strong>Warning:</strong> Your server is using a <b>self-signed SSL certificate</b> for the web terminal.<br> <strong>Warning:</strong> Your server is using a <b>self-signed SSL certificate</b> for the web terminal.<br>

View File

@@ -142,6 +142,14 @@
{% if not error %} {% if not error %}
{% if accessed_via_ip %}
<div class="alert alert-danger ssh-access-warning">
<strong>Notice:</strong> You are accessing CyberPanel via an <b>IP address</b>.<br>
The Web Terminal will not work when accessed via IP. Please issue a <b>hostname SSL</b> and access the panel using your hostname (with valid SSL) to enable the terminal.<br>
<a href="{{ ssl_issue_link }}" target="_blank" class="btn btn-warning" style="margin-top:10px;">Issue Hostname SSL</a>
</div>
{% endif %}
<div style="display:flex;justify-content:flex-end;gap:18px;margin-bottom:18px;align-items:center;"> <div style="display:flex;justify-content:flex-end;gap:18px;margin-bottom:18px;align-items:center;">
<!-- Open Terminal Button --> <!-- Open Terminal Button -->
<button ng-click="openWebTerminal()" type="button" class="btn btn-success" <button ng-click="openWebTerminal()" type="button" class="btn btn-success"

View File

@@ -43,6 +43,7 @@ from plogical.cronUtil import CronUtil
from .StagingSetup import StagingSetup from .StagingSetup import StagingSetup
import validators import validators
from django.http import JsonResponse from django.http import JsonResponse
import ipaddress
class WebsiteManager: class WebsiteManager:
@@ -3111,6 +3112,23 @@ Require valid-user
Data['is_selfsigned_ssl'] = bool(is_selfsigned) Data['is_selfsigned_ssl'] = bool(is_selfsigned)
Data['ssl_issue_link'] = ssl_issue_link Data['ssl_issue_link'] = ssl_issue_link
# Detect if accessed via IP
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter
accessed_via_ip = False
try:
host = request.get_host().split(':')[0] # Remove port if present
try:
ipaddress.ip_address(host)
accessed_via_ip = True
except ValueError:
accessed_via_ip = False
except Exception as e:
accessed_via_ip = False
CyberCPLogFileWriter.writeToFile(f"Error detecting accessed_via_ip: {str(e)}")
Data['accessed_via_ip'] = bool(accessed_via_ip)
proc = httpProc(request, 'websiteFunctions/website.html', Data) proc = httpProc(request, 'websiteFunctions/website.html', Data)
return proc.render() return proc.render()
else: else:
@@ -5096,8 +5114,21 @@ StrictHostKeyChecking no
is_selfsigned = True # If cert missing or unreadable, treat as self-signed is_selfsigned = True # If cert missing or unreadable, treat as self-signed
CyberCPLogFileWriter.writeToFile(f"is_selfsigned: {is_selfsigned}. Error: {str(e)}") CyberCPLogFileWriter.writeToFile(f"is_selfsigned: {is_selfsigned}. Error: {str(e)}")
# Detect if accessed via IP
accessed_via_ip = False
try:
host = request.get_host().split(':')[0] # Remove port if present
try:
ipaddress.ip_address(host)
accessed_via_ip = True
except ValueError:
accessed_via_ip = False
except Exception as e:
accessed_via_ip = False
CyberCPLogFileWriter.writeToFile(f"Error detecting accessed_via_ip: {str(e)}")
proc = httpProc(request, 'websiteFunctions/sshAccess.html', proc = httpProc(request, 'websiteFunctions/sshAccess.html',
{'domainName': self.domain, 'externalApp': externalApp, 'has_addons': has_addons, 'is_selfsigned_ssl': is_selfsigned, 'ssl_issue_link': ssl_issue_link}) {'domainName': self.domain, 'externalApp': externalApp, 'has_addons': has_addons, 'is_selfsigned_ssl': is_selfsigned, 'ssl_issue_link': ssl_issue_link, 'accessed_via_ip': accessed_via_ip})
return proc.render() return proc.render()
def saveSSHAccessChanges(self, userID=None, data=None): def saveSSHAccessChanges(self, userID=None, data=None):