/[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 1971 by torben, Tue Apr 16 15:21:10 2013 UTC revision 2105 by torben, Mon Feb 10 08:13:22 2014 UTC
# Line 1  Line 1 
1  <?php  <?php
2  include("config.php");  
3    if (! file_exists("config.php") ) {
4      die("Could not find config.php file");
5    }
6    
7    require("config.php");
8    
9  function format_memory($size) {  function format_memory($size) {
10    if (1024 > $size) {    if (1024 > $size) {
# Line 60  $namelabel = $host["name_label"]; Line 65  $namelabel = $host["name_label"];
65  var menu = 0;  var menu = 0;
66  var menu_uuid = '';  var menu_uuid = '';
67    
68    var user = "";
69    var password = "";
70    var loggedin = false;
71    
72    function isLoggedIn() {
73            if (loggedin == false) {
74                    alert("You need to login to perform this operation");
75            }
76            return loggedin;
77    }
78    
79    
80  $(document).ready( function() {  $(document).ready( function() {
81          $("#menu").hide();          $("#menu").hide();
82          setInterval(refreshData, 60000);                  setInterval(refreshData, 60000);        
# Line 71  $(document).ready( function() { Line 88  $(document).ready( function() {
88                  openConsole(conurl,session,name);                  openConsole(conurl,session,name);
89          });          });
90    
91            $('.bar').progressbar( );
92    
93          $('#logo').click( function() {          $('#logo').click( function() {
94                  refreshData();                  refreshData();
95          });          });
# Line 99  $(document).ready( function() { Line 118  $(document).ready( function() {
118                  event.stopPropagation();                  event.stopPropagation();
119          });          });
120    
121            $('.cd').click( function(event) {
122                    var uuid = $(this).attr('uuid');
123                    cdSelectorDialog(uuid);
124            });
125            $('#loginlink').click( function(event) {
126                    loginDialog();
127            });
128    
129          $(document).click( function(event) {          $(document).click( function(event) {
130                  closeMenu();                  closeMenu();
131          });          });
132            $('#dialog-login').keypress(function(e) {
133            if (e.keyCode == $.ui.keyCode.ENTER) {
134                            loginDialogSubmit();
135            }
136            });
137  });  });
138    
139    function loginDialog() {
140            $('#dialog-login').dialog({
141                    modal: true,
142                    height: 210,
143                    width: 350,
144                    buttons: {
145                            Login: loginDialogSubmit
146                    }
147            });
148    }
149    function loginDialogSubmit() {
150            var params = $('#loginform').serialize();
151    
152            $.get('login.php?' + params, function(data) {
153                    if (data == "OK") {
154                            loggedin = true;
155                            username = $('#username').val();
156                            password = $('#password').val();
157    
158                            $('#login').html("Logged in as <i>" + username + "</i>");
159                            refreshData();
160                    } else {
161                            alert(data);
162                    }
163                    $("#dialog-login").dialog( "close" );
164            });
165    }
166    
167    function cdSelectorDialog(uuid) {
168            if (isLoggedIn() == false)
169                    return;
170    
171            $('#cdselector').html('');
172            $('#cdselector').load( 'getisolist.php' );
173            var cddata;
174    
175            $.getJSON('getcdinfo.php?uuid=' + uuid, function(data) {
176                    cddata = data;
177                    if (data.ISO != '') {
178                            $('#cdcurrent').html(  data.ISO );
179                            $(":button:contains('Mount')").prop("disabled", true).addClass("ui-state-disabled");
180                    } else {
181                            $('#cdcurrent').html('<i>No ISO currently mounted</i>');
182                            $(":button:contains('Eject')").prop("disabled", true).addClass("ui-state-disabled");
183                    }
184            });
185            
186            $('#dialog-cd').dialog({
187                    modal: true,
188                    width: 800,
189                    height: 300,
190                    buttons: {
191                            Mount: function() {
192                                    $( this ).dialog( "close" );
193                                    var vdi = $("#cdselector").val();
194                                    cdAction("mount", cddata.VBD, vdi);
195                            },
196                            Eject: function() {
197                                    $( this ).dialog( "close" );
198                                    cdAction("eject", cddata.VBD, "");
199                            },
200                            Cancel: function() {
201                                    $( this ).dialog( "close" );
202                            }
203                            
204                    }
205            });
206    }
207    
208  function closeMenu() {  function closeMenu() {
209          if (menu > 0) {          if (menu > 0) {
210                  $("#menu").menu("destroy").hide();                  $("#menu").menu("destroy").hide();
# Line 118  function refreshData() { Line 218  function refreshData() {
218                  $(xml).find('host').each(function() {                  $(xml).find('host').each(function() {
219                          var memtotal = $(this).find('memtotal').text();                          var memtotal = $(this).find('memtotal').text();
220                          var memfree = $(this).find('memfree').text();                            var memfree = $(this).find('memfree').text();  
221                          var cpuavg = $(this).find('cpuavg').text();                          var cpuavg = $(this).find('cpuavg').text() * 1; // *1 is used to convert the string var to an int
222    
223                          memtotal = Math.round ( memtotal / (1024*1024) );                          memtotal = Math.round ( memtotal / (1024*1024) );
224                          memfree = Math.round ( memfree / (1024*1024) );                          memfree = Math.round ( memfree / (1024*1024) );
# Line 127  function refreshData() { Line 227  function refreshData() {
227    
228                          //alert(memused + ' ' + mem_percentage);                          //alert(memused + ' ' + mem_percentage);
229    
230                          $('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage);                          //$('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage);
231                            $('#server_memory_usage').progressbar( "value", mem_percentage );
232                          $('#server_memory_usage').attr('alt', mem_percentage + '%');                          $('#server_memory_usage').attr('alt', mem_percentage + '%');
233                          $('#server_memory_usage').attr('title', mem_percentage + '%');                          $('#server_memory_usage').attr('title', mem_percentage + '%');
234                          $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');                          $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');
235    
236    
237                          $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);                          //$('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);
238                            $('#server_cpu_usage').progressbar( "value", cpuavg );
239                          $('#server_cpu_usage').attr('alt', cpuavg + '%');                          $('#server_cpu_usage').attr('alt', cpuavg + '%');
240                          $('#server_cpu_usage').attr('title', cpuavg + '%');                          $('#server_cpu_usage').attr('title', cpuavg + '%');
241                          $('#server_cpu_usage_txt').text( cpuavg+ '%');                          $('#server_cpu_usage_txt').text( cpuavg+ '%');
# Line 179  function refreshData() { Line 281  function refreshData() {
281                                  vm.find('.console').data('session', session);                                  vm.find('.console').data('session', session);
282                                  vm.find('.console').data('name', name);                                  vm.find('.console').data('name', name);
283                                  vm.find('.settings').hide();                                  vm.find('.settings').hide();
284                                  vm.find('.actionstop').show();                                  if (loggedin) {
285                                  vm.find('.actionstart').hide();                                          vm.find('.actionstop').show();
286                                            vm.find('.actionstart').hide();
287                                    }
288                                  vm.find('.os').text(' - ' + os);                                  vm.find('.os').text(' - ' + os);
289    
290                                    cpuavg = cpuavg * 1;
291                                  vm.find('.cpu_graph').show();                                  vm.find('.cpu_graph').show();
292                                  vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);                                  //vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);
293                                    vm.find('.cpu_graph').progressbar( "value", cpuavg );
294                                  vm.find('.cpu_graph').attr('title',  cpuavg + '%');                                  vm.find('.cpu_graph').attr('title',  cpuavg + '%');
295    
296                                  vm.find('.mem_graph').show();                                  vm.find('.mem_graph').show();
297                                  vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);                                  //vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);
298                                    vm.find('.mem_graph').progressbar( "value", mempercent );
299                                  vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );                                  vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );
300                          } else {                          } else {
301                                  if (state == "Halted") {                                  if (state == "Halted") {
# Line 202  function refreshData() { Line 308  function refreshData() {
308                                  vm.find('.network').hide();                                  vm.find('.network').hide();
309                                  vm.find('.console').hide();                                  vm.find('.console').hide();
310                                  vm.find('.settings').show();                                  vm.find('.settings').show();
311                                  vm.find('.actionstop').hide();                                  if (loggedin) {
312                                  vm.find('.actionstart').show();                                          vm.find('.actionstop').hide();
313                                            vm.find('.actionstart').show();
314                                    }
315                                  vm.find('.cpu_graph').hide();                                  vm.find('.cpu_graph').hide();
316                                  vm.find('.mem_graph').hide();                                  vm.find('.mem_graph').hide();
317                          }                          }
318                            vm.find('.state').attr('title', state);
319                                                    
320                  });                  });
321                  $('#logo').show();                  $('#logo').show();
# Line 216  function refreshData() { Line 325  function refreshData() {
325  function doAction(action, uuid, vm) {  function doAction(action, uuid, vm) {
326          var val="";          var val="";
327    
328          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
329                  return;                  return;
330          }  
331          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
332          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
333    
# Line 237  function doAction(action, uuid, vm) { Line 345  function doAction(action, uuid, vm) {
345                  }                  }
346          }          }
347    
348          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;;          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + password + "&val=" + val;;
349          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
350                  if (data != 'OK') {                  if (data != 'OK') {
351                          alert(data);                          alert(data);
# Line 248  function doAction(action, uuid, vm) { Line 356  function doAction(action, uuid, vm) {
356          });          });
357  }  }
358    
359    function cdAction(action, vbd,vdi) {
360            if (isLoggedIn() == false)
361                    return;
362    
363            document.body.style.cursor = 'wait';
364            var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi;
365            var response = $.get(url, function(data) {
366                    if (data != 'OK') {
367                            alert(data);
368                    }
369                    document.body.style.cursor = 'default'
370            });
371            
372    }
373    
374  function openConsole(url, session, name) {  function openConsole(url, session, name) {
375          if (url == '')          if (url == '')
376                  return;                  return;
377    
378          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
379                  return;                  return;
380          }  
381          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + password + "&name=" + name;
382    
383          //window.location = url;          //window.location = url;
384          //$('#mainwindow').load(url);          //$('#mainwindow').load(url);
# Line 297  body { Line 419  body {
419          margin: 4;          margin: 4;
420          border: 1px solid #222;          border: 1px solid #222;
421  }  }
422    
423    .ui-progressbar-value {
424            background: #61B4F3;
425    }
426    
427    .ui-progressbar {
428            border-style:solid;
429            border-width:1px;
430            border-color: #666666;
431    }
432    
433    .bar {
434            width:  102px;
435            height:  16px;
436    }
437    
438  </style>  </style>
439  </head>  </head>
440  <body>  <body>
# Line 309  body { Line 447  body {
447          <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>
448  </tr>  </tr>
449  <tr>  <tr>
450    <td width='150'>
451            <span id="login" class='small'><i>Not <a href="#" id="loginlink">logged in</a></i>
452            </span>
453    </td>
454  <td width='150'></td>  <td width='150'></td>
455  <td width='150'></td>          <td width='150' align='right' class='small'>
456          <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>          <div id='server_cpu_usage' class='bar'></div>
457                  <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 src='gfx/icon-cpu.png'>
458                    <span id='server_cpu_usage_txt'>12%</span>
459            </td>
460    
461          <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>          <td width='150' align='right' class='small'>
462                  <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>          <div id='server_memory_usage' class='bar'></div>
463                    <img src='gfx/icon-memory.png'>
464                    <span id='server_memory_usage_txt'>0/4 MB</span>
465        </td>
466  <!--  <!--
467          <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'>
468                  <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>
# Line 366  foreach($vms_array as $vm) { Line 513  foreach($vms_array as $vm) {
513                          <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>
514                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
515                                  <span class='network'></span>                                  <span class='network'></span>
516                                    <a href='#' class='cd' uuid='<?php echo $uuid;?>' >
517                                            <img src='gfx/icon-cd.gif' style='vertical-align: middle;'></a>
518                                  <a href='#' style='display:none;' class='console'>                                  <a href='#' style='display:none;' class='console'>
519                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
520                                  </a>                                  </a>
521    
522                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>
523                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>
524                                  </a>                                  </a>
# Line 382  foreach($vms_array as $vm) { Line 532  foreach($vms_array as $vm) {
532                          <span class="actionstop" style='display:none'>                          <span class="actionstop" style='display:none'>
533                                  start |                                  start |
534                                  <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> |
535                                  <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> |
536                                    <a href='#' onclick="doAction('hardreboot','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force reboot</a>
537                          </span>                          </span>
538                                                    
539                          <span class="actionstart">                                                <span class="actionstart" style='display:none'>                
540                                  <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> |
541                                  stop |                                  stop |
542                                  force shutdown                                  force shutdown
# Line 394  foreach($vms_array as $vm) { Line 545  foreach($vms_array as $vm) {
545                  </td>                  </td>
546    
547                  <td width='100' align='right' class='small' valign='top'>                  <td width='100' align='right' class='small' valign='top'>
548                          <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br>                          <div class='cpu_graph bar'></div>
549                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
550                          <span class='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>                          <span class='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
551                  </td>                  </td>
552                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
553                          <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br>                          <div class='mem_graph bar'></div>
554                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
555                          <span class='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>                          <span class='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>
556                  </td>                  </td>
# Line 424  foreach($vms_array as $vm) { Line 575  foreach($vms_array as $vm) {
575    
576  <br>  <br>
577    
578    <div style="display: none;">
579    
580    <div id="dialog-login" title="Login">
581            <form id="loginform">
582            <table border="0">
583                    <tr>
584                            <td>Username: </td>
585                            <td><input type="text" id="username" name="username"></td>
586                    <tr>
587                    <tr>
588                            <td>Password: </td>
589                            <td><input type="password" id="password" name="password"></td>
590                    </tr>
591            </table>
592            </form>
593    </div>
594    
595    <div id="dialog-cd" title="Select CD">
596    
597            <table border=0>
598                    <tr>
599                            <td>Current: <span id="cdcurrent"></span></td>
600                    </tr>
601                    <tr>
602                            <td>
603                                    CD: <select id="cdselector"></select>
604                            </td>
605                    </tr>
606            </table>
607    </div>
608    
609    </div>
610    
611  <ul id="menu">  <ul id="menu">
612          <li action="memory"><a href="#">Set Memory Size</a></li>          <li action="memory"><a href="#">Set Memory Size</a></li>
613          <li action="cpu"><a href="#">Set CPU Count</a></li>          <li action="cpu"><a href="#">Set CPU Count</a></li>

Legend:
Removed from v.1971  
changed lines
  Added in v.2105

  ViewVC Help
Powered by ViewVC 1.1.20