I'm building a NAS control application with PHP, that can be only accessed from the local network.
I'll start it off with that PHP-FPM does not allow to launch it's pools with user root
, and I have not found a way to force it.
Yes, yes, running PHP as root is not secure (and building an OS configuration app also), but I have no other idea how could I edit Arch Linux's /etc/rc.conf
directly from PHP with file_put_contents()
and after execute rc.d restart network
.
I have set open_basedir = /
in php.ini
.
I have read this and, therefore, I set up a sudoer, launch PHP-FPM pool with the respective user and group.
My sudoer is a system user, added with:
useradd -r -s /bin/bash -g wheel -d /srv/http/ systemphp
In sudoer configuration I have added the entry:
systemphp stone=NOPASSWD: ALL
stone
is the actual hostname of the system.
The problem with this is that I'd have to sudo <everything>
, but I do not want to base everything on shell_exec()
/ exec()
.
Since, any option here is an option, I still tried:
var_dump(shell_exec('sudo fdisk -l'));
That returned null
. Where in PuTTY, su systemphp
, sudo fdisk -l
returned the actual list.
Without shell_exec()
, the following code results in fopen(/etc/rc.conf): failed to open stream: Permission denied
:
$handle = fopen('/etc/rc.conf', 'r+');
if ( $handle )
{
while( ($buffer = fgets($handle)) !== false)
{
echo $buffer;
}
if ( !feof($handle) )
{
echo 'Error: fgets() unexpectedly failed' . PHP_EOF;
}
fclose($handle);
}
How would I set such an environment up or at least reflect it?