Compare commits

..

No commits in common. "3d7f414c1e9d0f1e64f4ba1c3c6d674e7fcd6edf" and "96d5f566fd6a50838d384843e04baf6690b81bd1" have entirely different histories.

6 changed files with 23 additions and 42 deletions

View File

@ -2,4 +2,4 @@
## Overview ## Overview
restarter is a simple web page for restarting specific services. It is a pure convenience project and uses no safety measures whatsoever. Don't use it. No, really, you shouldn't use it. 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.

View File

@ -1,10 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-US"> <html>
<head> <head>
<title>Restarter</title> <title>Restarter</title>
<script type="text/javascript"> <script type="text/javascript">
function restart(service) { function restart(command) {
let query = new URLSearchParams({ "s" : service }); let query = new URLSearchParams({ "q" : command });
console.log(query);
let xhttp = new XMLHttpRequest(); let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
@ -19,7 +20,8 @@ function restart(service) {
</script> </script>
</head> </head>
<body> <body>
<button type=button onClick="restart(`minidlna`)">MiniDLNA</button> <button type=button onClick="restart('sudo systemctl restart minidlna.service')">MiniDLNA</button>
<!-- <button type=button onClick="restart('ls -al')">MiniDLNA</button> -->
<div id="result"> <div id="result">
</div> </div>
</body> </body>

View File

@ -1,34 +1,23 @@
<?php <?php
// define restartable services
$restartables = array("minidlna");
// make sure script is called through a web server, not the command line // make sure script is called through a web server, not the command line
if (PHP_SAPI === 'cli') { if (PHP_SAPI === 'cli') {
echo "This script needs to be run through a web server; aborting."; echo "nope\n";
die(1); die(1);
} }
// retrieve query value for key "s" (as in service) // retrieve query value for key "q"
$service = $_GET['s']; $command = $_GET['q'];
echo "Command is <code>", $command, "</code><br>";//DEBUG
// make sure command exists and is not empty // make sure command exists and is not empty
if ($service === "" || empty($service)) { if ($command === "" || empty($command)) {
echo "No service to restart; aborting."; echo "empty query";
die(2); die(2);
} }
// make sure service from query is available for restart // execute shell command
if ( ! in_array($service, $restartables) ) {
echo "Can't restart service ", $service, "; aborting";
die(3);
}
// put together command
$command = "/usr/bin/sudo /usr/bin/systemctl restart " . $service . ".service";
echo "Command is <code>", $command, "</code><br>";//DEBUG
// execute command
echo "Restarting service ", $service, "";
exec($command, $output, $exitcode); exec($command, $output, $exitcode);
// echo "Output is <pre>", join("<br>", $output), "</pre><br>";//DEBUG echo "Output is <pre>", join("<br>", $output), "</pre><br>";//DEBUG
if ( $exitcode == "0" ) { if ( $exitcode == "0" ) {
echo "OK"; echo "Success";
} else { } else {
echo "failed with exit code ", $exitcode; echo "Command failed with exit code", $exitcode;
} }
?> ?>

View File

@ -1,7 +0,0 @@
restarter is a simple web page for restarting specific services. It is a pure convenience project and uses no safety measures whatsoever. Don't use it. No, really, you shouldn't use it.
This package is not a YunoHost-wrapper for an existing app; it *is* the app. Therefore it only works on a YunoHost server. If you don't have YunoHost, please consult the guide to learn how to install it.
## YunoHost specific features
* defaut visibility is public

View File

@ -2,9 +2,9 @@ packaging_format = 2
id = "restarter" id = "restarter"
name = "Restarter for yunohost" name = "Restarter for yunohost"
description.en = "A simple service restarter for Yunohost. Currently supporting these apps: MiniDLNA" description.en = "A simple service restarter for Yunohost, supporting these apps: MiniDLNA"
version = "1.0~ynh2" version = "0.2~ynh1"
maintainers = ["eclipse"] maintainers = ["eclipse"]
@ -43,3 +43,6 @@ ram.runtime = "1M"
[resources.permissions] [resources.permissions]
main.url = "/" main.url = "/"
# [resources.apt]
# packages = "php8.2-fpm"

View File

@ -3,13 +3,6 @@
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#TODO: define restartable services in one place and use those values to checking which restartable services are installed
# then add corresponding lines dynamically to files:
# - index.html: one button per service
# - restarter.php: add services as array
# - sudoer: add command for each service
#================================================= #=================================================
# CHECK IF RESTARTABLE SERVICES EXIST # CHECK IF RESTARTABLE SERVICES EXIST
#================================================= #=================================================
@ -53,6 +46,7 @@ phpversion="${php_executable:(-3)}"
ynh_app_setting_set --app=$app --key="phpversion" --value="$phpversion" ynh_app_setting_set --app=$app --key="phpversion" --value="$phpversion"
ynh_add_fpm_config --phpversion="$phpversion" ynh_add_fpm_config --phpversion="$phpversion"
ynh_script_progression --message="Adding nginx configuration …" --weight=1 ynh_script_progression --message="Adding nginx configuration …" --weight=1
# get local subnet address ranges from routing table # get local subnet address ranges from routing table
ranges=$(netstat -nr | grep -o "^\(192\.168\|172.\(1[6-9]\|2[0-9]\|3[01]\)\|10\.[0-9]\+\)\.[0-9]\+\.[0-9]\+") ranges=$(netstat -nr | grep -o "^\(192\.168\|172.\(1[6-9]\|2[0-9]\|3[01]\)\|10\.[0-9]\+\)\.[0-9]\+\.[0-9]\+")