Start/Restart/Stop Daemons thru PHP problem

Ask questions about Arch Linux ARM. Please search before making a new topic.

Start/Restart/Stop Daemons thru PHP problem

Postby chris5h » Tue May 22, 2012 3:57 am

So I am trying to make a little back end PHP admin to start, restart, and stop some of my daemons. I already made a little PHP interface to to wget files without needing to SSH in. It is just done with an HTML file with a webform, with a POST action to a PHP file.
$this->bbcode_second_pass_code('', '
<?php
{
$file = $_POST['file'];
}
system("wget '$file'")
?>
')

Now, this works great, so I thought to myself, if it works for wget why not rc.d start commands.

So, first, I tried:
$this->bbcode_second_pass_code('', '
<?php
system("rc.d start samba")
?>
')

Which give me the error:
$this->bbcode_second_pass_quote('', '
')A daemon is starting another daemon, this is unlikely to work as intended. :: Starting Samba Server [BUSY] [FAIL]


So I figured, OK, lets try a different approach. I made a .sh file, and changed the PHP file to run that.

samba.sh:
$this->bbcode_second_pass_code('', '
/etc/rc.d/samba start
')

PHP File:
$this->bbcode_second_pass_code('', '
<?php
system("sh samba.sh")
?>
')

And I get the exact same error. Does anyone know of a way to get this to work, or what I am doing wrong?

Thanks in advance everyone.
chris5h
 
Posts: 44
Joined: Mon May 14, 2012 1:18 pm

Re: Start/Restart/Stop Daemons thru PHP problem

Postby pepedog » Tue May 22, 2012 7:39 am

What user is executing the script? If a web server, it will be apache. Webmin can do it for other systems, but it runs as root I believe.
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: Start/Restart/Stop Daemons thru PHP problem

Postby chris5h » Tue May 22, 2012 5:19 pm

I dont have a user "apache". I do have an HTTP user and as a test I added it to the root group but it still is giving me the same error message
chris5h
 
Posts: 44
Joined: Mon May 14, 2012 1:18 pm

Re: Start/Restart/Stop Daemons thru PHP problem

Postby tomcheng76 » Thu May 24, 2012 2:00 am

does SUID works?
make the owner of the script file to root....
although doing such thing is highly not recommended.......
perhaps you can do some authentication in php side, but you cannot control users in the server os, they have controls to run the scripts anyway.
tomcheng76
 
Posts: 130
Joined: Mon Dec 13, 2010 11:24 am

Re: Start/Restart/Stop Daemons thru PHP problem

Postby chris5h » Fri May 25, 2012 6:35 pm

I changed the ownership of samba.sh to root and chmod'd ti SUID. Here's the ls -l results:
$this->bbcode_second_pass_code('', '
-r-sr-xr-x 1 http root 22 May 21 20:35 samba.sh
')

But I get the same exact error.
chris5h
 
Posts: 44
Joined: Mon May 14, 2012 1:18 pm

Re: Start/Restart/Stop Daemons thru PHP problem

Postby pepedog » Fri May 25, 2012 7:48 pm

/etc/php/php.ini (restart httpd after changes)
safe_mode = Off

; By default, Safe Mode does a UID compare check when
; opening files. If you want to relax this to a GID compare,
; then turn on safe_mode_gid.
safe_mode_gid = Off

; When safe_mode is on, UID/GID checks are bypassed when
; including files from this directory and its subdirectories.
; (directory must also be in include_path or full path must
; be used when including)
safe_mode_include_dir =

; When safe_mode is on, only executables located in the safe_mode_exec_dir
; will be allowed to be executed via the exec family of functions.
safe_mode_exec_dir =
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: Start/Restart/Stop Daemons thru PHP problem

Postby chris5h » Fri May 25, 2012 9:38 pm

$this->bbcode_second_pass_quote('pepedog', '/')etc/php/php.ini (restart httpd after changes)
safe_mode = Off

; By default, Safe Mode does a UID compare check when
; opening files. If you want to relax this to a GID compare,
; then turn on safe_mode_gid.
safe_mode_gid = Off

; When safe_mode is on, UID/GID checks are bypassed when
; including files from this directory and its subdirectories.
; (directory must also be in include_path or full path must
; be used when including)
safe_mode_include_dir =

; When safe_mode is on, only executables located in the safe_mode_exec_dir
; will be allowed to be executed via the exec family of functions.
safe_mode_exec_dir =


I dont have any of the above in my php.ini file. I pasted it in and resart he httpd daemon, and ever rebooted my machine, and still get the same error.


Just want to say thanks BTW to everyone trying to help me out. I really appreciate it and am loving the comradeship on this forum.
chris5h
 
Posts: 44
Joined: Mon May 14, 2012 1:18 pm

Re: Start/Restart/Stop Daemons thru PHP problem

Postby chris5h » Mon Jun 04, 2012 2:36 am

If anyone is interested I figured out a solution to this.

I installed SUDO and added http as a user that could sudo without a password. The a change the PHP script to actually SUDO the command , so it is: sudo rc.d start samba

And it works great. Woot!
chris5h
 
Posts: 44
Joined: Mon May 14, 2012 1:18 pm


Return to User Questions

Who is online

Users browsing this forum: No registered users and 4 guests