"", "wanaccess" => "no", "wanport" => "443" ]; } if (empty($remote['wanport'])) { $remote['wanport'] = 443; } // remoteaccess, externalport if ($cli) { $remoteaccess = $remote['wanaccess']; $externalport = $remote['wanport']; } else { $remoteaccess = $_POST['remoteaccess']; $externalport = intval($_POST['externalport']); if ($remoteaccess != 'yes') { $remoteaccess = 'no'; } if ($externalport < 1 || $externalport > 65535) { $externalport = 443; } if ($remote['wanaccess'] != $remoteaccess) { // update the wanaccess ini value $orig = @parse_ini_file('/boot/config/plugins/dynamix.my.servers/myservers.cfg',true); if ($orig === false) { $orig = ['remote' => $remote]; } $orig['remote']['wanaccess'] = $remoteaccess; $text = ''; foreach ($orig as $section => $block) { $pairs = ""; foreach ($block as $key => $value) if (strlen($value)) $pairs .= "$key=\"$value\"\n"; if ($pairs) $text .= "[$section]\n".$pairs; } if ($text) file_put_contents('/boot/config/plugins/dynamix.my.servers/myservers.cfg', $text); // reload nginx exec("/etc/rc.d/rc.nginx reload &>/dev/null"); } } $isRegistered = !empty($remote) && !empty($remote['username']); $certhostname = ''; $certPath = '/boot/config/ssl/certs/certificate_bundle.pem'; $hasCert = file_exists($certPath); if ($hasCert) { $certhostname = trim(exec("/usr/bin/openssl x509 -subject -noout -in ".escapeshellarg($certPath)." | awk -F' = ' '{print $2}'")); $isCertUnraidNet = preg_match('/.*\.(my)?unraid\.net$/', $certhostname); if (!$isCertUnraidNet) { // handle custom wildcard certs $certhostname = str_replace('*', $var['NAME'], $certhostname); } } // protocols, hostnames, ports $internalprotocol = 'http'; $internalport = $var['PORT']; $internalhostname = $var['NAME'] . (empty($var['LOCAL_TLD']) ? '' : '.'.$var['LOCAL_TLD']); $externalprotocol = 'https'; $externalhostname = $certhostname; if ($var['USE_SSL']!='no' && $hasCert) { $internalprotocol = 'https'; $internalport = $var['PORTSSL']; $internalhostname = $certhostname; } // only proceed when when signed in (or when (my)?unraid.net SSL certificate is active in 6.10.0-rc1 and earlier) $requireAuth = !version_compare($var['version'], '6.10.0-rc1', '<='); if (($requireAuth && !$isRegistered) || (!$requireAuth && !$isRegistered && !$isCertUnraidNet)) { response_complete(406, '{"error":"'._('Nothing to do').'"}'); } // keyfile $keyfile = @file_get_contents($var['regFILE']); if ($keyfile === false) { response_complete(406, '{"error":"'._('Registration key required').'"}'); } $keyfile = @base64_encode($keyfile); // internalip extract(parse_ini_file('/var/local/emhttp/network.ini',true)); $ethX = 'eth0'; $internalip = ipaddr($ethX); // My Servers version $plgversion = trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net*.plg 2>/dev/null')); // DNS Rebind Protection $rebindDisabled = (host_lookup_ip("rebindtest.unraid.net") == "192.168.42.42"); // build post array $post = [ 'keyfile' => $keyfile, 'plgversion' => $plgversion ]; if ($isCertUnraidNet) { // if there is an unraid.net cert, enable local ddns regardless of use_ssl value $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; } if ($isRegistered) { $post['internalhostname'] = $internalhostname; $post['internalport'] = $internalport; $post['internalprotocol'] = $internalprotocol; $post['remoteaccess'] = $remoteaccess; $post['servercomment'] = $var['COMMENT']; $post['servername'] = $var['NAME']; if ($remoteaccess == 'yes') { // include wanip in the cache file so we can track if it changes $post['_wanip'] = trim(@file_get_contents("https://wanip4.unraid.net/")); $post['externalhostname'] = $externalhostname; $post['externalport'] = $externalport; $post['externalprotocol'] = $externalprotocol; // if wanip.hash.myunraid.net or www.hash.unraid.net does not resolve to the wanip, disable caching if (host_lookup_ip(generate_external_host($post['externalhostname'], $post['_wanip'])) != $post['_wanip']) $dnserr = true; } } // maxage is 36 hours $maxage = 36*60*60; if ($dnserr || $verbose) $maxage = 0; $datafile = "/tmp/UpdateDNS.txt"; $dataprev = @file_get_contents($datafile) ?: ''; $datanew = implode("\n",$post)."\n"; if ($datanew == $dataprev && (time()-filemtime($datafile) < $maxage)) { response_complete(204, null, _('No change to report')); } file_put_contents($datafile,$datanew); // do not submit the wanip, it will be captured from the submission if needed for remote access unset($post['_wanip']); // report necessary server details to limetech for DNS updates $ch = curl_init('https://keys.lime-technology.com/account/server/register'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); if ($result === false) { // delete cache file to retry submission on next run @unlink($datafile); response_complete(500, '{"error":"'.$error.'"}'); } response_complete($httpcode, $result, _('success')); ?>