I'm trying to have a button on a webpage, hosted on my raspberry Pi, shutdown a QNAP via a script.
The script works when I run it from the pi command line. I've tested it. I can also see the html page is working, to a point where the key is added to the url when I click the button.
The script does not run when I press the button on the webpage.
The webpage is hosted using NGINX. This is my NGINX.config
http {
server {
listen <myip>:80;
root /var/www/control;
index index.html;
server_name <myWebAddress> www.<myWebAddress>;
location / {
try_files $uri $uri/ =404;
}
}
}
This is my index.html page
<!DOCTYPE html>
<html style="font-size: 16px;">
<head>
<title>Home</title>
</head>
<body>
<header>
<?php
if ($_GET['poweroffqnap']) {
exec("/etc/control/scripts/poweroffqnap.sh");
}
?>
<h1>control</h1>
</header>
<section>
<div>
<a href="?poweroffqnap=true">shutdown QNAP</a>
</div>
</section>
</body>
</html>
all folders and scripts are 755 and owned by root
I run 'ps aux' and see the following:
root 28221 0.0 0.1 49472 1172 ? Ss 13:46 0:00 nginx: master process /usr/sbin/nginx -g daemon on; mas
www-data 28222 0.0 0.3 49628 3372 ? S 13:46 0:00 nginx: worker process
www-data 28223 0.0 0.2 49628 2616 ? S 13:46 0:00 nginx: worker process
www-data 28224 0.0 0.2 49628 2616 ? S 13:46 0:00 nginx: worker process
www-data 28225 0.0 0.2 49628 2616 ? S 13:46 0:00 nginx: worker process
I think this might be related to user permissions for www-data. I'm not sure how to do any further troubleshooting. I know how to add permissions for a user.
Is my code correct and how can I check what user the web-page us running with, to ascertain if the user can't execute the script?
-
1What exactly is not working so far? Is this a bash problem, a PHP problem, or a HTML problem?Nico Haase– Nico Haase2022年04月07日 13:48:32 +00:00Commented Apr 7, 2022 at 13:48
-
edited for clarificationpwzero– pwzero2022年04月07日 13:51:07 +00:00Commented Apr 7, 2022 at 13:51
-
1"The script does not run" - what does that mean? Is the script not run at all? Is the script run, but it cannot shutdown the server? Why not check the output of the script for any message?Nico Haase– Nico Haase2022年04月07日 13:52:09 +00:00Commented Apr 7, 2022 at 13:52
-
1"Nothing happens" sounds strange, especially if you haven't checked why this is the case. Why not check whether the script outputs anything? Whether it asks for elevated permissions when run through PHP?Nico Haase– Nico Haase2022年04月07日 13:56:55 +00:00Commented Apr 7, 2022 at 13:56
-
2Did you try shell_exec (instead of exec) ? See this linkKen Lee– Ken Lee2022年04月08日 03:21:45 +00:00Commented Apr 8, 2022 at 3:21
1 Answer 1
This is my index.html page
Should it not be index.php ...
1 Comment
shell_exec and the ownership of the script files needed to be amended as well as setting permissions using sudo visudo as I outlined myself earlier.Explore related questions
See similar questions with these tags.