mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-07 03:15:51 +02: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.cosmetic_context',
|
||||||
'baseTemplate.context_processors.notification_preferences_context',
|
'baseTemplate.context_processors.notification_preferences_context',
|
||||||
'baseTemplate.context_processors.firewall_static_context',
|
'baseTemplate.context_processors.firewall_static_context',
|
||||||
|
'baseTemplate.context_processors.dns_static_context',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,3 +78,28 @@ def firewall_static_context(request):
|
|||||||
return {
|
return {
|
||||||
'FIREWALL_STATIC_VERSION': version
|
'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 '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 '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 '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 '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 'ftp/ftp.js' %}?v={{ CP_VERSION }}" data-cfasync="false"></script>
|
||||||
<script src="{% static 'backup/backup.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:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
dm = DNSManager()
|
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:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user