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

Diff of /misc/xenconsole/index.php

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

revision 1885 by torben, Fri Nov 30 17:56:07 2012 UTC revision 2018 by torben, Thu Jul 18 13:00:14 2013 UTC
# Line 1  Line 1 
1  <?php  <?php
2  include("config.php");  require("config.php");
3    
4  function format_memory($size) {  function format_memory($size) {
5    if (1024 > $size) {    if (1024 > $size) {
# Line 28  include('xenapi.php'); Line 28  include('xenapi.php');
28  /* Establish session with Xenserver */  /* Establish session with Xenserver */
29  $xenserver = new XenApi($url, $login, $password);  $xenserver = new XenApi($url, $login, $password);
30    
31    $hosts_array = $xenserver->host__get_all();
32    $host = $xenserver->host__get_record($hosts_array[0]);
33    $host_metrics = $xenserver->host_metrics__get_record($host["metrics"]);
34    
35    $xenversion = $host["software_version"]["product_brand"] . " " . $host["software_version"]["product_version"];
36    $xenversion .= " / Linux:" . $host["software_version"]["linux"] . " / xen: " . $host["software_version"]["xen"] . " / xapi: " . $host["software_version"]["xapi"] ;
37    
38    $expire = split('T', $host["license_params"]["expiry"]);
39    $license = "License: " . $host["license_params"]["sku_type"] . ", expires " . $expire[0] ;
40    
41  $vms_array = $xenserver->VM__get_all_records();  $vms_array = $xenserver->VM__get_all_records();
42    
43    $namelabel = $host["name_label"];
44    
45  ?>  ?>
46  <html>  <html>
47  <head>  <head>
48  <title>XenServer::SERVER</title>  <title>XenServer::<?php echo $namelabel;?></title>
49  <script type='text/javascript' src="jquery-1.8.2.min.js"></script>  
50    <link rel="stylesheet" type="text/css" href="jquery/theme/jquery-ui.css">
51    <style>
52    .ui-menu {
53            width: 200px;
54    }
55    </style>
56    <script type='text/javascript' src="jquery/jquery-1.9.1.min.js"></script>
57    <script type='text/javascript' src="jquery/jquery-ui-1.10.2.min.js"></script>
58    
59  <script type='text/javascript'>  <script type='text/javascript'>
60    var menu = 0;
61    var menu_uuid = '';
62    
63  $(document).ready( function() {  $(document).ready( function() {
64            $("#menu").hide();
65          setInterval(refreshData, 60000);                  setInterval(refreshData, 60000);        
66          refreshData();          refreshData();
67          $('.console').click( function() {          $('.console').click( function() {
68                  var session = $(this).data('session');                  var session = $(this).data('session');
69                  var conurl = $(this).data('conurl');                  var conurl = $(this).data('conurl');
70                  console(conurl,session);                  var name = $(this).data('name');
71                    openConsole(conurl,session,name);
72            });
73    
74            $('#logo').click( function() {
75                    refreshData();
76            });
77    
78            $('.settings').click( function(event) {
79                    menu_uuid = $(this).attr('uuid');
80    
81                    $('#menu').menu( {
82                            select: function(event2,ui) {
83                                            var action = $(ui.item).attr("action");
84                                            if (action == "memory") {
85                                                    doAction("setMemory", menu_uuid, "");  
86                                            }
87                                            if (action == "cpu") {
88                                                    doAction("setCPU", menu_uuid, "");      
89                                            }
90                                    },
91                            create: function(event3,ui) {
92                                    menu = 1;
93                                    }
94                            /*position: {
95                                    my: "left", of: event
96                            }*/
97                    });
98                    $('#menu').show().position( {my: "left top", of: event} );
99                    event.stopPropagation();
100            });
101    
102            $('.cd').click( function(event) {
103                    var uuid = $(this).attr('uuid');
104                    cdSelectorDialog(uuid);
105            });
106    
107            $(document).click( function(event) {
108                    closeMenu();
109          });          });
110  });  });
111    
112    function cdSelectorDialog(uuid) {
113            $('#cdselector').html('');
114            $('#cdselector').load( 'getisolist.php' );
115            var cddata;
116    
117            $.getJSON('getcdinfo.php?uuid=' + uuid, function(data) {
118                    cddata = data;
119                    if (data.ISO != '') {
120                            $('#cdcurrent').html(  data.ISO );
121                    } else {
122                            $('#cdcurrent').html('<i>No ISO currently mounted</i>');
123                    }
124            });
125            
126            $('#dialog-cd').dialog({
127                    modal: true,
128                    width: 800,
129                    height: 300,
130                    buttons: {
131                            Mount: function() {
132                                    $( this ).dialog( "close" );
133                                    var vdi = $("#cdselector").val();
134                                    cdAction("mount", cddata.VBD, vdi);
135                            },
136                            Eject: function() {
137                                    $( this ).dialog( "close" );
138                                    cdAction("eject", cddata.VBD, "");
139                            },
140                            Cancel: function() {
141                                    $( this ).dialog( "close" );
142                            }
143                            
144                    }
145            });
146    }
147    
148    function closeMenu() {
149            if (menu > 0) {
150                    $("#menu").menu("destroy").hide();
151                    menu = 0;
152            }
153    }
154    
155  function refreshData() {  function refreshData() {
156            $("#logo").hide();      
157          $.get('ajaxdata.php', function(xml) {          $.get('ajaxdata.php', function(xml) {
158                    $(xml).find('host').each(function() {
159                            var memtotal = $(this).find('memtotal').text();
160                            var memfree = $(this).find('memfree').text();  
161                            var cpuavg = $(this).find('cpuavg').text();
162    
163                            memtotal = Math.round ( memtotal / (1024*1024) );
164                            memfree = Math.round ( memfree / (1024*1024) );
165                            var memused = memtotal - memfree;
166                            var mem_percentage = Math.round( (memused/memtotal) * 100);
167    
168                            //alert(memused + ' ' + mem_percentage);
169    
170                            $('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage);
171                            $('#server_memory_usage').attr('alt', mem_percentage + '%');
172                            $('#server_memory_usage').attr('title', mem_percentage + '%');
173                            $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');
174    
175    
176                            $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);
177                            $('#server_cpu_usage').attr('alt', cpuavg + '%');
178                            $('#server_cpu_usage').attr('title', cpuavg + '%');
179                            $('#server_cpu_usage_txt').text( cpuavg+ '%');
180                    });
181                  $(xml).find('vm').each(function() {                  $(xml).find('vm').each(function() {
182                          var name = $(this).find('name').text();                          var name = $(this).find('name').text();
183                          var state = $(this).find('state').text();                          var state = $(this).find('state').text();
# Line 57  function refreshData() { Line 185  function refreshData() {
185                          var state = $(this).find('state').text();                          var state = $(this).find('state').text();
186                          var conurl = $(this).find('conurl').text();                          var conurl = $(this).find('conurl').text();
187                          var session = $(this).find('session').text();                          var session = $(this).find('session').text();
188                            var os = $(this).find('os').text();
189                          name = name.replace(" ", "_");                          var guestversion = $(this).find('guestversion').text();
190                          name = name.replace(".", "_");                          var cpuavg = $(this).find('cpuavg').text();
191                            var curmem = $(this).find('curmem').text();
192                            var maxmem = $(this).find('maxmem').text();
193                            var cpus = $(this).find('cpus').text();
194    
195                            var mempercent = Math.round( (curmem*100) / maxmem );
196    
197                            name = name.replace(/ /g, "_");
198                            name = name.replace(/\./g, "_");
199                            name = name.replace(/\(/g, "_");
200                            name = name.replace(/\)/g, "_");
201                                                    
202                          var id = "#vm_" + name;                          var id = "#vm_" + name;
203    
204                          var vm = $(id);                                          var vm = $(id);                
205    
206                            if (guestversion != '') {
207                                    os += ' Guest Tools: ' + guestversion;
208                            }
209    
210                            vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB");
211                            vm.find('.vps_cpu_usage_txt_UID').text( cpus + " VCPU");
212    
213                          if (state == "Running") {                          if (state == "Running") {
214                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");
215                                  vm.find('.network').show();                                  vm.find('.network').show();
# Line 72  function refreshData() { Line 217  function refreshData() {
217                                  vm.find('.console').show();                                  vm.find('.console').show();
218                                  vm.find('.console').data('conurl', conurl);                                  vm.find('.console').data('conurl', conurl);
219                                  vm.find('.console').data('session', session);                                  vm.find('.console').data('session', session);
220                                    vm.find('.console').data('name', name);
221                                    vm.find('.settings').hide();
222                                  vm.find('.actionstop').show();                                  vm.find('.actionstop').show();
223                                  vm.find('.actionstart').hide();                                  vm.find('.actionstart').hide();
224                                    vm.find('.os').text(' - ' + os);
225    
226    
227                                    vm.find('.cpu_graph').show();
228                                    vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);
229                                    vm.find('.cpu_graph').attr('title',  cpuavg + '%');
230    
231                                    vm.find('.mem_graph').show();
232                                    vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);
233                                    vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );
234                          } else {                          } else {
235                                  if (state == "Halted") {                                  if (state == "Halted") {
236                                          vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");                                          vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");
237                                  } else {                                  } else {
238                                          vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");                                          vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
239                                  }                                  }
240                                    vm.find('.os').text('');
241    
242                                  vm.find('.network').hide();                                  vm.find('.network').hide();
243                                  vm.find('.console').hide();                                  vm.find('.console').hide();
244                                    vm.find('.settings').show();
245                                  vm.find('.actionstop').hide();                                  vm.find('.actionstop').hide();
246                                  vm.find('.actionstart').show();                                  vm.find('.actionstart').show();
247                                    vm.find('.cpu_graph').hide();
248                                    vm.find('.mem_graph').hide();
249                          }                          }
250                                                    
251             })                  });
252                    $('#logo').show();
253         });         });
254  }  }
255    
256  function doAction(action, uuid) {  function doAction(action, uuid, vm) {
257            var val="";
258    
259          var key = prompt("Key");          var key = prompt("Key");
260          if (key == "" || key == null) {          if (key == "" || key == null) {
261                  return;                  return;
262          }          }
263          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
264            $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
265    
266          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;          if (action == "setMemory") {
267                    val = prompt("Set memory target");
268                    val *= (1024*1024);
269                    if (val == "" || val == null) {
270                            return;
271                    }
272            }
273            if (action == "setCPU") {
274                    val = prompt("Set CPU count");
275                    if (val == "" || val == null) {
276                            return;
277                    }
278            }
279    
280            var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;;
281          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
282                  alert(data);                  if (data != 'OK') {
283                            alert(data);
284                    }
285                  document.body.style.cursor = 'default'                  document.body.style.cursor = 'default'
286    
287                  refreshData();                  refreshData();
288          });          });
289  }  }
290    
291  function console(url, session) {  function cdAction(action, vbd,vdi) {
292            var key = prompt("Key");
293            if (key == "" || key == null) {
294                    return;
295            }
296            document.body.style.cursor = 'wait';
297            var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + key + "&VDI=" + vdi;
298            var response = $.get(url, function(data) {
299                    if (data != 'OK') {
300                            alert(data);
301                    }
302                    document.body.style.cursor = 'default'
303            });
304            
305    }
306    
307    function openConsole(url, session, name) {
308          if (url == '')          if (url == '')
309                  return;                  return;
310    
# Line 114  function console(url, session) { Line 312  function console(url, session) {
312          if (key == "" || key == null) {          if (key == "" || key == null) {
313                  return;                  return;
314          }          }
315          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name;
316    
317          //window.location = url;          //window.location = url;
318          //$('#mainwindow').load(url);          //$('#mainwindow').load(url);
# Line 163  body { Line 361  body {
361    
362  <table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'>  <table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'>
363  <tr>  <tr>
364          <td rowspan='2' width='160'><img src='gfx/citrix-logo.png'></td>          <td rowspan='2' width='160'><img src='gfx/citrix-logo.png' id='logo'></td>
365          <td colspan='3' class='small' align='right'>Linux:2.6.32.12-0.7.1.xs6.0.2.542.170665xen / xen: 4.1.2 / xapi: 1.3</td>          <td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></td>
366  </tr>  </tr>
367  <tr>  <tr>
368    <td width='150'></td>
369    <td width='150'></td>
370          <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>          <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>
371                  <img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16'><div id='server_cpu_usage_txt'>12%</div></td>                  <img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16' title='static dummy data'><div id='server_cpu_usage_txt'>12%</div></td>
372  <!--  
373          <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>          <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>
374                  <img id='server_memory_usage' src='usagebar.php?usage=81' width='102' height='16'><div id='server_memory_usage_txt'>4096/7912 MB</div></td>                  <img id='server_memory_usage' src='usagebar.php?usage=1' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>0/4 MB</div></td>
375  -->  <!--
376          <td width='150' align='right' class='small'><img src='gfx/icon-network.png'>          <td width='150' align='right' class='small'><img src='gfx/icon-network.png'>
377                  <img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_net_usage_txt'>1%</div></td>                  <img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16' title='static dummy data'><div id='server_net_usage_txt'>1%</div></td>
378          <td width='150' align='right' class='small'><img src='gfx/icon-disk.png'>          <td width='150' align='right' class='small'><img src='gfx/icon-disk.png'>
379                  <img id='server_disk_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_memory_usage_txt'>89.3/405.5 GB</div></td>                  <img id='server_disk_usage' src='usagebar.php?usage=41' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>89.3/405.5 GB</div></td>
   
380          </td>          </td>
381    -->
382  </tr></table>  </tr></table>
383    
384    
# Line 191  foreach($vms_array as $vm) { Line 391  foreach($vms_array as $vm) {
391          }          }
392    
393          $name = $vm["name_label"];          $name = $vm["name_label"];
394            $description = $vm["name_description"];
395          $uuid = $vm["uuid"];          $uuid = $vm["uuid"];
396          $state = $vm["power_state"] ;          $state = $vm["power_state"] ;
397          $memory = $vm['memory_target'];          $memory = $vm['memory_target'];
# Line 199  foreach($vms_array as $vm) { Line 400  foreach($vms_array as $vm) {
400    
401          $clean_name = str_replace(" ", "_", $name);          $clean_name = str_replace(" ", "_", $name);
402          $clean_name = str_replace(".", "_", $clean_name);          $clean_name = str_replace(".", "_", $clean_name);
403            $clean_name = str_replace("(", "_", $clean_name);
404            $clean_name = str_replace(")", "_", $clean_name);
405                    
406    
407          foreach ($vm["VBDs"] as $vbds) {          foreach ($vm["VBDs"] as $vbds) {
# Line 216  foreach($vms_array as $vm) { Line 419  foreach($vms_array as $vm) {
419          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>
420                  <tr background='gfx/vps_topbg.png'  >                  <tr background='gfx/vps_topbg.png'  >
421                          <td width='10' class='small state'>&nbsp;</td>                          <td width='10' class='small state'>&nbsp;</td>
422                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>                          <td colspan='2' class='small' title='<?php echo $description;?>'><b><?php echo $name; ?></b><span class='os'></span></td>
423                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
424                                  <span class='network'></span>                                  <span class='network'></span>
425                                    <a href='#' class='cd' uuid='<?php echo $uuid;?>' >
426                                            <img src='gfx/icon-cd.png' style='vertical-align: middle;'>
427                                    </a>
428                                  <a href='#' style='display:none;' class='console'>                                  <a href='#' style='display:none;' class='console'>
429                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
430                                  </a>                                  </a>
431                                    <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>
432                                            <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>
433                                    </a>
434                          </td>                          </td>
435                  </tr>                  </tr>
436    
# Line 231  foreach($vms_array as $vm) { Line 440  foreach($vms_array as $vm) {
440                  <td width='150' class='small'>                  <td width='150' class='small'>
441                          <span class="actionstop" style='display:none'>                          <span class="actionstop" style='display:none'>
442                                  start |                                  start |
443                                  <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>')" >stop</a> |                                  <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> |
444                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>')" >force shutdown</a>                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a>
445                          </span>                          </span>
446                                                    
447                          <span class="actionstart">                                                <span class="actionstart">                      
448                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>')" >start</a> |                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
449                                  stop |                                  stop |
450                                  force shutdown                                  force shutdown
451                          </span>                          </span>
452    
453                  </td>                  </td>
454    
455                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small' valign='top'>
456                            <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br>
457                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
458                          <span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>                          <span class='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
459                  </td>                  </td>
460                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
461                            <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br>
462                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
463                          <span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>                          <span class='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>
464                  </td>                  </td>
465  <!--  <!--
466                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
# Line 257  foreach($vms_array as $vm) { Line 468  foreach($vms_array as $vm) {
468                          <span id='vps_net_usage_txt_UID'>na</span>                          <span id='vps_net_usage_txt_UID'>na</span>
469                  </td>                  </td>
470  -->  -->
471                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small' valign='bottom'>
472                          <img src='gfx/icon-disk.png' style='vertical-align: middle;'>                          <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
473                          <span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span>                          <span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span>
474                  </td>                  </td>
475                  </tr>                  </tr>
476                    
477    
478          </table>          </table>
479          <!-- MACHINE END -->          <!-- MACHINE END -->
480    
481  <?PHP } ?>  <?PHP } ?>
482  </td></tr></table>  </td></tr></table>
483    
484    <br>
485    
486    <div style="display: none;">
487    
488    <div id="dialog-cd" title="Select CD">
489    
490            <table border=0>
491                    <tr>
492                            <td>Current: <span id="cdcurrent"></span></td>
493                    </tr>
494                    <tr>
495                            <td>
496                                    CD: <select id="cdselector"></select>
497                            </td>
498                    </tr>
499            </table>
500    </div>
501    
502    </div>
503    
504    <ul id="menu">
505            <li action="memory"><a href="#">Set Memory Size</a></li>
506            <li action="cpu"><a href="#">Set CPU Count</a></li>
507    
508    
509    <!--    <li><a href="#">Item 3</a>
510                    <ul>
511                            <li><a href="#">Item 3-1</a></li>
512                            <li><a href="#">Item 3-2</a></li>
513                            <li><a href="#">Item 3-3</a></li>
514                            <li><a href="#">Item 3-4</a></li>
515                            <li><a href="#">Item 3-5</a></li>
516                    </ul>
517            </li>
518            <li><a href="#">Item 4</a></li>
519            <li><a href="#">Item 5</a></li>-->
520    </ul>
521    
522  </body></html>  </body></html>
523    

Legend:
Removed from v.1885  
changed lines
  Added in v.2018

  ViewVC Help
Powered by ViewVC 1.1.20