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