mirror of
https://github.com/unraid/api.git
synced 2026-01-06 00:30:22 -06:00
refactor: callback progress
This commit is contained in:
@@ -16,48 +16,124 @@ $localSource = '/plugins/dynamix.my.servers/webComponents/' . $webComponentFile;
|
||||
// add the web component source to the DOM
|
||||
echo '<script id="unraid-webcomponents" defer src="' . $localSource . '"></script>';
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$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',
|
||||
];
|
||||
// read flashbackup ini file
|
||||
$flashbackup_ini = '/var/local/emhttp/flashbackup.ini';
|
||||
$flashbackup_status = (file_exists($flashbackup_ini)) ? @parse_ini_file($flashbackup_ini) : [];
|
||||
|
||||
$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
|
||||
} 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';
|
||||
}
|
||||
|
||||
$serverData = [
|
||||
"avatar" => (!empty($myservers['remote']['avatar']) && $plgInstalled) ? $myservers['remote']['avatar'] : '',
|
||||
"apiKey" => $myservers['upc']['apikey'] ?? '',
|
||||
"apiVersion" => $myservers['api']['version'] ?? '',
|
||||
"avatar" => (!empty($myservers['remote']['avatar']) && $pluginInstalled) ? $myservers['remote']['avatar'] : '',
|
||||
"banner" => $display['banner'] ?? '',
|
||||
"bannerGradient" => $display['showBannerGradient'] ?? 'yes',
|
||||
"bgColor" => ($backgnd) ? '#'.$backgnd : '',
|
||||
"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'],
|
||||
"descriptionShow" => ($display['headerdescription']??''!='no') ? 'true' : '',
|
||||
"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'],
|
||||
"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'],
|
||||
"internalIp" => ipaddr(),
|
||||
"internalPort" => $_SERVER['SERVER_PORT'],
|
||||
"keyfile" => empty($var['regFILE'])? "" : str_replace(['+','/','='], ['-','_',''], trim(base64_encode(@file_get_contents($var['regFILE'])))),
|
||||
"locale" => 'en',
|
||||
"locale" => ($_SESSION['locale']) ? $_SESSION['locale'] : 'en_US',
|
||||
"metaColor" => ($display['headermetacolor']??'') ? '#'.$display['headermetacolor'] : '',
|
||||
"model" => $var['SYS_MODEL'],
|
||||
"name" => $var['NAME'],
|
||||
"osVersion" => $var['version'],
|
||||
"plgVersion" => $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'] ),
|
||||
"plgInstalled" => $plgInstalled,
|
||||
"pluginInstalled" => $pluginInstalled,
|
||||
"protocol" => $_SERVER['REQUEST_SCHEME'],
|
||||
"reggen" => (int)$var['regGen'],
|
||||
"regGen" => (int)$var['regGen'],
|
||||
"regGuid" => $var['regGUID'],
|
||||
"registered" => (!empty($myservers['remote']['username']) && $plgInstalled),
|
||||
"name" => $var['NAME'],
|
||||
"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']),
|
||||
"textColor" => ($header) ? '#'.$header : '',
|
||||
"theme" => $display['theme'],
|
||||
"ts" => time(),
|
||||
"username" => (!empty($myservers['remote']['username']) && $plgInstalled) ? $myservers['remote']['username'] : '',
|
||||
"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>";
|
||||
$themeBg = '#111';
|
||||
if ($display['theme'] === 'black' || $display['theme'] === 'azure') {
|
||||
$themeBg = '#fff';
|
||||
}
|
||||
?>
|
||||
<connect-callback-handler></connect-callback-handler>
|
||||
<connect-auth></connect-auth>
|
||||
<connect-key-actions></connect-key-actions>
|
||||
<connect-wan-ip-check php-wan-ip="<?=@file_get_contents('https://wanip4.unraid.net/')?>"></connect-wan-ip-check>
|
||||
<style>
|
||||
.ComponentWrapper {
|
||||
padding: 16px;
|
||||
}
|
||||
</style>
|
||||
<div class="ComponentWrapper" style="background-color: <?=$themeBg?>;">
|
||||
<?="<connect-user-profile server='" . json_encode($serverData) . "'></connect-user-profile>"?>
|
||||
</div>
|
||||
<div class="ComponentWrapper">
|
||||
<connect-auth></connect-auth>
|
||||
</div>
|
||||
<div class="ComponentWrapper">
|
||||
<connect-key-actions></connect-key-actions>
|
||||
</div>
|
||||
<div class="ComponentWrapper">
|
||||
<connect-wan-ip-check php-wan-ip="<?=@file_get_contents('https://wanip4.unraid.net/')?>"></connect-wan-ip-check>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user