0

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?

asked Apr 7, 2022 at 13:47
9
  • 1
    What exactly is not working so far? Is this a bash problem, a PHP problem, or a HTML problem? Commented Apr 7, 2022 at 13:48
  • edited for clarification Commented 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? Commented 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? Commented Apr 7, 2022 at 13:56
  • 2
    Did you try shell_exec (instead of exec) ? See this link Commented Apr 8, 2022 at 3:21

1 Answer 1

0

This is my index.html page

Should it not be index.php ...

answered Apr 8, 2022 at 2:44
Sign up to request clarification or add additional context in comments.

1 Comment

The correct answer is a combination of a couple of the comments and the answer. I hadn't setup php correctly in nginx, the index file did indeed need to be renamed .php, the correct command is 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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.