2013-04-12 21:52:27 +00:00
|
|
|
<?php
|
|
|
|
|
2017-10-08 17:53:03 +00:00
|
|
|
/**
|
|
|
|
* LXC vm management code
|
|
|
|
*
|
|
|
|
* @copyright AlternC-Team 2000-2017 https://alternc.com/
|
|
|
|
*/
|
|
|
|
|
2013-04-12 21:52:27 +00:00
|
|
|
require_once("../class/config.php");
|
|
|
|
|
|
|
|
$fields = array (
|
2013-09-17 17:36:58 +00:00
|
|
|
"action" => array ("request", "string", ''),
|
|
|
|
"script" => array ("request", "boolean", 0),
|
2013-04-12 21:52:27 +00:00
|
|
|
);
|
|
|
|
getFields($fields);
|
|
|
|
|
2013-04-21 15:49:56 +00:00
|
|
|
if (in_array($action, array('start', 'stop', 'monit'))) {
|
2013-04-21 10:04:32 +00:00
|
|
|
$res = $hooks->invoke($action, array(), 'lxc');
|
2013-04-12 21:52:27 +00:00
|
|
|
}
|
2013-09-17 17:36:58 +00:00
|
|
|
switch ($action) {
|
|
|
|
case "start":
|
|
|
|
$lxc->start();
|
|
|
|
break;
|
|
|
|
case "stop":
|
|
|
|
$lxc->stop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($lxc->error && !$script) {
|
|
|
|
$error=$lxc->error;
|
|
|
|
}
|
2013-04-12 21:52:27 +00:00
|
|
|
|
2013-04-21 15:49:56 +00:00
|
|
|
$infos = $lxc->getvm();
|
|
|
|
|
2013-04-22 07:20:49 +00:00
|
|
|
if ($script) {
|
2013-09-17 17:36:58 +00:00
|
|
|
header("Content-Type: text/plain");
|
2013-04-22 08:03:36 +00:00
|
|
|
if (isset($res)) {
|
|
|
|
echo "ACTION:".$action."\n";
|
|
|
|
echo "RETURN:".intval($res['lxc'])."\n";
|
|
|
|
}
|
|
|
|
if ($infos) {
|
2013-04-23 12:58:36 +00:00
|
|
|
echo "VM_STATUS:OK\n";
|
2013-09-17 17:36:58 +00:00
|
|
|
echo "VM_START:".$infos['starttime']."\n";
|
|
|
|
echo "VM_HOSTNAME:".$infos['hostname']."\n";
|
2013-10-18 12:56:46 +00:00
|
|
|
foreach($infos['ssh-keys'] as $k)
|
|
|
|
if (trim($k))
|
|
|
|
echo "VM_SSHKEY:".trim($k)."\n";
|
2013-04-22 08:03:36 +00:00
|
|
|
} else {
|
2013-04-23 12:58:36 +00:00
|
|
|
echo "VM_STATUS:NONE\n";
|
2013-04-22 08:03:36 +00:00
|
|
|
}
|
2013-04-22 07:20:49 +00:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
# Show the header after the "if script" ;)
|
|
|
|
include_once("head.php");
|
|
|
|
|
2013-04-12 21:52:27 +00:00
|
|
|
?>
|
|
|
|
|
2013-04-21 15:49:56 +00:00
|
|
|
<h3><?php __('Console access'); ?></h3>
|
|
|
|
<hr/>
|
|
|
|
<br/>
|
|
|
|
|
2017-08-17 01:32:18 +00:00
|
|
|
<?php
|
|
|
|
echo $msg->msg_html_all();
|
|
|
|
?>
|
2013-04-21 15:49:56 +00:00
|
|
|
|
|
|
|
<div>
|
|
|
|
<?php if (empty($infos)) {
|
2013-09-17 17:36:58 +00:00
|
|
|
?>
|
2013-10-18 09:12:41 +00:00
|
|
|
<p class="alert alert-info"><?php __("You can start a virtual machine."); ?></p>
|
2013-09-17 17:36:58 +00:00
|
|
|
<form method="post" action="vm.php">
|
2016-05-20 12:21:47 +00:00
|
|
|
<?php csrf_get(); ?>
|
2013-09-17 17:36:58 +00:00
|
|
|
<input type="hidden" name="action" value="start" />
|
2013-10-18 14:14:37 +00:00
|
|
|
<input type="submit" class="inb ok" name="go" value="<?php __("Click here to start a virtual machine."); ?>" />
|
2013-09-17 17:36:58 +00:00
|
|
|
</form>
|
|
|
|
<?php
|
2013-10-18 12:56:46 +00:00
|
|
|
} else {
|
2013-04-21 15:49:56 +00:00
|
|
|
echo "<table class='tedit'>";
|
2013-09-17 17:36:58 +00:00
|
|
|
echo "<tr><th>"._("Hostname")."</th><td>".$infos['hostname']."</td></tr>";
|
|
|
|
echo "<tr><th>"._("Start time")."</th><td>".date('Y-m-d H:i:s',$infos['starttime'])."</td></tr>";
|
|
|
|
echo "<tr><th>"._("SSH Fingerprint")."</th><td style=\"font-family: Courier, fixed;\">".implode('<br />',$infos['ssh-keys'])."</td></tr>";
|
|
|
|
echo "<tr><th>"._("Useful command")."</th><td><pre>";
|
|
|
|
echo "ssh ".$mem->user['login']."@".$infos['hostname']."\n";
|
|
|
|
echo "rsync ".$mem->user['login']."@".$infos['hostname']."\n";
|
2013-04-22 13:37:48 +00:00
|
|
|
echo "</pre></td></tr>";
|
2013-09-17 17:36:58 +00:00
|
|
|
echo "</table>";
|
|
|
|
?>
|
2013-10-18 09:12:41 +00:00
|
|
|
<p class="alert alert-info"><?php __("You can stop your virtual machine."); ?></p>
|
2013-09-17 17:36:58 +00:00
|
|
|
<form method="post" action="vm.php">
|
2016-05-20 12:21:47 +00:00
|
|
|
<?php csrf_get(); ?>
|
2013-09-17 17:36:58 +00:00
|
|
|
<input type="hidden" name="action" value="stop" />
|
2013-10-18 14:14:37 +00:00
|
|
|
<input type="submit" class="inb cancel" name="go" value="<?php __("Click here to stop your running virtual machine."); ?>" />
|
2013-09-17 17:36:58 +00:00
|
|
|
</form>
|
|
|
|
<?php
|
2013-04-21 15:49:56 +00:00
|
|
|
} // empty infos ?>
|
|
|
|
</div>
|
2013-04-12 21:52:27 +00:00
|
|
|
|
2013-04-22 07:20:49 +00:00
|
|
|
<br/>
|
|
|
|
<br/>
|
|
|
|
<hr/>
|
2013-10-18 08:22:12 +00:00
|
|
|
|
2013-04-23 12:58:36 +00:00
|
|
|
<h3><?php __("Tips"); ?></h3>
|
2013-10-18 08:22:12 +00:00
|
|
|
|
|
|
|
<div id="tabs-tips-vm">
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li class="help"><a href="#tabs-tips-soft"><?php __("Available softwares"); ?></a></li>
|
|
|
|
<li class="help"><a href="#tabs-tips-script"><?php __("Remotely start/stop a VM"); ?></a></li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
<div id='tabs-tips-script'>
|
|
|
|
<?php __("You can script the launch the console access in command line by using this url:"); ?>
|
|
|
|
<pre>http://<?php echo $mem->user['login'].':ALTERNC_PASSWORD@'.$host.'/vm.php?http_auth=1&script=1&action=start' ?></pre>
|
|
|
|
<?php __("You can halt the vm by using:"); ?>
|
|
|
|
<pre>http://<?php echo $mem->user['login'].':ALTERNC_PASSWORD@'.$host.'/vm.php?http_auth=1&script=1&action=stop' ?></pre>
|
|
|
|
<?php __("And you can see existing vm information (if the vm is running) by using:"); ?>
|
|
|
|
<pre>http://<?php echo $mem->user['login'].':ALTERNC_PASSWORD@'.$host.'/vm.php?http_auth=1&script=1' ?></pre>
|
|
|
|
<i><?php __("Warning: if you do not use HTTPS, your password will be transfered without any protection"); ?></i>
|
2013-04-23 12:58:36 +00:00
|
|
|
</div>
|
|
|
|
|
2013-10-18 08:22:12 +00:00
|
|
|
<div id='tabs-tips-soft'>
|
|
|
|
<?php __("To access a remote console with SSH, you can use Putty.");?>
|
|
|
|
<br/>
|
|
|
|
<?php __("To transfer files, you can use Filezilla in SFTP mode."); ?>
|
2013-04-23 12:58:36 +00:00
|
|
|
</div>
|
|
|
|
|
2013-10-18 08:22:12 +00:00
|
|
|
</div><!-- tabs-tips-vm -->
|
|
|
|
|
2013-04-23 12:58:36 +00:00
|
|
|
<script type="text/javascript">
|
2013-10-18 08:22:12 +00:00
|
|
|
$(function() {$( "#tabs-tips-vm" ).tabs();});
|
2013-04-23 12:58:36 +00:00
|
|
|
</script>
|
|
|
|
|
2013-04-21 15:49:56 +00:00
|
|
|
<?php
|
|
|
|
include_once("foot.php");
|
|
|
|
?>
|