SiDoMan/pages/do.php

59 lines
1.7 KiB
PHP
Raw Normal View History

2020-10-23 20:53:31 +00:00
<?php
if(isset($_SESSION['LOGIN']))
{
if($_SESSION['LOGIN'] == 'true')
{
$dockerClient = new Docker();
$allContainers = $dockerClient->getAllContainers();
$container = NULL;
foreach($allContainers as $thisContainer)
if($thisContainer['Id'] == $_SESSION['CONTAINER'] || $_SESSION['CONTAINER'] == ltrim($thisContainer['Names']['0'], '/'))
$container = $thisContainer;
if($container == NULL)
die("unknown container");
if(isset($_REQUEST['do-start']))
2020-10-23 20:55:03 +00:00
$dockerClient->startContainer($container['Id']);
2020-10-23 20:53:31 +00:00
if(isset($_REQUEST['do-stop']))
2020-10-23 20:55:03 +00:00
$dockerClient->stopContainer($container['Id']);
2020-10-23 20:53:31 +00:00
if(isset($_REQUEST['do-kill']))
2020-10-23 20:55:03 +00:00
$dockerClient->killContainer($container['Id']);
2020-10-23 20:53:31 +00:00
if(isset($_REQUEST['do-restart']))
{
2020-10-23 20:55:03 +00:00
$dockerClient->killContainer($container['Id']);
$dockerClient->startContainer($container['Id']);
2020-10-23 20:53:31 +00:00
}
2020-10-24 11:48:01 +00:00
if(isset($_REQUEST['do-command']))
{
if(isset($_REQUEST['commandtext']))
{
$filename = "/tmp/command".time().".txt";
$command = trim($_REQUEST['commandtext']);
2020-10-24 11:49:25 +00:00
if($command != "")
{
2020-10-24 11:53:32 +00:00
file_put_contents($filename, $command."\n");
2020-10-24 11:49:25 +00:00
2020-10-24 11:50:20 +00:00
system('cat '.$filename.' | socat EXEC:"docker attach '.$container['Id'].'",pty STDIN');
2020-10-24 12:22:17 +00:00
unlink($filename);
2020-10-24 11:49:25 +00:00
}
2020-10-24 11:48:01 +00:00
}
}
2020-10-24 11:34:14 +00:00
header("Location: index.php");
die();
2020-10-23 20:53:31 +00:00
}else{
die("Login is not valid!");
}
}else{
die("Access denied!");
}
?>