function set_dyndns()
 {
     //https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1
     //https://username:password@dynupdate.no-ip.com/nic/update?hostname=mytest.testdomain.com&myip=1.2.3.4
     $command = "/sbin/ifconfig tun1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print \$1}'";
     $localIP = exec($command);
     if ($localIP == "") {
         return;
     }
     $sql = "SELECT * FROM dyndns_settings ";
     $res = $this->settings['dbconn']->query($sql);
     $row = $res->fetch(PDO::FETCH_ASSOC);
     if ($row['DYNDNS_ENABLED'] == 0) {
         return;
     }
     $params = array();
     $params['hostname'] = stripslashes($row['DYNDNS_HOSTNAME']);
     $params['myip'] = $localIP;
     $username = stripslashes($row['DYNDNS_USERNAME']);
     $password = stripslashes($row['DYNDNS_PASSWORD']);
     if ($username == "" || $password == "") {
         return;
     }
     $url = "";
     if ($row['DYNDNS_COMPANY'] == "dyndns") {
         $url = "https://members.dyndns.org/nic/update";
     }
     if ($row['DYNDNS_COMPANY'] == "noip") {
         $url = "https://dynupdate.no-ip.com/nic/update";
     }
     if ($url == "") {
         return;
     }
     $url = $url . '?' . http_build_query($params, '', '&');
     print_r($url);
     $user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
     $user_agent = "User-Agent: openmediavpn/0.0.1 edgar.pisani@gmail.com";
     include_once "include/mycurl.php";
     $curl = new mycurl($url);
     $curl->useAuth(true);
     //$curl->setCert(config::getMainIni('cert'));
     $curl->setName($username);
     $curl->setPass($password);
     $curl->setUserAgent($user_agent);
     $curl->createCurl();
     $result = $curl->getWebPage();
     $status = $curl->getHttpStatus();
     $codes = explode(" ", $result);
     if ($codes[0] == "good" || $codes[0] == "nochg") {
         $row['DYNDNS_RETRIES'] = 0;
     } else {
         //after 3 retries the vpn will be disabled
         $row['DYNDNS_RETRIES']++;
         if ($row['DYNDNS_RETRIES'] >= 3) {
             $row['DYNDNS_ENABLED'] = 0;
         }
     }
     $sql = "UPDATE dyndns_settings SET DYNDNS_RETRIES=" . $row['DYNDNS_RETRIES'] . ",DYNDNS_ENABLED=" . $row['DYNDNS_ENABLED'] . ",DYNDNS_LASTRESPONSE='" . $codes[0] . "'";
     print_r($sql);
     $res = $this->settings['dbconn']->query($sql);
 }
Beispiel #2
0
// simple api for getting ip.
$api_ip = config::getMainIni('api_ip');
if (!$api_ip) {
    $api_ip = 'http://www.os-cms.net/api/your_addr.php';
}
$my_ip = @file_get_contents($api_ip);
if ($my_ip === false) {
    log::error("Could not get your public IP. No check of current DNS settings");
    return;
}
if (!IP::isPublic($my_ip)) {
    log::error("IP {$my_ip} is not public");
}
$my_ip = trim($my_ip);
$my_hostnames = config::getMainIni('my_hostnames');
// if more hosts use a comma seperated list
$url = config::getMainIni('api_url');
$url .= "?hostname={$my_hostnames}&myip={$my_ip}";
$user_agent = "User-Agent: noiphp/0.0.1 dennis.iversen@gmail.com";
$curl = new mycurl($url);
$curl->useAuth(true);
//$curl->setCert(config::getMainIni('cert'));
$email = config::getMainIni('email');
$password = config::getMainIni('password');
$curl->setName($email);
$curl->setPass($password);
$curl->setUserAgent($user_agent);
$curl->createCurl();
$result = $curl->getWebPage();
log::error($result);
die;