add api
This commit is contained in:
parent
85016dbc94
commit
30675bb52f
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
date_default_timezone_set("Europe/Berlin");
|
||||
header('Strict-Transport-Security: max-age=657000');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include_once("classen/helper.php");
|
||||
include_once("classen/docker.php");
|
||||
|
||||
if(isset($_REQUEST['CONTAINER']) || isset($_REQUEST['KEY']))
|
||||
{
|
||||
if(trim($_REQUEST['CONTAINER']) != "" && trim($_REQUEST['KEY']) != "")
|
||||
{
|
||||
$dockerClient = new Docker();
|
||||
$allContainers = $dockerClient->getAllContainers();
|
||||
$container = NULL;
|
||||
|
||||
foreach($allContainers as $thisContainer)
|
||||
{
|
||||
if($thisContainer['Id'] == trim($_REQUEST['CONTAINER']) || trim($_REQUEST['CONTAINER']) == ltrim($thisContainer['Names']['0'], '/'))
|
||||
{
|
||||
if(isset($thisContainer['Labels']['remotepass']))
|
||||
{
|
||||
if(trim($thisContainer['Labels']['remotepass']) == trim($_REQUEST['KEY']))
|
||||
{
|
||||
$container = $thisContainer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($container == NULL)
|
||||
die("access denied!");
|
||||
|
||||
if(isset($_REQUEST['METODE']))
|
||||
{
|
||||
if(trim($_REQUEST['METODE']) != "")
|
||||
{
|
||||
if(strtoupper($_REQUEST['METODE']) == "START")
|
||||
{
|
||||
$dockerClient->startContainer($container['Id']);
|
||||
}
|
||||
|
||||
if(strtoupper($_REQUEST['METODE']) == "STOP")
|
||||
{
|
||||
$dockerClient->stopContainer($container['Id']);
|
||||
}
|
||||
|
||||
if(strtoupper($_REQUEST['METODE']) == "KILL")
|
||||
{
|
||||
$dockerClient->killContainer($container['Id']);
|
||||
}
|
||||
|
||||
if(strtoupper($_REQUEST['METODE']) == "RESTART")
|
||||
{
|
||||
$dockerClient->killContainer($container['Id']);
|
||||
$dockerClient->startContainer($container['Id']);
|
||||
}
|
||||
|
||||
if(strtoupper($_REQUEST['METODE']) == "COMMAND")
|
||||
{
|
||||
if(isset($_REQUEST['COMMAND']))
|
||||
{
|
||||
if(trim($_REQUEST['COMMAND']) != "")
|
||||
{
|
||||
$filename = "/tmp/command".time().".txt";
|
||||
$command = trim($_REQUEST['COMMAND']);
|
||||
|
||||
file_put_contents($filename, $command."\n");
|
||||
|
||||
system('cat '.$filename.' | socat EXEC:"docker attach '.$container['Id'].'",pty STDIN');
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -10,9 +10,6 @@ include_once("classen/HTML.php");
|
|||
include_once("classen/helper.php");
|
||||
include_once("classen/docker.php");
|
||||
|
||||
//$_SESSION['CONTAINER'] = "Game.OpenSimulator.Twix";
|
||||
//$_SESSION['LOGIN'] = "true";
|
||||
|
||||
if(isset($_REQUEST['logout']))
|
||||
if($_REQUEST['logout'] == '1')
|
||||
$_SESSION = array();
|
||||
|
|
Loading…
Reference in New Issue