mirror of
https://github.com/unraid/api.git
synced 2026-01-06 00:30:22 -06:00
Pass wanip to checkdns
This commit is contained in:
@@ -222,7 +222,10 @@ function dnsCheckServer(button) {
|
||||
};
|
||||
|
||||
$(button).prop("disabled", true).html("_(Checking)_ <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>");
|
||||
$.post("https://keys.lime-technology.com/account/server/checkdns",{externalport:$('#wanport').val(),keyfile:"<?=$keyfile?>"},success).fail(failure);
|
||||
$.post('/plugins/dynamix.my.servers/include/unraid-api.php',{command:'wanip'}, function(data) {
|
||||
wanip = (data && data.result) ? data.result : "";
|
||||
$.post("https://keys.lime-technology.com/account/server/checkdns",{wanip:wanip,externalport:$('#wanport').val(),keyfile:"<?=$keyfile?>"},success).fail(failure);
|
||||
});
|
||||
}
|
||||
|
||||
function changeRemoteAccess(dropdown) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2023, Lime Technology
|
||||
* Copyright 2012-2023, Bergware International.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$cli = php_sapi_name() == 'cli';
|
||||
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
/**
|
||||
* @name response_complete
|
||||
* @param {HTTP Response Status Code} $httpcode https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
||||
* @param {String|Array} $result - strings are assumed to be encoded JSON. Arrays will be encoded to JSON.
|
||||
* @param {String} $cli_success_msg
|
||||
*/
|
||||
function response_complete($httpcode, $result, $cli_success_msg='') {
|
||||
global $cli;
|
||||
$mutatedResult = is_array($result) ? json_encode($result) : $result;
|
||||
if ($cli) {
|
||||
$json = @json_decode($mutatedResult,true);
|
||||
if (!empty($json['error'])) {
|
||||
echo 'Error: '.$json['error'].PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
exit($cli_success_msg.PHP_EOL);
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
http_response_code($httpcode);
|
||||
exit((string)$mutatedResult);
|
||||
}
|
||||
|
||||
$validCommands = [
|
||||
'start',
|
||||
'restart',
|
||||
'stop',
|
||||
'report',
|
||||
'wanip'
|
||||
];
|
||||
|
||||
$command = 'none';
|
||||
$param1 = '';
|
||||
if ($cli) {
|
||||
if ($argc > 1) $command = $argv[1];
|
||||
if ($argc > 2) $param1 = $argv[2];
|
||||
} else {
|
||||
$command = $_POST['command'];
|
||||
$param1 = $_POST['param1'];
|
||||
}
|
||||
if (!in_array($command, $validCommands)) $command = 'none';
|
||||
|
||||
if (!file_exists('/usr/local/sbin/unraid-api') || !file_exists('/usr/local/bin/unraid-api/unraid-api')) {
|
||||
response_complete(406, array('error' => 'Please reinstall the My Servers plugin'));
|
||||
}
|
||||
|
||||
switch ($command) {
|
||||
case 'start':
|
||||
$output = implode(PHP_EOL, $output);
|
||||
response_complete(200, array('result' => $output), $output);
|
||||
break;
|
||||
case 'restart':
|
||||
exec('unraid-api restart 2>/dev/null', $output, $retval);
|
||||
$output = implode(PHP_EOL, $output);
|
||||
response_complete(200, array('result' => $output), $output);
|
||||
break;
|
||||
case 'stop':
|
||||
exec('unraid-api stop 2>/dev/null', $output, $retval);
|
||||
$output = implode(PHP_EOL, $output);
|
||||
response_complete(200, array('result' => $output), $output);
|
||||
break;
|
||||
case 'report':
|
||||
$flag = ($param1 && ($param1=='-v' || $param1=='-vv'))
|
||||
? ($param1=='-vv' ? '-vv' : '-v')
|
||||
: '';
|
||||
exec("unraid-api report {$flag} —-raw 2>/dev/null", $output, $retval);
|
||||
$output = implode(PHP_EOL, $output);
|
||||
response_complete(200, array('result' => $output), $output);
|
||||
break;
|
||||
case 'wanip':
|
||||
$wanip = trim(@file_get_contents("https://wanip4.unraid.net/"));
|
||||
response_complete(200, array('result' => $wanip), $wanip);
|
||||
break;
|
||||
case 'none':
|
||||
response_complete(406, array('error' => 'Nothing to do'));
|
||||
break;
|
||||
}
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user