Merge branch 'master' of github.com:unraid/graphql-api

This commit is contained in:
Alexis Tyler
2020-07-18 14:45:40 +09:30

View File

@@ -176,7 +176,7 @@ This is work in progress. Use this for testing purposes only!
<FILE Name="/usr/local/emhttp/plugins/dynamix.unraid.net/Unraid.net.page">
<INLINE>
<![CDATA[
Menu="NetworkServices"
Menu="ManagementAccess:100"
Title="Unraid.net"
Icon="icon-u-globe"
Tag="globe"
@@ -816,7 +816,7 @@ response_complete($httpcode, '{}');
function showRegWizard() {
<? $license_state = strtoupper(empty($var['regCheck']) ? $var['regTy'] : $var['regCheck']); ?>
Shadowbox.open({
content:'https://dev.d1eohvtyc6gnee.amplifyapp.com/?ts=<?=time()?>&guid=<?=$var['flashGUID']?>&state=<?=$license_state?>&keyfile=<?=str_replace(['+','/','='], ['-','_',''], trim(base64_encode(@file_get_contents($var['regFILE']))))?>&reggen=<?=$var['regGen']?>&flashproduct=<?=$var['flashProduct']?>&flashvendor=<?=$var['flashVendor']?>&registered=<?=empty($remote['apikey'])||empty($var['regFILE'])?0:1?>&servername=<?=$var['NAME']?>&serverip=<?=$_SERVER['SERVER_ADDR']?>&internalport=<?=$_SERVER['SERVER_PORT']?>&protocol=<?=$_SERVER['REQUEST_SCHEME']?>&site='+location.origin+'&email=<?=$remote['email']?>',
content:'https://registration-dev.unraid.net/?ts=<?=time()?>&guid=<?=$var['flashGUID']?>&state=<?=$license_state?>&keyfile=<?=str_replace(['+','/','='], ['-','_',''], trim(base64_encode(@file_get_contents($var['regFILE']))))?>&reggen=<?=$var['regGen']?>&flashproduct=<?=$var['flashProduct']?>&flashvendor=<?=$var['flashVendor']?>&registered=<?=empty($remote['apikey'])||empty($var['regFILE'])?0:1?>&servername=<?=$var['NAME']?>&serverip=<?=$_SERVER['SERVER_ADDR']?>&internalport=<?=$_SERVER['SERVER_PORT']?>&protocol=<?=$_SERVER['REQUEST_SCHEME']?>&site='+location.origin+'&email=<?=$remote['email']?>',
player: 'iframe',
options: {modal: true, animate: false, displayNav: false, overlayOpacity: 0.8, viewportPadding: 0, showMovieControls: false}
});
@@ -833,8 +833,41 @@ function handleMessage(e) {
hideRegWizard();
return;
}
const SAFE_JSON_PARSE = (str) => {
try {
return [null, JSON.parse(str)];
} catch (err) {
return [err];
}
};
var data = JSON.parse(e.data);
const [err, data] = SAFE_JSON_PARSE(e.data);
if (err) return false; // swallow json parse error
const HANDLE_LICENSES = (data, e) => {
if (data.license) {
$.get('/webGui/include/InstallKey.php', {url: data.license}, function() {
console.log('New license key installed: ' + data.license);
const payload = {
event: 'LICENSE_SUCCESS',
message: 'New license key installed',
license: data.license,
};
e.source.postMessage(JSON.stringify(payload), e.origin);
}).fail(function() {
console.error('Failed to license new key: ' + data.license);
const payload = {
event: 'LICENSE_ERROR',
message: 'Failed to license new key',
license: data.license,
};
e.source.postMessage(JSON.stringify(payload), e.origin);
});
} else {
console.error('KEY_PURCHASE event fired! but missing license data:', data);
}
};
switch (data.event) {
case "CLOSE_SHADOWBOX":
@@ -851,38 +884,15 @@ function handleMessage(e) {
}
$.post('/update.php', postargs, function() {
console.log('dynamix/dynamix.cfg: Updated apikey under [remote] section');
if (!data.license) {
setTimeout(function(){ window.location.href = '/Main'; }, 500);
}
}).fail(function() {
console.error('Failed to update apikey under [remote] section');
});
}
if (data.license) {
hideRegWizard(function (){
$.get('/webGui/include/InstallKey.php', {url: data.license}, function() {
console.log('New license key installed: ' + data.license);
setTimeout(function(){ window.location.href = '/Main'; }, 500);
}).fail(function() {
console.error('Failed to license new key: ' + data.license);
});
});
}
// duplicate conditional so we don't get the error from HANDLE_LICENSES()
if (data.license) HANDLE_LICENSES(data, e);
break;
case "INSTALL_KEY":
case "KEY_PURCHASE":
if (data.license) {
hideRegWizard(function () {
$.get('/webGui/include/InstallKey.php', {url: data.license}, function() {
console.log('New license key installed: ' + data.license);
setTimeout(function(){ window.location.href = '/Main'; }, 500);
}).fail(function() {
console.error('Failed to license new key: ' + data.license);
});
});
} else {
console.error('KEY_PURCHASE event fired! but missing license data:', data);
}
HANDLE_LICENSES(data, e);
break;
case "GET_STATE":
$.get('/plugins/dynamix.unraid.net/include/state.php', function(newstate) {
@@ -898,6 +908,10 @@ function handleMessage(e) {
console.error('Failed to unregister');
});
break;
case "RELOAD":
return window.location.reload();
case "REDIRECT_MAIN":
return window.location.href = '/Main';
default:
console.error('Unhandled event \'' + data.event + '\' fired. data:', data);
break;
@@ -992,16 +1006,16 @@ echo json_encode($arr);
<!-- user profile component -->
<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;
}
vue-userprofile,
unraid-user-profile {