From 45ed135591dd3075ed0e43896da6bf811634a88f Mon Sep 17 00:00:00 2001 From: Mark Schouten Date: Fri, 5 Dec 2014 13:54:09 +0100 Subject: [PATCH] Create a 'save this zone' button --- css/base.css | 7 +++++++ img/lock_open.png | Bin 727 -> 437 bytes index.php | 33 +++++++++++++++++++++++++++++++-- zones.php | 15 +++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/css/base.css b/css/base.css index e31bc21..b4161be 100644 --- a/css/base.css +++ b/css/base.css @@ -68,9 +68,16 @@ input[type="submit"] { margin: 0 0 50px; } img.list { + opacity: .4; +} + +.clickme { cursor: pointer; } +.clickme:hover { + opacity: 1; +} /* overrides jtable.css */ div.jtable-main-container > div.jtable-title { background-color: #FFFFFF; diff --git a/img/lock_open.png b/img/lock_open.png index a471765ff1432092e7113e56b42f2798968b443f..6bb98df4d0fe811bdce87853c3e803724970cb2f 100644 GIT binary patch delta 422 zcmV;X0a^an1+@c^8Gi%-006c6H|hWY00Lr5M??VshmXv^00009a7bBm000XU000XU z0RWnu7ytkO2XskIMF-vt1quQmq-P*)0003-NklNk*dHe$VyMi5h2N}BiuEPqW%1o2NG0f}ysjdSl@ zi^&>t%9n@doHt}`R&J&z$2VMvAL7fwn*RwcFnrv5H4_SqY~{VBXRjwf1;eY|<$m~T z2R;38v^>AN{k8=P`2F!x@4KD*gD?m`A8fkVz4u~bC_pFr@oTUG&xiK*!*usdg)+%$ za(X(=nUU-HlYd5XO_n4{y*gTT*DW4~kgezICQ!=f!mW@NGbBBC*GLGaf%%$e25>Iu*qJ`0YGW!t_;Cx)suBv+gl+z}m^ z^GDR20*z$Tl#Wt1vhPq|JHMiq&ARNIQX#92)tb|a+8=vSlq69)F*cHne?jt%r`G0f QEdT%j07*qoM6N<$g0C&LR{#J2 delta 714 zcmV;*0yX`$1J?zR8Gi-<001BJ|6u?C00d`2O+f$vugEtAis=9V02y>eSaefwW^{L9 za%BKPWN%_+AW3auXJt}lVPtu6$z?nM00L=AL_t(I%XN~=YZFlvhrc^%6RR1G#0n`= zHP#2ZaIHcYf(tjID=7+!f)!!38=?IVq^{hE>p(yR#f1wO;(yAOs1!85YO{#6jTmT> zKBhDGaa@d#A=m?ldpO+t@%x>7l!%ayYPEXOT6-&sqGP}oW6TR<%)KB8Uhc1 z0RmR@v3l_=a28y!p?9SOW;A^@zUQ4wTA+>xY2?h=a8bBPT|Q!+D%p1Lu%9 zN&$=kCtzdRwYPZQ77B-t^Zof<#O-8w^c3ySHR5myf6sPAETZEyK!XTkHHCu*@UlBV zIc#Kk-+vlln3%%8y{xb15VHp2{sKGz(Hap8R^2#9L~hFYc(>Peb|(T zzAQKc-8SLUPxR_C{_s`=m)K4NL@c>oR~guyK|^J8$rpP4;4H);ez=U)5#nqzFJn@G wIHLaKb}|cN5Tk#m`Fmn*vRKw8wM!QE7r?f0S1xi-SO5S307*qoM6N<$f(-sin*aa+ diff --git a/index.php b/index.php index f67d645..3c36113 100644 --- a/index.php +++ b/index.php @@ -149,7 +149,7 @@ $(document).ready(function () { function displayDnssecIcon(zone) { if (zone.record.dnssec == true) { - var $img = $(''); + var $img = $(''); $img.click(function () { $("#dnssecinfo").html(""); $.each(zone.record.keyinfo, function ( i, val) { @@ -170,10 +170,23 @@ function displayDnssecIcon(zone) { }); return $img; } else { - return ''; + return ''; } } +function displayExportIcon(zone) { + var $img = $(''); + $img.click(function () { + var $zexport = $.getJSON("zones.php?zone="+zone.record.name+"&action=export", function(data) { + var dl = document.createElement('a'); + dl.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data.Record.zone)); + dl.setAttribute('download', zone.record.name+'.txt'); + dl.click(); + }); + }); + return $img; +} + function displayContent(fieldName) { return function(data) { var value = data.record[fieldName]; @@ -331,6 +344,14 @@ $(document).ready(function () { }); return $img; } + }, + exportzone: { + title: '', + width: '1%', + create: false, + edit: false, + display: displayExportIcon, + listClass: 'exportzone' } } }); @@ -564,6 +585,14 @@ $(document).ready(function () { }); return $img; } + }, + exportzone: { + title: '', + width: '1%', + create: false, + edit: false, + display: displayExportIcon, + listClass: 'exportzone' } } }); diff --git a/zones.php b/zones.php index f8ed210..c64f008 100644 --- a/zones.php +++ b/zones.php @@ -28,9 +28,11 @@ function api_request($path, $opts = null, $type = null) { } } + $headers = array(); + array_push($headers, 'Accept: application/json'); $ch = curl_init(); if ($authmethod == "xapikey") { - curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-Key: '.$apipass)); + array_push($headers, 'X-API-Key: '.$apipass); } else { curl_setopt($ch, CURLOPT_USERPWD, "$apiuser:$apipass"); } @@ -41,10 +43,11 @@ function api_request($path, $opts = null, $type = null) { $type = 'POST'; } $postdata = json_encode($opts); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + array_push($headers, 'Content-Type: application/json'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); } + switch ($type) { case 'DELETE': case 'PATCH': @@ -55,6 +58,7 @@ function api_request($path, $opts = null, $type = null) { break; } + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $return = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $json = json_decode($return, 1); @@ -622,6 +626,13 @@ case "deleterecord": jtable_respond(null, 'delete'); break; +case "export": + $zone = $_GET['zone']; + $export = api_request("/servers/${apisid}/zones/${zone}/export"); + + jtable_respond($export, 'single'); + break; + default: jtable_respond(null, 'error', 'No such action'); break;