Skip to content

Commit

Permalink
add CNAME
Browse files Browse the repository at this point in the history
  • Loading branch information
osnosn committed Oct 11, 2022
1 parent 4079bb5 commit 859b809
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

简单又实用的动态域名管理系统
使用 bind9 + php + mysql , 创建个人的动态域名系统。
Use bind9 + php + mysql , create a personal ddns server, update by an URL. Only support "A","AAAA","TXT" recorder.
Use bind9 + php + mysql , create a personal ddns server, update by an URL. Only support "A","AAAA","TXT","CNAME" recorder.

#### 条件
- 首先,需要一个有管理权的域名。
Expand Down Expand Up @@ -98,5 +98,9 @@ Use bind9 + php + mysql , create a personal ddns server, update by an URL. Only
- 强制指定TXT内容
`wget http://www.mydomain.net/ddns/ddns.php?key=xxxxxxxxx&domain=dddd&ip=20181015abcdefg`

- 如果是 CNAME 记录
- 强制指定CNAME内容
`wget http://www.mydomain.net/ddns/ddns.php?key=xxxxxxxxx&domain=dddd&ip=abc.def.ghi.jk`

write at 2019-03-24.
--- end ---
20 changes: 11 additions & 9 deletions ddns/adm1.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
$hrectype=1;
if(isset($_POST['domain'])) $hdomain=trim($_POST['domain']);
if(isset($_POST['rectype'])) $hrectype=intval($_POST['rectype']);
if($hrectype<1 or $hrectype>3) $hrectype=1;
if($hrectype<1 or $hrectype>4) $hrectype=1;
do {
if(strlen($hdomain)<1) {
$errmsg='domain empty';
Expand Down Expand Up @@ -184,6 +184,8 @@
$hip='20180101txt_string';
}else if ($hrectype==3) { // AAAA 记录
$hip='::1';
}else if ($hrectype==4) { // CNAME 记录
$hip='test.test.';
}else { // A 记录
$hip='127.0.0.1';
}
Expand All @@ -203,7 +205,7 @@
echo '</td><td>'."\n";
echo '<input type=text name=domain size=8 style="text-align:right">'.$config_dot_zone;
echo '</td><td>'."\n";
echo '<select name="rectype"><option value=1>A</option><option value=2>TXT</option><option value=3>AAAA</option></select>'."\n";
echo '<select name="rectype"><option value=1>A</option><option value=2>TXT</option><option value=3>AAAA</option><option value=4>CNAME</option></select>'."\n";
echo '</td><td>'."\n";
echo '<input type=submit name=submit value="Add">';
echo '</td></tr>'."\n";
Expand Down Expand Up @@ -351,11 +353,11 @@

function mylog($s){
global $log_file;
$fp=fopen($log_file,'a');
flock($fp,LOCK_EX);
fputs($fp,date('Y-m-d.H:i:s ').$_SERVER['REMOTE_ADDR'].' adm:');
fputs($fp,$s);
fputs($fp,"\n");
flock($fp,LOCK_UN);
fclose($fp);
$fp=fopen($log_file,'a');
flock($fp,LOCK_EX);
fputs($fp,date('Y-m-d.H:i:s ').$_SERVER['REMOTE_ADDR'].' adm:');
fputs($fp,$s);
fputs($fp,"\n");
flock($fp,LOCK_UN);
fclose($fp);
}
8 changes: 7 additions & 1 deletion ddns/adm_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
echo '<tr><td>user</td><td colspan=2>'. $user ."</td></tr>\n";
echo '<tr><td>key</td><td colspan=2>'. $bkey ."</td></tr>\n";
echo '<tr><td>last update</td><td colspan=2>'. $btime ."</td></tr>\n";
echo '<tr><td>IP '.($brectype==2?'(TXT)':'').'</td><td>'. $bip .'</td><td width="180px">'."\n";
echo '<tr><td>IP '.($brectype==2?'(TXT)':'').($brectype==4?'(CNAME)':'').'</td><td>'. $bip .'</td><td width="180px">'."\n";
echo '删除这个域名';
echo '<input type=checkbox name=deldomain value="DEL" style="font-size:12px">';
echo '<input type=submit name=submit value="DEL" style="font-size:12px">';
Expand Down Expand Up @@ -216,6 +216,12 @@
echo 'TXT的字符串内容写在ip参数中 , 如TXT指定为"20181015abcdefg"<br>';
echo '&nbsp; &nbsp; ';
echo 'http://'.$config_link.'/ddns.php?key='.$bkey.'&domain='.urlencode($bdomain).'&ip=20181015abcdefg';
} else if($brectype==4) {
echo '指定内容更新: <br>';
echo '&nbsp; &nbsp; &nbsp; &nbsp; ';
echo 'CNAME的内容写在ip参数中 , 如CNAME指定为"abc.123.def.jk"<br>';
echo '&nbsp; &nbsp; ';
echo 'http://'.$config_link.'/ddns.php?key='.$bkey.'&domain='.urlencode($bdomain).'&ip=abc.123.def.jk';
} else {
echo '指定内容更新: <br>';
echo '&nbsp; &nbsp; ';
Expand Down
4 changes: 2 additions & 2 deletions ddns/check_domain.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
function check_domain($domain,$type) { // 1=A,2=TXT
function check_domain($domain,$type) { // 1=A,2=TXT,3=AAAA,4=CNAME
// 检查域名前后不能有小数点,不能是连字符
$domainLen=strlen($domain);
if($domain{0}=='.' || $domain{$domainLen-1}=='.'
Expand All @@ -12,7 +12,7 @@ function check_domain($domain,$type) { // 1=A,2=TXT
if(preg_match('/^[0-9a-z_`~!@#$%^&*()\[\]{}|+=<>,?\/.-]+$/',$domain)<1) {
return 'domain中字符不合法,添加失败. ';
}
} else { // A或AAAA记录
} else { // A或AAAA或CNAME记录
// 域名不能有非法字符
if(preg_match('/^[0-9a-z.-]+$/',$domain)<1) {
// 只能由'a-z0-9' 和 '-' 组成,不区分大小写
Expand Down
2 changes: 2 additions & 0 deletions ddns/ddns.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
// 检查ip格式
$ip='::1';
}
} else if($brectype==4) { // CNAME记录
if(strlen($ip)>250) $ip=substr($ip,0,250);
}

$chged=0;
Expand Down
2 changes: 1 addition & 1 deletion ddns/ddns_update_cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
$bip=$vv->ip;
$bchged=$vv->changed;
$nsupdate_txt.='update delete '.$bdomain.$config_dot_zone.' '.$brectype."\n";
if(strcmp($brectype,'TXT')==0) {
if(strcmp($brectype,'TXT')==0 || strcmp($brectype,'CNAME')==0) {
$nsupdate_txt.='update add '.$bdomain.$config_dot_zone.' 60 '.$brectype.' '.$bip."\n";
} else { // A 和 AAA 记录
$nsupdate_txt.='update add '.$bdomain.$config_dot_zone.' 600 '.$brectype.' '.$bip."\n";
Expand Down
2 changes: 1 addition & 1 deletion ddns/readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
num tinyint default 5, -- 此用户可以添加的记录数
time timestamp default 0, -- 更新时间
domain char(16) not null, -- 子域名
rectype tinyint default 1, -- 记录类型 1=A,2=TXT,3=AAAA,
rectype tinyint default 1, -- 记录类型 1=A,2=TXT,3=AAAA,4=CNAME,
ip varchar(255) not null, -- 记录内容
changed tinyint default 0, -- 记录是否改变过
PRIMARY KEY (id),
Expand Down
2 changes: 2 additions & 0 deletions ddns/rectype.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function rectype($typ) {
case 1: return 'A';break;
case 2: return 'TXT';break;
case 3: return 'AAAA';break;
case 4: return 'CNAME';break;
default: return 'UNKNOWN';
}
}
Expand All @@ -12,6 +13,7 @@ function rectype_num($typ) {
case 'A': return 1;break;
case 'TXT': return 2;break;
case 'AAAA': return 3;break;
case 'CNAME': return 4;break;
default: return -1;
}
}

0 comments on commit 859b809

Please sign in to comment.