diff --git a/README.md b/README.md index ab20392..6efe3e1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ![Docker build status](https://img.shields.io/docker/cloud/build/bbaerthlein/docker-ddns-server) ![Docker build automated](https://img.shields.io/docker/cloud/automated/bbaerthlein/docker-ddns-server) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/benjaminbear/docker-ddns-server) ![Go version](https://img.shields.io/github/go-mod/go-version/benjaminbear/docker-ddns-server?filename=dyndns%2Fgo.mod) ![License](https://img.shields.io/github/license/benjaminbear/docker-ddns-server) diff --git a/dyndns/static/js/additional.js b/dyndns/static/js/actions.js similarity index 58% rename from dyndns/static/js/additional.js rename to dyndns/static/js/actions.js index 796f45f..9e0e44b 100644 --- a/dyndns/static/js/additional.js +++ b/dyndns/static/js/actions.js @@ -1,28 +1,48 @@ -function deleteHost(id) { +$("button.addHost").click(function () { + location.href='/hosts/add'; +}); + +$("button.editHost").click(function () { + location.href='/hosts/edit/' + $(this).attr('id'); +}); + +$("button.deleteHost").click(function () { $.ajax({ contentType: 'application/x-www-form-urlencoded; charset=UTF-8', type: 'GET', - url: "/hosts/delete/" + id + url: "/hosts/delete/" + $(this).attr('id') }).done(function(data, textStatus, jqXHR) { location.href="/hosts"; }).fail(function(jqXHR, textStatus, errorThrown) { alert("Error: " + $.parseJSON(jqXHR.responseText).message); location.reload() }); -} +}); -function addEditHost(id, addedit) { - if (id == null) { - id = "" - } else { +$("button.showHostLog").click(function () { + location.href='/logs/host/' + $(this).attr('id'); +}); + +$("button.add, button.edit").click(function () { + let id = $(this).attr('id'); + if (id !== "") { id = "/"+id } + let action; + if ($(this).hasClass("add")) { + action = "add"; + } + + if ($(this).hasClass("edit")) { + action = "edit"; + } + $.ajax({ contentType: 'application/x-www-form-urlencoded; charset=UTF-8', - data: $('#edithostform').serialize(), + data: $('#editHostForm').serialize(), type: 'POST', - url: '/hosts/'+addedit+id, + url: '/hosts/'+action+id, }).done(function(data, textStatus, jqXHR) { location.href="/hosts"; }).fail(function(jqXHR, textStatus, errorThrown) { @@ -30,7 +50,7 @@ function addEditHost(id, addedit) { }); return false; -} +}); function logOut(){ try { @@ -58,26 +78,37 @@ function logOut(){ } function randomHash() { - var chars = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890"; - var pass = ""; - for (var x = 0; x < 32; x++) { - var i = Math.floor(Math.random() * chars.length); + let chars = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890"; + let pass = ""; + for (let x = 0; x < 32; x++) { + let i = Math.floor(Math.random() * chars.length); pass += chars.charAt(i); } return pass; } -function generateUsername() { - edithostform.username.value = randomHash(); -} +$("button.copyToClipboard").click(function () { + let id; + if ($(this).hasClass('username')) { + id = "username"; + } else if ($(this).hasClass('password')) { + id = "password"; + } -function generatePassword() { - edithostform.password.value = randomHash(); -} - -function copyToClipboard(inputId) { - var copyText = document.getElementById(inputId); + let copyText = document.getElementById(id); copyText.select(); copyText.setSelectionRange(0, 99999); document.execCommand("copy"); -} \ No newline at end of file +}); + +$("button.generateHash").click(function () { + let id; + if ($(this).hasClass('username')) { + id = "username"; + } else if ($(this).hasClass('password')) { + id = "password"; + } + + let input = document.getElementById(id); + input.value = randomHash(); +}); \ No newline at end of file diff --git a/dyndns/views/edithost.html b/dyndns/views/edithost.html index aabda11..e233877 100644 --- a/dyndns/views/edithost.html +++ b/dyndns/views/edithost.html @@ -1,7 +1,7 @@ {{define "content"}}

{{if eq .addEdit "edit" }}Edit{{else if eq .addEdit "add" }}Add{{end}} Host Entry

-
+
Hostname:
@@ -37,11 +37,11 @@
Username:
- +
- +
- +
@@ -51,17 +51,17 @@
Password:
- +
- +
- +
-
+
diff --git a/dyndns/views/layouts/master.html b/dyndns/views/layouts/master.html index b06a31d..c9cde59 100644 --- a/dyndns/views/layouts/master.html +++ b/dyndns/views/layouts/master.html @@ -53,6 +53,6 @@ - + \ No newline at end of file diff --git a/dyndns/views/listhosts.html b/dyndns/views/listhosts.html index 42bbb95..0eb3a2d 100644 --- a/dyndns/views/listhosts.html +++ b/dyndns/views/listhosts.html @@ -8,7 +8,7 @@ IP TTL LastUpdate - + @@ -18,7 +18,7 @@ {{.Ip}} {{.Ttl}} {{.LastUpdate.Format "01/02/2006 15:04 MEZ"}} -   +   {{end}}