Merge pull request #1002 from bergware/master

Expand ipaddr() with protocol; selection
This commit is contained in:
tom mortensen
2022-01-15 07:35:31 -08:00
committed by GitHub
8 changed files with 17 additions and 13 deletions

View File

@@ -42,7 +42,6 @@ $dockerManPaths = [
$ethX = 'eth0';
if (!isset($$ethX)) extract(parse_ini_file("$docroot/state/network.ini",true));
$host = ipaddr($ethX);
$host = is_array($host) ? $host[0] : $host;
// get network drivers
$driver = DockerUtil::driver();

View File

@@ -471,7 +471,7 @@
"flashvendor" => $var['flashVendor'],
"guid" => $var['flashGUID'],
"regGuid" => $var['regGUID'],
"internalip" => is_array(ipaddr()) ? ipaddr()[0] : ipaddr(),
"internalip" => ipaddr(),
"internalport" => $_SERVER['SERVER_PORT'],
"keyfile" => str_replace(['+','/','='], ['-','_',''], trim(base64_encode(@file_get_contents($var['regFILE'])))),
"osVersion" => $var['version'],

View File

@@ -67,7 +67,7 @@ if ($certPresent) {
$dnsRebindingProtection = ($rebindtest_ip != $rebindip);
if (!$dnsRebindingProtection) {
$certtest_ip = exec("host $protocol $subjectURL 2>/dev/null|awk '{print \$4}'");
$dnsValid = is_array($addr) ? in_array($certtest_ip, $addr) : $certtest_ip==$addr;
$dnsValid = $certtest_ip==$addr;
}
// more: similar test for "www.$certSubject" dns valid goes here
}
@@ -86,7 +86,7 @@ $portsInUse = [];
exec("lsof -Pni|awk '/LISTEN/ && \$9!~/127.0.0.1/ && \$9!~/\\[::1\\]/{print \$9}'|sort -u", $output);
$bind = $var['BIND_MGT']=='yes';
$list = is_array($addr) ? array_merge(['*'],$addr) : ['*',$addr];
$list = ['*',$addr];
foreach ($output as $line) {
[$ip, $port] = my_explode(':', $line);
@@ -119,7 +119,7 @@ function updateDNS(button) {
var success = function(data) {
$(button).prop("disabled", false).html("_(Update DNS)_");
<?$text = _('Your local IP address %s has been updated for unraid.net')?>
swal({title:"",text:"<?=sprintf($text,is_array($addr)?$addr[0]:$addr)?>",type:"success",html:true,confirmButtonText:"_(Ok)_"});
swal({title:"",text:"<?=sprintf($text,$addr)?>",type:"success",html:true,confirmButtonText:"_(Ok)_"});
};
$.post("/webGui/include/UpdateDNS.php",success).fail(failure);
}

View File

@@ -28,7 +28,7 @@ exec("lsof -Pni|awk '/LISTEN/ && \$9!~/127.0.0.1/ && \$9!~/\\[::1\\]/{print \$9}
$ethX = 'eth0';
$addr = ipaddr($ethX);
$bind = $var['BIND_MGT']=='yes';
$list = is_array($addr) ? array_merge(['*'],$addr) : ['*',$addr];
$list = ['*',$addr];
foreach ($output as $line) {
[$ip, $port] = my_explode(':', $line);

View File

@@ -131,7 +131,6 @@ $template = "$docroot/webGui/WGX.page";
$tower = $var['NAME'];
$ethX = 'eth0';
$server = ipaddr($ethX);
$server = is_array($server) ? $server[0] : $server;
$dnsserver = $$ethX['DNS_SERVER1'];
$link = iflink($ethX);

View File

@@ -77,7 +77,7 @@ $ch = curl_init("https://keys.lime-technology.com/account/ssl/$endpoint");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'internalip' => is_array($internalip) ? $internalip[0] : $internalip,
'internalip' => $internalip,
'internalport' => $internalport,
'keyfile' => $keyfile
]);

View File

@@ -19,7 +19,7 @@ require_once "$docroot/webGui/include/Helpers.php";
// add 'ipaddr' function for 6.9 backwards compatibility
if (!function_exists('ipaddr')) {
function ipaddr($ethX='eth0') {
function ipaddr($ethX='eth0', $prot=4) {
global $$ethX;
switch ($$ethX['PROTOCOL:0']) {
case 'ipv4':
@@ -27,7 +27,10 @@ if (!function_exists('ipaddr')) {
case 'ipv6':
return $$ethX['IPADDR6:0'];
case 'ipv4+ipv6':
return [$$ethX['IPADDR:0'],$$ethX['IPADDR6:0']];
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'];
}
@@ -283,7 +286,7 @@ $post = [
];
if ($isCertUnraidNet) {
// if there is an unraid.net cert, enable local ddns regardless of use_ssl value
$post['internalip'] = is_array($internalip) ? $internalip[0] : $internalip;
$post['internalip'] = $internalip;
// if DNS Rebind Protection is disabled and host.unraid.net does not resolve to the internalip, disable caching
if ($rebindDisabled && host_lookup_ip(generate_internal_host($certhostname, $post['internalip'])) != $post['internalip']) $dnserr = true;
}

View File

@@ -67,7 +67,7 @@ function port_name($port) {
function exceed($value, $limit, $top=100) {
return ($value>$limit && $limit>0 && $value<=$top);
}
function ipaddr($ethX='eth0') {
function ipaddr($ethX='eth0', $prot=4) {
global $$ethX;
switch ($$ethX['PROTOCOL:0']) {
case 'ipv4':
@@ -75,7 +75,10 @@ function ipaddr($ethX='eth0') {
case 'ipv6':
return $$ethX['IPADDR6:0'];
case 'ipv4+ipv6':
return [$$ethX['IPADDR:0'],$$ethX['IPADDR6:0']];
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'];
}