Alternc  latest
Alternc logiel libre pour l'hébergement
vm.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * LXC vm management code
5  *
6  * @copyright AlternC-Team 2000-2017 https://alternc.com/
7  */
8 
9 require_once("../class/config.php");
10 
11 $fields = array (
12  "action" => array ("request", "string", ''),
13  "script" => array ("request", "boolean", 0),
14 );
16 
17 if (in_array($action, array('start', 'stop', 'monit'))) {
18  $res = $hooks->invoke($action, array(), 'lxc');
19 }
20 switch ($action) {
21 case "start":
22  $lxc->start();
23  break;
24 case "stop":
25  $lxc->stop();
26  break;
27 }
28 if ($lxc->error && !$script) {
29  $error=$lxc->error;
30 }
31 
32 $infos = $lxc->getvm();
33 
34 if ($script) {
35  header("Content-Type: text/plain");
36  if (isset($res)) {
37  echo "ACTION:".$action."\n";
38  echo "RETURN:".intval($res['lxc'])."\n";
39  }
40  if ($infos) {
41  echo "VM_STATUS:OK\n";
42  echo "VM_START:".$infos['starttime']."\n";
43  echo "VM_HOSTNAME:".$infos['hostname']."\n";
44  foreach($infos['ssh-keys'] as $k)
45  if (trim($k))
46  echo "VM_SSHKEY:".trim($k)."\n";
47  } else {
48  echo "VM_STATUS:NONE\n";
49  }
50  die();
51 }
52 
53 # Show the header after the "if script" ;)
54 include_once("head.php");
55 
56 ?>
57 
58 <h3><?php __('Console access'); ?></h3>
59 <hr/>
60 <br/>
61 
62 <?php
63 echo $msg->msg_html_all();
64 ?>
65 
66 <div>
67 <?php if (empty($infos)) {
68 ?>
69 <p class="alert alert-info"><?php __("You can start a virtual machine."); ?></p>
70 <form method="post" action="vm.php">
71  <?php csrf_get(); ?>
72  <input type="hidden" name="action" value="start" />
73 <input type="submit" class="inb ok" name="go" value="<?php __("Click here to start a virtual machine."); ?>" />
74 </form>
75 <?php
76  } else {
77  echo "<table class='tedit'>";
78  echo "<tr><th>"._("Hostname")."</th><td>".$infos['hostname']."</td></tr>";
79  echo "<tr><th>"._("Start time")."</th><td>".date('Y-m-d H:i:s',$infos['starttime'])."</td></tr>";
80  echo "<tr><th>"._("SSH Fingerprint")."</th><td style=\"font-family: Courier, fixed;\">".implode('<br />',$infos['ssh-keys'])."</td></tr>";
81  echo "<tr><th>"._("Useful command")."</th><td><pre>";
82  echo "ssh ".$mem->user['login']."@".$infos['hostname']."\n";
83  echo "rsync ".$mem->user['login']."@".$infos['hostname']."\n";
84  echo "</pre></td></tr>";
85  echo "</table>";
86 ?>
87 <p class="alert alert-info"><?php __("You can stop your virtual machine."); ?></p>
88 <form method="post" action="vm.php">
89 <?php csrf_get(); ?>
90  <input type="hidden" name="action" value="stop" />
91 <input type="submit" class="inb cancel" name="go" value="<?php __("Click here to stop your running virtual machine."); ?>" />
92 </form>
93 <?php
94 } // empty infos ?>
95 </div>
96 
97 <br/>
98 <br/>
99 <hr/>
100 
101 <h3><?php __("Tips"); ?></h3>
102 
103 <div id="tabs-tips-vm">
104 
105 <ul>
106  <li class="help"><a href="#tabs-tips-soft"><?php __("Available softwares"); ?></a></li>
107  <li class="help"><a href="#tabs-tips-script"><?php __("Remotely start/stop a VM"); ?></a></li>
108 </ul>
109 
110 
111 <div id='tabs-tips-script'>
112  <?php __("You can script the launch the console access in command line by using this url:"); ?>
113  <pre>http://<?php echo $mem->user['login'].':ALTERNC_PASSWORD@'.$host.'/vm.php?http_auth=1&amp;script=1&amp;action=start' ?></pre>
114  <?php __("You can halt the vm by using:"); ?>
115  <pre>http://<?php echo $mem->user['login'].':ALTERNC_PASSWORD@'.$host.'/vm.php?http_auth=1&amp;script=1&amp;action=stop' ?></pre>
116  <?php __("And you can see existing vm information (if the vm is running) by using:"); ?>
117  <pre>http://<?php echo $mem->user['login'].':ALTERNC_PASSWORD@'.$host.'/vm.php?http_auth=1&amp;script=1' ?></pre>
118  <i><?php __("Warning: if you do not use HTTPS, your password will be transfered without any protection"); ?></i>
119 </div>
120 
121 <div id='tabs-tips-soft'>
122  <?php __("To access a remote console with SSH, you can use Putty.");?>
123  <br/>
124  <?php __("To transfer files, you can use Filezilla in SFTP mode."); ?>
125 </div>
126 
127 </div><!-- tabs-tips-vm -->
128 
129 <script type="text/javascript">
130  $(function() {$( "#tabs-tips-vm" ).tabs();});
131 </script>
132 
133 <?php
134 include_once("foot.php");
135 ?>
$hooks
Definition: bootstrap.php:74
$msg
Definition: bootstrap.php:75
$res
Definition: index.php:111
__($str)
Definition: functions.php:404
getFields($fields, $requestOnly=false)
Get the Fields of the posted form from $_REQUEST or POST or GET and check their type.
Definition: functions.php:688
csrf_get($return=false)
Give a new CSRF uniq token for a form the session must be up since the CSRF is linked to the session ...
Definition: functions.php:1159
Definition: vm.class.php:2
$error
Definition: ssl_delete.php:45
$fields
LXC vm management code.
Definition: vm.php:11
if(in_array($action, array('start', 'stop', 'monit'))) switch($action) if($lxc->error &&! $script) $infos
Definition: vm.php:32