使用ZE3kr-Cloudflare(CFP)面板添加解析代码报错,如下
Client error: `POST https://api.cloudflare.com/client/v4/zones/cab156fc85326d9d87e887dc4eb6b75b/dns_records` resulted in a `400 Bad Request` response: { "result": null, "success": false, "errors": [ { "code": 9207, "message": "Failed to parse reques (truncated...)
其实和白嫖不白嫖的关系不大。白嫖一样能用,不过CF的API解析参数严格了一些。
问题出现在:
添加DNS记录:
actions/add_record.php 第20行往后
$options = [
'type' => $_POST['type'],
'name' => $_POST['name'],
'content' => $_POST['content'],
'proxied' => $_POST['proxied'],
'ttl' => intval($_POST['ttl']),
'data' => $dns_data,
];
if ($_POST['type'] == 'MX') {
$options['priority'] = intval($_POST['priority']);
}
try {
$dns = $adapter->post('zones/' . $_GET['zoneid'] . '/dns_records', $options);
上面的data在非CAA、SRV记录中是空的(见record_data.php中定义)。但是CF的API无法解析这个空数组,所以就无法添加DNS记录。
修改DNS记录:
actions/edit_record.php 第31行记录
巴拉巴拉巴拉吧(同样的问题,不再赘述)
解决:
部分代码修改法
传入之前删除这个空数组。
$options = [
'type' => $_POST['type'],
'name' => $_POST['name'],
'content' => $_POST['content'],
'proxied' => $_POST['proxied'],
'ttl' => intval($_POST['ttl']),
'data' => $dns_data,
];
if ($_POST['type'] == 'MX') {
$options['priority'] = intval($_POST['priority']);
}
try {
if(empty($options['data']))unset($options['data']);##就是这一行啦。
$dns = $adapter->post('zones/' . $_GET['zoneid'] . '/dns_records', $options);
直接文件替换法
当然你也可以直接下载
https://github.com/yumusb/Fix-ZE3kr-Cloudflare/blob/master/add_record.php 替换掉 actions/add_record.php
https://github.com/yumusb/Fix-ZE3kr-Cloudflare/blob/master/edit_record.php 替换掉 actions/edit_record.php
全部代码替换法
或修改actions/edit_record.php为以下代码:
<?php /* * Edit a record. */ if (!isset($adapter)) {exit;} ?> <strong><?php echo '<h1 class="h5"><a href="?action=zone&domain=' . $_GET['domain'] . '&zoneid=' . $_GET['zoneid'] . '"><- ' . _('Back') . '</a></h1>'; ?></strong><hr> <?php $dns = new \Cloudflare\API\Endpoints\DNS($adapter); $dns_details = $dns->getRecordDetails($_GET['zoneid'], $_GET['recordid']); if (isset($_POST['submit'])) { if (isset($_POST['proxied']) && $_POST['proxied'] == 'true') { $_POST['proxied'] = true; } else { $_POST['proxied'] = false; } $_POST['ttl'] = intval($_POST['ttl']); $_POST['type'] = $dns_details->type; if (isset($_POST['priority']) && $_POST['type'] == 'MX') { $_POST['priority'] = intval($_POST['priority']); } else { $_POST['priority'] = 10; } if (!isset($_POST['content'])) { $_POST['content'] = ""; } include "record_data.php"; try { $options = ['type' => $dns_details->type, 'name' => $_POST['name'], 'content' => $_POST['content'], 'ttl' => intval($_POST['ttl']), 'priority' => $_POST['priority'], 'proxied' => $_POST['proxied'], 'data' => $dns_data]; if(empty($options['data']))unset($options['data']); if ($dns->updateRecordDetails($_GET['zoneid'], $_GET['recordid'], $options)) { exit('<p class="alert alert-success" role="alert">' . _('Success') . '</p>'); } else { echo '<p class="alert alert-danger" role="alert">' . _('Failed') . '</p>'; } } catch (Exception $e) { echo '<p class="alert alert-danger" role="alert">' . _('Failed') . '</p>'; echo '<div class="alert alert-warning" role="alert">' . $e->getMessage() . '</div>'; } } if (isset($msg)) {echo $msg;} ?> <form method="POST" action=""> <fieldset> <legend><?php echo _('Edit DNS Record'); ?></legend> <div class="form-group"> <label for="name"><?php echo _('Record Name (e.g. “@”, “www”, etc.)'); ?></label> <input type="text" name="name" id="name" value="<?php echo htmlspecialchars($dns_details->name); ?>" class="form-control"> </div> <div class="form-group"> <label for="type"><?php echo _('Record Type'); ?></label> <select name="type" id="type" disabled="disabled" class="form-control"> <option value="<?php echo $dns_details->type; ?>"><?php echo $dns_details->type; ?></option> </select> </div> <?php if ($dns_details->type == 'CAA') {?> <div class="form-group"> <label for="data_tag"><?php echo _('Tag'); ?></label> <select name="data_tag" id="data_tag" class="form-control" data-selected="<?php echo $dns_details->data->tag ?>"> <option value="issue"><?php echo _('Only allow specific hostnames') ?></option> <option value="issuewild"><?php echo _('Only allow wildcards') ?></option> <option value="iodef"><?php echo _('Send violation reports to URL (http:, https:, or mailto:)') ?></option> </select> </div> <div class="form-group"> <label for="data_value"><?php echo _('Value'); ?></label> <input type="text" name="data_value" id="data_value" value="<?php echo htmlspecialchars($dns_details->data->value); ?>" class="form-control"> </div> <input type="hidden" name="data_flags" value="0"> <?php } elseif ($dns_details->type == 'SRV') {?> <div class="form-group"> <label for="srv_service"><?php echo _('Service'); ?></label> <input type="text" name="srv_service" id="srv_service" value="<?php echo $dns_details->data->service ?>" class="form-control"> </div> <div class="form-group"> <label for="srv_proto"><?php echo _('Proto'); ?></label> <select name="srv_proto" id="srv_proto" class="form-control" data-selected="<?php echo $dns_details->data->proto ?>"> <option value="_tcp">TCP</option> <option value="_udp">UDP</option> <option value="_tls">TLS</option> </select> </div> <div class="form-group"> <label for="srv_name"><?php echo _('Name'); ?></label> <input type="text" name="srv_name" id="srv_name" value="<?php echo $dns_details->data->name ?>" class="form-control"> </div> <div class="form-group"> <label for="srv_priority"><?php echo _('Priority'); ?></label> <input type="text" name="srv_priority" id="srv_priority" value="<?php echo $dns_details->data->priority ?>" class="form-control"> </div> <div class="form-group"> <label for="srv_weight"><?php echo _('Weight'); ?></label> <input type="text" name="srv_weight" id="srv_weight" value="<?php echo $dns_details->data->weight ?>" class="form-control"> </div> <div class="form-group"> <label for="srv_port"><?php echo _('Port'); ?></label> <input type="text" name="srv_port" id="srv_port" value="<?php echo $dns_details->data->port ?>" class="form-control"> </div> <div class="form-group"> <label for="srv_target"><?php echo _('Target'); ?></label> <input type="text" name="srv_target" id="srv_target" value="<?php echo $dns_details->data->target ?>" class="form-control"> </div> <?php } else {?> <div class="form-group"> <label for="doc-ta-1"><?php echo _('Record Content'); ?></label> <textarea name="content" rows="5" id="doc-ta-1" class="form-control"><?php echo htmlspecialchars($dns_details->content); ?></textarea> </div> <?php if ($dns_details->type == 'MX' || $dns_details->type == 'SRV') {?> <div class="form-group"> <label for="priority"><?php echo _('Priority'); ?></label> <input type="number" name="priority" id="priority" step="1" min="1" value="<?php echo $dns_details->priority; ?>" class="form-control"> </div> <?php }?> <?php }?> <div class="form-group"> <label for="ttl">TTL</label> <select name="ttl" id="ttl" class="form-control"> <?php foreach ($ttl_translate as $_ttl => $_ttl_name) { echo '<option value="' . $_ttl . '">' . $_ttl_name . '</option>'; } ?> </select> </div> <?php if ($dns_details->proxiable) {?> <div class="form-group"> <label for="proxied">CDN</label> <select name="proxied" id="proxied" class="form-control"> <option value="true" <?php if ($dns_details->proxied) {echo 'selected="selected"';}?>><?php echo _('On'); ?></option> <option value="false" <?php if (!$dns_details->proxied) {echo 'selected="selected"';}?>><?php echo _('Off'); ?></option> </select> </div> <?php }?> <button type="submit" name="submit" class="btn btn-primary"><?php echo _('Submit'); ?></button> </fieldset> </form>
修改 actions/add_record.php为以下代码
<?php /* * Add record for specific domain. */ if (!isset($adapter)) {exit;} if (isset($_POST['submit'])) { if ($_POST['proxied'] == 'false') { $_POST['proxied'] = false; } else { $_POST['proxied'] = true; } if ($_POST['type'] != 'A' && $_POST['type'] != 'AAAA' && $_POST['type'] != 'CNAME') { $_POST['proxied'] = false; } include "record_data.php"; $options = [ 'type' => $_POST['type'], 'name' => $_POST['name'], 'content' => $_POST['content'], 'proxied' => $_POST['proxied'], 'ttl' => intval($_POST['ttl']), 'data' => $dns_data, ]; if ($_POST['type'] == 'MX') { $options['priority'] = intval($_POST['priority']); } try { if(empty($options['data']))unset($options['data']); $dns = $adapter->post('zones/' . $_GET['zoneid'] . '/dns_records', $options); $dns = json_decode($dns->getBody()); if (isset($dns->result->id)) { exit('<p class="alert alert-success" role="alert">' . _('Success') . ', <a href="?action=add_record&zoneid=' . $_GET['zoneid'] . '&domain=' . $_GET['domain'] . '">' . _('Add New Record') . '</a>, ' . _('Or') . '<a href="?action=zone&domain=' . $_GET['domain'] . '&zoneid=' . $_GET['zoneid'] . '">' . _('Go to console') . '</a></p>'); } else { exit('<p class="alert alert-danger" role="alert">' . _('Failed') . ', <a href="?action=add_record&zoneid=' . $_GET['zoneid'] . '&domain=' . $_GET['domain'] . '">' . _('Add New Record') . '</a>, ' . _('Or') . '<a href="?action=zone&domain=' . $_GET['domain'] . '&zoneid=' . $_GET['zoneid'] . '">' . _('Go to console') . '</a></p>'); } } catch (Exception $e) { echo '<p class="alert alert-danger" role="alert">' . _('Failed') . '</p>'; echo '<div class="alert alert-warning" role="alert">' . $e->getMessage() . '</div>'; } } ?> <strong><?php echo '<h1 class="h5"><a href="?action=zone&domain=' . $_GET['domain'] . '&zoneid=' . $_GET['zoneid'] . '"><- ' . _('Back') . '</a></h1>'; ?></strong><hr> <form method="POST" action=""> <fieldset> <legend><?php echo _('Add DNS Record'); ?></legend> <div class="form-group"> <label for="name"><?php echo _('Record Name (e.g. “@”, “www”, etc.)'); ?></label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <label for="type"><?php echo _('Record Type'); ?></label> <select name="type" id="type" class="form-control"> <option value="A">A</option> <option value="AAAA">AAAA</option> <option value="CNAME">CNAME</option> <option value="MX">MX</option> <option value="SPF">SPF</option> <option value="TXT">TXT</option> <option value="NS">NS</option> <option value="PTR">PTR</option> <option value="CAA">CAA</option> <option value="SRV">SRV</option> </select> </div> <div class="form-group" id="dns-content"> <label for="doc-ta-1"><?php echo _('Record Content'); ?></label> <textarea name="content" rows="5" id="doc-ta-1" class="form-control"></textarea> </div> <div class="form-group" id="dns-mx-priority"> <label for="priority"><?php echo _('Priority'); ?></label> <input type="number" name="priority" id="priority" step="1" min="1" value="1" class="form-control"> </div> <div id="dns-data-caa"> <div class="form-group"> <label for="data_tag"><?php echo _('Tag'); ?></label> <select name="data_tag" id="data_tag" class="form-control"> <option value="issue" selected="selected"><?php echo _('Only allow specific hostnames') ?></option> <option value="issuewild"><?php echo _('Only allow wildcards') ?></option> <option value="iodef"><?php echo _('Send violation reports to URL (http:, https:, or mailto:)') ?></option> </select> </div> <div class="form-group"> <label for="data_value"><?php echo _('Value'); ?></label> <input type="text" name="data_value" id="data_value" class="form-control"> </div> <input type="hidden" name="data_flags" value="0"> </div> <div id="dns-data-srv"> <div class="form-group"> <label for="srv_service"><?php echo _('Service'); ?></label> <input type="text" name="srv_service" id="srv_service" value="_sip" class="form-control"> </div> <div class="form-group"> <label for="srv_proto"><?php echo _('Proto'); ?></label> <select name="srv_proto" id="srv_proto" class="form-control"> <option value="_tcp" selected="selected">TCP</option> <option value="_udp">UDP</option> <option value="_tls">TLS</option> </select> </div> <div class="form-group"> <label for="srv_priority"><?php echo _('Priority'); ?></label> <input type="text" name="srv_priority" id="srv_priority" value="1" class="form-control"> </div> <div class="form-group"> <label for="srv_weight"><?php echo _('Weight'); ?></label> <input type="text" name="srv_weight" id="srv_weight" value="1" class="form-control"> </div> <div class="form-group"> <label for="srv_port"><?php echo _('Port'); ?></label> <input type="text" name="srv_port" id="srv_port" value="1" class="form-control"> </div> <div class="form-group"> <label for="srv_target"><?php echo _('Target'); ?></label> <input type="text" name="srv_target" id="srv_target" class="form-control"> </div> </div> <div class="form-group"> <label for="ttl">TTL</label> <select name="ttl" id="ttl" class="form-control"> <?php foreach ($ttl_translate as $_ttl => $_ttl_name) { echo '<option value="' . $_ttl . '">' . $_ttl_name . '</option>'; } ?> </select> </div> <div class="form-group"> <label for="proxied">CDN</label> <select name="proxied" id="proxied" class="form-control"> <option value="true"><?php echo _('On'); ?></option> <option value="false"><?php echo _('Off'); ?></option> </select> </div> <p><button type="submit" name="submit" class="btn btn-primary"><?php echo _('Submit'); ?></button></p> </fieldset> <script> </script> </form>
保存即可。
最后
如果有帮助到你,请不要吝啬。 http://33.al/donate
文章评论