Project

General

Profile

[Solved] Executing Reboot command from cgi-Script

Added by te_gonzales over 7 years ago

Hello,

i have a problem with running the reboot-Command from a cgi-Script.

My Target-Platform is an arm cortex Processor with linux 4.1. The lighttpd installation was done with buildroot and i configured
the webserver to use mod_cgi and lighttpd is started as user www-data.

I am calling my cgi-file (c compiled elf binary) from my Webinterface to reboot the system. However system("reboot"); always fails, and also using sync(); reboot(LINUX_REBOOT_CMD_RESTART); will not reboot the device.

My first suspicion was that the user www-data has no right to execute the reboot command, but when i'm using ssh shell and enter

su www-data
and then
reboot

the system reboot works well.

Is there anything that needs to be configured in order to enable cgi-Scripts executing system commands ?

------------------------
lighttpd/1.4.36 (ssl)
buildroot-2015.08.1

cgi.conf:
---------
server.modules += ( "mod_cgi" )

cgi.assign = ( ".cgi" => "" )
alias.url += ( "/cgi_bin" => server_root + "/cgi-bin" )
$HTTP["url"] =~ "^/cgi-bin" {
cgi.assign = ( "" => "" )
}

lighttpd.conf:
--------------
var.log_root = "/var/log"
var.server_root = "/var/myApp/www"
var.state_dir = "/var/run"
var.home_dir = "/var/lib/lighttpd"
var.conf_dir = "/etc/lighttpd"
var.vhosts_dir = server_root + "/vhosts"
var.cache_dir = "/var/cache/lighttpd"
var.socket_dir = home_dir + "/sockets"

include "modules.conf"

server.port = 80
server.username = "www-data"
server.groupname = "www-data"
server.document-root = server_root
server.pid-file = state_dir + "/lighttpd.pid"
server.errorlog = log_root + "/lighttpd-error.log"

include "conf.d/access_log.conf"
include "conf.d/debug.conf"
server.event-handler = "linux-sysepoll"
server.network-backend = "writev"
server.max-fds = 2048
server.stat-cache-engine = "simple"
server.max-connections = 1024

index-file.names += (
"index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)

url.access-deny = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi" )
include "conf.d/mime.conf"
include "conf.d/dirlisting.conf"
server.follow-symlink = "enable"
server.upload-dirs = ( "/var/tmp" )

$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/var/myApp/sysconfig/lighttpd.pem"
}
-----------------------------

Best regards,
Tom


Replies (2)

RE: Executing Reboot command from cgi-Script - Added by gstrauss over 7 years ago

I am calling my cgi-file (c compiled elf binary) from my Webinterface to reboot the system. However system("reboot"); always fails, and also using sync(); reboot(LINUX_REBOOT_CMD_RESTART); will not reboot the device.

Have you asked questions about errors before? Why haven't you included the error message or error code?

If 'reboot' works from command line after su, then reboot might be configured to run when caller is logged into a TTY (including ptty).

If that is not the case, here are other solutions (which you should read before posting further here)
http://unix.stackexchange.com/questions/80687/rebooting-fails-randomly
http://unix.stackexchange.com/questions/43135/allowing-a-user-to-use-sudo-without-a-password
http://unix.stackexchange.com/questions/117148/how-can-i-run-reboot-as-a-normal-user-without-needing-to-enter-a-password
http://askubuntu.com/questions/168879/shutdown-from-terminal-without-entering-password

RE: Executing Reboot command from cgi-Script - Added by te_gonzales over 7 years ago

Thank you for the reply.

Sorry, if i didn't post an error message or an error code, possibly this board was the wrong place to ask help with my specific problem.

Anyway, i got a clue about the actual behaviour of my system: www-data had no permission to reboot the system.
Best regards,
Tom

    (1-2/2)