OpenDNS missing its own configure hooks (hidden in dyndns), move to core

This commit is contained in:
Ad Schellevis 2019-08-22 15:20:56 +02:00
parent 6bac85d66a
commit a3a07327cb
2 changed files with 66 additions and 7 deletions

View File

@ -0,0 +1,64 @@
<?php
/*
* Copyright (C) 2019 Deciso B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function opendns_configure()
{
return array(
'bootup' => 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;
}

View File

@ -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'];