diff --git a/html-Common/SQL/index.html b/html-Common/SQL/index.html index 84c5a2eb..13fd3ba0 100644 --- a/html-Common/SQL/index.html +++ b/html-Common/SQL/index.html @@ -45,4 +45,4 @@

SQL database

- + diff --git a/html-Common/SQL/sql.js b/html-Common/SQL/sql.js index bc169308..4b7df8b9 100644 --- a/html-Common/SQL/sql.js +++ b/html-Common/SQL/sql.js @@ -1,3 +1,5 @@ +import { GetPSQLTable } from "/includes/functions.js"; + var output = document.getElementById("output"); var tableselect = document.getElementById("tableselect"); var select = document.querySelector('select'); @@ -9,39 +11,9 @@ var limit= document.getElementById("limit"); //update dropdown at startup updatedropdown(); - -function gettable(command){ //generic get sql table command - - return new Promise(function(resolve, reject){ - var xhr = new XMLHttpRequest(); - - var url = "/cgi-bin/sqlquery.cgi"; - - var user ="root"; - var db="daq"; - - // Set the request method to POST - xhr.open("POST", url); - - // Set the request header to indicate that the request body contains form data - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - - - var dataString = "user=" + user + "&db=" + db + "&command=" + command; - - - // Send the request - xhr.send(dataString); - - xhr.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - - resolve(xhr.responseText); - } -// else reject(new Error('error loading')); - } - }); - + +function gettable(command) { + return GetPSQLTable(command, 'root', 'daq', true); } diff --git a/html-Common/includes/functions.js b/html-Common/includes/functions.js index 196e2f1a..989be37e 100644 --- a/html-Common/includes/functions.js +++ b/html-Common/includes/functions.js @@ -367,7 +367,9 @@ export function SendSCCommand(ip, port, command_output, ...incommands){ export function GetPSQLTable(command, user, database, async=false){ - var data_string = "user=" + user + "&db=" + database + "&command=" + command; + var data_string = "user=" + user + + "&db=" + database + + "&command=" + encodeURIComponent(command); return HTTPRequest("POST", "/cgi-bin/sqlquery.cgi", async, data_string); diff --git a/html-StandAlone/sql.js b/html-StandAlone/sql.js index 05558532..c3cd349e 100644 --- a/html-StandAlone/sql.js +++ b/html-StandAlone/sql.js @@ -26,9 +26,9 @@ function gettable(command){ //generic get sql table command // Set the request header to indicate that the request body contains form data xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - - var dataString = "user=" + user + "&db=" + db + "&command=" + command; - + var dataString = "user=" + user + + "&db=" + db + + "&command=" + encodeURIComponent(command); // Send the request xhr.send(dataString);