diff --git a/.history/app/controller/DnsController_20221217221940 b/.history/app/controller/DnsController_20221217221940 new file mode 100644 index 0000000..e69de29 diff --git a/.history/app/controller/DnsController_20221217222004 b/.history/app/controller/DnsController_20221217222004 new file mode 100644 index 0000000..644bff2 --- /dev/null +++ b/.history/app/controller/DnsController_20221217222004 @@ -0,0 +1,22 @@ + 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217222441.php b/.history/app/controller/DnsController_20221217222441.php new file mode 100644 index 0000000..059fcee --- /dev/null +++ b/.history/app/controller/DnsController_20221217222441.php @@ -0,0 +1,30 @@ +id; + $send['query']=$data->query; + + $return=json_encode($send) + return $return; + } + + public function view(Request $request) + { + return view('index/view', ['name' => 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217222442 b/.history/app/controller/DnsController_20221217222442 new file mode 100644 index 0000000..059fcee --- /dev/null +++ b/.history/app/controller/DnsController_20221217222442 @@ -0,0 +1,30 @@ +id; + $send['query']=$data->query; + + $return=json_encode($send) + return $return; + } + + public function view(Request $request) + { + return view('index/view', ['name' => 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217222849.php b/.history/app/controller/DnsController_20221217222849.php new file mode 100644 index 0000000..8fb05d1 --- /dev/null +++ b/.history/app/controller/DnsController_20221217222849.php @@ -0,0 +1,30 @@ +id; + $send['query']=$data->query; + + $return=json_encode($send); + return $return; + } + + public function view(Request $request) + { + return view('index/view', ['name' => 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217222936.php b/.history/app/controller/DnsController_20221217222936.php new file mode 100644 index 0000000..f0f9fe6 --- /dev/null +++ b/.history/app/controller/DnsController_20221217222936.php @@ -0,0 +1,30 @@ +id; + $send['query']=$data->query; + + $return=json_encode($send); + return $return; + } + + public function view(Request $request) + { + return view('index/view', ['name' => 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223042.php b/.history/app/controller/DnsController_20221217223042.php new file mode 100644 index 0000000..d777e21 --- /dev/null +++ b/.history/app/controller/DnsController_20221217223042.php @@ -0,0 +1,30 @@ + 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223130.php b/.history/app/controller/DnsController_20221217223130.php new file mode 100644 index 0000000..cc85397 --- /dev/null +++ b/.history/app/controller/DnsController_20221217223130.php @@ -0,0 +1,31 @@ + 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223139.php b/.history/app/controller/DnsController_20221217223139.php new file mode 100644 index 0000000..cc85397 --- /dev/null +++ b/.history/app/controller/DnsController_20221217223139.php @@ -0,0 +1,31 @@ + 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223236.php b/.history/app/controller/DnsController_20221217223236.php new file mode 100644 index 0000000..65247e6 --- /dev/null +++ b/.history/app/controller/DnsController_20221217223236.php @@ -0,0 +1,34 @@ + 'webman']); + } + + public function json(Request $request) + { + return json(['code' => 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223419.php b/.history/app/controller/DnsController_20221217223419.php new file mode 100644 index 0000000..7737ec1 --- /dev/null +++ b/.history/app/controller/DnsController_20221217223419.php @@ -0,0 +1,42 @@ + 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223433.php b/.history/app/controller/DnsController_20221217223433.php new file mode 100644 index 0000000..305e6a9 --- /dev/null +++ b/.history/app/controller/DnsController_20221217223433.php @@ -0,0 +1,46 @@ + 0, 'msg' => 'ok']); + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217223504.php b/.history/app/controller/DnsController_20221217223504.php new file mode 100644 index 0000000..6de7bec --- /dev/null +++ b/.history/app/controller/DnsController_20221217223504.php @@ -0,0 +1,56 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224046.php b/.history/app/controller/DnsController_20221217224046.php new file mode 100644 index 0000000..ebf5c17 --- /dev/null +++ b/.history/app/controller/DnsController_20221217224046.php @@ -0,0 +1,86 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224155.php b/.history/app/controller/DnsController_20221217224155.php new file mode 100644 index 0000000..06c6010 --- /dev/null +++ b/.history/app/controller/DnsController_20221217224155.php @@ -0,0 +1,117 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224247.php b/.history/app/controller/DnsController_20221217224247.php new file mode 100644 index 0000000..cd27abd --- /dev/null +++ b/.history/app/controller/DnsController_20221217224247.php @@ -0,0 +1,149 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224408.php b/.history/app/controller/DnsController_20221217224408.php new file mode 100644 index 0000000..5449dad --- /dev/null +++ b/.history/app/controller/DnsController_20221217224408.php @@ -0,0 +1,150 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224410.php b/.history/app/controller/DnsController_20221217224410.php new file mode 100644 index 0000000..2049e4b --- /dev/null +++ b/.history/app/controller/DnsController_20221217224410.php @@ -0,0 +1,150 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224446.php b/.history/app/controller/DnsController_20221217224446.php new file mode 100644 index 0000000..66773e8 --- /dev/null +++ b/.history/app/controller/DnsController_20221217224446.php @@ -0,0 +1,150 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224558.php b/.history/app/controller/DnsController_20221217224558.php new file mode 100644 index 0000000..29921f1 --- /dev/null +++ b/.history/app/controller/DnsController_20221217224558.php @@ -0,0 +1,150 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224621.php b/.history/app/controller/DnsController_20221217224621.php new file mode 100644 index 0000000..60378e5 --- /dev/null +++ b/.history/app/controller/DnsController_20221217224621.php @@ -0,0 +1,150 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['type']='CNAME'; + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217224945.php b/.history/app/controller/DnsController_20221217224945.php new file mode 100644 index 0000000..eedc839 --- /dev/null +++ b/.history/app/controller/DnsController_20221217224945.php @@ -0,0 +1,149 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217225003.php b/.history/app/controller/DnsController_20221217225003.php new file mode 100644 index 0000000..376f9bb --- /dev/null +++ b/.history/app/controller/DnsController_20221217225003.php @@ -0,0 +1,155 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217225031.php b/.history/app/controller/DnsController_20221217225031.php new file mode 100644 index 0000000..05ba830 --- /dev/null +++ b/.history/app/controller/DnsController_20221217225031.php @@ -0,0 +1,162 @@ +ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理,请按照本方式传递16进制无":"的完整16位IPv6 + $send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96")); + $send['ttl']=30; + + + $send['type']='AAAA'; + */ + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function NS($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='coco.bunny.net'; + $send['detail'][2]='kiki.bunny.net'; + $send['ttl']=600; + + $send['type']='NS'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function CNAME($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='baidu.cn'; + $send['detail'][2]='baidu.com'; + $send['ttl']=600; + + $send['type']='CNAME'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function TEXT($type,$name,$rip,$id,$query) + { + + $send['detail'][1]='text1-test'; + $send['detail'][2]='text2-test'; + $send['ttl']=600; + + $send['type']='TEXT'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function MX($type,$name,$rip,$id,$query) + { + + $send['detail'][1]['name']='mx.zoho.com'; + $send['detail'][1]['pre']='20'; #权重 + $send['detail'][2]['name']='mx2.zoho.com'; + $send['detail'][2]['pre']='30'; #权重 + $send['detail'][3]['name']='mx3.zoho.com'; + $send['detail'][3]['pre']='50'; #权重 + $send['ttl']=600; + + $send['type']='MX'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } + + public function SOA($type,$name,$rip,$id,$query) + { + $send['detail']= array(); + + $send['detail']['type']='none'; + $send['detail']['name']=$name; + + /** + * SOA类型,如遇域名存在但无该查询类型的记录时返回 + * 请勿随意填写,本DNS协议将自动向服务器配置的DNS获取SOA + * + * 自行返回SOA记录(不建议)[除非你真的准备直接把域名NS到这里] + * $send['detail']['type']='self'; + * $send['detail']['mname']='dns31.hichina.com'; #主DNS服务器名 + * $send['detail']['rname']='hostmaster.hichina.com'; #DNS管理员邮箱 + * $send['detail']['serial']='2022052002'; #序列号 序列号必须递增 类似于dns记录的版本号 序列号变大时递归dns将更新记录 + * $send['detail']['refresh']='3600'; #区域应当被刷新前的时间间隔 + * $send['detail']['retry']='1200'; #刷新失败重试的时间间隔 + * $send['detail']['expire']='86400'; #规定在区域不再是权威的之前可以等待的时间间隔的上限 + * $send['detail']['minimum-ttl']='600'; #最小TTL + * + * $send['ttl']='180'; #当前TTL + **/ + + + $send['type']='SOA'; + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221217230111.php b/.history/app/controller/DnsController_20221217230111.php new file mode 100644 index 0000000..c87c8bd --- /dev/null +++ b/.history/app/controller/DnsController_20221217230111.php @@ -0,0 +1,28 @@ +ip2bin($ip); + */ + +class DnsController +{ + public function DNS($type,$name,$rip,$id,$query) + { + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + + #此处请根据业务需要,通过判断$name和$rip返回正确的数据 + + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + $send['type']='PTR'; + + + #此处无需修改 + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/app/controller/DnsController_20221218180755.php b/.history/app/controller/DnsController_20221218180755.php new file mode 100644 index 0000000..8c3d2af --- /dev/null +++ b/.history/app/controller/DnsController_20221218180755.php @@ -0,0 +1,33 @@ +ip2bin($ip); + */ + +class DnsController +{ + public function DNS($type,$name,$rip,$id,$query) + { + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + + #此处请根据业务需要,通过判断$name和$rip返回正确的数据 + #详情请参见 https://github.com/ywnsya/workerman-dns 尤其是 https://github.com/ywnsya/Workerman-DNS/blob/master/start.php 中的用法 + + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + $send['type']='PTR'; + + + #此处无需修改 + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221217204856.php b/.history/config/plugin/laysense/dns/process_20221217204856.php new file mode 100644 index 0000000..e69de29 diff --git a/.history/config/plugin/laysense/dns/process_20221217204933.php b/.history/config/plugin/laysense/dns/process_20221217204933.php new file mode 100644 index 0000000..24c6ad3 --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221217204933.php @@ -0,0 +1,9 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\Pusher::class, + 'listen' => 'websocket://0.0.0.0:8888', + 'count' => 1, + ], +]; \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221217205042.php b/.history/config/plugin/laysense/dns/process_20221217205042.php new file mode 100644 index 0000000..6712b62 --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221217205042.php @@ -0,0 +1,9 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\dns\Dns::class, + 'listen' => 'websocket://0.0.0.0:8888', + 'count' => 1, + ], +]; \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221217205122.php b/.history/config/plugin/laysense/dns/process_20221217205122.php new file mode 100644 index 0000000..a056157 --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221217205122.php @@ -0,0 +1,9 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\Dns::class, + 'listen' => 'websocket://0.0.0.0:8888', + 'count' => 1, + ], +]; \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221217205636.php b/.history/config/plugin/laysense/dns/process_20221217205636.php new file mode 100644 index 0000000..5a19464 --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221217205636.php @@ -0,0 +1,11 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 14, + 'count' => 1, + ], +]; \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221217205638.php b/.history/config/plugin/laysense/dns/process_20221217205638.php new file mode 100644 index 0000000..d084aa1 --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221217205638.php @@ -0,0 +1,11 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4, + 'count' => 1, + ], +]; \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221217205659.php b/.history/config/plugin/laysense/dns/process_20221217205659.php new file mode 100644 index 0000000..fcec556 --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221217205659.php @@ -0,0 +1,10 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4 + ], +]; \ No newline at end of file diff --git a/.history/config/plugin/laysense/dns/process_20221218180928.php b/.history/config/plugin/laysense/dns/process_20221218180928.php new file mode 100644 index 0000000..ec5ab5b --- /dev/null +++ b/.history/config/plugin/laysense/dns/process_20221218180928.php @@ -0,0 +1,9 @@ + [ + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4 + ], +]; \ No newline at end of file diff --git a/.history/config/server_20221217203949.php b/.history/config/server_20221217203949.php new file mode 100644 index 0000000..f55ce3c --- /dev/null +++ b/.history/config/server_20221217203949.php @@ -0,0 +1,31 @@ + + * @copyright walkor + * @link http://www.workerman.net/ + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ + +return [ + 'listen' => 'http://0.0.0.0:8787', + 'transport' => 'tcp', + 'context' => [], + 'name' => 'webman', + 'count' => cpu_count() * 4, + 'user' => '', + 'group' => '', + 'reusePort' => false, + 'event_loop' => '', + 'stop_timeout' => 2, + 'pid_file' => runtime_path() . '/webman.pid', + 'status_file' => runtime_path() . '/webman.status', + 'stdout_file' => runtime_path() . '/logs/stdout.log', + 'log_file' => runtime_path() . '/logs/workerman.log', + 'max_package_size' => 10 * 1024 * 1024 +]; diff --git a/.history/config/server_20221217205622.php b/.history/config/server_20221217205622.php new file mode 100644 index 0000000..a65ac6a --- /dev/null +++ b/.history/config/server_20221217205622.php @@ -0,0 +1,31 @@ + + * @copyright walkor + * @link http://www.workerman.net/ + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ + +return [ + 'listen' => 'http://0.0.0.0:8787', + 'transport' => 'tcp', + 'context' => [], + 'name' => 'webman', + 'count' => cpu_count() * 2, + 'user' => '', + 'group' => '', + 'reusePort' => false, + 'event_loop' => '', + 'stop_timeout' => 2, + 'pid_file' => runtime_path() . '/webman.pid', + 'status_file' => runtime_path() . '/webman.status', + 'stdout_file' => runtime_path() . '/logs/stdout.log', + 'log_file' => runtime_path() . '/logs/workerman.log', + 'max_package_size' => 10 * 1024 * 1024 +]; diff --git a/.history/config/server_20221217205625.php b/.history/config/server_20221217205625.php new file mode 100644 index 0000000..b72116a --- /dev/null +++ b/.history/config/server_20221217205625.php @@ -0,0 +1,31 @@ + + * @copyright walkor + * @link http://www.workerman.net/ + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ + +return [ + 'listen' => 'http://0.0.0.0:8787', + 'transport' => 'tcp', + 'context' => [], + 'name' => 'webman', + 'count' => cpu_count() * 1, + 'user' => '', + 'group' => '', + 'reusePort' => false, + 'event_loop' => '', + 'stop_timeout' => 2, + 'pid_file' => runtime_path() . '/webman.pid', + 'status_file' => runtime_path() . '/webman.status', + 'stdout_file' => runtime_path() . '/logs/stdout.log', + 'log_file' => runtime_path() . '/logs/workerman.log', + 'max_package_size' => 10 * 1024 * 1024 +]; diff --git a/.history/process/DnsProcess_20221217210428.php b/.history/process/DnsProcess_20221217210428.php new file mode 100644 index 0000000..dbfe9b4 --- /dev/null +++ b/.history/process/DnsProcess_20221217210428.php @@ -0,0 +1,27 @@ +send($data); + } + + public function onClose(TcpConnection $connection) + { + echo "onClose\n"; + } +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217210754.php b/.history/process/DnsProcess_20221217210754.php new file mode 100644 index 0000000..a51d71f --- /dev/null +++ b/.history/process/DnsProcess_20221217210754.php @@ -0,0 +1,13 @@ +send($data); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217210802.php b/.history/process/DnsProcess_20221217210802.php new file mode 100644 index 0000000..5106b9c --- /dev/null +++ b/.history/process/DnsProcess_20221217210802.php @@ -0,0 +1,14 @@ +send($data); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217211004.php b/.history/process/DnsProcess_20221217211004.php new file mode 100644 index 0000000..3328690 --- /dev/null +++ b/.history/process/DnsProcess_20221217211004.php @@ -0,0 +1,31 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + + $send=json_encode($send); + $connection->send($send); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222328.php b/.history/process/DnsProcess_20221217222328.php new file mode 100644 index 0000000..be6a5e9 --- /dev/null +++ b/.history/process/DnsProcess_20221217222328.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + *// + $return=json_encode($return); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222504.php b/.history/process/DnsProcess_20221217222504.php new file mode 100644 index 0000000..6d6a42b --- /dev/null +++ b/.history/process/DnsProcess_20221217222504.php @@ -0,0 +1,34 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + *// + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222523.php b/.history/process/DnsProcess_20221217222523.php new file mode 100644 index 0000000..8074946 --- /dev/null +++ b/.history/process/DnsProcess_20221217222523.php @@ -0,0 +1,34 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222735.php b/.history/process/DnsProcess_20221217222735.php new file mode 100644 index 0000000..a1179a4 --- /dev/null +++ b/.history/process/DnsProcess_20221217222735.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222745.php b/.history/process/DnsProcess_20221217222745.php new file mode 100644 index 0000000..103acdf --- /dev/null +++ b/.history/process/DnsProcess_20221217222745.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222822.php b/.history/process/DnsProcess_20221217222822.php new file mode 100644 index 0000000..13c745d --- /dev/null +++ b/.history/process/DnsProcess_20221217222822.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222824.php b/.history/process/DnsProcess_20221217222824.php new file mode 100644 index 0000000..8e356e3 --- /dev/null +++ b/.history/process/DnsProcess_20221217222824.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217222828.php b/.history/process/DnsProcess_20221217222828.php new file mode 100644 index 0000000..23a0261 --- /dev/null +++ b/.history/process/DnsProcess_20221217222828.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217223023.php b/.history/process/DnsProcess_20221217223023.php new file mode 100644 index 0000000..c672dd3 --- /dev/null +++ b/.history/process/DnsProcess_20221217223023.php @@ -0,0 +1,35 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip,$data->id,$data->query); + /** + $send['type']='PTR'; + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + + $send['id']=$data->id; + $send['query']=$data->query; + + + */ + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217223058.php b/.history/process/DnsProcess_20221217223058.php new file mode 100644 index 0000000..b21aa5f --- /dev/null +++ b/.history/process/DnsProcess_20221217223058.php @@ -0,0 +1,25 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($name,$rip,$data->id,$data->query); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217223126.php b/.history/process/DnsProcess_20221217223126.php new file mode 100644 index 0000000..dd36c51 --- /dev/null +++ b/.history/process/DnsProcess_20221217223126.php @@ -0,0 +1,25 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($type,$name,$rip,$data->id,$data->query); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217223207.php b/.history/process/DnsProcess_20221217223207.php new file mode 100644 index 0000000..9ed83f7 --- /dev/null +++ b/.history/process/DnsProcess_20221217223207.php @@ -0,0 +1,24 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($type,$name,$rip,$data->id,$data->query); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217224318.php b/.history/process/DnsProcess_20221217224318.php new file mode 100644 index 0000000..54f95de --- /dev/null +++ b/.history/process/DnsProcess_20221217224318.php @@ -0,0 +1,24 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->$type($type,$name,$rip,$data->id,$data->query); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/DnsProcess_20221217230035.php b/.history/process/DnsProcess_20221217230035.php new file mode 100644 index 0000000..3f4f2d5 --- /dev/null +++ b/.history/process/DnsProcess_20221217230035.php @@ -0,0 +1,24 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->DNS($type,$name,$rip,$data->id,$data->query); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/.history/process/Dns_20221217204824.php b/.history/process/Dns_20221217204824.php new file mode 100644 index 0000000..e69de29 diff --git a/.history/process/Dns_20221217204827.php b/.history/process/Dns_20221217204827.php new file mode 100644 index 0000000..fafc916 --- /dev/null +++ b/.history/process/Dns_20221217204827.php @@ -0,0 +1,27 @@ +send($data); + } + + public function onClose(TcpConnection $connection) + { + echo "onClose\n"; + } +} \ No newline at end of file diff --git a/.history/process/dns/Dns_20221217204826.php b/.history/process/dns/Dns_20221217204826.php new file mode 100644 index 0000000..fafc916 --- /dev/null +++ b/.history/process/dns/Dns_20221217204826.php @@ -0,0 +1,27 @@ +send($data); + } + + public function onClose(TcpConnection $connection) + { + echo "onClose\n"; + } +} \ No newline at end of file diff --git a/.history/process/dns/Dns_20221217205100.php b/.history/process/dns/Dns_20221217205100.php new file mode 100644 index 0000000..d90d2aa --- /dev/null +++ b/.history/process/dns/Dns_20221217205100.php @@ -0,0 +1,27 @@ +send($data); + } + + public function onClose(TcpConnection $connection) + { + echo "onClose\n"; + } +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/Install_20221217204513.php b/.history/vendor/laysense/dns/src/Install_20221217204513.php new file mode 100644 index 0000000..c796cca --- /dev/null +++ b/.history/vendor/laysense/dns/src/Install_20221217204513.php @@ -0,0 +1,74 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/Install_20221217210026.php b/.history/vendor/laysense/dns/src/Install_20221217210026.php new file mode 100644 index 0000000..f34b005 --- /dev/null +++ b/.history/vendor/laysense/dns/src/Install_20221217210026.php @@ -0,0 +1,77 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/Install_20221217210128.php b/.history/vendor/laysense/dns/src/Install_20221217210128.php new file mode 100644 index 0000000..677cc4b --- /dev/null +++ b/.history/vendor/laysense/dns/src/Install_20221217210128.php @@ -0,0 +1,78 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/Install_20221217210329.php b/.history/vendor/laysense/dns/src/Install_20221217210329.php new file mode 100644 index 0000000..677cc4b --- /dev/null +++ b/.history/vendor/laysense/dns/src/Install_20221217210329.php @@ -0,0 +1,78 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/Install_20221218180906.php b/.history/vendor/laysense/dns/src/Install_20221218180906.php new file mode 100644 index 0000000..7344322 --- /dev/null +++ b/.history/vendor/laysense/dns/src/Install_20221218180906.php @@ -0,0 +1,80 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + copy(__DIR__ .'/resource/DnsController.php',base_path().'/app/controller/DnsController.php'); + echo "Create DNS Process Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/Install_20221218180911.php b/.history/vendor/laysense/dns/src/Install_20221218180911.php new file mode 100644 index 0000000..1347b4b --- /dev/null +++ b/.history/vendor/laysense/dns/src/Install_20221218180911.php @@ -0,0 +1,80 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + copy(__DIR__ .'/resource/DnsController.php',base_path().'/app/controller/DnsController.php'); + echo "Create Dns Controller Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/config/plugin/laysense/dns/process_20221217210307.php b/.history/vendor/laysense/dns/src/config/plugin/laysense/dns/process_20221217210307.php new file mode 100644 index 0000000..fcec556 --- /dev/null +++ b/.history/vendor/laysense/dns/src/config/plugin/laysense/dns/process_20221217210307.php @@ -0,0 +1,10 @@ + [ + // 这里指定进程类,就是上面定义的Pusher类 + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4 + ], +]; \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/config/plugin/laysense/dns/process_20221218180942.php b/.history/vendor/laysense/dns/src/config/plugin/laysense/dns/process_20221218180942.php new file mode 100644 index 0000000..ec5ab5b --- /dev/null +++ b/.history/vendor/laysense/dns/src/config/plugin/laysense/dns/process_20221218180942.php @@ -0,0 +1,9 @@ + [ + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4 + ], +]; \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/install_20221217210339.backup b/.history/vendor/laysense/dns/src/install_20221217210339.backup new file mode 100644 index 0000000..e69de29 diff --git a/.history/vendor/laysense/dns/src/install_20221217210342.backup b/.history/vendor/laysense/dns/src/install_20221217210342.backup new file mode 100644 index 0000000..677cc4b --- /dev/null +++ b/.history/vendor/laysense/dns/src/install_20221217210342.backup @@ -0,0 +1,78 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/DnsController_20221218180804.php b/.history/vendor/laysense/dns/src/resource/DnsController_20221218180804.php new file mode 100644 index 0000000..8c3d2af --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/DnsController_20221218180804.php @@ -0,0 +1,33 @@ +ip2bin($ip); + */ + +class DnsController +{ + public function DNS($type,$name,$rip,$id,$query) + { + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + + #此处请根据业务需要,通过判断$name和$rip返回正确的数据 + #详情请参见 https://github.com/ywnsya/workerman-dns 尤其是 https://github.com/ywnsya/Workerman-DNS/blob/master/start.php 中的用法 + + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + $send['type']='PTR'; + + + #此处无需修改 + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/DnsController_20221218180808.php b/.history/vendor/laysense/dns/src/resource/DnsController_20221218180808.php new file mode 100644 index 0000000..8c3d2af --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/DnsController_20221218180808.php @@ -0,0 +1,33 @@ +ip2bin($ip); + */ + +class DnsController +{ + public function DNS($type,$name,$rip,$id,$query) + { + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + + #此处请根据业务需要,通过判断$name和$rip返回正确的数据 + #详情请参见 https://github.com/ywnsya/workerman-dns 尤其是 https://github.com/ywnsya/Workerman-DNS/blob/master/start.php 中的用法 + + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + $send['type']='PTR'; + + + #此处无需修改 + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/DnsProcess_20221217205352.php b/.history/vendor/laysense/dns/src/resource/DnsProcess_20221217205352.php new file mode 100644 index 0000000..e69de29 diff --git a/.history/vendor/laysense/dns/src/resource/DnsProcess_20221217205413.php b/.history/vendor/laysense/dns/src/resource/DnsProcess_20221217205413.php new file mode 100644 index 0000000..dbfe9b4 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/DnsProcess_20221217205413.php @@ -0,0 +1,27 @@ +send($data); + } + + public function onClose(TcpConnection $connection) + { + echo "onClose\n"; + } +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/Dns_20221217205338.php b/.history/vendor/laysense/dns/src/resource/Dns_20221217205338.php new file mode 100644 index 0000000..e69de29 diff --git a/.history/vendor/laysense/dns/src/resource/Dns_20221217205733.php b/.history/vendor/laysense/dns/src/resource/Dns_20221217205733.php new file mode 100644 index 0000000..66a4f8c --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/Dns_20221217205733.php @@ -0,0 +1,252 @@ +type; + switch($type){ + case 'A': + $type='0001'; + #$lenth='0004'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'NS': + $type='0002'; + #$lenth='0004'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'PTR': + $type='000C'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'CNAME': + $type='0005'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'SOA': + $type='0006'; + $ns=$buffer->detail; + $ns=json_decode( json_encode( $ns),true); + if($ns['type']=='none'){ + $Rns=dns_get_record($ns['name'],DNS_SOA); + $Rns=$Rns[0]; + $ns=$Rns; + $buffer->ttl=$Rns['ttl']; + } + + $nss=explode('.',$ns['mname']); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'AAAA': + $type='001C'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $detail[$n]="$i"; + $lenth[$n]="0010"; + $n=$n+1; + }; + break; + case 'TEXT': + $type='0010'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $detail[$n]=''; + $text=bin2hex($i); + $tlen=str_pad(dechex((strlen($text)/2)),2,"0",STR_PAD_LEFT); + $detail[$n]=$tlen.$text; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'MX': + $type='000F'; + $ns=$buffer->detail; + $n=0; + + print_r($ns); + + foreach($ns as $i){ + $nss=explode('.',$i->name); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)+2),4,"0",STR_PAD_LEFT).str_pad(dechex($i->pre),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + } + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8180'; + $questions='0001'; + $AnswerRRs=str_pad(count((array)$buffer->detail),4,"0",STR_PAD_LEFT); + #$AnswerRRs='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + $answer=''; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$rlenth.$c; + } + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + } + + /** + * 解包,当接收到的数据字节数等于input返回的值(大于0的值)自动调用 + * 并传递给onMessage回调函数的$data参数 + * @param string $buffer + * @return string + */ + public static function decode($buffer) + { + $data=bin2hex($buffer); + $id=substr($data,0,4); + $type=substr($data,-8,4); + switch($type){ + case '0001': + $type='A'; + break; + case '0002': + $type='NS'; + break; + case '000c': + $type='PTR'; + break; + case '0006': + $type='SOA'; + break; + case '001c': + $type='AAAA'; + break; + case '0005': + $type='CNAME'; + break; + case '0010': + $type='TEXT'; + break; + case '000f': + $type='MX'; + break; + } + $name=substr($data,24,-8); + $namede=str_split($name,2); + $realname=''; + foreach($namede as $cha){ + $chat=hex2bin($cha); + if(!ctype_alnum($chat)){ + $chat='.'; + } + $realname=$realname.$chat; + } + $realname=substr($realname,1,-1); + $query=substr($data,24); + + #$returndata="$type".'|||'."$realname"; + $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); + + return $returndata; + } +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/Dns_20221218180431.php b/.history/vendor/laysense/dns/src/resource/Dns_20221218180431.php new file mode 100644 index 0000000..f44ee5d --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/Dns_20221218180431.php @@ -0,0 +1,419 @@ +type; + switch($type){ + case 'A': + $type='0001'; + #$lenth='0004'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'NS': + $type='0002'; + #$lenth='0004'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'PTR': + $type='000C'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'CNAME': + $type='0005'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'CNAME+A': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_A); + $type='0001'; + $n=0; + foreach($ip as $i){ + $ttl=str_pad(dechex($i['ttl']),8,"0",STR_PAD_LEFT); + $i=$i['ip']; + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + + }; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02B'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'CNAME+AAAA': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_AAAA); + $type='001C'; + $n=0; + foreach($ip as $i){ + $ipv6=$i['ipv6']; + $hexstr = unpack("H*hex", inet_pton($ipv6)); + $ipv6=substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hexstr['hex']), 0, -1); + $ipv6=str_replace(':','',$ipv6); + #$ipv6= bin2hex($ipv6); + $detail[$n]="$ipv6"; + $lenth[$n]="0010"; + $n=$n+1; + }; + + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02C'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'SOA': + $type='0006'; + $ns=$buffer->detail; + $ns=json_decode( json_encode( $ns),true); + if($ns['type']=='none'){ + $Rns=dns_get_record($ns['name'],DNS_SOA); + $Rns=$Rns[0]; + $ns=$Rns; + $buffer->ttl=$Rns['ttl']; + } + + $nss=explode('.',$ns['mname']); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'AAAA': + $type='001C'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $detail[$n]="$i"; + $lenth[$n]="0010"; + $n=$n+1; + }; + break; + case 'TEXT': + $type='0010'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $detail[$n]=''; + $text=bin2hex($i); + $tlen=str_pad(dechex((strlen($text)/2)),2,"0",STR_PAD_LEFT); + $detail[$n]=$tlen.$text; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'MX': + $type='000F'; + $ns=$buffer->detail; + $n=0; + + print_r($ns); + + foreach($ns as $i){ + $nss=explode('.',$i->name); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)+2),4,"0",STR_PAD_LEFT).str_pad(dechex($i->pre),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'none': + $type='0006'; + $ns=$buffer->detail; + $url=$ns; + while(true){ + preg_match("#\.(.*)#i",$url,$match);//获取根域名 + $domin = $match[1]; + $soa=dns_get_record($domin,DNS_SOA); + if(array_key_exists('0',$soa)){ + if(array_key_exists('mname',$soa[0])){ + $qname=$domin; + $ns=$soa[0]; + break; + }else{ + $url=$domin; + } + }else{ + $url=$domin; + } + } + + $nss=explode('.',$ns['mname']); + $detail=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth=str_pad(dechex((strlen($detail)/2)),4,"0",STR_PAD_LEFT); + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8183'; + $questions='0001'; + $AnswerRRs='0000'; + $AuthorityRRs='0001'; + $AdditionalRRs='0000'; + + #$qname + $nss=explode('.',$qname); + $qname=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $qname=$qname.$len.$tpart; + }; + $qname=$qname.'00'; + + $answer=''; + $answer=$answer.$qname.$type.'0001'.$ttl.$lenth.$detail; + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + break; + } + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8180'; + $questions='0001'; + $AnswerRRs=str_pad(count((array)$buffer->detail),4,"0",STR_PAD_LEFT); + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + $answer=''; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$rlenth.$c; + } + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + } + + /** + * 解包,当接收到的数据字节数等于input返回的值(大于0的值)自动调用 + * 并传递给onMessage回调函数的$data参数 + * @param string $buffer + * @return string + */ + public static function decode($buffer) + { + $data=bin2hex($buffer); + $id=substr($data,0,4); + $type=substr($data,-8,4); + switch($type){ + case '0001': + $type='A'; + break; + case '0002': + $type='NS'; + break; + case '000c': + $type='PTR'; + break; + case '0006': + $type='SOA'; + break; + case '001c': + $type='AAAA'; + break; + case '0005': + $type='CNAME'; + break; + case '0010': + $type='TEXT'; + break; + case '000f': + $type='MX'; + break; + } + $name=substr($data,24,-8); + $namede=str_split($name,2); + $realname=''; + foreach($namede as $cha){ + $chat=hex2bin($cha); + if(!ctype_alnum($chat)){ + $chat='.'; + } + $realname=$realname.$chat; + } + $realname=substr($realname,1,-1); + $query=substr($data,24); + + #$returndata="$type".'|||'."$realname"; + $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); + + return $returndata; + } +} \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217223817.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217223817.php new file mode 100644 index 0000000..e69de29 diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217223921.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217223921.php new file mode 100644 index 0000000..68bedf6 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/ipv6_20221217223921.php @@ -0,0 +1,204 @@ + + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217224400.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224400.php new file mode 100644 index 0000000..ef82535 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224400.php @@ -0,0 +1,205 @@ + + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217224432.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224432.php new file mode 100644 index 0000000..f17dbe8 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224432.php @@ -0,0 +1,205 @@ + + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217224436.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224436.php new file mode 100644 index 0000000..65b6a78 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224436.php @@ -0,0 +1,205 @@ + + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217224528.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224528.php new file mode 100644 index 0000000..acf7957 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224528.php @@ -0,0 +1,204 @@ + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/.history/vendor/laysense/dns/src/resource/ipv6_20221217224616.php b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224616.php new file mode 100644 index 0000000..d686a34 --- /dev/null +++ b/.history/vendor/laysense/dns/src/resource/ipv6_20221217224616.php @@ -0,0 +1,204 @@ + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/.history/vendor/workerman/workerman/Protocols/Dns_20221217210440.php b/.history/vendor/workerman/workerman/Protocols/Dns_20221217210440.php new file mode 100644 index 0000000..66a4f8c --- /dev/null +++ b/.history/vendor/workerman/workerman/Protocols/Dns_20221217210440.php @@ -0,0 +1,252 @@ +type; + switch($type){ + case 'A': + $type='0001'; + #$lenth='0004'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'NS': + $type='0002'; + #$lenth='0004'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'PTR': + $type='000C'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'CNAME': + $type='0005'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'SOA': + $type='0006'; + $ns=$buffer->detail; + $ns=json_decode( json_encode( $ns),true); + if($ns['type']=='none'){ + $Rns=dns_get_record($ns['name'],DNS_SOA); + $Rns=$Rns[0]; + $ns=$Rns; + $buffer->ttl=$Rns['ttl']; + } + + $nss=explode('.',$ns['mname']); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'AAAA': + $type='001C'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $detail[$n]="$i"; + $lenth[$n]="0010"; + $n=$n+1; + }; + break; + case 'TEXT': + $type='0010'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $detail[$n]=''; + $text=bin2hex($i); + $tlen=str_pad(dechex((strlen($text)/2)),2,"0",STR_PAD_LEFT); + $detail[$n]=$tlen.$text; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'MX': + $type='000F'; + $ns=$buffer->detail; + $n=0; + + print_r($ns); + + foreach($ns as $i){ + $nss=explode('.',$i->name); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)+2),4,"0",STR_PAD_LEFT).str_pad(dechex($i->pre),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + } + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8180'; + $questions='0001'; + $AnswerRRs=str_pad(count((array)$buffer->detail),4,"0",STR_PAD_LEFT); + #$AnswerRRs='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + $answer=''; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$rlenth.$c; + } + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + } + + /** + * 解包,当接收到的数据字节数等于input返回的值(大于0的值)自动调用 + * 并传递给onMessage回调函数的$data参数 + * @param string $buffer + * @return string + */ + public static function decode($buffer) + { + $data=bin2hex($buffer); + $id=substr($data,0,4); + $type=substr($data,-8,4); + switch($type){ + case '0001': + $type='A'; + break; + case '0002': + $type='NS'; + break; + case '000c': + $type='PTR'; + break; + case '0006': + $type='SOA'; + break; + case '001c': + $type='AAAA'; + break; + case '0005': + $type='CNAME'; + break; + case '0010': + $type='TEXT'; + break; + case '000f': + $type='MX'; + break; + } + $name=substr($data,24,-8); + $namede=str_split($name,2); + $realname=''; + foreach($namede as $cha){ + $chat=hex2bin($cha); + if(!ctype_alnum($chat)){ + $chat='.'; + } + $realname=$realname.$chat; + } + $realname=substr($realname,1,-1); + $query=substr($data,24); + + #$returndata="$type".'|||'."$realname"; + $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); + + return $returndata; + } +} \ No newline at end of file diff --git a/.history/vendor/workerman/workerman/Protocols/Dns_20221218180452.php b/.history/vendor/workerman/workerman/Protocols/Dns_20221218180452.php new file mode 100644 index 0000000..f44ee5d --- /dev/null +++ b/.history/vendor/workerman/workerman/Protocols/Dns_20221218180452.php @@ -0,0 +1,419 @@ +type; + switch($type){ + case 'A': + $type='0001'; + #$lenth='0004'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'NS': + $type='0002'; + #$lenth='0004'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'PTR': + $type='000C'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'CNAME': + $type='0005'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'CNAME+A': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_A); + $type='0001'; + $n=0; + foreach($ip as $i){ + $ttl=str_pad(dechex($i['ttl']),8,"0",STR_PAD_LEFT); + $i=$i['ip']; + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + + }; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02B'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'CNAME+AAAA': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_AAAA); + $type='001C'; + $n=0; + foreach($ip as $i){ + $ipv6=$i['ipv6']; + $hexstr = unpack("H*hex", inet_pton($ipv6)); + $ipv6=substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hexstr['hex']), 0, -1); + $ipv6=str_replace(':','',$ipv6); + #$ipv6= bin2hex($ipv6); + $detail[$n]="$ipv6"; + $lenth[$n]="0010"; + $n=$n+1; + }; + + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02C'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'SOA': + $type='0006'; + $ns=$buffer->detail; + $ns=json_decode( json_encode( $ns),true); + if($ns['type']=='none'){ + $Rns=dns_get_record($ns['name'],DNS_SOA); + $Rns=$Rns[0]; + $ns=$Rns; + $buffer->ttl=$Rns['ttl']; + } + + $nss=explode('.',$ns['mname']); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'AAAA': + $type='001C'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $detail[$n]="$i"; + $lenth[$n]="0010"; + $n=$n+1; + }; + break; + case 'TEXT': + $type='0010'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $detail[$n]=''; + $text=bin2hex($i); + $tlen=str_pad(dechex((strlen($text)/2)),2,"0",STR_PAD_LEFT); + $detail[$n]=$tlen.$text; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'MX': + $type='000F'; + $ns=$buffer->detail; + $n=0; + + print_r($ns); + + foreach($ns as $i){ + $nss=explode('.',$i->name); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)+2),4,"0",STR_PAD_LEFT).str_pad(dechex($i->pre),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'none': + $type='0006'; + $ns=$buffer->detail; + $url=$ns; + while(true){ + preg_match("#\.(.*)#i",$url,$match);//获取根域名 + $domin = $match[1]; + $soa=dns_get_record($domin,DNS_SOA); + if(array_key_exists('0',$soa)){ + if(array_key_exists('mname',$soa[0])){ + $qname=$domin; + $ns=$soa[0]; + break; + }else{ + $url=$domin; + } + }else{ + $url=$domin; + } + } + + $nss=explode('.',$ns['mname']); + $detail=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth=str_pad(dechex((strlen($detail)/2)),4,"0",STR_PAD_LEFT); + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8183'; + $questions='0001'; + $AnswerRRs='0000'; + $AuthorityRRs='0001'; + $AdditionalRRs='0000'; + + #$qname + $nss=explode('.',$qname); + $qname=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $qname=$qname.$len.$tpart; + }; + $qname=$qname.'00'; + + $answer=''; + $answer=$answer.$qname.$type.'0001'.$ttl.$lenth.$detail; + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + break; + } + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8180'; + $questions='0001'; + $AnswerRRs=str_pad(count((array)$buffer->detail),4,"0",STR_PAD_LEFT); + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + $answer=''; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$rlenth.$c; + } + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + } + + /** + * 解包,当接收到的数据字节数等于input返回的值(大于0的值)自动调用 + * 并传递给onMessage回调函数的$data参数 + * @param string $buffer + * @return string + */ + public static function decode($buffer) + { + $data=bin2hex($buffer); + $id=substr($data,0,4); + $type=substr($data,-8,4); + switch($type){ + case '0001': + $type='A'; + break; + case '0002': + $type='NS'; + break; + case '000c': + $type='PTR'; + break; + case '0006': + $type='SOA'; + break; + case '001c': + $type='AAAA'; + break; + case '0005': + $type='CNAME'; + break; + case '0010': + $type='TEXT'; + break; + case '000f': + $type='MX'; + break; + } + $name=substr($data,24,-8); + $namede=str_split($name,2); + $realname=''; + foreach($namede as $cha){ + $chat=hex2bin($cha); + if(!ctype_alnum($chat)){ + $chat='.'; + } + $realname=$realname.$chat; + } + $realname=substr($realname,1,-1); + $query=substr($data,24); + + #$returndata="$type".'|||'."$realname"; + $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); + + return $returndata; + } +} \ No newline at end of file diff --git a/app/controller/DnsController.php b/app/controller/DnsController.php new file mode 100644 index 0000000..8c3d2af --- /dev/null +++ b/app/controller/DnsController.php @@ -0,0 +1,33 @@ +ip2bin($ip); + */ + +class DnsController +{ + public function DNS($type,$name,$rip,$id,$query) + { + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + + #此处请根据业务需要,通过判断$name和$rip返回正确的数据 + #详情请参见 https://github.com/ywnsya/workerman-dns 尤其是 https://github.com/ywnsya/Workerman-DNS/blob/master/start.php 中的用法 + + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + $send['type']='PTR'; + + + #此处无需修改 + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index f331210..7de78e9 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ }, "autoload": { "psr-4": { + "Laysense\\Dns\\" : "vendor/laysense/dns/src", "": "./", "app\\": "./app", "App\\": "./app", diff --git a/config/plugin/laysense/dns/app.php b/config/plugin/laysense/dns/app.php new file mode 100644 index 0000000..8f9c426 --- /dev/null +++ b/config/plugin/laysense/dns/app.php @@ -0,0 +1,4 @@ + true, +]; \ No newline at end of file diff --git a/config/plugin/laysense/dns/process.php b/config/plugin/laysense/dns/process.php new file mode 100644 index 0000000..ec5ab5b --- /dev/null +++ b/config/plugin/laysense/dns/process.php @@ -0,0 +1,9 @@ + [ + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4 + ], +]; \ No newline at end of file diff --git a/config/server.php b/config/server.php index f55ce3c..b72116a 100644 --- a/config/server.php +++ b/config/server.php @@ -17,7 +17,7 @@ return [ 'transport' => 'tcp', 'context' => [], 'name' => 'webman', - 'count' => cpu_count() * 4, + 'count' => cpu_count() * 1, 'user' => '', 'group' => '', 'reusePort' => false, diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000..4e51466 Binary files /dev/null and b/dump.rdb differ diff --git a/process/DnsProcess.php b/process/DnsProcess.php new file mode 100644 index 0000000..3f4f2d5 --- /dev/null +++ b/process/DnsProcess.php @@ -0,0 +1,24 @@ +type; #查询类型 + $name=$data->name; #查询内容(一般是域名,PTR时为倒序IP) + $rip=$connection->getRemoteIp(); #客户端IP + + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + $dns=new DnsController; + $return=$dns->DNS($type,$name,$rip,$data->id,$data->query); + $connection->send($return); + } + +} \ No newline at end of file diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 542e388..e7d3341 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -26,6 +26,7 @@ return array( 'Psr\\Log\\' => array($vendorDir . '/psr/log/src'), 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), 'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'), + 'Laysense\\Dns\\' => array($vendorDir . '/laysense/dns/src'), 'FastRoute\\' => array($vendorDir . '/nikic/fast-route/src'), 'Doctrine\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib/Doctrine/Inflector'), 'App\\' => array($baseDir . '/app'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index e7e6875..432ec6a 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -55,6 +55,10 @@ class ComposerStaticInitfdb689ed918f2ee4ecdf1e51d93bd946 array ( 'Monolog\\' => 8, ), + 'L' => + array ( + 'Laysense\\Dns\\' => 13, + ), 'F' => array ( 'FastRoute\\' => 10, @@ -150,6 +154,10 @@ class ComposerStaticInitfdb689ed918f2ee4ecdf1e51d93bd946 array ( 0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog', ), + 'Laysense\\Dns\\' => + array ( + 0 => __DIR__ . '/..' . '/laysense/dns/src', + ), 'FastRoute\\' => array ( 0 => __DIR__ . '/..' . '/nikic/fast-route/src', diff --git a/vendor/laysense/dns/.gitignore b/vendor/laysense/dns/.gitignore new file mode 100644 index 0000000..1795c8d --- /dev/null +++ b/vendor/laysense/dns/.gitignore @@ -0,0 +1 @@ +.history \ No newline at end of file diff --git a/vendor/laysense/dns/composer.json b/vendor/laysense/dns/composer.json new file mode 100644 index 0000000..4480759 --- /dev/null +++ b/vendor/laysense/dns/composer.json @@ -0,0 +1,13 @@ +{ + "name": "laysense/dns", + "type": "library", + "license": "MIT", + "description": "Webman plugin laysense/dns. You can making a DNS Server with Webman now", + "require": { + }, + "autoload": { + "psr-4": { + "Laysense\\Dns\\": "src" + } + } +} \ No newline at end of file diff --git a/vendor/laysense/dns/src/Install.php b/vendor/laysense/dns/src/Install.php new file mode 100644 index 0000000..1347b4b --- /dev/null +++ b/vendor/laysense/dns/src/Install.php @@ -0,0 +1,80 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + copy(__DIR__ .'/resource/DnsController.php',base_path().'/app/controller/DnsController.php'); + echo "Create Dns Controller Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/vendor/laysense/dns/src/config/plugin/laysense/dns/app.php b/vendor/laysense/dns/src/config/plugin/laysense/dns/app.php new file mode 100644 index 0000000..8f9c426 --- /dev/null +++ b/vendor/laysense/dns/src/config/plugin/laysense/dns/app.php @@ -0,0 +1,4 @@ + true, +]; \ No newline at end of file diff --git a/vendor/laysense/dns/src/config/plugin/laysense/dns/process.php b/vendor/laysense/dns/src/config/plugin/laysense/dns/process.php new file mode 100644 index 0000000..ec5ab5b --- /dev/null +++ b/vendor/laysense/dns/src/config/plugin/laysense/dns/process.php @@ -0,0 +1,9 @@ + [ + 'handler' => process\DnsProcess::class, + 'listen' => 'Dns://0.0.0.0:53', + 'transport' => 'udp', + 'count' => cpu_count() * 4 + ], +]; \ No newline at end of file diff --git a/vendor/laysense/dns/src/install.backup b/vendor/laysense/dns/src/install.backup new file mode 100644 index 0000000..677cc4b --- /dev/null +++ b/vendor/laysense/dns/src/install.backup @@ -0,0 +1,78 @@ + 'config/plugin/laysense/dns', +); + + /** + * Install + * @return void + */ + public static function install() + { + static::installByRelation(); + } + + /** + * Uninstall + * @return void + */ + public static function uninstall() + { + self::uninstallByRelation(); + } + + /** + * installByRelation + * @return void + */ + public static function installByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + if ($pos = strrpos($dest, '/')) { + $parent_dir = base_path().'/'.substr($dest, 0, $pos); + if (!is_dir($parent_dir)) { + mkdir($parent_dir, 0777, true); + } + } + //symlink(__DIR__ . "/$source", base_path()."/$dest"); + copy_dir(__DIR__ . "/$source", base_path()."/$dest"); + echo "Create $dest +"; + } + copy(__DIR__ .'/resource/Dns.php',base_path().'/vendor/workerman/workerman/Protocols/Dns.php'); + echo "Create DNS Protocol Successfully"; + copy(__DIR__ .'/resource/DnsProcess.php',base_path().'/process/DnsProcess.php'); + echo "Create DNS Process Successfully"; + } + + /** + * uninstallByRelation + * @return void + */ + public static function uninstallByRelation() + { + foreach (static::$pathRelation as $source => $dest) { + $path = base_path()."/$dest"; + if (!is_dir($path) && !is_file($path)) { + continue; + } + echo "Remove $dest +"; + if (is_file($path) || is_link($path)) { + unlink($path); + continue; + } + remove_dir($path); + } + } + +} \ No newline at end of file diff --git a/vendor/laysense/dns/src/resource/Dns.php b/vendor/laysense/dns/src/resource/Dns.php new file mode 100644 index 0000000..f44ee5d --- /dev/null +++ b/vendor/laysense/dns/src/resource/Dns.php @@ -0,0 +1,419 @@ +type; + switch($type){ + case 'A': + $type='0001'; + #$lenth='0004'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'NS': + $type='0002'; + #$lenth='0004'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'PTR': + $type='000C'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'CNAME': + $type='0005'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'CNAME+A': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_A); + $type='0001'; + $n=0; + foreach($ip as $i){ + $ttl=str_pad(dechex($i['ttl']),8,"0",STR_PAD_LEFT); + $i=$i['ip']; + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + + }; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02B'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'CNAME+AAAA': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_AAAA); + $type='001C'; + $n=0; + foreach($ip as $i){ + $ipv6=$i['ipv6']; + $hexstr = unpack("H*hex", inet_pton($ipv6)); + $ipv6=substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hexstr['hex']), 0, -1); + $ipv6=str_replace(':','',$ipv6); + #$ipv6= bin2hex($ipv6); + $detail[$n]="$ipv6"; + $lenth[$n]="0010"; + $n=$n+1; + }; + + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02C'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'SOA': + $type='0006'; + $ns=$buffer->detail; + $ns=json_decode( json_encode( $ns),true); + if($ns['type']=='none'){ + $Rns=dns_get_record($ns['name'],DNS_SOA); + $Rns=$Rns[0]; + $ns=$Rns; + $buffer->ttl=$Rns['ttl']; + } + + $nss=explode('.',$ns['mname']); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'AAAA': + $type='001C'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $detail[$n]="$i"; + $lenth[$n]="0010"; + $n=$n+1; + }; + break; + case 'TEXT': + $type='0010'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $detail[$n]=''; + $text=bin2hex($i); + $tlen=str_pad(dechex((strlen($text)/2)),2,"0",STR_PAD_LEFT); + $detail[$n]=$tlen.$text; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'MX': + $type='000F'; + $ns=$buffer->detail; + $n=0; + + print_r($ns); + + foreach($ns as $i){ + $nss=explode('.',$i->name); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)+2),4,"0",STR_PAD_LEFT).str_pad(dechex($i->pre),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'none': + $type='0006'; + $ns=$buffer->detail; + $url=$ns; + while(true){ + preg_match("#\.(.*)#i",$url,$match);//获取根域名 + $domin = $match[1]; + $soa=dns_get_record($domin,DNS_SOA); + if(array_key_exists('0',$soa)){ + if(array_key_exists('mname',$soa[0])){ + $qname=$domin; + $ns=$soa[0]; + break; + }else{ + $url=$domin; + } + }else{ + $url=$domin; + } + } + + $nss=explode('.',$ns['mname']); + $detail=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth=str_pad(dechex((strlen($detail)/2)),4,"0",STR_PAD_LEFT); + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8183'; + $questions='0001'; + $AnswerRRs='0000'; + $AuthorityRRs='0001'; + $AdditionalRRs='0000'; + + #$qname + $nss=explode('.',$qname); + $qname=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $qname=$qname.$len.$tpart; + }; + $qname=$qname.'00'; + + $answer=''; + $answer=$answer.$qname.$type.'0001'.$ttl.$lenth.$detail; + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + break; + } + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8180'; + $questions='0001'; + $AnswerRRs=str_pad(count((array)$buffer->detail),4,"0",STR_PAD_LEFT); + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + $answer=''; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$rlenth.$c; + } + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + } + + /** + * 解包,当接收到的数据字节数等于input返回的值(大于0的值)自动调用 + * 并传递给onMessage回调函数的$data参数 + * @param string $buffer + * @return string + */ + public static function decode($buffer) + { + $data=bin2hex($buffer); + $id=substr($data,0,4); + $type=substr($data,-8,4); + switch($type){ + case '0001': + $type='A'; + break; + case '0002': + $type='NS'; + break; + case '000c': + $type='PTR'; + break; + case '0006': + $type='SOA'; + break; + case '001c': + $type='AAAA'; + break; + case '0005': + $type='CNAME'; + break; + case '0010': + $type='TEXT'; + break; + case '000f': + $type='MX'; + break; + } + $name=substr($data,24,-8); + $namede=str_split($name,2); + $realname=''; + foreach($namede as $cha){ + $chat=hex2bin($cha); + if(!ctype_alnum($chat)){ + $chat='.'; + } + $realname=$realname.$chat; + } + $realname=substr($realname,1,-1); + $query=substr($data,24); + + #$returndata="$type".'|||'."$realname"; + $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); + + return $returndata; + } +} \ No newline at end of file diff --git a/vendor/laysense/dns/src/resource/DnsController.php b/vendor/laysense/dns/src/resource/DnsController.php new file mode 100644 index 0000000..8c3d2af --- /dev/null +++ b/vendor/laysense/dns/src/resource/DnsController.php @@ -0,0 +1,33 @@ +ip2bin($ip); + */ + +class DnsController +{ + public function DNS($type,$name,$rip,$id,$query) + { + #输出信息 + #echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n"; + + + #此处请根据业务需要,通过判断$name和$rip返回正确的数据 + #详情请参见 https://github.com/ywnsya/workerman-dns 尤其是 https://github.com/ywnsya/Workerman-DNS/blob/master/start.php 中的用法 + + $send['detail']='dns.laysense.com'; + $send['ttl']=30; + $send['type']='PTR'; + + + #此处无需修改 + $send['id']=$id; + $send['query']=$query; + $return=json_encode($send); + return $return; + } +} \ No newline at end of file diff --git a/vendor/laysense/dns/src/resource/DnsProcess.php b/vendor/laysense/dns/src/resource/DnsProcess.php new file mode 100644 index 0000000..dbfe9b4 --- /dev/null +++ b/vendor/laysense/dns/src/resource/DnsProcess.php @@ -0,0 +1,27 @@ +send($data); + } + + public function onClose(TcpConnection $connection) + { + echo "onClose\n"; + } +} \ No newline at end of file diff --git a/vendor/laysense/dns/src/resource/ipv6.php b/vendor/laysense/dns/src/resource/ipv6.php new file mode 100644 index 0000000..d686a34 --- /dev/null +++ b/vendor/laysense/dns/src/resource/ipv6.php @@ -0,0 +1,204 @@ + + */ +class ipv6 { + function addr($addr=null) { + // 常规获取IPv6地址或格式化IP地址为IPv6格式 + !$addr && ($addr = $_SERVER['REMOTE_ADDR']); + $type = self::type($addr); + if ( $type === 6 && self::ipv6_check($addr) ) return $addr; + elseif ( $type === 4 ) return self::ip426($addr); + else return 'Unknown'; + } + + /** + * realip()因为在Webman(Workerman)下无效,为防止冲突已删除 + */ + + function cut($addr) { + // 压缩IPv6地址 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::fill($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $arr2[] = preg_replace('/^0{1,3}(\w+)/','\1',$a); + } + $addr = join(':',$arr2); + $olen = strlen($addr); + for($i=6;$i>0;$i--){ + // 初步压缩 + $addr = preg_replace('/:(0\:){'.$i.'}/','::',$addr,1); + if (strlen($addr) < $olen ) break; + } + $addr = preg_replace('/^0\:\:/','::',$addr); + $addr = preg_replace('/\:\:0$/','::',$addr); + return $addr; + } + + function fill($addr) { + // 标准IPv6格式 + if (!self::ipv6_check($addr)) return $addr; + $addr = self::_fix_v4($addr); + $arr = explode(':',$addr); + foreach ($arr as $a) { + $l = strlen($a); + if ( $l > 0 && $l < 4 ) + $arr2[] = str_repeat('0', 4-$l).$a; + else $arr2[] = $a; + } + $addr = join(':',$arr2); + $fil = ':'.str_repeat('0000:', 9-count($arr)); + $addr = str_replace('::',$fil,$addr); + $addr = preg_replace('/^\:/','0000:',$addr); + $addr = preg_replace('/\:$/',':0000',$addr); + return $addr; + } + + function ip2bin($addr) { + $type = self::type($addr); + if ( $type === 0 ) return false; + elseif ( $type === 4 ) $addr = self::ip426($addr); + else $addr = self::fill($addr); + $hexstr = str_replace(':','',$addr); + return pack('H*', $hexstr); + } + + function bin2ip($bin) { + if ( strlen($bin) !== 16 ) return false; + $arr = str_split(join('',unpack('H*', $bin)), 4); + $addr = join(':',$arr); + return $addr; + } + + function ip426($addr) { + // IPv4 to IPv6 + if (!self::ipv4_check($addr)) return $addr; + $hex = dechex(self::ip2long($addr)); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $ipv6 = '0000:0000:0000:0000:0000:0000:'; + $ipv6 .= substr($hex,0,4) . ':' . substr($hex,4,4); + return $ipv6; + } + + function type($addr) { + if ( self::ipv6_check($addr) ) return 6; + elseif ( self::ipv4_check($addr) ) return 4; + else return 0; + } + + function ipv4_check($addr) { + $arr = explode('.', $addr); + $l = count($arr); + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + } + return true; + } + + function ipv6_check($addr) { + $addr = self::_fix_v4($addr); + if ( strpos($addr, '.') ) return false; + $l1 = count(explode('::',$addr)); + if ( $l1 > 2 ) return false; + $l2 = count(explode(':',$addr)); + if ( $l2 < 3 || $l2 > 8 ) return false; + if ( $l2 < 8 && $l1 !== 2 ) return false; + preg_match('/^([0-9a-f]{0,4}\:)+[0-9a-f]{0,4}$/i',$addr,$arr); + if ( !$arr[0] ) return false; + return true; + } + + function ip2long($addr) { + $arr = explode('.', $addr); + $l = count($arr); + $long = 0; + for ( $i=0;$i<$l;$i++ ) { + if ( strlen($arr[$i]) > 3 ) return false; + if ( !is_numeric($arr[$i]) ) return false; + $a = intval($arr[$i], 10); + if ($a > 255 || $a <0) return false; + $long += $a * pow(2, 24-$i*8); + } + return $long; + } + + function wan_ip($addr) { + // 检查外网可用地址 + if ( self::ipv6_check($addr) ) { + $addr = self::fill($addr); + // IPv4类地址处理 + $v4p = substr($addr,0,29); + if ( $v4p == '0000:0000:0000:0000:0000:0000' + || strtolower($v4p) == 'ffff:0000:0000:0000:0000:0000' ) { + $t = str_replace($v4p,'',$addr); + $t = str_replace(':','',$t); + $ipv4 = long2ip(hexdec($t)); + return self::_wan_ipv4($ipv4); + } + // 取前16位进行比较 + $v6p = substr($addr,0,4); + $bin = decbin(hexdec($v6p)); + $p = str_repeat(0, 16-strlen($bin)).$bin; + if ( (($p&'1110000000000000')=='0010000000000000') //2000::/3 + || (($p&'1111111000000000')=='1111110000000000') //FC00::/7 + || (($p&'1111111111000000')=='1111111010000000') //FE80::/10 + || (($p&'1111111100000000')=='1111111100000000') //FF00::/8 + ) return false; + return true; + } else { + return self::_wan_ipv4($addr); + } + } + + private function _wan_ipv4($addr){ + if ( !self::ipv4_check($addr) ) return false; + $arr = explode('.',$addr); + $bin = decbin($arr[0]*256+$arr[1]); + $p = str_repeat(0, 16-strlen($bin)).$bin; + $p8 = $p & '1111111100000000'; + $p16 = &$p; + if ( ($p8 == '0000000000000000') // 0/8 + || ($p8 == '0000010100000000') // 5/8 + || ($p8 == '0000101000000000') // 10/8 + || ($p8 == '0001011100000000') // 23/8 + || ($p8 == '0010010000000000') // 36/8 + || ($p8 == '0010010100000000') // 37/8 + || ($p8 == '0010011100000000') // 39/8 + || ($p8 == '0010101000000000') // 42/8 + || ($p8 == '0110010000000000') // 100/8 + || ($p8 == '0110011000000000') // 102/8 + || ($p8 == '0110011100000000') // 103/8 + || ($p8 == '0110100000000000') // 104/8 + || ($p8 == '0110100100000000') // 105/8 + || ($p8 == '0110101000000000') // 106/8 + || ($p8 == '0111111100000000') // 127/8 + || ($p16 == '1010100111111110') // 169.254/16 + || (($p&'1111111111110000')=='1010110000010000') // 172.16/12 + || ($p8 == '1011001100000000') // 179/8 + || ($p8 == '1011100100000000') // 185/8 + || ($p16 == '1100000010101000') // 192.168/16 + || (($p&'1110000000000000')=='1110000000000000') // 224/8-255/8 + ) return false; + return true; + } + + private function _fix_v4($addr) { + // 修正IPv4位址类IPv6格式为标准IPv6格式,不验证合法性 + if ( !strpos($addr, '.') ) return $addr; + preg_match('/(\d+\.){3}\d+$/',$addr,$arr); + if ( !self::ipv4_check($arr[0]) ) return $addr; + $hex = dechex(self::ip2long($arr[0])); + $hex = str_repeat('0', 8-strlen($hex)).$hex; + $v4p = substr($hex,0,4) . ':' . substr($hex,4,4); + $p1 = str_replace($arr[0],'',$addr); + strtolower($p1) === 'ffff:' && $p1 = '::'.$p1; + $addr = $p1 . $v4p; + return $addr; + } +} +?> \ No newline at end of file diff --git a/vendor/workerman/workerman/Protocols/Dns.php b/vendor/workerman/workerman/Protocols/Dns.php new file mode 100644 index 0000000..f44ee5d --- /dev/null +++ b/vendor/workerman/workerman/Protocols/Dns.php @@ -0,0 +1,419 @@ +type; + switch($type){ + case 'A': + $type='0001'; + #$lenth='0004'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'NS': + $type='0002'; + #$lenth='0004'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'PTR': + $type='000C'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'CNAME': + $type='0005'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'CNAME+A': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_A); + $type='0001'; + $n=0; + foreach($ip as $i){ + $ttl=str_pad(dechex($i['ttl']),8,"0",STR_PAD_LEFT); + $i=$i['ip']; + $nss=explode('.',$i); + $detail[$n]=''; + foreach($nss as $part){ + $tpart=str_pad(dechex($part),2,"0",STR_PAD_LEFT); + $detail[$n]=$detail[$n].$tpart; + }; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + + }; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02B'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'CNAME+AAAA': + $type='0005'; + $ns=$buffer->detail; + $nss=explode('.',$ns); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + + $answer=''; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$lenth[0].$detail[0]; + + $ip=dns_get_record($ns,DNS_AAAA); + $type='001C'; + $n=0; + foreach($ip as $i){ + $ipv6=$i['ipv6']; + $hexstr = unpack("H*hex", inet_pton($ipv6)); + $ipv6=substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hexstr['hex']), 0, -1); + $ipv6=str_replace(':','',$ipv6); + #$ipv6= bin2hex($ipv6); + $detail[$n]="$ipv6"; + $lenth[$n]="0010"; + $n=$n+1; + }; + + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C02C'.$type.'0001'.$ttl.$rlenth.$c; + } + + $status='8180'; + $questions='0001'; + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + + $AnswerRRs=str_pad((count((array)$ip)+1),4,"0",STR_PAD_LEFT); + + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + + break; + case 'SOA': + $type='0006'; + $ns=$buffer->detail; + $ns=json_decode( json_encode( $ns),true); + if($ns['type']=='none'){ + $Rns=dns_get_record($ns['name'],DNS_SOA); + $Rns=$Rns[0]; + $ns=$Rns; + $buffer->ttl=$Rns['ttl']; + } + + $nss=explode('.',$ns['mname']); + $detail[0]=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[0]=$detail[0].$len.$tpart; + }; + $detail[0]=$detail[0].'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth[0]=str_pad(dechex((strlen($detail[0])/2)),4,"0",STR_PAD_LEFT); + break; + case 'AAAA': + $type='001C'; + $ip=$buffer->detail; + $n=0; + foreach($ip as $i){ + $detail[$n]="$i"; + $lenth[$n]="0010"; + $n=$n+1; + }; + break; + case 'TEXT': + $type='0010'; + $ns=$buffer->detail; + $n=0; + foreach($ns as $i){ + $detail[$n]=''; + $text=bin2hex($i); + $tlen=str_pad(dechex((strlen($text)/2)),2,"0",STR_PAD_LEFT); + $detail[$n]=$tlen.$text; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'MX': + $type='000F'; + $ns=$buffer->detail; + $n=0; + + print_r($ns); + + foreach($ns as $i){ + $nss=explode('.',$i->name); + $detail[$n]=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail[$n]=$detail[$n].$len.$tpart; + }; + $detail[$n]=$detail[$n].'00'; + $lenth[$n]=str_pad(dechex((strlen($detail[$n])/2)+2),4,"0",STR_PAD_LEFT).str_pad(dechex($i->pre),4,"0",STR_PAD_LEFT); + $n=$n+1; + }; + break; + case 'none': + $type='0006'; + $ns=$buffer->detail; + $url=$ns; + while(true){ + preg_match("#\.(.*)#i",$url,$match);//获取根域名 + $domin = $match[1]; + $soa=dns_get_record($domin,DNS_SOA); + if(array_key_exists('0',$soa)){ + if(array_key_exists('mname',$soa[0])){ + $qname=$domin; + $ns=$soa[0]; + break; + }else{ + $url=$domin; + } + }else{ + $url=$domin; + } + } + + $nss=explode('.',$ns['mname']); + $detail=''; + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'; + unset($nss,$len,$tpart); + $nss=explode('.',$ns['rname']); + foreach($nss as $part){ + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $detail=$detail.$len.$tpart; + }; + $detail=$detail.'00'.str_pad(dechex($ns['serial']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['refresh']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['retry']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['expire']),8,"0",STR_PAD_LEFT).str_pad(dechex($ns['minimum-ttl']),8,"0",STR_PAD_LEFT); + + + $lenth=str_pad(dechex((strlen($detail)/2)),4,"0",STR_PAD_LEFT); + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8183'; + $questions='0001'; + $AnswerRRs='0000'; + $AuthorityRRs='0001'; + $AdditionalRRs='0000'; + + #$qname + $nss=explode('.',$qname); + $qname=''; + foreach($nss as $part){ + #$len=strlen($part); + $len=str_pad(dechex(strlen($part)),2,"0",STR_PAD_LEFT); + $tpart=bin2hex($part); + $qname=$qname.$len.$tpart; + }; + $qname=$qname.'00'; + + $answer=''; + $answer=$answer.$qname.$type.'0001'.$ttl.$lenth.$detail; + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + break; + } + $ttl=str_pad(dechex($buffer->ttl),8,"0",STR_PAD_LEFT); + $status='8180'; + $questions='0001'; + $AnswerRRs=str_pad(count((array)$buffer->detail),4,"0",STR_PAD_LEFT); + $AuthorityRRs='0000'; + $AdditionalRRs='0000'; + $answer=''; + $n=0; + foreach($detail as $c){ + $rlenth=''; + $rlenth=$lenth[$n]; + $n=$n+1; + $answer=$answer.'C00C'.$type.'0001'.$ttl.$rlenth.$c; + } + $response=$buffer->id.$status.$questions.$AnswerRRs.$AuthorityRRs.$AdditionalRRs.$buffer->query.$answer; + return hex2bin($response); + } + + /** + * 解包,当接收到的数据字节数等于input返回的值(大于0的值)自动调用 + * 并传递给onMessage回调函数的$data参数 + * @param string $buffer + * @return string + */ + public static function decode($buffer) + { + $data=bin2hex($buffer); + $id=substr($data,0,4); + $type=substr($data,-8,4); + switch($type){ + case '0001': + $type='A'; + break; + case '0002': + $type='NS'; + break; + case '000c': + $type='PTR'; + break; + case '0006': + $type='SOA'; + break; + case '001c': + $type='AAAA'; + break; + case '0005': + $type='CNAME'; + break; + case '0010': + $type='TEXT'; + break; + case '000f': + $type='MX'; + break; + } + $name=substr($data,24,-8); + $namede=str_split($name,2); + $realname=''; + foreach($namede as $cha){ + $chat=hex2bin($cha); + if(!ctype_alnum($chat)){ + $chat='.'; + } + $realname=$realname.$chat; + } + $realname=substr($realname,1,-1); + $query=substr($data,24); + + #$returndata="$type".'|||'."$realname"; + $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); + + return $returndata; + } +} \ No newline at end of file