-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
108 lines (91 loc) · 2.94 KB
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
function post_data($url, $post=null, $header=array(), $timeout=8, $https=0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
if ($https) // https
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
}
if ($header)
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
if ($post)
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($post) ? http_build_query($post) : $post);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
// header 共用
$header = array(
"X-Auth-Email:[email protected]",
"X-Auth-Key:xxx",
"Content-Type:application/json"
);
$domain = file_get_contents('./domain.txt');
$domain = explode("\r\n", $domain);
$record = file_get_contents('./record.txt');
$record = explode("\r\n", $record);
foreach ($domain as $v_domain)
{
// 添加域名
$url = "https://api.cloudflare.com/client/v4/zones";
$post = array(
"name" => $v_domain,
"jump_start" => true
);
$post = json_encode($post);
$rs = post_data($url, $post, $header, 8, 1);
$rs = json_decode($rs, true);
if ($rs['success'] == false)
{
echo '添加失败,错误原因:' . $rs['errors'][0]['message'] . "\n";
continue;
}
else
{
echo '添加域名成功' . "\n";
echo '域名id:' . $rs['result']['id'] . "\n";
echo '域名:' . $rs['result']['name'] . "\n";
echo '域名状态:' . $rs['result']['status'] . "\n";
echo '开始添加解析' . "\n";
$zoneid = $rs['result']['id'];
}
foreach ($record as $v_record)
{
// 添加解析
$url_add_records = "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records";
$record_detail = explode(',', $v_record);
$name = strtolower($record_detail[0]);
$type = strtoupper($record_detail[1]);
$ip = $record_detail[2];
$post = array(
"type" => $type,
"name" => $name,
"content" => $ip,
"ttl" => 120, // 1 为自动
"priority" => 10,
"proxied" => false // true 为开启 dns and http proxy (cdn)
);
$post = json_encode($post);
$add_records_rs = post_data($url_add_records, $post, $header, 8, 1);
$rs = json_decode($add_records_rs, true);
if ($rs['success'] == false)
{
echo '记录添加失败,错误原因:' . $rs['errors'][0]['message'] . "\n";
}
else
{
echo '记录添加成功' . "\n";
}
}
}