/[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 1898 by torben, Mon Dec 10 12:40:58 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 46  $namelabel = $host["name_label"]; Line 46  $namelabel = $host["name_label"];
46  <html>  <html>
47  <head>  <head>
48  <title>XenServer::<?php echo $namelabel;?></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() {          $('#logo').click( function() {
75                  refreshData();                  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();                $("#logo").hide();      
157          $.get('ajaxdata.php', function(xml) {          $.get('ajaxdata.php', function(xml) {
# Line 101  function refreshData() { Line 190  function refreshData() {
190                          var cpuavg = $(this).find('cpuavg').text();                          var cpuavg = $(this).find('cpuavg').text();
191                          var curmem = $(this).find('curmem').text();                          var curmem = $(this).find('curmem').text();
192                          var maxmem = $(this).find('maxmem').text();                          var maxmem = $(this).find('maxmem').text();
193                            var cpus = $(this).find('cpus').text();
194    
195                          var mempercent = Math.round( (curmem*100) / maxmem );                          var mempercent = Math.round( (curmem*100) / maxmem );
196    
197                          name = name.replace(" ", "_");                          name = name.replace(/ /g, "_");
198                          name = name.replace(".", "_");                          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    
# Line 115  function refreshData() { Line 207  function refreshData() {
207                                  os += ' Guest Tools: ' + guestversion;                                  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 122  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);                                  vm.find('.os').text(' - ' + os);
# Line 140  function refreshData() { Line 237  function refreshData() {
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();                                  vm.find('.cpu_graph').hide();
# Line 154  function refreshData() { Line 254  function refreshData() {
254  }  }
255    
256  function doAction(action, uuid, vm) {  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;
# Line 161  function doAction(action, uuid, vm) { Line 263  function doAction(action, uuid, vm) {
263          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
264          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");          $('#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                  if (data != 'OK') {                  if (data != 'OK') {
283                          alert(data);                          alert(data);
# Line 172  function doAction(action, uuid, vm) { Line 288  function doAction(action, uuid, vm) {
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 180  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 233  body { Line 365  body {
365          <td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></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' title='static dummy data'><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=1' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>0/4 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' title='static dummy data'><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' title='static dummy data'><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 257  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 265  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 282  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='3' class='small'><b><?php echo $name; ?></b><span class='os'></span></td>                          <td colspan='2' class='small' title='<?php echo $description;?>'><b><?php echo $name; ?></b><span class='os'></span></td>
423                          <td colspan='1' 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 312  foreach($vms_array as $vm) { Line 455  foreach($vms_array as $vm) {
455                  <td width='100' align='right' class='small' valign='top'>                  <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>                          <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>                          <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 337  foreach($vms_array as $vm) { Line 480  foreach($vms_array as $vm) {
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.1898  
changed lines
  Added in v.2018

  ViewVC Help
Powered by ViewVC 1.1.20