/[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 1958 by torben, Tue Mar 26 13:43:07 2013 UTC revision 2028 by torben, Tue Jul 23 15:30:12 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 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 99  $(document).ready( function() { Line 111  $(document).ready( function() {
111                  event.stopPropagation();                  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) {          $(document).click( function(event) {
123                  closeMenu();                  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: 350,
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                            refreshData();
153                    } else {
154                            alert(data);
155                    }
156                    $("#dialog-login").dialog( "close" );
157            });
158    }
159    
160    function cdSelectorDialog(uuid) {
161            if (isLoggedIn() == false)
162                    return;
163    
164            $('#cdselector').html('');
165            $('#cdselector').load( 'getisolist.php' );
166            var cddata;
167    
168            $.getJSON('getcdinfo.php?uuid=' + uuid, function(data) {
169                    cddata = data;
170                    if (data.ISO != '') {
171                            $('#cdcurrent').html(  data.ISO );
172                            $(":button:contains('Mount')").prop("disabled", true).addClass("ui-state-disabled");
173                    } else {
174                            $('#cdcurrent').html('<i>No ISO currently mounted</i>');
175                            $(":button:contains('Eject')").prop("disabled", true).addClass("ui-state-disabled");
176                    }
177            });
178            
179            $('#dialog-cd').dialog({
180                    modal: true,
181                    width: 800,
182                    height: 300,
183                    buttons: {
184                            Mount: function() {
185                                    $( this ).dialog( "close" );
186                                    var vdi = $("#cdselector").val();
187                                    cdAction("mount", cddata.VBD, vdi);
188                            },
189                            Eject: function() {
190                                    $( this ).dialog( "close" );
191                                    cdAction("eject", cddata.VBD, "");
192                            },
193                            Cancel: function() {
194                                    $( this ).dialog( "close" );
195                            }
196                            
197                    }
198            });
199    }
200    
201  function closeMenu() {  function closeMenu() {
202          if (menu > 0) {          if (menu > 0) {
203                  $("#menu").menu("destroy").hide();                  $("#menu").menu("destroy").hide();
# Line 154  function refreshData() { Line 247  function refreshData() {
247    
248                          var mempercent = Math.round( (curmem*100) / maxmem );                          var mempercent = Math.round( (curmem*100) / maxmem );
249    
250                          name = name.replace(" ", "_");                          name = name.replace(/ /g, "_");
251                          name = name.replace(".", "_");                          name = name.replace(/\./g, "_");
252                            name = name.replace(/\(/g, "_");
253                            name = name.replace(/\)/g, "_");
254                                                    
255                          var id = "#vm_" + name;                          var id = "#vm_" + name;
256    
# Line 177  function refreshData() { Line 272  function refreshData() {
272                                  vm.find('.console').data('session', session);                                  vm.find('.console').data('session', session);
273                                  vm.find('.console').data('name', name);                                  vm.find('.console').data('name', name);
274                                  vm.find('.settings').hide();                                  vm.find('.settings').hide();
275                                  vm.find('.actionstop').show();                                  if (loggedin) {
276                                  vm.find('.actionstart').hide();                                          vm.find('.actionstop').show();
277                                            vm.find('.actionstart').hide();
278                                    }
279                                  vm.find('.os').text(' - ' + os);                                  vm.find('.os').text(' - ' + os);
280    
281    
# Line 200  function refreshData() { Line 297  function refreshData() {
297                                  vm.find('.network').hide();                                  vm.find('.network').hide();
298                                  vm.find('.console').hide();                                  vm.find('.console').hide();
299                                  vm.find('.settings').show();                                  vm.find('.settings').show();
300                                  vm.find('.actionstop').hide();                                  if (loggedin) {
301                                  vm.find('.actionstart').show();                                          vm.find('.actionstop').hide();
302                                            vm.find('.actionstart').show();
303                                    }
304                                  vm.find('.cpu_graph').hide();                                  vm.find('.cpu_graph').hide();
305                                  vm.find('.mem_graph').hide();                                  vm.find('.mem_graph').hide();
306                          }                          }
# Line 214  function refreshData() { Line 313  function refreshData() {
313  function doAction(action, uuid, vm) {  function doAction(action, uuid, vm) {
314          var val="";          var val="";
315    
316          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
317                  return;                  return;
318          }  
319          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
320          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
321    
322          if (action == "setMemory") {          if (action == "setMemory") {
323                  val = prompt("Set memory target");                  val = prompt("Set memory target");
324                    val *= (1024*1024);
325                  if (val == "" || val == null) {                  if (val == "" || val == null) {
326                          return;                          return;
327                  }                  }
# Line 234  function doAction(action, uuid, vm) { Line 333  function doAction(action, uuid, vm) {
333                  }                  }
334          }          }
335    
336          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;;          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + password + "&val=" + val;;
337          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
338                  if (data != 'OK') {                  if (data != 'OK') {
339                          alert(data);                          alert(data);
# Line 245  function doAction(action, uuid, vm) { Line 344  function doAction(action, uuid, vm) {
344          });          });
345  }  }
346    
347    function cdAction(action, vbd,vdi) {
348            if (isLoggedIn() == false)
349                    return;
350    
351            document.body.style.cursor = 'wait';
352            var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi;
353            var response = $.get(url, function(data) {
354                    if (data != 'OK') {
355                            alert(data);
356                    }
357                    document.body.style.cursor = 'default'
358            });
359            
360    }
361    
362  function openConsole(url, session, name) {  function openConsole(url, session, name) {
363          if (url == '')          if (url == '')
364                  return;                  return;
365    
366          var key = prompt("Key");          if (isLoggedIn() == false)
         if (key == "" || key == null) {  
367                  return;                  return;
368          }  
369          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + password + "&name=" + name;
370    
371          //window.location = url;          //window.location = url;
372          //$('#mainwindow').load(url);          //$('#mainwindow').load(url);
# Line 306  body { Line 419  body {
419          <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>
420  </tr>  </tr>
421  <tr>  <tr>
422  <td width='150'></td>  <td width='150'>
423            <span id="login" class='small'><i>Not <a href="#" id="loginlink">logged in</a></i>
424            </span>
425    </td>
426  <td width='150'></td>  <td width='150'></td>
427          <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'>
428                  <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>
# Line 341  foreach($vms_array as $vm) { Line 457  foreach($vms_array as $vm) {
457    
458          $clean_name = str_replace(" ", "_", $name);          $clean_name = str_replace(" ", "_", $name);
459          $clean_name = str_replace(".", "_", $clean_name);          $clean_name = str_replace(".", "_", $clean_name);
460            $clean_name = str_replace("(", "_", $clean_name);
461            $clean_name = str_replace(")", "_", $clean_name);
462                    
463    
464          foreach ($vm["VBDs"] as $vbds) {          foreach ($vm["VBDs"] as $vbds) {
# Line 361  foreach($vms_array as $vm) { Line 479  foreach($vms_array as $vm) {
479                          <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>
480                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
481                                  <span class='network'></span>                                  <span class='network'></span>
482                                    <a href='#' class='cd' uuid='<?php echo $uuid;?>' >
483                                            <img src='gfx/icon-cd.gif' style='vertical-align: middle;'></a>
484                                  <a href='#' style='display:none;' class='console'>                                  <a href='#' style='display:none;' class='console'>
485                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
486                                  </a>                                  </a>
487    
488                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>
489                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>
490                                  </a>                                  </a>
# Line 380  foreach($vms_array as $vm) { Line 501  foreach($vms_array as $vm) {
501                                  <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>
502                          </span>                          </span>
503                                                    
504                          <span class="actionstart">                                                <span class="actionstart" style='display:none'>                
505                                  <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> |
506                                  stop |                                  stop |
507                                  force shutdown                                  force shutdown
# Line 419  foreach($vms_array as $vm) { Line 540  foreach($vms_array as $vm) {
540    
541  <br>  <br>
542    
543    <div style="display: none;">
544    
545    <div id="dialog-login" title="Login">
546            <form id="loginform">
547            <table border="0">
548                    <tr>
549                            <td>Username: </td>
550                            <td><input type="text" id="username" name="username"></td>
551                    <tr>
552                    <tr>
553                            <td>Password: </td>
554                            <td><input type="password" id="password" name="password"></td>
555                    </tr>
556            </table>
557            </form>
558    </div>
559    
560    <div id="dialog-cd" title="Select CD">
561    
562            <table border=0>
563                    <tr>
564                            <td>Current: <span id="cdcurrent"></span></td>
565                    </tr>
566                    <tr>
567                            <td>
568                                    CD: <select id="cdselector"></select>
569                            </td>
570                    </tr>
571            </table>
572    </div>
573    
574    </div>
575    
576  <ul id="menu">  <ul id="menu">
577          <li action="memory"><a href="#">Set Memory Size</a></li>          <li action="memory"><a href="#">Set Memory Size</a></li>
578          <li action="cpu"><a href="#">Set CPU Count</a></li>          <li action="cpu"><a href="#">Set CPU Count</a></li>

Legend:
Removed from v.1958  
changed lines
  Added in v.2028

  ViewVC Help
Powered by ViewVC 1.1.20