shell_exec launch firefox from remote client - php

Trying to launch a Firefox window in Centos/RHEL5 with Gnome via a PHP. I want the ability to take screenshots of the requested page.
Gave my WWW user sudo rights and confirmed this is working on the server, firefox window opens successfully if the php script is run on the server (as WWW user, hence the whoami echo to confirm user I am running as), however if the PHP page is called from a remote user the firefox window does not open, however the whoami returns the WWW username.
<?php
$page= 'index.html';
$launch= "sudo /usr/bin/firefox \"http://another.server.com/".$page."\"";
echo shell_exec('whoami');
echo shell_exec($launch);
?>
The WWW user login shell is /bin/bash and no pass required. Running on a private network, not concerned about the sudo access to the WWW user

Related

Reload apache with php automatically

I have an application running where customers can connect their own domain. That is, my customers can log in, enter their domain and a new virtual host is created in the background.
shell_exec('cp /var/www/xxxxxxx/storage/app/vhosts/'.$relativeDomain.'.conf /etc/apache2/sites-available');
shell_exec('rm /var/www/xxxxxxx/storage/app/vhosts/'.$relativeDomain.'.conf');
shell_exec('chmod 777 /etc/apache2/sites-available/'.$relativeDomain.'.conf');
shell_exec('a2ensite '.$relativeDomain);
The only problem is, as long as Apache is not reloaded, the Virtual Host cannot be applied. Is there any way to execute the command "systemctl reload apache2" via shell script or with the PHP function shell_exec or exec? When i do shell_exec('systemctl reload apache2') nothing happens.

Trying to open a Chromium Browser via a shell_exec command from a user accessing the device?

My device does not have a touchscreen, so the user accesses features via their phone over WiFi and the device sits as a local webserver. I'm trying to get it so if a user submits to a form it will run a command to open up a Chromium browser on the device.
Right now It shows output on the user's phone, but nothing happens on the device. I understand the security concerns, but only the single user has access to the device this way and must be in close proximity.
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
//if user clicked "video on"
if(isset($_POST["video_on"])){
echo shell_exec('./video_on.sh');
}
}
Now here is video_on.sh:
#!/bin/bash
DISPLAY=:0 chromium-browser --incognito --start-maximized --kiosk
http://localhost/videoloop
Thanks!
www-data does not have access to your xserver (display) running, so chromium will start without screen output, in background. You have to run your webserver as a user that is currently logged into the startx server, easiest way to do this is to call a php embedded server in terminal from the X server to ensure that you have all necesarry permissions.

running bat file from php to add user to windows

PHP file
<?php
echo exec("rules.bat");
?>
BAT file
net user username Welcome12! /ADD /FULLNAME:Test /PASSWORDCHG:NO
When I try to run the php script I get the following
C:\inetpub\wwwroot\e\sso\home>net user username Welcome12! /ADD /FULLNAME:Test /PASSWORDCHG:NO
But no user is added. I can run the BAT file from the same directory and the user is added. I've also tried to run the following in my php script and it doesn't work
<?php
echo exec("net user username Welcome12! /ADD /FULLNAME:Test /PASSWORDCHG:NO");
?>
I've also tried using system, shell_exec, passthru
When I run
echo exec("whoami");
it shows my user that has admin rights
What windows version?
Does it have Admin Rights? as to add a user to windows you will have to run in Admin mode / Root Rights.
Even running net user username Welcome12! /ADD /FULLNAME:Test /PASSWORDCHG:NO
in Command, returns: Access is denied.
Web server has 1User with rights, When logged into the Device i.e. RDP you possibly have Admin rights.
Stating the obvious here, But this is what it sounds to me
echo exec(" start cmd /c net user $directoryname $password /ADD /FULLNAME:$username /PASSWORDCHG:NO");
this resolved it

Accessing X Display through Apache

I am trying to send keypresses to a Raspberry Pi running Raspdbian from from a web page hosted on an Apache server at /var/www.
I'm using xdotool, which can send keypresses using commands like this:
xdotool key C
I made a python script xdotool.py that sends a few keypresses like that:
#!/usr/bin/env python
import os
print 'sending HI'
os.system("export DISPLAY=:0")
os.system("xdotool key H")
os.system("xdotool key I")
I am SSH'd into the Raspberry as user Pi, and running this script from terminal works fine and sends the keystrokes "HI" to the Raspberry.
However, I want to be able to do this through a web page. I've made a php-script that runs python scripts and displays the terminal output in the browser, but it does not work with the xdotool.py script. I have given the script permission to be viewed/changed/executed by all users.
I've also changed the Apache settings in /etc/apache2/envvars and changed the user from www-data to pi. The user pi should have all necessary permissions.
The script does run, and "sending HI" is displayed in the browser. But it doesn't send the keystrokes. The error I get from error.log is this:
Error: Can't open display: (null)
Failed creating new xdo instance
Any ideas how I can accomplish this? If there's a way to give everyone permission to do everything, that wouldn't be a problem seeing that this server will only run on a local network with no internet access.

Access bitbucket git repo via PHP script from browser

I'm trying to set up my POST hook to automatically update the git repo on the server on each push. This works all fine and when I am user apache on the command line and execute the script, it works all fine - the permissions are set, the ssh keys work and it runs the pull.
But when I try and run the same script via the browser, I get a permission denied error - here the output from the php script in the browser:
$ echo $PWD
/var/www/vhosts/dev-build
$ whoami
apache
$ ssh -T git#bitbucket.org 2>&1
Permission denied (publickey).
I am the same user 'apache' as on the command line, and there it is all fine - what am I missing?
Obviously the moment you write it all down it becomes clear, but I'll answer here anyway, just in case someone has the same issue:
I did generate the ssh-keys with a passphrase and then stored this passphrase for the current ssh session. However when I logged out and then in again, I realised it asked me for the passphrase again - I though it would save it automatically when I enter it once.
So the php script run from the browser in it's own session, didn't have the passphrase and threw an error.
I regenerated the ssh-keys with an empty passphrase, and voila - all works as expected.

Categories