mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-02-17 03:56:48 +01:00
DNS: cache-bust dns.js (DNS_STATIC_VERSION), no-cache headers on CloudFlare page
This commit is contained in:
@@ -141,6 +141,7 @@ TEMPLATES = [
|
||||
'baseTemplate.context_processors.cosmetic_context',
|
||||
'baseTemplate.context_processors.notification_preferences_context',
|
||||
'baseTemplate.context_processors.firewall_static_context',
|
||||
'baseTemplate.context_processors.dns_static_context',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -77,4 +77,29 @@ def firewall_static_context(request):
|
||||
version = int(time.time())
|
||||
return {
|
||||
'FIREWALL_STATIC_VERSION': version
|
||||
}
|
||||
|
||||
|
||||
def dns_static_context(request):
|
||||
"""Cache-busting for DNS static assets (bumps when dns.js changes). Avoids stale JS/layout."""
|
||||
try:
|
||||
from django.conf import settings
|
||||
base = settings.BASE_DIR
|
||||
paths = [
|
||||
os.path.join(base, 'dns', 'static', 'dns', 'dns.js'),
|
||||
os.path.join(base, 'static', 'dns', 'dns.js'),
|
||||
os.path.join(base, 'public', 'static', 'dns', 'dns.js'),
|
||||
]
|
||||
version = 0
|
||||
for p in paths:
|
||||
try:
|
||||
version = max(version, int(os.path.getmtime(p)))
|
||||
except (OSError, TypeError):
|
||||
pass
|
||||
if version <= 0:
|
||||
version = int(time.time())
|
||||
except (OSError, AttributeError):
|
||||
version = int(time.time())
|
||||
return {
|
||||
'DNS_STATIC_VERSION': version
|
||||
}
|
||||
@@ -2220,7 +2220,7 @@
|
||||
<script src="{% static 'websiteFunctions/websiteFunctions.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'userManagment/userManagment.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'databases/databases.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'dns/dns.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'dns/dns.js' %}?v={{ CP_VERSION }}&dns={{ DNS_STATIC_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'mailServer/mailServer.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'ftp/ftp.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
<script src="{% static 'backup/backup.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||
|
||||
@@ -199,7 +199,12 @@ def addDeleteDNSRecordsCloudFlare(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DNSManager()
|
||||
return dm.addDeleteDNSRecordsCloudFlare(request, userID)
|
||||
response = dm.addDeleteDNSRecordsCloudFlare(request, userID)
|
||||
if hasattr(response, 'headers'):
|
||||
response['Cache-Control'] = 'no-cache, no-store, must-revalidate, max-age=0'
|
||||
response['Pragma'] = 'no-cache'
|
||||
response['Expires'] = '0'
|
||||
return response
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user