Game Control Panel
Im about to build a custom panel for my site, it will need to talk to a CentOS (linux) Server and do commands like stop, start. Simple Question is..
..How to i make a PHP site talk to a CentOS server and start/stop processes.
Also there will be many users so the use of a su and /home directory would be needed.
Edit:
So if i have a page for say "A" server I would like to click the Kill Button and have it run for "A"'s process only the command kill -9
ps aux | grep --regexp="`netstat -nlept | awk '/:$PORT/ {split($9,t,"/"); print t[1]}'`" | awk '{print $2}'``
This would KILL the process for "A" and only "A".
I have done the work and build the whole dashboard and the made the whole thing, just need to know how to make a command from a php site that will edit the server process.
I build this so far using the info i have googled.
<?php
$process = new Process('ls -al');
$process = new Process();
$process.setPid(my_pid);
?>
<?php
$process.stop();
$process.start();
if ($process.status()){
echo "The process is currently running";
}else{
echo "The proce开发者_开发知识库ss is not running.";
}
?>
That is as far as i have gotten iv put a lot of work into this panel. But its this that is stopping me get towards a fully done panel.
The PHP exec command is just one way of many ways to do this.
http://php.net/manual/en/function.exec.php
exec('ps -aux');
I'm sure some other answers will pop up here. Just make sure you aren't throwing unsanitized user data in there, last thing you want is your system to be compromised. Also executing shell commands should be your last option. Think about what you actually want to do. A lot of the time a simple google search you can find native ways for PHP to accomplish what you are trying to do.
精彩评论