/[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 1955 by torben, Mon Mar 25 20:27:58 2013 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 48  $namelabel = $host["name_label"]; Line 48  $namelabel = $host["name_label"];
48  <title>XenServer::<?php echo $namelabel;?></title>  <title>XenServer::<?php echo $namelabel;?></title>
49    
50  <link rel="stylesheet" type="text/css" href="jquery/theme/jquery-ui.css">  <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>  <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>  <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                  var name = $(this).data('name');                  var name = $(this).data('name');
71                  console(conurl,session,name);                  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 106  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 121  function refreshData() { Line 208  function refreshData() {
208                          }                          }
209    
210                          vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB");                          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')");
# Line 130  function refreshData() { Line 218  function refreshData() {
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);                                  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 152  function refreshData() { Line 241  function refreshData() {
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 175  function doAction(action, uuid, vm) { Line 265  function doAction(action, uuid, vm) {
265    
266          if (action == "setMemory") {          if (action == "setMemory") {
267                  val = prompt("Set memory target");                  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) {                  if (val == "" || val == null) {
                         alert("" + val);  
276                          return;                          return;
277                  }                  }
278          }          }
# Line 192  function doAction(action, uuid, vm) { Line 288  function doAction(action, uuid, vm) {
288          });          });
289  }  }
290    
291  function console(url, session, name) {  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 288  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 308  foreach($vms_array as $vm) { Line 422  foreach($vms_array as $vm) {
422                          <td colspan='2' class='small' title='<?php echo $description;?>'><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='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 321  foreach($vms_array as $vm) { Line 441  foreach($vms_array as $vm) {
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;?>','<?php echo $clean_name;?>')" >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;?>','<?php echo $clean_name;?>')" >force shutdown</a> |                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a>
                                 set memory  
445                          </span>                          </span>
446                                                    
447                          <span class="actionstart">                                                <span class="actionstart">                      
448                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
449                                  stop |                                  stop |
450                                  force shutdown |                                  force shutdown
   
                                 <a href='#' onclick="doAction('setMemory','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >set memory</a>  
451                          </span>                          </span>
452    
453                  </td>                  </td>
# Line 338  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>
# Line 363  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.1955  
changed lines
  Added in v.2018

  ViewVC Help
Powered by ViewVC 1.1.20