style: readability in includes

This commit is contained in:
Zack Spear
2023-06-21 11:03:44 -05:00
committed by Zack Spear
parent 1660ac7e02
commit 77cf384d6a
2 changed files with 142 additions and 137 deletions

View File

@@ -1,20 +1,20 @@
<style>
#header {
z-index: 102 !important;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
z-index: 102 !important;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
connect-user-profile {
font-size: 16px;
margin-left: auto;
height: 100%;
font-size: 16px;
margin-left: auto;
height: 100%;
}
</style>
<?php
@@ -26,44 +26,44 @@ $remoteResourceUrl = 'https://components.myunraid.com/';
// Check if session cookie exists
if (!isset($_COOKIE['manifest_last_checked']) || time() - $_COOKIE['manifest_last_checked'] >= 300) {
// Get the remote manifest JSON
$remoteManifestJson = file_get_contents($remoteResourceUrl . 'manifest.json');
// Get the remote manifest JSON
$remoteManifestJson = file_get_contents($remoteResourceUrl . 'manifest.json');
// Compare the remote and local manifest versions
$remoteManifest = json_decode($remoteManifestJson, true);
$localManifest = json_decode(file_get_contents($localManifestFile), true);
// Compare the remote and local manifest versions
$remoteManifest = json_decode($remoteManifestJson, true);
$localManifest = json_decode(file_get_contents($localManifestFile), true);
if ($remoteManifest && $localManifest && $remoteManifest !== $localManifest) {
// Update the local manifest
file_put_contents($localManifestFile, $remoteManifestJson);
if ($remoteManifest && $localManifest && $remoteManifest !== $localManifest) {
// Update the local manifest
file_put_contents($localManifestFile, $remoteManifestJson);
// Download the file contents for the search value
$searchText = 'connect-components.client.mjs';
$fileValue = null;
// Download the file contents for the search value
$searchText = 'connect-components.client.mjs';
$fileValue = null;
foreach ($remoteManifest as $key => $value) {
if (strpos($key, $searchText) !== false && isset($value["file"])) {
$fileValue = file_get_contents($remoteResourceUrl . $value["file"]);
break;
}
foreach ($remoteManifest as $key => $value) {
if (strpos($key, $searchText) !== false && isset($value["file"])) {
$fileValue = file_get_contents($remoteResourceUrl . $value["file"]);
break;
}
}
if ($fileValue !== null) {
// Extract the directory path from the URL
$directoryPath = pathinfo($value["file"], PATHINFO_DIRNAME);
// Set the local file path
$localFilePath = '/usr/local/emhttp/plugins/dynamix.my.servers' . $directoryPath;
// Create the directory if it doesn't exist
if (!is_dir($localFilePath)) {
mkdir($localFilePath, 0777, true);
}
// Save the file contents to a local file
file_put_contents($localFilePath . '/' . basename($value["file"]), $fileValue);
}
}
if ($fileValue !== null) {
// Extract the directory path from the URL
$directoryPath = pathinfo($value["file"], PATHINFO_DIRNAME);
// Set the local file path
$localFilePath = '/usr/local/emhttp/plugins/dynamix.my.servers' . $directoryPath;
// Create the directory if it doesn't exist
if (!is_dir($localFilePath)) {
mkdir($localFilePath, 0777, true);
}
// Save the file contents to a local file
file_put_contents($localFilePath . '/' . basename($value["file"]), $fileValue);
}
}
// Set the session cookie with the current timestamp
setcookie('manifest_last_checked', time(), time() + 300); // Expire in 5 minutes
// Set the session cookie with the current timestamp
setcookie('manifest_last_checked', time(), time() + 300); // Expire in 5 minutes
}
// Load the local manifest
@@ -73,16 +73,16 @@ $searchText = 'connect-components.client.mjs';
$fileValue = null;
foreach ($localManifest as $key => $value) {
if (strpos($key, $searchText) !== false && isset($value["file"])) {
$fileValue = $value["file"];
break;
}
if (strpos($key, $searchText) !== false && isset($value["file"])) {
$fileValue = $value["file"];
break;
}
}
if ($fileValue !== null) {
$prefixedPath = '/plugins/dynamix.my.servers/connect-components/';
echo '<script src="' . $prefixedPath . $fileValue . '"></script>';
$prefixedPath = '/plugins/dynamix.my.servers/connect-components/';
echo '<script src="' . $prefixedPath . $fileValue . '"></script>';
} else {
echo '<script>console.error("%cNo matching key containing \'' . $searchText . '\' found.", "font-weight: bold; color: white; background-color: red");</script>';
echo '<script>console.error("%cNo matching key containing \'' . $searchText . '\' found.", "font-weight: bold; color: white; background-color: red");</script>';
}
?>

View File

@@ -1,33 +1,40 @@
<!-- myservers2 -->
<?
<?php
/**
* Build vars for user profile prop
*/
// add 'ipaddr' function for 6.9 backwards compatibility
if (!function_exists('ipaddr')) {
function ipaddr($ethX='eth0', $prot=4) {
global $$ethX;
switch ($$ethX['PROTOCOL:0']) {
case 'ipv4':
return $$ethX['IPADDR:0'];
case 'ipv6':
return $$ethX['IPADDR6:0'];
case 'ipv4+ipv6':
switch ($prot) {
case 4: return $$ethX['IPADDR:0'];
case 6: return $$ethX['IPADDR6:0'];
default:return [$$ethX['IPADDR:0'],$$ethX['IPADDR6:0']];}
default:
return $$ethX['IPADDR:0'];
function ipaddr($ethX = 'eth0', $prot = 4)
{
$ethXData = $$ethX;
if (isset($ethXData['PROTOCOL:0'])) {
$protocol = $ethXData['PROTOCOL:0'];
$ipaddr = $ethXData['IPADDR:0'];
$ipaddr6 = $ethXData['IPADDR6:0'];
switch ($protocol) {
case 'ipv4':
return $ipaddr;
case 'ipv6':
return $ipaddr6;
case 'ipv4+ipv6':
return ($prot === 4) ? $ipaddr : $ipaddr6;
}
}
return '';
}
}
}
$configErrorEnum = [ // used to map $var['configValid'] value to mimic unraid-api's `configError` ENUM
"error" => 'UNKNOWN_ERROR',
"invalid" => 'INVALID',
"nokeyserver" => 'NO_KEY_SERVER',
"withdrawn" => 'WITHDRAWN',
$configErrorEnum = [
"error" => 'UNKNOWN_ERROR',
"invalid" => 'INVALID',
"nokeyserver" => 'NO_KEY_SERVER',
"withdrawn" => 'WITHDRAWN',
];
// read flashbackup ini file
$flashbackup_ini = '/var/local/emhttp/flashbackup.ini';
$flashbackup_status = (file_exists($flashbackup_ini)) ? @parse_ini_file($flashbackup_ini) : [];
@@ -36,70 +43,69 @@ $nginx = parse_ini_file('/var/local/emhttp/nginx.ini');
$pluginInstalled = '';
if (!file_exists('/var/lib/pkgtools/packages/dynamix.unraid.net') && !file_exists('/var/lib/pkgtools/packages/dynamix.unraid.net.staging')) {
$pluginInstalled = ''; // base OS only, plugin not installed • show ad for plugin
$pluginInstalled = ''; // base OS only, plugin not installed • show ad for plugin
} else {
// plugin is installed but if the unraid-api file doesn't fully install it's a failed install
if (file_exists('/var/lib/pkgtools/packages/dynamix.unraid.net')) $pluginInstalled = 'dynamix.unraid.net.plg';
if (file_exists('/var/lib/pkgtools/packages/dynamix.unraid.net.staging')) $pluginInstalled = 'dynamix.unraid.net.staging.plg';
// plugin install failed • append failure detected so we can show warning about failed install via UPC
if (!file_exists('/usr/local/sbin/unraid-api')) $pluginInstalled = $pluginInstalled . '_installFailed';
// plugin is installed but if the unraid-api file doesn't fully install it's a failed install
if (file_exists('/var/lib/pkgtools/packages/dynamix.unraid.net')) $pluginInstalled = 'dynamix.unraid.net.plg';
if (file_exists('/var/lib/pkgtools/packages/dynamix.unraid.net.staging')) $pluginInstalled = 'dynamix.unraid.net.staging.plg';
// plugin install failed • append failure detected so we can show warning about failed install via UPC
if (!file_exists('/usr/local/sbin/unraid-api')) $pluginInstalled .= '_installFailed';
}
$plgversion = file_exists('/var/log/plugins/dynamix.unraid.net.plg')
? trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net.plg 2>/dev/null'))
: ( file_exists('/var/log/plugins/dynamix.unraid.net.staging.plg')
? trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net.staging.plg 2>/dev/null'))
: 'base-'.$var['version'] );
? trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net.plg 2>/dev/null'))
: (file_exists('/var/log/plugins/dynamix.unraid.net.staging.plg')
? trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net.staging.plg 2>/dev/null'))
: 'base-' . $var['version']);
$serverData = [
"apiKey" => $myservers['upc']['apikey'] ?? '',
"apiVersion" => $myservers['api']['version'] ?? '',
"avatar" => (!empty($myservers['remote']['avatar']) && $pluginInstalled) ? $myservers['remote']['avatar'] : '',
"config" => [
'valid' => $var['configValid'] === 'yes',
'error' => $var['configValid'] !== 'yes'
? (array_key_exists($var['configValid'], $configErrorEnum) ? $configErrorEnum[$var['configValid']] : 'UNKNOWN_ERROR')
: null,
],
"csrf" => $var['csrf_token'],
"description" => $var['COMMENT'] ?? '',
"deviceCount" => $var['deviceCount'],
"email" => $myservers['remote']['email'] ?? '',
"expireTime" => 1000 * ($var['regTy'] == 'Trial' || strstr($var['regTy'],'expired') ? $var['regTm2'] : 0),
"extraOrigins" => explode(',', $myservers['api']['extraOrigins']??''),
"flashProduct" => $var['flashProduct'],
"flashVendor" => $var['flashVendor'],
"flashBackupActivated" => empty($flashbackup_status['activated']) ? '' : 'true',
"guid" => $var['flashGUID'],
"hasRemoteApikey" => !empty($myservers['remote']['apikey']),
"internalIp" => ipaddr(),
"internalPort" => $_SERVER['SERVER_PORT'],
"keyfile" => empty($var['regFILE']) ? '' : str_replace(['+','/','='], ['-','_',''], trim(base64_encode(@file_get_contents($var['regFILE'])))),
"locale" => ($_SESSION['locale']) ? $_SESSION['locale'] : 'en_US',
"model" => $var['SYS_MODEL'],
"name" => $var['NAME'],
"osVersion" => $var['version'],
"pluginInstalled" => $pluginInstalled,
"pluginVersion" => $pluginVersion,
"protocol" => $_SERVER['REQUEST_SCHEME'],
"regGen" => (int)$var['regGen'],
"regGuid" => $var['regGUID'],
"registered" => (!empty($myservers['remote']['username']) && $pluginInstalled),
"registeredTime" => $myservers['remote']['regWizTime'] ?? '',
"site" => $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'],
"state" => strtoupper(empty($var['regCheck']) ? $var['regTy'] : $var['regCheck']),
"theme" => [
"banner" => $display['banner'] ?? '',
"bannerGradient" => $display['showBannerGradient'] ?? 'yes',
"bgColor" => ($backgnd) ? '#'.$backgnd : '',
"descriptionShow" => ($display['headerdescription'] ?? '' != 'no') ? 'true' : '',
"metaColor" => ($display['headermetacolor'] ?? '') ? '#'.$display['headermetacolor'] : '',
"name" => $display['theme'],
"textColor" => ($header) ? '#'.$header : '',
],
"ts" => time(),
"uptime" => 1000 * (time() - round(strtok(exec("cat /proc/uptime"),' '))),
"username" => (!empty($myservers['remote']['username']) && $pluginInstalled) ? $myservers['remote']['username'] : '',
"wanFQDN" => $nginx['NGINX_WANFQDN'] ?? '',
"apiKey" => $myservers['upc']['apikey'] ?? '',
"apiVersion" => $myservers['api']['version'] ?? '',
"avatar" => (!empty($myservers['remote']['avatar']) && $pluginInstalled) ? $myservers['remote']['avatar'] : '',
"config" => [
'valid' => ($var['configValid'] === 'yes'),
'error' => isset($configErrorEnum[$var['configValid']]) ? $configErrorEnum[$var['configValid']] : 'UNKNOWN_ERROR',
],
"csrf" => $var['csrf_token'],
"description" => $var['COMMENT'] ?? '',
"deviceCount" => $var['deviceCount'],
"email" => $myservers['remote']['email'] ?? '',
"expireTime" => 1000 * (($var['regTy'] === 'Trial' || strstr($var['regTy'], 'expired')) ? $var['regTm2'] : 0),
"extraOrigins" => explode(',', $myservers['api']['extraOrigins'] ?? ''),
"flashProduct" => $var['flashProduct'],
"flashVendor" => $var['flashVendor'],
"flashBackupActivated" => empty($flashbackup_status['activated']) ? '' : 'true',
"guid" => $var['flashGUID'],
"hasRemoteApikey" => !empty($myservers['remote']['apikey']),
"internalIp" => ipaddr(),
"internalPort" => $_SERVER['SERVER_PORT'],
"keyfile" => empty($var['regFILE']) ? '' : str_replace(['+', '/', '='], ['-', '_', ''], trim(base64_encode(@file_get_contents($var['regFILE'])))),
"locale" => ($_SESSION['locale']) ? $_SESSION['locale'] : 'en_US',
"model" => $var['SYS_MODEL'],
"name" => $var['NAME'],
"osVersion" => $var['version'],
"pluginInstalled" => $pluginInstalled,
"pluginVersion" => $pluginVersion,
"protocol" => $_SERVER['REQUEST_SCHEME'],
"regGen" => (int)$var['regGen'],
"regGuid" => $var['regGUID'],
"registered" => (!empty($myservers['remote']['username']) && $pluginInstalled),
"registeredTime" => $myservers['remote']['regWizTime'] ?? '',
"site" => $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'],
"state" => strtoupper(empty($var['regCheck']) ? $var['regTy'] : $var['regCheck']),
"theme" => [
"banner" => $display['banner'] ?? '',
"bannerGradient" => $display['showBannerGradient'] ?? 'yes',
"bgColor" => ($backgnd) ? '#' . $backgnd : '',
"descriptionShow" => (!empty($display['headerdescription']) && $display['headerdescription'] !== 'no'),
"metaColor" => ($display['headermetacolor'] ?? '') ? '#' . $display['headermetacolor'] : '',
"name" => $display['theme'],
"textColor" => ($header) ? '#' . $header : '',
],
"ts" => time(),
"uptime" => 1000 * (time() - round(strtok(exec("cat /proc/uptime"), ' '))),
"username" => (!empty($myservers['remote']['username']) && $pluginInstalled) ? $myservers['remote']['username'] : '',
"wanFQDN" => $nginx['NGINX_WANFQDN'] ?? '',
];
echo "<connect-user-profile server='" . json_encode($serverData) . "'></connect-user-profile>";
@@ -111,9 +117,8 @@ echo "<connect-user-profile server='" . json_encode($serverData) . "'></connect-
*/
const modalsWebComponent = 'connect-modals';
if (!document.getElementsByTagName(modalsWebComponent).length) {
const $body = document.getElementsByTagName('body')[0];
const $modals = document.createElement(modalsWebComponent);
$body.appendChild($modals);
const $body = document.getElementsByTagName('body')[0];
const $modals = document.createElement(modalsWebComponent);
$body.appendChild($modals);
}
</script>
<!-- /myservers2 -->