Browse Source

Enabled fetching of soa data

Lukas Metzger 9 years ago
parent
commit
5b23d5ae95
4 changed files with 97 additions and 2 deletions
  1. 27 0
      api/edit-master.php
  2. 1 1
      edit-master.php
  3. 34 1
      js/edit-master.js
  4. 35 0
      lib/soa-mail.php

+ 27 - 0
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);

+ 1 - 1
edit-master.php

@@ -69,7 +69,7 @@ limitations under the License.
                                 <label for="soa-mail" class="control-label">Email</label>
                                 <input type="text" class="form-control" id="soa-mail" placeholder="Email" autocomplete="off" data-regex="^.+\@.+\.[^.]+$" tabindex="2">
                             </div>
-                            <button type="submit" class="btn btn-primary" tabindex="7">Save</button>
+                            <button disabled type="submit" class="btn btn-primary" tabindex="7">Save</button>
                         </div>
                         
                         <div class="col-md-2 col-md-offset-1">

+ 34 - 1
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() {
+    
 }

+ 35 - 0
lib/soa-mail.php

@@ -0,0 +1,35 @@
+<?php
+
+/* 
+ * Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
+ *
+ * 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);
+}