mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-03-06 12:20:45 +01:00
additional setting for improved wp page
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
{% csrf_token %}
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
@@ -302,7 +303,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="wp-site-content">
|
||||
<img src="{% if site.screenshot %}{{ site.screenshot }}{% else %}{% static 'images/wp-default.png' %}{% endif %}"
|
||||
<img src="{% if site.screenshot %}{{ site.screenshot }}{% else %}{% static 'websiteFunctions/images/wp-default.png' %}{% endif %}"
|
||||
class="wp-site-preview" alt="{{ site.title }}">
|
||||
|
||||
<div class="wp-site-info">
|
||||
@@ -368,17 +369,24 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Function to fetch and update site data
|
||||
function updateSiteData(siteId) {
|
||||
fetch('/websiteFunctions/FetchWPdata', {
|
||||
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||
|
||||
fetch('{% url "FetchWPdata" %}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
WPid: siteId
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.status === 1) {
|
||||
const site = data.ret_data;
|
||||
@@ -402,6 +410,13 @@
|
||||
site.passwordprotection === 1;
|
||||
document.querySelector(`.maintenance-mode[data-site-id="${siteId}"]`).checked =
|
||||
site.maintenanceMode === 1;
|
||||
} else {
|
||||
console.error('Error in response:', data);
|
||||
document.querySelectorAll(`[data-site-id="${siteId}"]`).forEach(el => {
|
||||
if (el.tagName !== 'INPUT') {
|
||||
el.textContent = 'Error loading';
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -414,21 +429,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Get CSRF token from cookies
|
||||
function getCookie(name) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
// Add CSRF token to the page
|
||||
const csrfToken = '{% csrf_token %}';
|
||||
document.body.insertAdjacentHTML('beforeend', csrfToken);
|
||||
|
||||
// Update data for all sites
|
||||
document.querySelectorAll('.wp-site-card').forEach(card => {
|
||||
@@ -442,12 +445,13 @@
|
||||
const siteId = this.dataset.siteId;
|
||||
const setting = this.className;
|
||||
const value = this.checked ? 1 : 0;
|
||||
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||
|
||||
fetch('/websiteFunctions/UpdateWPSettings', {
|
||||
fetch('{% url "UpdateWPSettings" %}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
siteId: siteId,
|
||||
@@ -455,7 +459,12 @@
|
||||
value: value
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (!data.status) {
|
||||
// Revert toggle if update failed
|
||||
@@ -472,9 +481,9 @@
|
||||
});
|
||||
});
|
||||
|
||||
function DeleteWPNow(url, siteId) {
|
||||
function DeleteWPNow(url) {
|
||||
if (confirm('Are you sure you want to delete this WordPress site?')) {
|
||||
window.location.href = `${url}?DeleteID=${siteId}`;
|
||||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user