I was wondering how I could execute a command through PHP into a screen running on my virtual private server.
i.e.
if(submit){
do "say This is a minecraft server." in screen.
}
Thanks in advance,
If you are running the script under screen, then just echo or print the data you want to display.
Otherwise you can:
make a system call to write or wall
write to a file that you are tail -fing in the screen (or some other system by which the screen polls something for new messages)
run a service in the screen that you can connect to over the network
Still unclear on exactly what you mean, but if this is what you're looking for, you can execute linux commands by using the backtick operator, such as
echo `ls`;
to print the contents of the directory where the script is located. So if you wanted to print commands to your server, you could do it that way.
Related
I'm trying to execute an Asterisk client command with PHP, to display with html. I used to do it normally. When the server was rebooted, I used to give 777 permissions to the file "/var/run/asterisk/asterisk.ctl" and then I could run a command and display it with PHP and HTML.
Now, I do all those steps, but when I try to display a command, nothing is shown, and Asterisk does not return any message. The command that I try to execute with PHP is:
exec('sudo asterisk -rx "sip show peers"',$data);
The variable $data returns nothing.
I think first you have check is "what is path for your apache account".
It is really unlikly apache see /usr/sbin/. So you need use full path to asterisk
Second thing you have check - if your sudo(/etc/sudoers) REALLY allow run asterisk for apache(or nobody, depend of your setup) user.
Finally I could solve it. It remained an issue of permissions.
Apparently, you can't use the pre-command "sudo". So I removed it, and the online users console reappeared in PHP.
Thanks for your help!
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
I'm making a Minecraft control panel, but are sort of confused on how to send a command to each screen. I understand how to execute a command to a screen, but I don't understand to read the output.
Ex. I have screen A and screen B. I want to execute something in screen A, and get the output, and then exit the screen.
Here's an easier solution:
Use Websend bukkit plugin (Download&info) in both servers. PHP can simply execute commands and receive outputs when plugin is installed and php classes setted up, also this can be more complex than bash screen, and much easier to setup and use.
Here's an example use of this:
<?php
include_once 'Websend.php';
//Replace with bukkit server IP. To use a different port, change the constructor to new Websend(ip, port)
$ws = new Websend($ServerIP, $ServerPort);
//Replace with password specified in Websend config file
$ws->connect("password");
$ws->doCommandAsConsole("give ".$PlayerName." 64 1");
$ws->disconnect();
?>
In this example the script item to a variable-definied player.
You can execute a custom variable command with replacing $ws->doCommandAsConsole("give ".$PlayerName." 64 1");' to$ws->doCommandAsConsole("$_REQUEST['customCMD']"); where customCMD is a field in a GET or POST form.`
Don't actually need a plugin, but keep in mind using shell_exec could open a massive world of pain for you when it comes to security.
However, I was having a similar issue with implementing a control panel in drupal, I managed to run commands to a screen using the following code.
shell_exec("screen -S ScreenName -X stuff \"echo hello world\"'\n'");
You're welcome.
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
Let's say I have a local webpage, that when a button is pressed, executes a program in C. I already can do that. The problem is that this program outputs logs and needs input from the user. My question is: how can I display bash-like window and run this program through it, so that output and input is seen through the screen?
Perhaps you could use ajaxterm, and specify the program that you want to run as the shell:
ajaxterm.py --command=/your/command --port=yourfavoriteport
You could redirect the user to the specified port, or display the terminal via an iframe.
I develop plugin for jquery "Terminal Emulator" you can check this out. If you write your C program as JSON-RPC you can create your terminal with one line of javascript.
The other solution is to not use PHP at all, and creating your code as CGI written in C or even in Bash.
Update: You can modify your program to be CGI script
int main() {
printf("Content-Type: text/plain\n\n");
// code of your program here
}
and put it in cgi-bin directory and run it through browser http://yourserver.com/cgi-bin/program it display the output in browser