public static function update() { // system("echo '" . $as->getSystemValue('dbtype') . "' > /srv/www/htdocs/owncloud/test"); $app = new Application(); $c = $app->getContainer(); $as = $c->query('OCA\\OCIPv6\\Service\\AuthorService'); $hostname = $as->getAppValue('hostname'); $token = $as->getAppValue('token'); $last_ip = $as->getAppValue('last_ip'); if ($hostname && $token && !empty($hostname) && !empty($token)) { exec("ip -6 a s scope global", $output, $ret); $current_ip = join($output); if ($last_ip != $current_ip) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://dynv6.com/api/update?hostname=" . $hostname . "&ipv6=auto&token=" . $token); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $head = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode == 200) { $as->setAppValue('last_ip', $current_ip); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://ipv4.dynv6.com/api/update?hostname=" . $hostname . '&ipv4=auto&token=' . $token); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $head = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } } $upnp = $as->getAppValue('upnp'); $port = $as->getAppValue('upnp_port'); if (preg_match('/^[0-9.]+$/', $upnp)) { exec("upnpc -l", $output, $ret); $intip = ""; foreach ($output as $i) { if (preg_match('/.*TCP[[:blank:]]*443->([0-9.]+):443/', $i, $match)) { $intip = $match[1]; } } if ($intip != $upnp) { exec("upnpc -d 443 TCP", $output, $ret); exec("upnpc -d {$port} TCP", $output, $ret); exec("upnpc -a {$upnp} {$port} {$port} TCP", $output, $ret); } } }
/** * @AdminRequired */ public function SetuPnP($ip) { \OCP\JSON::setContentTypeHeader('application/json'); $app = new Application(); $c = $app->getContainer(); $as = $c->query('OCA\\OCIPv6\\Service\\AuthorService'); exec("upnpc -d 443 TCP", $output, $ret); $port = $as->getAppValue('upnp_port'); exec("upnpc -d {$port} TCP", $output, $ret); if (preg_match('/^[0-9.]+$/', $ip)) { exec("upnpc -a {$ip} 443 443 TCP", $output, $ret); if ($ret != 0 || !preg_match('/:443 TCP is redirected to internal/', array_pop($output), $match)) { exec("upnpc -a {$ip} 4443 4443 TCP", $output, $ret); $port = 4443; } if ($ret == 0) { $as->setAppValue('upnp', $ip); $as->setAppValue('upnp_port', $port); return new JSONResponse(array('result' => $ret)); } } $as->setAppValue('upnp', ''); $as->setAppValue('upnp_port', '443'); return new JSONResponse(array('result' => $ret)); }