Added way to create images
This commit is contained in:
@@ -43,7 +43,7 @@ if (array_key_exists("containers", $_GET)) { // Will list all avaliable containe
|
||||
} else {
|
||||
missingPrivilege($USERNAME);
|
||||
}
|
||||
} else if (array_key_exists("createContainer", $_POST) and array_key_exists("link", $_POST) and array_key_exists("port", $_POST)) {
|
||||
} else if (array_key_exists("createContainer", $_POST) and array_key_exists("link", $_POST) and array_key_exists("port", $_POST)) { // Will create a container
|
||||
if ($PRIVILEGE["dockerAdmin"]) {
|
||||
$id = $USERNAME;
|
||||
$id .= rand();
|
||||
@@ -54,6 +54,35 @@ if (array_key_exists("containers", $_GET)) { // Will list all avaliable containe
|
||||
writeLog(28, "$USERNAME created container with id $id and with ip $address");
|
||||
echo "Created container with id $id";
|
||||
|
||||
} else {
|
||||
missingPrivilege($USERNAME);
|
||||
}
|
||||
} else if (array_key_exists("deleteImage", $_POST)) { // Used to delete a container
|
||||
$name = $OGPOST["deleteImage"];
|
||||
$name2 = $_POST["deleteImage"];
|
||||
if ($PRIVILEGE["dockerAdmin"]) {
|
||||
if (dbRequest2("SELECT * FROM dockerImages WHERE realName=?", "*", [$name])) {
|
||||
dbCommand("DELETE FROM dockerImages WHERE realName=?", [$name]);
|
||||
writeLog(28, "$USERNAME deleted image with name $name2 and with ip $address");
|
||||
echo "Deleted image";
|
||||
} else {
|
||||
http_response_code(404);
|
||||
echo "Could not find image";
|
||||
}
|
||||
} else {
|
||||
missingPrivilege($USERNAME);
|
||||
}
|
||||
} else if (array_key_exists("createImage", $_POST) and array_key_exists("name", $_POST)) { // Will create a container
|
||||
if ($PRIVILEGE["dockerAdmin"]) {
|
||||
$name = $_POST["name"];
|
||||
$realName2 = $_POST["createImage"];
|
||||
$realName = htmlspecialchars($OGPOST["createImage"]);
|
||||
dbCommand("DELETE FROM dockerImages WHERE realName=?", [$realName]);
|
||||
echo $realName;
|
||||
dbCommand("INSERT INTO dockerImages VALUES (?, '$name')", [$realName]);
|
||||
writeLog(28, "$USERNAME created image with name $realName2 and with ip $address");
|
||||
echo "Created image with name $realName2";
|
||||
|
||||
} else {
|
||||
missingPrivilege($USERNAME);
|
||||
}
|
||||
|
||||
49
html/docker/admin.js
Normal file → Executable file
49
html/docker/admin.js
Normal file → Executable file
@@ -34,6 +34,40 @@ function updateContainer() { // Used to update the table
|
||||
ajax.send();
|
||||
}
|
||||
|
||||
function deleteImage(name) { // Used to delete an image
|
||||
const ajax = new XMLHttpRequest();
|
||||
|
||||
ajax.onload = function() {
|
||||
if (ajax.status != 200) {
|
||||
JQerror(this.responseText);
|
||||
}
|
||||
updateImage();
|
||||
}
|
||||
ajax.open("POST", `/api/docker.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`deleteImage=${name}&key='${getCookie('user')}'`);
|
||||
}
|
||||
|
||||
function updateImage() { // Used to update the table
|
||||
const ajax = new XMLHttpRequest();
|
||||
|
||||
ajax.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
let text = "<tr><th>Docker Image</th><th>Name</th></tr>";
|
||||
Object.values(JSON.parse(this.responseText)).forEach(element => {
|
||||
text += `<tr><td>${element["realName"]}</td><td>${element["shortName"]}</td>`;
|
||||
text += `<td><button onclick='deleteImage("${element["realName"]}")'>Delete</button></td>`;
|
||||
text += "</tr>"
|
||||
});
|
||||
$("#image").html(text);
|
||||
} else {
|
||||
JQerror(this.responseText);
|
||||
}
|
||||
}
|
||||
ajax.open("GET", `/api/docker.php?images=get&key='${getCookie('user')}'`);
|
||||
ajax.send();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
updateContainer();
|
||||
$("#createContainer").click(function() { // Used to create a container.
|
||||
@@ -48,5 +82,18 @@ $(document).ready(function() {
|
||||
ajax.open("POST", `/api/docker.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`createContainer=true&link=${encodeURI($("#link").val())}&port=${encodeURI($("#port").val())}&key='${getCookie('user')}'`);
|
||||
})
|
||||
});
|
||||
$("#createImage").click(function() { // Used to create an image
|
||||
const ajax = new XMLHttpRequest();
|
||||
|
||||
ajax.onload = function() {
|
||||
if (ajax.status != 200) {
|
||||
JQerror(this.responseText);
|
||||
}
|
||||
updateImage();
|
||||
}
|
||||
ajax.open("POST", `/api/docker.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`createImage=${encodeURI($("#imageName").val())}&name=${encodeURI($("#name").val())}&key='${getCookie('user')}'`);
|
||||
});
|
||||
});
|
||||
14
html/docker/admin.php
Normal file → Executable file
14
html/docker/admin.php
Normal file → Executable file
@@ -45,6 +45,20 @@
|
||||
<label for="port">The port to be used: </label><input type='number' id='port'>
|
||||
<br>
|
||||
<button id='createContainer'>Create</button>
|
||||
<h1>Images</h1>
|
||||
<table>
|
||||
<tbody id='image'>
|
||||
<tr>
|
||||
<th>Docker Image</th><th>Name</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<label for="imageName">Image: </label><input id='imageName'>
|
||||
<br>
|
||||
<label for="name">Easy name: </label><input id='name'>
|
||||
<br>
|
||||
<button id='createImage'>Create</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -181,7 +181,7 @@ def repair(): # Repairs all tables
|
||||
"golfGameCards" : [["gameID", 1], ["user", 0], ["card", 1], ["cardPlacement", 1], ["faceUp", 6]],
|
||||
"golfGame" : [["ID", 5], ["deck", 4], ["discard", 4], ["cardNumber", 1], ["flipNumber", 1], ["multiplierForFlip", 1], ["pointsToEnd", 1], ["name", 0], ["password", 0], ["players", 1], ["playersToStart", 1], ["currentPlayer", 1], ["turnStartTime", 1], ["locked", 6]],
|
||||
"docker" : [["link", 0], ["action", 0], ["image", 0], ["password", 0], ["owner", 0], ["port", 1], ["ID", 0]],
|
||||
"dockerImages" : [["realName", 0], ["shortName", 0], ["description", 0]]
|
||||
"dockerImages" : [["realName", 0], ["shortName", 0]]
|
||||
}
|
||||
changedTables = []
|
||||
for x in databaseDict:
|
||||
@@ -249,7 +249,7 @@ def repair(): # Repairs all tables
|
||||
updatedVersions.append("v1.1")
|
||||
if versionNumber == "v1.1":
|
||||
createTable("docker", [["link", 0], ["action", 0], ["image", 0], ["password", 0], ["owner", 0], ["port", 1], ["ID", 0]])
|
||||
createTable("dockerImage", [["realName", 0], ["shortName", 0], ["description", 0]])
|
||||
createTable("dockerImage", [["realName", 0], ["shortName", 0]])
|
||||
version = "v2.0"
|
||||
updatedVersions.append("v2.0")
|
||||
# Fixes the version if it is invalid to the latest version
|
||||
|
||||
Reference in New Issue
Block a user