/[projects]/misc/xenconsole/index.php
ViewVC logotype

Diff of /misc/xenconsole/index.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

misc/xenconsole/webadmin.php revision 1876 by torben, Fri Nov 30 08:27:52 2012 UTC misc/xenconsole/index.php revision 1884 by torben, Fri Nov 30 15:54:54 2012 UTC
# Line 39  $vms_array = $xenserver->VM__get_all_rec Line 39  $vms_array = $xenserver->VM__get_all_rec
39    
40  <script type='text/javascript'>  <script type='text/javascript'>
41  $(document).ready( function() {  $(document).ready( function() {
42          loadServer();          setInterval(refreshData, 60000);        
43            refreshData();
44  });  });
45    
46    function refreshData() {
47            $.get('ajaxdata.php', function(xml) {
48                    $(xml).find('vm').each(function() {
49                            var name = $(this).find('name').text();
50                            var state = $(this).find('state').text();
51    
52                            name = name.replace(" ", "_");
53                            name = name.replace(".", "_");
54                            
55                            var id = "#state_" + name;
56                            var css = $(id).css("background");
57    
58                            if (state == "Running") {
59                                    $(id).css("background-image", "url('gfx/vps_topgreen.png')");
60                            } else {
61                                    $(id).css("background-image", "url('gfx/vps_topred.png')");
62                            }
63                            
64               })
65           });
66    }
67    
68  function doAction(action, uuid) {  function doAction(action, uuid) {
69          var key = prompt("Key");          var key = prompt("Key");
70          if (key == "" || key == null) {          if (key == "" || key == null) {
# Line 53  function doAction(action, uuid) { Line 76  function doAction(action, uuid) {
76          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
77                  alert(data);                  alert(data);
78                  document.body.style.cursor = 'default'                  document.body.style.cursor = 'default'
79                  if (data == "OK") {  
80                          window.location.reload();                  refreshData();
                 }  
81          });          });
82  }  }
83    
84  function console(url, session) {  function console(url, session) {
85            if (url == '')
86                    return;
87    
88          var key = prompt("Key");          var key = prompt("Key");
89          if (key == "" || key == null) {          if (key == "" || key == null) {
90                  return;                  return;
# Line 67  function console(url, session) { Line 92  function console(url, session) {
92          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;
93    
94          //window.location = url;          //window.location = url;
95          $('#mainwindow').load(url);          //$('#mainwindow').load(url);
96            window.open(url);
97  }  }
98    
 function loadServer() {  
         $('#mainwindow').load('server.php');  
 }  
99    
 function loadvm(uuid) {  
         $('#mainwindow').load('vm.php?uuid=' + uuid );  
 }  
100    
101  </script>  </script>
102    
# Line 152  foreach($vms_array as $vm) { Line 172  foreach($vms_array as $vm) {
172          $harddrive_size = 0;          $harddrive_size = 0;
173          $cpu_count = $vm["VCPUs_max"];          $cpu_count = $vm["VCPUs_max"];
174    
175            $clean_name = str_replace(" ", "_", $name);
176            $clean_name = str_replace(".", "_", $clean_name);
177            
178    
179          foreach ($vm["VBDs"] as $vbds) {          foreach ($vm["VBDs"] as $vbds) {
180                  $vbd = $xenserver->VBD__get_record($vbds);                  $vbd = $xenserver->VBD__get_record($vbds);
181                  if ($vbd["type"] == 'Disk') {                  if ($vbd["type"] == 'Disk') {
# Line 168  foreach($vms_array as $vm) { Line 192  foreach($vms_array as $vm) {
192                  $vps_topbg = 'vps_topred.png';                  $vps_topbg = 'vps_topred.png';
193          }          }
194    
195            $network = "";
196            if ( $vm["power_state"] == "Running" && $vm["guest_metrics"] != "OpaqueRef:NULL" ) {
197                    $guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] );
198                    $network = "(IP: " . implode( ",",  $guest_metrics["networks"]) . ")";
199            } else {
200                    $guest_metrics = Array() ;
201            }
202    
203    
204            $url = "";
205            $session = "";
206            foreach($vm["consoles"] as $conref) {
207                    $con = $xenserver->console__get_record( $conref );
208                    //var_dump($con);
209    
210                    if ($con["protocol"] == "rfb") {
211                            $url = urlencode( $con["location"] );
212                            $session = $xenserver->get_id();
213                    }
214            }
215            
216    
217    
218    
219  //      echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";  //      echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";
220  ?>  ?>
221          <!-- MACHINE -->          <!-- MACHINE -->
222          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps'>          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='<?php echo $name;?>'>
223                  <tr background='gfx/vps_topbg.png'>                  <tr background='gfx/vps_topbg.png'>
224                          <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'>&nbsp;</td>                          <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small' id='state_<?php echo $clean_name;?>'>&nbsp;</td>
225                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
226                          <td colspan='2' class='small' align='right'>(IP: 192.168.10.45, 172.10.0.34) <img src='gfx/icon-terminal.png' style='vertical-align: middle;'></td>                          <td colspan='2' class='small' align='right'>
227                                    <?php echo $network;?>
228                                    <?php
229                                    if ($url != "") {
230                                            echo "<a href='#' onclick=\"console('$url','$session')\"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a>";
231                                    }
232                                    ?>
233                            </td>
234                  </tr>                  </tr>
235    
236                  <tr bgcolor='#eee'>                  <tr bgcolor='#eee'>
237                  <td></td>                  <td></td>
238    
239                          <td width='150' class='small'>start stop force</td>                  <td width='150' class='small'>
240                            <?php
241                            if ($state == "Running") {
242                                    echo "start | ";
243                                    echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | ";
244                                    echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>";
245                            } else {
246                                    echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | ";
247                                    echo "stop | ";
248                                    echo "force shutdown";
249                            }
250                            ?>
251    
252                    </td>
253    
254                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
255                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>

Legend:
Removed from v.1876  
changed lines
  Added in v.1884

  ViewVC Help
Powered by ViewVC 1.1.20