Skip to content

Commit

Permalink
txt验证、禁止用户注册
Browse files Browse the repository at this point in the history
  • Loading branch information
Netrvin committed Feb 9, 2021
1 parent 59cefa0 commit 3d43400
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 525 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
config.php
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ Cloudflare Partner Management Panel

打开config.php,根据里面的注释进行设置后即可使用

English version: [https://github.com/Netrvin/CFPMP/tree/en-v0.2.3](https://github.com/Netrvin/CFPMP/tree/en-v0.2.3)

## 功能
* CNAME接入
* reCAPTCHA
* 设置回源地址为IP(基于sslip.io)(默认关闭此功能)
* 通过 TXT 记录验证域名是否受用户控制

可用实例:[https://cf.yuzu.im/](https://cf.yuzu.im/)
25 changes: 16 additions & 9 deletions add_domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@

$cloudflare->is_login();

function msg($s){
$_SESSION["msg"]=$s;
function msg($s)
{
$_SESSION["msg"] = $s;
header("Location: domains.php");
exit(0);
}

if (empty($_POST["domain"])){
if (empty($_POST["domain"])) {
msg("域名不能为空");
}

$r=$cloudflare->zone_set($_POST["domain"],$_POST["domain"],"www:".$_POST["domain"]);
if (Enable_TXT_Verification){
if (!$cloudflare->check_txt_record($_POST["domain"])){
msg("TXT 记录验证失败");
}
}

$r = $cloudflare->zone_set($_POST["domain"], $_POST["domain"], "www:" . $_POST["domain"]);

if ($r["result"]=="success"){
if ($r["result"] == "success") {
msg("添加成功");
}else{
if (empty($r["msg")){
} else {
if (empty($r["msg"])) {
msg("请刷新本页面以确认域名是否添加成功");
}else{
msg("添加失败:".$r["msg"]);
} else {
msg("添加失败:" . $r["msg"]);
}
}
35 changes: 16 additions & 19 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@

include_once("cf.class.php");

function msg($s){
$_SESSION["login_msg"]=$s;
function msg($s)
{
$_SESSION["login_msg"] = $s;
header("Location: index.php");
exit(0);
}

if (Enable_reCAPTCHA)
{
if (!empty($_POST["g-recaptcha-response"]))
{
if (!($cloudflare->reCAPTCHA($_POST["g-recaptcha-response"])))
{
if (Enable_reCAPTCHA) {
if (!empty($_POST["g-recaptcha-response"])) {
if (!($cloudflare->reCAPTCHA($_POST["g-recaptcha-response"]))) {
msg("请完成验证码");
}
}else{
} else {
msg("请完成验证码");
}
}

if ((!empty($_POST["email"]))&&(!empty($_POST["password"])))
{
$r=$cloudflare->login($_POST["email"],$_POST["password"]);
if ($r["result"]=="success")
{
$_SESSION["user_key"]=$r["response"]["user_key"];
$_SESSION["email"]=$r["response"]["cloudflare_email"];
if ((!empty($_POST["email"])) && (!empty($_POST["password"]))) {
$r = $cloudflare->login($_POST["email"], $_POST["password"]);
if ($r["result"] == "success") {
$_SESSION["user_key"] = $r["response"]["user_key"];
$_SESSION["email"] = $r["response"]["cloudflare_email"];
if (Enable_TXT_Verification) $_SESSION["txt_verification"] = password_hash(Random_String.$_SESSION["email"],PASSWORD_BCRYPT );
header("Location: domains.php");
}else{
msg("登录 / 注册失败:".$r["msg"]);
} else {
msg("失败:" . $r["msg"]);
}
}else{
} else {
msg("用户名和密码不能为空");
}
213 changes: 117 additions & 96 deletions cf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,147 +2,168 @@

include_once("config.php");

if (Enable_TXT_Verification&&(strlen(Random_String)<64)){
die("Please set Random_String in config.php or disable TXT record verification");
}

session_start();

class CF {
public function post($data){
$data["host_key"]=HOST_KEY;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"https://api.cloudflare.com/host-gw.html");
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$r=curl_exec($ch);
class CF
{
public function post($data)
{
$data["host_key"] = HOST_KEY;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/host-gw.html");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
return json_decode($r,true);
return json_decode($r, true);
}

public function login($email,$password){
$data["act"]="user_create";
$data["cloudflare_email"]=$email;
$data["cloudflare_pass"]=$password;
$data["unique_id"]=NULL;
return self::post($data);
public function login($email, $password)
{
$data["act"] = (Allow_Register ? "user_create" : "user_auth");
$data["cloudflare_email"] = $email;
$data["cloudflare_pass"] = $password;
$data["unique_id"] = NULL;
return self::post($data);
}

public function logout(){
if (!empty($_SESSION["email"])){
public function logout()
{
if (!empty($_SESSION["email"])) {
unset($_SESSION["email"]);
}
if (!empty($_SESSION["user_key"])){
if (!empty($_SESSION["user_key"])) {
unset($_SESSION["user_key"]);
}
}

public function is_login(){
if ((empty($_SESSION["email"]))||(empty($_SESSION["user_key"]))){
public function is_login()
{
if ((empty($_SESSION["email"])) || (empty($_SESSION["user_key"]))) {
header("Location: index.php");
exit(0);
}
}

public function user_lookup(){
$data["act"]="user_lookup";
$data["cloudflare_email"]=$_SESSION["email"];
return self::post($data);
}

public function zone_set($zone_name,$resolve_to,$subdomains){
$data["act"] = "zone_set";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
$data["resolve_to"] = $resolve_to;
$data["subdomains"] = $subdomains;
return self::post($data);
}

public function zone_delete($zone_name){
$data["act"] = "zone_delete";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
return self::post($data);
}

public function zone_lookup($zone_name){
$data["act"] = "zone_lookup";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
return self::post($data);
}

public function update_record($zone_name,$record){
if (empty($record["@"])){
$record["@"]=$zone_name;
public function user_lookup()
{
$data["act"] = "user_lookup";
$data["cloudflare_email"] = $_SESSION["email"];
return self::post($data);
}

public function zone_set($zone_name, $resolve_to, $subdomains)
{
$data["act"] = "zone_set";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
$data["resolve_to"] = $resolve_to;
$data["subdomains"] = $subdomains;
return self::post($data);
}

public function zone_delete($zone_name)
{
$data["act"] = "zone_delete";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
return self::post($data);
}

public function zone_lookup($zone_name)
{
$data["act"] = "zone_lookup";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
return self::post($data);
}

public function update_record($zone_name, $record)
{
if (empty($record["@"])) {
$record["@"] = $zone_name;
}
$at=$record["@"];
$at = $record["@"];
unset($record["@"]);
if ((Enable_A_Record) && (filter_var($at,FILTER_VALIDATE_IP,FILTER_FLAG_IPV4))){
$at=$at.'.sslip.io';
if ((Enable_A_Record) && (filter_var($at, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))) {
$at = $at . '.sslip.io';
}
$str="";
foreach ($record as $key => $value){
if ((Enable_A_Record) && (filter_var($value,FILTER_VALIDATE_IP,FILTER_FLAG_IPV4))){
$str.=$key.":".$value.".sslip.io,";
}else{
$str.=$key.":".$value.",";
$str = "";
foreach ($record as $key => $value) {
if ((Enable_A_Record) && (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))) {
$str .= $key . ":" . $value . ".sslip.io,";
} else {
$str .= $key . ":" . $value . ",";
}
}
if (empty($str)){
$str="www:".$zone_name;
}else{
$str=substr($str,0,strlen($str)-1);
if (empty($str)) {
$str = "www:" . $zone_name;
} else {
$str = substr($str, 0, strlen($str) - 1);
}
return self::zone_set($zone_name,$at,$str);
return self::zone_set($zone_name, $at, $str);
}

public function remove_zone_name($zone_name,$data){
foreach ($data["hosted_cnames"] as $record => $set)
{
if (strlen($record) > strlen($zone_name)){
$record2 = substr($record,0,strlen($record)-strlen($zone_name)-1);
}else{
$record2="@";
public function remove_zone_name($zone_name, $data)
{
foreach ($data["hosted_cnames"] as $record => $set) {
if (strlen($record) > strlen($zone_name)) {
$record2 = substr($record, 0, strlen($record) - strlen($zone_name) - 1);
} else {
$record2 = "@";
}
$data["hosted_cnames"][$record2] = $set;
unset($data["hosted_cnames"][$record]);
}
foreach ($data["forward_tos"] as $record => $set)
{
if (strlen($record) > strlen($zone_name)){
$record2 = substr($record,0,strlen($record)-strlen($zone_name)-1);
}else{
$record2="@";
foreach ($data["forward_tos"] as $record => $set) {
if (strlen($record) > strlen($zone_name)) {
$record2 = substr($record, 0, strlen($record) - strlen($zone_name) - 1);
} else {
$record2 = "@";
}
$data["forward_tos"][$record2] = $set;
unset($data["forward_tos"][$record]);
}
return $data;
}

public function reCAPTCHA($response){
$url= "https://www.recaptcha.net/recaptcha/api/siteverify";
$data=array (
public function reCAPTCHA($response)
{
$url = "https://www.recaptcha.net/recaptcha/api/siteverify";
$data = array(
"secret" => reCAPTCHA_Secret,
"response" => $response
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
$r=curl_exec($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$r = curl_exec($ch);
curl_close($ch);
$re=json_decode($r,true);
if (!empty($re["success"])){
if ($re["success"]=="true"){
$re = json_decode($r, true);
if (!empty($re["success"])) {
if ($re["success"] == "true") {
return true;
}else{
} else {
return false;
}
}else{
} else {
return false;
}
}
}

public function check_txt_record($domain){
foreach(dns_get_record("cfpmp.".$domain, DNS_TXT) as $v){
if (password_verify(Random_String.$_SESSION["email"], $v["txt"])) return true;
}
return false;
}
}

$cloudflare=new CF();
$cloudflare = new CF();
Loading

0 comments on commit 3d43400

Please sign in to comment.