/[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 1890 by torben, Sat Dec 1 16:17:13 2012 UTC revision 2025 by torben, Fri Jul 19 13:13:34 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 40  $license = "License: " . $host["license_ Line 40  $license = "License: " . $host["license_
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    var user = "";
64    var password = "";
65    var loggedin = false;
66    
67    function isLoggedIn() {
68            if (loggedin == false) {
69                    alert("You need to login to perform this operation");
70            }
71            return loggedin;
72    }
73    
74    
75  $(document).ready( function() {  $(document).ready( function() {
76            $("#menu").hide();
77          setInterval(refreshData, 60000);                  setInterval(refreshData, 60000);        
78          refreshData();          refreshData();
79          $('.console').click( function() {          $('.console').click( function() {
80                  var session = $(this).data('session');                  var session = $(this).data('session');
81                  var conurl = $(this).data('conurl');                  var conurl = $(this).data('conurl');
82                  console(conurl,session);                  var name = $(this).data('name');
83                    openConsole(conurl,session,name);
84          });          });
85    
86          $('#logo').click( function() {          $('#logo').click( function() {
87                  refreshData();                  refreshData();
88          });          });
89    
90            $('.settings').click( function(event) {
91                    menu_uuid = $(this).attr('uuid');
92    
93                    $('#menu').menu( {
94                            select: function(event2,ui) {
95                                            var action = $(ui.item).attr("action");
96                                            if (action == "memory") {
97                                                    doAction("setMemory", menu_uuid, "");  
98                                            }
99                                            if (action == "cpu") {
100                                                    doAction("setCPU", menu_uuid, "");      
101                                            }
102                                    },
103                            create: function(event3,ui) {
104                                    menu = 1;
105                                    }
106                            /*position: {
107                                    my: "left", of: event
108                            }*/
109                    });
110                    $('#menu').show().position( {my: "left top", of: event} );
111                    event.stopPropagation();
112            });
113    
114            $('.cd').click( function(event) {
115                    var uuid = $(this).attr('uuid');
116                    cdSelectorDialog(uuid);
117            });
118            $('#loginlink').click( function(event) {
119                    loginDialog();
120            });
121    
122            $(document).click( function(event) {
123                    closeMenu();
124            });
125            $('#dialog-login').keypress(function(e) {
126            if (e.keyCode == $.ui.keyCode.ENTER) {
127                            loginDialogSubmit();
128            }
129            });
130  });  });
131    
132    function loginDialog() {
133            $('#dialog-login').dialog({
134                    modal: true,
135                    height: 210,
136                    width: 325,
137                    buttons: {
138                            Login: loginDialogSubmit
139                    }
140            });
141    }
142    function loginDialogSubmit() {
143            var params = $('#loginform').serialize();
144    
145            $.get('login.php?' + params, function(data) {
146                    if (data == "OK") {
147                            loggedin = true;
148                            username = $('#username').val();
149                            password = $('#password').val();
150    
151                            $('#login').html("Logged in as <i>" + username + "</i>");
152                    } else {
153                            alert(data);
154                    }
155                    $("#dialog-login").dialog( "close" );
156            });
157    }
158    
159    function cdSelectorDialog(uuid) {
160            if (isLoggedIn() == false)
161                    return;
162    
163            $('#cdselector').html('');
164            $('#cdselector').load( 'getisolist.php' );
165            var cddata;
166    
167            $.getJSON('getcdinfo.php?uuid=' + uuid, function(data) {
168                    cddata = data;
169                    if (data.ISO != '') {
170                            $('#cdcurrent').html(  data.ISO );
171                    } else {
172                            $('#cdcurrent').html('<i>No ISO currently mounted</i>');
173                    }
174            });
175            
176            $('#dialog-cd').dialog({
177                    modal: true,
178                    width: 800,
179                    height: 300,
180                    buttons: {
181                            Mount: function() {
182                                    $( this ).dialog( "close" );
183                                    var vdi = $("#cdselector").val();
184                                    cdAction("mount", cddata.VBD, vdi);
185                            },
186                            Eject: function() {
187                                    $( this ).dialog( "close" );
188                                    cdAction("eject", cddata.VBD, "");
189                            },
190                            Cancel: function() {
191                                    $( this ).dialog( "close" );
192                            }
193                            
194                    }
195            });
196    }
197    
198    function closeMenu() {
199            if (menu > 0) {
200                    $("#menu").menu("destroy").hide();
201                    menu = 0;
202            }
203    }
204    
205  function refreshData() {  function refreshData() {
206            $("#logo").hide();      
207          $.get('ajaxdata.php', function(xml) {          $.get('ajaxdata.php', function(xml) {
208                  $(xml).find('host').each(function() {                  $(xml).find('host').each(function() {
209                          var memtotal = $(this).find('memtotal').text();                          var memtotal = $(this).find('memtotal').text();
210                          var memfree = $(this).find('memfree').text();                            var memfree = $(this).find('memfree').text();  
211                            var cpuavg = $(this).find('cpuavg').text();
212    
213                          memtotal = Math.round ( memtotal / (1024*1024) );                          memtotal = Math.round ( memtotal / (1024*1024) );
214                          memfree = Math.round ( memfree / (1024*1024) );                          memfree = Math.round ( memfree / (1024*1024) );
215                          var memused = memtotal - memfree;                          var memused = memtotal - memfree;
# Line 78  function refreshData() { Line 221  function refreshData() {
221                          $('#server_memory_usage').attr('alt', mem_percentage + '%');                          $('#server_memory_usage').attr('alt', mem_percentage + '%');
222                          $('#server_memory_usage').attr('title', mem_percentage + '%');                          $('#server_memory_usage').attr('title', mem_percentage + '%');
223                          $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');                          $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');
224    
225    
226                            $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);
227                            $('#server_cpu_usage').attr('alt', cpuavg + '%');
228                            $('#server_cpu_usage').attr('title', cpuavg + '%');
229                            $('#server_cpu_usage_txt').text( cpuavg+ '%');
230                  });                  });
231                  $(xml).find('vm').each(function() {                  $(xml).find('vm').each(function() {
232                          var name = $(this).find('name').text();                          var name = $(this).find('name').text();
# Line 87  function refreshData() { Line 236  function refreshData() {
236                          var conurl = $(this).find('conurl').text();                          var conurl = $(this).find('conurl').text();
237                          var session = $(this).find('session').text();                          var session = $(this).find('session').text();
238                          var os = $(this).find('os').text();                          var os = $(this).find('os').text();
239                            var guestversion = $(this).find('guestversion').text();
240                          name = name.replace(" ", "_");                          var cpuavg = $(this).find('cpuavg').text();
241                          name = name.replace(".", "_");                          var curmem = $(this).find('curmem').text();
242                            var maxmem = $(this).find('maxmem').text();
243                            var cpus = $(this).find('cpus').text();
244    
245                            var mempercent = Math.round( (curmem*100) / maxmem );
246    
247                            name = name.replace(/ /g, "_");
248                            name = name.replace(/\./g, "_");
249                            name = name.replace(/\(/g, "_");
250                            name = name.replace(/\)/g, "_");
251                                                    
252                          var id = "#vm_" + name;                          var id = "#vm_" + name;
253    
254                          var vm = $(id);                                          var vm = $(id);                
255    
256                            if (guestversion != '') {
257                                    os += ' Guest Tools: ' + guestversion;
258                            }
259    
260                            vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB");
261                            vm.find('.vps_cpu_usage_txt_UID').text( cpus + " VCPU");
262    
263                          if (state == "Running") {                          if (state == "Running") {
264                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");
265                                  vm.find('.network').show();                                  vm.find('.network').show();
# Line 102  function refreshData() { Line 267  function refreshData() {
267                                  vm.find('.console').show();                                  vm.find('.console').show();
268                                  vm.find('.console').data('conurl', conurl);                                  vm.find('.console').data('conurl', conurl);
269                                  vm.find('.console').data('session', session);                                  vm.find('.console').data('session', session);
270                                    vm.find('.console').data('name', name);
271                                    vm.find('.settings').hide();
272                                  vm.find('.actionstop').show();                                  vm.find('.actionstop').show();
273                                  vm.find('.actionstart').hide();                                  vm.find('.actionstart').hide();
274                                  vm.find('.os').text(' - ' + os);                                  vm.find('.os').text(' - ' + os);
275    
276    
277                                    vm.find('.cpu_graph').show();
278                                    vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);
279                                    vm.find('.cpu_graph').attr('title',  cpuavg + '%');
280    
281                                    vm.find('.mem_graph').show();
282                                    vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);
283                                    vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );
284                          } else {                          } else {
285                                  if (state == "Halted") {                                  if (state == "Halted") {
286                                          vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");                                          vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");
287                                  } else {                                  } else {
288                                          vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");                                          vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
289                                  }                                  }
290                                    vm.find('.os').text('');
291    
292                                  vm.find('.network').hide();                                  vm.find('.network').hide();
293                                  vm.find('.console').hide();                                  vm.find('.console').hide();
294                                    vm.find('.settings').show();
295                                  vm.find('.actionstop').hide();                                  vm.find('.actionstop').hide();
296                                  vm.find('.actionstart').show();                                  vm.find('.actionstart').show();
297                                    vm.find('.cpu_graph').hide();
298                                    vm.find('.mem_graph').hide();
299                          }                          }
300                                                    
301                  })                  });
302                    $('#logo').show();
303         });         });
304  }  }
305    
306  function doAction(action, uuid, vm) {  function doAction(action, uuid, vm) {
307          var key = prompt("Key");          var val="";
308          if (key == "" || key == null) {  
309            if (isLoggedIn() == false)
310                  return;                  return;
311          }  
312          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
313          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
314    
315          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;          if (action == "setMemory") {
316                    val = prompt("Set memory target");
317                    val *= (1024*1024);
318                    if (val == "" || val == null) {
319                            return;
320                    }
321            }
322            if (action == "setCPU") {
323                    val = prompt("Set CPU count");
324                    if (val == "" || val == null) {
325                            return;
326                    }
327            }
328    
329            var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + password + "&val=" + val;;
330          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
331                  if (data != 'OK') {                  if (data != 'OK') {
332                          alert(data);                          alert(data);
# Line 140  function doAction(action, uuid, vm) { Line 337  function doAction(action, uuid, vm) {
337          });          });
338  }  }
339    
340  function console(url, session) {  function cdAction(action, vbd,vdi) {
341            if (isLoggedIn() == false)
342                    return;
343    
344            document.body.style.cursor = 'wait';
345            var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi;
346            var response = $.get(url, function(data) {
347                    if (data != 'OK') {
348                            alert(data);
349                    }
350                    document.body.style.cursor = 'default'
351            });
352            
353    }
354    
355    function openConsole(url, session, name) {
356          if (url == '')          if (url == '')
357                  return;                  return;
358    
359          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
360                  return;                  return;
361          }  
362          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + password + "&name=" + name;
363    
364          //window.location = url;          //window.location = url;
365          //$('#mainwindow').load(url);          //$('#mainwindow').load(url);
# Line 198  body { Line 409  body {
409  <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'>
410  <tr>  <tr>
411          <td rowspan='2' width='160'><img src='gfx/citrix-logo.png' id='logo'></td>          <td rowspan='2' width='160'><img src='gfx/citrix-logo.png' id='logo'></td>
412          <td colspan='4' class='small' align='right'><?php echo $xenversion;?><br><?php echo $license;?></td>          <td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></td>
413  </tr>  </tr>
414  <tr>  <tr>
415    <td width='150'>
416            <span id="login" class='small'><i>Not <a href="#" id="loginlink">logged in</a></i>
417            </span>
418    </td>
419    <td width='150'></td>
420          <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'>
421                  <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>
422    
423          <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'>
424                  <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>
425    <!--
426          <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'>
427                  <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>
428          <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'>
429                  <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>
   
430          </td>          </td>
431    -->
432  </tr></table>  </tr></table>
433    
434    
# Line 225  foreach($vms_array as $vm) { Line 441  foreach($vms_array as $vm) {
441          }          }
442    
443          $name = $vm["name_label"];          $name = $vm["name_label"];
444            $description = $vm["name_description"];
445          $uuid = $vm["uuid"];          $uuid = $vm["uuid"];
446          $state = $vm["power_state"] ;          $state = $vm["power_state"] ;
447          $memory = $vm['memory_target'];          $memory = $vm['memory_target'];
# Line 233  foreach($vms_array as $vm) { Line 450  foreach($vms_array as $vm) {
450    
451          $clean_name = str_replace(" ", "_", $name);          $clean_name = str_replace(" ", "_", $name);
452          $clean_name = str_replace(".", "_", $clean_name);          $clean_name = str_replace(".", "_", $clean_name);
453            $clean_name = str_replace("(", "_", $clean_name);
454            $clean_name = str_replace(")", "_", $clean_name);
455                    
456    
457          foreach ($vm["VBDs"] as $vbds) {          foreach ($vm["VBDs"] as $vbds) {
# Line 250  foreach($vms_array as $vm) { Line 469  foreach($vms_array as $vm) {
469          <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;?>'>
470                  <tr background='gfx/vps_topbg.png'  >                  <tr background='gfx/vps_topbg.png'  >
471                          <td width='10' class='small state'>&nbsp;</td>                          <td width='10' class='small state'>&nbsp;</td>
472                          <td colspan='2' 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>
473                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
474                                  <span class='network'></span>                                  <span class='network'></span>
475                                    <a href='#' class='cd' uuid='<?php echo $uuid;?>' >
476                                            <img src='gfx/icon-cd.gif' style='vertical-align: middle;'></a>
477                                  <a href='#' style='display:none;' class='console'>                                  <a href='#' style='display:none;' class='console'>
478                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
479                                  </a>                                  </a>
480    
481                                    <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>
482                                            <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>
483                                    </a>
484                          </td>                          </td>
485                  </tr>                  </tr>
486    
# Line 277  foreach($vms_array as $vm) { Line 502  foreach($vms_array as $vm) {
502    
503                  </td>                  </td>
504    
505                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small' valign='top'>
506                            <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br>
507                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
508                          <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>
509                  </td>                  </td>
510                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
511                            <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br>
512                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
513                          <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>
514                  </td>                  </td>
515  <!--  <!--
516                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
# Line 291  foreach($vms_array as $vm) { Line 518  foreach($vms_array as $vm) {
518                          <span id='vps_net_usage_txt_UID'>na</span>                          <span id='vps_net_usage_txt_UID'>na</span>
519                  </td>                  </td>
520  -->  -->
521                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small' valign='bottom'>
522                          <img src='gfx/icon-disk.png' style='vertical-align: middle;'>                          <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
523                          <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>
524                  </td>                  </td>
525                  </tr>                  </tr>
526                    
527    
528          </table>          </table>
529          <!-- MACHINE END -->          <!-- MACHINE END -->
530    
531  <?PHP } ?>  <?PHP } ?>
532  </td></tr></table>  </td></tr></table>
533    
534    <br>
535    
536    <div style="display: none;">
537    
538    <div id="dialog-login" title="Login">
539            <form id="loginform">
540            <table border="0">
541                    <tr>
542                            <td>Username: </td>
543                            <td><input type="text" id="username" name="username"></td>
544                    <tr>
545                    <tr>
546                            <td>Password: </td>
547                            <td><input type="password" id="password" name="password"></td>
548                    </tr>
549            </table>
550            </form>
551    </div>
552    
553    <div id="dialog-cd" title="Select CD">
554    
555            <table border=0>
556                    <tr>
557                            <td>Current: <span id="cdcurrent"></span></td>
558                    </tr>
559                    <tr>
560                            <td>
561                                    CD: <select id="cdselector"></select>
562                            </td>
563                    </tr>
564            </table>
565    </div>
566    
567    </div>
568    
569    <ul id="menu">
570            <li action="memory"><a href="#">Set Memory Size</a></li>
571            <li action="cpu"><a href="#">Set CPU Count</a></li>
572    
573    
574    <!--    <li><a href="#">Item 3</a>
575                    <ul>
576                            <li><a href="#">Item 3-1</a></li>
577                            <li><a href="#">Item 3-2</a></li>
578                            <li><a href="#">Item 3-3</a></li>
579                            <li><a href="#">Item 3-4</a></li>
580                            <li><a href="#">Item 3-5</a></li>
581                    </ul>
582            </li>
583            <li><a href="#">Item 4</a></li>
584            <li><a href="#">Item 5</a></li>-->
585    </ul>
586    
587  </body></html>  </body></html>
588    

Legend:
Removed from v.1890  
changed lines
  Added in v.2025

  ViewVC Help
Powered by ViewVC 1.1.20