initial commit

This commit is contained in:
Tobias 2023-09-26 14:57:16 +02:00
commit b933ad4fc9
4 changed files with 53 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.geany

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Service restarter for YunoHost
## Overview
restarter is a simple web page for restarting specific, previously hardcoded services. It is a pure convenience project and uses no safety measures whatsoever. Don't use it. No, really, you shouldn't use it.

28
src/index.html Normal file
View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Restarter</title>
<script type="text/javascript">
function restart(command) {
let query = new URLSearchParams({ "q" : command });
console.log(query);
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("result").innerHTML = this.responseText;
}
};
xhttp.open("GET", "./restarter.php?" + query.toString(), true);
xhttp.send();
}
</script>
</head>
<body>
<button type=button onClick="restart('ls -al')">MiniDLNA</button>
<!-- PHP built-in web server: php -S [IP]:[port] -t [path]</pre></p> -->
<div id="result">
</div>
</body>
</html>

19
src/restarter.php Normal file
View File

@ -0,0 +1,19 @@
<?php
// make sure script is called through a web server, not the command line
if (PHP_SAPI === 'cli') {
echo "nope\n";
die(1);
}
// retrieve query value for key "q"
$command = $_GET['q'];
echo "Command is <code>", $command, "</code><br>";//DEBUG
// make sure command exists and is not empty
if ($command === "" || empty($command)) {
echo "empty query";
die(2);
}
// execute shell command
exec($command, $output, $exitcode);
echo "Output is <pre>", join("<br>", $output), "</pre><br>";
echo "Exit code is ", $exitcode;
?>