X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/e47cb29f1f12b3196bd9f7c24b58b0e3a9b440b6..4074d0d1de874693d331ce32700f1277de0b36aa:/settings/add-plugin.php diff --git a/settings/add-plugin.php b/settings/add-plugin.php index 21ecf90..adc0016 100644 --- a/settings/add-plugin.php +++ b/settings/add-plugin.php @@ -4,6 +4,9 @@ require_once "../inc/common.php"; require_once "../inc/header.php"; require_once "../Classes/class-plugin-git.php"; +if (!current_user_can(PERMISSION_MANAGE_PLUGINS)) + die("Access denied"); + $p = new PluginRepo(); ?> @@ -26,8 +29,127 @@ $p = new PluginRepo(); ?> - \ No newline at end of file + + const ibtns = document.querySelectorAll(".btn-install-plugin"); + ibtns.forEach((ib) => { + ib.addEventListener('click', (e) => { + if (ib.innerHTML !== "Install" && ib.innerHTML !== "Uninstall") // some point between, don't do anything + {} + else if (ib.innerHTML == "Install") // install button pressed! + { + let req = requestInstall(ib.id.slice(0,-7)) + if (req == true) + { + ib.classList.replace("btn-primary", "btn-secondary"); + ib.innerHTML = "Installing..."; + } + else + { + let uhoh = new bsModal("Error", "Could not install: "+req, "", null, false, true); + } + } + else if (ib.innerHTML == "Uninstall") + { + let req = requestInstall(ib.id.slice(0,-7), true); // true = uninstall + if (req == true) + { + ib.classList.replace("btn-outline-danger", "btn-secondary"); + ib.innerHTML = "Uninstalling..."; + } + else + { + let uhoh = new bsModal("Error", "Could not uninstall: "+req, "", null, false, true); + } + } + }); + }) + const installed = document.querySelectorAll(".installed"); + installed.forEach((el) => { + let btn = document.getElementById(el.id + 'install'); + btn.classList.replace("btn-primary", "btn-outline-danger"); + btn.innerHTML = "Uninstall"; + }); + + function requestInstall(name, uninstall = false) + { + let inst = (uninstall) ? "uninstall" : "install"; + var xhr = new XMLHttpRequest(); + + xhr.onload = function() { + if (xhr.status === 200) { + var response = JSON.parse(xhr.responseText); + console.log(response.success); + let install_button = document.getElementById(name+'install'); + if (response.success !== undefined) + { + if (install_button) + { + install_button.innerHTML = (inst == "uninstall") ? "Install" : "Uninstall"; + install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-primary' : 'btn-outline-danger'); + let icomplete = bsModal(((inst == "uninstall") ? "Uninstall" : "Install") + " Plugin", response.success,"