/[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 2018 by torben, Thu Jul 18 13:00:14 2013 UTC revision 2069 by torben, Thu Nov 7 21:27:15 2013 UTC
# Line 60  $namelabel = $host["name_label"]; Line 60  $namelabel = $host["name_label"];
60  var menu = 0;  var menu = 0;
61  var menu_uuid = '';  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();          $("#menu").hide();
77          setInterval(refreshData, 60000);                  setInterval(refreshData, 60000);        
# Line 71  $(document).ready( function() { Line 83  $(document).ready( function() {
83                  openConsole(conurl,session,name);                  openConsole(conurl,session,name);
84          });          });
85    
86            $('.bar').progressbar( );
87    
88          $('#logo').click( function() {          $('#logo').click( function() {
89                  refreshData();                  refreshData();
90          });          });
# Line 103  $(document).ready( function() { Line 117  $(document).ready( function() {
117                  var uuid = $(this).attr('uuid');                  var uuid = $(this).attr('uuid');
118                  cdSelectorDialog(uuid);                  cdSelectorDialog(uuid);
119          });          });
120            $('#loginlink').click( function(event) {
121                    loginDialog();
122            });
123    
124          $(document).click( function(event) {          $(document).click( function(event) {
125                  closeMenu();                  closeMenu();
126          });          });
127            $('#dialog-login').keypress(function(e) {
128            if (e.keyCode == $.ui.keyCode.ENTER) {
129                            loginDialogSubmit();
130            }
131            });
132  });  });
133    
134    function loginDialog() {
135            $('#dialog-login').dialog({
136                    modal: true,
137                    height: 210,
138                    width: 350,
139                    buttons: {
140                            Login: loginDialogSubmit
141                    }
142            });
143    }
144    function loginDialogSubmit() {
145            var params = $('#loginform').serialize();
146    
147            $.get('login.php?' + params, function(data) {
148                    if (data == "OK") {
149                            loggedin = true;
150                            username = $('#username').val();
151                            password = $('#password').val();
152    
153                            $('#login').html("Logged in as <i>" + username + "</i>");
154                            refreshData();
155                    } else {
156                            alert(data);
157                    }
158                    $("#dialog-login").dialog( "close" );
159            });
160    }
161    
162  function cdSelectorDialog(uuid) {  function cdSelectorDialog(uuid) {
163            if (isLoggedIn() == false)
164                    return;
165    
166          $('#cdselector').html('');          $('#cdselector').html('');
167          $('#cdselector').load( 'getisolist.php' );          $('#cdselector').load( 'getisolist.php' );
168          var cddata;          var cddata;
# Line 118  function cdSelectorDialog(uuid) { Line 171  function cdSelectorDialog(uuid) {
171                  cddata = data;                  cddata = data;
172                  if (data.ISO != '') {                  if (data.ISO != '') {
173                          $('#cdcurrent').html(  data.ISO );                          $('#cdcurrent').html(  data.ISO );
174                            $(":button:contains('Mount')").prop("disabled", true).addClass("ui-state-disabled");
175                  } else {                  } else {
176                          $('#cdcurrent').html('<i>No ISO currently mounted</i>');                          $('#cdcurrent').html('<i>No ISO currently mounted</i>');
177                            $(":button:contains('Eject')").prop("disabled", true).addClass("ui-state-disabled");
178                  }                  }
179          });          });
180                    
# Line 158  function refreshData() { Line 213  function refreshData() {
213                  $(xml).find('host').each(function() {                  $(xml).find('host').each(function() {
214                          var memtotal = $(this).find('memtotal').text();                          var memtotal = $(this).find('memtotal').text();
215                          var memfree = $(this).find('memfree').text();                            var memfree = $(this).find('memfree').text();  
216                          var cpuavg = $(this).find('cpuavg').text();                          var cpuavg = $(this).find('cpuavg').text() * 1; // *1 is used to convert the string var to an int
217    
218                          memtotal = Math.round ( memtotal / (1024*1024) );                          memtotal = Math.round ( memtotal / (1024*1024) );
219                          memfree = Math.round ( memfree / (1024*1024) );                          memfree = Math.round ( memfree / (1024*1024) );
# Line 167  function refreshData() { Line 222  function refreshData() {
222    
223                          //alert(memused + ' ' + mem_percentage);                          //alert(memused + ' ' + mem_percentage);
224    
225                          $('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage);                          //$('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage);
226                            $('#server_memory_usage').progressbar( "value", mem_percentage );
227                          $('#server_memory_usage').attr('alt', mem_percentage + '%');                          $('#server_memory_usage').attr('alt', mem_percentage + '%');
228                          $('#server_memory_usage').attr('title', mem_percentage + '%');                          $('#server_memory_usage').attr('title', mem_percentage + '%');
229                          $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');                          $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');
230    
231    
232                          $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);                          //$('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);
233                            $('#server_cpu_usage').progressbar( "value", cpuavg );
234                          $('#server_cpu_usage').attr('alt', cpuavg + '%');                          $('#server_cpu_usage').attr('alt', cpuavg + '%');
235                          $('#server_cpu_usage').attr('title', cpuavg + '%');                          $('#server_cpu_usage').attr('title', cpuavg + '%');
236                          $('#server_cpu_usage_txt').text( cpuavg+ '%');                          $('#server_cpu_usage_txt').text( cpuavg+ '%');
# Line 219  function refreshData() { Line 276  function refreshData() {
276                                  vm.find('.console').data('session', session);                                  vm.find('.console').data('session', session);
277                                  vm.find('.console').data('name', name);                                  vm.find('.console').data('name', name);
278                                  vm.find('.settings').hide();                                  vm.find('.settings').hide();
279                                  vm.find('.actionstop').show();                                  if (loggedin) {
280                                  vm.find('.actionstart').hide();                                          vm.find('.actionstop').show();
281                                            vm.find('.actionstart').hide();
282                                    }
283                                  vm.find('.os').text(' - ' + os);                                  vm.find('.os').text(' - ' + os);
284    
285                                    cpuavg = cpuavg * 1;
286                                  vm.find('.cpu_graph').show();                                  vm.find('.cpu_graph').show();
287                                  vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);                                  //vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);
288                                    vm.find('.cpu_graph').progressbar( "value", cpuavg );
289                                  vm.find('.cpu_graph').attr('title',  cpuavg + '%');                                  vm.find('.cpu_graph').attr('title',  cpuavg + '%');
290    
291                                  vm.find('.mem_graph').show();                                  vm.find('.mem_graph').show();
292                                  vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);                                  //vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);
293                                    vm.find('.mem_graph').progressbar( "value", mempercent );
294                                  vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );                                  vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );
295                          } else {                          } else {
296                                  if (state == "Halted") {                                  if (state == "Halted") {
# Line 242  function refreshData() { Line 303  function refreshData() {
303                                  vm.find('.network').hide();                                  vm.find('.network').hide();
304                                  vm.find('.console').hide();                                  vm.find('.console').hide();
305                                  vm.find('.settings').show();                                  vm.find('.settings').show();
306                                  vm.find('.actionstop').hide();                                  if (loggedin) {
307                                  vm.find('.actionstart').show();                                          vm.find('.actionstop').hide();
308                                            vm.find('.actionstart').show();
309                                    }
310                                  vm.find('.cpu_graph').hide();                                  vm.find('.cpu_graph').hide();
311                                  vm.find('.mem_graph').hide();                                  vm.find('.mem_graph').hide();
312                          }                          }
# Line 256  function refreshData() { Line 319  function refreshData() {
319  function doAction(action, uuid, vm) {  function doAction(action, uuid, vm) {
320          var val="";          var val="";
321    
322          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
323                  return;                  return;
324          }  
325          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
326          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
327    
# Line 277  function doAction(action, uuid, vm) { Line 339  function doAction(action, uuid, vm) {
339                  }                  }
340          }          }
341    
342          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;;          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + password + "&val=" + val;;
343          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
344                  if (data != 'OK') {                  if (data != 'OK') {
345                          alert(data);                          alert(data);
# Line 289  function doAction(action, uuid, vm) { Line 351  function doAction(action, uuid, vm) {
351  }  }
352    
353  function cdAction(action, vbd,vdi) {  function cdAction(action, vbd,vdi) {
354          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
355                  return;                  return;
356          }  
357          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
358          var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + key + "&VDI=" + vdi;          var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi;
359          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
360                  if (data != 'OK') {                  if (data != 'OK') {
361                          alert(data);                          alert(data);
# Line 308  function openConsole(url, session, name) Line 369  function openConsole(url, session, name)
369          if (url == '')          if (url == '')
370                  return;                  return;
371    
372          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
373                  return;                  return;
374          }  
375          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + password + "&name=" + name;
376    
377          //window.location = url;          //window.location = url;
378          //$('#mainwindow').load(url);          //$('#mainwindow').load(url);
# Line 353  body { Line 413  body {
413          margin: 4;          margin: 4;
414          border: 1px solid #222;          border: 1px solid #222;
415  }  }
416    
417    .ui-progressbar-value {
418            background: #61B4F3;
419    }
420    
421    .ui-progressbar {
422            border-style:solid;
423            border-width:1px;
424            border-color: #666666;
425    }
426    
427    .bar {
428            width:  102px;
429            height:  16px;
430    }
431    
432  </style>  </style>
433  </head>  </head>
434  <body>  <body>
# Line 365  body { Line 441  body {
441          <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>
442  </tr>  </tr>
443  <tr>  <tr>
444    <td width='150'>
445            <span id="login" class='small'><i>Not <a href="#" id="loginlink">logged in</a></i>
446            </span>
447    </td>
448  <td width='150'></td>  <td width='150'></td>
449  <td width='150'></td>          <td width='150' align='right' class='small'>
450          <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>          <div id='server_cpu_usage' class='bar'></div>
451                  <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'>
452                    <span id='server_cpu_usage_txt'>12%</span>
453            </td>
454    
455          <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>          <td width='150' align='right' class='small'>
456                  <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>
457                    <img src='gfx/icon-memory.png'>
458                    <span id='server_memory_usage_txt'>0/4 MB</span>
459        </td>
460  <!--  <!--
461          <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'>
462                  <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 423  foreach($vms_array as $vm) { Line 508  foreach($vms_array as $vm) {
508                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
509                                  <span class='network'></span>                                  <span class='network'></span>
510                                  <a href='#' class='cd' uuid='<?php echo $uuid;?>' >                                  <a href='#' class='cd' uuid='<?php echo $uuid;?>' >
511                                          <img src='gfx/icon-cd.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-cd.gif' style='vertical-align: middle;'></a>
                                 </a>  
512                                  <a href='#' style='display:none;' class='console'>                                  <a href='#' style='display:none;' class='console'>
513                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
514                                  </a>                                  </a>
515    
516                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>
517                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>
518                                  </a>                                  </a>
# Line 441  foreach($vms_array as $vm) { Line 526  foreach($vms_array as $vm) {
526                          <span class="actionstop" style='display:none'>                          <span class="actionstop" style='display:none'>
527                                  start |                                  start |
528                                  <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> |
529                                  <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> |
530                                    <a href='#' onclick="doAction('hardreboot','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force reboot</a>
531                          </span>                          </span>
532                                                    
533                          <span class="actionstart">                                                <span class="actionstart" style='display:none'>                
534                                  <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> |
535                                  stop |                                  stop |
536                                  force shutdown                                  force shutdown
# Line 453  foreach($vms_array as $vm) { Line 539  foreach($vms_array as $vm) {
539                  </td>                  </td>
540    
541                  <td width='100' align='right' class='small' valign='top'>                  <td width='100' align='right' class='small' valign='top'>
542                          <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br>                          <div class='cpu_graph bar'></div>
543                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
544                          <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>
545                  </td>                  </td>
546                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
547                          <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br>                          <div class='mem_graph bar'></div>
548                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
549                          <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>
550                  </td>                  </td>
# Line 485  foreach($vms_array as $vm) { Line 571  foreach($vms_array as $vm) {
571    
572  <div style="display: none;">  <div style="display: none;">
573    
574    <div id="dialog-login" title="Login">
575            <form id="loginform">
576            <table border="0">
577                    <tr>
578                            <td>Username: </td>
579                            <td><input type="text" id="username" name="username"></td>
580                    <tr>
581                    <tr>
582                            <td>Password: </td>
583                            <td><input type="password" id="password" name="password"></td>
584                    </tr>
585            </table>
586            </form>
587    </div>
588    
589  <div id="dialog-cd" title="Select CD">  <div id="dialog-cd" title="Select CD">
590    
591          <table border=0>          <table border=0>

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

  ViewVC Help
Powered by ViewVC 1.1.20