1 Star 0 Fork 0

JourneyBean/bind9-ddns-scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api.php 4.47 KB
一键复制 编辑 原始数据 按行查看 历史
JourneyBean 提交于 2020-10-06 23:09 . v1.0.5 bugfix
<?php
/**
* api.php
*
* Index file handling input data
*
* @author Johnson Liu
* @version v1.1
*
*/
// ini_set('display_errors', 'on');
require_once(__DIR__ . '/libNsdata.php');
require_once(__DIR__ . '/libIpPool.php');
require_once(__DIR__ . '/libConfig.php');
loadConfig();
$input_key = $_GET['key'];
$input_action = $_GET['action'];
if ($input_key == getSecret()) {
// Auth success
switch($input_action) {
case 'new_zone':
if ($_GET['name']) {
echo "[ddns-server] " . "[INFO] Adding zone [" . $_GET['name'] . "]\n";
addZone($_GET['name'], $_GET['v4_addr'], $_GET['v6_addr'], $_GET['v6_prefix'], $_GET['v6_cidr']);
};
break;
case 'new_client':
if ($_GET['name']) {
echo "[ddns-server] " . "[INFO] Adding client [" . $_GET['name'] . "]\n";
addClient($_GET['name'], $_GET['v4_addr'], $_GET['v6_addr'], $_GET['v6_suffix']);
};
break;
case 'mod_zone':
if ($_GET['name'] && getZoneByName($_GET['name'])) {
echo "[ddns-server] " . "[INFO] Modifying zone [" . $_GET['name'] . "]\n";
modifyZoneByName($_GET['name'], $_GET['name'], $_GET['v4_addr'], $_GET['v6_addr'], $_GET['v6_prefix'], $_GET['v6_cidr']);
} else {
echo "[ddns-server] " . "[ERR] Invalid parameters." . "\n";
}
break;
case 'mod_client':
if ($_GET['name'] && getClientByName($_GET['name'])) {
echo "[ddns-server] " . "[INFO] Modifying client [" . $_GET['name'] . "]\n";
modifyClientByName($_GET['name'], $_GET['name'], $_GET['v4_addr'], $_GET['v6_addr'], $_GET['v6_suffix']);
} else {
echo "[ddns-server] " . "[ERR] Invalid parameters." . "\n";
}
break;
case 'update_zone':
if ($_GET['name'] && getZoneByName($_GET['name'])) {
echo "[ddns-server] " . "[INFO] Updating zone [" . $_GET['name'] . "]\n";
updateZoneByName($_GET['name'], $_GET['name'], $_GET['v4_addr'], $_GET['v6_addr'], $_GET['v6_prefix'], $_GET['v6_cidr']);
} else {
echo "[ddns-server] " . "[ERR] Invalid parameters." . "\n";
}
break;
case 'update_client':
if ($_GET['name'] && getClientByName($_GET['name'])) {
echo "[ddns-server] " . "[INFO] Updating client [" . $_GET['name'] . "]\n";
updateClientByName($_GET['name'], $_GET['name'], $_GET['v4_addr'], $_GET['v6_addr'], $_GET['v6_suffix']);
} else {
echo "[ddns-server] " . "[ERR] Invalid parameters." . "\n";
}
break;
case 'del_zone':
if ($_GET['name']) {
echo "[ddns-server] " . "[INFO] Deleting zone [" . $_GET['name'] . "]\n";
deleteZoneByName($_GET['name']);
} else {
echo "[ddns-server] " . "[ERR] Invalid parameters." . "\n";
}
break;
case 'del_client':
if ($_GET['name']) {
echo "[ddns-server] " . "[INFO] Deleting client [" . $_GET['name'] . "]\n";
deleteClientByName($_GET['name']);
} else {
echo "[ddns-server] " . "[ERR] Invalid parameters." . "\n";
}
break;
default:
echo "[ddns-server] " . "[ERR] Operation not supported." . "\n";
exit;
}
} else {
// Auth failed
echo "[ddns-server] " . "[ERR] Authentication failed." . "\n";
exit;
}
// write config.php
saveConfig();
// old nsdata
if (file_exists(getZonefilePath())) {
$nsdata_old = file_get_contents(getZonefilePath());
} else {
$nsdata_old = '';
}
// new nsdata generated with old serial
$ip_pool = getIpPool();
$nsdata_raw = readNsdata();
$serial_old = getSerialOld();
$nsdata = translateNsdata($ip_pool, $nsdata_raw, $serial_old);
// compare nsdata
if ($nsdata_old == $nsdata) {
echo "[ddns-server] " . "[INFO] Same profile. Ignoring update request." . "\n";
exit;
}
// write nsdata
$serial = date('YmdH');
$nsdata = translateNsdata($ip_pool, $nsdata_raw, $serial);
$GLOBALS['config']['serial'] = $serial;
file_put_contents(getZonefilePath(), $nsdata);
// inform bind9 to reload
echo "[ddns-server] " . "[INFO] ";
system('rndc reload');
// write config.php
saveConfig();
echo "[ddns-server] " . "[OK] Script exec success." . "\n";
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/journeybean/bind9-ddns-scripts.git
[email protected]:journeybean/bind9-ddns-scripts.git
journeybean
bind9-ddns-scripts
bind9-ddns-scripts
master

搜索帮助