diff --git a/src/etc/inc/plugins.inc.d/opendns.inc b/src/etc/inc/plugins.inc.d/opendns.inc new file mode 100644 index 000000000..4779031c9 --- /dev/null +++ b/src/etc/inc/plugins.inc.d/opendns.inc @@ -0,0 +1,64 @@ + array('opendns_configure_do'), + 'local' => array('opendns_configure_do'), + 'newwanip' => array('opendns_configure_do:1'), + ); +} + +function opendns_configure_do($verbose = false) +{ + global $config; + if (!empty($config['opendns']) && !empty($config['opendns']['enable'])) { + if ($verbose) { + echo 'Configure OpenDNS...'; + flush(); + } + $result = opendns_register($config['opendns']); + syslog(LOG_NOTICE, "opendns response : " . $result); + if ($verbose) { + echo "done.\n"; + } + } +} + +function opendns_register($pconfig) +{ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, sprintf( 'https://updates.opendns.com/nic/update?hostname=%s', $pconfig['host'])); + curl_setopt($ch, CURLOPT_USERPWD, sprintf('%s:%s', $pconfig['username'], $pconfig['password'])); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $output = curl_exec($ch); + curl_close($ch); + return $output; +} diff --git a/src/www/services_opendns.php b/src/www/services_opendns.php index b2cc4fd77..06f60805b 100644 --- a/src/www/services_opendns.php +++ b/src/www/services_opendns.php @@ -30,6 +30,7 @@ require_once("guiconfig.inc"); require_once("system.inc"); require_once("interfaces.inc"); +require_once("plugins.inc.d/opendns.inc"); config_read_array('opendns'); @@ -59,13 +60,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } if (!empty($pconfig['test'])) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, sprintf( 'https://updates.opendns.com/nic/update?hostname=%s', $pconfig['host'])); - curl_setopt($ch, CURLOPT_USERPWD, sprintf('%s:%s', $pconfig['username'], $pconfig['password'])); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $output = curl_exec($ch); - curl_close($ch); - $test_results = explode("\r\n", $output); + $test_results = explode("\r\n", opendns_register($pconfig)); } elseif (count($input_errors) == 0) { $config['opendns']['enable'] = !empty($pconfig['enable']); $config['opendns']['username'] = $pconfig['username'];