From 114624896405249121582b3bb5061d03aa7a11e7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 13 Oct 2023 09:41:10 +0200 Subject: [PATCH 1/2] Revert "Fix AJAX JSON data (#2742)" This reverts commit 340d373711c29a9eba0bba1afd94c3205ad943b2, reversing changes made to 1ed1efdc91320e36b2bcedcfb9e9c4f3b1402375. Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 5 ++--- scripts/pi-hole/js/groups-adlists.js | 6 +++--- scripts/pi-hole/js/groups-clients.js | 6 +++--- scripts/pi-hole/js/groups-domains.js | 8 ++++---- scripts/pi-hole/js/groups.js | 8 ++++---- scripts/pi-hole/js/login.js | 3 +-- scripts/pi-hole/js/settings-api.js | 3 +-- scripts/pi-hole/js/settings.js | 3 +-- scripts/pi-hole/js/utils.js | 4 ++-- 9 files changed, 21 insertions(+), 25 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 6cd7bfba4..70bc1d391 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -119,11 +119,10 @@ function piholeChange(action, duration) { $.ajax({ url: "/api/dns/blocking", method: "POST", - dataType: "json", - data: { + data: JSON.stringify({ blocking: action === "enable", timer: parseInt(duration, 10) > 0 ? parseInt(duration, 10) : null, - }, + }), }) .done(function (data) { if (data.blocking === action + "d") { diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 624972b3c..84ff709c2 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -516,7 +516,7 @@ function addAdlist(event) { url: "/api/lists", method: "post", dataType: "json", - data: { address: address, comment: comment, type: type }, + data: JSON.stringify({ address: address, comment: comment, type: type }), success: function () { utils.enableAll(); utils.showAlert("success", "fas fa-plus", "Successfully added " + type + "list", address); @@ -582,12 +582,12 @@ function editAdlist() { url: "/api/lists/" + encodeURIComponent(addressDecoded), method: "put", dataType: "json", - data: { + data: JSON.stringify({ groups: groups, comment: comment, enabled: enabled, type: type, - }, + }), success: function () { utils.enableAll(); utils.showAlert( diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 6a7aecefa..843be7b97 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -440,7 +440,7 @@ function addClient() { url: "/api/clients", method: "post", dataType: "json", - data: { client: ip, comment: comment }, + data: JSON.stringify({ client: ip, comment: comment }), success: function () { utils.enableAll(); utils.showAlert("success", "fas fa-plus", "Successfully added client", ip); @@ -495,12 +495,12 @@ function editClient() { url: "/api/clients/" + encodeURIComponent(clientDecoded), method: "put", dataType: "json", - data: { + data: JSON.stringify({ client: client, groups: groups, comment: comment, enabled: enabled, - }, + }), success: function () { utils.enableAll(); utils.showAlert( diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 8158caf88..1429a95a1 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -527,12 +527,12 @@ function addDomain() { url: "/api/domains/" + type + "/" + kind, method: "post", dataType: "json", - data: { + data: JSON.stringify({ domain: domain, comment: comment, type: type, kind: kind, - }, + }), success: function () { utils.enableAll(); utils.showAlert("success", "fas fa-plus", "Successfully added domain", domain); @@ -609,13 +609,13 @@ function editDomain() { url: "/api/domains/" + newTypestr + "/" + encodeURIComponent(domainDecoded), method: "put", dataType: "json", - data: { + data: JSON.stringify({ groups: groups, comment: comment, enabled: enabled, type: oldType, kind: oldKind, - }, + }), success: function () { utils.enableAll(); utils.showAlert( diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js index 5e8f99303..0beab5baf 100644 --- a/scripts/pi-hole/js/groups.js +++ b/scripts/pi-hole/js/groups.js @@ -294,11 +294,11 @@ function addGroup() { url: "/api/groups", method: "post", dataType: "json", - data: { + data: JSON.stringify({ name: name, comment: comment, enabled: true, - }, + }), success: function () { utils.enableAll(); utils.showAlert("success", "fas fa-plus", "Successfully added group", name); @@ -360,11 +360,11 @@ function editGroup() { url: "/api/groups/" + oldName, method: "put", dataType: "json", - data: { + data: JSON.stringify({ name: name, comment: comment, enabled: enabled, - }, + }), success: function () { utils.enableAll(); utils.showAlert("success", "fas fa-pencil-alt", "Successfully " + done + " group", oldName); diff --git a/scripts/pi-hole/js/login.js b/scripts/pi-hole/js/login.js index 4dc518f47..3f4028413 100644 --- a/scripts/pi-hole/js/login.js +++ b/scripts/pi-hole/js/login.js @@ -60,8 +60,7 @@ function doLogin(password) { $.ajax({ url: "/api/auth", method: "POST", - dataType: "json", - data: { password: password, totp: parseInt($("#totp").val(), 10) }, + data: JSON.stringify({ password: password, totp: parseInt($("#totp").val(), 10) }), }) .done(function () { wrongPassword(false, true); diff --git a/scripts/pi-hole/js/settings-api.js b/scripts/pi-hole/js/settings-api.js index 6bb17f678..b0e4fea21 100644 --- a/scripts/pi-hole/js/settings-api.js +++ b/scripts/pi-hole/js/settings-api.js @@ -318,8 +318,7 @@ function setTOTPSecret(secret) { $.ajax({ url: "/api/config", type: "PATCH", - dataType: "json", - data: { config: { webserver: { api: { totp_secret: secret } } } }, + data: JSON.stringify({ config: { webserver: { api: { totp_secret: secret } } } }), contentType: "application/json", }) .done(function () { diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index b7ef7265e..6922cdbb5 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -137,8 +137,7 @@ function saveSettings() { $.ajax({ url: "/api/config", method: "PATCH", - dataType: "json", - data: { config: settings }, + data: JSON.stringify({ config: settings }), contentType: "application/json; charset=utf-8", }) .done(function () { diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 530725ab0..cbeb63041 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -315,12 +315,12 @@ function addFromQueryLog(domain, list) { url: "/api/domains/" + list + "/exact", method: "post", dataType: "json", - data: { + data: JSON.stringify({ domain: domain, comment: "Added from Query Log", type: list, kind: "exact", - }, + }), success: function (response) { alProcessing.hide(); if ("domains" in response && response.domains.length > 0) { From 43c8ede674aba2a492025a6f74d214388a4698e4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 13 Oct 2023 09:44:01 +0200 Subject: [PATCH 2/2] Add "processData: false" to all JSON data we send Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 2 ++ scripts/pi-hole/js/groups-adlists.js | 2 ++ scripts/pi-hole/js/groups-clients.js | 2 ++ scripts/pi-hole/js/groups-domains.js | 2 ++ scripts/pi-hole/js/groups.js | 2 ++ scripts/pi-hole/js/login.js | 2 ++ scripts/pi-hole/js/settings-api.js | 2 ++ scripts/pi-hole/js/settings-system.js | 2 ++ scripts/pi-hole/js/settings.js | 2 ++ scripts/pi-hole/js/utils.js | 1 + 10 files changed, 19 insertions(+) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 70bc1d391..289f104c9 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -119,6 +119,8 @@ function piholeChange(action, duration) { $.ajax({ url: "/api/dns/blocking", method: "POST", + dataType: "json", + processData: false, data: JSON.stringify({ blocking: action === "enable", timer: parseInt(duration, 10) > 0 ? parseInt(duration, 10) : null, diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 84ff709c2..c05a84ad3 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -516,6 +516,7 @@ function addAdlist(event) { url: "/api/lists", method: "post", dataType: "json", + processData: false, data: JSON.stringify({ address: address, comment: comment, type: type }), success: function () { utils.enableAll(); @@ -582,6 +583,7 @@ function editAdlist() { url: "/api/lists/" + encodeURIComponent(addressDecoded), method: "put", dataType: "json", + processData: false, data: JSON.stringify({ groups: groups, comment: comment, diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 843be7b97..32483b4f9 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -440,6 +440,7 @@ function addClient() { url: "/api/clients", method: "post", dataType: "json", + processData: false, data: JSON.stringify({ client: ip, comment: comment }), success: function () { utils.enableAll(); @@ -495,6 +496,7 @@ function editClient() { url: "/api/clients/" + encodeURIComponent(clientDecoded), method: "put", dataType: "json", + processData: false, data: JSON.stringify({ client: client, groups: groups, diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js index 1429a95a1..d0f07e01e 100644 --- a/scripts/pi-hole/js/groups-domains.js +++ b/scripts/pi-hole/js/groups-domains.js @@ -527,6 +527,7 @@ function addDomain() { url: "/api/domains/" + type + "/" + kind, method: "post", dataType: "json", + processData: false, data: JSON.stringify({ domain: domain, comment: comment, @@ -609,6 +610,7 @@ function editDomain() { url: "/api/domains/" + newTypestr + "/" + encodeURIComponent(domainDecoded), method: "put", dataType: "json", + processData: false, data: JSON.stringify({ groups: groups, comment: comment, diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js index 0beab5baf..fdb9ed360 100644 --- a/scripts/pi-hole/js/groups.js +++ b/scripts/pi-hole/js/groups.js @@ -294,6 +294,7 @@ function addGroup() { url: "/api/groups", method: "post", dataType: "json", + processData: false, data: JSON.stringify({ name: name, comment: comment, @@ -360,6 +361,7 @@ function editGroup() { url: "/api/groups/" + oldName, method: "put", dataType: "json", + processData: false, data: JSON.stringify({ name: name, comment: comment, diff --git a/scripts/pi-hole/js/login.js b/scripts/pi-hole/js/login.js index 3f4028413..ef1ff70fa 100644 --- a/scripts/pi-hole/js/login.js +++ b/scripts/pi-hole/js/login.js @@ -60,6 +60,8 @@ function doLogin(password) { $.ajax({ url: "/api/auth", method: "POST", + dataType: "json", + processData: false, data: JSON.stringify({ password: password, totp: parseInt($("#totp").val(), 10) }), }) .done(function () { diff --git a/scripts/pi-hole/js/settings-api.js b/scripts/pi-hole/js/settings-api.js index b0e4fea21..d2e80cc8a 100644 --- a/scripts/pi-hole/js/settings-api.js +++ b/scripts/pi-hole/js/settings-api.js @@ -318,6 +318,8 @@ function setTOTPSecret(secret) { $.ajax({ url: "/api/config", type: "PATCH", + dataType: "json", + processData: false, data: JSON.stringify({ config: { webserver: { api: { totp_secret: secret } } } }), contentType: "application/json", }) diff --git a/scripts/pi-hole/js/settings-system.js b/scripts/pi-hole/js/settings-system.js index a7f8b4256..c7f5c6477 100644 --- a/scripts/pi-hole/js/settings-system.js +++ b/scripts/pi-hole/js/settings-system.js @@ -290,6 +290,8 @@ $("#loggingButton").confirm({ $.ajax({ url: "/api/config/dns/queryLogging", type: "PATCH", + dataType: "json", + processData: false, data: JSON.stringify(data), }) .done(function (data) { diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 6922cdbb5..17d28f406 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -137,6 +137,8 @@ function saveSettings() { $.ajax({ url: "/api/config", method: "PATCH", + dataType: "json", + processData: false, data: JSON.stringify({ config: settings }), contentType: "application/json; charset=utf-8", }) diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index cbeb63041..b0795ff1b 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -315,6 +315,7 @@ function addFromQueryLog(domain, list) { url: "/api/domains/" + list + "/exact", method: "post", dataType: "json", + processData: false, data: JSON.stringify({ domain: domain, comment: "Added from Query Log",