mirror of
https://github.com/unraid/webgui.git
synced 2026-01-14 05:30:07 -06:00
Merge branch 'master' of github.com:limetech/webgui
This commit is contained in:
@@ -611,12 +611,12 @@
|
||||
banner="<?=$display['banner'] ?? ''?>"
|
||||
bgcolor="<?=($backgnd) ? '#'.$backgnd : ''?>"
|
||||
csrf="<?=$var['csrf_token']?>"
|
||||
displaydesc="<?=($display['headerdescription']!='no') ? 'true' : ''?>"
|
||||
displaydesc="<?=($display['headerdescription']??''!='no') ? 'true' : ''?>"
|
||||
expiretime="<?=1000*($var['regTy']=='Trial'||strstr($var['regTy'],'expired')?$var['regTm2']:0)?>"
|
||||
hide-my-servers="<?=$plgInstalled ? '' : 'yes' ?>"
|
||||
locale="<?=($_SESSION['locale']) ? $_SESSION['locale'] : 'en_US'?>"
|
||||
locale-messages="<?=rawurlencode(json_encode($upc_translations, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE))?>"
|
||||
metacolor="<?=($display['headermetacolor']) ? '#'.$display['headermetacolor'] : ''?>"
|
||||
metacolor="<?=($display['headermetacolor']??'') ? '#'.$display['headermetacolor'] : ''?>"
|
||||
plg-path="dynamix.my.servers"
|
||||
reg-wiz-time="<?=$remote['regWizTime'] ?? ''?>"
|
||||
serverdesc="<?=$var['COMMENT']?>"
|
||||
|
||||
@@ -57,9 +57,11 @@ $arr['internalip'] = $_SERVER['SERVER_ADDR'];
|
||||
$arr['internalport'] = $_SERVER['SERVER_PORT'];
|
||||
$arr['plgVersion'] = 'base-'.$var['version'];
|
||||
$arr['protocol'] = $_SERVER['REQUEST_SCHEME'];
|
||||
$arr['locale'] = $_SESSION['locale'] ? $_SESSION['locale'] : 'en_US';
|
||||
$arr['locale'] = $_SESSION['locale'] ?? 'en_US';
|
||||
$arr['expiretime']=1000*($var['regTy']=='Trial'||strstr($var['regTy'],'expired')?$var['regTm2']:0);
|
||||
$arr['uptime']=1000*(time() - round(strtok(exec("cat /proc/uptime"),' ')));
|
||||
$arr['hasRemoteApikey'] = empty($remote['apikey']) ? 0 : 1;
|
||||
$arr['hideMyServers'] = (file_exists('/usr/local/sbin/unraid-api')) ? '' : 'yes';
|
||||
$arr['config'] = [
|
||||
'valid' => $var['configValid'] === 'yes',
|
||||
'error' => $var['configValid'] !== 'yes'
|
||||
|
||||
@@ -273,7 +273,7 @@ function loadlist() {
|
||||
$(function() {
|
||||
<?if ($msg):?>
|
||||
<?$color = strpos($msg, "rror:")!==false ? 'red-text':'green-text'?>
|
||||
$('#countdown').html("<span class='<?-$color?>'><?=_($msg)?></span>");
|
||||
$('#countdown').html("<span class='<?=$color?>'><?=_($msg)?></span>");
|
||||
<?endif;?>
|
||||
$('#btnAddVM').click(function AddVMEvent(){$('.tab>input#tab2').click();});
|
||||
loadlist();
|
||||
|
||||
@@ -685,9 +685,7 @@
|
||||
}
|
||||
|
||||
$sharestr = '';
|
||||
$memorybacking ="<memoryBacking>
|
||||
<nosharepages/>
|
||||
</memoryBacking>" ;
|
||||
$memorybacking = json_decode($domain['memoryBacking'],true);
|
||||
|
||||
if (!empty($shares)) {
|
||||
foreach ($shares as $i => $share) {
|
||||
@@ -696,10 +694,8 @@
|
||||
}
|
||||
|
||||
if ($share['mode'] == "virtiofs") {
|
||||
$memorybacking = "<memoryBacking>
|
||||
<source type='memfd'/>
|
||||
<access mode='shared'/>
|
||||
</memoryBacking>" ;
|
||||
if (!isset($memorybacking['source'])) $memorybacking['source']["@attributes"]["type"] = "memfd" ;
|
||||
if (!isset($memorybacking['access'])) $memorybacking['access']["@attributes"]["mode"] = "shared" ;
|
||||
|
||||
$sharestr .= "<filesystem type='mount' accessmode='passthrough'>
|
||||
<driver type='virtiofs' queue='1024' />
|
||||
@@ -884,6 +880,8 @@
|
||||
</memballoon>";
|
||||
}
|
||||
#$osbootdev = "" ;
|
||||
$memorybackingXML = Array2XML::createXML('memoryBacking', $memorybacking);
|
||||
$memoryBackingXML = $memorybackingXML->saveXML($memorybackingXML->documentElement);
|
||||
return "<domain type='$type' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
||||
<uuid>$uuid</uuid>
|
||||
<name>$name</name>
|
||||
@@ -892,7 +890,7 @@
|
||||
<currentMemory unit='KiB'>$mem</currentMemory>
|
||||
<memory unit='KiB'>$maxmem</memory>
|
||||
$cpustr
|
||||
$memorybacking
|
||||
$memoryBackingXML
|
||||
<os>
|
||||
$loader
|
||||
<type arch='$arch' machine='$machine'>hvm</type>
|
||||
@@ -1215,7 +1213,7 @@
|
||||
'capacity' => '-',
|
||||
'allocation' => '-',
|
||||
'physical' => '-',
|
||||
'bus' => $disk->target->attributes()->bus,
|
||||
'bus' => $disk->target->attributes()->bus->__toString(),
|
||||
'boot order' => $disk->boot->attributes()->order ,
|
||||
'serial' => $disk->serial
|
||||
];
|
||||
@@ -1273,10 +1271,13 @@
|
||||
$ret = 0;
|
||||
for ($i = 0; $i < sizeof($tmp); $i++) {
|
||||
if (($disk == '*') || ($tmp[$i]['device'] == $disk))
|
||||
if ($physical)
|
||||
if ($physical) {
|
||||
if($tmp[$i]['physical'] == "-") $tmp[$i]['physical'] = "0" ;
|
||||
$ret += $tmp[$i]['physical'];
|
||||
else
|
||||
} else {
|
||||
if($tmp[$i]['capacity'] == "-") $tmp[$i]['capacity'] = "0" ;
|
||||
$ret += $tmp[$i]['capacity'];
|
||||
}
|
||||
}
|
||||
unset($tmp);
|
||||
|
||||
|
||||
@@ -12,6 +12,155 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
/**
|
||||
* Array2XML: A class to convert array in PHP to XML
|
||||
* It also takes into account attributes names unlike SimpleXML in PHP
|
||||
* It returns the XML in form of DOMDocument class for further manipulation.
|
||||
* It throws exception if the tag name or attribute name has illegal chars.
|
||||
*
|
||||
* Author : Lalit Patel
|
||||
* Website: http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes
|
||||
* License: Apache License 2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Version: 0.1 (10 July 2011)
|
||||
* Version: 0.2 (16 August 2011)
|
||||
* - replaced htmlentities() with htmlspecialchars() (Thanks to Liel Dulev)
|
||||
* - fixed a edge case where root node has a false/null/0 value. (Thanks to Liel Dulev)
|
||||
* Version: 0.3 (22 August 2011)
|
||||
* - fixed tag sanitize regex which didn't allow tagnames with single character.
|
||||
* Version: 0.4 (18 September 2011)
|
||||
* - Added support for CDATA section using @cdata instead of @value.
|
||||
* Version: 0.5 (07 December 2011)
|
||||
* - Changed logic to check numeric array indices not starting from 0.
|
||||
* Version: 0.6 (04 March 2012)
|
||||
* - Code now doesn't @cdata to be placed in an empty array
|
||||
* Version: 0.7 (24 March 2012)
|
||||
* - Reverted to version 0.5
|
||||
* Version: 0.8 (02 May 2012)
|
||||
* - Removed htmlspecialchars() before adding to text node or attributes.
|
||||
*
|
||||
* Usage:
|
||||
* $xml = Array2XML::createXML('root_node_name', $php_array);
|
||||
* echo $xml->saveXML();
|
||||
*/
|
||||
class Array2XML {
|
||||
private static $xml = null;
|
||||
private static $encoding = 'UTF-8';
|
||||
/**
|
||||
* Initialize the root XML node [optional]
|
||||
* @param $version
|
||||
* @param $encoding
|
||||
* @param $format_output
|
||||
*/
|
||||
public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
|
||||
self::$xml = new DomDocument($version, $encoding);
|
||||
self::$xml->formatOutput = $format_output;
|
||||
self::$encoding = $encoding;
|
||||
}
|
||||
/**
|
||||
* Convert an Array to XML
|
||||
* @param string $node_name - name of the root node to be converted
|
||||
* @param array $arr - aray to be converterd
|
||||
* @return DomDocument
|
||||
*/
|
||||
public static function &createXML($node_name, $arr=array()) {
|
||||
$xml = self::getXMLRoot();
|
||||
$xml->appendChild(self::convert($node_name, $arr));
|
||||
self::$xml = null; // clear the xml node in the class for 2nd time use.
|
||||
return $xml;
|
||||
}
|
||||
/**
|
||||
* Convert an Array to XML
|
||||
* @param string $node_name - name of the root node to be converted
|
||||
* @param array $arr - aray to be converterd
|
||||
* @return DOMNode
|
||||
*/
|
||||
private static function &convert($node_name, $arr=array()) {
|
||||
//print_arr($node_name);
|
||||
$xml = self::getXMLRoot();
|
||||
$node = $xml->createElement($node_name);
|
||||
if(is_array($arr)){
|
||||
// get the attributes first.;
|
||||
if(isset($arr['@attributes'])) {
|
||||
foreach($arr['@attributes'] as $key => $value) {
|
||||
if(!self::isValidTagName($key)) {
|
||||
throw new Exception('[Array2XML] Illegal character in attribute name. attribute: '.$key.' in node: '.$node_name);
|
||||
}
|
||||
$node->setAttribute($key, self::bool2str($value));
|
||||
}
|
||||
unset($arr['@attributes']); //remove the key from the array once done.
|
||||
}
|
||||
// check if it has a value stored in @value, if yes store the value and return
|
||||
// else check if its directly stored as string
|
||||
if(isset($arr['@value'])) {
|
||||
$node->appendChild($xml->createTextNode(self::bool2str($arr['@value'])));
|
||||
unset($arr['@value']); //remove the key from the array once done.
|
||||
//return from recursion, as a note with value cannot have child nodes.
|
||||
return $node;
|
||||
} else if(isset($arr['@cdata'])) {
|
||||
$node->appendChild($xml->createCDATASection(self::bool2str($arr['@cdata'])));
|
||||
unset($arr['@cdata']); //remove the key from the array once done.
|
||||
//return from recursion, as a note with cdata cannot have child nodes.
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
//create subnodes using recursion
|
||||
if(is_array($arr)){
|
||||
// recurse to get the node for that key
|
||||
foreach($arr as $key=>$value){
|
||||
if(!self::isValidTagName($key)) {
|
||||
throw new Exception('[Array2XML] Illegal character in tag name. tag: '.$key.' in node: '.$node_name);
|
||||
}
|
||||
if(is_array($value) && is_numeric(key($value))) {
|
||||
// MORE THAN ONE NODE OF ITS KIND;
|
||||
// if the new array is numeric index, means it is array of nodes of the same kind
|
||||
// it should follow the parent key name
|
||||
foreach($value as $k=>$v){
|
||||
$node->appendChild(self::convert($key, $v));
|
||||
}
|
||||
} else {
|
||||
// ONLY ONE NODE OF ITS KIND
|
||||
$node->appendChild(self::convert($key, $value));
|
||||
}
|
||||
unset($arr[$key]); //remove the key from the array once done.
|
||||
}
|
||||
}
|
||||
// after we are done with all the keys in the array (if it is one)
|
||||
// we check if it has any text value, if yes, append it.
|
||||
if(!is_array($arr)) {
|
||||
$node->appendChild($xml->createTextNode(self::bool2str($arr ?? "")));
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
/*
|
||||
* Get the root XML node, if there isn't one, create it.
|
||||
*/
|
||||
private static function getXMLRoot(){
|
||||
if(empty(self::$xml)) {
|
||||
self::init();
|
||||
}
|
||||
return self::$xml;
|
||||
}
|
||||
/*
|
||||
* Get string representation of boolean value
|
||||
*/
|
||||
private static function bool2str($v){
|
||||
//convert boolean to text value.
|
||||
$v = $v === true ? 'true' : $v;
|
||||
$v = $v === false ? 'false' : $v;
|
||||
return $v;
|
||||
}
|
||||
/*
|
||||
* Check if the tag name or attribute name contains illegal characters
|
||||
* Ref: http://www.w3.org/TR/xml/#sec-common-syn
|
||||
*/
|
||||
private static function isValidTagName($tag){
|
||||
$pattern = '/^[a-z_]+[a-z0-9\:\-\.\_]*[^:]*$/i';
|
||||
return preg_match($pattern, $tag, $matches) && $matches[0] == $tag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt.php";
|
||||
|
||||
@@ -1119,7 +1268,8 @@
|
||||
'state' => $lv->domain_state_translate($dom['state']),
|
||||
'ovmf' => $strOVMF,
|
||||
'usbboot' => $osbootdev,
|
||||
'usbmode' => $strUSBMode
|
||||
'usbmode' => $strUSBMode,
|
||||
'memoryBacking' => getmemoryBacking($res)
|
||||
],
|
||||
'media' => [
|
||||
'cdrom' => (!empty($medias) && !empty($medias[0]) && array_key_exists('file', $medias[0])) ? $medias[0]['file'] : '',
|
||||
@@ -1183,7 +1333,7 @@
|
||||
foreach ($old['devices']['disk'] as $k => $d) if ($source==$d['source']['@attributes']['file']) $new['devices']['disk'][$key]['driver']['@attributes'] = $d['driver']['@attributes'];
|
||||
}
|
||||
// settings not in the GUI, but maybe customized
|
||||
unset($new['memoryBacking'], $new['clock']);
|
||||
unset($new['clock']);
|
||||
// preserve vnc/spice port settings
|
||||
// unset($new['devices']['graphics']['@attributes']['port'],$new['devices']['graphics']['@attributes']['autoport']);
|
||||
if (!$new['devices']['graphics']) unset($old['devices']['graphics']);
|
||||
@@ -1274,6 +1424,14 @@
|
||||
return $data ;
|
||||
}
|
||||
|
||||
function getmemoryBacking($res) {
|
||||
global $lv ;
|
||||
$xml = $lv->domain_get_xml($res) ;
|
||||
$memoryBacking = new SimpleXMLElement($xml);
|
||||
$memorybacking = $memoryBacking->memoryBacking ;
|
||||
return json_encode($memorybacking); ;
|
||||
}
|
||||
|
||||
function getchannels($res) {
|
||||
global $lv ;
|
||||
$xml = $lv->domain_get_xml($res) ;
|
||||
|
||||
@@ -57,7 +57,8 @@
|
||||
'vcpu' => [0],
|
||||
'hyperv' => 1,
|
||||
'ovmf' => 1,
|
||||
'usbmode' => 'usb2'
|
||||
'usbmode' => 'usb2',
|
||||
'memoryBacking' => '{"nosharepages":{}}'
|
||||
],
|
||||
'media' => [
|
||||
'cdrom' => '',
|
||||
@@ -287,6 +288,7 @@
|
||||
<input type="hidden" name="domain[clock]" id="domain_clock" value="<?=htmlspecialchars($arrConfig['domain']['clock'])?>">
|
||||
<input type="hidden" name="domain[arch]" value="<?=htmlspecialchars($arrConfig['domain']['arch'])?>">
|
||||
<input type="hidden" name="domain[oldname]" id="domain_oldname" value="<?=htmlspecialchars($arrConfig['domain']['name'])?>">
|
||||
<input type="hidden" name="domain[memoryBacking]" id="domain_memorybacking" value="<?=htmlspecialchars($arrConfig['domain']['memoryBacking'])?>">
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
|
||||
@@ -39,7 +39,7 @@ if (!function_exists('ipaddr')) {
|
||||
|
||||
function host_lookup_ip($host) {
|
||||
$result = @dns_get_record($host, DNS_A);
|
||||
$ip = ($result) ? $result[0]['ip'] : '';
|
||||
$ip = ($result) ? $result[0]['ip']??'' : '';
|
||||
return($ip);
|
||||
}
|
||||
function rebindDisabled() {
|
||||
@@ -163,7 +163,8 @@ function verbose_output($httpcode, $result) {
|
||||
}
|
||||
if ($result) {
|
||||
echo "Response (HTTP $httpcode):".PHP_EOL;
|
||||
echo @json_encode(@json_decode($result, true), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
$mutatedResult = is_array($result) ? json_encode($result) : $result;
|
||||
echo @json_encode(@json_decode($mutatedResult, true), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -191,11 +192,11 @@ function response_complete($httpcode, $result, $cli_success_msg='') {
|
||||
|
||||
$cli = php_sapi_name()=='cli';
|
||||
$verbose = $anon = false;
|
||||
if ($cli && $argv[1] == "-v") {
|
||||
if ($cli && ($argc > 1) && $argv[1] == "-v") {
|
||||
$verbose = true;
|
||||
$anon = true;
|
||||
}
|
||||
if ($cli && $argv[1] == "-vv") {
|
||||
if ($cli && ($argc > 1) && $argv[1] == "-vv") {
|
||||
$verbose = true;
|
||||
}
|
||||
$var = parse_ini_file('/var/local/emhttp/var.ini');
|
||||
@@ -293,7 +294,7 @@ $plgversion = file_exists("/var/log/plugins/dynamix.unraid.net.plg") ? trim(@exe
|
||||
|
||||
// only proceed when when signed in or when legacy unraid.net SSL certificate exists
|
||||
if (!$isRegistered && !$isLegacyCert) {
|
||||
response_complete(406, array('error' => _('Nothing to do')));
|
||||
response_complete(406, array('error' => _('Nothing to do')));
|
||||
}
|
||||
|
||||
// keyfile
|
||||
@@ -343,7 +344,7 @@ if ($isRegistered) {
|
||||
}
|
||||
|
||||
// if remoteaccess is enabled in 6.10.0-rc3+ and WANIP has changed since nginx started, reload nginx
|
||||
if ($post['_wanip'] && ($post['_wanip'] != $nginx['NGINX_WANIP']) && version_compare($var['version'],"6.10.0-rc2",">")) $reloadNginx = true;
|
||||
if (isset($post['_wanip']) && ($post['_wanip'] != $nginx['NGINX_WANIP']) && version_compare($var['version'],"6.10.0-rc2",">")) $reloadNginx = true;
|
||||
// if remoteaccess is currently disabled (perhaps because a wanip was not available when nginx was started)
|
||||
// BUT the system is configured to have it enabled AND a wanip is now available
|
||||
// then reload nginx
|
||||
|
||||
Reference in New Issue
Block a user