diff --git a/api/edit-master.php b/api/edit-master.php index ebaaadf..2aa58ec 100644 --- a/api/edit-master.php +++ b/api/edit-master.php @@ -19,6 +19,7 @@ require_once '../config/config-default.php'; require_once '../lib/database.php'; require_once '../lib/session.php'; +require_once '../lib/soa-mail.php'; $input = json_decode(file_get_contents('php://input')); @@ -124,4 +125,30 @@ if(isset($input->action) && $input->action == "getRecords") { } +//Action for getting SOA +if(isset($input->action) && $input->action == "getSoa") { + $domainId = (int)$input->domain; + + $stmt = $db->prepare("SELECT content FROM records WHERE type='SOA' AND domain_id=?"); + $stmt->bind_param("i", $domainId); + $stmt->execute(); + + $stmt->bind_result($content); + $stmt->fetch(); + + $content = explode(" ", $content); + + $retval = Array(); + + $retval['primary'] = preg_replace('/\\.$/', "", $content[0]); + $retval['email'] = soa_to_mail($content[1]); + $retval['serial'] = $content[2]; + $retval['refresh'] = $content[3]; + $retval['retry'] = $content[4]; + $retval['expire'] = $content[5]; + $retval['ttl'] = $content[6]; + + +} + echo json_encode($retval); diff --git a/edit-master.php b/edit-master.php index 7df3371..efab7f1 100644 --- a/edit-master.php +++ b/edit-master.php @@ -69,7 +69,7 @@ limitations under the License. - +
diff --git a/js/edit-master.js b/js/edit-master.js index 865cff6..99fda86 100644 --- a/js/edit-master.js +++ b/js/edit-master.js @@ -23,10 +23,15 @@ $(document).ready(function() { $('#soa button[type=submit]').click(function(){ if(validateSoaData()) { - $('#soa button[type=submit]').prop("disabled", "true"); + saveSoaData(); + $('#soa button[type=submit]').prop("disabled", true); } }); + $('#soa input').bind("paste keyup change", function() { + $('#soa button[type=submit]').prop("disabled", false); + }); + $('#soa form input').bind("paste keyup change", function() { var regex = new RegExp($(this).attr('data-regex')); if(!regex.test($(this).val()) && $(this).val().length > 0) { @@ -67,6 +72,7 @@ $(document).ready(function() { }); requestRecordData(); + requestSoaData(); }); @@ -133,4 +139,31 @@ function requestRecordData() { }, "json" ); +} + +function requestSoaData() { + var data = { + action: "getSoa" + }; + + data.domain = location.hash.substring(1); + + $.post( + "api/edit-master.php", + JSON.stringify(data), + function(data) { + $('#soa-primary').val(data.primary); + $('#soa-mail').val(data.email); + $('#soa-refresh').val(data.refresh); + $('#soa-retry').val(data.retry); + $('#soa-expire').val(data.expire); + $('#soa-ttl').val(data.ttl); + $('#soa-serial').val(data.serial); + }, + "json" + ); +} + +function saveSoaData() { + } \ No newline at end of file diff --git a/lib/soa-mail.php b/lib/soa-mail.php new file mode 100644 index 0000000..c2644a1 --- /dev/null +++ b/lib/soa-mail.php @@ -0,0 +1,35 @@ +. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function soa_to_mail($soa) { + $tmp = preg_replace('/([^\\\\])\\./', '\\1@', $soa, 1); + $tmp = preg_replace('/\\\\\\./', ".", $tmp); + $tmp = preg_replace('/\\.$/', "", $tmp); + + return $tmp; +} + +function mail_to_soa($mail) { + $parts = explode("@", $mail); + + $parts[0] = str_replace(".", "\.", $parts[0]); + + $parts[] = ""; + + return implode(".", $parts); +} \ No newline at end of file