initial commit
@@ -0,0 +1,20 @@
|
||||
Title="Add VM"
|
||||
Cond="(pgrep('libvirtd')!==false)"
|
||||
Markdown="false"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
|
||||
<?
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/VMedit.php');
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
Title="Update VM"
|
||||
Cond="(pgrep('libvirtd')!==false)"
|
||||
Markdown="false"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
|
||||
<?
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/VMedit.php');
|
||||
?>
|
||||
@@ -0,0 +1,643 @@
|
||||
Menu="VMs"
|
||||
Title="Virtual Machines"
|
||||
Cond="(pgrep('libvirtd')!==false)"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
|
||||
<?
|
||||
$action = array_key_exists('action', $_GET) ? $_GET['action'] : '';
|
||||
$subaction = array_key_exists('subaction', $_GET) ? $_GET['subaction'] : '';
|
||||
$uuid = $_GET['uuid'];
|
||||
if ($_GET['refresh']) {
|
||||
$name = $_GET['name'];
|
||||
if($lv->domain_is_active($name)){
|
||||
echo "<meta http-equiv='refresh' content='5; url=/VMs?name=$name&refresh=true'>";
|
||||
$msg = "Waiting for $name to shutdown...";
|
||||
}else{
|
||||
echo "<script>clearHistory();</script>";
|
||||
$msg = "$name has been shutdown";
|
||||
}
|
||||
}
|
||||
if ($action) {
|
||||
|
||||
}else{
|
||||
if ($subaction) {
|
||||
$domName = $lv->domain_get_name_by_uuid($uuid);
|
||||
if ($subaction == 'domain-diskdev') {
|
||||
$msg = $lv->domain_set_disk_dev($domName, $_GET['olddev'], $_POST['diskdev']) ?
|
||||
$domName.' disk dev has been changed from '.$_GET['olddev'].' to '.$_POST['diskdev']:
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'disk-resize') {
|
||||
$capacity = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_POST['cap']));
|
||||
$oldcap = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_GET['oldcap']));
|
||||
if (substr($oldcap,0,-1) < substr($capacity,0,-1)){
|
||||
shell_exec("qemu-img resize -q " . escapeshellarg($_GET['disk']) . " $capacity");
|
||||
$msg = $domName." disk capacity has been changed to $capacity";
|
||||
}else {
|
||||
$msg = "Error: disk capacity has to be greater than {$_GET['oldcap']}";
|
||||
}
|
||||
}
|
||||
elseif ($subaction == 'cdrom-change') {
|
||||
$msg = $lv->domain_change_cdrom($domName, $_POST['cdrom'], $_GET['dev'], $_GET['bus']) ?
|
||||
"$domName cdrom has been changed" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'memory-change') {
|
||||
$msg = $lv->domain_set_memory($domName, $_GET['memory']*1024) ?
|
||||
"$domName memory has been changed to ".$_GET['memory']." MiB" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'vcpu-change') {
|
||||
$vcpu = $_GET['vcpu'];
|
||||
$msg = $lv->domain_set_vcpu($domName, $vcpu) ?
|
||||
"$domName vcpu number has been changed to $vcpu" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'bootdev-change') {
|
||||
$bootdev = $_GET['bootdev'];
|
||||
$msg = $lv->domain_set_boot_device($domName, $bootdev) ?
|
||||
"$domName boot device has been changed to $bootdev" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'disk-remove') {
|
||||
$msg = $lv->domain_disk_remove($domName, $_GET['dev']) ?
|
||||
"$domName disk has been removed" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-create') {
|
||||
$msg = $lv->domain_snapshot_create($domName) ?
|
||||
"Snapshot for $domName has been created" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-delete') {
|
||||
$msg = $lv->domain_snapshot_delete($domName, $_GET['snap']) ?
|
||||
"Snapshot for $domName has been deleted" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-revert') {
|
||||
$msg = $lv->domain_snapshot_revert($domName, $_GET['snap']) ?
|
||||
"$domName has been reverted" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-desc') {
|
||||
$msg = $lv->snapshot_set_metadata($domName, $_GET['snap'], $_POST['snapdesc']) ?
|
||||
"Snapshot description for $domName has been saved":
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
echo "<script>clearHistory();</script>";
|
||||
}
|
||||
echo "<table class='tablesorter kvm' id='kvm_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-th-list'></i></th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>CPUs</th>
|
||||
<th class='header'>Memory</th>
|
||||
<th class='header'>Hard Drives</th>
|
||||
<th class='header'>VNC Port</th>
|
||||
<th class='header'>Autostart</th>
|
||||
<th class='header'>Log</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>";
|
||||
//Get domain variables for each domain
|
||||
if ($libvirt_running == "yes")
|
||||
$doms = $lv->get_domains();
|
||||
if(!is_array($doms)){
|
||||
if ($libvirt_running == "yes") {
|
||||
echo "<tr><td></td><td colspan=\"7\">No Virtual Machines Installed</td></tr>";
|
||||
$msg = "No VMs defined. Create from template or add XML.";
|
||||
} else {
|
||||
$msg = "Libvirt is not running. Goto Settings tab then click Start.";
|
||||
}
|
||||
} else {
|
||||
sort($doms);
|
||||
$contextMenus = array();
|
||||
|
||||
for ($i = 0; $i < sizeof($doms); $i++) {
|
||||
$name = $doms[$i];
|
||||
$res = $lv->get_domain_by_name($name);
|
||||
$uuid = $lv->domain_get_uuid($res);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$id = $lv->domain_get_id($res);
|
||||
$is_autostart = $lv->domain_get_autostart($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
switch ($state) {
|
||||
case 'running':
|
||||
$shape = 'play';
|
||||
$status = 'started';
|
||||
break;
|
||||
case 'paused': //no break on purpose
|
||||
case 'pmsuspended':
|
||||
$shape = 'pause';
|
||||
$status = 'paused';
|
||||
break;
|
||||
default:
|
||||
$shape = 'square';
|
||||
$status = 'stopped';
|
||||
break;
|
||||
}
|
||||
if ($state == 'running') {
|
||||
$mem = $dom['memory'] / 1024;
|
||||
}else{
|
||||
$mem = $lv->domain_get_memory($res)/1024;
|
||||
}
|
||||
$mem = number_format($mem, 0);
|
||||
$vcpu = $dom['nrVirtCpu'];
|
||||
$auto = $is_autostart ? 'checked="checked"':"";
|
||||
$template = $lv->_get_single_xpath_result($res, '//domain/metadata/vmtemplate/@name');
|
||||
if (empty($template)) {
|
||||
$template = 'Custom';
|
||||
}
|
||||
$log = (is_file('/var/log/libvirt/qemu/' . $name . '.log') ? 'libvirt/qemu/' . $name . '.log' : '');
|
||||
if (($diskcnt = $lv->get_disk_count($res)) > 0) {
|
||||
$disks = $diskcnt.' / '.$lv->get_disk_capacity($res);
|
||||
$diskdesc = 'Current physical size: '.$lv->get_disk_capacity($res, true);
|
||||
}else{
|
||||
$disks = '-';
|
||||
$diskdesc = '';
|
||||
}
|
||||
|
||||
$vncport = $lv->domain_get_vnc_port($res);
|
||||
|
||||
$vnc = '';
|
||||
if ($vncport > 0) {
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
$vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host=' . $var['IPADDR'] . '&port=' . $wsport;
|
||||
} else {
|
||||
$vncport = ($vncport < 0) ? "auto" : "";
|
||||
}
|
||||
|
||||
$bootdev = $lv->domain_get_boot_devices($res)[0];
|
||||
|
||||
unset($tmp);
|
||||
if (!$id)
|
||||
$id = '-';
|
||||
unset($dom);
|
||||
|
||||
$contextMenus[] = sprintf("addVMContext('%s', '%s', '%s', '%s', '%s', '%s');", addslashes($name), addslashes($uuid), addslashes($template), $state, addslashes($vnc), addslashes($log));
|
||||
|
||||
// fallback icon for users that created VMs before metadata support was added
|
||||
$vmicon = '/plugins/dynamix.vm.manager/templates/images/' . ($lv->domain_get_clock_offset($res) == 'localtime' ? 'windows.png' : 'linux.png');
|
||||
|
||||
$vmtemplateicon = $lv->_get_single_xpath_result($res, '//domain/metadata/vmtemplate/@icon');
|
||||
if (!empty($vmtemplateicon)) {
|
||||
if (file_exists($vmtemplateicon)) {
|
||||
$vmicon = $vmtemplateicon;
|
||||
} else if (file_exists('/usr/local/emhttp/plugins/dynamix.vm.manager/templates/images/' . $vmtemplateicon)) {
|
||||
$vmicon = '/plugins/dynamix.vm.manager/templates/images/' . $vmtemplateicon;
|
||||
}
|
||||
}
|
||||
|
||||
//Domain information
|
||||
echo "<tr style='background-color:".bcolor($i,$theme)."'>
|
||||
<td style=\"width: 48px; padding: 4px\">
|
||||
<div id=\"vm-" . htmlspecialchars($uuid) . "\" style=\"display:block; cursor:pointer\">
|
||||
<div style=\"position: relative; width: 48px; height: 48px; margin: 0px auto;\">
|
||||
<img src=\"" . $vmicon . "\" class=\"$status\" style=\"position: absolute; z-index: 1; top: 0; bottom: 0; left: 0; right: 0; width: 48px; height: 48px;\"/>
|
||||
<i class=\"fa iconstatus fa-$shape $status\" title='$status'></i>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href='#' onclick=\"return toggle_id('name$i');\" title='click for more VM info'>$name</a></td>
|
||||
<td>$vcpu</td>
|
||||
<td>$mem</td>
|
||||
<td title='$diskdesc'>$disks</td>
|
||||
<td>$vncport</td>
|
||||
<td><input class='autostart' type='checkbox' name='auto_$name' title='Toggle VM auostart' $auto uuid='$uuid'></td>";
|
||||
|
||||
// Log file
|
||||
if (!empty($log)) {
|
||||
echo "<td><a class='log' href='#' onclick=\"openWindow('/webGui/scripts/tail_log&arg1=$log', '$name QEMU Log', 600, 900); return false;\"><img class='basic' src='/webGui/icons/log.png'/></a></td>";
|
||||
} else {
|
||||
echo "<td><img class='basic' src='/webGui/icons/log.png' style='opacity: 0.3' title='Log not available'/></a></td>";
|
||||
}
|
||||
|
||||
echo "</tr>
|
||||
<tr id='name$i' style='display: none'>";
|
||||
/* Disk device information */
|
||||
echo "<td colspan='8' style='overflow: hidden'>
|
||||
<table class='tablesorter domdisk' id='domdisk_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-hdd-o'></i><b> Disk devices </b>
|
||||
<select name='boot_dev' class='narrow' onchange='location = this.options[this.selectedIndex].value;' title='change boot device'>
|
||||
<option ";
|
||||
//boot device select
|
||||
if($bootdev == 'hd')
|
||||
echo "selected ";
|
||||
echo "value='?subaction=bootdev-change&uuid=$uuid&bootdev=hd'>hd</option>
|
||||
<option ";
|
||||
if($bootdev == 'cdrom')
|
||||
echo "selected ";
|
||||
echo "value='?subaction=bootdev-change&uuid=$uuid&bootdev=cdrom'>cd</option>
|
||||
</select><font size='-6'>(boot)</font>
|
||||
</th>
|
||||
<th class='header'>Driver type</th>
|
||||
<th class='header'>Dev Name</th>
|
||||
<th class='header'>Capacity</th>
|
||||
<th class='header'>Allocation</th>
|
||||
<th class='header'>Actions</th><th class='header'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>";
|
||||
/* Display domain disks */
|
||||
$tmp = $lv->get_disk_stats($res);
|
||||
if (!empty($tmp)) {
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$capacity = $lv->format_size($tmp[$ii]['capacity'], 0);
|
||||
$allocation = $lv->format_size($tmp[$ii]['allocation'], 2);
|
||||
$disk = (array_key_exists('file', $tmp[$ii])) ? $tmp[$ii]['file'] : $tmp[$ii]['partition'];
|
||||
$type = $tmp[$ii]['type'];
|
||||
$dev = $tmp[$ii]['device'];
|
||||
echo "<tr>
|
||||
<td>".basename($disk)."</td>
|
||||
<td>$type</td>
|
||||
<td title='Click to change Dev Name'><form method='post' action='?subaction=domain-diskdev&uuid=$uuid&olddev=$dev' /><span class='diskdev' style='width:30px'>
|
||||
<span class='text' ><a href='#'> $dev </a></span>
|
||||
<input class='input' type='text' style='width:36px' name='diskdev' value='$dev' val='diskdev' hidden />
|
||||
</span></form>
|
||||
</td>
|
||||
<td title='Click to increase Disk Size'>
|
||||
<form method='post' action='?subaction=disk-resize&uuid=$uuid&disk=$disk&oldcap=$capacity' /><span class='diskresize' style='width:30px'>
|
||||
<span class='text' ><a href='#'> $capacity </a></span>
|
||||
<input class='input' type='text' style='width:46px' name='cap' value='$capacity' val='diskresize' hidden />
|
||||
</span></form>
|
||||
</td>
|
||||
<td>$allocation</td>
|
||||
<td>";
|
||||
/* add detach button if shutoff */
|
||||
if ($state == 'shutoff')
|
||||
echo "detach <a href='#' onclick=\"swal({title:'Are you sure?',text:'Detach ".basename($disk)." from VM: ".$name."',type:'warning',showCancelButton:true},function(){ajaxVMDispatch('attached',{action:'disk-remove',uuid:'".$uuid."',dev:'".$dev."'});});return false;\" title='detach disk from VM'>
|
||||
<i class='fa fa-eject blue'></i></a>";
|
||||
else
|
||||
echo "N/A";
|
||||
echo '</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
/*end display disk display*/
|
||||
|
||||
/* Display domain cdroms */
|
||||
$tmp = $lv->get_cdrom_stats($res);
|
||||
if (!empty($tmp)) {
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$capacity = $lv->format_size($tmp[$ii]['capacity'], 2);
|
||||
$allocation = $lv->format_size($tmp[$ii]['allocation'], 2);
|
||||
$disk = (array_key_exists('file', $tmp[$ii])) ? $tmp[$ii]['file'] : $tmp[$ii]['partition'];
|
||||
$type = $tmp[$ii]['type'];
|
||||
$dev = $tmp[$ii]['device'];
|
||||
$bus = $tmp[$ii]['bus'];
|
||||
echo "<tr>
|
||||
<td>
|
||||
<form method='post' id='cdrom_form$i$ii' name='cdromform' action='?subaction=cdrom-change&uuid=$uuid&dev=$dev&bus=$bus' />
|
||||
<span>
|
||||
<span class='text'><a href='#'>".basename($disk)."</a></span>
|
||||
<input class='input cdrom_file' id='cdrom_file$i$ii'
|
||||
onclick='CDRomTree(cdrom_tree$i$ii, cdrom_file$i$ii, cdrom_form$i$ii);' hidden type='text' name='cdrom' value='$disk' title=change cdrom image'>
|
||||
<div class='cdrom_tree' id='cdrom_tree$i$ii' hidden></div>
|
||||
</span>
|
||||
</form>
|
||||
</td>
|
||||
<td>$type</td>
|
||||
<td title='Click to change Dev Name'><form method='post' action='?subaction=domain-diskdev&uuid=$uuid&dev=$dev' /><span class='diskdev' style='width:30px'>
|
||||
<span class='text' ><a href='#'> $dev </a></span>
|
||||
<input class='input' type='text' style='width:36px' name='diskdev' value='$dev' val='diskdev' hidden />
|
||||
</span></form>
|
||||
</td>
|
||||
<td>$capacity</td>
|
||||
<td>$allocation</td>
|
||||
<td>";
|
||||
/* add detach button if shutoff */
|
||||
if ($state == 'shutoff')
|
||||
echo "detach <a href='#' onclick=\"swal({title:'Are you sure?',text:'Detach ".basename($disk)." from VM: ".$name."',type:'warning',showCancelButton:true},function(){ajaxVMDispatch('attached',{action:'disk-remove',uuid:'".$uuid."',dev:'".$dev."'});});return false;\" title='detach disk from VM'>
|
||||
<i class='fa fa-eject blue'></i></a>";
|
||||
else
|
||||
echo "N/A";
|
||||
echo '</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
/*end display cdrom display*/
|
||||
echo "</tbody></table>";
|
||||
unset($capacity, $dev, $disk, $type, $vcpu);
|
||||
/* Backup information */
|
||||
/* echo "<table class='tablesorter domsnap' id='backup_table'>
|
||||
<tr>
|
||||
<thead>
|
||||
<th class='header'><i class='fa fa-floppy-o'></i><b> Backups </b>";
|
||||
if ($state == 'shutoff')
|
||||
echo "<a href='?subaction=backup-create&uuid=$uuid' title='create a backup of current domain'><i class='fa fa-plus green'></i></a>";
|
||||
echo "</th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Date</th>
|
||||
<th class='header'>Time</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>Actions ";
|
||||
if ($state == 'running')
|
||||
echo " <small>(stop to enable)</small>";
|
||||
echo "</th><th class='header'></th><th class='header'></th>
|
||||
</thead>
|
||||
</tr>";
|
||||
if (false) {
|
||||
sort($tmp);
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$backup = $tmp[$ii];
|
||||
$date = date("D d M Y",$name);
|
||||
$time = date("H:i:s",$backup);
|
||||
$info = $lv->domain_backup_get_info($name, $backup);
|
||||
if(empty($info)){
|
||||
$info = "Click to change description";
|
||||
$val = "";}
|
||||
else
|
||||
$val = $info;
|
||||
echo "<tr style='background-color:".bcolor($ii,$theme)."'>
|
||||
<td>".($ii+1)."</td>
|
||||
<td>$backup</td>
|
||||
<td>$date</td>
|
||||
<td>$time</td>
|
||||
<td><form method='post' action='?subaction=backup-desc&uuid=$uuid&backup=$backup' /><span class='backdesc'>
|
||||
<span class='text'><a href='#'> $info </a></span>
|
||||
<input class='input' type='text' name='backdesc' value='$val' val='backdesc' hidden placeholder='Click to change description' title='Click to change description'/>
|
||||
</span></form>
|
||||
</td>
|
||||
<td>
|
||||
revert <a href='?subaction=backup-revert&uuid=$uuid&backup=$backup'><i class='fa fa-refresh lightblue'></i></a>
|
||||
</td>
|
||||
<td>
|
||||
delete <a href='?subaction=backup-delete&uuid=$uuid&backup=$backup'><i class='fa fa-remove red'></i></a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<tr><td>no backups</td>
|
||||
<td>none</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
</tr>";
|
||||
echo '</table>';*/
|
||||
|
||||
/* End Backup information*/
|
||||
|
||||
/* Snapshot information */
|
||||
/*
|
||||
echo "<table class='tablesorter domsnap' id='domsnap_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-camera-retro'></i><b> Snapshots </b>";
|
||||
if ($state == 'shutoff')
|
||||
echo "<a href='?subaction=snap-create&uuid=$uuid' title='create a snapshot of current domain state'><i class='fa fa-plus green'></i></a>";
|
||||
echo "</th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Date</th>
|
||||
<th class='header'>Time</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>Actions ";
|
||||
if ($state == 'running')
|
||||
echo " <small>(stop to enable)</small>";
|
||||
echo "</th><th class='header'></th><th class='header'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>";
|
||||
$tmp = $lv->domain_snapshots_list($res);
|
||||
if (!empty($tmp)) {
|
||||
sort($tmp);
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$snap = $tmp[$ii];
|
||||
$date = date("D d M Y",$snap);
|
||||
$time = date("H:i:s",$snap);
|
||||
$info = $lv->domain_snapshot_get_info($res, $snap);
|
||||
if(empty($info)){
|
||||
$info = "Click to change description";
|
||||
$val = "";}
|
||||
else
|
||||
$val = $info;
|
||||
echo "<tr style='background-color:".bcolor($ii,$theme)."'>
|
||||
<td>".($ii+1)."</td>
|
||||
<td>$snap</td>
|
||||
<td>$date</td>
|
||||
<td>$time</td>
|
||||
<td><form method='post' action='?subaction=snap-desc&uuid=$uuid&snap=$snap' /><span class='snapdesc'>
|
||||
<span class='text'><a href='#'> $info </a></span>
|
||||
<input class='input' type='text' name='snapdesc' value='$val' val='snapdesc' hidden placeholder='Click to change description' title='Click to change description'/>
|
||||
</span></form>
|
||||
</td>
|
||||
<td>
|
||||
revert <a href='?subaction=snap-revert&uuid=$uuid&snap=$snap'><i class='fa fa-refresh lightblue'></i></a>
|
||||
</td>
|
||||
<td>
|
||||
delete <a href='?subaction=snap-delete&uuid=$uuid&snap=$snap'><i class='fa fa-trash red'></i></a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<tr><td>no snapshots</td>
|
||||
<td>none</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
</tr>";
|
||||
echo '</tbody></table>';
|
||||
*/
|
||||
echo '</td></tr>';
|
||||
}
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
/* End Snapshot information */
|
||||
unset($name, $val);
|
||||
if($msg){
|
||||
if(strpos($msg, "rror:"))
|
||||
$color = 'red';
|
||||
else
|
||||
$color = 'green';
|
||||
echo "<script type='text/javascript'>$(function() { $('#countdown').html('<font class=\"".$color."\">".$msg."</font>');}); </script>";
|
||||
}
|
||||
?>
|
||||
|
||||
<input type="button" id="btnAddVM" value="Add VM"/>
|
||||
|
||||
<script>
|
||||
function vncOpen() {
|
||||
$.post('/plugins/dynamix.vm.manager/classes/vnc.php',{cmd:'open',root:'<?=$docroot?>',file:'/usr/local/emhttp/plugins/dynamix.vm.manager/vncconnect.vnc'},function(data) {
|
||||
window.location.href = data;
|
||||
});
|
||||
}
|
||||
|
||||
function toggle_id(itemID){
|
||||
if ((document.getElementById(itemID).style.display == 'none')) {
|
||||
slideDownRows($('#'+itemID));
|
||||
} else {
|
||||
slideUpRows($('#'+itemID));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function showInput(){
|
||||
$(this).off('click');
|
||||
$(this).siblings('input').each(function(){$(this).show();});
|
||||
$(this).siblings('input').focus();
|
||||
$(this).hide();
|
||||
}
|
||||
|
||||
function hideInput(){
|
||||
$(this).hide();
|
||||
$(this).siblings('span').show();
|
||||
$(this).siblings('span').click(showInput);
|
||||
}
|
||||
|
||||
function ajaxVMDispatch(currentstate, params){
|
||||
$.post("/plugins/dynamix.vm.manager/VMajax.php", params, function( data ) {
|
||||
if (data.error) {
|
||||
swal({title:"Execution error",text:data.error,type:"error"});
|
||||
} else {
|
||||
if (!data.state || currentstate != data.state) {
|
||||
location = window.location.href;
|
||||
}
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
|
||||
function addVMContext(name, uuid, template, state, vncurl, log){
|
||||
var opts = [{header: name, image: "/plugins/dynamix.vm.manager/images/dynamix.vm.manager.png"}];
|
||||
|
||||
var path = location.pathname;
|
||||
var x = path.indexOf("?");
|
||||
if (x!=-1) path = path.substring(0,x);
|
||||
|
||||
if (vncurl !== "") {
|
||||
opts.push({text: "VNC Remote", icon: "fa-desktop", action: function(e){ e.preventDefault(); window.open(vncurl, '_blank', 'scrollbars=yes,resizable=yes'); } });
|
||||
opts.push({divider: true});
|
||||
}
|
||||
|
||||
if (state == "running") {
|
||||
|
||||
opts.push({text: "Stop", icon: "fa-stop", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-stop", uuid: uuid });
|
||||
}});
|
||||
|
||||
opts.push({text: "Pause", icon: "fa-pause", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-pause", uuid: uuid });
|
||||
}});
|
||||
|
||||
opts.push({text: "Restart", icon: "fa-refresh", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-restart", uuid: uuid });
|
||||
}});
|
||||
|
||||
opts.push({text: "Force Stop", icon: "fa-bomb", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-destroy", uuid: uuid });
|
||||
}});
|
||||
|
||||
} else if (state == "pmsuspended") {
|
||||
|
||||
opts.push({text: "Resume", icon: "fa-play", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-pmwakeup", uuid: uuid });
|
||||
}});
|
||||
|
||||
opts.push({text: "Force Stop", icon: "fa-bomb", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-destroy", uuid: uuid });
|
||||
}});
|
||||
|
||||
} else if (state == "paused" || state == "unknown") {
|
||||
|
||||
opts.push({text: "Resume", icon: "fa-play", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-resume", uuid: uuid });
|
||||
}});
|
||||
|
||||
opts.push({text: "Force Stop", icon: "fa-bomb", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-destroy", uuid: uuid });
|
||||
}});
|
||||
|
||||
} else {
|
||||
|
||||
opts.push({text: "Start", icon: "fa-play", action: function(e) {
|
||||
e.preventDefault();
|
||||
ajaxVMDispatch(state, { action: "domain-start", uuid: uuid });
|
||||
}});
|
||||
|
||||
}
|
||||
|
||||
opts.push({divider: true});
|
||||
|
||||
if (log !== "") {
|
||||
if (location.pathname.indexOf("/Dashboard") === 0) {
|
||||
opts.push({text: "Logs", icon: "fa-navicon", action: function(e){ e.preventDefault(); openWindow('/webGui/scripts/tail_log&arg1=' + log + ')', 'Log for: ' + name, 600, 900); } });
|
||||
}
|
||||
}
|
||||
|
||||
if (state == "shutoff") {
|
||||
|
||||
opts.push({text: "Edit", icon: "fa-pencil", href: path+'/UpdateVM?uuid='+uuid });
|
||||
opts.push({text: "Edit XML", icon: "fa-code", href: path+'/UpdateVM?template=XML_Expert&uuid='+uuid });
|
||||
|
||||
opts.push({divider: true});
|
||||
|
||||
opts.push({text: "Remove VM", icon: "fa-minus", action: function(e) {
|
||||
e.preventDefault();
|
||||
swal({title:"Are you sure?",text:"Remove definition: "+name,type:"warning",showCancelButton:true},function(){ajaxVMDispatch(state,{action:"domain-undefine",uuid:uuid});});
|
||||
}});
|
||||
|
||||
if (template != 'OpenELEC') {
|
||||
opts.push({text: "Remove VM + Disks", icon: "fa-trash", action: function(e) {
|
||||
e.preventDefault();
|
||||
swal({title:"Are you sure?",text:"Completely REMOVE "+name+" disk image and definition",type:"warning",showCancelButton:true},function(){ajaxVMDispatch(state,{action:"domain-delete",uuid:uuid});});
|
||||
}});
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
opts.push({text: "View XML", icon: "fa-code", href: path+'/UpdateVM?template=XML_Expert&uuid='+uuid });
|
||||
|
||||
}
|
||||
|
||||
context.attach('#vm-'+uuid, opts);
|
||||
}
|
||||
|
||||
|
||||
$(function() {
|
||||
$('.text').click(showInput);
|
||||
$('.input').blur(hideInput);
|
||||
$('#btnAddVM').click(function AddVMEvent() {
|
||||
window.location = '/VMs/AddVM';
|
||||
});
|
||||
|
||||
$('.autostart').switchButton({
|
||||
labels_placement: "right"
|
||||
});
|
||||
$('.autostart').change(function () {
|
||||
$.post( "/plugins/dynamix.vm.manager/VMajax.php", { action: "domain-autostart", uuid: $(this).attr('uuid'), autostart: $(this).prop('checked'), response: "json" }, function( data ) {
|
||||
$(this).prop('checked', data.autostart );
|
||||
}, "json");
|
||||
});
|
||||
|
||||
context.init({ preventDoubleContext: false });
|
||||
<?=implode("\n\t", $contextMenus);?>
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
Menu="OtherSettings"
|
||||
Title="VM Manager"
|
||||
Icon="dynamix.vm.manager.png"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
if ($var['fsState'] != "Started") {
|
||||
echo "<p class='notice'>Array must be Started to manage Virtual Machines.</p>";
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt_helpers.php');
|
||||
|
||||
|
||||
// Check for Intel VT-x (vmx) or AMD-V (svm) cpu virtualzation support
|
||||
// Attempt to load either of the kvm modules to see if virtualzation hw is supported
|
||||
exec('modprobe -a kvm_intel kvm_amd 2>/dev/null');
|
||||
|
||||
// If either kvm_intel or kvm_amd are loaded then Intel VT-x (vmx) or AMD-V (svm) cpu virtualzation support was found
|
||||
$strLoadedModules = shell_exec("lsmod | grep '^kvm_\(amd\|intel\)'");
|
||||
|
||||
if (empty($strLoadedModules)) {
|
||||
?><p class="notice">Your hardware does not have Intel VT-x or AMD-V capability. This is required to create VMs in KVM. <a href="http://lime-technology.com/wiki/index.php/UnRAID_Manual_6#Hardware-Assisted_Virtualization_.28HVM.29" target="_blank">Click here to see the unRAID Wiki for more information</a></p><?php
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$arrValidBridges = getNetworkBridges();
|
||||
|
||||
|
||||
// Check for PCIE ACS capabilities
|
||||
$boolACSEnabled = (strpos(file_get_contents('/proc/cmdline'), 'pcie_acs_override=') !== false);
|
||||
|
||||
// Check the /boot/syslinux/syslinux.cfg for the existance of pcie_acs_override=
|
||||
$arrSyslinuxCfg = file('/boot/syslinux/syslinux.cfg');
|
||||
$strCurrentLabel = '';
|
||||
$boolACSInSyslinux = false;
|
||||
|
||||
foreach ($arrSyslinuxCfg as &$strSyslinuxCfg) {
|
||||
if (stripos(trim($strSyslinuxCfg), 'label ') === 0) {
|
||||
$strCurrentLabel = trim(str_ireplace('label ', '', $strSyslinuxCfg));
|
||||
}
|
||||
if (stripos($strSyslinuxCfg, 'append ') !== false) {
|
||||
if (stripos($strSyslinuxCfg, 'pcie_acs_override=') !== false) {
|
||||
// pcie_acs_override= was found
|
||||
$boolACSInSyslinux = true;
|
||||
}
|
||||
|
||||
// We just examine the first append line
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($boolACSEnabled != $boolACSInSyslinux) {
|
||||
?><p class="notice">You must reboot for changes to take effect</p><?php
|
||||
}
|
||||
?>
|
||||
<link type="text/css" rel="stylesheet" href="/plugins/dynamix.vm.manager/styles/dynamix.vm.manager.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
<style>
|
||||
body { -webkit-overflow-scrolling: touch;}
|
||||
.fileTree {
|
||||
width: 305px;
|
||||
max-height: 150px;
|
||||
overflow: scroll;
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<form id="settingsForm" markdown="1" method="POST" action="/update.php" target="progressFrame">
|
||||
<input type="hidden" name="#file" value="<?=$domain_cfgfile;?>" />
|
||||
<input type="hidden" id="command" name="#command" value="" />
|
||||
|
||||
Enable VMs:
|
||||
: <select id="SERVICE" name="SERVICE" class="narrow">
|
||||
<?= mk_option($libvirt_service, 'disable', 'No'); ?>
|
||||
<?= mk_option($libvirt_service, 'enable', 'Yes'); ?>
|
||||
</select>
|
||||
|
||||
> Stopping the VM Manager will first attempt to shutdown all running VMs. After 40 seconds, any remaining VM instances will be terminated.
|
||||
|
||||
<? if ($libvirt_service == 'enable') {
|
||||
$libvirt_info = libvirt_version('libvirt');
|
||||
$qemu_info = $lv->get_connect_information(); ?>
|
||||
Libvirt Version:
|
||||
: <?= $libvirt_info['libvirt.major'] . '.' . $libvirt_info['libvirt.minor'] . '.' . $libvirt_info['libvirt.release']; ?>
|
||||
|
||||
QEMU Version:
|
||||
: <?= $qemu_info['hypervisor_major'] . '.' . $qemu_info['hypervisor_minor'] . '.' . $qemu_info['hypervisor_release']; ?>
|
||||
<? } ?>
|
||||
|
||||
ISO Library Share <span style="font-weight: normal">(optional)</span>:
|
||||
: <input type="text" data-pickfolders="true" data-pickfilter="NO_FILES_FILTER" data-pickroot="<?= (is_dir('/mnt/user/') ? '/mnt/user/' : '/mnt/') ?>" name="MEDIADIR" value="<?=$domain_cfg['MEDIADIR']?>" placeholder="Click to Select">
|
||||
|
||||
> Specify a user share that contains all your installation media for operating systems
|
||||
|
||||
VirtIO Windows Drivers ISO <span style="font-weight: normal">(optional)</span>:
|
||||
: <input type="text" data-pickfilter="iso" data-pickcloseonfile="true" data-pickroot="<?= (is_dir('/mnt/user/') ? '/mnt/user/' : '/mnt/') ?>" name="VIRTIOISO" value="<?=$domain_cfg['VIRTIOISO']?>" placeholder="Click to Select">
|
||||
|
||||
> Specify the virtual CD-ROM (ISO) that contains the VirtIO Windows drivers as provided by the Fedora Project.
|
||||
> Download the latest ISO from here: <a href="https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download" target="_blank">https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download</a>
|
||||
>
|
||||
> When installing Windows, you will reach a step where no disk devices will be found.
|
||||
> There is an option to browse for drivers on that screen. Click browse and locate the additional CD-ROM in the menu.
|
||||
> Inside there will be various folders for the different versions of Windows. Open the folder for the version of Windows
|
||||
> you are installing and then select the AMD64 subfolder inside (even if you are on an Intel system, select AMD64).
|
||||
> Three drivers will be found. Select them all, click next, and the vDisks you have assigned will appear.
|
||||
|
||||
<!--
|
||||
vDisk Share <span style="font-weight: normal">(optional)</span>:
|
||||
: <input type="text" data-pickfolders="true" data-pickfilter="NO_FILES_FILTER" data-pickroot="/mnt/" name="DISKDIR" value="<?=$domain_cfg['DISKDIR']?>" placeholder="Click to Select (ie. /mnt/cache/images)" title="Click to Select (ie. /mnt/cache/images)">
|
||||
-->
|
||||
|
||||
Default Network Bridge:
|
||||
: <select id="bridge" name="BRNAME">
|
||||
<?php
|
||||
foreach ($arrValidBridges as $strBridge) {
|
||||
echo mk_option($domain_cfg['BRNAME'], $strBridge, $strBridge);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
> Enter the name of the network bridge you wish to use for your VMs here, otherwise leave the field blank and
|
||||
> libvirt will create a bridge that will utilize NAT (network address translation) and act as a DHCP server to hand out
|
||||
> IP addresses to virtual machines directly.
|
||||
>
|
||||
> NOTE: You can also specify an network bridge on a per-VM basis.
|
||||
|
||||
PCIe ACS Override:
|
||||
: <select id="pcie_acs_override" class="narrow">
|
||||
<?= mk_option(($boolACSInSyslinux ? '1' : '0'), '0', 'No'); ?>
|
||||
<?= mk_option(($boolACSInSyslinux ? '1' : '0'), '1', 'Yes'); ?>
|
||||
</select>
|
||||
|
||||
> Warning: Use of this setting could cause possible data corruption with certain hardware configurations. Please visit the Lime Technology forums for more information.
|
||||
>
|
||||
> A reboot will be required for changes to this setting to take affect.
|
||||
|
||||
|
||||
: <input type="button" id="applyBtn" value="Apply"/><input type="button" value="Done" onclick="done()">
|
||||
</form>
|
||||
|
||||
> View the log for libvirt: <a id="openlog" title="/var/log/libvirt/libvirtd.log" href="#" onclick="openWindow('/webGui/scripts/tail_log&arg1=libvirt/libvirtd.log','Log Information',600,900);">/var/log/libvirt/libvirtd.log</a>
|
||||
|
||||
|
||||
<script src="/webGui/javascript/jquery.filetree.js"></script>
|
||||
<script src="/webGui/javascript/jquery.switchbutton.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/dynamix.vm.manager.js"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
$("#applyBtn").click(function(){
|
||||
$("#command").val("/plugins/dynamix.vm.manager/event/" + ($("#SERVICE").val()=="enable" ? "started" : "stopping_svcs"));
|
||||
|
||||
if ($('#pcie_acs_override').val() == '1') {
|
||||
$.get("/plugins/dynamix.vm.manager/VMajax.php?action=acs-override-enable", function( data ) {
|
||||
$("#settingsForm").submit();
|
||||
}, "json");
|
||||
} else {
|
||||
$.get("/plugins/dynamix.vm.manager/VMajax.php?action=acs-override-disable", function( data ) {
|
||||
$("#settingsForm").submit();
|
||||
}, "json");
|
||||
}
|
||||
});
|
||||
|
||||
$("input[data-pickroot]").fileTreeAttach();
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,372 @@
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
|
||||
require_once('/usr/local/emhttp/webGui/include/Helpers.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt_helpers.php');
|
||||
|
||||
$arrSizePrefix = [
|
||||
0 => '',
|
||||
1 => 'K',
|
||||
2 => 'M',
|
||||
3 => 'G',
|
||||
4 => 'T',
|
||||
5 => 'P'
|
||||
];
|
||||
|
||||
$_REQUEST = array_merge($_GET, $_POST);
|
||||
|
||||
$action = array_key_exists('action', $_REQUEST) ? $_REQUEST['action'] : '';
|
||||
$uuid = array_key_exists('uuid', $_REQUEST) ? $_REQUEST['uuid'] : '';
|
||||
|
||||
// Make sure libvirt is connected to qemu
|
||||
if (!isset($lv) || !$lv->enabled()) {
|
||||
header('Content-Type: application/json');
|
||||
die(json_encode(['error' => 'failed to connect to the hypervisor']));
|
||||
}
|
||||
|
||||
if ($uuid) {
|
||||
$domName = $lv->domain_get_name_by_uuid($uuid);
|
||||
if (!$domName) {
|
||||
header('Content-Type: application/json');
|
||||
die(json_encode(['error' => $lv->get_last_error()]));
|
||||
}
|
||||
}
|
||||
|
||||
$arrResponse = [];
|
||||
|
||||
|
||||
switch ($action) {
|
||||
|
||||
case 'domain-autostart':
|
||||
$arrResponse = $lv->domain_set_autostart($domName, ($_REQUEST['autostart'] != "false")) ?
|
||||
['success' => true, 'autostart' => (bool)$lv->domain_get_autostart($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-start':
|
||||
$arrResponse = $lv->domain_start($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-pause':
|
||||
$arrResponse = $lv->domain_suspend($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-resume':
|
||||
$arrResponse = $lv->domain_resume($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-pmwakeup':
|
||||
// No support in libvirt-php to do a dompmwakeup, use virsh tool instead
|
||||
exec("virsh dompmwakeup " . escapeshellarg($uuid) . " 2>&1", $arrOutput, $intReturnCode);
|
||||
$arrResponse = ($intReturnCode == 0) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => str_replace('error: ', '', implode('. ', $arrOutput))];
|
||||
break;
|
||||
|
||||
case 'domain-restart':
|
||||
$arrResponse = $lv->domain_reboot($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-save':
|
||||
$arrResponse = $lv->domain_save($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-stop':
|
||||
$arrResponse = $lv->domain_shutdown($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-destroy':
|
||||
$arrResponse = $lv->domain_destroy($domName) ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-delete':
|
||||
$arrResponse = $lv->domain_delete($domName) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-undefine':
|
||||
$arrResponse = $lv->domain_undefine($domName) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-define':
|
||||
$domName = $lv->domain_define($_REQUEST['xml']);
|
||||
$arrResponse = $domName ?
|
||||
['success' => true, 'state' => $lv->domain_get_state($domName)] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-state':
|
||||
$state = $lv->domain_get_state($domName);
|
||||
$arrResponse = ($state) ?
|
||||
['success' => true, 'state' => $state] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-diskdev':
|
||||
$arrResponse = ($lv->domain_set_disk_dev($domName, $_REQUEST['olddev'], $_REQUEST['diskdev'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'cdrom-change':
|
||||
$arrResponse = ($lv->domain_change_cdrom($domName, $_REQUEST['cdrom'], $_REQUEST['dev'], $_REQUEST['bus'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'memory-change':
|
||||
$arrResponse = ($lv->domain_set_memory($domName, $_REQUEST['memory']*1024)) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'vcpu-change':
|
||||
$arrResponse = ($lv->domain_set_vcpu($domName, $_REQUEST['vcpu'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'bootdev-change':
|
||||
$arrResponse = ($lv->domain_set_boot_device($domName, $_REQUEST['bootdev'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'disk-remove':
|
||||
$arrResponse = ($lv->domain_disk_remove($domName, $_REQUEST['dev'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'snap-create':
|
||||
$arrResponse = ($lv->domain_snapshot_create($domName)) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'snap-delete':
|
||||
$arrResponse = ($lv->domain_snapshot_delete($domName, $_REQUEST['snap'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'snap-revert':
|
||||
$arrResponse = ($lv->domain_snapshot_revert($domName, $_REQUEST['snap'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'snap-desc':
|
||||
$arrResponse = ($lv->snapshot_set_metadata($domName, $_REQUEST['snap'], $_REQUEST['snapdesc'])) ?
|
||||
['success' => true] :
|
||||
['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'disk-create':
|
||||
$disk = $_REQUEST['disk'];
|
||||
$driver = $_REQUEST['driver'];
|
||||
$size = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_REQUEST['size']));
|
||||
|
||||
$dir = dirname($disk);
|
||||
|
||||
if (!is_dir($dir))
|
||||
mkdir($dir);
|
||||
|
||||
// determine the actual disk if user share is being used
|
||||
if (strpos($dir, '/mnt/user/') === 0) {
|
||||
$tmp = parse_ini_string(shell_exec("getfattr -n user.LOCATION " . escapeshellarg($dir) . " | grep user.LOCATION"));
|
||||
$dir = str_replace('/mnt/user', '/mnt/' . $tmp['user.LOCATION'], $dir); // replace 'user' with say 'cache' or 'disk1' etc
|
||||
}
|
||||
|
||||
@exec("chattr +C -R " . escapeshellarg($dir) . " >/dev/null");
|
||||
|
||||
$strLastLine = exec("qemu-img create -q -f " . escapeshellarg($driver) . " " . escapeshellarg($disk) . " " . escapeshellarg($size) . " 2>&1", $out, $status);
|
||||
|
||||
if (empty($status)) {
|
||||
$arrResponse = ['success' => true];
|
||||
} else {
|
||||
$arrResponse = ['error' => $strLastLine];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'disk-resize':
|
||||
$disk = $_REQUEST['disk'];
|
||||
$capacity = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_REQUEST['cap']));
|
||||
$old_capacity = str_replace(array("KB","MB","GB","TB","PB", " ", ","), array("K","M","G","T","P", "", ""), strtoupper($_REQUEST['oldcap']));
|
||||
|
||||
if (substr($old_capacity,0,-1) < substr($capacity,0,-1)){
|
||||
$strLastLine = exec("qemu-img resize -q " . escapeshellarg($disk) . " " . escapeshellarg($capacity) . " 2>&1", $out, $status);
|
||||
if (empty($status)) {
|
||||
$arrResponse = ['success' => true];
|
||||
} else {
|
||||
$arrResponse = ['error' => $strLastLine];
|
||||
}
|
||||
} else {
|
||||
$arrResponse = ['error' => "Disk capacity has to be greater than " . $old_capacity];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'file-info':
|
||||
$file = $_REQUEST['file'];
|
||||
|
||||
$arrResponse = [
|
||||
'isfile' => (!empty($file) ? is_file($file) : false),
|
||||
'isdir' => (!empty($file) ? is_dir($file) : false),
|
||||
'isblock' => (!empty($file) ? is_block($file) : false),
|
||||
'resizable' => false
|
||||
];
|
||||
|
||||
// if file, get size and format info
|
||||
if (is_file($file)) {
|
||||
$json_info = json_decode(shell_exec("qemu-img info --output json " . escapeshellarg($file)), true);
|
||||
if (!empty($json_info)) {
|
||||
$intDisplaySize = (int)$json_info['virtual-size'];
|
||||
$intShifts = 0;
|
||||
while (!empty($intDisplaySize) &&
|
||||
(floor($intDisplaySize) == $intDisplaySize) &&
|
||||
isset($arrSizePrefix[$intShifts])) {
|
||||
|
||||
$arrResponse['display-size'] = $intDisplaySize . $arrSizePrefix[$intShifts];
|
||||
|
||||
$intDisplaySize /= 1024;
|
||||
$intShifts++;
|
||||
}
|
||||
|
||||
$arrResponse['virtual-size'] = $json_info['virtual-size'];
|
||||
$arrResponse['actual-size'] = $json_info['actual-size'];
|
||||
$arrResponse['format'] = $json_info['format'];
|
||||
$arrResponse['dirty-flag'] = $json_info['dirty-flag'];
|
||||
$arrResponse['resizable'] = true;
|
||||
}
|
||||
} else if (is_block($file)) {
|
||||
$strDevSize = trim(shell_exec("blockdev --getsize64 " . escapeshellarg($file)));
|
||||
if (!empty($strDevSize) && is_numeric($strDevSize)) {
|
||||
$arrResponse['actual-size'] = (int)$strDevSize;
|
||||
$arrResponse['format'] = 'raw';
|
||||
|
||||
$intDisplaySize = (int)$strDevSize;
|
||||
$intShifts = 0;
|
||||
while (!empty($intDisplaySize) &&
|
||||
($intDisplaySize >= 2) &&
|
||||
isset($arrSizePrefix[$intShifts])) {
|
||||
|
||||
$arrResponse['display-size'] = round($intDisplaySize, 0) . $arrSizePrefix[$intShifts];
|
||||
|
||||
$intDisplaySize /= 1000; // 1000 looks better than 1024 for block devs
|
||||
$intShifts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'generate-mac':
|
||||
$arrResponse = [
|
||||
'mac' => $lv->generate_random_mac_addr()
|
||||
];
|
||||
break;
|
||||
|
||||
case 'acs-override-enable':
|
||||
// Check the /boot/syslinux/syslinux.cfg for the existance of pcie_acs_override=downstream, add it in if not found
|
||||
$arrSyslinuxCfg = file('/boot/syslinux/syslinux.cfg');
|
||||
$strCurrentLabel = '';
|
||||
$boolModded = false;
|
||||
foreach ($arrSyslinuxCfg as &$strSyslinuxCfg) {
|
||||
if (stripos(trim($strSyslinuxCfg), 'label ') === 0) {
|
||||
$strCurrentLabel = trim(str_ireplace('label ', '', $strSyslinuxCfg));
|
||||
}
|
||||
if (stripos($strSyslinuxCfg, 'append ') !== false) {
|
||||
if (stripos($strSyslinuxCfg, 'pcie_acs_override=') === false) {
|
||||
// pcie_acs_override=downstream was not found so append it in
|
||||
$strSyslinuxCfg = str_ireplace('append ', 'append pcie_acs_override=downstream ', $strSyslinuxCfg);
|
||||
$boolModded = true;
|
||||
}
|
||||
|
||||
// We just modify the first append line, other boot menu items are untouched
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($boolModded) {
|
||||
// Backup syslinux.cfg
|
||||
copy('/boot/syslinux/syslinux.cfg', '/boot/syslinux/syslinux.cfg-');
|
||||
|
||||
// Write Changes to syslinux.cfg
|
||||
file_put_contents('/boot/syslinux/syslinux.cfg', implode('', $arrSyslinuxCfg));
|
||||
}
|
||||
|
||||
$arrResponse = ['success' => true, 'label' => $strCurrentLabel];
|
||||
break;
|
||||
|
||||
case 'acs-override-disable':
|
||||
// Check the /boot/syslinux/syslinux.cfg for the existance of pcie_acs_override=, remove it if found
|
||||
$arrSyslinuxCfg = file('/boot/syslinux/syslinux.cfg');
|
||||
$strCurrentLabel = '';
|
||||
$boolModded = false;
|
||||
foreach ($arrSyslinuxCfg as &$strSyslinuxCfg) {
|
||||
if (stripos(trim($strSyslinuxCfg), 'label ') === 0) {
|
||||
$strCurrentLabel = trim(str_ireplace('label ', '', $strSyslinuxCfg));
|
||||
}
|
||||
if (stripos($strSyslinuxCfg, 'append ') !== false) {
|
||||
if (stripos($strSyslinuxCfg, 'pcie_acs_override=') !== false) {
|
||||
// pcie_acs_override= was found so remove the two variations
|
||||
$strSyslinuxCfg = str_ireplace('pcie_acs_override=downstream ', '', $strSyslinuxCfg);
|
||||
$strSyslinuxCfg = str_ireplace('pcie_acs_override=multifunction ', '', $strSyslinuxCfg);
|
||||
$boolModded = true;
|
||||
}
|
||||
|
||||
// We just modify the first append line, other boot menu items are untouched
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($boolModded) {
|
||||
// Backup syslinux.cfg
|
||||
copy('/boot/syslinux/syslinux.cfg', '/boot/syslinux/syslinux.cfg-');
|
||||
|
||||
// Write Changes to syslinux.cfg
|
||||
file_put_contents('/boot/syslinux/syslinux.cfg', implode('', $arrSyslinuxCfg));
|
||||
}
|
||||
|
||||
$arrResponse = ['success' => true, 'label' => $strCurrentLabel];
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
$arrResponse = ['error' => 'Unknown action \'' . $action . '\''];
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
die(json_encode($arrResponse));
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
require_once('/usr/local/emhttp/webGui/include/Helpers.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt_helpers.php');
|
||||
|
||||
$arrLoad = [
|
||||
'name' => '',
|
||||
'icon' => 'default.png',
|
||||
'desc' => '',
|
||||
'autostart' => false
|
||||
];
|
||||
|
||||
$strSelectedTemplate = 'Custom';
|
||||
|
||||
if (!empty($_GET['uuid'])) {
|
||||
// Edit VM mode
|
||||
$res = $lv->domain_get_domain_by_uuid($_GET['uuid']);
|
||||
|
||||
$strIcon = $lv->_get_single_xpath_result($res, '//domain/metadata/vmtemplate/@icon');
|
||||
|
||||
if (!empty($strIcon)) {
|
||||
if (file_exists($strIcon)) {
|
||||
$strIconURL = $strIcon;
|
||||
} else if (file_exists('/usr/local/emhttp/plugins/dynamix.vm.manager/templates/images/' . $strIcon)) {
|
||||
$strIconURL = '/plugins/dynamix.vm.manager/templates/images/' . $strIcon;
|
||||
}
|
||||
} else {
|
||||
$strIcon = ($lv->domain_get_clock_offset($res) == 'localtime' ? 'windows.png' : 'linux.png');
|
||||
$strIconURL = '/plugins/dynamix.vm.manager/templates/images/' . $strIcon;
|
||||
}
|
||||
|
||||
$arrLoad = [
|
||||
'name' => $lv->domain_get_name($res),
|
||||
'icon' => $strIcon,
|
||||
'desc' => $lv->domain_get_description($res),
|
||||
'autostart' => $lv->domain_get_autostart($res)
|
||||
];
|
||||
|
||||
if (!empty($_GET['template'])) {
|
||||
$strSelectedTemplate = $_GET['template'];
|
||||
} else {
|
||||
$strTemplate = $lv->_get_single_xpath_result($res, '//domain/metadata/vmtemplate/@name');
|
||||
if (!empty($strTemplate)) {
|
||||
$strSelectedTemplate = $strTemplate;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// New VM mode
|
||||
$strIcon = 'windows.png';
|
||||
$strIconURL = '/plugins/dynamix.vm.manager/templates/images/windows.png';
|
||||
|
||||
$arrLoad['icon'] = $strIcon;
|
||||
|
||||
if (!empty($_GET['template'])) {
|
||||
$strSelectedTemplate = $_GET['template'];
|
||||
}
|
||||
}
|
||||
|
||||
$arrTemplates = array();
|
||||
|
||||
// Read files from the templates folder
|
||||
foreach (glob('plugins/dynamix.vm.manager/templates/*.form.php') as $template) {
|
||||
$arrTemplates[] = basename($template, '.form.php');
|
||||
}
|
||||
|
||||
if (!empty($arrTemplates) && !in_array($strSelectedTemplate, $arrTemplates)) {
|
||||
$strSelectedTemplate = $arrTemplates[0];
|
||||
}
|
||||
|
||||
?>
|
||||
<link type="text/css" rel="stylesheet" href="/plugins/dynamix.vm.manager/styles/dynamix.vm.manager.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
<style type="text/css">
|
||||
body { -webkit-overflow-scrolling: touch;}
|
||||
.fileTree {
|
||||
width: 305px;
|
||||
max-height: 150px;
|
||||
overflow: scroll;
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
display: none;
|
||||
}
|
||||
#createform table {
|
||||
margin-top: 0;
|
||||
}
|
||||
#createform div#title + table {
|
||||
margin-top: -21px;
|
||||
}
|
||||
#createform table tr {
|
||||
vertical-align: top;
|
||||
line-height: 24px;
|
||||
}
|
||||
#createform table tr td:nth-child(odd) {
|
||||
width: 150px;
|
||||
text-align: right;
|
||||
padding-right: 10px;
|
||||
}
|
||||
#createform table tr td:nth-child(even) {
|
||||
width: 80px;
|
||||
}
|
||||
#createform table tr td:last-child {
|
||||
width: inherit;
|
||||
}
|
||||
#createform .multiple {
|
||||
position: relative;
|
||||
}
|
||||
#createform .sectionbutton {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
cursor: pointer;
|
||||
opacity: 0.4;
|
||||
font-size: 15px;
|
||||
line-height: 17px;
|
||||
z-index: 10;
|
||||
transition-property: opacity, left;
|
||||
transition-duration: 0.1s;
|
||||
transition-timing-function: linear;
|
||||
}
|
||||
#createform .sectionbutton.remove { top: 0; opacity: 0.3; }
|
||||
#createform .sectionbutton.add { bottom: 0; }
|
||||
#createform .sectionbutton:hover { opacity: 1.0; }
|
||||
#createform .sectiontab {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
bottom: 2px;
|
||||
left: 0;
|
||||
width: 6px;
|
||||
border-radius: 3px;
|
||||
background-color: #DDDDDD;
|
||||
transition-property: background, width;
|
||||
transition-duration: 0.1s;
|
||||
transition-timing-function: linear;
|
||||
}
|
||||
#createform .multiple:hover .sectionbutton {
|
||||
opacity: 0.7;
|
||||
left: 4px;
|
||||
}
|
||||
#createform .multiple:hover .sectionbutton.remove {
|
||||
opacity: 0.6;
|
||||
}
|
||||
#createform .multiple:hover .sectiontab {
|
||||
background-color: #CCCCCC;
|
||||
width: 8px;
|
||||
}
|
||||
#form_content {
|
||||
margin-top: -21px;
|
||||
}
|
||||
span.advancedview_panel {
|
||||
display: none;
|
||||
line-height: 16px;
|
||||
margin-top: 1px;
|
||||
}
|
||||
.basic {
|
||||
/*Empty placeholder*/
|
||||
}
|
||||
.advanced {
|
||||
display: none;
|
||||
}
|
||||
.switch-button-label.off {
|
||||
color: inherit;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="content" style="margin-top:-21px;margin-left:0px">
|
||||
<form id="createform" method="POST">
|
||||
<input type="hidden" name="domain[type]" value="kvm" />
|
||||
|
||||
<table>
|
||||
<tr <? if (!empty($arrLoad['name'])) echo 'style="display: none"'; ?>>
|
||||
<td>Template:</td>
|
||||
<td>
|
||||
<select id="domain_template" name="template[name]" class="narrow" title="Choose a preconfigured template or select Custom to create your own from scratch">
|
||||
<?php
|
||||
foreach ($arrTemplates as $strTemplate) {
|
||||
echo mk_option($strSelectedTemplate, $strTemplate, str_replace('_', ' ', $strTemplate));
|
||||
}
|
||||
?>
|
||||
</select><img src="/webGui/images/spinner.gif" style="display: none">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div <? if (!empty($arrLoad['name'])) echo 'style="display: none"'; ?>>
|
||||
<blockquote class="inline_help">
|
||||
<p>Choose a preconfigured template or select Custom to create your own from scratch.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Icon:</td>
|
||||
<td><input type="hidden" name="template[icon]" id="template_icon" value="<?=$arrLoad['icon']?>" /><img id="template_img" src="<?=htmlentities($strIconURL)?>" width="48" height="48" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tr class="non_expert_xml">
|
||||
<td>Name:</td>
|
||||
<td><input type="text" name="domain[name]" class="textTemplate" title="Name of virtual machine" placeholder="e.g. My Workstation" value="<?=htmlentities($arrLoad['name'])?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="non_expert_xml">
|
||||
<blockquote class="inline_help">
|
||||
<p>Give the VM a name (e.g. Work, Gaming, Media Player, Firewall, Bitcoin Miner)</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr class="non_expert_xml">
|
||||
<td>Description:</td>
|
||||
<td><input type="text" name="domain[desc]" title="description of virtual machine" placeholder="description of virtual machine (optional)" value="<?=htmlentities($arrLoad['desc'])?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="non_expert_xml">
|
||||
<blockquote class="inline_help">
|
||||
<p>Give the VM a brief description (optional field).</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr style="line-height: 15px; vertical-align: middle;">
|
||||
<td>Autostart:</td>
|
||||
<td><div style="margin-left: -10px"><input type="checkbox" id="domain_autostart" name="domain[autostart]" style="display: none" class="autostart" value="1" <? if ($arrLoad['autostart']) echo 'checked'; ?>></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
<blockquote class="inline_help">
|
||||
<p>If you want this VM to start with the array, set this to yes.</p>
|
||||
</blockquote>
|
||||
|
||||
<div id="title">
|
||||
<span class="left"><img src="/plugins/dynamix.docker.manager/icons/preferences.png" class="icon">Template Settings</span>
|
||||
<span class="status advancedview_panel"><input type="checkbox" class="advancedview"></span>
|
||||
</div>
|
||||
|
||||
<div id="form_content"></div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="/webGui/javascript/jquery.filetree.js"></script>
|
||||
<script src="/webGui/javascript/jquery.switchbutton.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/dynamix.vm.manager.js"></script>
|
||||
<script>
|
||||
function isVMAdvancedMode() {
|
||||
return ($.cookie('vmmanager_listview_mode') == 'advanced');
|
||||
}
|
||||
function checkForAdvancedMode() {
|
||||
var $el = $('#form_content');
|
||||
|
||||
var $advanced = $el.find('.advanced');
|
||||
var $basic = $el.find('.basic');
|
||||
|
||||
if ($advanced.length || $basic.length) {
|
||||
$('.advancedview_panel').fadeIn('fast');
|
||||
if (isVMAdvancedMode()) {
|
||||
$('.basic').hide();
|
||||
$('.advanced').filter(function() {
|
||||
return (($(this).prop('style').display + '') === '');
|
||||
}).show();
|
||||
} else {
|
||||
$('.advanced').hide();
|
||||
$('.basic').filter(function() {
|
||||
return (($(this).prop('style').display + '') === '');
|
||||
}).show();
|
||||
}
|
||||
} else {
|
||||
$('.advancedview_panel').fadeOut('fast');
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$('.autostart').switchButton({
|
||||
on_label: 'Yes',
|
||||
off_label: 'No',
|
||||
labels_placement: "right"
|
||||
});
|
||||
$('.autostart').change(function () {
|
||||
$('#domain_autostart').prop('checked', $(this).is(':checked'));
|
||||
});
|
||||
|
||||
$('.advancedview').switchButton({
|
||||
labels_placement: "left",
|
||||
on_label: 'Advanced View',
|
||||
off_label: 'Basic View',
|
||||
checked: isVMAdvancedMode()
|
||||
});
|
||||
$('.advancedview').change(function () {
|
||||
toggleRows('advanced', $(this).is(':checked'), 'basic');
|
||||
$.cookie('vmmanager_listview_mode', $(this).is(':checked') ? 'advanced' : 'basic', { expires: 3650 });
|
||||
});
|
||||
|
||||
$('#domain_template').change(function loadDomainTemplate(){
|
||||
var $el = $('#form_content');
|
||||
var templateName = $(this).val();
|
||||
|
||||
toggleRows('non_expert_xml', (templateName != 'XML_Expert'));
|
||||
|
||||
$el.fadeOut(100, function(){
|
||||
$el.html('<div style="padding-left: 80px; padding-top: 20px; font-size: 1.3em"><img src="/webGui/images/spinner.gif"> Loading...</div>').fadeIn('fast');
|
||||
});
|
||||
|
||||
$.get('/plugins/dynamix.vm.manager/templates/' + templateName + '.form.php' + location.search, function(data) {
|
||||
$el.stop(true, false).fadeOut(100, function() {
|
||||
$el.html(data);
|
||||
|
||||
checkForAdvancedMode();
|
||||
|
||||
if ($.cookie('help')=='help') {
|
||||
$('.inline_help').show();
|
||||
}
|
||||
|
||||
$el.fadeIn('fast');
|
||||
});
|
||||
});
|
||||
}).change(); // Fire now too
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,40 @@
|
||||
Menu="Tasks:70"
|
||||
Type="xmenu"
|
||||
Cond="(pgrep('libvirtd')!==false)"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<link type="text/css" rel="stylesheet" href="/plugins/dynamix.vm.manager/styles/dynamix.vm.manager.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/context.standalone.css">
|
||||
<style type="text/css">
|
||||
body{-webkit-overflow-scrolling:touch;}
|
||||
.fileTree{width:305px;max-height:150px;overflow:scroll;position:absolute;z-index:100;display:none;}
|
||||
</style>
|
||||
<script src="/webGui/javascript/jquery.filetree.js"></script>
|
||||
<script src="/webGui/javascript/jquery.switchbutton.js"></script>
|
||||
<script src="/webGui/javascript/context.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/dynamix.vm.manager.js"></script>
|
||||
|
||||
<?
|
||||
if ($var['fsState'] != "Started") {
|
||||
echo "<p class='notice'>Array must be Started to manage Virtual Machines.</p>";
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt_helpers.php');
|
||||
|
||||
if (count($pages)==2) $tabbed = false;
|
||||
?>
|
||||
@@ -0,0 +1,542 @@
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
|
||||
// Load emhttp variables if needed.
|
||||
if (! isset($var)){
|
||||
if (! is_file("/usr/local/emhttp/state/var.ini")) shell_exec("wget -qO /dev/null localhost:$(lsof -nPc emhttp | grep -Po 'TCP[^\d]*\K\d+')");
|
||||
$var = @parse_ini_file("/usr/local/emhttp/state/var.ini");
|
||||
}
|
||||
|
||||
|
||||
// Check if program is running and
|
||||
$libvirt_running = trim(shell_exec( "[ -f /proc/`cat /var/run/libvirt/libvirtd.pid 2> /dev/null`/exe ] && echo 'yes' || echo 'no' 2> /dev/null" ));
|
||||
|
||||
// Create domain config if needed
|
||||
$domain_cfgfile = "/boot/config/domain.cfg";
|
||||
if (!file_exists($domain_cfgfile)) {
|
||||
file_put_contents($domain_cfgfile, 'SERVICE="disable"'."\n".'DEBUG="no"'."\n".'MEDIADIR="/mnt/"'."\n".'VIRTIOISO=""'."\n".'DISKDIR="/mnt/"'."\n".'BRNAME=""'."\n");
|
||||
} else {
|
||||
// This will clean any ^M characters (\r) caused by windows from the config file
|
||||
shell_exec("sed -i 's!\r!!g' '$domain_cfgfile'");
|
||||
}
|
||||
|
||||
$domain_cfg = parse_ini_file($domain_cfgfile);
|
||||
|
||||
if (!isset($domain_cfg['VIRTIOISO'])) {
|
||||
$domain_cfg['VIRTIOISO'] = "";
|
||||
}
|
||||
|
||||
$domain_debug = isset($domain_cfg['DEBUG']) ? $domain_cfg['DEBUG'] : "no";
|
||||
if ($domain_debug != "yes") {
|
||||
error_reporting(0);
|
||||
}
|
||||
|
||||
$domain_bridge = (!($domain_cfg['BRNAME'])) ? 'virbr0' : $domain_cfg['BRNAME'];
|
||||
$msg = (empty($domain_bridge)) ? "Error: Setup Bridge in Settings/Network Settings" : false;
|
||||
$libvirt_service = isset($domain_cfg['SERVICE']) ? $domain_cfg['SERVICE'] : "disable";
|
||||
|
||||
if ($libvirt_running == "yes"){
|
||||
$lv = new Libvirt('qemu:///system', null, null, false);
|
||||
$arrHostInfo = $lv->host_get_node_info();
|
||||
$maxcpu = (int)$arrHostInfo['cpus'];
|
||||
$maxmem = number_format(($arrHostInfo['memory'] / 1048576), 1, '.', ' ');
|
||||
}
|
||||
|
||||
$theme = $display['theme'];
|
||||
//set color on even rows for white or black theme
|
||||
function bcolor($row, $color) {
|
||||
if ($color == "white")
|
||||
$color = ($row % 2 == 0) ? "transparent" : "#F8F8F8";
|
||||
else
|
||||
$color = ($row % 2 == 0) ? "transparent" : "#0C0C0C";
|
||||
return $color;
|
||||
}
|
||||
|
||||
//create checkboxes for usb devices
|
||||
function usb_checkbox($usb, $key) {
|
||||
$deviceid = substr(strstr($usb, 'ID'),3,9);
|
||||
echo '<input class="checkbox" type="checkbox" value="'.$deviceid.'" name="usb['.$key.']" />';
|
||||
echo "<label>$usb</label><br />";
|
||||
}
|
||||
|
||||
//create memory drop down option based on max memory
|
||||
function memOption($maxmem) {
|
||||
for ($i = 1; $i <= ($maxmem*2); $i++) {
|
||||
$mem = ($i*512);
|
||||
echo "<option value='$mem'>$mem</option>";
|
||||
}
|
||||
}
|
||||
|
||||
//create drop down options from arrays
|
||||
function arrayOptions($ValueArray, $DisplayArray, $value) {
|
||||
for ($i = 0; $i < sizeof($ValueArray); $i++) {
|
||||
echo "<option value='$ValueArray[$i]'";
|
||||
if ($ValueArray[$i] == $value)
|
||||
echo " selected='selected'>$DisplayArray[$i] *</option>";
|
||||
else
|
||||
echo ">$DisplayArray[$i]</option>";
|
||||
}
|
||||
}
|
||||
|
||||
//create memory drop down options
|
||||
function memOptions($maxmem, $mem) {
|
||||
for ($i = 1; $i <= ($maxmem*2); $i++) {
|
||||
$mem2 = ($i*512);
|
||||
echo "<option value=".$mem2*1024;
|
||||
if ((int)$mem == $mem2*1024)
|
||||
echo " selected='selected'>$mem2 *</option>";
|
||||
else
|
||||
echo ">$mem2</option>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mk_dropdown_options($arrOptions, $strSelected) {
|
||||
foreach ($arrOptions as $key => $label) {
|
||||
echo mk_option($strSelected, $key, $label);
|
||||
}
|
||||
}
|
||||
|
||||
function appendOrdinalSuffix($number) {
|
||||
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
|
||||
|
||||
if (($number % 100) >= 11 && ($number % 100) <= 13) {
|
||||
$abbreviation = $number . 'th';
|
||||
} else {
|
||||
$abbreviation = $number . $ends[$number % 10];
|
||||
}
|
||||
|
||||
return $abbreviation;
|
||||
}
|
||||
|
||||
|
||||
$cacheValidPCIDevices = null;
|
||||
function getValidPCIDevices() {
|
||||
global $cacheValidPCIDevices;
|
||||
|
||||
if (!is_null($cacheValidPCIDevices)) {
|
||||
return $cacheValidPCIDevices;
|
||||
}
|
||||
|
||||
$strOSUSBController = trim(shell_exec("udevadm info -q path -n /dev/disk/by-label/UNRAID 2>/dev/null | grep -Po '0000:\K\w{2}:\w{2}\.\w{1}'"));
|
||||
$strOSNetworkDevice = trim(shell_exec("udevadm info -q path -p /sys/class/net/eth0 2>/dev/null | grep -Po '0000:\K\w{2}:\w{2}\.\w{1}'"));
|
||||
|
||||
//TODO: add any drive controllers currently being used by unraid to the blacklist
|
||||
|
||||
$arrBlacklistIDs = array($strOSUSBController, $strOSNetworkDevice);
|
||||
$arrBlacklistClassIDregex = '/^(05|06|08|0a|0b|0c05)/';
|
||||
// Got Class IDs at the bottom of /usr/share/hwdata/pci.ids
|
||||
$arrWhitelistGPUClassIDregex = '/^(0001|03)/';
|
||||
$arrWhitelistAudioClassIDregex = '/^(0403)/';
|
||||
|
||||
$arrValidPCIDevices = array();
|
||||
|
||||
exec("lspci -m -nn 2>/dev/null", $arrAllPCIDevices);
|
||||
|
||||
foreach ($arrAllPCIDevices as $strPCIDevice) {
|
||||
// Example: 00:1f.0 "ISA bridge [0601]" "Intel Corporation [8086]" "Z77 Express Chipset LPC Controller [1e44]" -r04 "Micro-Star International Co., Ltd. [MSI] [1462]" "Device [7759]"
|
||||
if (preg_match('/^(?P<id>\S+) \"(?P<type>[^"]+) \[(?P<typeid>[a-f0-9]{4})\]\" \"(?P<vendorname>[^"]+) \[(?P<vendorid>[a-f0-9]{4})\]\" \"(?P<productname>[^"]+) \[(?P<productid>[a-f0-9]{4})\]\"/', $strPCIDevice, $arrMatch)) {
|
||||
if (in_array($arrMatch['id'], $arrBlacklistIDs) || preg_match($arrBlacklistClassIDregex, $arrMatch['typeid'])) {
|
||||
// Device blacklisted, skip device
|
||||
continue;
|
||||
}
|
||||
|
||||
$strClass = 'other';
|
||||
if (preg_match($arrWhitelistGPUClassIDregex, $arrMatch['typeid'])) {
|
||||
$strClass = 'vga';
|
||||
// Specialized product name cleanup for GPU
|
||||
// GF116 [GeForce GTX 550 Ti] --> GeForce GTX 550 Ti
|
||||
if (preg_match('/.+\[(?P<gpuname>.+)\]/', $arrMatch['productname'], $arrGPUMatch)) {
|
||||
$arrMatch['productname'] = $arrGPUMatch['gpuname'];
|
||||
}
|
||||
} else if (preg_match($arrWhitelistAudioClassIDregex, $arrMatch['typeid'])) {
|
||||
$strClass = 'audio';
|
||||
}
|
||||
|
||||
if ($strClass == 'vga' &&
|
||||
strpos($arrMatch['id'], '00:') === 0 &&
|
||||
(stripos($arrMatch['productname'], 'integrated') !== false || strpos($arrMatch['vendorname'], 'Intel ') !== false)) {
|
||||
// Our sorry attempt to detect a integrated gpu
|
||||
// Integrated gpus dont work for passthrough, skip device
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!file_exists('/sys/bus/pci/devices/0000:' . $arrMatch['id'] . '/iommu_group/')) {
|
||||
// No IOMMU support for device, skip device
|
||||
continue;
|
||||
}
|
||||
|
||||
// Specialized vendor name cleanup
|
||||
// e.g.: Advanced Micro Devices, Inc. [AMD/ATI] --> Advanced Micro Devices, Inc.
|
||||
if (preg_match('/(?P<gpuvendor>.+) \[.+\]/', $arrMatch['vendorname'], $arrGPUMatch)) {
|
||||
$arrMatch['vendorname'] = $arrGPUMatch['gpuvendor'];
|
||||
}
|
||||
|
||||
// Clean up the vendor and product name
|
||||
$arrMatch['vendorname'] = str_replace(['Advanced Micro Devices, Inc.'], 'AMD', $arrMatch['vendorname']);
|
||||
$arrMatch['vendorname'] = str_replace([' Corporation', ' Semiconductor Co., Ltd.', ' Technology Group Ltd.', ' Electronics Systems Ltd.', ' Systems, Inc.'], '', $arrMatch['vendorname']);
|
||||
$arrMatch['productname'] = str_replace([' PCI Express'], [' PCIe'], $arrMatch['productname']);
|
||||
|
||||
$arrValidPCIDevices[] = array(
|
||||
'id' => $arrMatch['id'],
|
||||
'type' => $arrMatch['type'],
|
||||
'typeid' => $arrMatch['typeid'],
|
||||
'vendorid' => $arrMatch['vendorid'],
|
||||
'vendorname' => $arrMatch['vendorname'],
|
||||
'productid' => $arrMatch['productid'],
|
||||
'productname' => $arrMatch['productname'],
|
||||
'class' => $strClass,
|
||||
'name' => $arrMatch['vendorname'] . ' ' . $arrMatch['productname']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$cacheValidPCIDevices = $arrValidPCIDevices;
|
||||
|
||||
return $arrValidPCIDevices;
|
||||
}
|
||||
|
||||
|
||||
function getValidGPUDevices() {
|
||||
$arrValidPCIDevices = getValidPCIDevices();
|
||||
|
||||
$arrValidGPUDevices = array_filter($arrValidPCIDevices, function($arrDev) {
|
||||
return ($arrDev['class'] == 'vga');
|
||||
});
|
||||
|
||||
return $arrValidGPUDevices;
|
||||
}
|
||||
|
||||
|
||||
function getValidAudioDevices() {
|
||||
$arrValidPCIDevices = getValidPCIDevices();
|
||||
|
||||
$arrValidAudioDevices = array_filter($arrValidPCIDevices, function($arrDev) {
|
||||
return ($arrDev['class'] == 'audio');
|
||||
});
|
||||
|
||||
return $arrValidAudioDevices;
|
||||
}
|
||||
|
||||
|
||||
function getValidOtherDevices() {
|
||||
$arrValidPCIDevices = getValidPCIDevices();
|
||||
|
||||
$arrValidOtherDevices = array_filter($arrValidPCIDevices, function($arrDev) {
|
||||
return ($arrDev['class'] == 'other');
|
||||
});
|
||||
|
||||
return $arrValidOtherDevices;
|
||||
}
|
||||
|
||||
|
||||
$cacheValidUSBDevices = null;
|
||||
function getValidUSBDevices() {
|
||||
global $cacheValidUSBDevices;
|
||||
|
||||
if (!is_null($cacheValidUSBDevices)) {
|
||||
return $cacheValidUSBDevices;
|
||||
}
|
||||
|
||||
$arrValidUSBDevices = array();
|
||||
|
||||
// Get a list of all usb hubs so we can blacklist them
|
||||
exec("cat /sys/bus/usb/drivers/hub/*/modalias | grep -Po 'usb:v\K\w{9}' | tr 'p' ':'", $arrAllUSBHubs);
|
||||
|
||||
exec("lsusb 2>/dev/null", $arrAllUSBDevices);
|
||||
|
||||
foreach ($arrAllUSBDevices as $strUSBDevice) {
|
||||
if (preg_match('/^.+ID (?P<id>\S+) (?P<name>.+)$/', $strUSBDevice, $arrMatch)) {
|
||||
$arrMatch['name'] = trim($arrMatch['name']);
|
||||
|
||||
if (empty($arrMatch['name'])) {
|
||||
// Device name is blank, replace using fallback default
|
||||
$arrMatch['name'] = 'unnamed device ('.$arrMatch['id'].')';
|
||||
}
|
||||
|
||||
if (stripos($GLOBALS['var']['flashGUID'], str_replace(':', '-', $arrMatch['id'])) === 0) {
|
||||
// Device id matches the unraid boot device, skip device
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array(strtoupper($arrMatch['id']), $arrAllUSBHubs)) {
|
||||
// Device class is a Hub, skip device
|
||||
continue;
|
||||
}
|
||||
|
||||
$arrValidUSBDevices[] = array(
|
||||
'id' => $arrMatch['id'],
|
||||
'name' => $arrMatch['name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$cacheValidUSBDevices = $arrValidUSBDevices;
|
||||
|
||||
return $arrValidUSBDevices;
|
||||
}
|
||||
|
||||
|
||||
function getValidMachineTypes() {
|
||||
global $lv;
|
||||
|
||||
$arrValidMachineTypes = [];
|
||||
|
||||
$arrQEMUInfo = $lv->get_connect_information();
|
||||
$arrMachineTypes = $lv->get_machine_types('x86_64');
|
||||
|
||||
$strQEMUVersion = $arrQEMUInfo['hypervisor_major'] . '.' . $arrQEMUInfo['hypervisor_minor'];
|
||||
|
||||
foreach ($arrMachineTypes as $arrMachine) {
|
||||
if ($arrMachine['name'] == 'q35') {
|
||||
// Latest Q35
|
||||
$arrValidMachineTypes['pc-q35-' . $strQEMUVersion] = 'Q35-' . $strQEMUVersion;
|
||||
}
|
||||
if (strpos($arrMachine['name'], 'q35-') !== false) {
|
||||
// Prior releases of Q35
|
||||
$arrValidMachineTypes[$arrMachine['name']] = str_replace(['q35', 'pc-'], ['Q35', ''], $arrMachine['name']);
|
||||
}
|
||||
if ($arrMachine['name'] == 'pc') {
|
||||
// Latest i440fx
|
||||
$arrValidMachineTypes['pc-i440fx-' . $strQEMUVersion] = 'i440fx-' . $strQEMUVersion;
|
||||
}
|
||||
if (strpos($arrMachine['name'], 'i440fx-') !== false) {
|
||||
// Prior releases of i440fx
|
||||
$arrValidMachineTypes[$arrMachine['name']] = str_replace('pc-', '', $arrMachine['name']);
|
||||
}
|
||||
}
|
||||
|
||||
arsort($arrValidMachineTypes);
|
||||
|
||||
return $arrValidMachineTypes;
|
||||
}
|
||||
|
||||
|
||||
function getLatestMachineType($strType = 'i440fx') {
|
||||
$arrMachineTypes = getValidMachineTypes();
|
||||
|
||||
foreach ($arrMachineTypes as $key => $value) {
|
||||
if (stripos($key, $strType) !== false) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return array_shift(array_keys($arrMachineTypes));
|
||||
}
|
||||
|
||||
|
||||
function getValidDiskDrivers() {
|
||||
$arrValidDiskDrivers = [
|
||||
'raw' => 'raw',
|
||||
'qcow2' => 'qcow2'
|
||||
];
|
||||
|
||||
return $arrValidDiskDrivers;
|
||||
}
|
||||
|
||||
|
||||
function getValidKeyMaps() {
|
||||
$arrValidKeyMaps = [
|
||||
'ar' => 'Arabic (ar)',
|
||||
'hr' => 'Croatian (hr)',
|
||||
'cz' => 'Czech (cz)',
|
||||
'da' => 'Danish (da)',
|
||||
'nl' => 'Dutch (nl)',
|
||||
'nl-be' => 'Dutch-Belgium (nl-be)',
|
||||
'en-gb' => 'English-United Kingdom (en-gb)',
|
||||
'en-us' => 'English-United States (en-us)',
|
||||
'es' => 'Español (es)',
|
||||
'et' => 'Estonian (et)',
|
||||
'fo' => 'Faroese (fo)',
|
||||
'fi' => 'Finnish (fi)',
|
||||
'fr' => 'French (fr)',
|
||||
'bepo' => 'French-Bépo (bepo)',
|
||||
'fr-be' => 'French-Belgium (fr-be)',
|
||||
'fr-ca' => 'French-Canadian (fr-ca)',
|
||||
'fr-ch' => 'French-Switzerland (fr-ch)',
|
||||
'de-ch' => 'German-Switzerland (de-ch)',
|
||||
'hu' => 'Hungarian (hu)',
|
||||
'is' => 'Icelandic (is)',
|
||||
'it' => 'Italian (it)',
|
||||
'ja' => 'Japanese (ja)',
|
||||
'lv' => 'Latvian (lv)',
|
||||
'lt' => 'Lithuanian (lt)',
|
||||
'mk' => 'Macedonian (mk)',
|
||||
'no' => 'Norwegian (no)',
|
||||
'pl' => 'Polish (pl)',
|
||||
'pt-br' => 'Portuguese-Brazil (pt-br)',
|
||||
'ru' => 'Russian (ru)',
|
||||
'sl' => 'Slovene (sl)',
|
||||
'sv' => 'Swedish (sv)',
|
||||
'th' => 'Thailand (th)',
|
||||
'tr' => 'Turkish (tr)'
|
||||
];
|
||||
|
||||
return $arrValidKeyMaps;
|
||||
}
|
||||
|
||||
|
||||
function getHostCPUModel() {
|
||||
$cpu = explode('#', exec("dmidecode -q -t 4|awk -F: '{if(/Version:/) v=$2; else if(/Current Speed:/) s=$2} END{print v\"#\"s}'"));
|
||||
list($strCPUModel) = explode('@', str_replace(array("Processor","CPU","(C)","(R)","(TM)"), array("","","©","®","™"), $cpu[0]) . '@');
|
||||
return trim($strCPUModel);
|
||||
}
|
||||
|
||||
|
||||
function getNetworkBridges() {
|
||||
exec("brctl show | awk -F'\t' 'FNR > 1 {print \$1}' | awk 'NF > 0'", $arrValidBridges);
|
||||
|
||||
if (!is_array($arrValidBridges)) {
|
||||
$arrValidBridges = [];
|
||||
}
|
||||
|
||||
// Make sure the default libvirt bridge is first in the list
|
||||
if (($key = array_search('virbr0', $arrValidBridges)) !== false) {
|
||||
unset($arrValidBridges[$key]);
|
||||
}
|
||||
// We always list virbr0 because libvirt might not be started yet (thus the bridge doesn't exists)
|
||||
array_unshift($arrValidBridges, 'virbr0');
|
||||
|
||||
return array_values($arrValidBridges);
|
||||
}
|
||||
|
||||
|
||||
function domain_to_config($uuid) {
|
||||
global $lv;
|
||||
|
||||
$arrValidGPUDevices = getValidGPUDevices();
|
||||
$arrValidAudioDevices = getValidAudioDevices();
|
||||
$arrValidOtherDevices = getValidOtherDevices();
|
||||
$arrValidUSBDevices = getValidUSBDevices();
|
||||
$arrValidDiskDrivers = getValidDiskDrivers();
|
||||
|
||||
$res = $lv->domain_get_domain_by_uuid($uuid);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$medias = $lv->get_cdrom_stats($res);
|
||||
$disks = $lv->get_disk_stats($res, false);
|
||||
$arrNICs = $lv->get_nic_info($res);
|
||||
$arrHostDevs = $lv->domain_get_host_devices_pci($res);
|
||||
$arrUSBDevs = $lv->domain_get_host_devices_usb($res);
|
||||
|
||||
|
||||
// Metadata Parsing
|
||||
// libvirt xpath parser sucks, use php's xpath parser instead
|
||||
$strDOMXML = $lv->domain_get_xml($res);
|
||||
$xmldoc = new DOMDocument();
|
||||
$xmldoc->loadXML($strDOMXML);
|
||||
$xpath = new DOMXPath($xmldoc);
|
||||
$objNodes = $xpath->query('//domain/metadata/vmtemplate/@*');
|
||||
|
||||
$arrTemplateValues = [];
|
||||
if ($objNodes->length > 0) {
|
||||
foreach ($objNodes as $objNode) {
|
||||
$arrTemplateValues[$objNode->nodeName] = $objNode->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($arrTemplateValues['name'])) {
|
||||
$arrTemplateValues['name'] = 'Custom';
|
||||
}
|
||||
|
||||
|
||||
$arrGPUDevices = [];
|
||||
$arrAudioDevices = [];
|
||||
$arrOtherDevices = [];
|
||||
|
||||
// check for vnc; add to arrGPUDevices
|
||||
$intVNCPort = $lv->domain_get_vnc_port($res);
|
||||
if (!empty($intVNCPort)) {
|
||||
$arrGPUDevices[] = [
|
||||
'id' => 'vnc',
|
||||
'keymap' => $lv->domain_get_vnc_keymap($res)
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($arrHostDevs as $arrHostDev) {
|
||||
$arrFoundGPUDevices = array_filter($arrValidGPUDevices, function($arrDev) use ($arrHostDev) { return ($arrDev['id'] == $arrHostDev['id']); });
|
||||
if (!empty($arrFoundGPUDevices)) {
|
||||
$arrGPUDevices[] = ['id' => $arrHostDev['id']];
|
||||
continue;
|
||||
}
|
||||
|
||||
$arrFoundAudioDevices = array_filter($arrValidAudioDevices, function($arrDev) use ($arrHostDev) { return ($arrDev['id'] == $arrHostDev['id']); });
|
||||
if (!empty($arrFoundAudioDevices)) {
|
||||
$arrAudioDevices[] = ['id' => $arrHostDev['id']];
|
||||
continue;
|
||||
}
|
||||
|
||||
$arrFoundOtherDevices = array_filter($arrValidOtherDevices, function($arrDev) use ($arrHostDev) { return ($arrDev['id'] == $arrHostDev['id']); });
|
||||
if (!empty($arrFoundOtherDevices)) {
|
||||
$arrOtherDevices[] = ['id' => $arrHostDev['id']];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Add claimed USB devices by this VM to the available USB devices
|
||||
/*
|
||||
foreach($arrUSBDevs as $arrUSB) {
|
||||
$arrValidUSBDevices[] = array(
|
||||
'id' => $arrUSB['id'],
|
||||
'name' => $arrUSB['product'],
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
$arrDisks = [];
|
||||
foreach ($disks as $disk) {
|
||||
$arrDisks[] = [
|
||||
'new' => (empty($disk['file']) ? $disk['partition'] : $disk['file']),
|
||||
'size' => '',
|
||||
'driver' => 'raw',
|
||||
'dev' => $disk['device'],
|
||||
'bus' => $disk['bus']
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'template' => $arrTemplateValues,
|
||||
'domain' => [
|
||||
'name' => $lv->domain_get_name($res),
|
||||
'desc' => $lv->domain_get_description($res),
|
||||
'persistent' => 1,
|
||||
'uuid' => $lv->domain_get_uuid($res),
|
||||
'clock' => $lv->domain_get_clock_offset($res),
|
||||
'arch' => $lv->domain_get_arch($res),
|
||||
'machine' => $lv->domain_get_machine($res),
|
||||
'mem' => $lv->domain_get_current_memory($res),
|
||||
'maxmem' => $lv->domain_get_memory($res),
|
||||
'password' => '', //TODO?
|
||||
'cpumode' => $lv->domain_get_cpu_type($res),
|
||||
'vcpus' => $dom['nrVirtCpu'],
|
||||
'vcpu' => $lv->domain_get_vcpu_pins($res),
|
||||
'hyperv' => ($lv->domain_get_feature($res, 'hyperv') ? 1 : 0),
|
||||
'autostart' => ($lv->domain_get_autostart($res) ? 1 : 0),
|
||||
'state' => $lv->domain_state_translate($dom['state']),
|
||||
'ovmf' => ($lv->domain_get_ovmf($res) ? 1 : 0)
|
||||
],
|
||||
'media' => [
|
||||
'cdrom' => (!empty($medias) && !empty($medias[0]) && array_key_exists('file', $medias[0])) ? $medias[0]['file'] : '',
|
||||
'drivers' => (!empty($medias) && !empty($medias[1]) && array_key_exists('file', $medias[1])) ? $medias[1]['file'] : ''
|
||||
],
|
||||
'disk' => $arrDisks,
|
||||
'gpu' => $arrGPUDevices,
|
||||
'audio' => $arrAudioDevices,
|
||||
'pci' => $arrOtherDevices,
|
||||
'nic' => $arrNICs,
|
||||
'usb' => $arrUSBDevs,
|
||||
'shares' => $lv->domain_get_mount_filesystems($res)
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env php
|
||||
|
||||
<?php
|
||||
if (!isset($argv[2]) || $argv[2] != 'start') {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$strXML = file_get_contents('php://stdin');
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadXML($strXML);
|
||||
|
||||
$xpath = new DOMXpath($doc);
|
||||
|
||||
$args = $xpath->evaluate("//domain/*[name()='qemu:commandline']/*[name()='qemu:arg']/@value");
|
||||
|
||||
for ($i = 0; $i < $args->length; $i++){
|
||||
$arg_list = explode(',', $args->item($i)->nodeValue);
|
||||
|
||||
if ($arg_list[0] !== 'vfio-pci') {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($arg_list as $arg) {
|
||||
$keypair = explode('=', $arg);
|
||||
|
||||
if ($keypair[0] == 'host' && !empty($keypair[1])) {
|
||||
vfio_bind($keypair[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(0); // end of script
|
||||
|
||||
|
||||
|
||||
function vfio_bind($strPassthruDevice) {
|
||||
// Ensure we have leading 0000:
|
||||
$strPassthruDeviceShort = str_replace('0000:', '', $strPassthruDevice);
|
||||
$strPassthruDeviceLong = '0000:' . $strPassthruDeviceShort;
|
||||
|
||||
// Determine the driver currently assigned to the device
|
||||
$strDriverSymlink = @readlink('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver');
|
||||
|
||||
if ($strDriverSymlink !== false) {
|
||||
// Device is bound to a Driver already
|
||||
|
||||
if (strpos($strDriverSymlink, 'vfio-pci') !== false) {
|
||||
// Driver bound to vfio-pci already - nothing left to do for this device now regarding vfio
|
||||
return true;
|
||||
}
|
||||
|
||||
// Driver bound to some other driver - attempt to unbind driver
|
||||
if (file_put_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver/unbind', $strPassthruDeviceLong) === false) {
|
||||
file_put_contents('php://stderr', 'Failed to unbind device ' . $strPassthruDeviceShort . ' from current driver');
|
||||
exit(1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get Vendor and Device IDs for the passthru device
|
||||
$strVendor = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/vendor');
|
||||
$strDevice = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/device');
|
||||
|
||||
// Attempt to bind driver to vfio-pci
|
||||
if (file_put_contents('/sys/bus/pci/drivers/vfio-pci/new_id', $strVendor . ' ' . $strDevice) === false) {
|
||||
file_put_contents('php://stderr', 'Failed to bind device ' . $strPassthruDeviceShort . ' to vfio-pci driver');
|
||||
exit(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Only start if array has started in Normal operation mode
|
||||
if grep -q 'fsState="Started"' /var/local/emhttp/var.ini && grep -q 'startMode="Normal"' /var/local/emhttp/var.ini; then
|
||||
|
||||
SERVICE="disable"
|
||||
if [ -f /boot/config/domain.cfg ]; then
|
||||
source /boot/config/domain.cfg
|
||||
fi
|
||||
|
||||
#copy old image to new
|
||||
if [ -f /boot/config/plugins/virtMan/virtMan.img ]; then
|
||||
if [ "$(mount | grep virtMan.img)" ]; then
|
||||
umount /etc/libvirt
|
||||
fi
|
||||
if [ ! -f /boot/config/plugins/dynamix.kvm.manager/domain.img ]; then
|
||||
mkdir -p /boot/config/plugins/dynamix.kvm.manager
|
||||
cp /boot/config/plugins/virtMan/virtMan.img /boot/config/plugins/dynamix.kvm.manager/domain.img
|
||||
fi
|
||||
fi
|
||||
|
||||
#copy seed loopback image and qemu hook, if needed, to flash drive
|
||||
if [ -d /usr/local/emhttp/plugins/dynamix.vm.manager/dynamix.kvm.manager ]; then
|
||||
mkdir -p /boot/config/plugins/dynamix.kvm.manager
|
||||
tar --no-same-owner -xkf /usr/local/emhttp/plugins/dynamix.vm.manager/dynamix.kvm.manager/domain.tar.xz -C /boot/config/plugins/dynamix.kvm.manager/
|
||||
cp -n /usr/local/emhttp/plugins/dynamix.vm.manager/dynamix.kvm.manager/qemu /boot/config/plugins/dynamix.kvm.manager/
|
||||
fi
|
||||
|
||||
if [ "$SERVICE" = "enable" ]; then
|
||||
# mount xml/conf image if not already mounted
|
||||
if [ ! "$(mount | grep domain.img)" ]; then
|
||||
mount -t ext4 /boot/config/plugins/dynamix.kvm.manager/domain.img /etc/libvirt
|
||||
mkdir -p /etc/libvirt/hooks
|
||||
cp /boot/config/plugins/dynamix.kvm.manager/qemu /etc/libvirt/hooks/
|
||||
fi
|
||||
|
||||
# Start libvirt
|
||||
if [ -x /etc/rc.d/rc.libvirt ]; then
|
||||
echo "Starting libvirt..."
|
||||
/etc/rc.d/rc.libvirt start |& logger
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Shutdown libvirt
|
||||
if [ -x /etc/rc.d/rc.libvirt ]; then
|
||||
echo "Stopping libvirt..."
|
||||
/etc/rc.d/rc.libvirt stop |& logger
|
||||
fi
|
||||
|
||||
if [ "$(mount | grep domain.img)" ]; then
|
||||
umount /etc/libvirt
|
||||
fi
|
||||
|
After Width: | Height: | Size: 875 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 812 B |
|
After Width: | Height: | Size: 693 B |
|
After Width: | Height: | Size: 628 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 816 B |
|
After Width: | Height: | Size: 339 B |
|
After Width: | Height: | Size: 842 B |
|
After Width: | Height: | Size: 501 B |
|
After Width: | Height: | Size: 404 B |
|
After Width: | Height: | Size: 354 B |
|
After Width: | Height: | Size: 317 B |
|
After Width: | Height: | Size: 579 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 963 B |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 385 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 453 B |
|
After Width: | Height: | Size: 851 B |
|
After Width: | Height: | Size: 532 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 511 B |
|
After Width: | Height: | Size: 517 B |
|
After Width: | Height: | Size: 497 B |
|
After Width: | Height: | Size: 513 B |
|
After Width: | Height: | Size: 390 B |
|
After Width: | Height: | Size: 525 B |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 735 B |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 387 B |
|
After Width: | Height: | Size: 516 B |
@@ -0,0 +1,526 @@
|
||||
/*
|
||||
* noVNC base CSS
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
|
||||
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||
*/
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
padding:0;
|
||||
font-family: Helvetica;
|
||||
/*Background image with light grey curve.*/
|
||||
background-color:#494949;
|
||||
background-repeat:no-repeat;
|
||||
background-position:right bottom;
|
||||
height:100%;
|
||||
}
|
||||
|
||||
html {
|
||||
height:100%;
|
||||
}
|
||||
|
||||
#noVNC_controls ul {
|
||||
list-style: none;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
#noVNC_controls li {
|
||||
padding-bottom:8px;
|
||||
}
|
||||
|
||||
#noVNC_host {
|
||||
width:150px;
|
||||
}
|
||||
#noVNC_port {
|
||||
width: 80px;
|
||||
}
|
||||
#noVNC_password {
|
||||
width: 150px;
|
||||
}
|
||||
#noVNC_encrypt {
|
||||
}
|
||||
#noVNC_path {
|
||||
width: 100px;
|
||||
}
|
||||
#noVNC_connect_button {
|
||||
width: 110px;
|
||||
float:right;
|
||||
}
|
||||
|
||||
#noVNC_buttons {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#noVNC_view_drag_button {
|
||||
display: none;
|
||||
}
|
||||
#sendCtrlAltDelButton {
|
||||
display: none;
|
||||
}
|
||||
#fullscreenButton {
|
||||
display: none;
|
||||
}
|
||||
#noVNC_xvp_buttons {
|
||||
display: none;
|
||||
}
|
||||
#noVNC_mobile_buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#noVNC_extra_keys {
|
||||
display: inline;
|
||||
list-style-type: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.noVNC-buttons-left {
|
||||
float: left;
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.noVNC-buttons-right {
|
||||
float:right;
|
||||
right: 0px;
|
||||
z-index: 2;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
#noVNC_status {
|
||||
font-size: 12px;
|
||||
padding-top: 4px;
|
||||
height:32px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#noVNC_settings_menu {
|
||||
margin: 3px;
|
||||
text-align: left;
|
||||
}
|
||||
#noVNC_settings_menu ul {
|
||||
list-style: none;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#noVNC_apply {
|
||||
float:right;
|
||||
}
|
||||
|
||||
/* Do not set width/height for VNC_screen or VNC_canvas or incorrect
|
||||
* scaling will occur. Canvas resizes to remote VNC settings */
|
||||
#noVNC_screen {
|
||||
display: table;
|
||||
width:100%;
|
||||
height:100%;
|
||||
background-color:#313131;
|
||||
border-bottom-right-radius: 800px 600px;
|
||||
/*border-top-left-radius: 800px 600px;*/
|
||||
}
|
||||
|
||||
#noVNC_container {
|
||||
display: none;
|
||||
position: absolute;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
bottom: 0px;
|
||||
top: 36px; /* the height of the control bar */
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#noVNC_canvas {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
#VNC_clipboard_clear_button {
|
||||
float:right;
|
||||
}
|
||||
#VNC_clipboard_text {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
#noVNC_clipboard_clear_button {
|
||||
float:right;
|
||||
}
|
||||
|
||||
/*Bubble contents divs*/
|
||||
#noVNC_settings {
|
||||
display:none;
|
||||
margin-top:73px;
|
||||
right:20px;
|
||||
position:fixed;
|
||||
}
|
||||
|
||||
#noVNC_controls {
|
||||
display:none;
|
||||
margin-top:73px;
|
||||
right:12px;
|
||||
position:fixed;
|
||||
}
|
||||
#noVNC_controls.top:after {
|
||||
right:15px;
|
||||
}
|
||||
|
||||
#noVNC_description {
|
||||
display:none;
|
||||
position:fixed;
|
||||
|
||||
margin-top:73px;
|
||||
right:20px;
|
||||
left:20px;
|
||||
padding:15px;
|
||||
color:#000;
|
||||
background:#eee; /* default background for browsers without gradient support */
|
||||
|
||||
border:2px solid #E0E0E0;
|
||||
-webkit-border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
border-radius:10px;
|
||||
}
|
||||
|
||||
#noVNC_popup_status {
|
||||
display:none;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
|
||||
margin:15px;
|
||||
margin-top:60px;
|
||||
padding:15px;
|
||||
width:auto;
|
||||
|
||||
text-align:center;
|
||||
font-weight:bold;
|
||||
word-wrap:break-word;
|
||||
color:#fff;
|
||||
background:rgba(0,0,0,0.65);
|
||||
|
||||
-webkit-border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
border-radius:10px;
|
||||
}
|
||||
|
||||
#noVNC_xvp {
|
||||
display:none;
|
||||
margin-top:73px;
|
||||
right:30px;
|
||||
position:fixed;
|
||||
}
|
||||
#noVNC_xvp.top:after {
|
||||
right:125px;
|
||||
}
|
||||
|
||||
#noVNC_clipboard {
|
||||
display:none;
|
||||
margin-top:73px;
|
||||
right:30px;
|
||||
position:fixed;
|
||||
}
|
||||
#noVNC_clipboard.top:after {
|
||||
right:85px;
|
||||
}
|
||||
|
||||
#keyboardinput {
|
||||
width:1px;
|
||||
height:1px;
|
||||
background-color:#fff;
|
||||
color:#fff;
|
||||
border:0;
|
||||
position: relative;
|
||||
left: -40px;
|
||||
z-index: -1;
|
||||
ime-mode: disabled;
|
||||
}
|
||||
|
||||
/*
|
||||
* Advanced Styling
|
||||
*/
|
||||
|
||||
.noVNC_status_normal {
|
||||
background: #b2bdcd; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #b2bdcd 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b2bdcd), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||
}
|
||||
.noVNC_status_error {
|
||||
background: #f04040; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #f04040 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f04040), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #f04040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #f04040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #f04040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #f04040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||
}
|
||||
.noVNC_status_warn {
|
||||
background: #f0f040; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #f0f040 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f0f040), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #f0f040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #f0f040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #f0f040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #f0f040 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||
}
|
||||
|
||||
/* Control bar */
|
||||
#noVNC-control-bar {
|
||||
position:fixed;
|
||||
|
||||
display:block;
|
||||
height:36px;
|
||||
left:0;
|
||||
top:0;
|
||||
width:100%;
|
||||
z-index:200;
|
||||
}
|
||||
|
||||
.noVNC_status_button {
|
||||
padding: 4px 4px;
|
||||
vertical-align: middle;
|
||||
border:1px solid #869dbc;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
background: #b2bdcd; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #b2bdcd 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b2bdcd), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b2bdcd', endColorstr='#6e84a3',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||
/*box-shadow:inset 0.4px 0.4px 0.4px #000000;*/
|
||||
}
|
||||
|
||||
.noVNC_status_button_selected {
|
||||
padding: 4px 4px;
|
||||
vertical-align: middle;
|
||||
border:1px solid #4366a9;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
background: #779ced; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #779ced 0%, #3970e0 49%, #2160dd 51%, #2463df 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#779ced), color-stop(49%,#3970e0), color-stop(51%,#2160dd), color-stop(100%,#2463df)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#779ced', endColorstr='#2463df',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* W3C */
|
||||
/*box-shadow:inset 0.4px 0.4px 0.4px #000000;*/
|
||||
}
|
||||
|
||||
.noVNC_status_button:disabled {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
|
||||
/*Settings Bubble*/
|
||||
.triangle-right {
|
||||
position:relative;
|
||||
padding:15px;
|
||||
margin:1em 0 3em;
|
||||
color:#fff;
|
||||
background:#fff; /* default background for browsers without gradient support */
|
||||
/* css3 */
|
||||
/*background:-webkit-gradient(linear, 0 0, 0 100%, from(#2e88c4), to(#075698));
|
||||
background:-moz-linear-gradient(#2e88c4, #075698);
|
||||
background:-o-linear-gradient(#2e88c4, #075698);
|
||||
background:linear-gradient(#2e88c4, #075698);*/
|
||||
-webkit-border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
border-radius:10px;
|
||||
color:#000;
|
||||
border:2px solid #E0E0E0;
|
||||
}
|
||||
|
||||
.triangle-right.top:after {
|
||||
border-color: transparent #E0E0E0;
|
||||
border-width: 20px 20px 0 0;
|
||||
bottom: auto;
|
||||
left: auto;
|
||||
right: 50px;
|
||||
top: -20px;
|
||||
}
|
||||
|
||||
.triangle-right:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
bottom:-20px; /* value = - border-top-width - border-bottom-width */
|
||||
left:50px; /* controls horizontal position */
|
||||
border-width:20px 0 0 20px; /* vary these values to change the angle of the vertex */
|
||||
border-style:solid;
|
||||
border-color:#E0E0E0 transparent;
|
||||
/* reduce the damage in FF3.0 */
|
||||
display:block;
|
||||
width:0;
|
||||
}
|
||||
|
||||
.triangle-right.top:after {
|
||||
top:-40px; /* value = - border-top-width - border-bottom-width */
|
||||
right:50px; /* controls horizontal position */
|
||||
bottom:auto;
|
||||
left:auto;
|
||||
border-width:40px 40px 0 0; /* vary these values to change the angle of the vertex */
|
||||
border-color:transparent #E0E0E0;
|
||||
}
|
||||
|
||||
/*Default noVNC logo.*/
|
||||
/* From: http://fonts.googleapis.com/css?family=Orbitron:700 */
|
||||
@font-face {
|
||||
font-family: 'Orbitron';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('?'), url('Orbitron700.woff') format('woff'),
|
||||
url('Orbitron700.ttf') format('truetype');
|
||||
}
|
||||
|
||||
#noVNC_logo {
|
||||
margin-top: 170px;
|
||||
margin-left: 10px;
|
||||
color:yellow;
|
||||
text-align:left;
|
||||
font-family: 'Orbitron', 'OrbitronTTF', sans-serif;
|
||||
line-height:90%;
|
||||
text-shadow:
|
||||
5px 5px 0 #000,
|
||||
-1px -1px 0 #000,
|
||||
1px -1px 0 #000,
|
||||
-1px 1px 0 #000,
|
||||
1px 1px 0 #000;
|
||||
}
|
||||
|
||||
|
||||
#noVNC_logo span{
|
||||
color:green;
|
||||
}
|
||||
|
||||
/* ----------------------------------------
|
||||
* Media sizing
|
||||
* ----------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
.noVNC_status_button {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#noVNC_clipboard_text {
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
#noVNC_logo {
|
||||
font-size: 180px;
|
||||
}
|
||||
|
||||
.noVNC-buttons-left {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.noVNC-buttons-right {
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
#noVNC_status {
|
||||
z-index: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
#showExtraKeysButton { display: none; }
|
||||
#toggleCtrlButton { display: inline; }
|
||||
#toggleAltButton { display: inline; }
|
||||
#sendTabButton { display: inline; }
|
||||
#sendEscButton { display: inline; }
|
||||
|
||||
/* left-align the status text on lower resolutions */
|
||||
@media screen and (max-width: 800px){
|
||||
#noVNC_status {
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
width: auto;
|
||||
float: left;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 640px){
|
||||
#noVNC_clipboard_text {
|
||||
width: 410px;
|
||||
}
|
||||
#noVNC_logo {
|
||||
font-size: 150px;
|
||||
}
|
||||
.noVNC_status_button {
|
||||
font-size: 10px;
|
||||
}
|
||||
.noVNC-buttons-left {
|
||||
padding-left: 0px;
|
||||
}
|
||||
.noVNC-buttons-right {
|
||||
padding-right: 0px;
|
||||
}
|
||||
/* collapse the extra keys on lower resolutions */
|
||||
#showExtraKeysButton {
|
||||
display: inline;
|
||||
}
|
||||
#toggleCtrlButton {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
left: 0px;
|
||||
}
|
||||
#toggleAltButton {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 65px;
|
||||
left: 0px;
|
||||
}
|
||||
#sendTabButton {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100px;
|
||||
left: 0px;
|
||||
}
|
||||
#sendEscButton {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 135px;
|
||||
left: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 321px) and (max-width: 480px) {
|
||||
#noVNC_clipboard_text {
|
||||
width: 250px;
|
||||
}
|
||||
#noVNC_logo {
|
||||
font-size: 110px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 320px) {
|
||||
.noVNC_status_button {
|
||||
font-size: 9px;
|
||||
}
|
||||
#noVNC_clipboard_text {
|
||||
width: 220px;
|
||||
}
|
||||
#noVNC_logo {
|
||||
font-size: 90px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
|
||||
|
||||
/*jslint white: false */
|
||||
/*global console */
|
||||
|
||||
var Base64 = {
|
||||
/* Convert data (an array of integers) to a Base64 string. */
|
||||
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
|
||||
base64Pad : '=',
|
||||
|
||||
encode: function (data) {
|
||||
"use strict";
|
||||
var result = '';
|
||||
var toBase64Table = Base64.toBase64Table;
|
||||
var length = data.length;
|
||||
var lengthpad = (length % 3);
|
||||
// Convert every three bytes to 4 ascii characters.
|
||||
|
||||
for (var i = 0; i < (length - 2); i += 3) {
|
||||
result += toBase64Table[data[i] >> 2];
|
||||
result += toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)];
|
||||
result += toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)];
|
||||
result += toBase64Table[data[i + 2] & 0x3f];
|
||||
}
|
||||
|
||||
// Convert the remaining 1 or 2 bytes, pad out to 4 characters.
|
||||
var j = 0;
|
||||
if (lengthpad === 2) {
|
||||
j = length - lengthpad;
|
||||
result += toBase64Table[data[j] >> 2];
|
||||
result += toBase64Table[((data[j] & 0x03) << 4) + (data[j + 1] >> 4)];
|
||||
result += toBase64Table[(data[j + 1] & 0x0f) << 2];
|
||||
result += toBase64Table[64];
|
||||
} else if (lengthpad === 1) {
|
||||
j = length - lengthpad;
|
||||
result += toBase64Table[data[j] >> 2];
|
||||
result += toBase64Table[(data[j] & 0x03) << 4];
|
||||
result += toBase64Table[64];
|
||||
result += toBase64Table[64];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
/* Convert Base64 data to a string */
|
||||
/* jshint -W013 */
|
||||
toBinaryTable : [
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
|
||||
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
|
||||
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
|
||||
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
|
||||
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
|
||||
],
|
||||
/* jshint +W013 */
|
||||
|
||||
decode: function (data, offset) {
|
||||
"use strict";
|
||||
offset = typeof(offset) !== 'undefined' ? offset : 0;
|
||||
var toBinaryTable = Base64.toBinaryTable;
|
||||
var base64Pad = Base64.base64Pad;
|
||||
var result, result_length;
|
||||
var leftbits = 0; // number of bits decoded, but yet to be appended
|
||||
var leftdata = 0; // bits decoded, but yet to be appended
|
||||
var data_length = data.indexOf('=') - offset;
|
||||
|
||||
if (data_length < 0) { data_length = data.length - offset; }
|
||||
|
||||
/* Every four characters is 3 resulting numbers */
|
||||
result_length = (data_length >> 2) * 3 + Math.floor((data_length % 4) / 1.5);
|
||||
result = new Array(result_length);
|
||||
|
||||
// Convert one by one.
|
||||
for (var idx = 0, i = offset; i < data.length; i++) {
|
||||
var c = toBinaryTable[data.charCodeAt(i) & 0x7f];
|
||||
var padding = (data.charAt(i) === base64Pad);
|
||||
// Skip illegal characters and whitespace
|
||||
if (c === -1) {
|
||||
console.error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Collect data into leftdata, update bitcount
|
||||
leftdata = (leftdata << 6) | c;
|
||||
leftbits += 6;
|
||||
|
||||
// If we have 8 or more bits, append 8 bits to the result
|
||||
if (leftbits >= 8) {
|
||||
leftbits -= 8;
|
||||
// Append if not padding.
|
||||
if (!padding) {
|
||||
result[idx++] = (leftdata >> leftbits) & 0xff;
|
||||
}
|
||||
leftdata &= (1 << leftbits) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any bits left, the base64 string was corrupted
|
||||
if (leftbits) {
|
||||
err = new Error('Corrupted base64 string');
|
||||
err.name = 'Base64-Error';
|
||||
throw err;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}; /* End of Base64 namespace */
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* noVNC black CSS
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
|
||||
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||
*/
|
||||
|
||||
#keyboardinput {
|
||||
background-color:#000;
|
||||
}
|
||||
|
||||
.noVNC_status_normal {
|
||||
background: #4c4c4c; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||
}
|
||||
.noVNC_status_error {
|
||||
background: #f04040; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #f04040 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f04040), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||
}
|
||||
.noVNC_status_warn {
|
||||
background: #f0f040; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #f0f040 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f0f040), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||
}
|
||||
|
||||
.triangle-right {
|
||||
border:2px solid #fff;
|
||||
background:#000;
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
.noVNC_status_button {
|
||||
font-size: 12px;
|
||||
vertical-align: middle;
|
||||
border:1px solid #4c4c4c;
|
||||
|
||||
background: #4c4c4c; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||
}
|
||||
|
||||
.noVNC_status_button_selected {
|
||||
background: #9dd53a; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* W3C */
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* noVNC blue CSS
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
|
||||
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||
*/
|
||||
|
||||
.noVNC_status_normal {
|
||||
background-color:#04073d;
|
||||
background-image: -webkit-gradient(
|
||||
linear,
|
||||
left bottom,
|
||||
left top,
|
||||
color-stop(0.54, rgb(10,15,79)),
|
||||
color-stop(0.5, rgb(4,7,61))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
center bottom,
|
||||
rgb(10,15,79) 54%,
|
||||
rgb(4,7,61) 50%
|
||||
);
|
||||
}
|
||||
.noVNC_status_error {
|
||||
background-color:#f04040;
|
||||
background-image: -webkit-gradient(
|
||||
linear,
|
||||
left bottom,
|
||||
left top,
|
||||
color-stop(0.54, rgb(240,64,64)),
|
||||
color-stop(0.5, rgb(4,7,61))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
center bottom,
|
||||
rgb(4,7,61) 54%,
|
||||
rgb(249,64,64) 50%
|
||||
);
|
||||
}
|
||||
.noVNC_status_warn {
|
||||
background-color:#f0f040;
|
||||
background-image: -webkit-gradient(
|
||||
linear,
|
||||
left bottom,
|
||||
left top,
|
||||
color-stop(0.54, rgb(240,240,64)),
|
||||
color-stop(0.5, rgb(4,7,61))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
center bottom,
|
||||
rgb(4,7,61) 54%,
|
||||
rgb(240,240,64) 50%
|
||||
);
|
||||
}
|
||||
|
||||
.triangle-right {
|
||||
border:2px solid #fff;
|
||||
background:#04073d;
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
#keyboardinput {
|
||||
background-color:#04073d;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Boris Smus (smus@chromium.org)
|
||||
*/
|
||||
|
||||
(function(exports) {
|
||||
|
||||
// Define some local variables here.
|
||||
var socket = chrome.socket || chrome.experimental.socket;
|
||||
var dns = chrome.experimental.dns;
|
||||
|
||||
/**
|
||||
* Creates an instance of the client
|
||||
*
|
||||
* @param {String} host The remote host to connect to
|
||||
* @param {Number} port The port to connect to at the remote host
|
||||
*/
|
||||
function TcpClient(host, port, pollInterval) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.pollInterval = pollInterval || 15;
|
||||
|
||||
// Callback functions.
|
||||
this.callbacks = {
|
||||
connect: null, // Called when socket is connected.
|
||||
disconnect: null, // Called when socket is disconnected.
|
||||
recvBuffer: null, // Called (as ArrayBuffer) when client receives data from server.
|
||||
recvString: null, // Called (as string) when client receives data from server.
|
||||
sent: null // Called when client sends data to server.
|
||||
};
|
||||
|
||||
// Socket.
|
||||
this.socketId = null;
|
||||
this.isConnected = false;
|
||||
|
||||
log('initialized tcp client');
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the TCP socket, and creates an open socket.
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-create
|
||||
* @param {Function} callback The function to call on connection
|
||||
*/
|
||||
TcpClient.prototype.connect = function(callback) {
|
||||
// First resolve the hostname to an IP.
|
||||
dns.resolve(this.host, function(result) {
|
||||
this.addr = result.address;
|
||||
socket.create('tcp', {}, this._onCreate.bind(this));
|
||||
|
||||
// Register connect callback.
|
||||
this.callbacks.connect = callback;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends an arraybuffer/view down the wire to the remote side
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-write
|
||||
* @param {String} msg The arraybuffer/view to send
|
||||
* @param {Function} callback The function to call when the message has sent
|
||||
*/
|
||||
TcpClient.prototype.sendBuffer = function(buf, callback) {
|
||||
if (buf.buffer) {
|
||||
buf = buf.buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
// Debug
|
||||
var bytes = [], u8 = new Uint8Array(buf);
|
||||
for (var i = 0; i < u8.length; i++) {
|
||||
bytes.push(u8[i]);
|
||||
}
|
||||
log("sending bytes: " + (bytes.join(',')));
|
||||
*/
|
||||
|
||||
socket.write(this.socketId, buf, this._onWriteComplete.bind(this));
|
||||
|
||||
// Register sent callback.
|
||||
this.callbacks.sent = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a string down the wire to the remote side
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-write
|
||||
* @param {String} msg The string to send
|
||||
* @param {Function} callback The function to call when the message has sent
|
||||
*/
|
||||
TcpClient.prototype.sendString = function(msg, callback) {
|
||||
/*
|
||||
// Debug
|
||||
log("sending string: " + msg);
|
||||
*/
|
||||
|
||||
this._stringToArrayBuffer(msg, function(arrayBuffer) {
|
||||
socket.write(this.socketId, arrayBuffer, this._onWriteComplete.bind(this));
|
||||
}.bind(this));
|
||||
|
||||
// Register sent callback.
|
||||
this.callbacks.sent = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the callback for when a message is received
|
||||
*
|
||||
* @param {Function} callback The function to call when a message has arrived
|
||||
* @param {String} type The callback argument type: "arraybuffer" or "string"
|
||||
*/
|
||||
TcpClient.prototype.addResponseListener = function(callback, type) {
|
||||
if (typeof type === "undefined") {
|
||||
type = "arraybuffer";
|
||||
}
|
||||
// Register received callback.
|
||||
if (type === "string") {
|
||||
this.callbacks.recvString = callback;
|
||||
} else {
|
||||
this.callbacks.recvBuffer = callback;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the callback for when the socket disconnects
|
||||
*
|
||||
* @param {Function} callback The function to call when the socket disconnects
|
||||
* @param {String} type The callback argument type: "arraybuffer" or "string"
|
||||
*/
|
||||
TcpClient.prototype.addDisconnectListener = function(callback) {
|
||||
// Register disconnect callback.
|
||||
this.callbacks.disconnect = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Disconnects from the remote side
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-disconnect
|
||||
*/
|
||||
TcpClient.prototype.disconnect = function() {
|
||||
if (this.isConnected) {
|
||||
this.isConnected = false;
|
||||
socket.disconnect(this.socketId);
|
||||
if (this.callbacks.disconnect) {
|
||||
this.callbacks.disconnect();
|
||||
}
|
||||
log('socket disconnected');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The callback function used for when we attempt to have Chrome
|
||||
* create a socket. If the socket is successfully created
|
||||
* we go ahead and connect to the remote side.
|
||||
*
|
||||
* @private
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-connect
|
||||
* @param {Object} createInfo The socket details
|
||||
*/
|
||||
TcpClient.prototype._onCreate = function(createInfo) {
|
||||
this.socketId = createInfo.socketId;
|
||||
if (this.socketId > 0) {
|
||||
socket.connect(this.socketId, this.addr, this.port, this._onConnectComplete.bind(this));
|
||||
} else {
|
||||
error('Unable to create socket');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The callback function used for when we attempt to have Chrome
|
||||
* connect to the remote side. If a successful connection is
|
||||
* made then polling starts to check for data to read
|
||||
*
|
||||
* @private
|
||||
* @param {Number} resultCode Indicates whether the connection was successful
|
||||
*/
|
||||
TcpClient.prototype._onConnectComplete = function(resultCode) {
|
||||
// Start polling for reads.
|
||||
this.isConnected = true;
|
||||
setTimeout(this._periodicallyRead.bind(this), this.pollInterval);
|
||||
|
||||
if (this.callbacks.connect) {
|
||||
log('connect complete');
|
||||
this.callbacks.connect();
|
||||
}
|
||||
log('onConnectComplete');
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks for new data to read from the socket
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-read
|
||||
*/
|
||||
TcpClient.prototype._periodicallyRead = function() {
|
||||
var that = this;
|
||||
socket.getInfo(this.socketId, function (info) {
|
||||
if (info.connected) {
|
||||
setTimeout(that._periodicallyRead.bind(that), that.pollInterval);
|
||||
socket.read(that.socketId, null, that._onDataRead.bind(that));
|
||||
} else if (that.isConnected) {
|
||||
log('socket disconnect detected');
|
||||
that.disconnect();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function for when data has been read from the socket.
|
||||
* Converts the array buffer that is read in to a string
|
||||
* and sends it on for further processing by passing it to
|
||||
* the previously assigned callback function.
|
||||
*
|
||||
* @private
|
||||
* @see TcpClient.prototype.addResponseListener
|
||||
* @param {Object} readInfo The incoming message
|
||||
*/
|
||||
TcpClient.prototype._onDataRead = function(readInfo) {
|
||||
// Call received callback if there's data in the response.
|
||||
if (readInfo.resultCode > 0) {
|
||||
log('onDataRead');
|
||||
|
||||
/*
|
||||
// Debug
|
||||
var bytes = [], u8 = new Uint8Array(readInfo.data);
|
||||
for (var i = 0; i < u8.length; i++) {
|
||||
bytes.push(u8[i]);
|
||||
}
|
||||
log("received bytes: " + (bytes.join(',')));
|
||||
*/
|
||||
|
||||
if (this.callbacks.recvBuffer) {
|
||||
// Return raw ArrayBuffer directly.
|
||||
this.callbacks.recvBuffer(readInfo.data);
|
||||
}
|
||||
if (this.callbacks.recvString) {
|
||||
// Convert ArrayBuffer to string.
|
||||
this._arrayBufferToString(readInfo.data, function(str) {
|
||||
this.callbacks.recvString(str);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
// Trigger another read right away
|
||||
setTimeout(this._periodicallyRead.bind(this), 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for when data has been successfully
|
||||
* written to the socket.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} writeInfo The outgoing message
|
||||
*/
|
||||
TcpClient.prototype._onWriteComplete = function(writeInfo) {
|
||||
log('onWriteComplete');
|
||||
// Call sent callback.
|
||||
if (this.callbacks.sent) {
|
||||
this.callbacks.sent(writeInfo);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts an array buffer to a string
|
||||
*
|
||||
* @private
|
||||
* @param {ArrayBuffer} buf The buffer to convert
|
||||
* @param {Function} callback The function to call when conversion is complete
|
||||
*/
|
||||
TcpClient.prototype._arrayBufferToString = function(buf, callback) {
|
||||
var bb = new Blob([new Uint8Array(buf)]);
|
||||
var f = new FileReader();
|
||||
f.onload = function(e) {
|
||||
callback(e.target.result);
|
||||
};
|
||||
f.readAsText(bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a string to an array buffer
|
||||
*
|
||||
* @private
|
||||
* @param {String} str The string to convert
|
||||
* @param {Function} callback The function to call when conversion is complete
|
||||
*/
|
||||
TcpClient.prototype._stringToArrayBuffer = function(str, callback) {
|
||||
var bb = new Blob([str]);
|
||||
var f = new FileReader();
|
||||
f.onload = function(e) {
|
||||
callback(e.target.result);
|
||||
};
|
||||
f.readAsArrayBuffer(bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper function for logging
|
||||
*/
|
||||
function log(msg) {
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function for error logging
|
||||
*/
|
||||
function error(msg) {
|
||||
console.error(msg);
|
||||
}
|
||||
|
||||
exports.TcpClient = TcpClient;
|
||||
|
||||
})(window);
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Ported from Flashlight VNC ActionScript implementation:
|
||||
* http://www.wizhelp.com/flashlight-vnc/
|
||||
*
|
||||
* Full attribution follows:
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* This DES class has been extracted from package Acme.Crypto for use in VNC.
|
||||
* The unnecessary odd parity code has been removed.
|
||||
*
|
||||
* These changes are:
|
||||
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
|
||||
* DesCipher - the DES encryption method
|
||||
*
|
||||
* The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
|
||||
*
|
||||
* Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
|
||||
* without fee is hereby granted, provided that this copyright notice is kept
|
||||
* intact.
|
||||
*
|
||||
* WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
|
||||
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
|
||||
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
* THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||||
* CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||||
* PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||||
* NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||||
* SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||||
* SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||||
* PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
|
||||
* SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
|
||||
* HIGH RISK ACTIVITIES.
|
||||
*
|
||||
*
|
||||
* The rest is:
|
||||
*
|
||||
* Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Visit the ACME Labs Java page for up-to-date versions of this and other
|
||||
* fine Java utilities: http://www.acme.com/java/
|
||||
*/
|
||||
|
||||
/* jslint white: false */
|
||||
|
||||
function DES(passwd) {
|
||||
"use strict";
|
||||
|
||||
// Tables, permutations, S-boxes, etc.
|
||||
// jshint -W013
|
||||
var PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
|
||||
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
|
||||
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
|
||||
totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28],
|
||||
z = 0x0, a,b,c,d,e,f, SP1,SP2,SP3,SP4,SP5,SP6,SP7,SP8,
|
||||
keys = [];
|
||||
|
||||
// jshint -W015
|
||||
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
|
||||
SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
|
||||
z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
|
||||
a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
|
||||
c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
|
||||
a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
|
||||
SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
|
||||
a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
|
||||
z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
|
||||
z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
|
||||
a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
|
||||
SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
|
||||
b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
|
||||
c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
|
||||
b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
|
||||
a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
|
||||
SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
|
||||
z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
|
||||
b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
|
||||
c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
|
||||
a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
|
||||
SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
|
||||
a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
|
||||
z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
|
||||
c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
|
||||
a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
|
||||
SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
|
||||
z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
|
||||
b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
|
||||
a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
|
||||
a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
|
||||
SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
|
||||
b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
|
||||
b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
|
||||
z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
|
||||
a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
|
||||
SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
|
||||
c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
|
||||
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
|
||||
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
|
||||
// jshint +W013,+W015
|
||||
|
||||
// Set the key.
|
||||
function setKeys(keyBlock) {
|
||||
var i, j, l, m, n, o, pc1m = [], pcr = [], kn = [],
|
||||
raw0, raw1, rawi, KnLi;
|
||||
|
||||
for (j = 0, l = 56; j < 56; ++j, l -= 8) {
|
||||
l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
|
||||
m = l & 0x7;
|
||||
pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; ++i) {
|
||||
m = i << 1;
|
||||
n = m + 1;
|
||||
kn[m] = kn[n] = 0;
|
||||
for (o = 28; o < 59; o += 28) {
|
||||
for (j = o - 28; j < o; ++j) {
|
||||
l = j + totrot[i];
|
||||
if (l < o) {
|
||||
pcr[j] = pc1m[l];
|
||||
} else {
|
||||
pcr[j] = pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 24; ++j) {
|
||||
if (pcr[PC2[j]] !== 0) {
|
||||
kn[m] |= 1 << (23 - j);
|
||||
}
|
||||
if (pcr[PC2[j + 24]] !== 0) {
|
||||
kn[n] |= 1 << (23 - j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cookey
|
||||
for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
|
||||
raw0 = kn[rawi++];
|
||||
raw1 = kn[rawi++];
|
||||
keys[KnLi] = (raw0 & 0x00fc0000) << 6;
|
||||
keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
||||
keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
||||
keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
|
||||
++KnLi;
|
||||
keys[KnLi] = (raw0 & 0x0003f000) << 12;
|
||||
keys[KnLi] |= (raw0 & 0x0000003f) << 16;
|
||||
keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
|
||||
keys[KnLi] |= (raw1 & 0x0000003f);
|
||||
++KnLi;
|
||||
}
|
||||
}
|
||||
|
||||
// Encrypt 8 bytes of text
|
||||
function enc8(text) {
|
||||
var i = 0, b = text.slice(), fval, keysi = 0,
|
||||
l, r, x; // left, right, accumulator
|
||||
|
||||
// Squash 8 bytes to 2 ints
|
||||
l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||
r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||
|
||||
x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
|
||||
r ^= x;
|
||||
l ^= (x << 4);
|
||||
x = ((l >>> 16) ^ r) & 0x0000ffff;
|
||||
r ^= x;
|
||||
l ^= (x << 16);
|
||||
x = ((r >>> 2) ^ l) & 0x33333333;
|
||||
l ^= x;
|
||||
r ^= (x << 2);
|
||||
x = ((r >>> 8) ^ l) & 0x00ff00ff;
|
||||
l ^= x;
|
||||
r ^= (x << 8);
|
||||
r = (r << 1) | ((r >>> 31) & 1);
|
||||
x = (l ^ r) & 0xaaaaaaaa;
|
||||
l ^= x;
|
||||
r ^= x;
|
||||
l = (l << 1) | ((l >>> 31) & 1);
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
x = (r << 28) | (r >>> 4);
|
||||
x ^= keys[keysi++];
|
||||
fval = SP7[x & 0x3f];
|
||||
fval |= SP5[(x >>> 8) & 0x3f];
|
||||
fval |= SP3[(x >>> 16) & 0x3f];
|
||||
fval |= SP1[(x >>> 24) & 0x3f];
|
||||
x = r ^ keys[keysi++];
|
||||
fval |= SP8[x & 0x3f];
|
||||
fval |= SP6[(x >>> 8) & 0x3f];
|
||||
fval |= SP4[(x >>> 16) & 0x3f];
|
||||
fval |= SP2[(x >>> 24) & 0x3f];
|
||||
l ^= fval;
|
||||
x = (l << 28) | (l >>> 4);
|
||||
x ^= keys[keysi++];
|
||||
fval = SP7[x & 0x3f];
|
||||
fval |= SP5[(x >>> 8) & 0x3f];
|
||||
fval |= SP3[(x >>> 16) & 0x3f];
|
||||
fval |= SP1[(x >>> 24) & 0x3f];
|
||||
x = l ^ keys[keysi++];
|
||||
fval |= SP8[x & 0x0000003f];
|
||||
fval |= SP6[(x >>> 8) & 0x3f];
|
||||
fval |= SP4[(x >>> 16) & 0x3f];
|
||||
fval |= SP2[(x >>> 24) & 0x3f];
|
||||
r ^= fval;
|
||||
}
|
||||
|
||||
r = (r << 31) | (r >>> 1);
|
||||
x = (l ^ r) & 0xaaaaaaaa;
|
||||
l ^= x;
|
||||
r ^= x;
|
||||
l = (l << 31) | (l >>> 1);
|
||||
x = ((l >>> 8) ^ r) & 0x00ff00ff;
|
||||
r ^= x;
|
||||
l ^= (x << 8);
|
||||
x = ((l >>> 2) ^ r) & 0x33333333;
|
||||
r ^= x;
|
||||
l ^= (x << 2);
|
||||
x = ((r >>> 16) ^ l) & 0x0000ffff;
|
||||
l ^= x;
|
||||
r ^= (x << 16);
|
||||
x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
|
||||
l ^= x;
|
||||
r ^= (x << 4);
|
||||
|
||||
// Spread ints to bytes
|
||||
x = [r, l];
|
||||
for (i = 0; i < 8; i++) {
|
||||
b[i] = (x[i>>>2] >>> (8 * (3 - (i % 4)))) % 256;
|
||||
if (b[i] < 0) { b[i] += 256; } // unsigned
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// Encrypt 16 bytes of text using passwd as key
|
||||
function encrypt(t) {
|
||||
return enc8(t.slice(0, 8)).concat(enc8(t.slice(8, 16)));
|
||||
}
|
||||
|
||||
setKeys(passwd); // Setup keys
|
||||
return {'encrypt': encrypt}; // Public interface
|
||||
|
||||
} // function DES
|
||||
@@ -0,0 +1,898 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Copyright (C) 2015 Samuel Mannehed for Cendio AB
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
/*jslint browser: true, white: false */
|
||||
/*global Util, Base64, changeCursor */
|
||||
|
||||
var Display;
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
|
||||
try {
|
||||
new ImageData(new Uint8ClampedArray(1), 1, 1);
|
||||
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true;
|
||||
} catch (ex) {
|
||||
// ignore failure
|
||||
}
|
||||
|
||||
Display = function (defaults) {
|
||||
this._drawCtx = null;
|
||||
this._c_forceCanvas = false;
|
||||
|
||||
this._renderQ = []; // queue drawing actions for in-oder rendering
|
||||
|
||||
// the full frame buffer (logical canvas) size
|
||||
this._fb_width = 0;
|
||||
this._fb_height = 0;
|
||||
|
||||
// the size limit of the viewport (start disabled)
|
||||
this._maxWidth = 0;
|
||||
this._maxHeight = 0;
|
||||
|
||||
// the visible "physical canvas" viewport
|
||||
this._viewportLoc = { 'x': 0, 'y': 0, 'w': 0, 'h': 0 };
|
||||
this._cleanRect = { 'x1': 0, 'y1': 0, 'x2': -1, 'y2': -1 };
|
||||
|
||||
this._prevDrawStyle = "";
|
||||
this._tile = null;
|
||||
this._tile16x16 = null;
|
||||
this._tile_x = 0;
|
||||
this._tile_y = 0;
|
||||
|
||||
Util.set_defaults(this, defaults, {
|
||||
'true_color': true,
|
||||
'colourMap': [],
|
||||
'scale': 1.0,
|
||||
'viewport': false,
|
||||
'render_mode': ''
|
||||
});
|
||||
|
||||
Util.Debug(">> Display.constructor");
|
||||
|
||||
if (!this._target) {
|
||||
throw new Error("Target must be set");
|
||||
}
|
||||
|
||||
if (typeof this._target === 'string') {
|
||||
throw new Error('target must be a DOM element');
|
||||
}
|
||||
|
||||
if (!this._target.getContext) {
|
||||
throw new Error("no getContext method");
|
||||
}
|
||||
|
||||
if (!this._drawCtx) {
|
||||
this._drawCtx = this._target.getContext('2d');
|
||||
}
|
||||
|
||||
Util.Debug("User Agent: " + navigator.userAgent);
|
||||
if (Util.Engine.gecko) { Util.Debug("Browser: gecko " + Util.Engine.gecko); }
|
||||
if (Util.Engine.webkit) { Util.Debug("Browser: webkit " + Util.Engine.webkit); }
|
||||
if (Util.Engine.trident) { Util.Debug("Browser: trident " + Util.Engine.trident); }
|
||||
if (Util.Engine.presto) { Util.Debug("Browser: presto " + Util.Engine.presto); }
|
||||
|
||||
this.clear();
|
||||
|
||||
// Check canvas features
|
||||
if ('createImageData' in this._drawCtx) {
|
||||
this._render_mode = 'canvas rendering';
|
||||
} else {
|
||||
throw new Error("Canvas does not support createImageData");
|
||||
}
|
||||
|
||||
if (this._prefer_js === null) {
|
||||
Util.Info("Prefering javascript operations");
|
||||
this._prefer_js = true;
|
||||
}
|
||||
|
||||
// Determine browser support for setting the cursor via data URI scheme
|
||||
if (this._cursor_uri || this._cursor_uri === null ||
|
||||
this._cursor_uri === undefined) {
|
||||
this._cursor_uri = Util.browserSupportsCursorURIs();
|
||||
}
|
||||
|
||||
Util.Debug("<< Display.constructor");
|
||||
};
|
||||
|
||||
Display.prototype = {
|
||||
// Public methods
|
||||
viewportChangePos: function (deltaX, deltaY) {
|
||||
var vp = this._viewportLoc;
|
||||
deltaX = Math.floor(deltaX);
|
||||
deltaY = Math.floor(deltaY);
|
||||
|
||||
if (!this._viewport) {
|
||||
deltaX = -vp.w; // clamped later of out of bounds
|
||||
deltaY = -vp.h;
|
||||
}
|
||||
|
||||
var vx2 = vp.x + vp.w - 1;
|
||||
var vy2 = vp.y + vp.h - 1;
|
||||
|
||||
// Position change
|
||||
|
||||
if (deltaX < 0 && vp.x + deltaX < 0) {
|
||||
deltaX = -vp.x;
|
||||
}
|
||||
if (vx2 + deltaX >= this._fb_width) {
|
||||
deltaX -= vx2 + deltaX - this._fb_width + 1;
|
||||
}
|
||||
|
||||
if (vp.y + deltaY < 0) {
|
||||
deltaY = -vp.y;
|
||||
}
|
||||
if (vy2 + deltaY >= this._fb_height) {
|
||||
deltaY -= (vy2 + deltaY - this._fb_height + 1);
|
||||
}
|
||||
|
||||
if (deltaX === 0 && deltaY === 0) {
|
||||
return;
|
||||
}
|
||||
Util.Debug("viewportChange deltaX: " + deltaX + ", deltaY: " + deltaY);
|
||||
|
||||
vp.x += deltaX;
|
||||
vx2 += deltaX;
|
||||
vp.y += deltaY;
|
||||
vy2 += deltaY;
|
||||
|
||||
// Update the clean rectangle
|
||||
var cr = this._cleanRect;
|
||||
if (vp.x > cr.x1) {
|
||||
cr.x1 = vp.x;
|
||||
}
|
||||
if (vx2 < cr.x2) {
|
||||
cr.x2 = vx2;
|
||||
}
|
||||
if (vp.y > cr.y1) {
|
||||
cr.y1 = vp.y;
|
||||
}
|
||||
if (vy2 < cr.y2) {
|
||||
cr.y2 = vy2;
|
||||
}
|
||||
|
||||
var x1, w;
|
||||
if (deltaX < 0) {
|
||||
// Shift viewport left, redraw left section
|
||||
x1 = 0;
|
||||
w = -deltaX;
|
||||
} else {
|
||||
// Shift viewport right, redraw right section
|
||||
x1 = vp.w - deltaX;
|
||||
w = deltaX;
|
||||
}
|
||||
|
||||
var y1, h;
|
||||
if (deltaY < 0) {
|
||||
// Shift viewport up, redraw top section
|
||||
y1 = 0;
|
||||
h = -deltaY;
|
||||
} else {
|
||||
// Shift viewport down, redraw bottom section
|
||||
y1 = vp.h - deltaY;
|
||||
h = deltaY;
|
||||
}
|
||||
|
||||
var saveStyle = this._drawCtx.fillStyle;
|
||||
var canvas = this._target;
|
||||
this._drawCtx.fillStyle = "rgb(255,255,255)";
|
||||
|
||||
// Due to this bug among others [1] we need to disable the image-smoothing to
|
||||
// avoid getting a blur effect when panning.
|
||||
//
|
||||
// 1. https://bugzilla.mozilla.org/show_bug.cgi?id=1194719
|
||||
//
|
||||
// We need to set these every time since all properties are reset
|
||||
// when the the size is changed
|
||||
if (this._drawCtx.mozImageSmoothingEnabled) {
|
||||
this._drawCtx.mozImageSmoothingEnabled = false;
|
||||
} else if (this._drawCtx.webkitImageSmoothingEnabled) {
|
||||
this._drawCtx.webkitImageSmoothingEnabled = false;
|
||||
} else if (this._drawCtx.msImageSmoothingEnabled) {
|
||||
this._drawCtx.msImageSmoothingEnabled = false;
|
||||
} else if (this._drawCtx.imageSmoothingEnabled) {
|
||||
this._drawCtx.imageSmoothingEnabled = false;
|
||||
}
|
||||
|
||||
// Copy the valid part of the viewport to the shifted location
|
||||
this._drawCtx.drawImage(canvas, 0, 0, vp.w, vp.h, -deltaX, -deltaY, vp.w, vp.h);
|
||||
|
||||
if (deltaX !== 0) {
|
||||
this._drawCtx.fillRect(x1, 0, w, vp.h);
|
||||
}
|
||||
if (deltaY !== 0) {
|
||||
this._drawCtx.fillRect(0, y1, vp.w, h);
|
||||
}
|
||||
this._drawCtx.fillStyle = saveStyle;
|
||||
},
|
||||
|
||||
viewportChangeSize: function(width, height) {
|
||||
|
||||
if (typeof(width) === "undefined" || typeof(height) === "undefined") {
|
||||
|
||||
Util.Debug("Setting viewport to full display region");
|
||||
width = this._fb_width;
|
||||
height = this._fb_height;
|
||||
}
|
||||
|
||||
var vp = this._viewportLoc;
|
||||
if (vp.w !== width || vp.h !== height) {
|
||||
|
||||
if (this._viewport) {
|
||||
if (this._maxWidth !== 0 && width > this._maxWidth) {
|
||||
width = this._maxWidth;
|
||||
}
|
||||
if (this._maxHeight !== 0 && height > this._maxHeight) {
|
||||
height = this._maxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
var cr = this._cleanRect;
|
||||
|
||||
if (width < vp.w && cr.x2 > vp.x + width - 1) {
|
||||
cr.x2 = vp.x + width - 1;
|
||||
}
|
||||
if (height < vp.h && cr.y2 > vp.y + height - 1) {
|
||||
cr.y2 = vp.y + height - 1;
|
||||
}
|
||||
|
||||
vp.w = width;
|
||||
vp.h = height;
|
||||
|
||||
var canvas = this._target;
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
|
||||
// We have to save the canvas data since changing the size will clear it
|
||||
var saveImg = null;
|
||||
if (vp.w > 0 && vp.h > 0 && canvas.width > 0 && canvas.height > 0) {
|
||||
var img_width = canvas.width < vp.w ? canvas.width : vp.w;
|
||||
var img_height = canvas.height < vp.h ? canvas.height : vp.h;
|
||||
saveImg = this._drawCtx.getImageData(0, 0, img_width, img_height);
|
||||
}
|
||||
|
||||
if (canvas.width !== width) {
|
||||
canvas.width = width;
|
||||
canvas.style.width = width + 'px';
|
||||
}
|
||||
if (canvas.height !== height) {
|
||||
canvas.height = height;
|
||||
canvas.style.height = height + 'px';
|
||||
}
|
||||
|
||||
if (saveImg) {
|
||||
this._drawCtx.putImageData(saveImg, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Return a map of clean and dirty areas of the viewport and reset the
|
||||
// tracking of clean and dirty areas
|
||||
//
|
||||
// Returns: { 'cleanBox': { 'x': x, 'y': y, 'w': w, 'h': h},
|
||||
// 'dirtyBoxes': [{ 'x': x, 'y': y, 'w': w, 'h': h }, ...] }
|
||||
getCleanDirtyReset: function () {
|
||||
var vp = this._viewportLoc;
|
||||
var cr = this._cleanRect;
|
||||
|
||||
var cleanBox = { 'x': cr.x1, 'y': cr.y1,
|
||||
'w': cr.x2 - cr.x1 + 1, 'h': cr.y2 - cr.y1 + 1 };
|
||||
|
||||
var dirtyBoxes = [];
|
||||
if (cr.x1 >= cr.x2 || cr.y1 >= cr.y2) {
|
||||
// Whole viewport is dirty
|
||||
dirtyBoxes.push({ 'x': vp.x, 'y': vp.y, 'w': vp.w, 'h': vp.h });
|
||||
} else {
|
||||
// Redraw dirty regions
|
||||
var vx2 = vp.x + vp.w - 1;
|
||||
var vy2 = vp.y + vp.h - 1;
|
||||
|
||||
if (vp.x < cr.x1) {
|
||||
// left side dirty region
|
||||
dirtyBoxes.push({'x': vp.x, 'y': vp.y,
|
||||
'w': cr.x1 - vp.x + 1, 'h': vp.h});
|
||||
}
|
||||
if (vx2 > cr.x2) {
|
||||
// right side dirty region
|
||||
dirtyBoxes.push({'x': cr.x2 + 1, 'y': vp.y,
|
||||
'w': vx2 - cr.x2, 'h': vp.h});
|
||||
}
|
||||
if(vp.y < cr.y1) {
|
||||
// top/middle dirty region
|
||||
dirtyBoxes.push({'x': cr.x1, 'y': vp.y,
|
||||
'w': cr.x2 - cr.x1 + 1, 'h': cr.y1 - vp.y});
|
||||
}
|
||||
if (vy2 > cr.y2) {
|
||||
// bottom/middle dirty region
|
||||
dirtyBoxes.push({'x': cr.x1, 'y': cr.y2 + 1,
|
||||
'w': cr.x2 - cr.x1 + 1, 'h': vy2 - cr.y2});
|
||||
}
|
||||
}
|
||||
|
||||
this._cleanRect = {'x1': vp.x, 'y1': vp.y,
|
||||
'x2': vp.x + vp.w - 1, 'y2': vp.y + vp.h - 1};
|
||||
|
||||
return {'cleanBox': cleanBox, 'dirtyBoxes': dirtyBoxes};
|
||||
},
|
||||
|
||||
absX: function (x) {
|
||||
return x + this._viewportLoc.x;
|
||||
},
|
||||
|
||||
absY: function (y) {
|
||||
return y + this._viewportLoc.y;
|
||||
},
|
||||
|
||||
resize: function (width, height) {
|
||||
this._prevDrawStyle = "";
|
||||
|
||||
this._fb_width = width;
|
||||
this._fb_height = height;
|
||||
|
||||
this._rescale(this._scale);
|
||||
|
||||
this.viewportChangeSize();
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
if (this._logo) {
|
||||
this.resize(this._logo.width, this._logo.height);
|
||||
this.blitStringImage(this._logo.data, 0, 0);
|
||||
} else {
|
||||
if (Util.Engine.trident === 6) {
|
||||
// NB(directxman12): there's a bug in IE10 where we can fail to actually
|
||||
// clear the canvas here because of the resize.
|
||||
// Clearing the current viewport first fixes the issue
|
||||
this._drawCtx.clearRect(0, 0, this._viewportLoc.w, this._viewportLoc.h);
|
||||
}
|
||||
this.resize(240, 20);
|
||||
this._drawCtx.clearRect(0, 0, this._viewportLoc.w, this._viewportLoc.h);
|
||||
}
|
||||
|
||||
this._renderQ = [];
|
||||
},
|
||||
|
||||
fillRect: function (x, y, width, height, color, from_queue) {
|
||||
if (this._renderQ.length !== 0 && !from_queue) {
|
||||
this.renderQ_push({
|
||||
'type': 'fill',
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
'color': color
|
||||
});
|
||||
} else {
|
||||
this._setFillColor(color);
|
||||
this._drawCtx.fillRect(x - this._viewportLoc.x, y - this._viewportLoc.y, width, height);
|
||||
}
|
||||
},
|
||||
|
||||
copyImage: function (old_x, old_y, new_x, new_y, w, h, from_queue) {
|
||||
if (this._renderQ.length !== 0 && !from_queue) {
|
||||
this.renderQ_push({
|
||||
'type': 'copy',
|
||||
'old_x': old_x,
|
||||
'old_y': old_y,
|
||||
'x': new_x,
|
||||
'y': new_y,
|
||||
'width': w,
|
||||
'height': h,
|
||||
});
|
||||
} else {
|
||||
var x1 = old_x - this._viewportLoc.x;
|
||||
var y1 = old_y - this._viewportLoc.y;
|
||||
var x2 = new_x - this._viewportLoc.x;
|
||||
var y2 = new_y - this._viewportLoc.y;
|
||||
|
||||
this._drawCtx.drawImage(this._target, x1, y1, w, h, x2, y2, w, h);
|
||||
}
|
||||
},
|
||||
|
||||
// start updating a tile
|
||||
startTile: function (x, y, width, height, color) {
|
||||
this._tile_x = x;
|
||||
this._tile_y = y;
|
||||
if (width === 16 && height === 16) {
|
||||
this._tile = this._tile16x16;
|
||||
} else {
|
||||
this._tile = this._drawCtx.createImageData(width, height);
|
||||
}
|
||||
|
||||
if (this._prefer_js) {
|
||||
var bgr;
|
||||
if (this._true_color) {
|
||||
bgr = color;
|
||||
} else {
|
||||
bgr = this._colourMap[color[0]];
|
||||
}
|
||||
var red = bgr[2];
|
||||
var green = bgr[1];
|
||||
var blue = bgr[0];
|
||||
|
||||
var data = this._tile.data;
|
||||
for (var i = 0; i < width * height * 4; i += 4) {
|
||||
data[i] = red;
|
||||
data[i + 1] = green;
|
||||
data[i + 2] = blue;
|
||||
data[i + 3] = 255;
|
||||
}
|
||||
} else {
|
||||
this.fillRect(x, y, width, height, color, true);
|
||||
}
|
||||
},
|
||||
|
||||
// update sub-rectangle of the current tile
|
||||
subTile: function (x, y, w, h, color) {
|
||||
if (this._prefer_js) {
|
||||
var bgr;
|
||||
if (this._true_color) {
|
||||
bgr = color;
|
||||
} else {
|
||||
bgr = this._colourMap[color[0]];
|
||||
}
|
||||
var red = bgr[2];
|
||||
var green = bgr[1];
|
||||
var blue = bgr[0];
|
||||
var xend = x + w;
|
||||
var yend = y + h;
|
||||
|
||||
var data = this._tile.data;
|
||||
var width = this._tile.width;
|
||||
for (var j = y; j < yend; j++) {
|
||||
for (var i = x; i < xend; i++) {
|
||||
var p = (i + (j * width)) * 4;
|
||||
data[p] = red;
|
||||
data[p + 1] = green;
|
||||
data[p + 2] = blue;
|
||||
data[p + 3] = 255;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.fillRect(this._tile_x + x, this._tile_y + y, w, h, color, true);
|
||||
}
|
||||
},
|
||||
|
||||
// draw the current tile to the screen
|
||||
finishTile: function () {
|
||||
if (this._prefer_js) {
|
||||
this._drawCtx.putImageData(this._tile, this._tile_x - this._viewportLoc.x,
|
||||
this._tile_y - this._viewportLoc.y);
|
||||
}
|
||||
// else: No-op -- already done by setSubTile
|
||||
},
|
||||
|
||||
blitImage: function (x, y, width, height, arr, offset, from_queue) {
|
||||
if (this._renderQ.length !== 0 && !from_queue) {
|
||||
this.renderQ_push({
|
||||
'type': 'blit',
|
||||
'data': arr,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
});
|
||||
} else if (this._true_color) {
|
||||
this._bgrxImageData(x, y, this._viewportLoc.x, this._viewportLoc.y, width, height, arr, offset);
|
||||
} else {
|
||||
this._cmapImageData(x, y, this._viewportLoc.x, this._viewportLoc.y, width, height, arr, offset);
|
||||
}
|
||||
},
|
||||
|
||||
blitRgbImage: function (x, y , width, height, arr, offset, from_queue) {
|
||||
if (this._renderQ.length !== 0 && !from_queue) {
|
||||
this.renderQ_push({
|
||||
'type': 'blitRgb',
|
||||
'data': arr,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
});
|
||||
} else if (this._true_color) {
|
||||
this._rgbImageData(x, y, this._viewportLoc.x, this._viewportLoc.y, width, height, arr, offset);
|
||||
} else {
|
||||
// probably wrong?
|
||||
this._cmapImageData(x, y, this._viewportLoc.x, this._viewportLoc.y, width, height, arr, offset);
|
||||
}
|
||||
},
|
||||
|
||||
blitRgbxImage: function (x, y, width, height, arr, offset, from_queue) {
|
||||
if (this._renderQ.length !== 0 && !from_queue) {
|
||||
// NB(directxman12): it's technically more performant here to use preallocated arrays, but it
|
||||
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
||||
// this probably isn't getting called *nearly* as much
|
||||
var new_arr = new Uint8Array(width * height * 4);
|
||||
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
||||
this.renderQ_push({
|
||||
'type': 'blitRgbx',
|
||||
'data': new_arr,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
});
|
||||
} else {
|
||||
this._rgbxImageData(x, y, this._viewportLoc.x, this._viewportLoc.y, width, height, arr, offset);
|
||||
}
|
||||
},
|
||||
|
||||
blitStringImage: function (str, x, y) {
|
||||
var img = new Image();
|
||||
img.onload = function () {
|
||||
this._drawCtx.drawImage(img, x - this._viewportLoc.x, y - this._viewportLoc.y);
|
||||
}.bind(this);
|
||||
img.src = str;
|
||||
return img; // for debugging purposes
|
||||
},
|
||||
|
||||
// wrap ctx.drawImage but relative to viewport
|
||||
drawImage: function (img, x, y) {
|
||||
this._drawCtx.drawImage(img, x - this._viewportLoc.x, y - this._viewportLoc.y);
|
||||
},
|
||||
|
||||
renderQ_push: function (action) {
|
||||
this._renderQ.push(action);
|
||||
if (this._renderQ.length === 1) {
|
||||
// If this can be rendered immediately it will be, otherwise
|
||||
// the scanner will start polling the queue (every
|
||||
// requestAnimationFrame interval)
|
||||
this._scan_renderQ();
|
||||
}
|
||||
},
|
||||
|
||||
changeCursor: function (pixels, mask, hotx, hoty, w, h) {
|
||||
if (this._cursor_uri === false) {
|
||||
Util.Warn("changeCursor called but no cursor data URI support");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._true_color) {
|
||||
Display.changeCursor(this._target, pixels, mask, hotx, hoty, w, h);
|
||||
} else {
|
||||
Display.changeCursor(this._target, pixels, mask, hotx, hoty, w, h, this._colourMap);
|
||||
}
|
||||
},
|
||||
|
||||
defaultCursor: function () {
|
||||
this._target.style.cursor = "default";
|
||||
},
|
||||
|
||||
disableLocalCursor: function () {
|
||||
this._target.style.cursor = "none";
|
||||
},
|
||||
|
||||
clippingDisplay: function () {
|
||||
var vp = this._viewportLoc;
|
||||
|
||||
var fbClip = this._fb_width > vp.w || this._fb_height > vp.h;
|
||||
var limitedVp = this._maxWidth !== 0 && this._maxHeight !== 0;
|
||||
var clipping = false;
|
||||
|
||||
if (limitedVp) {
|
||||
clipping = vp.w > this._maxWidth || vp.h > this._maxHeight;
|
||||
}
|
||||
|
||||
return fbClip || (limitedVp && clipping);
|
||||
},
|
||||
|
||||
// Overridden getters/setters
|
||||
get_context: function () {
|
||||
return this._drawCtx;
|
||||
},
|
||||
|
||||
set_scale: function (scale) {
|
||||
this._rescale(scale);
|
||||
},
|
||||
|
||||
set_width: function (w) {
|
||||
this._fb_width = w;
|
||||
},
|
||||
get_width: function () {
|
||||
return this._fb_width;
|
||||
},
|
||||
|
||||
set_height: function (h) {
|
||||
this._fb_height = h;
|
||||
},
|
||||
get_height: function () {
|
||||
return this._fb_height;
|
||||
},
|
||||
|
||||
autoscale: function (containerWidth, containerHeight, downscaleOnly) {
|
||||
var targetAspectRatio = containerWidth / containerHeight;
|
||||
var fbAspectRatio = this._fb_width / this._fb_height;
|
||||
|
||||
var scaleRatio;
|
||||
if (fbAspectRatio >= targetAspectRatio) {
|
||||
scaleRatio = containerWidth / this._fb_width;
|
||||
} else {
|
||||
scaleRatio = containerHeight / this._fb_height;
|
||||
}
|
||||
|
||||
var targetW, targetH;
|
||||
if (scaleRatio > 1.0 && downscaleOnly) {
|
||||
targetW = this._fb_width;
|
||||
targetH = this._fb_height;
|
||||
scaleRatio = 1.0;
|
||||
} else if (fbAspectRatio >= targetAspectRatio) {
|
||||
targetW = containerWidth;
|
||||
targetH = Math.round(containerWidth / fbAspectRatio);
|
||||
} else {
|
||||
targetW = Math.round(containerHeight * fbAspectRatio);
|
||||
targetH = containerHeight;
|
||||
}
|
||||
|
||||
// NB(directxman12): If you set the width directly, or set the
|
||||
// style width to a number, the canvas is cleared.
|
||||
// However, if you set the style width to a string
|
||||
// ('NNNpx'), the canvas is scaled without clearing.
|
||||
this._target.style.width = targetW + 'px';
|
||||
this._target.style.height = targetH + 'px';
|
||||
|
||||
this._scale = scaleRatio;
|
||||
|
||||
return scaleRatio; // so that the mouse, etc scale can be set
|
||||
},
|
||||
|
||||
// Private Methods
|
||||
_rescale: function (factor) {
|
||||
this._scale = factor;
|
||||
|
||||
var w;
|
||||
var h;
|
||||
|
||||
if (this._viewport &&
|
||||
this._maxWidth !== 0 && this._maxHeight !== 0) {
|
||||
w = Math.min(this._fb_width, this._maxWidth);
|
||||
h = Math.min(this._fb_height, this._maxHeight);
|
||||
} else {
|
||||
w = this._fb_width;
|
||||
h = this._fb_height;
|
||||
}
|
||||
|
||||
this._target.style.width = Math.round(factor * w) + 'px';
|
||||
this._target.style.height = Math.round(factor * h) + 'px';
|
||||
},
|
||||
|
||||
_setFillColor: function (color) {
|
||||
var bgr;
|
||||
if (this._true_color) {
|
||||
bgr = color;
|
||||
} else {
|
||||
bgr = this._colourMap[color];
|
||||
}
|
||||
|
||||
var newStyle = 'rgb(' + bgr[2] + ',' + bgr[1] + ',' + bgr[0] + ')';
|
||||
if (newStyle !== this._prevDrawStyle) {
|
||||
this._drawCtx.fillStyle = newStyle;
|
||||
this._prevDrawStyle = newStyle;
|
||||
}
|
||||
},
|
||||
|
||||
_rgbImageData: function (x, y, vx, vy, width, height, arr, offset) {
|
||||
var img = this._drawCtx.createImageData(width, height);
|
||||
var data = img.data;
|
||||
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 3) {
|
||||
data[i] = arr[j];
|
||||
data[i + 1] = arr[j + 1];
|
||||
data[i + 2] = arr[j + 2];
|
||||
data[i + 3] = 255; // Alpha
|
||||
}
|
||||
this._drawCtx.putImageData(img, x - vx, y - vy);
|
||||
},
|
||||
|
||||
_bgrxImageData: function (x, y, vx, vy, width, height, arr, offset) {
|
||||
var img = this._drawCtx.createImageData(width, height);
|
||||
var data = img.data;
|
||||
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
|
||||
data[i] = arr[j + 2];
|
||||
data[i + 1] = arr[j + 1];
|
||||
data[i + 2] = arr[j];
|
||||
data[i + 3] = 255; // Alpha
|
||||
}
|
||||
this._drawCtx.putImageData(img, x - vx, y - vy);
|
||||
},
|
||||
|
||||
_rgbxImageData: function (x, y, vx, vy, width, height, arr, offset) {
|
||||
// NB(directxman12): arr must be an Type Array view
|
||||
var img;
|
||||
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
|
||||
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
|
||||
} else {
|
||||
img = this._drawCtx.createImageData(width, height);
|
||||
img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4));
|
||||
}
|
||||
this._drawCtx.putImageData(img, x - vx, y - vy);
|
||||
},
|
||||
|
||||
_cmapImageData: function (x, y, vx, vy, width, height, arr, offset) {
|
||||
var img = this._drawCtx.createImageData(width, height);
|
||||
var data = img.data;
|
||||
var cmap = this._colourMap;
|
||||
for (var i = 0, j = offset; i < width * height * 4; i += 4, j++) {
|
||||
var bgr = cmap[arr[j]];
|
||||
data[i] = bgr[2];
|
||||
data[i + 1] = bgr[1];
|
||||
data[i + 2] = bgr[0];
|
||||
data[i + 3] = 255; // Alpha
|
||||
}
|
||||
this._drawCtx.putImageData(img, x - vx, y - vy);
|
||||
},
|
||||
|
||||
_scan_renderQ: function () {
|
||||
var ready = true;
|
||||
while (ready && this._renderQ.length > 0) {
|
||||
var a = this._renderQ[0];
|
||||
switch (a.type) {
|
||||
case 'copy':
|
||||
this.copyImage(a.old_x, a.old_y, a.x, a.y, a.width, a.height, true);
|
||||
break;
|
||||
case 'fill':
|
||||
this.fillRect(a.x, a.y, a.width, a.height, a.color, true);
|
||||
break;
|
||||
case 'blit':
|
||||
this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
||||
break;
|
||||
case 'blitRgb':
|
||||
this.blitRgbImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
||||
break;
|
||||
case 'blitRgbx':
|
||||
this.blitRgbxImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
||||
break;
|
||||
case 'img':
|
||||
if (a.img.complete) {
|
||||
this.drawImage(a.img, a.x, a.y);
|
||||
} else {
|
||||
// We need to wait for this image to 'load'
|
||||
// to keep things in-order
|
||||
ready = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (ready) {
|
||||
this._renderQ.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (this._renderQ.length > 0) {
|
||||
requestAnimFrame(this._scan_renderQ.bind(this));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Util.make_properties(Display, [
|
||||
['target', 'wo', 'dom'], // Canvas element for rendering
|
||||
['context', 'ro', 'raw'], // Canvas 2D context for rendering (read-only)
|
||||
['logo', 'rw', 'raw'], // Logo to display when cleared: {"width": w, "height": h, "data": data}
|
||||
['true_color', 'rw', 'bool'], // Use true-color pixel data
|
||||
['colourMap', 'rw', 'arr'], // Colour map array (when not true-color)
|
||||
['scale', 'rw', 'float'], // Display area scale factor 0.0 - 1.0
|
||||
['viewport', 'rw', 'bool'], // Use viewport clipping
|
||||
['width', 'rw', 'int'], // Display area width
|
||||
['height', 'rw', 'int'], // Display area height
|
||||
['maxWidth', 'rw', 'int'], // Viewport max width (0 if disabled)
|
||||
['maxHeight', 'rw', 'int'], // Viewport max height (0 if disabled)
|
||||
|
||||
['render_mode', 'ro', 'str'], // Canvas rendering mode (read-only)
|
||||
|
||||
['prefer_js', 'rw', 'str'], // Prefer Javascript over canvas methods
|
||||
['cursor_uri', 'rw', 'raw'] // Can we render cursor using data URI
|
||||
]);
|
||||
|
||||
// Class Methods
|
||||
Display.changeCursor = function (target, pixels, mask, hotx, hoty, w0, h0, cmap) {
|
||||
var w = w0;
|
||||
var h = h0;
|
||||
if (h < w) {
|
||||
h = w; // increase h to make it square
|
||||
} else {
|
||||
w = h; // increase w to make it square
|
||||
}
|
||||
|
||||
var cur = [];
|
||||
|
||||
// Push multi-byte little-endian values
|
||||
cur.push16le = function (num) {
|
||||
this.push(num & 0xFF, (num >> 8) & 0xFF);
|
||||
};
|
||||
cur.push32le = function (num) {
|
||||
this.push(num & 0xFF,
|
||||
(num >> 8) & 0xFF,
|
||||
(num >> 16) & 0xFF,
|
||||
(num >> 24) & 0xFF);
|
||||
};
|
||||
|
||||
var IHDRsz = 40;
|
||||
var RGBsz = w * h * 4;
|
||||
var XORsz = Math.ceil((w * h) / 8.0);
|
||||
var ANDsz = Math.ceil((w * h) / 8.0);
|
||||
|
||||
cur.push16le(0); // 0: Reserved
|
||||
cur.push16le(2); // 2: .CUR type
|
||||
cur.push16le(1); // 4: Number of images, 1 for non-animated ico
|
||||
|
||||
// Cursor #1 header (ICONDIRENTRY)
|
||||
cur.push(w); // 6: width
|
||||
cur.push(h); // 7: height
|
||||
cur.push(0); // 8: colors, 0 -> true-color
|
||||
cur.push(0); // 9: reserved
|
||||
cur.push16le(hotx); // 10: hotspot x coordinate
|
||||
cur.push16le(hoty); // 12: hotspot y coordinate
|
||||
cur.push32le(IHDRsz + RGBsz + XORsz + ANDsz);
|
||||
// 14: cursor data byte size
|
||||
cur.push32le(22); // 18: offset of cursor data in the file
|
||||
|
||||
// Cursor #1 InfoHeader (ICONIMAGE/BITMAPINFO)
|
||||
cur.push32le(IHDRsz); // 22: InfoHeader size
|
||||
cur.push32le(w); // 26: Cursor width
|
||||
cur.push32le(h * 2); // 30: XOR+AND height
|
||||
cur.push16le(1); // 34: number of planes
|
||||
cur.push16le(32); // 36: bits per pixel
|
||||
cur.push32le(0); // 38: Type of compression
|
||||
|
||||
cur.push32le(XORsz + ANDsz);
|
||||
// 42: Size of Image
|
||||
cur.push32le(0); // 46: reserved
|
||||
cur.push32le(0); // 50: reserved
|
||||
cur.push32le(0); // 54: reserved
|
||||
cur.push32le(0); // 58: reserved
|
||||
|
||||
// 62: color data (RGBQUAD icColors[])
|
||||
var y, x;
|
||||
for (y = h - 1; y >= 0; y--) {
|
||||
for (x = 0; x < w; x++) {
|
||||
if (x >= w0 || y >= h0) {
|
||||
cur.push(0); // blue
|
||||
cur.push(0); // green
|
||||
cur.push(0); // red
|
||||
cur.push(0); // alpha
|
||||
} else {
|
||||
var idx = y * Math.ceil(w0 / 8) + Math.floor(x / 8);
|
||||
var alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
|
||||
if (cmap) {
|
||||
idx = (w0 * y) + x;
|
||||
var rgb = cmap[pixels[idx]];
|
||||
cur.push(rgb[2]); // blue
|
||||
cur.push(rgb[1]); // green
|
||||
cur.push(rgb[0]); // red
|
||||
cur.push(alpha); // alpha
|
||||
} else {
|
||||
idx = ((w0 * y) + x) * 4;
|
||||
cur.push(pixels[idx + 2]); // blue
|
||||
cur.push(pixels[idx + 1]); // green
|
||||
cur.push(pixels[idx]); // red
|
||||
cur.push(alpha); // alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XOR/bitmask data (BYTE icXOR[])
|
||||
// (ignored, just needs to be the right size)
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < Math.ceil(w / 8); x++) {
|
||||
cur.push(0);
|
||||
}
|
||||
}
|
||||
|
||||
// AND/bitmask data (BYTE icAND[])
|
||||
// (ignored, just needs to be the right size)
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < Math.ceil(w / 8); x++) {
|
||||
cur.push(0);
|
||||
}
|
||||
}
|
||||
|
||||
var url = 'data:image/x-icon;base64,' + Base64.encode(cur);
|
||||
target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default';
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
|
||||
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
/*jslint browser: true, white: false */
|
||||
/*global window, Util */
|
||||
|
||||
var Keyboard, Mouse;
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
//
|
||||
// Keyboard event handler
|
||||
//
|
||||
|
||||
Keyboard = function (defaults) {
|
||||
this._keyDownList = []; // List of depressed keys
|
||||
// (even if they are happy)
|
||||
|
||||
Util.set_defaults(this, defaults, {
|
||||
'target': document,
|
||||
'focused': true
|
||||
});
|
||||
|
||||
// create the keyboard handler
|
||||
this._handler = new KeyEventDecoder(kbdUtil.ModifierSync(),
|
||||
VerifyCharModifier( /* jshint newcap: false */
|
||||
TrackKeyState(
|
||||
EscapeModifiers(this._handleRfbEvent.bind(this))
|
||||
)
|
||||
)
|
||||
); /* jshint newcap: true */
|
||||
|
||||
// keep these here so we can refer to them later
|
||||
this._eventHandlers = {
|
||||
'keyup': this._handleKeyUp.bind(this),
|
||||
'keydown': this._handleKeyDown.bind(this),
|
||||
'keypress': this._handleKeyPress.bind(this),
|
||||
'blur': this._allKeysUp.bind(this)
|
||||
};
|
||||
};
|
||||
|
||||
Keyboard.prototype = {
|
||||
// private methods
|
||||
|
||||
_handleRfbEvent: function (e) {
|
||||
if (this._onKeyPress) {
|
||||
Util.Debug("onKeyPress " + (e.type == 'keydown' ? "down" : "up") +
|
||||
", keysym: " + e.keysym.keysym + "(" + e.keysym.keyname + ")");
|
||||
this._onKeyPress(e.keysym.keysym, e.type == 'keydown');
|
||||
}
|
||||
},
|
||||
|
||||
_handleKeyDown: function (e) {
|
||||
if (!this._focused) { return true; }
|
||||
|
||||
if (this._handler.keydown(e)) {
|
||||
// Suppress bubbling/default actions
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
} else {
|
||||
// Allow the event to bubble and become a keyPress event which
|
||||
// will have the character code translated
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
_handleKeyPress: function (e) {
|
||||
if (!this._focused) { return true; }
|
||||
|
||||
if (this._handler.keypress(e)) {
|
||||
// Suppress bubbling/default actions
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
} else {
|
||||
// Allow the event to bubble and become a keyPress event which
|
||||
// will have the character code translated
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
_handleKeyUp: function (e) {
|
||||
if (!this._focused) { return true; }
|
||||
|
||||
if (this._handler.keyup(e)) {
|
||||
// Suppress bubbling/default actions
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
} else {
|
||||
// Allow the event to bubble and become a keyPress event which
|
||||
// will have the character code translated
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
_allKeysUp: function () {
|
||||
Util.Debug(">> Keyboard.allKeysUp");
|
||||
this._handler.releaseAll();
|
||||
Util.Debug("<< Keyboard.allKeysUp");
|
||||
},
|
||||
|
||||
// Public methods
|
||||
|
||||
grab: function () {
|
||||
//Util.Debug(">> Keyboard.grab");
|
||||
var c = this._target;
|
||||
|
||||
Util.addEvent(c, 'keydown', this._eventHandlers.keydown);
|
||||
Util.addEvent(c, 'keyup', this._eventHandlers.keyup);
|
||||
Util.addEvent(c, 'keypress', this._eventHandlers.keypress);
|
||||
|
||||
// Release (key up) if window loses focus
|
||||
Util.addEvent(window, 'blur', this._eventHandlers.blur);
|
||||
|
||||
//Util.Debug("<< Keyboard.grab");
|
||||
},
|
||||
|
||||
ungrab: function () {
|
||||
//Util.Debug(">> Keyboard.ungrab");
|
||||
var c = this._target;
|
||||
|
||||
Util.removeEvent(c, 'keydown', this._eventHandlers.keydown);
|
||||
Util.removeEvent(c, 'keyup', this._eventHandlers.keyup);
|
||||
Util.removeEvent(c, 'keypress', this._eventHandlers.keypress);
|
||||
Util.removeEvent(window, 'blur', this._eventHandlers.blur);
|
||||
|
||||
// Release (key up) all keys that are in a down state
|
||||
this._allKeysUp();
|
||||
|
||||
//Util.Debug(">> Keyboard.ungrab");
|
||||
},
|
||||
|
||||
sync: function (e) {
|
||||
this._handler.syncModifiers(e);
|
||||
}
|
||||
};
|
||||
|
||||
Util.make_properties(Keyboard, [
|
||||
['target', 'wo', 'dom'], // DOM element that captures keyboard input
|
||||
['focused', 'rw', 'bool'], // Capture and send key events
|
||||
|
||||
['onKeyPress', 'rw', 'func'] // Handler for key press/release
|
||||
]);
|
||||
|
||||
//
|
||||
// Mouse event handler
|
||||
//
|
||||
|
||||
Mouse = function (defaults) {
|
||||
this._mouseCaptured = false;
|
||||
|
||||
this._doubleClickTimer = null;
|
||||
this._lastTouchPos = null;
|
||||
|
||||
// Configuration attributes
|
||||
Util.set_defaults(this, defaults, {
|
||||
'target': document,
|
||||
'focused': true,
|
||||
'scale': 1.0,
|
||||
'touchButton': 1
|
||||
});
|
||||
|
||||
this._eventHandlers = {
|
||||
'mousedown': this._handleMouseDown.bind(this),
|
||||
'mouseup': this._handleMouseUp.bind(this),
|
||||
'mousemove': this._handleMouseMove.bind(this),
|
||||
'mousewheel': this._handleMouseWheel.bind(this),
|
||||
'mousedisable': this._handleMouseDisable.bind(this)
|
||||
};
|
||||
};
|
||||
|
||||
Mouse.prototype = {
|
||||
// private methods
|
||||
_captureMouse: function () {
|
||||
// capturing the mouse ensures we get the mouseup event
|
||||
if (this._target.setCapture) {
|
||||
this._target.setCapture();
|
||||
}
|
||||
|
||||
// some browsers give us mouseup events regardless,
|
||||
// so if we never captured the mouse, we can disregard the event
|
||||
this._mouseCaptured = true;
|
||||
},
|
||||
|
||||
_releaseMouse: function () {
|
||||
if (this._target.releaseCapture) {
|
||||
this._target.releaseCapture();
|
||||
}
|
||||
this._mouseCaptured = false;
|
||||
},
|
||||
|
||||
_resetDoubleClickTimer: function () {
|
||||
this._doubleClickTimer = null;
|
||||
},
|
||||
|
||||
_handleMouseButton: function (e, down) {
|
||||
if (!this._focused) { return true; }
|
||||
|
||||
if (this._notify) {
|
||||
this._notify(e);
|
||||
}
|
||||
|
||||
var evt = (e ? e : window.event);
|
||||
var pos = Util.getEventPosition(e, this._target, this._scale);
|
||||
|
||||
var bmask;
|
||||
if (e.touches || e.changedTouches) {
|
||||
// Touch device
|
||||
|
||||
// When two touches occur within 500 ms of each other and are
|
||||
// closer than 20 pixels together a double click is triggered.
|
||||
if (down == 1) {
|
||||
if (this._doubleClickTimer === null) {
|
||||
this._lastTouchPos = pos;
|
||||
} else {
|
||||
clearTimeout(this._doubleClickTimer);
|
||||
|
||||
// When the distance between the two touches is small enough
|
||||
// force the position of the latter touch to the position of
|
||||
// the first.
|
||||
|
||||
var xs = this._lastTouchPos.x - pos.x;
|
||||
var ys = this._lastTouchPos.y - pos.y;
|
||||
var d = Math.sqrt((xs * xs) + (ys * ys));
|
||||
|
||||
// The goal is to trigger on a certain physical width, the
|
||||
// devicePixelRatio brings us a bit closer but is not optimal.
|
||||
if (d < 20 * window.devicePixelRatio) {
|
||||
pos = this._lastTouchPos;
|
||||
}
|
||||
}
|
||||
this._doubleClickTimer = setTimeout(this._resetDoubleClickTimer.bind(this), 500);
|
||||
}
|
||||
bmask = this._touchButton;
|
||||
// If bmask is set
|
||||
} else if (evt.which) {
|
||||
/* everything except IE */
|
||||
bmask = 1 << evt.button;
|
||||
} else {
|
||||
/* IE including 9 */
|
||||
bmask = (evt.button & 0x1) + // Left
|
||||
(evt.button & 0x2) * 2 + // Right
|
||||
(evt.button & 0x4) / 2; // Middle
|
||||
}
|
||||
|
||||
if (this._onMouseButton) {
|
||||
Util.Debug("onMouseButton " + (down ? "down" : "up") +
|
||||
", x: " + pos.x + ", y: " + pos.y + ", bmask: " + bmask);
|
||||
this._onMouseButton(pos.x, pos.y, down, bmask);
|
||||
}
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
},
|
||||
|
||||
_handleMouseDown: function (e) {
|
||||
this._captureMouse();
|
||||
this._handleMouseButton(e, 1);
|
||||
},
|
||||
|
||||
_handleMouseUp: function (e) {
|
||||
if (!this._mouseCaptured) { return; }
|
||||
|
||||
this._handleMouseButton(e, 0);
|
||||
this._releaseMouse();
|
||||
},
|
||||
|
||||
_handleMouseWheel: function (e) {
|
||||
if (!this._focused) { return true; }
|
||||
|
||||
if (this._notify) {
|
||||
this._notify(e);
|
||||
}
|
||||
|
||||
var evt = (e ? e : window.event);
|
||||
var pos = Util.getEventPosition(e, this._target, this._scale);
|
||||
var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
|
||||
var bmask;
|
||||
if (wheelData > 0) {
|
||||
bmask = 1 << 3;
|
||||
} else {
|
||||
bmask = 1 << 4;
|
||||
}
|
||||
|
||||
if (this._onMouseButton) {
|
||||
this._onMouseButton(pos.x, pos.y, 1, bmask);
|
||||
this._onMouseButton(pos.x, pos.y, 0, bmask);
|
||||
}
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
},
|
||||
|
||||
_handleMouseMove: function (e) {
|
||||
if (! this._focused) { return true; }
|
||||
|
||||
if (this._notify) {
|
||||
this._notify(e);
|
||||
}
|
||||
|
||||
var evt = (e ? e : window.event);
|
||||
var pos = Util.getEventPosition(e, this._target, this._scale);
|
||||
if (this._onMouseMove) {
|
||||
this._onMouseMove(pos.x, pos.y);
|
||||
}
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
},
|
||||
|
||||
_handleMouseDisable: function (e) {
|
||||
if (!this._focused) { return true; }
|
||||
|
||||
var evt = (e ? e : window.event);
|
||||
var pos = Util.getEventPosition(e, this._target, this._scale);
|
||||
|
||||
/* Stop propagation if inside canvas area */
|
||||
if ((pos.realx >= 0) && (pos.realy >= 0) &&
|
||||
(pos.realx < this._target.offsetWidth) &&
|
||||
(pos.realy < this._target.offsetHeight)) {
|
||||
//Util.Debug("mouse event disabled");
|
||||
Util.stopEvent(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
// Public methods
|
||||
grab: function () {
|
||||
var c = this._target;
|
||||
|
||||
if ('ontouchstart' in document.documentElement) {
|
||||
Util.addEvent(c, 'touchstart', this._eventHandlers.mousedown);
|
||||
Util.addEvent(window, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'touchmove', this._eventHandlers.mousemove);
|
||||
} else {
|
||||
Util.addEvent(c, 'mousedown', this._eventHandlers.mousedown);
|
||||
Util.addEvent(window, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'mousemove', this._eventHandlers.mousemove);
|
||||
Util.addEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||
this._eventHandlers.mousewheel);
|
||||
}
|
||||
|
||||
/* Work around right and middle click browser behaviors */
|
||||
Util.addEvent(document, 'click', this._eventHandlers.mousedisable);
|
||||
Util.addEvent(document.body, 'contextmenu', this._eventHandlers.mousedisable);
|
||||
},
|
||||
|
||||
ungrab: function () {
|
||||
var c = this._target;
|
||||
|
||||
if ('ontouchstart' in document.documentElement) {
|
||||
Util.removeEvent(c, 'touchstart', this._eventHandlers.mousedown);
|
||||
Util.removeEvent(window, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'touchmove', this._eventHandlers.mousemove);
|
||||
} else {
|
||||
Util.removeEvent(c, 'mousedown', this._eventHandlers.mousedown);
|
||||
Util.removeEvent(window, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'mousemove', this._eventHandlers.mousemove);
|
||||
Util.removeEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||
this._eventHandlers.mousewheel);
|
||||
}
|
||||
|
||||
/* Work around right and middle click browser behaviors */
|
||||
Util.removeEvent(document, 'click', this._eventHandlers.mousedisable);
|
||||
Util.removeEvent(document.body, 'contextmenu', this._eventHandlers.mousedisable);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Util.make_properties(Mouse, [
|
||||
['target', 'ro', 'dom'], // DOM element that captures mouse input
|
||||
['notify', 'ro', 'func'], // Function to call to notify whenever a mouse event is received
|
||||
['focused', 'rw', 'bool'], // Capture and send mouse clicks/movement
|
||||
['scale', 'rw', 'float'], // Viewport scale factor 0.0 - 1.0
|
||||
|
||||
['onMouseButton', 'rw', 'func'], // Handler for mouse button click/release
|
||||
['onMouseMove', 'rw', 'func'], // Handler for mouse movement
|
||||
['touchButton', 'rw', 'int'] // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
|
||||
]);
|
||||
})();
|
||||
@@ -0,0 +1,676 @@
|
||||
/*
|
||||
* JSUnzip
|
||||
*
|
||||
* Copyright (c) 2011 by Erik Moller
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
var tinf;
|
||||
|
||||
function JSUnzip() {
|
||||
|
||||
this.getInt = function(offset, size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return (this.data.charCodeAt(offset + 3) & 0xff) << 24 |
|
||||
(this.data.charCodeAt(offset + 2) & 0xff) << 16 |
|
||||
(this.data.charCodeAt(offset + 1) & 0xff) << 8 |
|
||||
(this.data.charCodeAt(offset + 0) & 0xff);
|
||||
break;
|
||||
case 2:
|
||||
return (this.data.charCodeAt(offset + 1) & 0xff) << 8 |
|
||||
(this.data.charCodeAt(offset + 0) & 0xff);
|
||||
break;
|
||||
default:
|
||||
return this.data.charCodeAt(offset) & 0xff;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
this.getDOSDate = function(dosdate, dostime) {
|
||||
var day = dosdate & 0x1f;
|
||||
var month = ((dosdate >> 5) & 0xf) - 1;
|
||||
var year = 1980 + ((dosdate >> 9) & 0x7f)
|
||||
var second = (dostime & 0x1f) * 2;
|
||||
var minute = (dostime >> 5) & 0x3f;
|
||||
hour = (dostime >> 11) & 0x1f;
|
||||
return new Date(year, month, day, hour, minute, second);
|
||||
}
|
||||
|
||||
this.open = function(data) {
|
||||
this.data = data;
|
||||
this.files = [];
|
||||
|
||||
if (this.data.length < 22)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
var endOfCentralDirectory = this.data.length - 22;
|
||||
while (endOfCentralDirectory >= 0 && this.getInt(endOfCentralDirectory, 4) != 0x06054b50)
|
||||
--endOfCentralDirectory;
|
||||
if (endOfCentralDirectory < 0)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
if (this.getInt(endOfCentralDirectory + 4, 2) != 0 || this.getInt(endOfCentralDirectory + 6, 2) != 0)
|
||||
return { 'status' : false, 'error' : 'No multidisk support' };
|
||||
|
||||
var entriesInThisDisk = this.getInt(endOfCentralDirectory + 8, 2);
|
||||
var centralDirectoryOffset = this.getInt(endOfCentralDirectory + 16, 4);
|
||||
var globalCommentLength = this.getInt(endOfCentralDirectory + 20, 2);
|
||||
this.comment = this.data.slice(endOfCentralDirectory + 22, endOfCentralDirectory + 22 + globalCommentLength);
|
||||
|
||||
var fileOffset = centralDirectoryOffset;
|
||||
|
||||
for (var i = 0; i < entriesInThisDisk; ++i) {
|
||||
if (this.getInt(fileOffset + 0, 4) != 0x02014b50)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
if (this.getInt(fileOffset + 6, 2) > 20)
|
||||
return { 'status' : false, 'error' : 'Unsupported version' };
|
||||
if (this.getInt(fileOffset + 8, 2) & 1)
|
||||
return { 'status' : false, 'error' : 'Encryption not implemented' };
|
||||
|
||||
var compressionMethod = this.getInt(fileOffset + 10, 2);
|
||||
if (compressionMethod != 0 && compressionMethod != 8)
|
||||
return { 'status' : false, 'error' : 'Unsupported compression method' };
|
||||
|
||||
var lastModFileTime = this.getInt(fileOffset + 12, 2);
|
||||
var lastModFileDate = this.getInt(fileOffset + 14, 2);
|
||||
var lastModifiedDate = this.getDOSDate(lastModFileDate, lastModFileTime);
|
||||
|
||||
var crc = this.getInt(fileOffset + 16, 4);
|
||||
// TODO: crc
|
||||
|
||||
var compressedSize = this.getInt(fileOffset + 20, 4);
|
||||
var uncompressedSize = this.getInt(fileOffset + 24, 4);
|
||||
|
||||
var fileNameLength = this.getInt(fileOffset + 28, 2);
|
||||
var extraFieldLength = this.getInt(fileOffset + 30, 2);
|
||||
var fileCommentLength = this.getInt(fileOffset + 32, 2);
|
||||
|
||||
var relativeOffsetOfLocalHeader = this.getInt(fileOffset + 42, 4);
|
||||
|
||||
var fileName = this.data.slice(fileOffset + 46, fileOffset + 46 + fileNameLength);
|
||||
var fileComment = this.data.slice(fileOffset + 46 + fileNameLength + extraFieldLength, fileOffset + 46 + fileNameLength + extraFieldLength + fileCommentLength);
|
||||
|
||||
if (this.getInt(relativeOffsetOfLocalHeader + 0, 4) != 0x04034b50)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
var localFileNameLength = this.getInt(relativeOffsetOfLocalHeader + 26, 2);
|
||||
var localExtraFieldLength = this.getInt(relativeOffsetOfLocalHeader + 28, 2);
|
||||
var localFileContent = relativeOffsetOfLocalHeader + 30 + localFileNameLength + localExtraFieldLength;
|
||||
|
||||
this.files[fileName] =
|
||||
{
|
||||
'fileComment' : fileComment,
|
||||
'compressionMethod' : compressionMethod,
|
||||
'compressedSize' : compressedSize,
|
||||
'uncompressedSize' : uncompressedSize,
|
||||
'localFileContent' : localFileContent,
|
||||
'lastModifiedDate' : lastModifiedDate
|
||||
};
|
||||
|
||||
fileOffset += 46 + fileNameLength + extraFieldLength + fileCommentLength;
|
||||
}
|
||||
return { 'status' : true }
|
||||
};
|
||||
|
||||
|
||||
this.read = function(fileName) {
|
||||
var fileInfo = this.files[fileName];
|
||||
if (fileInfo) {
|
||||
if (fileInfo.compressionMethod == 8) {
|
||||
if (!tinf) {
|
||||
tinf = new TINF();
|
||||
tinf.init();
|
||||
}
|
||||
var result = tinf.uncompress(this.data, fileInfo.localFileContent);
|
||||
if (result.status == tinf.OK)
|
||||
return { 'status' : true, 'data' : result.data };
|
||||
else
|
||||
return { 'status' : false, 'error' : result.error };
|
||||
} else {
|
||||
return { 'status' : true, 'data' : this.data.slice(fileInfo.localFileContent, fileInfo.localFileContent + fileInfo.uncompressedSize) };
|
||||
}
|
||||
}
|
||||
return { 'status' : false, 'error' : "File '" + fileName + "' doesn't exist in zip" };
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* tinflate - tiny inflate
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* tinflate javascript port by Erik Moller in May 2011.
|
||||
* emoller@opera.com
|
||||
*
|
||||
* read_bits() patched by mike@imidio.com to allow
|
||||
* reading more then 8 bits (needed in some zlib streams)
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
function TINF() {
|
||||
|
||||
this.OK = 0;
|
||||
this.DATA_ERROR = (-3);
|
||||
this.WINDOW_SIZE = 32768;
|
||||
|
||||
/* ------------------------------ *
|
||||
* -- internal data structures -- *
|
||||
* ------------------------------ */
|
||||
|
||||
this.TREE = function() {
|
||||
this.table = new Array(16); /* table of code length counts */
|
||||
this.trans = new Array(288); /* code -> symbol translation table */
|
||||
};
|
||||
|
||||
this.DATA = function(that) {
|
||||
this.source = '';
|
||||
this.sourceIndex = 0;
|
||||
this.tag = 0;
|
||||
this.bitcount = 0;
|
||||
|
||||
this.dest = [];
|
||||
|
||||
this.history = [];
|
||||
|
||||
this.ltree = new that.TREE(); /* dynamic length/symbol tree */
|
||||
this.dtree = new that.TREE(); /* dynamic distance tree */
|
||||
};
|
||||
|
||||
/* --------------------------------------------------- *
|
||||
* -- uninitialized global data (static structures) -- *
|
||||
* --------------------------------------------------- */
|
||||
|
||||
this.sltree = new this.TREE(); /* fixed length/symbol tree */
|
||||
this.sdtree = new this.TREE(); /* fixed distance tree */
|
||||
|
||||
/* extra bits and base tables for length codes */
|
||||
this.length_bits = new Array(30);
|
||||
this.length_base = new Array(30);
|
||||
|
||||
/* extra bits and base tables for distance codes */
|
||||
this.dist_bits = new Array(30);
|
||||
this.dist_base = new Array(30);
|
||||
|
||||
/* special ordering of code length codes */
|
||||
this.clcidx = [
|
||||
16, 17, 18, 0, 8, 7, 9, 6,
|
||||
10, 5, 11, 4, 12, 3, 13, 2,
|
||||
14, 1, 15
|
||||
];
|
||||
|
||||
/* ----------------------- *
|
||||
* -- utility functions -- *
|
||||
* ----------------------- */
|
||||
|
||||
/* build extra bits and base tables */
|
||||
this.build_bits_base = function(bits, base, delta, first)
|
||||
{
|
||||
var i, sum;
|
||||
|
||||
/* build bits table */
|
||||
for (i = 0; i < delta; ++i) bits[i] = 0;
|
||||
for (i = 0; i < 30 - delta; ++i) bits[i + delta] = Math.floor(i / delta);
|
||||
|
||||
/* build base table */
|
||||
for (sum = first, i = 0; i < 30; ++i)
|
||||
{
|
||||
base[i] = sum;
|
||||
sum += 1 << bits[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* build the fixed huffman trees */
|
||||
this.build_fixed_trees = function(lt, dt)
|
||||
{
|
||||
var i;
|
||||
|
||||
/* build fixed length tree */
|
||||
for (i = 0; i < 7; ++i) lt.table[i] = 0;
|
||||
|
||||
lt.table[7] = 24;
|
||||
lt.table[8] = 152;
|
||||
lt.table[9] = 112;
|
||||
|
||||
for (i = 0; i < 24; ++i) lt.trans[i] = 256 + i;
|
||||
for (i = 0; i < 144; ++i) lt.trans[24 + i] = i;
|
||||
for (i = 0; i < 8; ++i) lt.trans[24 + 144 + i] = 280 + i;
|
||||
for (i = 0; i < 112; ++i) lt.trans[24 + 144 + 8 + i] = 144 + i;
|
||||
|
||||
/* build fixed distance tree */
|
||||
for (i = 0; i < 5; ++i) dt.table[i] = 0;
|
||||
|
||||
dt.table[5] = 32;
|
||||
|
||||
for (i = 0; i < 32; ++i) dt.trans[i] = i;
|
||||
}
|
||||
|
||||
/* given an array of code lengths, build a tree */
|
||||
this.build_tree = function(t, lengths, loffset, num)
|
||||
{
|
||||
var offs = new Array(16);
|
||||
var i, sum;
|
||||
|
||||
/* clear code length count table */
|
||||
for (i = 0; i < 16; ++i) t.table[i] = 0;
|
||||
|
||||
/* scan symbol lengths, and sum code length counts */
|
||||
for (i = 0; i < num; ++i) t.table[lengths[loffset + i]]++;
|
||||
|
||||
t.table[0] = 0;
|
||||
|
||||
/* compute offset table for distribution sort */
|
||||
for (sum = 0, i = 0; i < 16; ++i)
|
||||
{
|
||||
offs[i] = sum;
|
||||
sum += t.table[i];
|
||||
}
|
||||
|
||||
/* create code->symbol translation table (symbols sorted by code) */
|
||||
for (i = 0; i < num; ++i)
|
||||
{
|
||||
if (lengths[loffset + i]) t.trans[offs[lengths[loffset + i]]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------- *
|
||||
* -- decode functions -- *
|
||||
* ---------------------- */
|
||||
|
||||
/* get one bit from source stream */
|
||||
this.getbit = function(d)
|
||||
{
|
||||
var bit;
|
||||
|
||||
/* check if tag is empty */
|
||||
if (!d.bitcount--)
|
||||
{
|
||||
/* load next tag */
|
||||
d.tag = d.source[d.sourceIndex++] & 0xff;
|
||||
d.bitcount = 7;
|
||||
}
|
||||
|
||||
/* shift bit out of tag */
|
||||
bit = d.tag & 0x01;
|
||||
d.tag >>= 1;
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/* read a num bit value from a stream and add base */
|
||||
function read_bits_direct(source, bitcount, tag, idx, num)
|
||||
{
|
||||
var val = 0;
|
||||
while (bitcount < 24) {
|
||||
tag = tag | (source[idx++] & 0xff) << bitcount;
|
||||
bitcount += 8;
|
||||
}
|
||||
val = tag & (0xffff >> (16 - num));
|
||||
tag >>= num;
|
||||
bitcount -= num;
|
||||
return [bitcount, tag, idx, val];
|
||||
}
|
||||
this.read_bits = function(d, num, base)
|
||||
{
|
||||
if (!num)
|
||||
return base;
|
||||
|
||||
var ret = read_bits_direct(d.source, d.bitcount, d.tag, d.sourceIndex, num);
|
||||
d.bitcount = ret[0];
|
||||
d.tag = ret[1];
|
||||
d.sourceIndex = ret[2];
|
||||
return ret[3] + base;
|
||||
}
|
||||
|
||||
/* given a data stream and a tree, decode a symbol */
|
||||
this.decode_symbol = function(d, t)
|
||||
{
|
||||
while (d.bitcount < 16) {
|
||||
d.tag = d.tag | (d.source[d.sourceIndex++] & 0xff) << d.bitcount;
|
||||
d.bitcount += 8;
|
||||
}
|
||||
|
||||
var sum = 0, cur = 0, len = 0;
|
||||
do {
|
||||
cur = 2 * cur + ((d.tag & (1 << len)) >> len);
|
||||
|
||||
++len;
|
||||
|
||||
sum += t.table[len];
|
||||
cur -= t.table[len];
|
||||
|
||||
} while (cur >= 0);
|
||||
|
||||
d.tag >>= len;
|
||||
d.bitcount -= len;
|
||||
|
||||
return t.trans[sum + cur];
|
||||
}
|
||||
|
||||
/* given a data stream, decode dynamic trees from it */
|
||||
this.decode_trees = function(d, lt, dt)
|
||||
{
|
||||
var code_tree = new this.TREE();
|
||||
var lengths = new Array(288+32);
|
||||
var hlit, hdist, hclen;
|
||||
var i, num, length;
|
||||
|
||||
/* get 5 bits HLIT (257-286) */
|
||||
hlit = this.read_bits(d, 5, 257);
|
||||
|
||||
/* get 5 bits HDIST (1-32) */
|
||||
hdist = this.read_bits(d, 5, 1);
|
||||
|
||||
/* get 4 bits HCLEN (4-19) */
|
||||
hclen = this.read_bits(d, 4, 4);
|
||||
|
||||
for (i = 0; i < 19; ++i) lengths[i] = 0;
|
||||
|
||||
/* read code lengths for code length alphabet */
|
||||
for (i = 0; i < hclen; ++i)
|
||||
{
|
||||
/* get 3 bits code length (0-7) */
|
||||
var clen = this.read_bits(d, 3, 0);
|
||||
|
||||
lengths[this.clcidx[i]] = clen;
|
||||
}
|
||||
|
||||
/* build code length tree */
|
||||
this.build_tree(code_tree, lengths, 0, 19);
|
||||
|
||||
/* decode code lengths for the dynamic trees */
|
||||
for (num = 0; num < hlit + hdist; )
|
||||
{
|
||||
var sym = this.decode_symbol(d, code_tree);
|
||||
|
||||
switch (sym)
|
||||
{
|
||||
case 16:
|
||||
/* copy previous code length 3-6 times (read 2 bits) */
|
||||
{
|
||||
var prev = lengths[num - 1];
|
||||
for (length = this.read_bits(d, 2, 3); length; --length)
|
||||
{
|
||||
lengths[num++] = prev;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
/* repeat code length 0 for 3-10 times (read 3 bits) */
|
||||
for (length = this.read_bits(d, 3, 3); length; --length)
|
||||
{
|
||||
lengths[num++] = 0;
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
/* repeat code length 0 for 11-138 times (read 7 bits) */
|
||||
for (length = this.read_bits(d, 7, 11); length; --length)
|
||||
{
|
||||
lengths[num++] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* values 0-15 represent the actual code lengths */
|
||||
lengths[num++] = sym;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* build dynamic trees */
|
||||
this.build_tree(lt, lengths, 0, hlit);
|
||||
this.build_tree(dt, lengths, hlit, hdist);
|
||||
}
|
||||
|
||||
/* ----------------------------- *
|
||||
* -- block inflate functions -- *
|
||||
* ----------------------------- */
|
||||
|
||||
/* given a stream and two trees, inflate a block of data */
|
||||
this.inflate_block_data = function(d, lt, dt)
|
||||
{
|
||||
// js optimization.
|
||||
var ddest = d.dest;
|
||||
var ddestlength = ddest.length;
|
||||
|
||||
while (1)
|
||||
{
|
||||
var sym = this.decode_symbol(d, lt);
|
||||
|
||||
/* check for end of block */
|
||||
if (sym == 256)
|
||||
{
|
||||
return this.OK;
|
||||
}
|
||||
|
||||
if (sym < 256)
|
||||
{
|
||||
ddest[ddestlength++] = sym; // ? String.fromCharCode(sym);
|
||||
d.history.push(sym);
|
||||
} else {
|
||||
|
||||
var length, dist, offs;
|
||||
var i;
|
||||
|
||||
sym -= 257;
|
||||
|
||||
/* possibly get more bits from length code */
|
||||
length = this.read_bits(d, this.length_bits[sym], this.length_base[sym]);
|
||||
|
||||
dist = this.decode_symbol(d, dt);
|
||||
|
||||
/* possibly get more bits from distance code */
|
||||
offs = d.history.length - this.read_bits(d, this.dist_bits[dist], this.dist_base[dist]);
|
||||
|
||||
if (offs < 0)
|
||||
throw ("Invalid zlib offset " + offs);
|
||||
|
||||
/* copy match */
|
||||
for (i = offs; i < offs + length; ++i) {
|
||||
//ddest[ddestlength++] = ddest[i];
|
||||
ddest[ddestlength++] = d.history[i];
|
||||
d.history.push(d.history[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* inflate an uncompressed block of data */
|
||||
this.inflate_uncompressed_block = function(d)
|
||||
{
|
||||
var length, invlength;
|
||||
var i;
|
||||
|
||||
if (d.bitcount > 7) {
|
||||
var overflow = Math.floor(d.bitcount / 8);
|
||||
d.sourceIndex -= overflow;
|
||||
d.bitcount = 0;
|
||||
d.tag = 0;
|
||||
}
|
||||
|
||||
/* get length */
|
||||
length = d.source[d.sourceIndex+1];
|
||||
length = 256*length + d.source[d.sourceIndex];
|
||||
|
||||
/* get one's complement of length */
|
||||
invlength = d.source[d.sourceIndex+3];
|
||||
invlength = 256*invlength + d.source[d.sourceIndex+2];
|
||||
|
||||
/* check length */
|
||||
if (length != (~invlength & 0x0000ffff)) return this.DATA_ERROR;
|
||||
|
||||
d.sourceIndex += 4;
|
||||
|
||||
/* copy block */
|
||||
for (i = length; i; --i) {
|
||||
d.history.push(d.source[d.sourceIndex]);
|
||||
d.dest[d.dest.length] = d.source[d.sourceIndex++];
|
||||
}
|
||||
|
||||
/* make sure we start next block on a byte boundary */
|
||||
d.bitcount = 0;
|
||||
|
||||
return this.OK;
|
||||
}
|
||||
|
||||
/* inflate a block of data compressed with fixed huffman trees */
|
||||
this.inflate_fixed_block = function(d)
|
||||
{
|
||||
/* decode block using fixed trees */
|
||||
return this.inflate_block_data(d, this.sltree, this.sdtree);
|
||||
}
|
||||
|
||||
/* inflate a block of data compressed with dynamic huffman trees */
|
||||
this.inflate_dynamic_block = function(d)
|
||||
{
|
||||
/* decode trees from stream */
|
||||
this.decode_trees(d, d.ltree, d.dtree);
|
||||
|
||||
/* decode block using decoded trees */
|
||||
return this.inflate_block_data(d, d.ltree, d.dtree);
|
||||
}
|
||||
|
||||
/* ---------------------- *
|
||||
* -- public functions -- *
|
||||
* ---------------------- */
|
||||
|
||||
/* initialize global (static) data */
|
||||
this.init = function()
|
||||
{
|
||||
/* build fixed huffman trees */
|
||||
this.build_fixed_trees(this.sltree, this.sdtree);
|
||||
|
||||
/* build extra bits and base tables */
|
||||
this.build_bits_base(this.length_bits, this.length_base, 4, 3);
|
||||
this.build_bits_base(this.dist_bits, this.dist_base, 2, 1);
|
||||
|
||||
/* fix a special case */
|
||||
this.length_bits[28] = 0;
|
||||
this.length_base[28] = 258;
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
this.reset = function()
|
||||
{
|
||||
this.d = new this.DATA(this);
|
||||
delete this.header;
|
||||
}
|
||||
|
||||
/* inflate stream from source to dest */
|
||||
this.uncompress = function(source, offset)
|
||||
{
|
||||
|
||||
var d = this.d;
|
||||
var bfinal;
|
||||
|
||||
/* initialise data */
|
||||
d.source = source;
|
||||
d.sourceIndex = offset;
|
||||
d.bitcount = 0;
|
||||
|
||||
d.dest = [];
|
||||
|
||||
// Skip zlib header at start of stream
|
||||
if (typeof this.header == 'undefined') {
|
||||
this.header = this.read_bits(d, 16, 0);
|
||||
/* byte 0: 0x78, 7 = 32k window size, 8 = deflate */
|
||||
/* byte 1: check bits for header and other flags */
|
||||
}
|
||||
|
||||
var blocks = 0;
|
||||
|
||||
do {
|
||||
|
||||
var btype;
|
||||
var res;
|
||||
|
||||
/* read final block flag */
|
||||
bfinal = this.getbit(d);
|
||||
|
||||
/* read block type (2 bits) */
|
||||
btype = this.read_bits(d, 2, 0);
|
||||
|
||||
/* decompress block */
|
||||
switch (btype)
|
||||
{
|
||||
case 0:
|
||||
/* decompress uncompressed block */
|
||||
res = this.inflate_uncompressed_block(d);
|
||||
break;
|
||||
case 1:
|
||||
/* decompress block with fixed huffman trees */
|
||||
res = this.inflate_fixed_block(d);
|
||||
break;
|
||||
case 2:
|
||||
/* decompress block with dynamic huffman trees */
|
||||
res = this.inflate_dynamic_block(d);
|
||||
break;
|
||||
default:
|
||||
return { 'status' : this.DATA_ERROR };
|
||||
}
|
||||
|
||||
if (res != this.OK) return { 'status' : this.DATA_ERROR };
|
||||
blocks++;
|
||||
|
||||
} while (!bfinal && d.sourceIndex < d.source.length);
|
||||
|
||||
d.history = d.history.slice(-this.WINDOW_SIZE);
|
||||
|
||||
return { 'status' : this.OK, 'data' : d.dest };
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,543 @@
|
||||
var kbdUtil = (function() {
|
||||
"use strict";
|
||||
|
||||
function substituteCodepoint(cp) {
|
||||
// Any Unicode code points which do not have corresponding keysym entries
|
||||
// can be swapped out for another code point by adding them to this table
|
||||
var substitutions = {
|
||||
// {S,s} with comma below -> {S,s} with cedilla
|
||||
0x218 : 0x15e,
|
||||
0x219 : 0x15f,
|
||||
// {T,t} with comma below -> {T,t} with cedilla
|
||||
0x21a : 0x162,
|
||||
0x21b : 0x163
|
||||
};
|
||||
|
||||
var sub = substitutions[cp];
|
||||
return sub ? sub : cp;
|
||||
}
|
||||
|
||||
function isMac() {
|
||||
return navigator && !!(/mac/i).exec(navigator.platform);
|
||||
}
|
||||
function isWindows() {
|
||||
return navigator && !!(/win/i).exec(navigator.platform);
|
||||
}
|
||||
function isLinux() {
|
||||
return navigator && !!(/linux/i).exec(navigator.platform);
|
||||
}
|
||||
|
||||
// Return true if a modifier which is not the specified char modifier (and is not shift) is down
|
||||
function hasShortcutModifier(charModifier, currentModifiers) {
|
||||
var mods = {};
|
||||
for (var key in currentModifiers) {
|
||||
if (parseInt(key) !== XK_Shift_L) {
|
||||
mods[key] = currentModifiers[key];
|
||||
}
|
||||
}
|
||||
|
||||
var sum = 0;
|
||||
for (var k in currentModifiers) {
|
||||
if (mods[k]) {
|
||||
++sum;
|
||||
}
|
||||
}
|
||||
if (hasCharModifier(charModifier, mods)) {
|
||||
return sum > charModifier.length;
|
||||
}
|
||||
else {
|
||||
return sum > 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if the specified char modifier is currently down
|
||||
function hasCharModifier(charModifier, currentModifiers) {
|
||||
if (charModifier.length === 0) { return false; }
|
||||
|
||||
for (var i = 0; i < charModifier.length; ++i) {
|
||||
if (!currentModifiers[charModifier[i]]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper object tracking modifier key state
|
||||
// and generates fake key events to compensate if it gets out of sync
|
||||
function ModifierSync(charModifier) {
|
||||
if (!charModifier) {
|
||||
if (isMac()) {
|
||||
// on Mac, Option (AKA Alt) is used as a char modifier
|
||||
charModifier = [XK_Alt_L];
|
||||
}
|
||||
else if (isWindows()) {
|
||||
// on Windows, Ctrl+Alt is used as a char modifier
|
||||
charModifier = [XK_Alt_L, XK_Control_L];
|
||||
}
|
||||
else if (isLinux()) {
|
||||
// on Linux, ISO Level 3 Shift (AltGr) is used as a char modifier
|
||||
charModifier = [XK_ISO_Level3_Shift];
|
||||
}
|
||||
else {
|
||||
charModifier = [];
|
||||
}
|
||||
}
|
||||
|
||||
var state = {};
|
||||
state[XK_Control_L] = false;
|
||||
state[XK_Alt_L] = false;
|
||||
state[XK_ISO_Level3_Shift] = false;
|
||||
state[XK_Shift_L] = false;
|
||||
state[XK_Meta_L] = false;
|
||||
|
||||
function sync(evt, keysym) {
|
||||
var result = [];
|
||||
function syncKey(keysym) {
|
||||
return {keysym: keysyms.lookup(keysym), type: state[keysym] ? 'keydown' : 'keyup'};
|
||||
}
|
||||
|
||||
if (evt.ctrlKey !== undefined &&
|
||||
evt.ctrlKey !== state[XK_Control_L] && keysym !== XK_Control_L) {
|
||||
state[XK_Control_L] = evt.ctrlKey;
|
||||
result.push(syncKey(XK_Control_L));
|
||||
}
|
||||
if (evt.altKey !== undefined &&
|
||||
evt.altKey !== state[XK_Alt_L] && keysym !== XK_Alt_L) {
|
||||
state[XK_Alt_L] = evt.altKey;
|
||||
result.push(syncKey(XK_Alt_L));
|
||||
}
|
||||
if (evt.altGraphKey !== undefined &&
|
||||
evt.altGraphKey !== state[XK_ISO_Level3_Shift] && keysym !== XK_ISO_Level3_Shift) {
|
||||
state[XK_ISO_Level3_Shift] = evt.altGraphKey;
|
||||
result.push(syncKey(XK_ISO_Level3_Shift));
|
||||
}
|
||||
if (evt.shiftKey !== undefined &&
|
||||
evt.shiftKey !== state[XK_Shift_L] && keysym !== XK_Shift_L) {
|
||||
state[XK_Shift_L] = evt.shiftKey;
|
||||
result.push(syncKey(XK_Shift_L));
|
||||
}
|
||||
if (evt.metaKey !== undefined &&
|
||||
evt.metaKey !== state[XK_Meta_L] && keysym !== XK_Meta_L) {
|
||||
state[XK_Meta_L] = evt.metaKey;
|
||||
result.push(syncKey(XK_Meta_L));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function syncKeyEvent(evt, down) {
|
||||
var obj = getKeysym(evt);
|
||||
var keysym = obj ? obj.keysym : null;
|
||||
|
||||
// first, apply the event itself, if relevant
|
||||
if (keysym !== null && state[keysym] !== undefined) {
|
||||
state[keysym] = down;
|
||||
}
|
||||
return sync(evt, keysym);
|
||||
}
|
||||
|
||||
return {
|
||||
// sync on the appropriate keyboard event
|
||||
keydown: function(evt) { return syncKeyEvent(evt, true);},
|
||||
keyup: function(evt) { return syncKeyEvent(evt, false);},
|
||||
// Call this with a non-keyboard event (such as mouse events) to use its modifier state to synchronize anyway
|
||||
syncAny: function(evt) { return sync(evt);},
|
||||
|
||||
// is a shortcut modifier down?
|
||||
hasShortcutModifier: function() { return hasShortcutModifier(charModifier, state); },
|
||||
// if a char modifier is down, return the keys it consists of, otherwise return null
|
||||
activeCharModifier: function() { return hasCharModifier(charModifier, state) ? charModifier : null; }
|
||||
};
|
||||
}
|
||||
|
||||
// Get a key ID from a keyboard event
|
||||
// May be a string or an integer depending on the available properties
|
||||
function getKey(evt){
|
||||
if ('keyCode' in evt && 'key' in evt) {
|
||||
return evt.key + ':' + evt.keyCode;
|
||||
}
|
||||
else if ('keyCode' in evt) {
|
||||
return evt.keyCode;
|
||||
}
|
||||
else {
|
||||
return evt.key;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the most reliable keysym value we can get from a key event
|
||||
// if char/charCode is available, prefer those, otherwise fall back to key/keyCode/which
|
||||
function getKeysym(evt){
|
||||
var codepoint;
|
||||
if (evt.char && evt.char.length === 1) {
|
||||
codepoint = evt.char.charCodeAt();
|
||||
}
|
||||
else if (evt.charCode) {
|
||||
codepoint = evt.charCode;
|
||||
}
|
||||
else if (evt.keyCode && evt.type === 'keypress') {
|
||||
// IE10 stores the char code as keyCode, and has no other useful properties
|
||||
codepoint = evt.keyCode;
|
||||
}
|
||||
if (codepoint) {
|
||||
var res = keysyms.fromUnicode(substituteCodepoint(codepoint));
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
// we could check evt.key here.
|
||||
// Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list,
|
||||
// so we "just" need to map them to keysym, but AFAIK this is only available in IE10, which also provides evt.key
|
||||
// so we don't *need* it yet
|
||||
if (evt.keyCode) {
|
||||
return keysyms.lookup(keysymFromKeyCode(evt.keyCode, evt.shiftKey));
|
||||
}
|
||||
if (evt.which) {
|
||||
return keysyms.lookup(keysymFromKeyCode(evt.which, evt.shiftKey));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Given a keycode, try to predict which keysym it might be.
|
||||
// If the keycode is unknown, null is returned.
|
||||
function keysymFromKeyCode(keycode, shiftPressed) {
|
||||
if (typeof(keycode) !== 'number') {
|
||||
return null;
|
||||
}
|
||||
// won't be accurate for azerty
|
||||
if (keycode >= 0x30 && keycode <= 0x39) {
|
||||
return keycode; // digit
|
||||
}
|
||||
if (keycode >= 0x41 && keycode <= 0x5a) {
|
||||
// remap to lowercase unless shift is down
|
||||
return shiftPressed ? keycode : keycode + 32; // A-Z
|
||||
}
|
||||
if (keycode >= 0x60 && keycode <= 0x69) {
|
||||
return XK_KP_0 + (keycode - 0x60); // numpad 0-9
|
||||
}
|
||||
|
||||
switch(keycode) {
|
||||
case 0x20: return XK_space;
|
||||
case 0x6a: return XK_KP_Multiply;
|
||||
case 0x6b: return XK_KP_Add;
|
||||
case 0x6c: return XK_KP_Separator;
|
||||
case 0x6d: return XK_KP_Subtract;
|
||||
case 0x6e: return XK_KP_Decimal;
|
||||
case 0x6f: return XK_KP_Divide;
|
||||
case 0xbb: return XK_plus;
|
||||
case 0xbc: return XK_comma;
|
||||
case 0xbd: return XK_minus;
|
||||
case 0xbe: return XK_period;
|
||||
}
|
||||
|
||||
return nonCharacterKey({keyCode: keycode});
|
||||
}
|
||||
|
||||
// if the key is a known non-character key (any key which doesn't generate character data)
|
||||
// return its keysym value. Otherwise return null
|
||||
function nonCharacterKey(evt) {
|
||||
// evt.key not implemented yet
|
||||
if (!evt.keyCode) { return null; }
|
||||
var keycode = evt.keyCode;
|
||||
|
||||
if (keycode >= 0x70 && keycode <= 0x87) {
|
||||
return XK_F1 + keycode - 0x70; // F1-F24
|
||||
}
|
||||
switch (keycode) {
|
||||
|
||||
case 8 : return XK_BackSpace;
|
||||
case 13 : return XK_Return;
|
||||
|
||||
case 9 : return XK_Tab;
|
||||
|
||||
case 27 : return XK_Escape;
|
||||
case 46 : return XK_Delete;
|
||||
|
||||
case 36 : return XK_Home;
|
||||
case 35 : return XK_End;
|
||||
case 33 : return XK_Page_Up;
|
||||
case 34 : return XK_Page_Down;
|
||||
case 45 : return XK_Insert;
|
||||
|
||||
case 37 : return XK_Left;
|
||||
case 38 : return XK_Up;
|
||||
case 39 : return XK_Right;
|
||||
case 40 : return XK_Down;
|
||||
|
||||
case 16 : return XK_Shift_L;
|
||||
case 17 : return XK_Control_L;
|
||||
case 18 : return XK_Alt_L; // also: Option-key on Mac
|
||||
|
||||
case 224 : return XK_Meta_L;
|
||||
case 225 : return XK_ISO_Level3_Shift; // AltGr
|
||||
case 91 : return XK_Super_L; // also: Windows-key
|
||||
case 92 : return XK_Super_R; // also: Windows-key
|
||||
case 93 : return XK_Menu; // also: Windows-Menu, Command on Mac
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
return {
|
||||
hasShortcutModifier : hasShortcutModifier,
|
||||
hasCharModifier : hasCharModifier,
|
||||
ModifierSync : ModifierSync,
|
||||
getKey : getKey,
|
||||
getKeysym : getKeysym,
|
||||
keysymFromKeyCode : keysymFromKeyCode,
|
||||
nonCharacterKey : nonCharacterKey,
|
||||
substituteCodepoint : substituteCodepoint
|
||||
};
|
||||
})();
|
||||
|
||||
// Takes a DOM keyboard event and:
|
||||
// - determines which keysym it represents
|
||||
// - determines a keyId identifying the key that was pressed (corresponding to the key/keyCode properties on the DOM event)
|
||||
// - synthesizes events to synchronize modifier key state between which modifiers are actually down, and which we thought were down
|
||||
// - marks each event with an 'escape' property if a modifier was down which should be "escaped"
|
||||
// - generates a "stall" event in cases where it might be necessary to wait and see if a keypress event follows a keydown
|
||||
// This information is collected into an object which is passed to the next() function. (one call per event)
|
||||
function KeyEventDecoder(modifierState, next) {
|
||||
"use strict";
|
||||
function sendAll(evts) {
|
||||
for (var i = 0; i < evts.length; ++i) {
|
||||
next(evts[i]);
|
||||
}
|
||||
}
|
||||
function process(evt, type) {
|
||||
var result = {type: type};
|
||||
var keyId = kbdUtil.getKey(evt);
|
||||
if (keyId) {
|
||||
result.keyId = keyId;
|
||||
}
|
||||
|
||||
var keysym = kbdUtil.getKeysym(evt);
|
||||
|
||||
var hasModifier = modifierState.hasShortcutModifier() || !!modifierState.activeCharModifier();
|
||||
// Is this a case where we have to decide on the keysym right away, rather than waiting for the keypress?
|
||||
// "special" keys like enter, tab or backspace don't send keypress events,
|
||||
// and some browsers don't send keypresses at all if a modifier is down
|
||||
if (keysym && (type !== 'keydown' || kbdUtil.nonCharacterKey(evt) || hasModifier)) {
|
||||
result.keysym = keysym;
|
||||
}
|
||||
|
||||
var isShift = evt.keyCode === 0x10 || evt.key === 'Shift';
|
||||
|
||||
// Should we prevent the browser from handling the event?
|
||||
// Doing so on a keydown (in most browsers) prevents keypress from being generated
|
||||
// so only do that if we have to.
|
||||
var suppress = !isShift && (type !== 'keydown' || modifierState.hasShortcutModifier() || !!kbdUtil.nonCharacterKey(evt));
|
||||
|
||||
// If a char modifier is down on a keydown, we need to insert a stall,
|
||||
// so VerifyCharModifier knows to wait and see if a keypress is comnig
|
||||
var stall = type === 'keydown' && modifierState.activeCharModifier() && !kbdUtil.nonCharacterKey(evt);
|
||||
|
||||
// if a char modifier is pressed, get the keys it consists of (on Windows, AltGr is equivalent to Ctrl+Alt)
|
||||
var active = modifierState.activeCharModifier();
|
||||
|
||||
// If we have a char modifier down, and we're able to determine a keysym reliably
|
||||
// then (a) we know to treat the modifier as a char modifier,
|
||||
// and (b) we'll have to "escape" the modifier to undo the modifier when sending the char.
|
||||
if (active && keysym) {
|
||||
var isCharModifier = false;
|
||||
for (var i = 0; i < active.length; ++i) {
|
||||
if (active[i] === keysym.keysym) {
|
||||
isCharModifier = true;
|
||||
}
|
||||
}
|
||||
if (type === 'keypress' && !isCharModifier) {
|
||||
result.escape = modifierState.activeCharModifier();
|
||||
}
|
||||
}
|
||||
|
||||
if (stall) {
|
||||
// insert a fake "stall" event
|
||||
next({type: 'stall'});
|
||||
}
|
||||
next(result);
|
||||
|
||||
return suppress;
|
||||
}
|
||||
|
||||
return {
|
||||
keydown: function(evt) {
|
||||
sendAll(modifierState.keydown(evt));
|
||||
return process(evt, 'keydown');
|
||||
},
|
||||
keypress: function(evt) {
|
||||
return process(evt, 'keypress');
|
||||
},
|
||||
keyup: function(evt) {
|
||||
sendAll(modifierState.keyup(evt));
|
||||
return process(evt, 'keyup');
|
||||
},
|
||||
syncModifiers: function(evt) {
|
||||
sendAll(modifierState.syncAny(evt));
|
||||
},
|
||||
releaseAll: function() { next({type: 'releaseall'}); }
|
||||
};
|
||||
}
|
||||
|
||||
// Combines keydown and keypress events where necessary to handle char modifiers.
|
||||
// On some OS'es, a char modifier is sometimes used as a shortcut modifier.
|
||||
// For example, on Windows, AltGr is synonymous with Ctrl-Alt. On a Danish keyboard layout, AltGr-2 yields a @, but Ctrl-Alt-D does nothing
|
||||
// so when used with the '2' key, Ctrl-Alt counts as a char modifier (and should be escaped), but when used with 'D', it does not.
|
||||
// The only way we can distinguish these cases is to wait and see if a keypress event arrives
|
||||
// When we receive a "stall" event, wait a few ms before processing the next keydown. If a keypress has also arrived, merge the two
|
||||
function VerifyCharModifier(next) {
|
||||
"use strict";
|
||||
var queue = [];
|
||||
var timer = null;
|
||||
function process() {
|
||||
if (timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
var delayProcess = function () {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
process();
|
||||
};
|
||||
|
||||
while (queue.length !== 0) {
|
||||
var cur = queue[0];
|
||||
queue = queue.splice(1);
|
||||
switch (cur.type) {
|
||||
case 'stall':
|
||||
// insert a delay before processing available events.
|
||||
/* jshint loopfunc: true */
|
||||
timer = setTimeout(delayProcess, 5);
|
||||
/* jshint loopfunc: false */
|
||||
return;
|
||||
case 'keydown':
|
||||
// is the next element a keypress? Then we should merge the two
|
||||
if (queue.length !== 0 && queue[0].type === 'keypress') {
|
||||
// Firefox sends keypress even when no char is generated.
|
||||
// so, if keypress keysym is the same as we'd have guessed from keydown,
|
||||
// the modifier didn't have any effect, and should not be escaped
|
||||
if (queue[0].escape && (!cur.keysym || cur.keysym.keysym !== queue[0].keysym.keysym)) {
|
||||
cur.escape = queue[0].escape;
|
||||
}
|
||||
cur.keysym = queue[0].keysym;
|
||||
queue = queue.splice(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// swallow stall events, and pass all others to the next stage
|
||||
if (cur.type !== 'stall') {
|
||||
next(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
return function(evt) {
|
||||
queue.push(evt);
|
||||
process();
|
||||
};
|
||||
}
|
||||
|
||||
// Keeps track of which keys we (and the server) believe are down
|
||||
// When a keyup is received, match it against this list, to determine the corresponding keysym(s)
|
||||
// in some cases, a single key may produce multiple keysyms, so the corresponding keyup event must release all of these chars
|
||||
// key repeat events should be merged into a single entry.
|
||||
// Because we can't always identify which entry a keydown or keyup event corresponds to, we sometimes have to guess
|
||||
function TrackKeyState(next) {
|
||||
"use strict";
|
||||
var state = [];
|
||||
|
||||
return function (evt) {
|
||||
var last = state.length !== 0 ? state[state.length-1] : null;
|
||||
|
||||
switch (evt.type) {
|
||||
case 'keydown':
|
||||
// insert a new entry if last seen key was different.
|
||||
if (!last || !evt.keyId || last.keyId !== evt.keyId) {
|
||||
last = {keyId: evt.keyId, keysyms: {}};
|
||||
state.push(last);
|
||||
}
|
||||
if (evt.keysym) {
|
||||
// make sure last event contains this keysym (a single "logical" keyevent
|
||||
// can cause multiple key events to be sent to the VNC server)
|
||||
last.keysyms[evt.keysym.keysym] = evt.keysym;
|
||||
last.ignoreKeyPress = true;
|
||||
next(evt);
|
||||
}
|
||||
break;
|
||||
case 'keypress':
|
||||
if (!last) {
|
||||
last = {keyId: evt.keyId, keysyms: {}};
|
||||
state.push(last);
|
||||
}
|
||||
if (!evt.keysym) {
|
||||
console.log('keypress with no keysym:', evt);
|
||||
}
|
||||
|
||||
// If we didn't expect a keypress, and already sent a keydown to the VNC server
|
||||
// based on the keydown, make sure to skip this event.
|
||||
if (evt.keysym && !last.ignoreKeyPress) {
|
||||
last.keysyms[evt.keysym.keysym] = evt.keysym;
|
||||
evt.type = 'keydown';
|
||||
next(evt);
|
||||
}
|
||||
break;
|
||||
case 'keyup':
|
||||
if (state.length === 0) {
|
||||
return;
|
||||
}
|
||||
var idx = null;
|
||||
// do we have a matching key tracked as being down?
|
||||
for (var i = 0; i !== state.length; ++i) {
|
||||
if (state[i].keyId === evt.keyId) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we couldn't find a match (it happens), assume it was the last key pressed
|
||||
if (idx === null) {
|
||||
idx = state.length - 1;
|
||||
}
|
||||
|
||||
var item = state.splice(idx, 1)[0];
|
||||
// for each keysym tracked by this key entry, clone the current event and override the keysym
|
||||
var clone = (function(){
|
||||
function Clone(){}
|
||||
return function (obj) { Clone.prototype=obj; return new Clone(); };
|
||||
}());
|
||||
for (var key in item.keysyms) {
|
||||
var out = clone(evt);
|
||||
out.keysym = item.keysyms[key];
|
||||
next(out);
|
||||
}
|
||||
break;
|
||||
case 'releaseall':
|
||||
/* jshint shadow: true */
|
||||
for (var i = 0; i < state.length; ++i) {
|
||||
for (var key in state[i].keysyms) {
|
||||
var keysym = state[i].keysyms[key];
|
||||
next({keyId: 0, keysym: keysym, type: 'keyup'});
|
||||
}
|
||||
}
|
||||
/* jshint shadow: false */
|
||||
state = [];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Handles "escaping" of modifiers: if a char modifier is used to produce a keysym (such as AltGr-2 to generate an @),
|
||||
// then the modifier must be "undone" before sending the @, and "redone" afterwards.
|
||||
function EscapeModifiers(next) {
|
||||
"use strict";
|
||||
return function(evt) {
|
||||
if (evt.type !== 'keydown' || evt.escape === undefined) {
|
||||
next(evt);
|
||||
return;
|
||||
}
|
||||
// undo modifiers
|
||||
for (var i = 0; i < evt.escape.length; ++i) {
|
||||
next({type: 'keyup', keyId: 0, keysym: keysyms.lookup(evt.escape[i])});
|
||||
}
|
||||
// send the character event
|
||||
next(evt);
|
||||
// redo modifiers
|
||||
/* jshint shadow: true */
|
||||
for (var i = 0; i < evt.escape.length; ++i) {
|
||||
next({type: 'keydown', keyId: 0, keysym: keysyms.lookup(evt.escape[i])});
|
||||
}
|
||||
/* jshint shadow: false */
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
var XK_VoidSymbol = 0xffffff, /* Void symbol */
|
||||
|
||||
XK_BackSpace = 0xff08, /* Back space, back char */
|
||||
XK_Tab = 0xff09,
|
||||
XK_Linefeed = 0xff0a, /* Linefeed, LF */
|
||||
XK_Clear = 0xff0b,
|
||||
XK_Return = 0xff0d, /* Return, enter */
|
||||
XK_Pause = 0xff13, /* Pause, hold */
|
||||
XK_Scroll_Lock = 0xff14,
|
||||
XK_Sys_Req = 0xff15,
|
||||
XK_Escape = 0xff1b,
|
||||
XK_Delete = 0xffff, /* Delete, rubout */
|
||||
|
||||
/* Cursor control & motion */
|
||||
|
||||
XK_Home = 0xff50,
|
||||
XK_Left = 0xff51, /* Move left, left arrow */
|
||||
XK_Up = 0xff52, /* Move up, up arrow */
|
||||
XK_Right = 0xff53, /* Move right, right arrow */
|
||||
XK_Down = 0xff54, /* Move down, down arrow */
|
||||
XK_Prior = 0xff55, /* Prior, previous */
|
||||
XK_Page_Up = 0xff55,
|
||||
XK_Next = 0xff56, /* Next */
|
||||
XK_Page_Down = 0xff56,
|
||||
XK_End = 0xff57, /* EOL */
|
||||
XK_Begin = 0xff58, /* BOL */
|
||||
|
||||
|
||||
/* Misc functions */
|
||||
|
||||
XK_Select = 0xff60, /* Select, mark */
|
||||
XK_Print = 0xff61,
|
||||
XK_Execute = 0xff62, /* Execute, run, do */
|
||||
XK_Insert = 0xff63, /* Insert, insert here */
|
||||
XK_Undo = 0xff65,
|
||||
XK_Redo = 0xff66, /* Redo, again */
|
||||
XK_Menu = 0xff67,
|
||||
XK_Find = 0xff68, /* Find, search */
|
||||
XK_Cancel = 0xff69, /* Cancel, stop, abort, exit */
|
||||
XK_Help = 0xff6a, /* Help */
|
||||
XK_Break = 0xff6b,
|
||||
XK_Mode_switch = 0xff7e, /* Character set switch */
|
||||
XK_script_switch = 0xff7e, /* Alias for mode_switch */
|
||||
XK_Num_Lock = 0xff7f,
|
||||
|
||||
/* Keypad functions, keypad numbers cleverly chosen to map to ASCII */
|
||||
|
||||
XK_KP_Space = 0xff80, /* Space */
|
||||
XK_KP_Tab = 0xff89,
|
||||
XK_KP_Enter = 0xff8d, /* Enter */
|
||||
XK_KP_F1 = 0xff91, /* PF1, KP_A, ... */
|
||||
XK_KP_F2 = 0xff92,
|
||||
XK_KP_F3 = 0xff93,
|
||||
XK_KP_F4 = 0xff94,
|
||||
XK_KP_Home = 0xff95,
|
||||
XK_KP_Left = 0xff96,
|
||||
XK_KP_Up = 0xff97,
|
||||
XK_KP_Right = 0xff98,
|
||||
XK_KP_Down = 0xff99,
|
||||
XK_KP_Prior = 0xff9a,
|
||||
XK_KP_Page_Up = 0xff9a,
|
||||
XK_KP_Next = 0xff9b,
|
||||
XK_KP_Page_Down = 0xff9b,
|
||||
XK_KP_End = 0xff9c,
|
||||
XK_KP_Begin = 0xff9d,
|
||||
XK_KP_Insert = 0xff9e,
|
||||
XK_KP_Delete = 0xff9f,
|
||||
XK_KP_Equal = 0xffbd, /* Equals */
|
||||
XK_KP_Multiply = 0xffaa,
|
||||
XK_KP_Add = 0xffab,
|
||||
XK_KP_Separator = 0xffac, /* Separator, often comma */
|
||||
XK_KP_Subtract = 0xffad,
|
||||
XK_KP_Decimal = 0xffae,
|
||||
XK_KP_Divide = 0xffaf,
|
||||
|
||||
XK_KP_0 = 0xffb0,
|
||||
XK_KP_1 = 0xffb1,
|
||||
XK_KP_2 = 0xffb2,
|
||||
XK_KP_3 = 0xffb3,
|
||||
XK_KP_4 = 0xffb4,
|
||||
XK_KP_5 = 0xffb5,
|
||||
XK_KP_6 = 0xffb6,
|
||||
XK_KP_7 = 0xffb7,
|
||||
XK_KP_8 = 0xffb8,
|
||||
XK_KP_9 = 0xffb9,
|
||||
|
||||
/*
|
||||
* Auxiliary functions; note the duplicate definitions for left and right
|
||||
* function keys; Sun keyboards and a few other manufacturers have such
|
||||
* function key groups on the left and/or right sides of the keyboard.
|
||||
* We've not found a keyboard with more than 35 function keys total.
|
||||
*/
|
||||
|
||||
XK_F1 = 0xffbe,
|
||||
XK_F2 = 0xffbf,
|
||||
XK_F3 = 0xffc0,
|
||||
XK_F4 = 0xffc1,
|
||||
XK_F5 = 0xffc2,
|
||||
XK_F6 = 0xffc3,
|
||||
XK_F7 = 0xffc4,
|
||||
XK_F8 = 0xffc5,
|
||||
XK_F9 = 0xffc6,
|
||||
XK_F10 = 0xffc7,
|
||||
XK_F11 = 0xffc8,
|
||||
XK_L1 = 0xffc8,
|
||||
XK_F12 = 0xffc9,
|
||||
XK_L2 = 0xffc9,
|
||||
XK_F13 = 0xffca,
|
||||
XK_L3 = 0xffca,
|
||||
XK_F14 = 0xffcb,
|
||||
XK_L4 = 0xffcb,
|
||||
XK_F15 = 0xffcc,
|
||||
XK_L5 = 0xffcc,
|
||||
XK_F16 = 0xffcd,
|
||||
XK_L6 = 0xffcd,
|
||||
XK_F17 = 0xffce,
|
||||
XK_L7 = 0xffce,
|
||||
XK_F18 = 0xffcf,
|
||||
XK_L8 = 0xffcf,
|
||||
XK_F19 = 0xffd0,
|
||||
XK_L9 = 0xffd0,
|
||||
XK_F20 = 0xffd1,
|
||||
XK_L10 = 0xffd1,
|
||||
XK_F21 = 0xffd2,
|
||||
XK_R1 = 0xffd2,
|
||||
XK_F22 = 0xffd3,
|
||||
XK_R2 = 0xffd3,
|
||||
XK_F23 = 0xffd4,
|
||||
XK_R3 = 0xffd4,
|
||||
XK_F24 = 0xffd5,
|
||||
XK_R4 = 0xffd5,
|
||||
XK_F25 = 0xffd6,
|
||||
XK_R5 = 0xffd6,
|
||||
XK_F26 = 0xffd7,
|
||||
XK_R6 = 0xffd7,
|
||||
XK_F27 = 0xffd8,
|
||||
XK_R7 = 0xffd8,
|
||||
XK_F28 = 0xffd9,
|
||||
XK_R8 = 0xffd9,
|
||||
XK_F29 = 0xffda,
|
||||
XK_R9 = 0xffda,
|
||||
XK_F30 = 0xffdb,
|
||||
XK_R10 = 0xffdb,
|
||||
XK_F31 = 0xffdc,
|
||||
XK_R11 = 0xffdc,
|
||||
XK_F32 = 0xffdd,
|
||||
XK_R12 = 0xffdd,
|
||||
XK_F33 = 0xffde,
|
||||
XK_R13 = 0xffde,
|
||||
XK_F34 = 0xffdf,
|
||||
XK_R14 = 0xffdf,
|
||||
XK_F35 = 0xffe0,
|
||||
XK_R15 = 0xffe0,
|
||||
|
||||
/* Modifiers */
|
||||
|
||||
XK_Shift_L = 0xffe1, /* Left shift */
|
||||
XK_Shift_R = 0xffe2, /* Right shift */
|
||||
XK_Control_L = 0xffe3, /* Left control */
|
||||
XK_Control_R = 0xffe4, /* Right control */
|
||||
XK_Caps_Lock = 0xffe5, /* Caps lock */
|
||||
XK_Shift_Lock = 0xffe6, /* Shift lock */
|
||||
|
||||
XK_Meta_L = 0xffe7, /* Left meta */
|
||||
XK_Meta_R = 0xffe8, /* Right meta */
|
||||
XK_Alt_L = 0xffe9, /* Left alt */
|
||||
XK_Alt_R = 0xffea, /* Right alt */
|
||||
XK_Super_L = 0xffeb, /* Left super */
|
||||
XK_Super_R = 0xffec, /* Right super */
|
||||
XK_Hyper_L = 0xffed, /* Left hyper */
|
||||
XK_Hyper_R = 0xffee, /* Right hyper */
|
||||
|
||||
XK_ISO_Level3_Shift = 0xfe03, /* AltGr */
|
||||
|
||||
/*
|
||||
* Latin 1
|
||||
* (ISO/IEC 8859-1 = Unicode U+0020..U+00FF)
|
||||
* Byte 3 = 0
|
||||
*/
|
||||
|
||||
XK_space = 0x0020, /* U+0020 SPACE */
|
||||
XK_exclam = 0x0021, /* U+0021 EXCLAMATION MARK */
|
||||
XK_quotedbl = 0x0022, /* U+0022 QUOTATION MARK */
|
||||
XK_numbersign = 0x0023, /* U+0023 NUMBER SIGN */
|
||||
XK_dollar = 0x0024, /* U+0024 DOLLAR SIGN */
|
||||
XK_percent = 0x0025, /* U+0025 PERCENT SIGN */
|
||||
XK_ampersand = 0x0026, /* U+0026 AMPERSAND */
|
||||
XK_apostrophe = 0x0027, /* U+0027 APOSTROPHE */
|
||||
XK_quoteright = 0x0027, /* deprecated */
|
||||
XK_parenleft = 0x0028, /* U+0028 LEFT PARENTHESIS */
|
||||
XK_parenright = 0x0029, /* U+0029 RIGHT PARENTHESIS */
|
||||
XK_asterisk = 0x002a, /* U+002A ASTERISK */
|
||||
XK_plus = 0x002b, /* U+002B PLUS SIGN */
|
||||
XK_comma = 0x002c, /* U+002C COMMA */
|
||||
XK_minus = 0x002d, /* U+002D HYPHEN-MINUS */
|
||||
XK_period = 0x002e, /* U+002E FULL STOP */
|
||||
XK_slash = 0x002f, /* U+002F SOLIDUS */
|
||||
XK_0 = 0x0030, /* U+0030 DIGIT ZERO */
|
||||
XK_1 = 0x0031, /* U+0031 DIGIT ONE */
|
||||
XK_2 = 0x0032, /* U+0032 DIGIT TWO */
|
||||
XK_3 = 0x0033, /* U+0033 DIGIT THREE */
|
||||
XK_4 = 0x0034, /* U+0034 DIGIT FOUR */
|
||||
XK_5 = 0x0035, /* U+0035 DIGIT FIVE */
|
||||
XK_6 = 0x0036, /* U+0036 DIGIT SIX */
|
||||
XK_7 = 0x0037, /* U+0037 DIGIT SEVEN */
|
||||
XK_8 = 0x0038, /* U+0038 DIGIT EIGHT */
|
||||
XK_9 = 0x0039, /* U+0039 DIGIT NINE */
|
||||
XK_colon = 0x003a, /* U+003A COLON */
|
||||
XK_semicolon = 0x003b, /* U+003B SEMICOLON */
|
||||
XK_less = 0x003c, /* U+003C LESS-THAN SIGN */
|
||||
XK_equal = 0x003d, /* U+003D EQUALS SIGN */
|
||||
XK_greater = 0x003e, /* U+003E GREATER-THAN SIGN */
|
||||
XK_question = 0x003f, /* U+003F QUESTION MARK */
|
||||
XK_at = 0x0040, /* U+0040 COMMERCIAL AT */
|
||||
XK_A = 0x0041, /* U+0041 LATIN CAPITAL LETTER A */
|
||||
XK_B = 0x0042, /* U+0042 LATIN CAPITAL LETTER B */
|
||||
XK_C = 0x0043, /* U+0043 LATIN CAPITAL LETTER C */
|
||||
XK_D = 0x0044, /* U+0044 LATIN CAPITAL LETTER D */
|
||||
XK_E = 0x0045, /* U+0045 LATIN CAPITAL LETTER E */
|
||||
XK_F = 0x0046, /* U+0046 LATIN CAPITAL LETTER F */
|
||||
XK_G = 0x0047, /* U+0047 LATIN CAPITAL LETTER G */
|
||||
XK_H = 0x0048, /* U+0048 LATIN CAPITAL LETTER H */
|
||||
XK_I = 0x0049, /* U+0049 LATIN CAPITAL LETTER I */
|
||||
XK_J = 0x004a, /* U+004A LATIN CAPITAL LETTER J */
|
||||
XK_K = 0x004b, /* U+004B LATIN CAPITAL LETTER K */
|
||||
XK_L = 0x004c, /* U+004C LATIN CAPITAL LETTER L */
|
||||
XK_M = 0x004d, /* U+004D LATIN CAPITAL LETTER M */
|
||||
XK_N = 0x004e, /* U+004E LATIN CAPITAL LETTER N */
|
||||
XK_O = 0x004f, /* U+004F LATIN CAPITAL LETTER O */
|
||||
XK_P = 0x0050, /* U+0050 LATIN CAPITAL LETTER P */
|
||||
XK_Q = 0x0051, /* U+0051 LATIN CAPITAL LETTER Q */
|
||||
XK_R = 0x0052, /* U+0052 LATIN CAPITAL LETTER R */
|
||||
XK_S = 0x0053, /* U+0053 LATIN CAPITAL LETTER S */
|
||||
XK_T = 0x0054, /* U+0054 LATIN CAPITAL LETTER T */
|
||||
XK_U = 0x0055, /* U+0055 LATIN CAPITAL LETTER U */
|
||||
XK_V = 0x0056, /* U+0056 LATIN CAPITAL LETTER V */
|
||||
XK_W = 0x0057, /* U+0057 LATIN CAPITAL LETTER W */
|
||||
XK_X = 0x0058, /* U+0058 LATIN CAPITAL LETTER X */
|
||||
XK_Y = 0x0059, /* U+0059 LATIN CAPITAL LETTER Y */
|
||||
XK_Z = 0x005a, /* U+005A LATIN CAPITAL LETTER Z */
|
||||
XK_bracketleft = 0x005b, /* U+005B LEFT SQUARE BRACKET */
|
||||
XK_backslash = 0x005c, /* U+005C REVERSE SOLIDUS */
|
||||
XK_bracketright = 0x005d, /* U+005D RIGHT SQUARE BRACKET */
|
||||
XK_asciicircum = 0x005e, /* U+005E CIRCUMFLEX ACCENT */
|
||||
XK_underscore = 0x005f, /* U+005F LOW LINE */
|
||||
XK_grave = 0x0060, /* U+0060 GRAVE ACCENT */
|
||||
XK_quoteleft = 0x0060, /* deprecated */
|
||||
XK_a = 0x0061, /* U+0061 LATIN SMALL LETTER A */
|
||||
XK_b = 0x0062, /* U+0062 LATIN SMALL LETTER B */
|
||||
XK_c = 0x0063, /* U+0063 LATIN SMALL LETTER C */
|
||||
XK_d = 0x0064, /* U+0064 LATIN SMALL LETTER D */
|
||||
XK_e = 0x0065, /* U+0065 LATIN SMALL LETTER E */
|
||||
XK_f = 0x0066, /* U+0066 LATIN SMALL LETTER F */
|
||||
XK_g = 0x0067, /* U+0067 LATIN SMALL LETTER G */
|
||||
XK_h = 0x0068, /* U+0068 LATIN SMALL LETTER H */
|
||||
XK_i = 0x0069, /* U+0069 LATIN SMALL LETTER I */
|
||||
XK_j = 0x006a, /* U+006A LATIN SMALL LETTER J */
|
||||
XK_k = 0x006b, /* U+006B LATIN SMALL LETTER K */
|
||||
XK_l = 0x006c, /* U+006C LATIN SMALL LETTER L */
|
||||
XK_m = 0x006d, /* U+006D LATIN SMALL LETTER M */
|
||||
XK_n = 0x006e, /* U+006E LATIN SMALL LETTER N */
|
||||
XK_o = 0x006f, /* U+006F LATIN SMALL LETTER O */
|
||||
XK_p = 0x0070, /* U+0070 LATIN SMALL LETTER P */
|
||||
XK_q = 0x0071, /* U+0071 LATIN SMALL LETTER Q */
|
||||
XK_r = 0x0072, /* U+0072 LATIN SMALL LETTER R */
|
||||
XK_s = 0x0073, /* U+0073 LATIN SMALL LETTER S */
|
||||
XK_t = 0x0074, /* U+0074 LATIN SMALL LETTER T */
|
||||
XK_u = 0x0075, /* U+0075 LATIN SMALL LETTER U */
|
||||
XK_v = 0x0076, /* U+0076 LATIN SMALL LETTER V */
|
||||
XK_w = 0x0077, /* U+0077 LATIN SMALL LETTER W */
|
||||
XK_x = 0x0078, /* U+0078 LATIN SMALL LETTER X */
|
||||
XK_y = 0x0079, /* U+0079 LATIN SMALL LETTER Y */
|
||||
XK_z = 0x007a, /* U+007A LATIN SMALL LETTER Z */
|
||||
XK_braceleft = 0x007b, /* U+007B LEFT CURLY BRACKET */
|
||||
XK_bar = 0x007c, /* U+007C VERTICAL LINE */
|
||||
XK_braceright = 0x007d, /* U+007D RIGHT CURLY BRACKET */
|
||||
XK_asciitilde = 0x007e, /* U+007E TILDE */
|
||||
|
||||
XK_nobreakspace = 0x00a0, /* U+00A0 NO-BREAK SPACE */
|
||||
XK_exclamdown = 0x00a1, /* U+00A1 INVERTED EXCLAMATION MARK */
|
||||
XK_cent = 0x00a2, /* U+00A2 CENT SIGN */
|
||||
XK_sterling = 0x00a3, /* U+00A3 POUND SIGN */
|
||||
XK_currency = 0x00a4, /* U+00A4 CURRENCY SIGN */
|
||||
XK_yen = 0x00a5, /* U+00A5 YEN SIGN */
|
||||
XK_brokenbar = 0x00a6, /* U+00A6 BROKEN BAR */
|
||||
XK_section = 0x00a7, /* U+00A7 SECTION SIGN */
|
||||
XK_diaeresis = 0x00a8, /* U+00A8 DIAERESIS */
|
||||
XK_copyright = 0x00a9, /* U+00A9 COPYRIGHT SIGN */
|
||||
XK_ordfeminine = 0x00aa, /* U+00AA FEMININE ORDINAL INDICATOR */
|
||||
XK_guillemotleft = 0x00ab, /* U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK */
|
||||
XK_notsign = 0x00ac, /* U+00AC NOT SIGN */
|
||||
XK_hyphen = 0x00ad, /* U+00AD SOFT HYPHEN */
|
||||
XK_registered = 0x00ae, /* U+00AE REGISTERED SIGN */
|
||||
XK_macron = 0x00af, /* U+00AF MACRON */
|
||||
XK_degree = 0x00b0, /* U+00B0 DEGREE SIGN */
|
||||
XK_plusminus = 0x00b1, /* U+00B1 PLUS-MINUS SIGN */
|
||||
XK_twosuperior = 0x00b2, /* U+00B2 SUPERSCRIPT TWO */
|
||||
XK_threesuperior = 0x00b3, /* U+00B3 SUPERSCRIPT THREE */
|
||||
XK_acute = 0x00b4, /* U+00B4 ACUTE ACCENT */
|
||||
XK_mu = 0x00b5, /* U+00B5 MICRO SIGN */
|
||||
XK_paragraph = 0x00b6, /* U+00B6 PILCROW SIGN */
|
||||
XK_periodcentered = 0x00b7, /* U+00B7 MIDDLE DOT */
|
||||
XK_cedilla = 0x00b8, /* U+00B8 CEDILLA */
|
||||
XK_onesuperior = 0x00b9, /* U+00B9 SUPERSCRIPT ONE */
|
||||
XK_masculine = 0x00ba, /* U+00BA MASCULINE ORDINAL INDICATOR */
|
||||
XK_guillemotright = 0x00bb, /* U+00BB RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK */
|
||||
XK_onequarter = 0x00bc, /* U+00BC VULGAR FRACTION ONE QUARTER */
|
||||
XK_onehalf = 0x00bd, /* U+00BD VULGAR FRACTION ONE HALF */
|
||||
XK_threequarters = 0x00be, /* U+00BE VULGAR FRACTION THREE QUARTERS */
|
||||
XK_questiondown = 0x00bf, /* U+00BF INVERTED QUESTION MARK */
|
||||
XK_Agrave = 0x00c0, /* U+00C0 LATIN CAPITAL LETTER A WITH GRAVE */
|
||||
XK_Aacute = 0x00c1, /* U+00C1 LATIN CAPITAL LETTER A WITH ACUTE */
|
||||
XK_Acircumflex = 0x00c2, /* U+00C2 LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
|
||||
XK_Atilde = 0x00c3, /* U+00C3 LATIN CAPITAL LETTER A WITH TILDE */
|
||||
XK_Adiaeresis = 0x00c4, /* U+00C4 LATIN CAPITAL LETTER A WITH DIAERESIS */
|
||||
XK_Aring = 0x00c5, /* U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE */
|
||||
XK_AE = 0x00c6, /* U+00C6 LATIN CAPITAL LETTER AE */
|
||||
XK_Ccedilla = 0x00c7, /* U+00C7 LATIN CAPITAL LETTER C WITH CEDILLA */
|
||||
XK_Egrave = 0x00c8, /* U+00C8 LATIN CAPITAL LETTER E WITH GRAVE */
|
||||
XK_Eacute = 0x00c9, /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
|
||||
XK_Ecircumflex = 0x00ca, /* U+00CA LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
|
||||
XK_Ediaeresis = 0x00cb, /* U+00CB LATIN CAPITAL LETTER E WITH DIAERESIS */
|
||||
XK_Igrave = 0x00cc, /* U+00CC LATIN CAPITAL LETTER I WITH GRAVE */
|
||||
XK_Iacute = 0x00cd, /* U+00CD LATIN CAPITAL LETTER I WITH ACUTE */
|
||||
XK_Icircumflex = 0x00ce, /* U+00CE LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
|
||||
XK_Idiaeresis = 0x00cf, /* U+00CF LATIN CAPITAL LETTER I WITH DIAERESIS */
|
||||
XK_ETH = 0x00d0, /* U+00D0 LATIN CAPITAL LETTER ETH */
|
||||
XK_Eth = 0x00d0, /* deprecated */
|
||||
XK_Ntilde = 0x00d1, /* U+00D1 LATIN CAPITAL LETTER N WITH TILDE */
|
||||
XK_Ograve = 0x00d2, /* U+00D2 LATIN CAPITAL LETTER O WITH GRAVE */
|
||||
XK_Oacute = 0x00d3, /* U+00D3 LATIN CAPITAL LETTER O WITH ACUTE */
|
||||
XK_Ocircumflex = 0x00d4, /* U+00D4 LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
|
||||
XK_Otilde = 0x00d5, /* U+00D5 LATIN CAPITAL LETTER O WITH TILDE */
|
||||
XK_Odiaeresis = 0x00d6, /* U+00D6 LATIN CAPITAL LETTER O WITH DIAERESIS */
|
||||
XK_multiply = 0x00d7, /* U+00D7 MULTIPLICATION SIGN */
|
||||
XK_Oslash = 0x00d8, /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
|
||||
XK_Ooblique = 0x00d8, /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
|
||||
XK_Ugrave = 0x00d9, /* U+00D9 LATIN CAPITAL LETTER U WITH GRAVE */
|
||||
XK_Uacute = 0x00da, /* U+00DA LATIN CAPITAL LETTER U WITH ACUTE */
|
||||
XK_Ucircumflex = 0x00db, /* U+00DB LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
|
||||
XK_Udiaeresis = 0x00dc, /* U+00DC LATIN CAPITAL LETTER U WITH DIAERESIS */
|
||||
XK_Yacute = 0x00dd, /* U+00DD LATIN CAPITAL LETTER Y WITH ACUTE */
|
||||
XK_THORN = 0x00de, /* U+00DE LATIN CAPITAL LETTER THORN */
|
||||
XK_Thorn = 0x00de, /* deprecated */
|
||||
XK_ssharp = 0x00df, /* U+00DF LATIN SMALL LETTER SHARP S */
|
||||
XK_agrave = 0x00e0, /* U+00E0 LATIN SMALL LETTER A WITH GRAVE */
|
||||
XK_aacute = 0x00e1, /* U+00E1 LATIN SMALL LETTER A WITH ACUTE */
|
||||
XK_acircumflex = 0x00e2, /* U+00E2 LATIN SMALL LETTER A WITH CIRCUMFLEX */
|
||||
XK_atilde = 0x00e3, /* U+00E3 LATIN SMALL LETTER A WITH TILDE */
|
||||
XK_adiaeresis = 0x00e4, /* U+00E4 LATIN SMALL LETTER A WITH DIAERESIS */
|
||||
XK_aring = 0x00e5, /* U+00E5 LATIN SMALL LETTER A WITH RING ABOVE */
|
||||
XK_ae = 0x00e6, /* U+00E6 LATIN SMALL LETTER AE */
|
||||
XK_ccedilla = 0x00e7, /* U+00E7 LATIN SMALL LETTER C WITH CEDILLA */
|
||||
XK_egrave = 0x00e8, /* U+00E8 LATIN SMALL LETTER E WITH GRAVE */
|
||||
XK_eacute = 0x00e9, /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
|
||||
XK_ecircumflex = 0x00ea, /* U+00EA LATIN SMALL LETTER E WITH CIRCUMFLEX */
|
||||
XK_ediaeresis = 0x00eb, /* U+00EB LATIN SMALL LETTER E WITH DIAERESIS */
|
||||
XK_igrave = 0x00ec, /* U+00EC LATIN SMALL LETTER I WITH GRAVE */
|
||||
XK_iacute = 0x00ed, /* U+00ED LATIN SMALL LETTER I WITH ACUTE */
|
||||
XK_icircumflex = 0x00ee, /* U+00EE LATIN SMALL LETTER I WITH CIRCUMFLEX */
|
||||
XK_idiaeresis = 0x00ef, /* U+00EF LATIN SMALL LETTER I WITH DIAERESIS */
|
||||
XK_eth = 0x00f0, /* U+00F0 LATIN SMALL LETTER ETH */
|
||||
XK_ntilde = 0x00f1, /* U+00F1 LATIN SMALL LETTER N WITH TILDE */
|
||||
XK_ograve = 0x00f2, /* U+00F2 LATIN SMALL LETTER O WITH GRAVE */
|
||||
XK_oacute = 0x00f3, /* U+00F3 LATIN SMALL LETTER O WITH ACUTE */
|
||||
XK_ocircumflex = 0x00f4, /* U+00F4 LATIN SMALL LETTER O WITH CIRCUMFLEX */
|
||||
XK_otilde = 0x00f5, /* U+00F5 LATIN SMALL LETTER O WITH TILDE */
|
||||
XK_odiaeresis = 0x00f6, /* U+00F6 LATIN SMALL LETTER O WITH DIAERESIS */
|
||||
XK_division = 0x00f7, /* U+00F7 DIVISION SIGN */
|
||||
XK_oslash = 0x00f8, /* U+00F8 LATIN SMALL LETTER O WITH STROKE */
|
||||
XK_ooblique = 0x00f8, /* U+00F8 LATIN SMALL LETTER O WITH STROKE */
|
||||
XK_ugrave = 0x00f9, /* U+00F9 LATIN SMALL LETTER U WITH GRAVE */
|
||||
XK_uacute = 0x00fa, /* U+00FA LATIN SMALL LETTER U WITH ACUTE */
|
||||
XK_ucircumflex = 0x00fb, /* U+00FB LATIN SMALL LETTER U WITH CIRCUMFLEX */
|
||||
XK_udiaeresis = 0x00fc, /* U+00FC LATIN SMALL LETTER U WITH DIAERESIS */
|
||||
XK_yacute = 0x00fd, /* U+00FD LATIN SMALL LETTER Y WITH ACUTE */
|
||||
XK_thorn = 0x00fe, /* U+00FE LATIN SMALL LETTER THORN */
|
||||
XK_ydiaeresis = 0x00ff; /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/*jslint browser: true, white: false */
|
||||
/*global Util, VNC_frame_data, finish */
|
||||
|
||||
var rfb, mode, test_state, frame_idx, frame_length,
|
||||
iteration, iterations, istart_time,
|
||||
|
||||
// Pre-declarations for jslint
|
||||
send_array, next_iteration, queue_next_packet, do_packet, enable_test_mode;
|
||||
|
||||
// Override send_array
|
||||
send_array = function (arr) {
|
||||
// Stub out send_array
|
||||
};
|
||||
|
||||
enable_test_mode = function () {
|
||||
rfb._sock._mode = VNC_frame_encoding;
|
||||
rfb._sock.send = send_array;
|
||||
rfb._sock.close = function () {};
|
||||
rfb._sock.flush = function () {};
|
||||
rfb._checkEvents = function () {};
|
||||
rfb.connect = function (host, port, password, path) {
|
||||
this._rfb_host = host;
|
||||
this._rfb_port = port;
|
||||
this._rfb_password = (password !== undefined) ? password : "";
|
||||
this._rfb_path = (path !== undefined) ? path : "";
|
||||
this._sock.init('binary', 'ws');
|
||||
this._updateState('ProtocolVersion', "Starting VNC handshake");
|
||||
};
|
||||
};
|
||||
|
||||
next_iteration = function () {
|
||||
rfb = new RFB({'target': $D('VNC_canvas'),
|
||||
'onUpdateState': updateState});
|
||||
enable_test_mode();
|
||||
|
||||
if (iteration === 0) {
|
||||
frame_length = VNC_frame_data.length;
|
||||
test_state = 'running';
|
||||
}
|
||||
|
||||
if (test_state !== 'running') { return; }
|
||||
|
||||
iteration += 1;
|
||||
if (iteration > iterations) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
frame_idx = 0;
|
||||
istart_time = (new Date()).getTime();
|
||||
rfb.connect('test', 0, "bogus");
|
||||
|
||||
queue_next_packet();
|
||||
|
||||
};
|
||||
|
||||
queue_next_packet = function () {
|
||||
var frame, foffset, toffset, delay;
|
||||
if (test_state !== 'running') { return; }
|
||||
|
||||
frame = VNC_frame_data[frame_idx];
|
||||
while ((frame_idx < frame_length) && (frame.charAt(0) === "}")) {
|
||||
//Util.Debug("Send frame " + frame_idx);
|
||||
frame_idx += 1;
|
||||
frame = VNC_frame_data[frame_idx];
|
||||
}
|
||||
|
||||
if (frame === 'EOF') {
|
||||
Util.Debug("Finished, found EOF");
|
||||
next_iteration();
|
||||
return;
|
||||
}
|
||||
if (frame_idx >= frame_length) {
|
||||
Util.Debug("Finished, no more frames");
|
||||
next_iteration();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode === 'realtime') {
|
||||
foffset = frame.slice(1, frame.indexOf('{', 1));
|
||||
toffset = (new Date()).getTime() - istart_time;
|
||||
delay = foffset - toffset;
|
||||
if (delay < 1) {
|
||||
delay = 1;
|
||||
}
|
||||
|
||||
setTimeout(do_packet, delay);
|
||||
} else {
|
||||
setTimeout(do_packet, 1);
|
||||
}
|
||||
};
|
||||
|
||||
var bytes_processed = 0;
|
||||
|
||||
do_packet = function () {
|
||||
//Util.Debug("Processing frame: " + frame_idx);
|
||||
var frame = VNC_frame_data[frame_idx],
|
||||
start = frame.indexOf('{', 1) + 1;
|
||||
bytes_processed += frame.length - start;
|
||||
if (VNC_frame_encoding === 'binary') {
|
||||
var u8 = new Uint8Array(frame.length - start);
|
||||
for (var i = 0; i < frame.length - start; i++) {
|
||||
u8[i] = frame.charCodeAt(start + i);
|
||||
}
|
||||
rfb._sock._recv_message({'data' : u8});
|
||||
} else {
|
||||
rfb._sock._recv_message({'data' : frame.slice(start)});
|
||||
}
|
||||
frame_idx += 1;
|
||||
|
||||
queue_next_packet();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,622 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
/* jshint white: false, nonstandard: true */
|
||||
/*global window, console, document, navigator, ActiveXObject, INCLUDE_URI */
|
||||
|
||||
// Globals defined here
|
||||
var Util = {};
|
||||
|
||||
|
||||
/*
|
||||
* Make arrays quack
|
||||
*/
|
||||
|
||||
var addFunc = function (cl, name, func) {
|
||||
if (!cl.prototype[name]) {
|
||||
Object.defineProperty(cl.prototype, name, { enumerable: false, value: func });
|
||||
}
|
||||
};
|
||||
|
||||
addFunc(Array, 'push8', function (num) {
|
||||
"use strict";
|
||||
this.push(num & 0xFF);
|
||||
});
|
||||
|
||||
addFunc(Array, 'push16', function (num) {
|
||||
"use strict";
|
||||
this.push((num >> 8) & 0xFF,
|
||||
num & 0xFF);
|
||||
});
|
||||
|
||||
addFunc(Array, 'push32', function (num) {
|
||||
"use strict";
|
||||
this.push((num >> 24) & 0xFF,
|
||||
(num >> 16) & 0xFF,
|
||||
(num >> 8) & 0xFF,
|
||||
num & 0xFF);
|
||||
});
|
||||
|
||||
// IE does not support map (even in IE9)
|
||||
//This prototype is provided by the Mozilla foundation and
|
||||
//is distributed under the MIT license.
|
||||
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
||||
addFunc(Array, 'map', function (fun /*, thisp*/) {
|
||||
"use strict";
|
||||
var len = this.length;
|
||||
if (typeof fun != "function") {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
var res = new Array(len);
|
||||
var thisp = arguments[1];
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (i in this) {
|
||||
res[i] = fun.call(thisp, this[i], i, this);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
});
|
||||
|
||||
// IE <9 does not support indexOf
|
||||
//This prototype is provided by the Mozilla foundation and
|
||||
//is distributed under the MIT license.
|
||||
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
||||
addFunc(Array, 'indexOf', function (elt /*, from*/) {
|
||||
"use strict";
|
||||
var len = this.length >>> 0;
|
||||
|
||||
var from = Number(arguments[1]) || 0;
|
||||
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
|
||||
if (from < 0) {
|
||||
from += len;
|
||||
}
|
||||
|
||||
for (; from < len; from++) {
|
||||
if (from in this &&
|
||||
this[from] === elt) {
|
||||
return from;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
|
||||
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
|
||||
if (!Object.keys) {
|
||||
Object.keys = (function () {
|
||||
'use strict';
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
|
||||
dontEnums = [
|
||||
'toString',
|
||||
'toLocaleString',
|
||||
'valueOf',
|
||||
'hasOwnProperty',
|
||||
'isPrototypeOf',
|
||||
'propertyIsEnumerable',
|
||||
'constructor'
|
||||
],
|
||||
dontEnumsLength = dontEnums.length;
|
||||
|
||||
return function (obj) {
|
||||
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
|
||||
throw new TypeError('Object.keys called on non-object');
|
||||
}
|
||||
|
||||
var result = [], prop, i;
|
||||
|
||||
for (prop in obj) {
|
||||
if (hasOwnProperty.call(obj, prop)) {
|
||||
result.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDontEnumBug) {
|
||||
for (i = 0; i < dontEnumsLength; i++) {
|
||||
if (hasOwnProperty.call(obj, dontEnums[i])) {
|
||||
result.push(dontEnums[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
// PhantomJS 1.x doesn't support bind,
|
||||
// so leave this in until PhantomJS 2.0 is released
|
||||
//This prototype is provided by the Mozilla foundation and
|
||||
//is distributed under the MIT license.
|
||||
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
||||
addFunc(Function, 'bind', function (oThis) {
|
||||
if (typeof this !== "function") {
|
||||
// closest thing possible to the ECMAScript 5
|
||||
// internal IsCallable function
|
||||
throw new TypeError("Function.prototype.bind - " +
|
||||
"what is trying to be bound is not callable");
|
||||
}
|
||||
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1),
|
||||
fToBind = this,
|
||||
fNOP = function () {},
|
||||
fBound = function () {
|
||||
return fToBind.apply(this instanceof fNOP && oThis ? this
|
||||
: oThis,
|
||||
aArgs.concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
|
||||
fNOP.prototype = this.prototype;
|
||||
fBound.prototype = new fNOP();
|
||||
|
||||
return fBound;
|
||||
});
|
||||
|
||||
//
|
||||
// requestAnimationFrame shim with setTimeout fallback
|
||||
//
|
||||
|
||||
window.requestAnimFrame = (function () {
|
||||
"use strict";
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function (callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
})();
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Namespaced in Util
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Logging/debug routines
|
||||
*/
|
||||
|
||||
Util._log_level = 'warn';
|
||||
Util.init_logging = function (level) {
|
||||
"use strict";
|
||||
if (typeof level === 'undefined') {
|
||||
level = Util._log_level;
|
||||
} else {
|
||||
Util._log_level = level;
|
||||
}
|
||||
if (typeof window.console === "undefined") {
|
||||
if (typeof window.opera !== "undefined") {
|
||||
window.console = {
|
||||
'log' : window.opera.postError,
|
||||
'warn' : window.opera.postError,
|
||||
'error': window.opera.postError
|
||||
};
|
||||
} else {
|
||||
window.console = {
|
||||
'log' : function (m) {},
|
||||
'warn' : function (m) {},
|
||||
'error': function (m) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
|
||||
/* jshint -W086 */
|
||||
switch (level) {
|
||||
case 'debug':
|
||||
Util.Debug = function (msg) { console.log(msg); };
|
||||
case 'info':
|
||||
Util.Info = function (msg) { console.log(msg); };
|
||||
case 'warn':
|
||||
Util.Warn = function (msg) { console.warn(msg); };
|
||||
case 'error':
|
||||
Util.Error = function (msg) { console.error(msg); };
|
||||
case 'none':
|
||||
break;
|
||||
default:
|
||||
throw new Error("invalid logging type '" + level + "'");
|
||||
}
|
||||
/* jshint +W086 */
|
||||
};
|
||||
Util.get_logging = function () {
|
||||
return Util._log_level;
|
||||
};
|
||||
// Initialize logging level
|
||||
Util.init_logging();
|
||||
|
||||
Util.make_property = function (proto, name, mode, type) {
|
||||
"use strict";
|
||||
|
||||
var getter;
|
||||
if (type === 'arr') {
|
||||
getter = function (idx) {
|
||||
if (typeof idx !== 'undefined') {
|
||||
return this['_' + name][idx];
|
||||
} else {
|
||||
return this['_' + name];
|
||||
}
|
||||
};
|
||||
} else {
|
||||
getter = function () {
|
||||
return this['_' + name];
|
||||
};
|
||||
}
|
||||
|
||||
var make_setter = function (process_val) {
|
||||
if (process_val) {
|
||||
return function (val, idx) {
|
||||
if (typeof idx !== 'undefined') {
|
||||
this['_' + name][idx] = process_val(val);
|
||||
} else {
|
||||
this['_' + name] = process_val(val);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return function (val, idx) {
|
||||
if (typeof idx !== 'undefined') {
|
||||
this['_' + name][idx] = val;
|
||||
} else {
|
||||
this['_' + name] = val;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var setter;
|
||||
if (type === 'bool') {
|
||||
setter = make_setter(function (val) {
|
||||
if (!val || (val in {'0': 1, 'no': 1, 'false': 1})) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else if (type === 'int') {
|
||||
setter = make_setter(function (val) { return parseInt(val, 10); });
|
||||
} else if (type === 'float') {
|
||||
setter = make_setter(parseFloat);
|
||||
} else if (type === 'str') {
|
||||
setter = make_setter(String);
|
||||
} else if (type === 'func') {
|
||||
setter = make_setter(function (val) {
|
||||
if (!val) {
|
||||
return function () {};
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
});
|
||||
} else if (type === 'arr' || type === 'dom' || type == 'raw') {
|
||||
setter = make_setter();
|
||||
} else {
|
||||
throw new Error('Unknown property type ' + type); // some sanity checking
|
||||
}
|
||||
|
||||
// set the getter
|
||||
if (typeof proto['get_' + name] === 'undefined') {
|
||||
proto['get_' + name] = getter;
|
||||
}
|
||||
|
||||
// set the setter if needed
|
||||
if (typeof proto['set_' + name] === 'undefined') {
|
||||
if (mode === 'rw') {
|
||||
proto['set_' + name] = setter;
|
||||
} else if (mode === 'wo') {
|
||||
proto['set_' + name] = function (val, idx) {
|
||||
if (typeof this['_' + name] !== 'undefined') {
|
||||
throw new Error(name + " can only be set once");
|
||||
}
|
||||
setter.call(this, val, idx);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// make a special setter that we can use in set defaults
|
||||
proto['_raw_set_' + name] = function (val, idx) {
|
||||
setter.call(this, val, idx);
|
||||
//delete this['_init_set_' + name]; // remove it after use
|
||||
};
|
||||
};
|
||||
|
||||
Util.make_properties = function (constructor, arr) {
|
||||
"use strict";
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
Util.make_property(constructor.prototype, arr[i][0], arr[i][1], arr[i][2]);
|
||||
}
|
||||
};
|
||||
|
||||
Util.set_defaults = function (obj, conf, defaults) {
|
||||
var defaults_keys = Object.keys(defaults);
|
||||
var conf_keys = Object.keys(conf);
|
||||
var keys_obj = {};
|
||||
var i;
|
||||
for (i = 0; i < defaults_keys.length; i++) { keys_obj[defaults_keys[i]] = 1; }
|
||||
for (i = 0; i < conf_keys.length; i++) { keys_obj[conf_keys[i]] = 1; }
|
||||
var keys = Object.keys(keys_obj);
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
var setter = obj['_raw_set_' + keys[i]];
|
||||
if (!setter) {
|
||||
Util.Warn('Invalid property ' + keys[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (keys[i] in conf) {
|
||||
setter.call(obj, conf[keys[i]]);
|
||||
} else {
|
||||
setter.call(obj, defaults[keys[i]]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Decode from UTF-8
|
||||
*/
|
||||
Util.decodeUTF8 = function (utf8string) {
|
||||
"use strict";
|
||||
return decodeURIComponent(escape(utf8string));
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Cross-browser routines
|
||||
*/
|
||||
|
||||
|
||||
// Dynamically load scripts without using document.write()
|
||||
// Reference: http://unixpapa.com/js/dyna.html
|
||||
//
|
||||
// Handles the case where load_scripts is invoked from a script that
|
||||
// itself is loaded via load_scripts. Once all scripts are loaded the
|
||||
// window.onscriptsloaded handler is called (if set).
|
||||
Util.get_include_uri = function () {
|
||||
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/";
|
||||
};
|
||||
Util._loading_scripts = [];
|
||||
Util._pending_scripts = [];
|
||||
Util.load_scripts = function (files) {
|
||||
"use strict";
|
||||
var head = document.getElementsByTagName('head')[0], script,
|
||||
ls = Util._loading_scripts, ps = Util._pending_scripts;
|
||||
|
||||
var loadFunc = function (e) {
|
||||
while (ls.length > 0 && (ls[0].readyState === 'loaded' ||
|
||||
ls[0].readyState === 'complete')) {
|
||||
// For IE, append the script to trigger execution
|
||||
var s = ls.shift();
|
||||
//console.log("loaded script: " + s.src);
|
||||
head.appendChild(s);
|
||||
}
|
||||
if (!this.readyState ||
|
||||
(Util.Engine.presto && this.readyState === 'loaded') ||
|
||||
this.readyState === 'complete') {
|
||||
if (ps.indexOf(this) >= 0) {
|
||||
this.onload = this.onreadystatechange = null;
|
||||
//console.log("completed script: " + this.src);
|
||||
ps.splice(ps.indexOf(this), 1);
|
||||
|
||||
// Call window.onscriptsload after last script loads
|
||||
if (ps.length === 0 && window.onscriptsload) {
|
||||
window.onscriptsload();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (var f = 0; f < files.length; f++) {
|
||||
script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = Util.get_include_uri() + files[f];
|
||||
//console.log("loading script: " + script.src);
|
||||
script.onload = script.onreadystatechange = loadFunc;
|
||||
// In-order script execution tricks
|
||||
if (Util.Engine.trident) {
|
||||
// For IE wait until readyState is 'loaded' before
|
||||
// appending it which will trigger execution
|
||||
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
|
||||
ls.push(script);
|
||||
} else {
|
||||
// For webkit and firefox set async=false and append now
|
||||
// https://developer.mozilla.org/en-US/docs/HTML/Element/script
|
||||
script.async = false;
|
||||
head.appendChild(script);
|
||||
}
|
||||
ps.push(script);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Util.getPosition = function(obj) {
|
||||
"use strict";
|
||||
// NB(sross): the Mozilla developer reference seems to indicate that
|
||||
// getBoundingClientRect includes border and padding, so the canvas
|
||||
// style should NOT include either.
|
||||
var objPosition = obj.getBoundingClientRect();
|
||||
return {'x': objPosition.left + window.pageXOffset, 'y': objPosition.top + window.pageYOffset,
|
||||
'width': objPosition.width, 'height': objPosition.height};
|
||||
};
|
||||
|
||||
|
||||
// Get mouse event position in DOM element
|
||||
Util.getEventPosition = function (e, obj, scale) {
|
||||
"use strict";
|
||||
var evt, docX, docY, pos;
|
||||
//if (!e) evt = window.event;
|
||||
evt = (e ? e : window.event);
|
||||
evt = (evt.changedTouches ? evt.changedTouches[0] : evt.touches ? evt.touches[0] : evt);
|
||||
if (evt.pageX || evt.pageY) {
|
||||
docX = evt.pageX;
|
||||
docY = evt.pageY;
|
||||
} else if (evt.clientX || evt.clientY) {
|
||||
docX = evt.clientX + document.body.scrollLeft +
|
||||
document.documentElement.scrollLeft;
|
||||
docY = evt.clientY + document.body.scrollTop +
|
||||
document.documentElement.scrollTop;
|
||||
}
|
||||
pos = Util.getPosition(obj);
|
||||
if (typeof scale === "undefined") {
|
||||
scale = 1;
|
||||
}
|
||||
var realx = docX - pos.x;
|
||||
var realy = docY - pos.y;
|
||||
var x = Math.max(Math.min(realx, pos.width - 1), 0);
|
||||
var y = Math.max(Math.min(realy, pos.height - 1), 0);
|
||||
return {'x': x / scale, 'y': y / scale, 'realx': realx / scale, 'realy': realy / scale};
|
||||
};
|
||||
|
||||
|
||||
// Event registration. Based on: http://www.scottandrew.com/weblog/articles/cbs-events
|
||||
Util.addEvent = function (obj, evType, fn) {
|
||||
"use strict";
|
||||
if (obj.attachEvent) {
|
||||
var r = obj.attachEvent("on" + evType, fn);
|
||||
return r;
|
||||
} else if (obj.addEventListener) {
|
||||
obj.addEventListener(evType, fn, false);
|
||||
return true;
|
||||
} else {
|
||||
throw new Error("Handler could not be attached");
|
||||
}
|
||||
};
|
||||
|
||||
Util.removeEvent = function (obj, evType, fn) {
|
||||
"use strict";
|
||||
if (obj.detachEvent) {
|
||||
var r = obj.detachEvent("on" + evType, fn);
|
||||
return r;
|
||||
} else if (obj.removeEventListener) {
|
||||
obj.removeEventListener(evType, fn, false);
|
||||
return true;
|
||||
} else {
|
||||
throw new Error("Handler could not be removed");
|
||||
}
|
||||
};
|
||||
|
||||
Util.stopEvent = function (e) {
|
||||
"use strict";
|
||||
if (e.stopPropagation) { e.stopPropagation(); }
|
||||
else { e.cancelBubble = true; }
|
||||
|
||||
if (e.preventDefault) { e.preventDefault(); }
|
||||
else { e.returnValue = false; }
|
||||
};
|
||||
|
||||
Util._cursor_uris_supported = null;
|
||||
|
||||
Util.browserSupportsCursorURIs = function () {
|
||||
if (Util._cursor_uris_supported === null) {
|
||||
try {
|
||||
var target = document.createElement('canvas');
|
||||
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
|
||||
|
||||
if (target.style.cursor) {
|
||||
Util.Info("Data URI scheme cursor supported");
|
||||
Util._cursor_uris_supported = true;
|
||||
} else {
|
||||
Util.Warn("Data URI scheme cursor not supported");
|
||||
Util._cursor_uris_supported = false;
|
||||
}
|
||||
} catch (exc) {
|
||||
Util.Error("Data URI scheme cursor test exception: " + exc);
|
||||
Util._cursor_uris_supported = false;
|
||||
}
|
||||
}
|
||||
|
||||
return Util._cursor_uris_supported;
|
||||
};
|
||||
|
||||
// Set browser engine versions. Based on mootools.
|
||||
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
// 'presto': (function () { return (!window.opera) ? false : true; }()),
|
||||
var detectPresto = function () {
|
||||
return !!window.opera;
|
||||
};
|
||||
|
||||
// 'trident': (function () { return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4);
|
||||
var detectTrident = function () {
|
||||
if (!window.ActiveXObject) {
|
||||
return false;
|
||||
} else {
|
||||
if (window.XMLHttpRequest) {
|
||||
return (document.querySelectorAll) ? 6 : 5;
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 'webkit': (function () { try { return (navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); } catch (e) { return false; } }()),
|
||||
var detectInitialWebkit = function () {
|
||||
try {
|
||||
if (navigator.taintEnabled) {
|
||||
return false;
|
||||
} else {
|
||||
if (Util.Features.xpath) {
|
||||
return (Util.Features.query) ? 525 : 420;
|
||||
} else {
|
||||
return 419;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var detectActualWebkit = function (initial_ver) {
|
||||
var re = /WebKit\/([0-9\.]*) /;
|
||||
var str_ver = (navigator.userAgent.match(re) || ['', initial_ver])[1];
|
||||
return parseFloat(str_ver, 10);
|
||||
};
|
||||
|
||||
// 'gecko': (function () { return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19ssName) ? 19 : 18 : 18); }())
|
||||
var detectGecko = function () {
|
||||
/* jshint -W041 */
|
||||
if (!document.getBoxObjectFor && window.mozInnerScreenX == null) {
|
||||
return false;
|
||||
} else {
|
||||
return (document.getElementsByClassName) ? 19 : 18;
|
||||
}
|
||||
/* jshint +W041 */
|
||||
};
|
||||
|
||||
Util.Engine = {
|
||||
// Version detection break in Opera 11.60 (errors on arguments.callee.caller reference)
|
||||
//'presto': (function() {
|
||||
// return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); }()),
|
||||
'presto': detectPresto(),
|
||||
'trident': detectTrident(),
|
||||
'webkit': detectInitialWebkit(),
|
||||
'gecko': detectGecko(),
|
||||
};
|
||||
|
||||
if (Util.Engine.webkit) {
|
||||
// Extract actual webkit version if available
|
||||
Util.Engine.webkit = detectActualWebkit(Util.Engine.webkit);
|
||||
}
|
||||
})();
|
||||
|
||||
Util.Flash = (function () {
|
||||
"use strict";
|
||||
var v, version;
|
||||
try {
|
||||
v = navigator.plugins['Shockwave Flash'].description;
|
||||
} catch (err1) {
|
||||
try {
|
||||
v = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
|
||||
} catch (err2) {
|
||||
v = '0 r0';
|
||||
}
|
||||
}
|
||||
version = v.match(/\d+/g);
|
||||
return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
|
||||
}());
|
||||
@@ -0,0 +1,410 @@
|
||||
/*
|
||||
* Websock: high-performance binary WebSockets
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* Websock is similar to the standard WebSocket object but Websock
|
||||
* enables communication with raw TCP sockets (i.e. the binary stream)
|
||||
* via websockify. This is accomplished by base64 encoding the data
|
||||
* stream between Websock and websockify.
|
||||
*
|
||||
* Websock has built-in receive queue buffering; the message event
|
||||
* does not contain actual data but is simply a notification that
|
||||
* there is new data available. Several rQ* methods are available to
|
||||
* read binary data off of the receive queue.
|
||||
*/
|
||||
|
||||
/*jslint browser: true, bitwise: true */
|
||||
/*global Util*/
|
||||
|
||||
|
||||
// Load Flash WebSocket emulator if needed
|
||||
|
||||
// To force WebSocket emulator even when native WebSocket available
|
||||
//window.WEB_SOCKET_FORCE_FLASH = true;
|
||||
// To enable WebSocket emulator debug:
|
||||
//window.WEB_SOCKET_DEBUG=1;
|
||||
|
||||
if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||
Websock_native = true;
|
||||
} else if (window.MozWebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||
Websock_native = true;
|
||||
window.WebSocket = window.MozWebSocket;
|
||||
} else {
|
||||
/* no builtin WebSocket so load web_socket.js */
|
||||
|
||||
Websock_native = false;
|
||||
}
|
||||
|
||||
function Websock() {
|
||||
"use strict";
|
||||
|
||||
this._websocket = null; // WebSocket object
|
||||
|
||||
this._rQi = 0; // Receive queue index
|
||||
this._rQlen = 0; // Next write position in the receive queue
|
||||
this._rQbufferSize = 1024 * 1024 * 4; // Receive queue buffer size (4 MiB)
|
||||
this._rQmax = this._rQbufferSize / 8;
|
||||
// called in init: this._rQ = new Uint8Array(this._rQbufferSize);
|
||||
this._rQ = null; // Receive queue
|
||||
|
||||
this._sQbufferSize = 1024 * 10; // 10 KiB
|
||||
// called in init: this._sQ = new Uint8Array(this._sQbufferSize);
|
||||
this._sQlen = 0;
|
||||
this._sQ = null; // Send queue
|
||||
|
||||
this._mode = 'binary'; // Current WebSocket mode: 'binary', 'base64'
|
||||
this.maxBufferedAmount = 200;
|
||||
|
||||
this._eventHandlers = {
|
||||
'message': function () {},
|
||||
'open': function () {},
|
||||
'close': function () {},
|
||||
'error': function () {}
|
||||
};
|
||||
}
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var typedArrayToString = (function () {
|
||||
// This is only for PhantomJS, which doesn't like apply-ing
|
||||
// with Typed Arrays
|
||||
try {
|
||||
var arr = new Uint8Array([1, 2, 3]);
|
||||
String.fromCharCode.apply(null, arr);
|
||||
return function (a) { return String.fromCharCode.apply(null, a); };
|
||||
} catch (ex) {
|
||||
return function (a) {
|
||||
return String.fromCharCode.apply(
|
||||
null, Array.prototype.slice.call(a));
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
Websock.prototype = {
|
||||
// Getters and Setters
|
||||
get_sQ: function () {
|
||||
return this._sQ;
|
||||
},
|
||||
|
||||
get_rQ: function () {
|
||||
return this._rQ;
|
||||
},
|
||||
|
||||
get_rQi: function () {
|
||||
return this._rQi;
|
||||
},
|
||||
|
||||
set_rQi: function (val) {
|
||||
this._rQi = val;
|
||||
},
|
||||
|
||||
// Receive Queue
|
||||
rQlen: function () {
|
||||
return this._rQlen - this._rQi;
|
||||
},
|
||||
|
||||
rQpeek8: function () {
|
||||
return this._rQ[this._rQi];
|
||||
},
|
||||
|
||||
rQshift8: function () {
|
||||
return this._rQ[this._rQi++];
|
||||
},
|
||||
|
||||
rQskip8: function () {
|
||||
this._rQi++;
|
||||
},
|
||||
|
||||
rQskipBytes: function (num) {
|
||||
this._rQi += num;
|
||||
},
|
||||
|
||||
// TODO(directxman12): test performance with these vs a DataView
|
||||
rQshift16: function () {
|
||||
return (this._rQ[this._rQi++] << 8) +
|
||||
this._rQ[this._rQi++];
|
||||
},
|
||||
|
||||
rQshift32: function () {
|
||||
return (this._rQ[this._rQi++] << 24) +
|
||||
(this._rQ[this._rQi++] << 16) +
|
||||
(this._rQ[this._rQi++] << 8) +
|
||||
this._rQ[this._rQi++];
|
||||
},
|
||||
|
||||
rQshiftStr: function (len) {
|
||||
if (typeof(len) === 'undefined') { len = this.rQlen(); }
|
||||
var arr = new Uint8Array(this._rQ.buffer, this._rQi, len);
|
||||
this._rQi += len;
|
||||
return typedArrayToString(arr);
|
||||
},
|
||||
|
||||
rQshiftBytes: function (len) {
|
||||
if (typeof(len) === 'undefined') { len = this.rQlen(); }
|
||||
this._rQi += len;
|
||||
return new Uint8Array(this._rQ.buffer, this._rQi - len, len);
|
||||
},
|
||||
|
||||
rQshiftTo: function (target, len) {
|
||||
if (len === undefined) { len = this.rQlen(); }
|
||||
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ
|
||||
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len));
|
||||
this._rQi += len;
|
||||
},
|
||||
|
||||
rQwhole: function () {
|
||||
return new Uint8Array(this._rQ.buffer, 0, this._rQlen);
|
||||
},
|
||||
|
||||
rQslice: function (start, end) {
|
||||
if (end) {
|
||||
return new Uint8Array(this._rQ.buffer, this._rQi + start, end - start);
|
||||
} else {
|
||||
return new Uint8Array(this._rQ.buffer, this._rQi + start, this._rQlen - this._rQi - start);
|
||||
}
|
||||
},
|
||||
|
||||
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
|
||||
// to be available in the receive queue. Return true if we need to
|
||||
// wait (and possibly print a debug message), otherwise false.
|
||||
rQwait: function (msg, num, goback) {
|
||||
var rQlen = this._rQlen - this._rQi; // Skip rQlen() function call
|
||||
if (rQlen < num) {
|
||||
if (goback) {
|
||||
if (this._rQi < goback) {
|
||||
throw new Error("rQwait cannot backup " + goback + " bytes");
|
||||
}
|
||||
this._rQi -= goback;
|
||||
}
|
||||
return true; // true means need more data
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// Send Queue
|
||||
|
||||
flush: function () {
|
||||
if (this._websocket.bufferedAmount !== 0) {
|
||||
Util.Debug("bufferedAmount: " + this._websocket.bufferedAmount);
|
||||
}
|
||||
|
||||
if (this._websocket.bufferedAmount < this.maxBufferedAmount) {
|
||||
if (this._sQlen > 0) {
|
||||
this._websocket.send(this._encode_message());
|
||||
this._sQlen = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
Util.Info("Delaying send, bufferedAmount: " +
|
||||
this._websocket.bufferedAmount);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
send: function (arr) {
|
||||
this._sQ.set(arr, this._sQlen);
|
||||
this._sQlen += arr.length;
|
||||
return this.flush();
|
||||
},
|
||||
|
||||
send_string: function (str) {
|
||||
this.send(str.split('').map(function (chr) {
|
||||
return chr.charCodeAt(0);
|
||||
}));
|
||||
},
|
||||
|
||||
// Event Handlers
|
||||
off: function (evt) {
|
||||
this._eventHandlers[evt] = function () {};
|
||||
},
|
||||
|
||||
on: function (evt, handler) {
|
||||
this._eventHandlers[evt] = handler;
|
||||
},
|
||||
|
||||
_allocate_buffers: function () {
|
||||
this._rQ = new Uint8Array(this._rQbufferSize);
|
||||
this._sQ = new Uint8Array(this._sQbufferSize);
|
||||
},
|
||||
|
||||
init: function (protocols, ws_schema) {
|
||||
this._allocate_buffers();
|
||||
this._rQi = 0;
|
||||
this._websocket = null;
|
||||
|
||||
// Check for full typed array support
|
||||
var bt = false;
|
||||
if (('Uint8Array' in window) &&
|
||||
('set' in Uint8Array.prototype)) {
|
||||
bt = true;
|
||||
}
|
||||
|
||||
// Check for full binary type support in WebSockets
|
||||
// Inspired by:
|
||||
// https://github.com/Modernizr/Modernizr/issues/370
|
||||
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/websockets/binary.js
|
||||
var wsbt = false;
|
||||
try {
|
||||
if (bt && ('binaryType' in WebSocket.prototype ||
|
||||
!!(new WebSocket(ws_schema + '://.').binaryType))) {
|
||||
Util.Info("Detected binaryType support in WebSockets");
|
||||
wsbt = true;
|
||||
}
|
||||
} catch (exc) {
|
||||
// Just ignore failed test localhost connection
|
||||
}
|
||||
|
||||
// Default protocols if not specified
|
||||
if (typeof(protocols) === "undefined") {
|
||||
protocols = 'binary';
|
||||
}
|
||||
|
||||
if (Array.isArray(protocols) && protocols.indexOf('binary') > -1) {
|
||||
protocols = 'binary';
|
||||
}
|
||||
|
||||
if (!wsbt) {
|
||||
throw new Error("noVNC no longer supports base64 WebSockets. " +
|
||||
"Please use a browser which supports binary WebSockets.");
|
||||
}
|
||||
|
||||
if (protocols != 'binary') {
|
||||
throw new Error("noVNC no longer supports base64 WebSockets. Please " +
|
||||
"use the binary subprotocol instead.");
|
||||
}
|
||||
|
||||
return protocols;
|
||||
},
|
||||
|
||||
open: function (uri, protocols) {
|
||||
var ws_schema = uri.match(/^([a-z]+):\/\//)[1];
|
||||
protocols = this.init(protocols, ws_schema);
|
||||
|
||||
this._websocket = new WebSocket(uri, protocols);
|
||||
|
||||
if (protocols.indexOf('binary') >= 0) {
|
||||
this._websocket.binaryType = 'arraybuffer';
|
||||
}
|
||||
|
||||
this._websocket.onmessage = this._recv_message.bind(this);
|
||||
this._websocket.onopen = (function () {
|
||||
Util.Debug('>> WebSock.onopen');
|
||||
if (this._websocket.protocol) {
|
||||
this._mode = this._websocket.protocol;
|
||||
Util.Info("Server choose sub-protocol: " + this._websocket.protocol);
|
||||
} else {
|
||||
this._mode = 'binary';
|
||||
Util.Error('Server select no sub-protocol!: ' + this._websocket.protocol);
|
||||
}
|
||||
|
||||
if (this._mode != 'binary') {
|
||||
throw new Error("noVNC no longer supports base64 WebSockets. Please " +
|
||||
"use the binary subprotocol instead.");
|
||||
|
||||
}
|
||||
|
||||
this._eventHandlers.open();
|
||||
Util.Debug("<< WebSock.onopen");
|
||||
}).bind(this);
|
||||
this._websocket.onclose = (function (e) {
|
||||
Util.Debug(">> WebSock.onclose");
|
||||
this._eventHandlers.close(e);
|
||||
Util.Debug("<< WebSock.onclose");
|
||||
}).bind(this);
|
||||
this._websocket.onerror = (function (e) {
|
||||
Util.Debug(">> WebSock.onerror: " + e);
|
||||
this._eventHandlers.error(e);
|
||||
Util.Debug("<< WebSock.onerror: " + e);
|
||||
}).bind(this);
|
||||
},
|
||||
|
||||
close: function () {
|
||||
if (this._websocket) {
|
||||
if ((this._websocket.readyState === WebSocket.OPEN) ||
|
||||
(this._websocket.readyState === WebSocket.CONNECTING)) {
|
||||
Util.Info("Closing WebSocket connection");
|
||||
this._websocket.close();
|
||||
}
|
||||
|
||||
this._websocket.onmessage = function (e) { return; };
|
||||
}
|
||||
},
|
||||
|
||||
// private methods
|
||||
_encode_message: function () {
|
||||
// Put in a binary arraybuffer
|
||||
// according to the spec, you can send ArrayBufferViews with the send method
|
||||
return new Uint8Array(this._sQ.buffer, 0, this._sQlen);
|
||||
},
|
||||
|
||||
_decode_message: function (data) {
|
||||
// push arraybuffer values onto the end
|
||||
var u8 = new Uint8Array(data);
|
||||
this._rQ.set(u8, this._rQlen);
|
||||
this._rQlen += u8.length;
|
||||
},
|
||||
|
||||
_recv_message: function (e) {
|
||||
try {
|
||||
this._decode_message(e.data);
|
||||
if (this.rQlen() > 0) {
|
||||
this._eventHandlers.message();
|
||||
// Compact the receive queue
|
||||
if (this._rQlen == this._rQi) {
|
||||
this._rQlen = 0;
|
||||
this._rQi = 0;
|
||||
} else if (this._rQlen > this._rQmax) {
|
||||
if (this._rQlen - this._rQi > 0.5 * this._rQbufferSize) {
|
||||
var old_rQbuffer = this._rQ.buffer;
|
||||
this._rQbufferSize *= 2;
|
||||
this._rQmax = this._rQbufferSize / 8;
|
||||
this._rQ = new Uint8Array(this._rQbufferSize);
|
||||
this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi));
|
||||
} else {
|
||||
if (this._rQ.copyWithin) {
|
||||
// Firefox only, ATM
|
||||
this._rQ.copyWithin(0, this._rQi);
|
||||
} else {
|
||||
this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi));
|
||||
}
|
||||
}
|
||||
|
||||
this._rQlen = this._rQlen - this._rQi;
|
||||
this._rQi = 0;
|
||||
}
|
||||
} else {
|
||||
Util.Debug("Ignoring empty message");
|
||||
}
|
||||
} catch (exc) {
|
||||
var exception_str = "";
|
||||
if (exc.name) {
|
||||
exception_str += "\n name: " + exc.name + "\n";
|
||||
exception_str += " message: " + exc.message + "\n";
|
||||
}
|
||||
|
||||
if (typeof exc.description !== 'undefined') {
|
||||
exception_str += " description: " + exc.description + "\n";
|
||||
}
|
||||
|
||||
if (typeof exc.stack !== 'undefined') {
|
||||
exception_str += exc.stack;
|
||||
}
|
||||
|
||||
if (exception_str.length > 0) {
|
||||
Util.Error("recv_message, caught exception: " + exception_str);
|
||||
} else {
|
||||
Util.Error("recv_message, caught exception: " + exc);
|
||||
}
|
||||
|
||||
if (typeof exc.name !== 'undefined') {
|
||||
this._eventHandlers.error(exc.name + ": " + exc.message);
|
||||
} else {
|
||||
this._eventHandlers.error(exc);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Copyright (C) 2013 NTT corp.
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
/*jslint bitwise: false, white: false, browser: true, devel: true */
|
||||
/*global Util, window, document */
|
||||
|
||||
// Globals defined here
|
||||
var WebUtil = {}, $D;
|
||||
|
||||
/*
|
||||
* Simple DOM selector by ID
|
||||
*/
|
||||
if (!window.$D) {
|
||||
window.$D = function (id) {
|
||||
if (document.getElementById) {
|
||||
return document.getElementById(id);
|
||||
} else if (document.all) {
|
||||
return document.all[id];
|
||||
} else if (document.layers) {
|
||||
return document.layers[id];
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Namespaced in WebUtil
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
|
||||
// init log level reading the logging HTTP param
|
||||
WebUtil.init_logging = function (level) {
|
||||
"use strict";
|
||||
if (typeof level !== "undefined") {
|
||||
Util._log_level = level;
|
||||
} else {
|
||||
var param = document.location.href.match(/logging=([A-Za-z0-9\._\-]*)/);
|
||||
Util._log_level = (param || ['', Util._log_level])[1];
|
||||
}
|
||||
Util.init_logging();
|
||||
};
|
||||
|
||||
|
||||
WebUtil.dirObj = function (obj, depth, parent) {
|
||||
"use strict";
|
||||
if (! depth) { depth = 2; }
|
||||
if (! parent) { parent = ""; }
|
||||
|
||||
// Print the properties of the passed-in object
|
||||
var msg = "";
|
||||
for (var i in obj) {
|
||||
if ((depth > 1) && (typeof obj[i] === "object")) {
|
||||
// Recurse attributes that are objects
|
||||
msg += WebUtil.dirObj(obj[i], depth - 1, parent + "." + i);
|
||||
} else {
|
||||
//val = new String(obj[i]).replace("\n", " ");
|
||||
var val = "";
|
||||
if (typeof(obj[i]) === "undefined") {
|
||||
val = "undefined";
|
||||
} else {
|
||||
val = obj[i].toString().replace("\n", " ");
|
||||
}
|
||||
if (val.length > 30) {
|
||||
val = val.substr(0, 30) + "...";
|
||||
}
|
||||
msg += parent + "." + i + ": " + val + "\n";
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
// Read a query string variable
|
||||
WebUtil.getQueryVar = function (name, defVal) {
|
||||
"use strict";
|
||||
var re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
|
||||
match = document.location.href.match(re);
|
||||
if (typeof defVal === 'undefined') { defVal = null; }
|
||||
if (match) {
|
||||
return decodeURIComponent(match[1]);
|
||||
} else {
|
||||
return defVal;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
|
||||
*/
|
||||
|
||||
// No days means only for this browser session
|
||||
WebUtil.createCookie = function (name, value, days) {
|
||||
"use strict";
|
||||
var date, expires;
|
||||
if (days) {
|
||||
date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toGMTString();
|
||||
} else {
|
||||
expires = "";
|
||||
}
|
||||
|
||||
var secure;
|
||||
if (document.location.protocol === "https:") {
|
||||
secure = "; secure";
|
||||
} else {
|
||||
secure = "";
|
||||
}
|
||||
document.cookie = name + "=" + value + expires + "; path=/" + secure;
|
||||
};
|
||||
|
||||
WebUtil.readCookie = function (name, defaultValue) {
|
||||
"use strict";
|
||||
var nameEQ = name + "=",
|
||||
ca = document.cookie.split(';');
|
||||
|
||||
for (var i = 0; i < ca.length; i += 1) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) === ' ') { c = c.substring(1, c.length); }
|
||||
if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); }
|
||||
}
|
||||
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
|
||||
};
|
||||
|
||||
WebUtil.eraseCookie = function (name) {
|
||||
"use strict";
|
||||
WebUtil.createCookie(name, "", -1);
|
||||
};
|
||||
|
||||
/*
|
||||
* Setting handling.
|
||||
*/
|
||||
|
||||
WebUtil.initSettings = function (callback /*, ...callbackArgs */) {
|
||||
"use strict";
|
||||
var callbackArgs = Array.prototype.slice.call(arguments, 1);
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
window.chrome.storage.sync.get(function (cfg) {
|
||||
WebUtil.settings = cfg;
|
||||
console.log(WebUtil.settings);
|
||||
if (callback) {
|
||||
callback.apply(this, callbackArgs);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// No-op
|
||||
if (callback) {
|
||||
callback.apply(this, callbackArgs);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// No days means only for this browser session
|
||||
WebUtil.writeSetting = function (name, value) {
|
||||
"use strict";
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
//console.log("writeSetting:", name, value);
|
||||
if (WebUtil.settings[name] !== value) {
|
||||
WebUtil.settings[name] = value;
|
||||
window.chrome.storage.sync.set(WebUtil.settings);
|
||||
}
|
||||
} else {
|
||||
localStorage.setItem(name, value);
|
||||
}
|
||||
};
|
||||
|
||||
WebUtil.readSetting = function (name, defaultValue) {
|
||||
"use strict";
|
||||
var value;
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
value = WebUtil.settings[name];
|
||||
} else {
|
||||
value = localStorage.getItem(name);
|
||||
}
|
||||
if (typeof value === "undefined") {
|
||||
value = null;
|
||||
}
|
||||
if (value === null && typeof defaultValue !== undefined) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
WebUtil.eraseSetting = function (name) {
|
||||
"use strict";
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
window.chrome.storage.sync.remove(name);
|
||||
delete WebUtil.settings[name];
|
||||
} else {
|
||||
localStorage.removeItem(name);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Alternate stylesheet selection
|
||||
*/
|
||||
WebUtil.getStylesheets = function () {
|
||||
"use strict";
|
||||
var links = document.getElementsByTagName("link");
|
||||
var sheets = [];
|
||||
|
||||
for (var i = 0; i < links.length; i += 1) {
|
||||
if (links[i].title &&
|
||||
links[i].rel.toUpperCase().indexOf("STYLESHEET") > -1) {
|
||||
sheets.push(links[i]);
|
||||
}
|
||||
}
|
||||
return sheets;
|
||||
};
|
||||
|
||||
// No sheet means try and use value from cookie, null sheet used to
|
||||
// clear all alternates.
|
||||
WebUtil.selectStylesheet = function (sheet) {
|
||||
"use strict";
|
||||
if (typeof sheet === 'undefined') {
|
||||
sheet = 'default';
|
||||
}
|
||||
|
||||
var sheets = WebUtil.getStylesheets();
|
||||
for (var i = 0; i < sheets.length; i += 1) {
|
||||
var link = sheets[i];
|
||||
if (link.title === sheet) {
|
||||
Util.Debug("Using stylesheet " + sheet);
|
||||
link.disabled = false;
|
||||
} else {
|
||||
//Util.Debug("Skipping stylesheet " + link.title);
|
||||
link.disabled = true;
|
||||
}
|
||||
}
|
||||
return sheet;
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
|
||||
var prev = old && old != CodeMirror.Init;
|
||||
if (val && !prev) {
|
||||
cm.on("blur", onBlur);
|
||||
cm.on("change", onChange);
|
||||
onChange(cm);
|
||||
} else if (!val && prev) {
|
||||
cm.off("blur", onBlur);
|
||||
cm.off("change", onChange);
|
||||
clearPlaceholder(cm);
|
||||
var wrapper = cm.getWrapperElement();
|
||||
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
|
||||
}
|
||||
|
||||
if (val && !cm.hasFocus()) onBlur(cm);
|
||||
});
|
||||
|
||||
function clearPlaceholder(cm) {
|
||||
if (cm.state.placeholder) {
|
||||
cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
|
||||
cm.state.placeholder = null;
|
||||
}
|
||||
}
|
||||
function setPlaceholder(cm) {
|
||||
clearPlaceholder(cm);
|
||||
var elt = cm.state.placeholder = document.createElement("pre");
|
||||
elt.style.cssText = "height: 0; overflow: visible";
|
||||
elt.className = "CodeMirror-placeholder";
|
||||
elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
|
||||
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
|
||||
}
|
||||
|
||||
function onBlur(cm) {
|
||||
if (isEmpty(cm)) setPlaceholder(cm);
|
||||
}
|
||||
function onChange(cm) {
|
||||
var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
|
||||
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
|
||||
|
||||
if (empty) setPlaceholder(cm);
|
||||
else clearPlaceholder(cm);
|
||||
}
|
||||
|
||||
function isEmpty(cm) {
|
||||
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
function doFold(cm, pos, options, force) {
|
||||
if (options && options.call) {
|
||||
var finder = options;
|
||||
options = null;
|
||||
} else {
|
||||
var finder = getOption(cm, options, "rangeFinder");
|
||||
}
|
||||
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
|
||||
var minSize = getOption(cm, options, "minFoldSize");
|
||||
|
||||
function getRange(allowFolded) {
|
||||
var range = finder(cm, pos);
|
||||
if (!range || range.to.line - range.from.line < minSize) return null;
|
||||
var marks = cm.findMarksAt(range.from);
|
||||
for (var i = 0; i < marks.length; ++i) {
|
||||
if (marks[i].__isFold && force !== "fold") {
|
||||
if (!allowFolded) return null;
|
||||
range.cleared = true;
|
||||
marks[i].clear();
|
||||
}
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
var range = getRange(true);
|
||||
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
|
||||
pos = CodeMirror.Pos(pos.line - 1, 0);
|
||||
range = getRange(false);
|
||||
}
|
||||
if (!range || range.cleared || force === "unfold") return;
|
||||
|
||||
var myWidget = makeWidget(cm, options);
|
||||
CodeMirror.on(myWidget, "mousedown", function(e) {
|
||||
myRange.clear();
|
||||
CodeMirror.e_preventDefault(e);
|
||||
});
|
||||
var myRange = cm.markText(range.from, range.to, {
|
||||
replacedWith: myWidget,
|
||||
clearOnEnter: true,
|
||||
__isFold: true
|
||||
});
|
||||
myRange.on("clear", function(from, to) {
|
||||
CodeMirror.signal(cm, "unfold", cm, from, to);
|
||||
});
|
||||
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
|
||||
}
|
||||
|
||||
function makeWidget(cm, options) {
|
||||
var widget = getOption(cm, options, "widget");
|
||||
if (typeof widget == "string") {
|
||||
var text = document.createTextNode(widget);
|
||||
widget = document.createElement("span");
|
||||
widget.appendChild(text);
|
||||
widget.className = "CodeMirror-foldmarker";
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
// Clumsy backwards-compatible interface
|
||||
CodeMirror.newFoldFunction = function(rangeFinder, widget) {
|
||||
return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
|
||||
};
|
||||
|
||||
// New-style interface
|
||||
CodeMirror.defineExtension("foldCode", function(pos, options, force) {
|
||||
doFold(this, pos, options, force);
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("isFolded", function(pos) {
|
||||
var marks = this.findMarksAt(pos);
|
||||
for (var i = 0; i < marks.length; ++i)
|
||||
if (marks[i].__isFold) return true;
|
||||
});
|
||||
|
||||
CodeMirror.commands.toggleFold = function(cm) {
|
||||
cm.foldCode(cm.getCursor());
|
||||
};
|
||||
CodeMirror.commands.fold = function(cm) {
|
||||
cm.foldCode(cm.getCursor(), null, "fold");
|
||||
};
|
||||
CodeMirror.commands.unfold = function(cm) {
|
||||
cm.foldCode(cm.getCursor(), null, "unfold");
|
||||
};
|
||||
CodeMirror.commands.foldAll = function(cm) {
|
||||
cm.operation(function() {
|
||||
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
||||
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
|
||||
});
|
||||
};
|
||||
CodeMirror.commands.unfoldAll = function(cm) {
|
||||
cm.operation(function() {
|
||||
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
||||
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
|
||||
});
|
||||
};
|
||||
|
||||
CodeMirror.registerHelper("fold", "combine", function() {
|
||||
var funcs = Array.prototype.slice.call(arguments, 0);
|
||||
return function(cm, start) {
|
||||
for (var i = 0; i < funcs.length; ++i) {
|
||||
var found = funcs[i](cm, start);
|
||||
if (found) return found;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("fold", "auto", function(cm, start) {
|
||||
var helpers = cm.getHelpers(start, "fold");
|
||||
for (var i = 0; i < helpers.length; i++) {
|
||||
var cur = helpers[i](cm, start);
|
||||
if (cur) return cur;
|
||||
}
|
||||
});
|
||||
|
||||
var defaultOptions = {
|
||||
rangeFinder: CodeMirror.fold.auto,
|
||||
widget: "\u2194",
|
||||
minFoldSize: 0,
|
||||
scanUp: false
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("foldOptions", null);
|
||||
|
||||
function getOption(cm, options, name) {
|
||||
if (options && options[name] !== undefined)
|
||||
return options[name];
|
||||
var editorOptions = cm.options.foldOptions;
|
||||
if (editorOptions && editorOptions[name] !== undefined)
|
||||
return editorOptions[name];
|
||||
return defaultOptions[name];
|
||||
}
|
||||
|
||||
CodeMirror.defineExtension("foldOption", function(options, name) {
|
||||
return getOption(this, options, name);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,282 @@
|
||||
function getLibvirtSchema() {
|
||||
|
||||
var root = {};
|
||||
|
||||
root.domain = {
|
||||
"!attrs": {
|
||||
type: ["kvm"],
|
||||
"xmlns:qemu": ["http://libvirt.org/schemas/domain/qemu/1.0"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.name = {
|
||||
"!value": ""
|
||||
};
|
||||
|
||||
root.domain.description = {
|
||||
"!value": ""
|
||||
};
|
||||
|
||||
root.domain.memory = {
|
||||
"!attrs": {
|
||||
unit: ["MiB", "KiB", "GiB"]
|
||||
},
|
||||
"!value": 512
|
||||
};
|
||||
|
||||
root.domain.currentMemory = {
|
||||
"!attrs": {
|
||||
unit: ["MiB", "KiB", "GiB"]
|
||||
},
|
||||
"!value": 512
|
||||
};
|
||||
|
||||
root.domain.memoryBacking = {};
|
||||
root.domain.memoryBacking.nosharepages = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.memoryBacking.locked = {
|
||||
"!novalue": 1
|
||||
};
|
||||
|
||||
root.domain.vcpu = {
|
||||
"!attrs": {
|
||||
placement: ["static"]
|
||||
},
|
||||
"!value": 1
|
||||
};
|
||||
|
||||
root.domain.cputune = {};
|
||||
root.domain.cputune.vcpupin = {
|
||||
"!attrs": {
|
||||
vcpu: null,
|
||||
cpuset: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.cpu = {
|
||||
"!attrs": {
|
||||
mode: ["host-passthrough"]
|
||||
}
|
||||
};
|
||||
root.domain.cpu.topology = {
|
||||
"!attrs": {
|
||||
sockets: null,
|
||||
cores: null,
|
||||
threads: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.os = {};
|
||||
root.domain.os.type = {
|
||||
"!attrs": {
|
||||
arch: ["x86_64"],
|
||||
machine: ["pc", "q35"]
|
||||
},
|
||||
"!value": "hvm"
|
||||
};
|
||||
root.domain.os.loader = {
|
||||
"!attrs": {
|
||||
type: ["pflash"]
|
||||
},
|
||||
"!value": "/usr/share/qemu/ovmf-x64/OVMF-pure-efi.fd"
|
||||
};
|
||||
|
||||
root.domain.features = {};
|
||||
root.domain.features.acpi = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.features.apic = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.features.hyperv = {};
|
||||
root.domain.features.hyperv.relaxed = {
|
||||
"!attrs": {
|
||||
state: ["on", "off"]
|
||||
}
|
||||
};
|
||||
root.domain.features.hyperv.vapic = {
|
||||
"!attrs": {
|
||||
state: ["on", "off"]
|
||||
}
|
||||
};
|
||||
root.domain.features.hyperv.spinlocks = {
|
||||
"!attrs": {
|
||||
state: ["on", "off"],
|
||||
retries: null
|
||||
}
|
||||
};
|
||||
root.domain.features.pae = {
|
||||
"!novalue": 1
|
||||
};
|
||||
|
||||
root.domain.clock = {
|
||||
"!attrs": {
|
||||
offset: ["localtime", "utc"]
|
||||
}
|
||||
};
|
||||
root.domain.clock.timer = {
|
||||
"!attrs": {
|
||||
name: ["hypervclock", "hpet", "rtc", "pit"],
|
||||
tickpolicy: ["catchup", "delay"],
|
||||
present: ["no", "yes"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.on_poweroff = {
|
||||
"!value": "destroy"
|
||||
};
|
||||
|
||||
root.domain.on_reboot = {
|
||||
"!value": "restart"
|
||||
};
|
||||
|
||||
root.domain.on_crash = {
|
||||
"!value": "destroy"
|
||||
};
|
||||
|
||||
root.domain.devices = {};
|
||||
|
||||
root.domain.devices.emulator = {
|
||||
"!value": "/usr/bin/qemu-system-x86_64"
|
||||
};
|
||||
|
||||
root.domain.devices.disk = {
|
||||
"!attrs": {
|
||||
type: ["file"],
|
||||
device: ["disk", "cdrom"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.driver = {
|
||||
"!attrs": {
|
||||
name: ["qemu"],
|
||||
type: ["raw", "qcow2"],
|
||||
cache: ["none"],
|
||||
io: ["native"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.source = {
|
||||
"!attrs": {
|
||||
file: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.backingStore = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.devices.disk.target = {
|
||||
"!attrs": {
|
||||
dev: null,
|
||||
bus: ["ide", "sata", "virtio"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.readonly = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.devices.disk.boot = {
|
||||
"!attrs": {
|
||||
order: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.interface = {
|
||||
"!attrs": {
|
||||
type: ["bridge"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.interface.mac = {
|
||||
"!attrs": {
|
||||
address: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.interface.source = {
|
||||
"!attrs": {
|
||||
bridge: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.interface.model = {
|
||||
"!attrs": {
|
||||
type: ["virtio"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.input = {
|
||||
"!attrs": {
|
||||
type: ["tablet", "mouse", "keyboard"],
|
||||
bus: ["usb", "ps2"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.graphics = {
|
||||
"!attrs": {
|
||||
type: ["vnc"],
|
||||
port: ["-1"],
|
||||
autoport: ["yes", "no"],
|
||||
websocket: ["-1"],
|
||||
listen: ["0.0.0.0"],
|
||||
keymap: ["en-us", "en-gb", "ar", "hr", "cz", "da", "nl", "nl-be", "es", "et", "fo",
|
||||
"fi", "fr", "bepo", "fr-be", "fr-ca", "fr-ch", "de-ch", "hu", "is", "it",
|
||||
"ja", "lv", "lt", "mk", "no", "pl", "pt-br", "ru", "sl", "sv", "th", "tr"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.graphics.listen = {
|
||||
"!attrs": {
|
||||
type: ["address"],
|
||||
address: ["0.0.0.0"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.hostdev = {
|
||||
"!attrs": {
|
||||
mode: ["subsystem"],
|
||||
type: ["pci", "usb"],
|
||||
managed: ["yes", "no"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.driver = {
|
||||
"!attrs": {
|
||||
name: ["vfio"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.source = {};
|
||||
root.domain.devices.hostdev.source.address = {
|
||||
"!attrs": {
|
||||
domain: null,
|
||||
bus: null,
|
||||
slot: null,
|
||||
function: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.source.vendor = {
|
||||
"!attrs": {
|
||||
id: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.source.product = {
|
||||
"!attrs": {
|
||||
id: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.memballoon = {
|
||||
"!attrs": {
|
||||
model: ["virtio"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.memballoon.alias = {
|
||||
"!attrs": {
|
||||
name: ["balloon0"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain['qemu:commandline'] = {};
|
||||
root.domain['qemu:commandline']['qemu:arg'] = {
|
||||
"!attrs": {
|
||||
value: null
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
.CodeMirror-hints {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
list-style: none;
|
||||
|
||||
margin: 0;
|
||||
padding: 2px;
|
||||
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
border-radius: 3px;
|
||||
border: 1px solid silver;
|
||||
|
||||
background: white;
|
||||
font-size: 90%;
|
||||
font-family: monospace;
|
||||
|
||||
max-height: 20em;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.CodeMirror-hint {
|
||||
margin: 0;
|
||||
padding: 0 4px;
|
||||
border-radius: 2px;
|
||||
max-width: 19em;
|
||||
overflow: hidden;
|
||||
white-space: pre;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
li.CodeMirror-hint-active {
|
||||
background: #08f;
|
||||
color: white;
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
||||
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
||||
|
||||
// This is the old interface, kept around for now to stay
|
||||
// backwards-compatible.
|
||||
CodeMirror.showHint = function(cm, getHints, options) {
|
||||
if (!getHints) return cm.showHint(options);
|
||||
if (options && options.async) getHints.async = true;
|
||||
var newOpts = {hint: getHints};
|
||||
if (options) for (var prop in options) newOpts[prop] = options[prop];
|
||||
return cm.showHint(newOpts);
|
||||
};
|
||||
|
||||
CodeMirror.defineExtension("showHint", function(options) {
|
||||
// We want a single cursor position.
|
||||
if (this.listSelections().length > 1 || this.somethingSelected()) return;
|
||||
|
||||
if (this.state.completionActive) this.state.completionActive.close();
|
||||
var completion = this.state.completionActive = new Completion(this, options);
|
||||
var getHints = completion.options.hint;
|
||||
if (!getHints) return;
|
||||
|
||||
CodeMirror.signal(this, "startCompletion", this);
|
||||
if (getHints.async)
|
||||
getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
|
||||
else
|
||||
return completion.showHints(getHints(this, completion.options));
|
||||
});
|
||||
|
||||
function Completion(cm, options) {
|
||||
this.cm = cm;
|
||||
this.options = this.buildOptions(options);
|
||||
this.widget = this.onClose = null;
|
||||
}
|
||||
|
||||
Completion.prototype = {
|
||||
close: function() {
|
||||
if (!this.active()) return;
|
||||
this.cm.state.completionActive = null;
|
||||
|
||||
if (this.widget) this.widget.close();
|
||||
if (this.onClose) this.onClose();
|
||||
CodeMirror.signal(this.cm, "endCompletion", this.cm);
|
||||
},
|
||||
|
||||
active: function() {
|
||||
return this.cm.state.completionActive == this;
|
||||
},
|
||||
|
||||
pick: function(data, i) {
|
||||
var completion = data.list[i];
|
||||
if (completion.hint) completion.hint(this.cm, data, completion);
|
||||
else this.cm.replaceRange(getText(completion), completion.from || data.from,
|
||||
completion.to || data.to, "complete");
|
||||
CodeMirror.signal(data, "pick", completion);
|
||||
this.close();
|
||||
},
|
||||
|
||||
showHints: function(data) {
|
||||
if (!data || !data.list.length || !this.active()) return this.close();
|
||||
|
||||
if (this.options.completeSingle && data.list.length == 1)
|
||||
this.pick(data, 0);
|
||||
else
|
||||
this.showWidget(data);
|
||||
},
|
||||
|
||||
showWidget: function(data) {
|
||||
this.widget = new Widget(this, data);
|
||||
CodeMirror.signal(data, "shown");
|
||||
|
||||
var debounce = 0, completion = this, finished;
|
||||
var closeOn = this.options.closeCharacters;
|
||||
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
|
||||
|
||||
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
|
||||
return setTimeout(fn, 1000/60);
|
||||
};
|
||||
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
|
||||
|
||||
function done() {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
completion.close();
|
||||
completion.cm.off("cursorActivity", activity);
|
||||
if (data) CodeMirror.signal(data, "close");
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (finished) return;
|
||||
CodeMirror.signal(data, "update");
|
||||
var getHints = completion.options.hint;
|
||||
if (getHints.async)
|
||||
getHints(completion.cm, finishUpdate, completion.options);
|
||||
else
|
||||
finishUpdate(getHints(completion.cm, completion.options));
|
||||
}
|
||||
function finishUpdate(data_) {
|
||||
data = data_;
|
||||
if (finished) return;
|
||||
if (!data || !data.list.length) return done();
|
||||
if (completion.widget) completion.widget.close();
|
||||
completion.widget = new Widget(completion, data);
|
||||
}
|
||||
|
||||
function clearDebounce() {
|
||||
if (debounce) {
|
||||
cancelAnimationFrame(debounce);
|
||||
debounce = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function activity() {
|
||||
clearDebounce();
|
||||
var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line);
|
||||
if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch ||
|
||||
pos.ch < startPos.ch || completion.cm.somethingSelected() ||
|
||||
(pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) {
|
||||
completion.close();
|
||||
} else {
|
||||
debounce = requestAnimationFrame(update);
|
||||
if (completion.widget) completion.widget.close();
|
||||
}
|
||||
}
|
||||
this.cm.on("cursorActivity", activity);
|
||||
this.onClose = done;
|
||||
},
|
||||
|
||||
buildOptions: function(options) {
|
||||
var editor = this.cm.options.hintOptions;
|
||||
var out = {};
|
||||
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
|
||||
if (editor) for (var prop in editor)
|
||||
if (editor[prop] !== undefined) out[prop] = editor[prop];
|
||||
if (options) for (var prop in options)
|
||||
if (options[prop] !== undefined) out[prop] = options[prop];
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
function getText(completion) {
|
||||
if (typeof completion == "string") return completion;
|
||||
else return completion.text;
|
||||
}
|
||||
|
||||
function buildKeyMap(completion, handle) {
|
||||
var baseMap = {
|
||||
Up: function() {handle.moveFocus(-1);},
|
||||
Down: function() {handle.moveFocus(1);},
|
||||
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
|
||||
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
|
||||
Home: function() {handle.setFocus(0);},
|
||||
End: function() {handle.setFocus(handle.length - 1);},
|
||||
Enter: handle.pick,
|
||||
Tab: handle.pick,
|
||||
Esc: handle.close
|
||||
};
|
||||
var custom = completion.options.customKeys;
|
||||
var ourMap = custom ? {} : baseMap;
|
||||
function addBinding(key, val) {
|
||||
var bound;
|
||||
if (typeof val != "string")
|
||||
bound = function(cm) { return val(cm, handle); };
|
||||
// This mechanism is deprecated
|
||||
else if (baseMap.hasOwnProperty(val))
|
||||
bound = baseMap[val];
|
||||
else
|
||||
bound = val;
|
||||
ourMap[key] = bound;
|
||||
}
|
||||
if (custom)
|
||||
for (var key in custom) if (custom.hasOwnProperty(key))
|
||||
addBinding(key, custom[key]);
|
||||
var extra = completion.options.extraKeys;
|
||||
if (extra)
|
||||
for (var key in extra) if (extra.hasOwnProperty(key))
|
||||
addBinding(key, extra[key]);
|
||||
return ourMap;
|
||||
}
|
||||
|
||||
function getHintElement(hintsElement, el) {
|
||||
while (el && el != hintsElement) {
|
||||
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
|
||||
el = el.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
function Widget(completion, data) {
|
||||
this.completion = completion;
|
||||
this.data = data;
|
||||
var widget = this, cm = completion.cm;
|
||||
|
||||
var hints = this.hints = document.createElement("ul");
|
||||
hints.className = "CodeMirror-hints";
|
||||
this.selectedHint = data.selectedHint || 0;
|
||||
|
||||
var completions = data.list;
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
|
||||
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
|
||||
if (cur.className != null) className = cur.className + " " + className;
|
||||
elt.className = className;
|
||||
if (cur.render) cur.render(elt, data, cur);
|
||||
else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
|
||||
elt.hintId = i;
|
||||
}
|
||||
|
||||
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
|
||||
var left = pos.left, top = pos.bottom, below = true;
|
||||
hints.style.left = left + "px";
|
||||
hints.style.top = top + "px";
|
||||
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
||||
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
|
||||
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
||||
(completion.options.container || document.body).appendChild(hints);
|
||||
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
|
||||
if (overlapY > 0) {
|
||||
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
|
||||
if (curTop - height > 0) { // Fits above cursor
|
||||
hints.style.top = (top = pos.top - height) + "px";
|
||||
below = false;
|
||||
} else if (height > winH) {
|
||||
hints.style.height = (winH - 5) + "px";
|
||||
hints.style.top = (top = pos.bottom - box.top) + "px";
|
||||
var cursor = cm.getCursor();
|
||||
if (data.from.ch != cursor.ch) {
|
||||
pos = cm.cursorCoords(cursor);
|
||||
hints.style.left = (left = pos.left) + "px";
|
||||
box = hints.getBoundingClientRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
var overlapX = box.right - winW;
|
||||
if (overlapX > 0) {
|
||||
if (box.right - box.left > winW) {
|
||||
hints.style.width = (winW - 5) + "px";
|
||||
overlapX -= (box.right - box.left) - winW;
|
||||
}
|
||||
hints.style.left = (left = pos.left - overlapX) + "px";
|
||||
}
|
||||
|
||||
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
|
||||
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
||||
setFocus: function(n) { widget.changeActive(n); },
|
||||
menuSize: function() { return widget.screenAmount(); },
|
||||
length: completions.length,
|
||||
close: function() { completion.close(); },
|
||||
pick: function() { widget.pick(); },
|
||||
data: data
|
||||
}));
|
||||
|
||||
if (completion.options.closeOnUnfocus) {
|
||||
var closingOnBlur;
|
||||
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
||||
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
||||
}
|
||||
|
||||
var startScroll = cm.getScrollInfo();
|
||||
cm.on("scroll", this.onScroll = function() {
|
||||
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
|
||||
var newTop = top + startScroll.top - curScroll.top;
|
||||
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
|
||||
if (!below) point += hints.offsetHeight;
|
||||
if (point <= editor.top || point >= editor.bottom) return completion.close();
|
||||
hints.style.top = newTop + "px";
|
||||
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "dblclick", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "click", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {
|
||||
widget.changeActive(t.hintId);
|
||||
if (completion.options.completeOnSingleClick) widget.pick();
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "mousedown", function() {
|
||||
setTimeout(function(){cm.focus();}, 20);
|
||||
});
|
||||
|
||||
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget.prototype = {
|
||||
close: function() {
|
||||
if (this.completion.widget != this) return;
|
||||
this.completion.widget = null;
|
||||
this.hints.parentNode.removeChild(this.hints);
|
||||
this.completion.cm.removeKeyMap(this.keyMap);
|
||||
|
||||
var cm = this.completion.cm;
|
||||
if (this.completion.options.closeOnUnfocus) {
|
||||
cm.off("blur", this.onBlur);
|
||||
cm.off("focus", this.onFocus);
|
||||
}
|
||||
cm.off("scroll", this.onScroll);
|
||||
},
|
||||
|
||||
pick: function() {
|
||||
this.completion.pick(this.data, this.selectedHint);
|
||||
},
|
||||
|
||||
changeActive: function(i, avoidWrap) {
|
||||
if (i >= this.data.list.length)
|
||||
i = avoidWrap ? this.data.list.length - 1 : 0;
|
||||
else if (i < 0)
|
||||
i = avoidWrap ? 0 : this.data.list.length - 1;
|
||||
if (this.selectedHint == i) return;
|
||||
var node = this.hints.childNodes[this.selectedHint];
|
||||
node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
|
||||
node = this.hints.childNodes[this.selectedHint = i];
|
||||
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
|
||||
if (node.offsetTop < this.hints.scrollTop)
|
||||
this.hints.scrollTop = node.offsetTop - 3;
|
||||
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
|
||||
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
|
||||
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
|
||||
},
|
||||
|
||||
screenAmount: function() {
|
||||
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.registerHelper("hint", "auto", function(cm, options) {
|
||||
var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
|
||||
if (helpers.length) {
|
||||
for (var i = 0; i < helpers.length; i++) {
|
||||
var cur = helpers[i](cm, options);
|
||||
if (cur && cur.list.length) return cur;
|
||||
}
|
||||
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
|
||||
if (words) return CodeMirror.hint.fromList(cm, {words: words});
|
||||
} else if (CodeMirror.hint.anyword) {
|
||||
return CodeMirror.hint.anyword(cm, options);
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
var found = [];
|
||||
for (var i = 0; i < options.words.length; i++) {
|
||||
var word = options.words[i];
|
||||
if (word.slice(0, token.string.length) == token.string)
|
||||
found.push(word);
|
||||
}
|
||||
|
||||
if (found.length) return {
|
||||
list: found,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.commands.autocomplete = CodeMirror.showHint;
|
||||
|
||||
var defaultOptions = {
|
||||
hint: CodeMirror.hint.auto,
|
||||
completeSingle: true,
|
||||
alignWithWord: true,
|
||||
closeCharacters: /[\s()\[\]{};:>,]/,
|
||||
closeOnUnfocus: true,
|
||||
completeOnSingleClick: false,
|
||||
container: null,
|
||||
customKeys: null,
|
||||
extraKeys: null
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("hintOptions", null);
|
||||
});
|
||||
@@ -0,0 +1,135 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function getHints(cm, options) {
|
||||
var tags = options && options.schemaInfo;
|
||||
var quote = (options && options.quoteChar) || '"';
|
||||
if (!tags) return;
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
if (token.end > cur.ch) {
|
||||
token.end = cur.ch;
|
||||
token.string = token.string.slice(0, cur.ch - token.start);
|
||||
}
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
|
||||
if (inner.mode.name != "xml") return;
|
||||
var result = [], replaceToken = false, prefix;
|
||||
var tag = /\btag\b/.test(token.type) && !/>$/.test(token.string);
|
||||
var tagName = tag && /^\w/.test(token.string), tagStart;
|
||||
var tagType = null;
|
||||
|
||||
if (tagName) {
|
||||
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
|
||||
tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
|
||||
if (tagType) tagStart = token.start - (tagType == "close" ? 2 : 1);
|
||||
} else if (tag && token.string == "<") {
|
||||
tagType = "open";
|
||||
} else if (tag && token.string == "</") {
|
||||
tagType = "close";
|
||||
}
|
||||
|
||||
var cx = inner.state.context;
|
||||
|
||||
var localtags = tags;
|
||||
var topattrs = tags["!attrs"];
|
||||
|
||||
if (cx && cx.tagName) {
|
||||
var nodepath = [cx.tagName];
|
||||
var prevnode = cx.prev;
|
||||
while (prevnode) {
|
||||
nodepath.push(prevnode.tagName);
|
||||
prevnode = prevnode.prev;
|
||||
}
|
||||
for (var i = nodepath.length - 1; i >= 0; i--) {
|
||||
if (! localtags[nodepath[i]]) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (localtags["!attrs"]) {
|
||||
topattrs = localtags["!attrs"];
|
||||
}
|
||||
|
||||
localtags = localtags[nodepath[i]];
|
||||
}
|
||||
}
|
||||
|
||||
if (!tag && !inner.state.tagName || tagType) {
|
||||
if (tagName)
|
||||
prefix = token.string;
|
||||
replaceToken = tagType;
|
||||
if (tagType != "close") {
|
||||
for (var name in localtags) {
|
||||
if (localtags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && name != "!value" && (!prefix || name.lastIndexOf(prefix, 0) === 0)) {
|
||||
if (localtags[name]["!attrs"]) {
|
||||
result.push("<" + name);
|
||||
} else {
|
||||
if (Object.keys(localtags[name]).length === 1 && localtags[name].hasOwnProperty("!novalue")) {
|
||||
result.push("<" + name + "/>");
|
||||
} else if (Object.keys(localtags[name]).length === 1 && localtags[name].hasOwnProperty("!value")) {
|
||||
result.push("<" + name + ">");
|
||||
} else {
|
||||
result.push("<" + name + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) === 0)) {
|
||||
result.push("</" + cx.tagName + ">");
|
||||
}
|
||||
} else {
|
||||
// Attribute completion
|
||||
var attrs = localtags && localtags[inner.state.tagName] && localtags[inner.state.tagName]["!attrs"];
|
||||
if (!attrs) return;
|
||||
if (token.type == "string" || token.string == "=") { // A value
|
||||
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
|
||||
Pos(cur.line, token.type == "string" ? token.start : token.end));
|
||||
var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/), atValues;
|
||||
if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
|
||||
if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
|
||||
if (token.type == "string") {
|
||||
prefix = token.string;
|
||||
var n = 0;
|
||||
if (/['"]/.test(token.string.charAt(0))) {
|
||||
quote = token.string.charAt(0);
|
||||
prefix = token.string.slice(1);
|
||||
n++;
|
||||
}
|
||||
var len = token.string.length;
|
||||
if (/['"]/.test(token.string.charAt(len - 1))) {
|
||||
quote = token.string.charAt(len - 1);
|
||||
prefix = token.string.substr(n, len - 2);
|
||||
}
|
||||
replaceToken = true;
|
||||
}
|
||||
for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].lastIndexOf(prefix, 0) === 0)
|
||||
result.push(quote + atValues[i] + quote);
|
||||
} else { // An attribute name
|
||||
if (token.type == "attribute") {
|
||||
prefix = token.string;
|
||||
replaceToken = true;
|
||||
}
|
||||
for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.lastIndexOf(prefix, 0) === 0))
|
||||
result.push(attr);
|
||||
}
|
||||
}
|
||||
return {
|
||||
list: result,
|
||||
from: replaceToken ? Pos(cur.line, tagStart == null ? token.start : tagStart) : cur,
|
||||
to: replaceToken ? Pos(cur.line, token.end) : cur
|
||||
};
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("hint", "xml", getHints);
|
||||
});
|
||||
@@ -0,0 +1,309 @@
|
||||
/* BASICS */
|
||||
|
||||
.CodeMirror {
|
||||
/* Set height, width, borders, and global font properties here */
|
||||
font-family: monospace;
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
/* PADDING */
|
||||
|
||||
.CodeMirror-lines {
|
||||
padding: 4px 0; /* Vertical padding around content */
|
||||
}
|
||||
.CodeMirror pre {
|
||||
padding: 0 4px; /* Horizontal padding of content */
|
||||
}
|
||||
|
||||
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||
background-color: white; /* The little square between H and V scrollbars */
|
||||
}
|
||||
|
||||
/* GUTTER */
|
||||
|
||||
.CodeMirror-gutters {
|
||||
border-right: 1px solid #ddd;
|
||||
background-color: #f7f7f7;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.CodeMirror-linenumbers {}
|
||||
.CodeMirror-linenumber {
|
||||
padding: 0 3px 0 5px;
|
||||
min-width: 20px;
|
||||
text-align: right;
|
||||
color: #999;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
.CodeMirror-guttermarker { color: black; }
|
||||
.CodeMirror-guttermarker-subtle { color: #999; }
|
||||
|
||||
/* CURSOR */
|
||||
|
||||
.CodeMirror div.CodeMirror-cursor {
|
||||
border-left: 1px solid black;
|
||||
}
|
||||
/* Shown when moving in bi-directional text */
|
||||
.CodeMirror div.CodeMirror-secondarycursor {
|
||||
border-left: 1px solid silver;
|
||||
}
|
||||
.CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
|
||||
width: auto;
|
||||
border: 0;
|
||||
background: #7e7;
|
||||
}
|
||||
.CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.cm-animate-fat-cursor {
|
||||
width: auto;
|
||||
border: 0;
|
||||
-webkit-animation: blink 1.06s steps(1) infinite;
|
||||
-moz-animation: blink 1.06s steps(1) infinite;
|
||||
animation: blink 1.06s steps(1) infinite;
|
||||
}
|
||||
@-moz-keyframes blink {
|
||||
0% { background: #7e7; }
|
||||
50% { background: none; }
|
||||
100% { background: #7e7; }
|
||||
}
|
||||
@-webkit-keyframes blink {
|
||||
0% { background: #7e7; }
|
||||
50% { background: none; }
|
||||
100% { background: #7e7; }
|
||||
}
|
||||
@keyframes blink {
|
||||
0% { background: #7e7; }
|
||||
50% { background: none; }
|
||||
100% { background: #7e7; }
|
||||
}
|
||||
|
||||
/* Can style cursor different in overwrite (non-insert) mode */
|
||||
div.CodeMirror-overwrite div.CodeMirror-cursor {}
|
||||
|
||||
.cm-tab { display: inline-block; text-decoration: inherit; }
|
||||
|
||||
.CodeMirror-ruler {
|
||||
border-left: 1px solid #ccc;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
/* DEFAULT THEME */
|
||||
|
||||
.cm-s-default .cm-keyword {color: #708;}
|
||||
.cm-s-default .cm-atom {color: #219;}
|
||||
.cm-s-default .cm-number {color: #164;}
|
||||
.cm-s-default .cm-def {color: #00f;}
|
||||
.cm-s-default .cm-variable,
|
||||
.cm-s-default .cm-punctuation,
|
||||
.cm-s-default .cm-property,
|
||||
.cm-s-default .cm-operator {}
|
||||
.cm-s-default .cm-variable-2 {color: #05a;}
|
||||
.cm-s-default .cm-variable-3 {color: #085;}
|
||||
.cm-s-default .cm-comment {color: #a50;}
|
||||
.cm-s-default .cm-string {color: #a11;}
|
||||
.cm-s-default .cm-string-2 {color: #f50;}
|
||||
.cm-s-default .cm-meta {color: #555;}
|
||||
.cm-s-default .cm-qualifier {color: #555;}
|
||||
.cm-s-default .cm-builtin {color: #30a;}
|
||||
.cm-s-default .cm-bracket {color: #997;}
|
||||
.cm-s-default .cm-tag {color: #170;}
|
||||
.cm-s-default .cm-attribute {color: #00c;}
|
||||
.cm-s-default .cm-header {color: blue;}
|
||||
.cm-s-default .cm-quote {color: #090;}
|
||||
.cm-s-default .cm-hr {color: #999;}
|
||||
.cm-s-default .cm-link {color: #00c;}
|
||||
|
||||
.cm-negative {color: #d44;}
|
||||
.cm-positive {color: #292;}
|
||||
.cm-header, .cm-strong {font-weight: bold;}
|
||||
.cm-em {font-style: italic;}
|
||||
.cm-link {text-decoration: underline;}
|
||||
.cm-strikethrough {text-decoration: line-through;}
|
||||
|
||||
.cm-s-default .cm-error {color: #f00;}
|
||||
.cm-invalidchar {color: #f00;}
|
||||
|
||||
/* Default styles for common addons */
|
||||
|
||||
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
||||
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
||||
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
||||
.CodeMirror-activeline-background {background: #e8f2ff;}
|
||||
|
||||
/* STOP */
|
||||
|
||||
/* The rest of this file contains styles related to the mechanics of
|
||||
the editor. You probably shouldn't touch them. */
|
||||
|
||||
.CodeMirror {
|
||||
line-height: 1;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: white;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.CodeMirror-scroll {
|
||||
overflow: scroll !important; /* Things will break if this is overridden */
|
||||
/* 30px is the magic margin used to hide the element's real scrollbars */
|
||||
/* See overflow: hidden in .CodeMirror */
|
||||
margin-bottom: -30px; margin-right: -30px;
|
||||
padding-bottom: 30px;
|
||||
height: 100%;
|
||||
outline: none; /* Prevent dragging from highlighting the element */
|
||||
position: relative;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
.CodeMirror-sizer {
|
||||
position: relative;
|
||||
border-right: 30px solid transparent;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
||||
before actuall scrolling happens, thus preventing shaking and
|
||||
flickering artifacts. */
|
||||
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||
position: absolute;
|
||||
z-index: 6;
|
||||
display: none;
|
||||
}
|
||||
.CodeMirror-vscrollbar {
|
||||
right: 0; top: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.CodeMirror-hscrollbar {
|
||||
bottom: 0; left: 0;
|
||||
overflow-y: hidden;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
.CodeMirror-scrollbar-filler {
|
||||
right: 0; bottom: 0;
|
||||
}
|
||||
.CodeMirror-gutter-filler {
|
||||
left: 0; bottom: 0;
|
||||
}
|
||||
|
||||
.CodeMirror-gutters {
|
||||
position: absolute; left: 0; top: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
.CodeMirror-gutter {
|
||||
white-space: normal;
|
||||
height: 100%;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
display: inline-block;
|
||||
margin-bottom: -30px;
|
||||
/* Hack to make IE7 behave */
|
||||
*zoom:1;
|
||||
*display:inline;
|
||||
}
|
||||
.CodeMirror-gutter-wrapper {
|
||||
position: absolute;
|
||||
z-index: 4;
|
||||
height: 100%;
|
||||
}
|
||||
.CodeMirror-gutter-elt {
|
||||
position: absolute;
|
||||
cursor: default;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
.CodeMirror-lines {
|
||||
cursor: text;
|
||||
min-height: 1px; /* prevents collapsing before first draw */
|
||||
}
|
||||
.CodeMirror pre {
|
||||
/* Reset some styles that the rest of the page might have set */
|
||||
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
||||
border-width: 0;
|
||||
background: transparent;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
margin: 0;
|
||||
white-space: pre;
|
||||
word-wrap: normal;
|
||||
line-height: inherit;
|
||||
color: inherit;
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
}
|
||||
.CodeMirror-wrap pre {
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.CodeMirror-linebackground {
|
||||
position: absolute;
|
||||
left: 0; right: 0; top: 0; bottom: 0;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.CodeMirror-linewidget {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.CodeMirror-widget {}
|
||||
|
||||
.CodeMirror-measure {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
visibility: hidden;
|
||||
}
|
||||
.CodeMirror-measure pre { position: static; }
|
||||
|
||||
.CodeMirror div.CodeMirror-cursor {
|
||||
position: absolute;
|
||||
border-right: none;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
div.CodeMirror-cursors {
|
||||
visibility: hidden;
|
||||
position: relative;
|
||||
z-index: 3;
|
||||
}
|
||||
.CodeMirror-focused div.CodeMirror-cursors {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.CodeMirror-selected { background: #d9d9d9; }
|
||||
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
||||
.CodeMirror-crosshair { cursor: crosshair; }
|
||||
|
||||
.cm-searching {
|
||||
background: #ffa;
|
||||
background: rgba(255, 255, 0, .4);
|
||||
}
|
||||
|
||||
/* IE7 hack to prevent it from returning funny offsetTops on the spans */
|
||||
.CodeMirror span { *vertical-align: text-bottom; }
|
||||
|
||||
/* Used to force a border model for a node */
|
||||
.cm-force-border { padding-right: .1px; }
|
||||
|
||||
@media print {
|
||||
/* Hide the cursor when printing */
|
||||
.CodeMirror div.CodeMirror-cursors {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
/* See issue #2901 */
|
||||
.cm-tab-wrap-hack:after { content: ''; }
|
||||
|
||||
/* Help users use markselection to safely style text background */
|
||||
span.CodeMirror-selectedtext { background: none; }
|
||||
@@ -0,0 +1,384 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit;
|
||||
var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1;
|
||||
var multilineTagIndentPastTag = parserConfig.multilineTagIndentPastTag;
|
||||
if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true;
|
||||
|
||||
var Kludges = parserConfig.htmlMode ? {
|
||||
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
|
||||
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
|
||||
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
|
||||
'track': true, 'wbr': true, 'menuitem': true},
|
||||
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
|
||||
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
|
||||
'th': true, 'tr': true},
|
||||
contextGrabbers: {
|
||||
'dd': {'dd': true, 'dt': true},
|
||||
'dt': {'dd': true, 'dt': true},
|
||||
'li': {'li': true},
|
||||
'option': {'option': true, 'optgroup': true},
|
||||
'optgroup': {'optgroup': true},
|
||||
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
|
||||
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
|
||||
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
|
||||
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
|
||||
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
|
||||
'rp': {'rp': true, 'rt': true},
|
||||
'rt': {'rp': true, 'rt': true},
|
||||
'tbody': {'tbody': true, 'tfoot': true},
|
||||
'td': {'td': true, 'th': true},
|
||||
'tfoot': {'tbody': true},
|
||||
'th': {'td': true, 'th': true},
|
||||
'thead': {'tbody': true, 'tfoot': true},
|
||||
'tr': {'tr': true}
|
||||
},
|
||||
doNotIndent: {"pre": true},
|
||||
allowUnquoted: true,
|
||||
allowMissing: true,
|
||||
caseFold: true
|
||||
} : {
|
||||
autoSelfClosers: {},
|
||||
implicitlyClosed: {},
|
||||
contextGrabbers: {},
|
||||
doNotIndent: {},
|
||||
allowUnquoted: false,
|
||||
allowMissing: false,
|
||||
caseFold: false
|
||||
};
|
||||
var alignCDATA = parserConfig.alignCDATA;
|
||||
|
||||
// Return variables for tokenizers
|
||||
var type, setStyle;
|
||||
|
||||
function inText(stream, state) {
|
||||
function chain(parser) {
|
||||
state.tokenize = parser;
|
||||
return parser(stream, state);
|
||||
}
|
||||
|
||||
var ch = stream.next();
|
||||
if (ch == "<") {
|
||||
if (stream.eat("!")) {
|
||||
if (stream.eat("[")) {
|
||||
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
||||
else return null;
|
||||
} else if (stream.match("--")) {
|
||||
return chain(inBlock("comment", "-->"));
|
||||
} else if (stream.match("DOCTYPE", true, true)) {
|
||||
stream.eatWhile(/[\w\._\-]/);
|
||||
return chain(doctype(1));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (stream.eat("?")) {
|
||||
stream.eatWhile(/[\w\._\-]/);
|
||||
state.tokenize = inBlock("meta", "?>");
|
||||
return "meta";
|
||||
} else {
|
||||
type = stream.eat("/") ? "closeTag" : "openTag";
|
||||
state.tokenize = inTag;
|
||||
return "tag bracket";
|
||||
}
|
||||
} else if (ch == "&") {
|
||||
var ok;
|
||||
if (stream.eat("#")) {
|
||||
if (stream.eat("x")) {
|
||||
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
|
||||
} else {
|
||||
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
|
||||
}
|
||||
} else {
|
||||
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
|
||||
}
|
||||
return ok ? "atom" : "error";
|
||||
} else {
|
||||
stream.eatWhile(/[^&<]/);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function inTag(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
||||
state.tokenize = inText;
|
||||
type = ch == ">" ? "endTag" : "selfcloseTag";
|
||||
return "tag bracket";
|
||||
} else if (ch == "=") {
|
||||
type = "equals";
|
||||
return null;
|
||||
} else if (ch == "<") {
|
||||
state.tokenize = inText;
|
||||
state.state = baseState;
|
||||
state.tagName = state.tagStart = null;
|
||||
var next = state.tokenize(stream, state);
|
||||
return next ? next + " tag error" : "tag error";
|
||||
} else if (/[\'\"]/.test(ch)) {
|
||||
state.tokenize = inAttribute(ch);
|
||||
state.stringStartCol = stream.column();
|
||||
return state.tokenize(stream, state);
|
||||
} else {
|
||||
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
|
||||
return "word";
|
||||
}
|
||||
}
|
||||
|
||||
function inAttribute(quote) {
|
||||
var closure = function(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
if (stream.next() == quote) {
|
||||
state.tokenize = inTag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "string";
|
||||
};
|
||||
closure.isInAttribute = true;
|
||||
return closure;
|
||||
}
|
||||
|
||||
function inBlock(style, terminator) {
|
||||
return function(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
if (stream.match(terminator)) {
|
||||
state.tokenize = inText;
|
||||
break;
|
||||
}
|
||||
stream.next();
|
||||
}
|
||||
return style;
|
||||
};
|
||||
}
|
||||
function doctype(depth) {
|
||||
return function(stream, state) {
|
||||
var ch;
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == "<") {
|
||||
state.tokenize = doctype(depth + 1);
|
||||
return state.tokenize(stream, state);
|
||||
} else if (ch == ">") {
|
||||
if (depth == 1) {
|
||||
state.tokenize = inText;
|
||||
break;
|
||||
} else {
|
||||
state.tokenize = doctype(depth - 1);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "meta";
|
||||
};
|
||||
}
|
||||
|
||||
function Context(state, tagName, startOfLine) {
|
||||
this.prev = state.context;
|
||||
this.tagName = tagName;
|
||||
this.indent = state.indented;
|
||||
this.startOfLine = startOfLine;
|
||||
if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
|
||||
this.noIndent = true;
|
||||
}
|
||||
function popContext(state) {
|
||||
if (state.context) state.context = state.context.prev;
|
||||
}
|
||||
function maybePopContext(state, nextTagName) {
|
||||
var parentTagName;
|
||||
while (true) {
|
||||
if (!state.context) {
|
||||
return;
|
||||
}
|
||||
parentTagName = state.context.tagName;
|
||||
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
|
||||
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
|
||||
return;
|
||||
}
|
||||
popContext(state);
|
||||
}
|
||||
}
|
||||
|
||||
function baseState(type, stream, state) {
|
||||
if (type == "openTag") {
|
||||
state.tagStart = stream.column();
|
||||
return tagNameState;
|
||||
} else if (type == "closeTag") {
|
||||
return closeTagNameState;
|
||||
} else {
|
||||
return baseState;
|
||||
}
|
||||
}
|
||||
function tagNameState(type, stream, state) {
|
||||
if (type == "word") {
|
||||
state.tagName = stream.current();
|
||||
setStyle = "tag";
|
||||
return attrState;
|
||||
} else {
|
||||
setStyle = "error";
|
||||
return tagNameState;
|
||||
}
|
||||
}
|
||||
function closeTagNameState(type, stream, state) {
|
||||
if (type == "word") {
|
||||
var tagName = stream.current();
|
||||
if (state.context && state.context.tagName != tagName &&
|
||||
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
||||
popContext(state);
|
||||
if (state.context && state.context.tagName == tagName) {
|
||||
setStyle = "tag";
|
||||
return closeState;
|
||||
} else {
|
||||
setStyle = "tag error";
|
||||
return closeStateErr;
|
||||
}
|
||||
} else {
|
||||
setStyle = "error";
|
||||
return closeStateErr;
|
||||
}
|
||||
}
|
||||
|
||||
function closeState(type, _stream, state) {
|
||||
if (type != "endTag") {
|
||||
setStyle = "error";
|
||||
return closeState;
|
||||
}
|
||||
popContext(state);
|
||||
return baseState;
|
||||
}
|
||||
function closeStateErr(type, stream, state) {
|
||||
setStyle = "error";
|
||||
return closeState(type, stream, state);
|
||||
}
|
||||
|
||||
function attrState(type, _stream, state) {
|
||||
if (type == "word") {
|
||||
setStyle = "attribute";
|
||||
return attrEqState;
|
||||
} else if (type == "endTag" || type == "selfcloseTag") {
|
||||
var tagName = state.tagName, tagStart = state.tagStart;
|
||||
state.tagName = state.tagStart = null;
|
||||
if (type == "selfcloseTag" ||
|
||||
Kludges.autoSelfClosers.hasOwnProperty(tagName)) {
|
||||
maybePopContext(state, tagName);
|
||||
} else {
|
||||
maybePopContext(state, tagName);
|
||||
state.context = new Context(state, tagName, tagStart == state.indented);
|
||||
}
|
||||
return baseState;
|
||||
}
|
||||
setStyle = "error";
|
||||
return attrState;
|
||||
}
|
||||
function attrEqState(type, stream, state) {
|
||||
if (type == "equals") return attrValueState;
|
||||
if (!Kludges.allowMissing) setStyle = "error";
|
||||
return attrState(type, stream, state);
|
||||
}
|
||||
function attrValueState(type, stream, state) {
|
||||
if (type == "string") return attrContinuedState;
|
||||
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;}
|
||||
setStyle = "error";
|
||||
return attrState(type, stream, state);
|
||||
}
|
||||
function attrContinuedState(type, stream, state) {
|
||||
if (type == "string") return attrContinuedState;
|
||||
return attrState(type, stream, state);
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {tokenize: inText,
|
||||
state: baseState,
|
||||
indented: 0,
|
||||
tagName: null, tagStart: null,
|
||||
context: null};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (!state.tagName && stream.sol())
|
||||
state.indented = stream.indentation();
|
||||
|
||||
if (stream.eatSpace()) return null;
|
||||
type = null;
|
||||
var style = state.tokenize(stream, state);
|
||||
if ((style || type) && style != "comment") {
|
||||
setStyle = null;
|
||||
state.state = state.state(type || style, stream, state);
|
||||
if (setStyle)
|
||||
style = setStyle == "error" ? style + " error" : setStyle;
|
||||
}
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter, fullLine) {
|
||||
var context = state.context;
|
||||
// Indent multi-line strings (e.g. css).
|
||||
if (state.tokenize.isInAttribute) {
|
||||
if (state.tagStart == state.indented)
|
||||
return state.stringStartCol + 1;
|
||||
else
|
||||
return state.indented + indentUnit;
|
||||
}
|
||||
if (context && context.noIndent) return CodeMirror.Pass;
|
||||
if (state.tokenize != inTag && state.tokenize != inText)
|
||||
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
|
||||
// Indent the starts of attribute names.
|
||||
if (state.tagName) {
|
||||
if (multilineTagIndentPastTag)
|
||||
return state.tagStart + state.tagName.length + 2;
|
||||
else
|
||||
return state.tagStart + indentUnit * multilineTagIndentFactor;
|
||||
}
|
||||
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
||||
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
|
||||
if (tagAfter && tagAfter[1]) { // Closing tag spotted
|
||||
while (context) {
|
||||
if (context.tagName == tagAfter[2]) {
|
||||
context = context.prev;
|
||||
break;
|
||||
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
|
||||
context = context.prev;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (tagAfter) { // Opening tag spotted
|
||||
while (context) {
|
||||
var grabbers = Kludges.contextGrabbers[context.tagName];
|
||||
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
|
||||
context = context.prev;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (context && !context.startOfLine)
|
||||
context = context.prev;
|
||||
if (context) return context.indent + indentUnit;
|
||||
else return 0;
|
||||
},
|
||||
|
||||
electricInput: /<\/[\s\w:]+>$/,
|
||||
blockCommentStart: "<!--",
|
||||
blockCommentEnd: "-->",
|
||||
|
||||
configuration: parserConfig.htmlMode ? "html" : "xml",
|
||||
helperType: parserConfig.htmlMode ? "html" : "xml"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/xml", "xml");
|
||||
CodeMirror.defineMIME("application/xml", "xml");
|
||||
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
|
||||
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,223 @@
|
||||
function clearHistory(){
|
||||
window.history.pushState('VMs', 'Title', '/VMs');
|
||||
}
|
||||
|
||||
function ordinal_suffix_of(i) {
|
||||
var j = i % 10,
|
||||
k = i % 100;
|
||||
if (j == 1 && k != 11) {
|
||||
return i + "st";
|
||||
}
|
||||
if (j == 2 && k != 12) {
|
||||
return i + "nd";
|
||||
}
|
||||
if (j == 3 && k != 13) {
|
||||
return i + "rd";
|
||||
}
|
||||
return i + "th";
|
||||
}
|
||||
|
||||
function slideUpRows($tr, onComplete) {
|
||||
$tr.not('tr,table').finish().fadeOut('fast');
|
||||
|
||||
$tr.filter('tr').find('td').finish().each(function(){
|
||||
$(this)
|
||||
.data("paddingstate", $(this).css(["paddingTop", "paddingBottom"]))
|
||||
.animate({ paddingTop: 0, paddingBottom: 0 }, { duration: 'fast' })
|
||||
.wrapInner('<div />')
|
||||
.children()
|
||||
.slideUp("fast", function() {
|
||||
$(this).contents().unwrap();
|
||||
$tr.filter('tr').hide();
|
||||
if ($.isFunction(onComplete)) {
|
||||
onComplete();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$tr.filter('table').finish().each(function(){
|
||||
$(this)
|
||||
.wrap('<div style="overflow: hidden"></div>')
|
||||
.parent()
|
||||
.slideUp("fast", function() {
|
||||
$(this).contents().unwrap();
|
||||
$tr.filter('table').hide();
|
||||
if ($.isFunction(onComplete)) {
|
||||
onComplete();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
function slideDownRows($tr, onComplete) {
|
||||
$tr.filter(':hidden').not('tr,table').finish().fadeIn('fast');
|
||||
|
||||
$tr.filter('tr:hidden').find('td').finish().each(function(){
|
||||
$(this)
|
||||
.wrapInner('<div style="display: none"></div>')
|
||||
.animate($(this).data("paddingstate"), { duration: 'fast', start: function() { $tr.filter('tr:hidden').show(); } })
|
||||
.children()
|
||||
.slideDown("fast", function() {
|
||||
$(this).contents().unwrap();
|
||||
if ($.isFunction(onComplete)) {
|
||||
onComplete();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$tr.filter('table:hidden').finish().each(function(){
|
||||
$(this)
|
||||
.wrap('<div style="display: none; overflow: hidden"></div>')
|
||||
.show()
|
||||
.parent()
|
||||
.slideDown("fast", function() {
|
||||
$(this).contents().unwrap();
|
||||
if ($.isFunction(onComplete)) {
|
||||
onComplete();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
function toggleRows(what, val, what2, onComplete) {
|
||||
if (val == 1) {
|
||||
slideDownRows($('.'+what), onComplete);
|
||||
if (arguments.length > 2) {
|
||||
slideUpRows($('.'+what2), onComplete);
|
||||
}
|
||||
} else {
|
||||
slideUpRows($('.'+what), onComplete);
|
||||
if (arguments.length > 2) {
|
||||
slideDownRows($('.'+what2), onComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updatePrefixLabels(category) {
|
||||
$("#form_content table:data(category)").filter(function() {
|
||||
return $(this).data('category') == category;
|
||||
}).each(function (index) {
|
||||
var oldprefix = $(this).data('prefix');
|
||||
var newprefix = oldprefix;
|
||||
|
||||
if (index > 0) {
|
||||
newprefix = ordinal_suffix_of(index+1);
|
||||
}
|
||||
|
||||
$(this)
|
||||
.data('prefix', newprefix)
|
||||
.find('tr').each(function() {
|
||||
var $td = $(this).children('td').first();
|
||||
|
||||
var old = $td.text();
|
||||
if (oldprefix && old.indexOf(oldprefix) === 0) {
|
||||
old = old.replace(oldprefix + ' ', '');
|
||||
}
|
||||
|
||||
$td.text(newprefix + ' ' + old);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindSectionEvents(category) {
|
||||
var $Filtered = $("#form_content table:data(category)").filter(function(index) {
|
||||
return $(this).data('category') == category;
|
||||
});
|
||||
|
||||
var count = $Filtered.length;
|
||||
|
||||
$Filtered.each(function(index) {
|
||||
var $table = $(this);
|
||||
var config = $(this).data();
|
||||
var boolAdd = false;
|
||||
var boolDelete = false;
|
||||
|
||||
if (!config.hasOwnProperty('multiple')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean old sections
|
||||
var $first_td = $(this).find('td').first();
|
||||
|
||||
// delete section
|
||||
if (!config.hasOwnProperty('minimum') || parseInt(config.minimum) < (index+1)) {
|
||||
if ($first_td.children('.sectionbutton.remove').length === 0) {
|
||||
var $el_remove = $('<div class="sectionbutton remove" title="Remove ' + config.prefix + ' ' + category.replace('_', ' ') + '"><i class="fa fa-minus-circle red"></i></div>').one('click', clickRemoveSection);
|
||||
$first_td.append($el_remove);
|
||||
}
|
||||
boolDelete = true;
|
||||
} else {
|
||||
$first_td.children('.sectionbutton.remove').fadeOut('fast', function() { $(this).remove(); });
|
||||
}
|
||||
|
||||
// add section (can only add from the last section)
|
||||
if ((index+1) == count) {
|
||||
if (!config.hasOwnProperty('maximum') || parseInt(config.maximum) > (index+1)) {
|
||||
if ($first_td.children('.sectionbutton.add').length === 0) {
|
||||
var $el_add = $('<div class="sectionbutton add" title="Add another ' + category.replace('_', ' ') + '"><i class="fa fa-plus-circle green"></i></div>').one('click', clickAddSection);
|
||||
$first_td.append($el_add);
|
||||
}
|
||||
boolAdd = true;
|
||||
} else {
|
||||
$first_td.children('.sectionbutton.add').fadeOut('fast', function() { $(this).remove(); });
|
||||
}
|
||||
}
|
||||
|
||||
if (boolDelete || boolAdd) {
|
||||
$table.addClass("multiple");
|
||||
if ($first_td.children('.sectiontab').length === 0) {
|
||||
var $el_tab = $('<div class="sectiontab"></div>');
|
||||
$first_td.append($el_tab);
|
||||
}
|
||||
} else {
|
||||
$first_td.children('.sectionbutton, .sectiontab').fadeOut('fast', function() {
|
||||
$(this).remove();
|
||||
$table.removeClass("multiple");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function clickAddSection() {
|
||||
var $table = $(this).closest('table');
|
||||
$(this).remove();
|
||||
var newindex = new Date().getTime();
|
||||
var config = $table.data();
|
||||
|
||||
var $template = $($('<div/>').loadTemplate($("#tmpl" + config.category)).html().replace(/{{INDEX}}/g, newindex));
|
||||
|
||||
$template
|
||||
.data({
|
||||
multiple: true,
|
||||
category: config.category,
|
||||
index: newindex,
|
||||
minimum: config.minimum,
|
||||
maximum: config.maximum
|
||||
})
|
||||
.find('tr').hide()
|
||||
.find("input[data-pickroot]").fileTreeAttach();
|
||||
|
||||
$table.after($template);
|
||||
|
||||
updatePrefixLabels(config.category);
|
||||
bindSectionEvents(config.category);
|
||||
|
||||
$el_showable = $template.find('tr').not("." + (isVMAdvancedMode() ? 'basic' : 'advanced'));
|
||||
|
||||
slideDownRows($el_showable);
|
||||
}
|
||||
|
||||
function clickRemoveSection() {
|
||||
var $table = $(this).closest('table');
|
||||
var category = $table.data('category');
|
||||
|
||||
slideUpRows($table.find('tr'), function() {
|
||||
$table.remove();
|
||||
updatePrefixLabels(category);
|
||||
bindSectionEvents(category);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,681 @@
|
||||
/*!
|
||||
* Bootstrap v3.2.0 (http://getbootstrap.com)
|
||||
* Copyright 2011-2014 Twitter, Inc.
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
*/
|
||||
|
||||
button::-moz-focus-inner,
|
||||
input::-moz-focus-inner {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
}
|
||||
textarea {
|
||||
overflow: auto;
|
||||
width: 475px;
|
||||
}
|
||||
* {
|
||||
-webkit-box-sizing: inherit;
|
||||
-moz-box-sizing: inherit;
|
||||
box-sizing: inherit;
|
||||
}
|
||||
*:before,
|
||||
*:after {
|
||||
-webkit-box-sizing: inherit;
|
||||
-moz-box-sizing: inherit;
|
||||
box-sizing: inherit;
|
||||
}
|
||||
.btn {
|
||||
display: inline-block;
|
||||
margin-bottom: 0;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
background-image: none;
|
||||
border: 1px solid transparent;
|
||||
white-space: nowrap;
|
||||
padding: 6px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.42857143;
|
||||
border-radius: 4px;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.btn:focus,
|
||||
.btn:active:focus,
|
||||
.btn.active:focus {
|
||||
outline: thin dotted;
|
||||
outline: 5px auto -webkit-focus-ring-color;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.btn:hover,
|
||||
.btn:focus {
|
||||
color: #333333;
|
||||
text-decoration: none;
|
||||
}
|
||||
.btn:active,
|
||||
.btn.active {
|
||||
outline: 0;
|
||||
background-image: none;
|
||||
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
}
|
||||
.btn.disabled,
|
||||
.btn[disabled],
|
||||
fieldset[disabled] .btn {
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
opacity: 0.65;
|
||||
filter: alpha(opacity=65);
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
.btn-default {
|
||||
color: #333333;
|
||||
background-color: #E1E1E1;
|
||||
border-color: #cccccc;
|
||||
}
|
||||
.btn-default:hover,
|
||||
.btn-default:focus,
|
||||
.btn-default:active,
|
||||
.btn-default.active,
|
||||
.open > .dropdown-toggle.btn-default {
|
||||
color: #333333;
|
||||
background-color: #e6e6e6;
|
||||
border-color: #adadad;
|
||||
}
|
||||
.btn-default:active,
|
||||
.btn-default.active,
|
||||
.open > .dropdown-toggle.btn-default {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-default.disabled,
|
||||
.btn-default[disabled],
|
||||
fieldset[disabled] .btn-default,
|
||||
.btn-default.disabled:hover,
|
||||
.btn-default[disabled]:hover,
|
||||
fieldset[disabled] .btn-default:hover,
|
||||
.btn-default.disabled:focus,
|
||||
.btn-default[disabled]:focus,
|
||||
fieldset[disabled] .btn-default:focus,
|
||||
.btn-default.disabled:active,
|
||||
.btn-default[disabled]:active,
|
||||
fieldset[disabled] .btn-default:active,
|
||||
.btn-default.disabled.active,
|
||||
.btn-default[disabled].active,
|
||||
fieldset[disabled] .btn-default.active {
|
||||
background-color: #ffffff;
|
||||
border-color: #cccccc;
|
||||
}
|
||||
.btn-default .badge {
|
||||
color: #ffffff;
|
||||
background-color: #333333;
|
||||
}
|
||||
.btn-dynamix {
|
||||
color: inherit;
|
||||
background-color: inherit;
|
||||
border-color: inherit;
|
||||
}
|
||||
.btn-dynamix:hover,
|
||||
.btn-dynamix:focus,
|
||||
.btn-dynamix:active,
|
||||
.btn-dynamix.active,
|
||||
.open > .dropdown-toggle.btn-dynamix {
|
||||
color: inherit;
|
||||
background-color: inherit;
|
||||
border-color: inherit;
|
||||
}
|
||||
.btn-dynamix:active,
|
||||
.btn-dynamix.active,
|
||||
.open > .dropdown-toggle.btn-dynamix {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-dynamix.disabled,
|
||||
.btn-dynamix[disabled],
|
||||
fieldset[disabled] .btn-dynamix,
|
||||
.btn-dynamix.disabled:hover,
|
||||
.btn-dynamix[disabled]:hover,
|
||||
fieldset[disabled] .btn-dynamix:hover,
|
||||
.btn-dynamix.disabled:focus,
|
||||
.btn-dynamix[disabled]:focus,
|
||||
fieldset[disabled] .btn-dynamix:focus,
|
||||
.btn-dynamix.disabled:active,
|
||||
.btn-dynamix[disabled]:active,
|
||||
fieldset[disabled] .btn-dynamix:active,
|
||||
.btn-dynamix.disabled.active,
|
||||
.btn-dynamix[disabled].active,
|
||||
fieldset[disabled] .btn-dynamix.active {
|
||||
background-color: inherit;
|
||||
border-color: inherit;
|
||||
}
|
||||
.btn-dynamix .badge {
|
||||
color: inherit;
|
||||
background-color: inherit;
|
||||
}
|
||||
.btn-primary {
|
||||
color: #ffffff;
|
||||
background-color: #428bca;
|
||||
border-color: #357ebd;
|
||||
}
|
||||
.btn-primary:hover,
|
||||
.btn-primary:focus,
|
||||
.btn-primary:active,
|
||||
.btn-primary.active,
|
||||
.open > .dropdown-toggle.btn-primary {
|
||||
color: #ffffff;
|
||||
background-color: #3071a9;
|
||||
border-color: #285e8e;
|
||||
}
|
||||
.btn-primary:active,
|
||||
.btn-primary.active,
|
||||
.open > .dropdown-toggle.btn-primary {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-primary.disabled,
|
||||
.btn-primary[disabled],
|
||||
fieldset[disabled] .btn-primary,
|
||||
.btn-primary.disabled:hover,
|
||||
.btn-primary[disabled]:hover,
|
||||
fieldset[disabled] .btn-primary:hover,
|
||||
.btn-primary.disabled:focus,
|
||||
.btn-primary[disabled]:focus,
|
||||
fieldset[disabled] .btn-primary:focus,
|
||||
.btn-primary.disabled:active,
|
||||
.btn-primary[disabled]:active,
|
||||
fieldset[disabled] .btn-primary:active,
|
||||
.btn-primary.disabled.active,
|
||||
.btn-primary[disabled].active,
|
||||
fieldset[disabled] .btn-primary.active {
|
||||
background-color: #428bca;
|
||||
border-color: #357ebd;
|
||||
}
|
||||
.btn-primary .badge {
|
||||
color: #428bca;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.btn-success {
|
||||
color: #ffffff;
|
||||
background-color: #5cb85c;
|
||||
border-color: #4cae4c;
|
||||
}
|
||||
.btn-success:hover,
|
||||
.btn-success:focus,
|
||||
.btn-success:active,
|
||||
.btn-success.active,
|
||||
.open > .dropdown-toggle.btn-success {
|
||||
color: #ffffff;
|
||||
background-color: #449d44;
|
||||
border-color: #398439;
|
||||
}
|
||||
.btn-success:active,
|
||||
.btn-success.active,
|
||||
.open > .dropdown-toggle.btn-success {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-success.disabled,
|
||||
.btn-success[disabled],
|
||||
fieldset[disabled] .btn-success,
|
||||
.btn-success.disabled:hover,
|
||||
.btn-success[disabled]:hover,
|
||||
fieldset[disabled] .btn-success:hover,
|
||||
.btn-success.disabled:focus,
|
||||
.btn-success[disabled]:focus,
|
||||
fieldset[disabled] .btn-success:focus,
|
||||
.btn-success.disabled:active,
|
||||
.btn-success[disabled]:active,
|
||||
fieldset[disabled] .btn-success:active,
|
||||
.btn-success.disabled.active,
|
||||
.btn-success[disabled].active,
|
||||
fieldset[disabled] .btn-success.active {
|
||||
background-color: #5cb85c;
|
||||
border-color: #4cae4c;
|
||||
}
|
||||
.btn-success .badge {
|
||||
color: #5cb85c;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.btn-info {
|
||||
color: #ffffff;
|
||||
background-color: #5bc0de;
|
||||
border-color: #46b8da;
|
||||
}
|
||||
.btn-info:hover,
|
||||
.btn-info:focus,
|
||||
.btn-info:active,
|
||||
.btn-info.active,
|
||||
.open > .dropdown-toggle.btn-info {
|
||||
color: #ffffff;
|
||||
background-color: #31b0d5;
|
||||
border-color: #269abc;
|
||||
}
|
||||
.btn-info:active,
|
||||
.btn-info.active,
|
||||
.open > .dropdown-toggle.btn-info {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-info.disabled,
|
||||
.btn-info[disabled],
|
||||
fieldset[disabled] .btn-info,
|
||||
.btn-info.disabled:hover,
|
||||
.btn-info[disabled]:hover,
|
||||
fieldset[disabled] .btn-info:hover,
|
||||
.btn-info.disabled:focus,
|
||||
.btn-info[disabled]:focus,
|
||||
fieldset[disabled] .btn-info:focus,
|
||||
.btn-info.disabled:active,
|
||||
.btn-info[disabled]:active,
|
||||
fieldset[disabled] .btn-info:active,
|
||||
.btn-info.disabled.active,
|
||||
.btn-info[disabled].active,
|
||||
fieldset[disabled] .btn-info.active {
|
||||
background-color: #5bc0de;
|
||||
border-color: #46b8da;
|
||||
}
|
||||
.btn-info .badge {
|
||||
color: #5bc0de;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.btn-warning {
|
||||
color: #ffffff;
|
||||
background-color: #f0ad4e;
|
||||
border-color: #eea236;
|
||||
}
|
||||
.btn-warning:hover,
|
||||
.btn-warning:focus,
|
||||
.btn-warning:active,
|
||||
.btn-warning.active,
|
||||
.open > .dropdown-toggle.btn-warning {
|
||||
color: #ffffff;
|
||||
background-color: #ec971f;
|
||||
border-color: #d58512;
|
||||
}
|
||||
.btn-warning:active,
|
||||
.btn-warning.active,
|
||||
.open > .dropdown-toggle.btn-warning {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-warning.disabled,
|
||||
.btn-warning[disabled],
|
||||
fieldset[disabled] .btn-warning,
|
||||
.btn-warning.disabled:hover,
|
||||
.btn-warning[disabled]:hover,
|
||||
fieldset[disabled] .btn-warning:hover,
|
||||
.btn-warning.disabled:focus,
|
||||
.btn-warning[disabled]:focus,
|
||||
fieldset[disabled] .btn-warning:focus,
|
||||
.btn-warning.disabled:active,
|
||||
.btn-warning[disabled]:active,
|
||||
fieldset[disabled] .btn-warning:active,
|
||||
.btn-warning.disabled.active,
|
||||
.btn-warning[disabled].active,
|
||||
fieldset[disabled] .btn-warning.active {
|
||||
background-color: #f0ad4e;
|
||||
border-color: #eea236;
|
||||
}
|
||||
.btn-warning .badge {
|
||||
color: #f0ad4e;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.btn-danger {
|
||||
color: #ffffff;
|
||||
background-color: #d9534f;
|
||||
border-color: #d43f3a;
|
||||
}
|
||||
.btn-danger:hover,
|
||||
.btn-danger:focus,
|
||||
.btn-danger:active,
|
||||
.btn-danger.active,
|
||||
.open > .dropdown-toggle.btn-danger {
|
||||
color: #ffffff;
|
||||
background-color: #c9302c;
|
||||
border-color: #ac2925;
|
||||
}
|
||||
.btn-danger:active,
|
||||
.btn-danger.active,
|
||||
.open > .dropdown-toggle.btn-danger {
|
||||
background-image: none;
|
||||
}
|
||||
.btn-danger.disabled,
|
||||
.btn-danger[disabled],
|
||||
fieldset[disabled] .btn-danger,
|
||||
.btn-danger.disabled:hover,
|
||||
.btn-danger[disabled]:hover,
|
||||
fieldset[disabled] .btn-danger:hover,
|
||||
.btn-danger.disabled:focus,
|
||||
.btn-danger[disabled]:focus,
|
||||
fieldset[disabled] .btn-danger:focus,
|
||||
.btn-danger.disabled:active,
|
||||
.btn-danger[disabled]:active,
|
||||
fieldset[disabled] .btn-danger:active,
|
||||
.btn-danger.disabled.active,
|
||||
.btn-danger[disabled].active,
|
||||
fieldset[disabled] .btn-danger.active {
|
||||
background-color: #d9534f;
|
||||
border-color: #d43f3a;
|
||||
}
|
||||
.btn-danger .badge {
|
||||
color: #d9534f;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.btn-link {
|
||||
color: #428bca;
|
||||
font-weight: normal;
|
||||
cursor: pointer;
|
||||
border-radius: 0;
|
||||
}
|
||||
.btn-link,
|
||||
.btn-link:active,
|
||||
.btn-link[disabled],
|
||||
fieldset[disabled] .btn-link {
|
||||
background-color: transparent;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
.btn-link,
|
||||
.btn-link:hover,
|
||||
.btn-link:focus,
|
||||
.btn-link:active {
|
||||
border-color: transparent;
|
||||
}
|
||||
.btn-link:hover,
|
||||
.btn-link:focus {
|
||||
color: #2a6496;
|
||||
text-decoration: underline;
|
||||
background-color: transparent;
|
||||
}
|
||||
.btn-link[disabled]:hover,
|
||||
fieldset[disabled] .btn-link:hover,
|
||||
.btn-link[disabled]:focus,
|
||||
fieldset[disabled] .btn-link:focus {
|
||||
color: #777777;
|
||||
text-decoration: none;
|
||||
}
|
||||
.btn-lg,
|
||||
.btn-group-lg > .btn {
|
||||
padding: 10px 16px;
|
||||
font-size: 18px;
|
||||
line-height: 1.33;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.btn-sm,
|
||||
.btn-group-sm > .btn {
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border-radius: 3px;
|
||||
min-width: 13px;
|
||||
}
|
||||
.btn-xs,
|
||||
.btn-group-xs > .btn {
|
||||
padding: 1px 5px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.btn-block {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
.btn-block + .btn-block {
|
||||
margin-top: 5px;
|
||||
}
|
||||
input[type="submit"].btn-block,
|
||||
input[type="reset"].btn-block,
|
||||
input[type="button"].btn-block {
|
||||
width: 100%;
|
||||
}
|
||||
.btn-group,
|
||||
.btn-group-vertical {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.btn-group > .btn,
|
||||
.btn-group-vertical > .btn {
|
||||
position: relative;
|
||||
float: left;
|
||||
}
|
||||
.btn-group > .btn:hover,
|
||||
.btn-group-vertical > .btn:hover,
|
||||
.btn-group > .btn:focus,
|
||||
.btn-group-vertical > .btn:focus,
|
||||
.btn-group > .btn:active,
|
||||
.btn-group-vertical > .btn:active,
|
||||
.btn-group > .btn.active,
|
||||
.btn-group-vertical > .btn.active {
|
||||
z-index: 2;
|
||||
}
|
||||
.btn-group > .btn:focus,
|
||||
.btn-group-vertical > .btn:focus {
|
||||
outline: 0;
|
||||
}
|
||||
.btn-group .btn + .btn,
|
||||
.btn-group .btn + .btn-group,
|
||||
.btn-group .btn-group + .btn,
|
||||
.btn-group .btn-group + .btn-group {
|
||||
margin-left: -1px;
|
||||
}
|
||||
.btn-toolbar {
|
||||
margin-left: -5px;
|
||||
}
|
||||
.btn-toolbar .btn-group,
|
||||
.btn-toolbar .input-group {
|
||||
float: left;
|
||||
}
|
||||
.btn-toolbar > .btn,
|
||||
.btn-toolbar > .btn-group,
|
||||
.btn-toolbar > .input-group {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
|
||||
border-radius: 0;
|
||||
}
|
||||
.btn-group > .btn:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
.btn-group > .btn:first-child:not(:last-child):not(.dropdown-toggle) {
|
||||
border-bottom-right-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
.btn-group > .btn:last-child:not(:first-child),
|
||||
.btn-group > .dropdown-toggle:not(:first-child) {
|
||||
border-bottom-left-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
.btn-group > .btn-group {
|
||||
float: left;
|
||||
}
|
||||
.btn-group > .btn-group:not(:first-child):not(:last-child) > .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
.btn-group > .btn-group:first-child > .btn:last-child,
|
||||
.btn-group > .btn-group:first-child > .dropdown-toggle {
|
||||
border-bottom-right-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
.btn-group > .btn-group:last-child > .btn:first-child {
|
||||
border-bottom-left-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
.btn-group .dropdown-toggle:active,
|
||||
.btn-group.open .dropdown-toggle {
|
||||
outline: 0;
|
||||
}
|
||||
.btn-group > .btn + .dropdown-toggle {
|
||||
padding-left: 8px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
.btn-group > .btn-lg + .dropdown-toggle {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
}
|
||||
.btn-group.open .dropdown-toggle {
|
||||
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
}
|
||||
.btn-group.open .dropdown-toggle.btn-link {
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
.btn .caret {
|
||||
margin-left: 0;
|
||||
}
|
||||
.btn-lg .caret {
|
||||
border-width: 5px 5px 0;
|
||||
border-bottom-width: 0;
|
||||
}
|
||||
.dropup .btn-lg .caret {
|
||||
border-width: 0 5px 5px;
|
||||
}
|
||||
.btn-group-vertical > .btn,
|
||||
.btn-group-vertical > .btn-group,
|
||||
.btn-group-vertical > .btn-group > .btn {
|
||||
display: block;
|
||||
float: none;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
.btn-group-vertical > .btn-group > .btn {
|
||||
float: none;
|
||||
}
|
||||
.btn-group-vertical > .btn + .btn,
|
||||
.btn-group-vertical > .btn + .btn-group,
|
||||
.btn-group-vertical > .btn-group + .btn,
|
||||
.btn-group-vertical > .btn-group + .btn-group {
|
||||
margin-top: -1px;
|
||||
margin-left: 0;
|
||||
}
|
||||
.btn-group-vertical > .btn:not(:first-child):not(:last-child) {
|
||||
border-radius: 0;
|
||||
}
|
||||
.btn-group-vertical > .btn:first-child:not(:last-child) {
|
||||
border-top-right-radius: 4px;
|
||||
border-bottom-right-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
.btn-group-vertical > .btn:last-child:not(:first-child) {
|
||||
border-bottom-left-radius: 4px;
|
||||
border-top-right-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
.btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
.btn-group-vertical > .btn-group:first-child:not(:last-child) > .btn:last-child,
|
||||
.btn-group-vertical > .btn-group:first-child:not(:last-child) > .dropdown-toggle {
|
||||
border-bottom-right-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
.btn-group-vertical > .btn-group:last-child:not(:first-child) > .btn:first-child {
|
||||
border-top-right-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
.btn-group-justified {
|
||||
display: table;
|
||||
width: 100%;
|
||||
table-layout: fixed;
|
||||
border-collapse: separate;
|
||||
}
|
||||
.btn-group-justified > .btn,
|
||||
.btn-group-justified > .btn-group {
|
||||
float: none;
|
||||
display: table-cell;
|
||||
width: 1%;
|
||||
}
|
||||
.btn-group-justified > .btn-group .btn {
|
||||
width: 100%;
|
||||
}
|
||||
.btn-group-justified > .btn-group .dropdown-menu {
|
||||
left: auto;
|
||||
}
|
||||
.clearfix:before,
|
||||
.clearfix:after,
|
||||
.btn-toolbar:before,
|
||||
.btn-toolbar:after,
|
||||
.btn-group-vertical > .btn-group:before,
|
||||
.btn-group-vertical > .btn-group:after {
|
||||
content: " ";
|
||||
display: table;
|
||||
}
|
||||
.clearfix:after,
|
||||
.btn-toolbar:after,
|
||||
.btn-group-vertical > .btn-group:after {
|
||||
clear: both;
|
||||
}
|
||||
table.tablesorter.kvm{margin-top:-24px;border-spacing:0 3px;}
|
||||
table.tablesorter.kvm tr:nth-child(odd){background:none;}
|
||||
table.tablesorter.kvm tr:nth-child(even){background:none;}
|
||||
table.tablesorter.kvm th:first-child{width:3%;text-align:center;}
|
||||
table.tablesorter.kvm td:first-child{width:3%;text-align:center;}
|
||||
table.tablesorter.kvm th:nth-child(2){text-align:left;}
|
||||
table.tablesorter.kvm td:nth-child(2){text-align:left;}
|
||||
table.tablesorter.kvm th:nth-child(3){width:5%;text-align:center;}
|
||||
table.tablesorter.kvm td:nth-child(3){width:5%;text-align:center;}
|
||||
table.tablesorter.kvm th:nth-child(4){width:9%;text-align:center;}
|
||||
table.tablesorter.kvm td:nth-child(4){width:9%;text-align:center;}
|
||||
table.tablesorter.kvm th:nth-child(5){width:9%;text-align:center;}
|
||||
table.tablesorter.kvm td:nth-child(5){width:9%;text-align:center;}
|
||||
table.tablesorter.kvm th:nth-child(6){width:9%;text-align:center;}
|
||||
table.tablesorter.kvm td:nth-child(6){width:9%;text-align:center;}
|
||||
table.tablesorter.kvm th:nth-child(7){width:80px;text-align:center;}
|
||||
table.tablesorter.kvm td:nth-child(7){width:80px;text-align:left;}
|
||||
table.tablesorter.kvm th:nth-child(8){width:24px;text-align:center;}
|
||||
table.tablesorter.kvm td:nth-child(8){width:24px;text-align:center;}
|
||||
table.tablesorter.kvm tr>td+td+td{width:9%;white-space:nowrap;}
|
||||
table.tablesorter.kvm-span{margin-top:-20px;}
|
||||
table.tablesorter.kvm-span tr:nth-child(odd){background:none;}
|
||||
table.tablesorter.kvm-span tr:nth-child(even){background:none;}
|
||||
table.tablesorter.dominfo{margin-top: 5px;}
|
||||
table.tablesorter.dominfo{margin-left:48px;}
|
||||
table.tablesorter.domdisk{margin-top: 5px;}
|
||||
table.tablesorter.domdisk{margin-left:72px;}
|
||||
table.tablesorter.domdisk th:first-child{width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk td:first-child{width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(2){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(2){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(3){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(3){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(4){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(4){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(5){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(5){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(6){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(6){width:9%;text-align:left;}
|
||||
table.tablesorter.domdisk tr>td+td+td{width:9%;white-space:nowrap;}
|
||||
table.tablesorter.domdisk td:last-child{width:96px;padding:0;}
|
||||
table.tablesorter.domsnap{margin-top: 5px;}
|
||||
table.tablesorter.domsnap{margin-left:72px;}
|
||||
table.tablesorter.domsnap th:first-child{width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap td:first-child{width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap th:nth-child(2){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap td:nth-child(2){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap th:nth-child(3){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap td:nth-child(3){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap th:nth-child(4){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap td:nth-child(4){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap th:nth-child(5){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap td:nth-child(5){width:9%;text-align:left;}
|
||||
table.tablesorter.domsnap tr>td+td+td{width:9%;white-space:nowrap;}
|
||||
table.tablesorter.domsnap td:last-child{width:96px;padding:0;}
|
||||
|
||||
.iconstatus {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
bottom: -4px;
|
||||
right: -4px;
|
||||
font-size: 1.2em;
|
||||
text-shadow: 0 0 2px #FFF;
|
||||
}
|
||||
.iconstatus.started {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
img.started{opacity: 1.0;}
|
||||
img.stopped{opacity: 0.3;}
|
||||
img.paused{opacity: 1.0;}
|
||||
.started{color:#009900;}
|
||||
.stopped{color:#EF3D47;}
|
||||
.paused{color:#F0DD33;}
|
||||
|
||||
.log{cursor:zoom-in;}
|
||||
@@ -0,0 +1,990 @@
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
require_once('/usr/local/emhttp/webGui/include/Helpers.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt_helpers.php');
|
||||
|
||||
$arrValidMachineTypes = getValidMachineTypes();
|
||||
$arrValidGPUDevices = getValidGPUDevices();
|
||||
$arrValidAudioDevices = getValidAudioDevices();
|
||||
$arrValidOtherDevices = getValidOtherDevices();
|
||||
$arrValidUSBDevices = getValidUSBDevices();
|
||||
$arrValidDiskDrivers = getValidDiskDrivers();
|
||||
$arrValidKeyMaps = getValidKeyMaps();
|
||||
$arrValidBridges = getNetworkBridges();
|
||||
$strCPUModel = getHostCPUModel();
|
||||
|
||||
$arrOperatingSystems = [
|
||||
'windows' => 'Windows 8.1 / 2012',
|
||||
'windows7' => 'Windows 7 / 2008',
|
||||
'windowsxp' => 'Windows XP / 2003',
|
||||
'linux' => 'Linux',
|
||||
'arch' => 'Arch',
|
||||
'centos' => 'CentOS',
|
||||
'chromeos' => 'ChromeOS',
|
||||
'coreos' => 'CoreOS',
|
||||
'debian' => 'Debian',
|
||||
'fedora' => 'Fedora',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'openelec' => 'OpenELEC',
|
||||
'opensuse' => 'OpenSUSE',
|
||||
'redhat' => 'RedHat',
|
||||
'scientific' => 'Scientific',
|
||||
'slackware' => 'Slackware',
|
||||
'steamos' => 'SteamOS',
|
||||
'ubuntu' => 'Ubuntu'
|
||||
];
|
||||
|
||||
$arrConfigDefaults = [
|
||||
'template' => [
|
||||
'name' => 'Custom',
|
||||
'icon' => 'windows.png'
|
||||
],
|
||||
'domain' => [
|
||||
'persistent' => 1,
|
||||
'uuid' => $lv->domain_generate_uuid(),
|
||||
'clock' => 'localtime',
|
||||
'arch' => 'x86_64',
|
||||
'machine' => 'pc',
|
||||
'mem' => 512 * 1024,
|
||||
'maxmem' => 512 * 1024,
|
||||
'password' => '',
|
||||
'cpumode' => 'host-passthrough',
|
||||
'vcpus' => 1,
|
||||
'vcpu' => [0],
|
||||
'hyperv' => 1,
|
||||
'ovmf' => 0
|
||||
],
|
||||
'media' => [
|
||||
'cdrom' => '',
|
||||
'drivers' => $domain_cfg['VIRTIOISO']
|
||||
],
|
||||
'disk' => [
|
||||
[
|
||||
'new' => '',
|
||||
'size' => '',
|
||||
'driver' => 'raw',
|
||||
'dev' => 'hda'
|
||||
]
|
||||
],
|
||||
'gpu' => [
|
||||
[
|
||||
'id' => 'vnc',
|
||||
'keymap' => 'en-us'
|
||||
]
|
||||
],
|
||||
'audio' => [
|
||||
[
|
||||
'id' => ''
|
||||
]
|
||||
],
|
||||
'pci' => [],
|
||||
'nic' => [
|
||||
[
|
||||
'network' => $domain_bridge,
|
||||
'mac' => $lv->generate_random_mac_addr()
|
||||
]
|
||||
],
|
||||
'usb' => [],
|
||||
'shares' => [
|
||||
[
|
||||
'source' => '',
|
||||
'target' => ''
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// If we are editing a existing VM load it's existing configuration details
|
||||
$arrExistingConfig = (!empty($_GET['uuid']) ? domain_to_config($_GET['uuid']) : []);
|
||||
|
||||
// Active config for this page
|
||||
$arrConfig = array_replace_recursive($arrConfigDefaults, $arrExistingConfig);
|
||||
|
||||
// Add any custom metadata field defaults (e.g. os)
|
||||
if (empty($arrConfig['template']['os'])) {
|
||||
$arrConfig['template']['os'] = ($arrConfig['domain']['clock'] == 'localtime' ? 'windows' : 'linux');
|
||||
}
|
||||
|
||||
$boolRunning = (!empty($arrConfig['domain']['state']) && $arrConfig['domain']['state'] == 'running');
|
||||
|
||||
|
||||
if (array_key_exists('createvm', $_POST)) {
|
||||
//DEBUG
|
||||
file_put_contents('/tmp/debug_libvirt_postparams.txt', print_r($_POST, true));
|
||||
file_put_contents('/tmp/debug_libvirt_newxml.xml', $lv->config_to_xml($_POST));
|
||||
|
||||
$tmp = $lv->domain_new($_POST);
|
||||
if (!$tmp){
|
||||
$arrResponse = ['error' => $lv->get_last_error()];
|
||||
} else {
|
||||
$arrResponse = ['success' => true];
|
||||
|
||||
// Fire off the vnc popup if available
|
||||
$res = $lv->get_domain_by_name($_POST['domain']['name']);
|
||||
$vncport = $lv->domain_get_vnc_port($res);
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
|
||||
if ($vncport > 0) {
|
||||
$vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host='.$var['IPADDR'].'&port='.$wsport;
|
||||
$arrResponse['vncurl'] = $vnc;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($arrResponse);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (array_key_exists('updatevm', $_POST)) {
|
||||
//DEBUG
|
||||
file_put_contents('/tmp/debug_libvirt_postparams.txt', print_r($_POST, true));
|
||||
file_put_contents('/tmp/debug_libvirt_updatexml.xml', $lv->config_to_xml($_POST));
|
||||
|
||||
// Backup xml for existing domain in ram
|
||||
$strOldXML = '';
|
||||
$boolOldAutoStart = false;
|
||||
$res = $lv->domain_get_name_by_uuid($_POST['domain']['uuid']);
|
||||
if ($res) {
|
||||
$strOldXML = $lv->domain_get_xml($res);
|
||||
$boolOldAutoStart = $lv->domain_get_autostart($res);
|
||||
|
||||
//DEBUG
|
||||
file_put_contents('/tmp/debug_libvirt_oldxml.xml', $strOldXML);
|
||||
}
|
||||
|
||||
// Remove existing domain
|
||||
$lv->domain_undefine($res);
|
||||
|
||||
// Save new domain
|
||||
$tmp = $lv->domain_new($_POST);
|
||||
if (!$tmp){
|
||||
$strLastError = $lv->get_last_error();
|
||||
|
||||
// Failure -- try to restore existing domain
|
||||
$tmp = $lv->domain_define($strOldXML);
|
||||
if ($tmp) $lv->domain_set_autostart($tmp, $boolOldAutoStart);
|
||||
|
||||
$arrResponse = ['error' => $strLastError];
|
||||
} else {
|
||||
$lv->domain_set_autostart($tmp, $_POST['domain']['autostart'] == 1);
|
||||
|
||||
$arrResponse = ['success' => true];
|
||||
}
|
||||
|
||||
echo json_encode($arrResponse);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<style type="text/css">
|
||||
.four label {
|
||||
float: left;
|
||||
display: table-cell;
|
||||
width: 25%;
|
||||
}
|
||||
.four label:nth-child(4n+4) {
|
||||
float: none;
|
||||
clear: both;
|
||||
}
|
||||
.mac_generate {
|
||||
cursor: pointer;
|
||||
margin-left: -8px;
|
||||
color: #08C;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<input type="hidden" name="domain[persistent]" value="<?=$arrConfig['domain']['persistent']?>">
|
||||
<input type="hidden" name="domain[uuid]" value="<?=$arrConfig['domain']['uuid']?>">
|
||||
<input type="hidden" name="domain[clock]" id="domain_clock" value="<?=$arrConfig['domain']['clock']?>">
|
||||
<input type="hidden" name="domain[arch]" value="<?=$arrConfig['domain']['arch']?>">
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Operating System:</td>
|
||||
<td>
|
||||
<select name="template[os]" id="domain_os" class="narrow" title="define the base OS">
|
||||
<?php mk_dropdown_options($arrOperatingSystems, $arrConfig['template']['os']); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<blockquote class="inline_help">
|
||||
<p>Select Windows for any Microsoft operating systems</p>
|
||||
</blockquote>
|
||||
|
||||
<table>
|
||||
<tr class="advanced">
|
||||
<td>CPU Mode:</td>
|
||||
<td>
|
||||
<select name="domain[cpumode]" title="define type of cpu presented to this vm">
|
||||
<?php mk_dropdown_options(['host-passthrough' => 'Host Passthrough (' . $strCPUModel . ')', 'emulated' => 'Emulated (QEMU64)'], $arrConfig['domain']['cpumode']); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>There are two CPU modes available to choose:</p>
|
||||
<p>
|
||||
<b>Host Passthrough</b><br>
|
||||
With this mode, the CPU visible to the guest should be exactly the same as the host CPU even in the aspects that libvirt does not understand. For the best possible performance, use this setting.
|
||||
</p>
|
||||
<p>
|
||||
<b>Emulated</b><br>
|
||||
If you are having difficulties with Host Passthrough mode, you can try the emulated mode which doesn't expose the guest to host-based CPU features. This may impact the performance of your VM.
|
||||
</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>CPUs:</td>
|
||||
<td>
|
||||
<div class="textarea four">
|
||||
<?php
|
||||
for ($i = 0; $i < $maxcpu; $i++) {
|
||||
$extra = '';
|
||||
if (in_array($i, $arrConfig['domain']['vcpu'])) {
|
||||
$extra .= ' checked="checked"';
|
||||
if (count($arrConfig['domain']['vcpu']) == 1) {
|
||||
$extra .= ' disabled="disabled"';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<label for="vcpu<?=$i?>"><input type="checkbox" name="domain[vcpu][]" class="domain_vcpu" id="vcpu<?=$i?>" value="<?=$i?>" <?=$extra;?>/> Core <?=$i?></label>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>By default, VMs created will be pinned to physical CPU cores to improve performance. From this view, you can adjust which actual CPU cores a VM will be pinned (minimum 1).</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Initial Memory:</td>
|
||||
<td>
|
||||
<select name="domain[mem]" id="domain_mem" class="narrow" title="define the amount memory">
|
||||
<?php
|
||||
echo mk_option($arrConfig['domain']['mem'], 128 * 1024, '128 MB');
|
||||
echo mk_option($arrConfig['domain']['mem'], 256 * 1024, '256 MB');
|
||||
for ($i = 1; $i <= ($maxmem*2); $i++) {
|
||||
$label = ($i * 512) . ' MB';
|
||||
$value = $i * 512 * 1024;
|
||||
echo mk_option($arrConfig['domain']['mem'], $value, $label);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td class="advanced">Max Memory:</td>
|
||||
<td class="advanced">
|
||||
<select name="domain[maxmem]" id="domain_maxmem" class="narrow" title="define the maximum amount of memory">
|
||||
<?php
|
||||
echo mk_option($arrConfig['domain']['maxmem'], 128 * 1024, '128 MB');
|
||||
echo mk_option($arrConfig['domain']['maxmem'], 256 * 1024, '256 MB');
|
||||
for ($i = 1; $i <= ($maxmem*2); $i++) {
|
||||
$label = ($i * 512) . ' MB';
|
||||
$value = $i * 512 * 1024;
|
||||
echo mk_option($arrConfig['domain']['maxmem'], $value, $label);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="basic">
|
||||
<blockquote class="inline_help">
|
||||
<p>Select how much memory to allocate to the VM at boot.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>Select how much memory to allocate to the VM at boot (cannot be more than Max. Mem).</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr class="advanced">
|
||||
<td>Machine:</td>
|
||||
<td>
|
||||
<select name="domain[machine]" class="narrow" id="domain_machine" title="Select the machine model. i440fx will work for most. Q35 for a newer machine model with PCIE">
|
||||
<?php mk_dropdown_options($arrValidMachineTypes, $arrConfig['domain']['machine']); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>The machine type option primarily affects the success some users may have with various hardware and GPU pass through. For more information on the various QEMU machine types, see these links:</p>
|
||||
<a href="http://wiki.qemu.org/Documentation/Platforms/PC" target="_blank">http://wiki.qemu.org/Documentation/Platforms/PC</a><br>
|
||||
<a href="http://wiki.qemu.org/Features/Q35" target="_blank">http://wiki.qemu.org/Features/Q35</a><br>
|
||||
<p>As a rule of thumb, try to get your configuration working with i440fx first and if that fails, try adjusting to Q35 to see if that changes anything.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr class="advanced">
|
||||
<td>BIOS:</td>
|
||||
<td>
|
||||
<select name="domain[ovmf]" id="domain_ovmf" class="narrow" title="Select the BIOS. SeaBIOS will work for most. OVMF requires a UEFI-compatable OS (e.g. Windows 8/2012, newer Linux distros) and if using graphics device passthrough it too needs UEFI" <? if (!empty($arrConfig['domain']['state'])) echo 'disabled="disabled"'; ?>>
|
||||
<?php
|
||||
echo mk_option($arrConfig['domain']['ovmf'], '0', 'SeaBIOS');
|
||||
|
||||
if (file_exists('/usr/share/qemu/ovmf-x64/OVMF-pure-efi.fd')) {
|
||||
echo mk_option($arrConfig['domain']['ovmf'], '1', 'OVMF');
|
||||
} else {
|
||||
echo mk_option('', '0', 'OVMF (Not Available)', 'disabled="disabled"');
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php if (!empty($arrConfig['domain']['state'])) { ?>
|
||||
<input type="hidden" name="domain[ovmf]" value="<?=$arrConfig['domain']['ovmf']?>">
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>
|
||||
<b>SeaBIOS</b><br>
|
||||
is the default virtual BIOS used to create virtual machines and is compatible with all guest operating systems (Windows, Linux, etc.).
|
||||
</p>
|
||||
<p>
|
||||
<b>OVMF</b><br>
|
||||
(Open Virtual Machine Firmware) adds support for booting VMs using UEFI, but virtual machine guests must also support UEFI. Assigning graphics devices to a OVMF-based virtual machine requires that the graphics device also support UEFI.
|
||||
</p>
|
||||
<p>
|
||||
Once a VM is created this setting cannot be adjusted.
|
||||
</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<table class="domain_os windows">
|
||||
<tr class="advanced">
|
||||
<td>Hyper-V:</td>
|
||||
<td>
|
||||
<select name="domain[hyperv]" id="hyperv" class="narrow" title="Hyperv tweaks for Windows. Don't select if trying to passthrough Nvidia card">
|
||||
<?php mk_dropdown_options(['No', 'Yes'], $arrConfig['domain']['hyperv']); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="domain_os windows">
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>Exposes the guest to hyper-v extensions for Microsoft operating systems. Set to "Yes" by default, but set to "No" automatically if an NVIDIA-based GPU is assigned to the guest (but can be user-toggled back to "Yes").</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>OS Install ISO:</td>
|
||||
<td>
|
||||
<input type="text" data-pickcloseonfile="true" data-pickfilter="iso" data-pickroot="<?=$domain_cfg['MEDIADIR']?>" name="media[cdrom]" value="<?=$arrConfig['media']['cdrom']?>" placeholder="Click and Select cdrom image to install operating system">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<blockquote class="inline_help">
|
||||
<p>Select the virtual CD-ROM (ISO) that contains the installation media for your operating system. Clicking this field displays a list of ISOs found in the directory specified on the Settings page.</p>
|
||||
</blockquote>
|
||||
|
||||
<table class="domain_os windows">
|
||||
<tr class="advanced">
|
||||
<td><a href="https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download" target="_blank">VirtIO Drivers ISO:</a></td>
|
||||
<td>
|
||||
<input type="text" data-pickcloseonfile="true" data-pickfilter="iso" data-pickroot="<?=$domain_cfg['MEDIADIR']?>" name="media[drivers]" value="<?=$arrConfig['media']['drivers']?>" placeholder="Download, Click and Select virtio drivers image">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="domain_os windows">
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>Specify the virtual CD-ROM (ISO) that contains the VirtIO Windows drivers as provided by the Fedora Project. Download the latest ISO from here: <a href="https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download" target="_blank">https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download</a></p>
|
||||
<p>When installing Windows, you will reach a step where no disk devices will be found. There is an option to browse for drivers on that screen. Click browse and locate the additional CD-ROM in the menu. Inside there will be various folders for the different versions of Windows. Open the folder for the version of Windows you are installing and then select the AMD64 subfolder inside (even if you are on an Intel system, select AMD64). Three drivers will be found. Select them all, click next, and the vDisks you have assigned will appear.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<? foreach ($arrConfig['disk'] as $i => $arrDisk) {
|
||||
$strLabel = ($i > 0) ? appendOrdinalSuffix($i + 1) : 'Primary';
|
||||
|
||||
?>
|
||||
<table data-category="vDisk" data-multiple="true" data-minimum="1" data-maximum="24" data-index="<?=$i?>" data-prefix="<?=$strLabel?>">
|
||||
<tr>
|
||||
<td>vDisk Location:</td>
|
||||
<td>
|
||||
<input type="text" data-pickcloseonfile="true" data-pickfolders="true" data-pickfilter="img,qcow,qcow2" data-pickroot="/mnt/" name="disk[<?=$i?>][new]" class="disk" id="disk_<?=$i?>" value="<?=$arrDisk['new']?>" placeholder="Separate sub-folder and image will be created based on Name">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="disk_file_options">
|
||||
<td>vDisk Size:</td>
|
||||
<td>
|
||||
<input type="text" name="disk[<?=$i?>][size]" value="<?=$arrDisk['size']?>" placeholder="e.g. 10M, 1G, 10G...">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="advanced disk_file_options">
|
||||
<td>vDisk Type:</td>
|
||||
<td>
|
||||
<select name="disk[<?=$i?>][driver]" class="narrow" title="type of storage image">
|
||||
<?php mk_dropdown_options($arrValidDiskDrivers, $arrDisk['driver']); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<input type="hidden" name="disk[<?=$i?>][dev]" value="<?=$arrDisk['dev']?>">
|
||||
</table>
|
||||
<?php if ($i == 0) { ?>
|
||||
<blockquote class="inline_help">
|
||||
<p>
|
||||
<b>vDisk Location</b><br>
|
||||
Specify a path to a user share in which you wish to store the VM or specify an existing vDisk. The primary vDisk will store the operating system for your VM.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>vDisk Size</b><br>
|
||||
Specify a number followed by a letter. M for megabytes, G for gigabytes.
|
||||
</p>
|
||||
|
||||
<p class="advanced">
|
||||
<b>vDisk Type</b><br>
|
||||
Select RAW for best performance. QCOW2 implementation is still in development.
|
||||
</p>
|
||||
|
||||
<p>Additional devices can be added/removed by clicking the symbols to the left.</p>
|
||||
</blockquote>
|
||||
<? } ?>
|
||||
<? } ?>
|
||||
<script type="text/html" id="tmplvDisk">
|
||||
<table>
|
||||
<tr>
|
||||
<td>vDisk Location:</td>
|
||||
<td>
|
||||
<input type="text" data-pickcloseonfile="true" data-pickfolders="true" data-pickfilter="img,qcow,qcow2" data-pickroot="/mnt/" name="disk[{{INDEX}}][new]" class="disk" id="disk_{{INDEX}}" value="" placeholder="Separate sub-folder and image will be created based on Name">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="disk_file_options">
|
||||
<td>vDisk Size:</td>
|
||||
<td>
|
||||
<input type="text" name="disk[{{INDEX}}][size]" value="" placeholder="e.g. 10M, 1G, 10G...">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="advanced disk_file_options">
|
||||
<td>vDisk Type:</td>
|
||||
<td>
|
||||
<select name="disk[{{INDEX}}][driver]" class="narrow" title="type of storage image">
|
||||
<?php mk_dropdown_options($arrValidDiskDrivers, ''); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<input type="hidden" name="disk[{{INDEX}}][dev]" value="">
|
||||
</table>
|
||||
</script>
|
||||
|
||||
|
||||
<? foreach ($arrConfig['shares'] as $i => $arrShare) {
|
||||
$strLabel = ($i > 0) ? appendOrdinalSuffix($i + 1) : '';
|
||||
|
||||
?>
|
||||
<table class="domain_os other" data-category="Share" data-multiple="true" data-minimum="1" data-index="<?=$i?>" data-prefix="<?=$strLabel?>">
|
||||
<tr class="advanced">
|
||||
<td>unRAID Share:</td>
|
||||
<td>
|
||||
<input type="text" data-pickfolders="true" data-pickfilter="NO_FILES_FILTER" data-pickroot="/mnt/" value="<?=$arrShare['source']?>" name="shares[<?=$i?>][source]" placeholder="e.g. /mnt/user/..." title="path of unRAID share" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="advanced">
|
||||
<td>unRAID Mount tag:</td>
|
||||
<td>
|
||||
<input type="text" value="<?=$arrShare['target']?>" name="shares[<?=$i?>][target]" placeholder="e.g. shares (name of mount tag inside vm)" title="mount tag inside vm" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php if ($i == 0) { ?>
|
||||
<div class="domain_os other">
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>
|
||||
<b>unRAID Share</b><br>
|
||||
Used to create a VirtFS mapping to a Linux-based guest. Specify the path on the host here.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>unRAID Mount tag</b><br>
|
||||
Specify the mount tag that you will use for mounting the VirtFS share inside the VM. See this page for how to do this on a Linux-based guest: <a href="http://wiki.qemu.org/Documentation/9psetup" target="_blank">http://wiki.qemu.org/Documentation/9psetup</a>
|
||||
</p>
|
||||
|
||||
<p>Additional devices can be added/removed by clicking the symbols to the left.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<? } ?>
|
||||
<? } ?>
|
||||
<script type="text/html" id="tmplShare">
|
||||
<table class="domain_os other">
|
||||
<tr class="advanced">
|
||||
<td>unRAID Share:</td>
|
||||
<td>
|
||||
<input type="text" data-pickfolders="true" data-pickfilter="NO_FILES_FILTER" data-pickroot="/mnt/" value="" name="shares[{{INDEX}}][source]" placeholder="e.g. /mnt/user/..." title="path of unRAID share" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="advanced">
|
||||
<td>unRAID Mount tag:</td>
|
||||
<td>
|
||||
<input type="text" value="" name="shares[{{INDEX}}][target]" placeholder="e.g. shares (name of mount tag inside vm)" title="mount tag inside vm" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</script>
|
||||
|
||||
|
||||
<? foreach ($arrConfig['gpu'] as $i => $arrGPU) {
|
||||
$strLabel = ($i > 0) ? appendOrdinalSuffix($i + 1) : '';
|
||||
|
||||
?>
|
||||
<table data-category="Graphics_Card" data-multiple="true" data-minimum="1" data-maximum="<?=count($arrValidGPUDevices)+1?>" data-index="<?=$i?>" data-prefix="<?=$strLabel?>">
|
||||
<tr>
|
||||
<td>Graphics Card:</td>
|
||||
<td>
|
||||
<select name="gpu[<?=$i?>][id]" class="gpu narrow">
|
||||
<?php
|
||||
if ($i == 0) {
|
||||
// Only the first video card can be VNC
|
||||
echo mk_option($arrGPU['id'], 'vnc', 'VNC');
|
||||
} else {
|
||||
echo mk_option($arrGPU['id'], '', 'None');
|
||||
}
|
||||
|
||||
foreach($arrValidGPUDevices as $arrDev) {
|
||||
echo mk_option($arrGPU['id'], $arrDev['id'], $arrDev['name']);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<? if ($i == 0) { ?>
|
||||
<tr class="vncpassword">
|
||||
<td>VNC Password:</td>
|
||||
<td><input type="password" name="domain[password]" title="password for VNC" placeholder="Password for VNC (optional)" /></td>
|
||||
</tr>
|
||||
<tr class="advanced vnckeymap">
|
||||
<td>VNC Keyboard:</td>
|
||||
<td>
|
||||
<select name="gpu[<?=$i?>][keymap]" title="keyboard for VNC">
|
||||
<?php mk_dropdown_options($arrValidKeyMaps, $arrGPU['keymap']); ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<? } ?>
|
||||
</table>
|
||||
<?php if ($i == 0) { ?>
|
||||
<blockquote class="inline_help">
|
||||
<p>
|
||||
<b>Graphics Card</b><br>
|
||||
If you wish to assign a graphics card to the VM, select it from this list, otherwise leave it set to VNC.
|
||||
</p>
|
||||
|
||||
<p class="vncpassword">
|
||||
<b>VNC Password</b><br>
|
||||
If you wish to require a password to connect to the VM over a VNC connection, specify one here.
|
||||
</p>
|
||||
|
||||
<p class="advanced vnckeymap">
|
||||
<b>VNC Keyboard</b><br>
|
||||
If you wish to assign a different keyboard layout to use for a VNC connection, specify one here.
|
||||
</p>
|
||||
|
||||
<p>Additional devices can be added/removed by clicking the symbols to the left.</p>
|
||||
</blockquote>
|
||||
<? } ?>
|
||||
<? } ?>
|
||||
<script type="text/html" id="tmplGraphics_Card">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Graphics Card:</td>
|
||||
<td>
|
||||
<select name="gpu[{{INDEX}}][id]" class="gpu narrow">
|
||||
<?php
|
||||
echo mk_option('', '', 'None');
|
||||
|
||||
foreach($arrValidGPUDevices as $arrDev) {
|
||||
echo mk_option('', $arrDev['id'], $arrDev['name']);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</script>
|
||||
|
||||
|
||||
<? foreach ($arrConfig['audio'] as $i => $arrAudio) {
|
||||
$strLabel = ($i > 0) ? appendOrdinalSuffix($i + 1) : '';
|
||||
|
||||
?>
|
||||
<table data-category="Sound_Card" data-multiple="true" data-minimum="1" data-maximum="<?=count($arrValidAudioDevices)?>" data-index="<?=$i?>" data-prefix="<?=$strLabel?>">
|
||||
<tr>
|
||||
<td>Sound Card:</td>
|
||||
<td>
|
||||
<select name="audio[<?=$i?>][id]" class="audio narrow">
|
||||
<?php
|
||||
echo mk_option($arrAudio['id'], '', 'None');
|
||||
|
||||
foreach($arrValidAudioDevices as $arrDev) {
|
||||
echo mk_option($arrAudio['id'], $arrDev['id'], $arrDev['name']);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php if ($i == 0) { ?>
|
||||
<blockquote class="inline_help">
|
||||
<p>Select a sound device to assign to your VM. Most modern GPUs have a built-in audio device, but you can also select the on-board audio device(s) if present.</p>
|
||||
<p>Additional devices can be added/removed by clicking the symbols to the left.</p>
|
||||
</blockquote>
|
||||
<? } ?>
|
||||
<? } ?>
|
||||
<script type="text/html" id="tmplSound_Card">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Sound Card:</td>
|
||||
<td>
|
||||
<select name="audio[{{INDEX}}][id]" class="audio narrow">
|
||||
<?php
|
||||
foreach($arrValidAudioDevices as $arrDev) {
|
||||
echo mk_option('', $arrDev['id'], $arrDev['name']);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</script>
|
||||
|
||||
|
||||
<? foreach ($arrConfig['nic'] as $i => $arrNic) {
|
||||
$strLabel = ($i > 0) ? appendOrdinalSuffix($i + 1) : '';
|
||||
|
||||
?>
|
||||
<table data-category="Network" data-multiple="true" data-minimum="1" data-index="<?=$i?>" data-prefix="<?=$strLabel?>">
|
||||
<tr class="advanced">
|
||||
<td>Network MAC:</td>
|
||||
<td>
|
||||
<input type="text" name="nic[<?=$i?>][mac]" class="narrow" value="<?=$arrNic['mac']?>" title="random mac, you can supply your own" /> <i class="fa fa-refresh mac_generate" title="re-generate random mac address"></i>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="advanced">
|
||||
<td>Network Bridge:</td>
|
||||
<td>
|
||||
<select name="nic[<?=$i?>][network]">
|
||||
<?php
|
||||
foreach ($arrValidBridges as $strBridge) {
|
||||
echo mk_option($arrNic['network'], $strBridge, $strBridge);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php if ($i == 0) { ?>
|
||||
<div class="advanced">
|
||||
<blockquote class="inline_help">
|
||||
<p>
|
||||
<b>Network MAC</b><br>
|
||||
By default, a random MAC address will be assigned here that conforms to the standards for virtual network interface controllers. You can manually adjust this if desired.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Network Bridge</b><br>
|
||||
The default libvirt managed network bridge (virbr0) will be used, otherwise you may specify an alternative name for a private network bridge to the host.
|
||||
</p>
|
||||
|
||||
<p>Additional devices can be added/removed by clicking the symbols to the left.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<? } ?>
|
||||
<? } ?>
|
||||
<script type="text/html" id="tmplNetwork">
|
||||
<table>
|
||||
<tr class="advanced">
|
||||
<td>Network MAC:</td>
|
||||
<td>
|
||||
<input type="text" name="nic[{{INDEX}}][mac]" class="narrow" value="" title="random mac, you can supply your own" /> <i class="fa fa-refresh mac_generate" title="re-generate random mac address"></i>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="advanced">
|
||||
<td>Network Bridge:</td>
|
||||
<td>
|
||||
<select name="nic[{{INDEX}}][network]">
|
||||
<?php
|
||||
foreach ($arrValidBridges as $strBridge) {
|
||||
echo mk_option($domain_bridge, $strBridge, $strBridge);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</script>
|
||||
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>USB Devices:</td>
|
||||
<td>
|
||||
<div class="textarea">
|
||||
<?php
|
||||
if (!empty($arrValidUSBDevices)) {
|
||||
foreach($arrValidUSBDevices as $i => $arrDev) {
|
||||
?>
|
||||
<label for="usb<?=$i?>"><input type="checkbox" name="usb[]" id="usb<?=$i?>" value="<?=$arrDev['id']?>" <?php if (count(array_filter($arrConfig['usb'], function($arr) use ($arrDev) { return ($arr['id'] == $arrDev['id']); }))) echo 'checked="checked"'; ?>/> <?=$arrDev['name']?></label><br/>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
echo "<i>None available</i>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<blockquote class="inline_help">
|
||||
<p>If you wish to assign any USB devices to your guest, you can select them from this list.<br>
|
||||
NOTE: USB hotplug support is not yet implemented, so devices must be attached before the VM is started to use them.</p>
|
||||
</blockquote>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<? if (!$boolRunning) { ?>
|
||||
<? if (!empty($arrConfig['domain']['name'])) { ?>
|
||||
<input type="hidden" name="updatevm" value="1" />
|
||||
<input type="button" value="Update" busyvalue="Updating..." readyvalue="Update" id="btnSubmit" />
|
||||
<? } else { ?>
|
||||
<label for="domain_start"><input type="checkbox" name="domain[startnow]" id="domain_start" value="1" checked="checked"/> Start VM after creation</label>
|
||||
<br>
|
||||
<input type="hidden" name="createvm" value="1" />
|
||||
<input type="button" value="Create" busyvalue="Creating..." readyvalue="Create" id="btnSubmit" />
|
||||
<? } ?>
|
||||
<input type="button" value="Cancel" id="btnCancel" />
|
||||
<? } else { ?>
|
||||
<input type="button" value="Done" id="btnCancel" />
|
||||
<? } ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<blockquote class="inline_help">
|
||||
<p>Click Create to generate the vDisks and return to the Virtual Machines page where your new VM will be created.</p>
|
||||
</blockquote>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var OS2ImageMap = {<?php
|
||||
$arrItems = array();
|
||||
foreach ($arrOperatingSystems as $key => $value) {
|
||||
$arrItems[] = "'$key':'{$key}.png'";
|
||||
}
|
||||
echo implode(',', $arrItems);
|
||||
?>};
|
||||
|
||||
$(function() {
|
||||
var initComplete = false;
|
||||
|
||||
$("#form_content #domain_mem").change(function changeMemEvent() {
|
||||
$("#domain_maxmem").val($(this).val());
|
||||
});
|
||||
|
||||
$("#form_content .domain_vcpu").change(function changeVCPUEvent() {
|
||||
var $cores = $(".domain_vcpu:checked");
|
||||
|
||||
if ($cores.length == 1) {
|
||||
$cores.prop("disabled", true);
|
||||
} else {
|
||||
$(".domain_vcpu").prop("disabled", false);
|
||||
}
|
||||
});
|
||||
|
||||
$("#form_content #domain_maxmem").change(function changeMaxMemEvent() {
|
||||
if (parseFloat($(this).val()) < parseFloat($("#domain_mem").val())) {
|
||||
$("#domain_mem").val($(this).val());
|
||||
}
|
||||
});
|
||||
|
||||
$("#form_content").on("change keyup", ".disk", function changeDiskEvent() {
|
||||
var $input = $(this);
|
||||
var config = $input.data();
|
||||
|
||||
if (config.hasOwnProperty('pickfilter')) {
|
||||
var $other_sections = $input.closest('table').find('.disk_file_options');
|
||||
|
||||
$.get("/plugins/dynamix.vm.manager/VMajax.php?action=file-info&file=" + encodeURIComponent($input.val()), function( info ) {
|
||||
if (info.isfile || info.isblock) {
|
||||
slideUpRows($other_sections);
|
||||
|
||||
$other_sections.filter('.advanced').removeClass('advanced').addClass('wasadvanced');
|
||||
|
||||
$input.attr('name', $input.attr('name').replace('new', 'image'));
|
||||
} else {
|
||||
$other_sections.filter('.wasadvanced').removeClass('wasadvanced').addClass('advanced');
|
||||
|
||||
slideDownRows($other_sections.not(isVMAdvancedMode() ? '.basic' : '.advanced'));
|
||||
|
||||
$input.attr('name', $input.attr('name').replace('image', 'new'));
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
});
|
||||
|
||||
$("#form_content").on("change", ".gpu", function changeGPUEvent() {
|
||||
var myvalue = $(this).val();
|
||||
var mylabel = $(this).children('option:selected').text();
|
||||
|
||||
$vnc_sections = $('.vncpassword,.vnckeymap');
|
||||
if ($(".gpu option[value='vnc']:selected").length) {
|
||||
$vnc_sections.filter('.wasadvanced').removeClass('wasadvanced').addClass('advanced');
|
||||
slideDownRows($vnc_sections.not(isVMAdvancedMode() ? '.basic' : '.advanced'));
|
||||
} else {
|
||||
slideUpRows($vnc_sections);
|
||||
$vnc_sections.filter('.advanced').removeClass('advanced').addClass('wasadvanced');
|
||||
}
|
||||
|
||||
if (mylabel.indexOf('NVIDIA ') > -1) {
|
||||
$("#hyperv").val(0).change();
|
||||
}
|
||||
|
||||
$(".gpu").not(this).each(function () {
|
||||
if (myvalue == $(this).val()) {
|
||||
$(this).prop("selectedIndex", 0).change();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#form_content input[data-pickroot]").fileTreeAttach();
|
||||
|
||||
$("#form_content").on("click", ".mac_generate", function generateMac() {
|
||||
var $input = $(this).prev('input');
|
||||
|
||||
$.get("/plugins/dynamix.vm.manager/VMajax.php?action=generate-mac", function( data ) {
|
||||
if (data.mac) {
|
||||
$input.val(data.mac);
|
||||
}
|
||||
}, "json");
|
||||
});
|
||||
|
||||
$("#form_content #btnSubmit").click(function frmSubmit() {
|
||||
var $button = $(this);
|
||||
var $form = $('#domain_template').closest('form');
|
||||
|
||||
//TODO: form validation
|
||||
|
||||
$form.find('input').prop('disabled', false); // enable all inputs otherwise they wont post
|
||||
|
||||
var postdata = $form.serialize().replace(/'/g,"%27");
|
||||
|
||||
$form.find('input').prop('disabled', true);
|
||||
$button.val($button.attr('busyvalue'));
|
||||
|
||||
$.post("/plugins/dynamix.vm.manager/templates/<?=basename(__FILE__)?>", postdata, function( data ) {
|
||||
if (data.success) {
|
||||
if (data.vncurl) {
|
||||
window.open(data.vncurl, '_blank', 'scrollbars=yes,resizable=yes');
|
||||
}
|
||||
done();
|
||||
}
|
||||
if (data.error) {
|
||||
swal({title:"VM creation error",text:data.error,type:"error"});
|
||||
$form.find('input').prop('disabled', false);
|
||||
$("#form_content .domain_vcpu").change(); // restore the cpu checkbox disabled states
|
||||
<? if (!empty($arrConfig['domain']['state'])) echo '$(\'#domain_ovmf\').prop(\'disabled\', true); // restore bios disabled state' . "\n"; ?>
|
||||
$button.val($button.attr('readyvalue'));
|
||||
}
|
||||
}, "json");
|
||||
});
|
||||
|
||||
$("#form_content #btnCancel").click(done);
|
||||
|
||||
|
||||
// Fire events below once upon showing page
|
||||
$("#form_content table[data-category]").each(function () {
|
||||
var category = $(this).data('category');
|
||||
|
||||
updatePrefixLabels(category);
|
||||
bindSectionEvents(category);
|
||||
});
|
||||
|
||||
$("#form_content #domain_os").change(function changeOSEvent() {
|
||||
var os_casted = ($(this).val().indexOf('windows') == -1 ? 'other' : 'windows');
|
||||
|
||||
if (initComplete && !$('#template_img').attr('touched')) {
|
||||
var vmicon = OS2ImageMap[$(this).val()] || OS2ImageMap[os_casted];
|
||||
$('#template_icon').val(vmicon);
|
||||
$('#template_img').prop('src', '/plugins/dynamix.vm.manager/templates/images/' + vmicon);
|
||||
}
|
||||
|
||||
slideUpRows($('.domain_os').not($('.' + os_casted)));
|
||||
slideDownRows($('.domain_os.' + os_casted).not(isVMAdvancedMode() ? '.basic' : '.advanced'));
|
||||
|
||||
if (initComplete) {
|
||||
if (os_casted == 'windows') {
|
||||
$('#domain_clock').val('localtime');
|
||||
$("#domain_machine option").each(function(){
|
||||
if ($(this).val().indexOf('i440fx') != -1) {
|
||||
$('#domain_machine').val($(this).val());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#domain_clock').val('utc');
|
||||
$("#domain_machine option").each(function(){
|
||||
if ($(this).val().indexOf('q35') != -1) {
|
||||
$('#domain_machine').val($(this).val());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).change(); // Fire now too!
|
||||
|
||||
if ($(".gpu option[value='vnc']:selected").length) {
|
||||
$('.vncpassword,.vnckeymap').not(isVMAdvancedMode() ? '.basic' : '.advanced').show();
|
||||
} else {
|
||||
$('.vncpassword,.vnckeymap').hide();
|
||||
}
|
||||
|
||||
$("#form_content .disk").not("[value='']")
|
||||
.attr('name', function(){ return $(this).attr('name').replace('new', 'image'); })
|
||||
.closest('table').find('.disk_file_options').hide()
|
||||
.filter('.advanced').removeClass('advanced').addClass('wasadvanced');
|
||||
|
||||
initComplete = true;
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,198 @@
|
||||
<?PHP
|
||||
/* Copyright 2015, Lime Technology
|
||||
* Copyright 2015, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
require_once('/usr/local/emhttp/webGui/include/Helpers.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt.php');
|
||||
require_once('/usr/local/emhttp/plugins/dynamix.vm.manager/classes/libvirt_helpers.php');
|
||||
|
||||
$strXML = '';
|
||||
$strUUID = '';
|
||||
$boolRunning = false;
|
||||
|
||||
// If we are editing a existing VM load it's existing configuration details
|
||||
if (!empty($_GET['uuid'])) {
|
||||
$strUUID = $_GET['uuid'];
|
||||
$res = $lv->domain_get_name_by_uuid($strUUID);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
|
||||
$strXML = $lv->domain_get_xml($res);
|
||||
$boolRunning = ($lv->domain_state_translate($dom['state']) == 'running');
|
||||
}
|
||||
|
||||
|
||||
if (array_key_exists('createvm', $_POST)) {
|
||||
//DEBUG
|
||||
file_put_contents('/tmp/debug_libvirt_postparams.txt', print_r($_POST, true));
|
||||
file_put_contents('/tmp/debug_libvirt_newxml.xml', $_POST['xmldesc']);
|
||||
|
||||
$tmp = $lv->domain_define($_POST['xmldesc']);
|
||||
if (!$tmp){
|
||||
$arrResponse = ['error' => $lv->get_last_error()];
|
||||
} else {
|
||||
$lv->domain_set_autostart($tmp, $_POST['domain']['autostart'] == 1);
|
||||
|
||||
$arrResponse = ['success' => true];
|
||||
}
|
||||
|
||||
echo json_encode($arrResponse);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (array_key_exists('updatevm', $_POST)) {
|
||||
//DEBUG
|
||||
file_put_contents('/tmp/debug_libvirt_postparams.txt', print_r($_POST, true));
|
||||
file_put_contents('/tmp/debug_libvirt_updatexml.xml', $_POST['xmldesc']);
|
||||
|
||||
// Backup xml for existing domain in ram
|
||||
$strOldXML = '';
|
||||
$boolOldAutoStart = false;
|
||||
$res = $lv->domain_get_name_by_uuid($_POST['domain']['uuid']);
|
||||
if ($res) {
|
||||
$strOldXML = $lv->domain_get_xml($res);
|
||||
$boolOldAutoStart = $lv->domain_get_autostart($res);
|
||||
|
||||
//DEBUG
|
||||
file_put_contents('/tmp/debug_libvirt_oldxml.xml', $strOldXML);
|
||||
}
|
||||
|
||||
// Remove existing domain
|
||||
$lv->domain_undefine($res);
|
||||
|
||||
// Save new domain
|
||||
$tmp = $lv->domain_define($_POST['xmldesc']);
|
||||
if (!$tmp){
|
||||
$strLastError = $lv->get_last_error();
|
||||
|
||||
// Failure -- try to restore existing domain
|
||||
$tmp = $lv->domain_define($strOldXML);
|
||||
if ($tmp) $lv->domain_set_autostart($tmp, $boolOldAutoStart);
|
||||
|
||||
$arrResponse = ['error' => $strLastError];
|
||||
} else {
|
||||
$lv->domain_set_autostart($tmp, $_POST['domain']['autostart'] == 1);
|
||||
|
||||
$arrResponse = ['success' => true];
|
||||
}
|
||||
|
||||
echo json_encode($arrResponse);
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<link rel="stylesheet" href="/plugins/dynamix.vm.manager/scripts/codemirror/lib/codemirror.css">
|
||||
<link rel="stylesheet" href="/plugins/dynamix.vm.manager/scripts/codemirror/addon/hint/show-hint.css">
|
||||
<style type="text/css">
|
||||
.CodeMirror { border: 1px solid #eee; cursor: text; }
|
||||
.CodeMirror pre.CodeMirror-placeholder { color: #999; }
|
||||
</style>
|
||||
|
||||
<input type="hidden" name="domain[uuid]" value="<?=$strUUID?>">
|
||||
|
||||
<textarea id="addcode" name="xmldesc" placeholder="Copy & Paste Domain XML Configuration Here." autofocus><?= htmlspecialchars($strXML); ?></textarea>
|
||||
|
||||
|
||||
<? if (!$boolRunning) { ?>
|
||||
<? if (!empty($strXML)) { ?>
|
||||
<input type="hidden" name="updatevm" value="1" />
|
||||
<input type="button" value="Update" busyvalue="Updating..." readyvalue="Update" id="btnSubmit" />
|
||||
<? } else { ?>
|
||||
<label for="domain_start"><input type="checkbox" name="domain[startnow]" id="domain_start" value="1" checked="checked"/> Start VM after creation</label>
|
||||
<br>
|
||||
<input type="hidden" name="createvm" value="1" />
|
||||
<input type="button" value="Create" busyvalue="Creating..." readyvalue="Create" id="btnSubmit" />
|
||||
<? } ?>
|
||||
<input type="button" value="Cancel" id="btnCancel" />
|
||||
<? } else { ?>
|
||||
<input type="button" value="Done" id="btnCancel" />
|
||||
<? } ?>
|
||||
|
||||
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/lib/codemirror.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/addon/display/placeholder.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/addon/fold/foldcode.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/addon/hint/show-hint.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/addon/hint/xml-hint.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/addon/hint/libvirt-schema.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/codemirror/mode/xml/xml.js"></script>
|
||||
<script>
|
||||
$(function() {
|
||||
function completeAfter(cm, pred) {
|
||||
var cur = cm.getCursor();
|
||||
if (!pred || pred()) setTimeout(function() {
|
||||
if (!cm.state.completionActive)
|
||||
cm.showHint({completeSingle: false});
|
||||
}, 100);
|
||||
return CodeMirror.Pass;
|
||||
}
|
||||
|
||||
function completeIfAfterLt(cm) {
|
||||
return completeAfter(cm, function() {
|
||||
var cur = cm.getCursor();
|
||||
return cm.getRange(CodeMirror.Pos(cur.line, cur.ch - 1), cur) == "<";
|
||||
});
|
||||
}
|
||||
|
||||
function completeIfInTag(cm) {
|
||||
return completeAfter(cm, function() {
|
||||
var tok = cm.getTokenAt(cm.getCursor());
|
||||
if (tok.type == "string" && (!/['"]/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1)) return false;
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), tok.state).state;
|
||||
return inner.tagName;
|
||||
});
|
||||
}
|
||||
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("addcode"), {
|
||||
mode: "xml",
|
||||
lineNumbers: true,
|
||||
foldGutter: true,
|
||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
||||
extraKeys: {
|
||||
"'<'": completeAfter,
|
||||
"'/'": completeIfAfterLt,
|
||||
"' '": completeIfInTag,
|
||||
"'='": completeIfInTag,
|
||||
"Ctrl-Space": "autocomplete"
|
||||
},
|
||||
hintOptions: {schemaInfo: getLibvirtSchema()}
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
editor.refresh();
|
||||
}, 1);
|
||||
|
||||
$("#form_content #btnSubmit").click(function frmSubmit() {
|
||||
var $button = $(this);
|
||||
|
||||
editor.save();
|
||||
|
||||
var $form = $('#domain_template').closest('form');
|
||||
var postdata = $form.serialize().replace(/'/g,"%27");
|
||||
|
||||
$form.find('input').prop('disabled', true);
|
||||
$button.val($button.attr('busyvalue'));
|
||||
|
||||
$.post("/plugins/dynamix.vm.manager/templates/<?=basename(__FILE__)?>", postdata, function( data ) {
|
||||
if (data.success) {
|
||||
done();
|
||||
}
|
||||
if (data.error) {
|
||||
swal({title:"VM creation error",text:data.error,type:"error"});
|
||||
$form.find('input').prop('disabled', false);
|
||||
$button.val($button.attr('readyvalue'));
|
||||
}
|
||||
}, "json");
|
||||
});
|
||||
|
||||
$("#form_content #btnCancel").click(done);
|
||||
});
|
||||
</script>
|
||||
|
After Width: | Height: | Size: 1007 B |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.3 KiB |