LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 10-30-2007, 05:42 AM   #1
jcaga
LQ Newbie
 
Registered: Apr 2005
Location: philippines
Posts: 8

Rep: Reputation: 0
Unable to execute "reboot" in cgi script


Hi,

I am trying to execute "reboot" command inside a cgi script but nothing happens. I am using 2.6.18-1.2798.fc6. My script /var/www/cgi-bin/reboot.cgi contains:
---------------
reboot
---------------

Executing the script from a remote client:
http://192.168.15.43/cgi-bin/reboot.cgi

/var/log/httpd/error_log gives me the error:

[Tue Oct 30 18:36:58 2007] [error] [client 192.168.15.91] reboot: must be superuser.
[Tue Oct 30 18:36:58 2007] [error] [client 192.168.15.91] Premature end of script headers: reboot.cgi

How do I fix this?

Thanks
 
Old 10-30-2007, 09:37 AM   #2
shafty023
Member
 
Registered: Oct 2007
Distribution: OSX
Posts: 248

Rep: Reputation: 31
That would be because your apache user which is running apache does not have access privs to execute a system reboot. That would be a huge gaping security hole if any standard user could execute a system reboot remotely like that. Especially through apache.

If you want to add that support you'll need to add this to the sudoers file, assuming your apache user is "apache" ---> apache ALL=NOPASSWD: /sbin/reboot .

How do you add this to the sudoers file you ask?

1) su - root
2) visudo
3) add this line in there -> apache ALL=NOPASSWD: /sbin/reboot
4) save the changes
5) now change your script to say "sudo reboot"
 
Old 10-30-2007, 09:02 PM   #3
jcaga
LQ Newbie
 
Registered: Apr 2005
Location: philippines
Posts: 8

Original Poster
Rep: Reputation: 0
This line is already there:

apache ALL=(ALL) NOPASSWD:ALL

do I have to modify it to:

apache ALL=NOPASSWD: /sbin/reboot
 
Old 10-30-2007, 09:50 PM   #4
jcaga
LQ Newbie
 
Registered: Apr 2005
Location: philippines
Posts: 8

Original Poster
Rep: Reputation: 0
gotcha!

1.) changed apache ALL=(ALL) NOPASSWD:ALL to apache ALL=(root) NOPASSWD:ALL
2.) added sudo before the reboot command in cgi scripts
3.) commented out "Defaults requiretty" in /etc/sudoers, else you will see, "sorry, you must have a tty to run sudo"
 
Old 05-10-2012, 08:45 AM   #5
amit_1
LQ Newbie
 
Registered: Mar 2012
Posts: 25

Rep: Reputation: Disabled
Followed the steps given by jcaga. But still not able to implement it.

When i try to open localhost/cgi-bin/reboot.cgi following error comes:-
Error 500 Internal Server Error

/var/log/httpd/error_log gives me the error:

Exec Format Error : Exec of ..cgi-bin/reboot.cgi failed

reboot.cgi has 700 permission

Any help please??

---------- Post added 05-10-12 at 07:46 AM ----------

I forgot to mention i am using RHEL 5.6
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
execute a script every 5 minutes "cron" ALInux Linux - General 1 02-10-2006 02:36 AM
running a script: ". scriptname" vs "./scriptname" to execute beeblequix Linux - Enterprise 3 11-07-2005 04:40 PM
cgi-bin: "attempt to invoke directory as script" hamish Linux - Software 0 12-09-2004 12:45 PM
remove the "Run or Display?" when I execute a script llee Programming 5 05-05-2003 11:21 AM
remove the "Run or Display?" when I execute a script llee Linux - Software 0 05-02-2003 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration