Running an application in your localhost using php - php

I have written a php script that will enable me to run a few batch files and python script in cmd prompt. The batch files and the python script are located in the same machine as my php script. The php script have a hyperlink image where if a user click the image it will load the command prompt to run the batch files and the python. In order to do this i need to have a .dll file called launchinIE.dll and also enable the activeX settings in the Internet explorer (you can refer to this link http://www.whirlywiryweb.com/q/%2Flaunchinie.asp)
the problem is that the php script can only run properly in internet explorer but not in firefox....... how to do this????
<script language="JavaScript">
function openPyt(strDoc)
{
var obj = new ActiveXObject("LaunchinIE.Launch");
obj.ShellExecute("open", strDoc);
}
</script>

You're using ActiveX, which firefox does not support. It sounds like you're trying to run a python script via a web browser? The simplest way to do this in a way that will work with all browsers is CGI. This means that the code will run on the web server instead of in the web browser, though, which might not be what you want. What are you trying to do?

Related

Open webbrowser with python script executed by php

I want to open a specific url with a python script which is activated by php. When I run the python script itself with cmd it works fine but when I execute the python script with php on a WAMPserver it does not open the webpage. Anyone know about this issue?
php
<?php
$result = exec("C:/Python27/python openpage.py");
echo $result;
?>
python
import webbrowser
webbrowser.open('http://www.google.com', new=1, autoraise=True)
You know PHP is server side?
This means you can call this php script of course in any browser, but it won't open the page there.
Instead it might open this page on your webserver.
If you run php in command line, it makes more sense, but there's still the question why you want it this way then.
it will not open webpage. if you want open new webpage look for jQuery or JS. you can put JS code with php and it will open webpage in browser.

Webserver to trigger ssh shell script

I have googled this a lot but none of the results I have found worked for me. So far, I have only tried to do this with php, but cgi, javascript or whatever works is fine with me, as long as it gets the job done.
I would like to access a certain URL on my debian webserver. Once opened in the browser, this file shall execute the following shell commands. No buttons or links. If possible, I'd like to just open the URL, then have the script being started.
ssh user#192.168.189.12 <<'ENDSSH'
osascript ~/Desktop/Scripts/script.scpt
When running this as a regular .sh file it works fine. I have created lockkeys so that no password is prompted when connecting from A to B. What can I do to trigger this from, for example, the browser on my smartphone?
I am not trying to connect directly from any device to the Mac containing script.scpt. It is essential that the debian server triggers it and that it is executed by the webserver.
I just started learning about terminal comments, scripts and so on, so I have very basic knowledge of the subject. Please be patient with me.
Thanks in advance for your help :)
for simplicity I prefer to create a bash script. Let's call it
/var/NONwebroot/sshcoolstuff.sh
#!/bin/bash
ssh user#192.168.189.12 <<'ENDSSH'
osascript ~/Desktop/Scripts/script.scpt
make sure it is executable
<?php
exec('/var/NONWwebroot/sshcoolstuff.sh');
?>
Now I'd recommend putting some protection on that PHP script. Either limit who has access to it by IP address, or a password, or both.
here is a test bash script for you
#!/bin/sh
cat > test << EOF
Hello World!
This is my test text file.
You
can also
have
a whole lot
more text and
lines
EOF

How to launch an application from the browser using PHP?

I have installed .exe file using wine in my linux machine. Using shell_exec I could launch the exe file via command prompt using php. When I try to run php program from the browser am getting a blank page. How to launch the executables from the browser using php?
And also, using ip address I should be able to launch in other system browser which is installed in one system.
php code:
<?php
shell_exec("cd / ; wine /home/quads/.wine/drive_c/Program\ Files/MathType/MathType.exe");
?>
If I run this through command prompt it could launch an application but via browser it
doesn't work.It it works via browser then I can access that application from other system using
myipaddress/phpprogram
Please try this
<?php
shell_exec("wine MathType");
?>
It will work only in Internet Explorer and ActiveX control should be enabled in the browser
code:
function openapp(){
var obj=new ActiveXObject("WScript.Shell");
obj.Run("file_exe_path",1,true);
}
<input type="button" onclick="openapp();" />

Server side script for launching application

I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps

Run a .cmd asynchronously using php on windows/wamp

Here is the task:
I have a windows .cmd file that basically navigates to a given directory and runs a given Java program. I can directly run this file and it works just as I expect it to. However, I would like to run it from within a locally hosted php webpage and I would also like for this to be run asynchronously so that my webpage can make use of the data being produced by the java program.
I have tried several things that I was able to find online, including this proposed solution: PHP exec() as Background Process (Windows Wampserver Environment) but nothing seems to work for me.
I was under the impression that a function like this:
<?php
function runAsynchronously($path) {
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($path, 7, false);
unset($WshShell,$oExec);
}
?>
when called with
runAsynchronously('notepad');
(for example), should open notepad and continue to run the php scrip from where it was called. However, nothing seems to happen when I do that. Any suggestions? Beware that I am not experienced with php at all, so I could be unknowingly doing something very stupid :)

Categories