I have a media server (with only LAN access) that I want to be able to control via some scripts accessed by a web interface. So I want to run the scripts like I would via an SSH terminal.
using the command shell_exec() is really what I want, for example:
<?php
$output = shell_exec('/home/user/scripts/scriptname.sh 2>&1');
echo $output;
?>
The issue with this is that it runs them as the www user, not the user that they were designed to be run as (don't want to have to run as root).
An example of a .sh file:
#!/bin/bash
xdotool key --window "$(xdotool search --name kodi)" q
sleep 5
pkill -9 -x kodi.bin
This script will kill Kodi if it locks up or anything, it has to be run by the user that ran it (in this case, the user is the one that logs in automatically to Ubuntu), and I want to have a button on a page that can do this from any web browser on any device on the LAN.
I do not want to do these things via permission changes, groups etc, I want to be able to log in as a different user as part of the shell_exec command using the username and password I do for ssh.
libssh2 authenticates with the required username and password, so I will install it if need be, but would be nice to just be able to use functions included with the default install of PHP
access your linux shell with php isn't recommended , I think isn't secure. If you want to access your linux shell with ssh , you use firefox with firessh plugin . Firessh