1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-08 22:20:05 +00:00

Remove old assets, prepare adding Vue serving

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-11-04 14:32:00 +01:00
parent 4379055434
commit 0ad1681ee0
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
10 changed files with 3 additions and 482 deletions

View file

@ -3,11 +3,12 @@ package main
import ( import (
"mime" "mime"
"net/http" "net/http"
"path"
"path/filepath" "path/filepath"
) )
func serveAssets(res http.ResponseWriter, r *http.Request) { func serveAssets(res http.ResponseWriter, r *http.Request) {
data, err := Asset(r.RequestURI[1:]) data, err := Asset(path.Join("dist", r.RequestURI[1:]))
if err != nil { if err != nil {
http.Error(res, "Not found", http.StatusNotFound) http.Error(res, "Not found", http.StatusNotFound)
return return

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 561 B

View file

@ -1,423 +0,0 @@
// Generated by CoffeeScript 1.12.4
(function() {
var CloudKeys;
CloudKeys = (function() {
function CloudKeys() {
this.entities = [];
this.version = "";
this.password = '';
$('#pw').focus().keyup((function(_this) {
return function(evt) {
var that = this;
if (evt.keyCode === 13) {
_this.password = $(that).val();
$('#loader').removeClass('hide');
_this.fetchData();
$('#newEntityLink').click(function() {
return _this.showForm();
});
$('#editEncPWLink').click(function() {
return _this.showEditEncPWForm();
});
$('#passwordRequest').addClass('hide');
$('#search').keyup(function() {
var that = this;
_this.limitItems(_this.getItems($(that).val()));
});
$('#search').focus();
return $(window).keyup(function(evt) {
if (evt.altKey === true && evt.keyCode === 66) {
if (typeof window.copyToClipboard === "function") {
copyToClipboard($('#items li.active .username').val());
} else {
$('#items li.active .username').focus().select();
}
}
if (evt.altKey === true && evt.keyCode === 79) {
if (typeof window.copyToClipboard === "function") {
copyToClipboard($('#items li.active .password').data('toggle'));
} else {
$('#items li.active .passwordtoggle em').click();
$('#items li.active .password').focus().select();
}
}
if (evt.altKey === true && evt.keyCode === 80) {
if (typeof window.copyToClipboard === "function") {
copyToClipboard($('#items li.active .password').data('toggle'));
} else {
$('#items li.active .password').focus().select();
}
}
if (evt.altKey === true && evt.keyCode === 85) {
if (typeof window.copyToClipboard === "function") {
return copyToClipboard($('#items li.active .url').val());
} else {
return $('#items li.active .url').focus().select();
}
}
});
}
};
})(this));
}
CloudKeys.prototype["import"] = function(xml) {
var e, entity, entry, group, j, l, len, len1, parsedXML, ref, ref1, tag;
parsedXML = $.parseXML(xml);
ref = $(parsedXML).find('group');
for (j = 0, len = ref.length; j < len; j++) {
group = ref[j];
tag = $(group).find('>title').text();
ref1 = $(group).find('entry');
for (l = 0, len1 = ref1.length; l < len1; l++) {
entry = ref1[l];
e = $(entry);
entity = {};
entity['title'] = e.find('title').text();
entity['username'] = e.find('username').text();
entity['password'] = e.find('password').text();
entity['url'] = e.find('url').text();
entity['comment'] = e.find('comment').text();
entity['tags'] = tag;
this.entities.push(entity);
}
}
return this.updateData((function(_this) {
return function() {
$('#import').val('');
return $('#importLink').click();
};
})(this));
};
CloudKeys.prototype.updateData = function(callback) {
var encrypted, hash;
encrypted = this.encrypt(JSON.stringify(this.entities));
hash = CryptoJS.SHA1(encrypted).toString();
return $.post('ajax', {
'version': this.version,
'checksum': hash,
'data': encrypted
}, (function(_this) {
return function(result) {
if (result.error === true) {
return alert("An error occured, please reload and try it again");
} else {
if (typeof callback !== "undefined") {
callback();
}
return _this.updateInformation(result);
}
};
})(this), "json");
};
CloudKeys.prototype.fetchData = function() {
return $.get('ajax', (function(_this) {
return function(data) {
return _this.updateInformation(data);
};
})(this), "json");
};
CloudKeys.prototype.updateInformation = function(data) {
var e;
this.version = data.version;
if (data.data === "") {
this.entities = [];
} else {
try {
this.entities = $.parseJSON(this.decrypt(data.data));
} catch (error) {
e = error;
window.location.reload();
}
}
this.entities.sort(this.sortItems);
this.showItems(this.getItems(''));
return this.limitItems(this.getItems($('#search').val()));
};
CloudKeys.prototype.encrypt = function(value) {
return CryptoJS.AES.encrypt(value, this.password).toString();
};
CloudKeys.prototype.decrypt = function(value) {
return CryptoJS.AES.decrypt(value, this.password).toString(CryptoJS.enc.Utf8);
};
CloudKeys.prototype.getClipboardCode = function(value) {
var cb;
cb = $('<div class="clipboard"></div>');
cb.click(function(e) {
var elem;
elem = $("<textarea>" + value + "</textarea>").css({
'position': 'absolute',
'left': '-9999px',
'readonly': 'readonly',
'top': (window.pageYOffset || document.documentElement.scrollTop) + 'px'
});
$("body").append(elem);
elem.focus();
elem.select();
document.execCommand('copy');
elem.remove();
});
return cb;
};
CloudKeys.prototype.limitItems = function(items) {
var current;
$('#resultdescription span').text(items.length);
current = 0;
$('#items>li').each((function(_this) {
return function(k, v) {
var item;
item = $(v);
item.removeClass('odd');
if ($.inArray(item.data('num'), items) === -1) {
item.addClass('hide');
} else {
if (item.hasClass('hide')) {
item.removeClass('hide');
}
if (current % 2 === 0) {
item.addClass('odd');
}
current = current + 1;
}
};
})(this));
};
CloudKeys.prototype.showItems = function(items) {
var additionalClass, c, char, counter, field, i, item, itemContainer, j, len, lines_match, password, ref, ul;
$('#items li').remove();
itemContainer = $('#items');
$('#resultdescription span').text(items.length);
for (i = j = 0, len = items.length; j < len; i = ++j) {
item = items[i];
additionalClass = "";
if (i % 2 === 0) {
additionalClass = "odd";
}
item = this.entities[item];
c = $("<li data-num=\"" + item.num + "\" class=\"" + additionalClass + "\">" + item.title + " <span>" + item.username + "</span></li>");
ul = $("<ul></ul>");
password = "";
ref = item.password;
for (char in ref) {
i = ref[char];
password += "*";
}
field = $("<li><label>Username:</label><input type=\"text\" class=\"username\" value=\"" + item.username + "\"><br></li>");
ul.append(field);
this.getClipboardCode(item.username).insertBefore(field.find("br"));
field = $("<li class=\"passwordtoggle\"><label>Password:</label><input type=\"text\" class=\"password\" value=\"" + password + "\" data-toggle=\"" + (item.password.replace(/"/g, '&quot;')) + "\"><em> (toggle visibility)</em></span><br></li>");
ul.append(field);
this.getClipboardCode(item.password).insertBefore(field.find("br"));
field = $("<li><label>URL:</label><input type=\"text\" class=\"url\" value=\"" + item.url + "\"><br></li>");
ul.append(field);
this.getClipboardCode(item.url).insertBefore(field.find("br"));
lines_match = item.comment.match(/\n/g);
if (lines_match !== null) {
counter = lines_match.length;
}
if (counter < 2) {
counter = 2;
}
field = $("<li><label>Comment:</label><textarea class=\"comment\" rows=\"" + (counter + 2) + "\">" + item.comment + "</textarea><br></li>");
ul.append(field);
this.getClipboardCode(item.comment).insertBefore(field.find("br"));
field = $("<li><label>Tags:</label><input type=\"text\" class=\"tags\" value=\"" + item.tags + "\"><br></li>");
ul.append(field);
this.getClipboardCode(item.tags).insertBefore(field.find("br"));
ul.append("<li class=\"last\"><button class=\"btn btn-primary\">Edit</button><br></li>");
ul.find('.btn-primary').click((function(_this) {
return function() {
var t = this;
var num;
num = $(t).parent().parent().parent().data('num');
if (typeof num !== "undefined" && typeof num !== null) {
return _this.showForm(num);
}
};
})(this));
ul.find('.passwordtoggle em').click((function(_this) {
return function() {
var t = this;
var elem, original;
elem = $(t).parent().find('.password');
original = elem.data('toggle');
elem.data('toggle', elem.val());
return elem.val(original);
};
})(this));
c.append(ul);
c.click((function(_this) {
return function() {
var that = this;
var elem;
elem = $(that);
if (elem.hasClass('active') === false) {
$('#items li.active').removeClass('active').find('ul').slideUp();
elem.addClass('active');
return elem.find('ul').slideDown();
}
};
})(this));
c.find('input').focus().select();
itemContainer.append(c);
}
$('.hide').removeClass('hide');
$('#loader').addClass('hide');
$('#passwordRequest').addClass('hide');
$('#search').focus();
};
CloudKeys.prototype.getItems = function(search) {
var i, item, j, len, ref, result;
result = [];
search = search.toLowerCase();
ref = this.entities;
for (i = j = 0, len = ref.length; j < len; i = ++j) {
item = ref[i];
if (item.title.toLowerCase().indexOf(search) !== -1 || item.username.toLowerCase().indexOf(search) !== -1 || item.tags.toLowerCase().indexOf(search) !== -1) {
item.num = i;
result.push(i);
}
}
return result;
};
CloudKeys.prototype.sortItems = function(a, b) {
var aTitle, bTitle;
aTitle = a.title.toLowerCase();
bTitle = b.title.toLowerCase();
return ((aTitle < bTitle) ? -1 : ((aTitle > bTitle) ? 1 : 0));
};
CloudKeys.prototype.showForm = function(num) {
var elem, fields, j, len;
$('#editDialog input').val('');
$('#editDialog textarea').val('');
$('#editDialog .hide').removeClass('hide');
fields = ['title', 'username', 'password', 'url', 'comment', 'tags'];
if (typeof num !== "undefined" && typeof this.entities[num] !== "undefined") {
$('#editDialog input[name="num"]').val(num);
for (j = 0, len = fields.length; j < len; j++) {
elem = fields[j];
$("#editDialog #" + elem).val(this.entities[num][elem]);
}
$("#editDialog input#repeat_password").val(this.entities[num]['password']);
} else {
$('#editDialog button.btn-danger').addClass('hide');
}
$('#editDialog').modal({});
$('#editDialog .btn-danger').unbind('click').click((function(_this) {
return function() {
var confirmation;
confirmation = confirm('Are you sure?');
if (confirmation === true) {
num = $('#editDialog input[name="num"]').val();
if (typeof num !== "undefined" && typeof num !== null && num !== "") {
_this.entities.splice(num, 1);
return _this.updateData(function() {
return $('#formClose').click();
});
}
}
};
})(this));
return $('#editDialog .btn-primary').unbind('click').click((function(_this) {
return function() {
var entity, field, l, len1;
if (_this.validateForm()) {
num = $('#editDialog input[name="num"]').val();
entity = {};
for (l = 0, len1 = fields.length; l < len1; l++) {
field = fields[l];
entity[field] = $("#" + field).val();
}
if (typeof num !== "undefined" && num !== "") {
_this.entities[num] = entity;
} else {
_this.entities.push(entity);
}
_this.updateData(function() {
return $('#formClose').click();
});
}
};
})(this));
};
CloudKeys.prototype.validateForm = function() {
var success;
$('#editDialog .has-error').removeClass('has-error');
success = true;
if ($('#title').val() === "") {
$('#title').parent().addClass('has-error');
success = false;
}
if ($('#password').val() !== "" && $('#repeat_password').val() !== $('#password').val()) {
$('#password, #repeat_password').parent().addClass('has-error');
success = false;
}
return success;
};
CloudKeys.prototype.showEditEncPWForm = function() {
$('#editEncPWDialog input').val('');
$('#editEncPWDialog .hide').removeClass('hide');
$('#editEncPWDialog').modal({});
return $('#editEncPWDialog .btn-primary').unbind('click').click((function(_this) {
return function() {
var confirmation, new_password;
$('#editEncPWDialog .has-error').removeClass('has-error');
confirmation = confirm('Do you really want to update your encryption password?');
if (confirmation !== true) {
return;
}
if ($('#editEncPW_current_password').val() !== _this.password) {
$('#editEncPW_current_password').parent().addClass('has-error');
return;
}
new_password = $('#editEncPW_password').val();
if (new_password === void 0 || new_password === '') {
$('#editEncPW_password').parent().addClass('has-error');
return;
}
if (new_password !== $('#editEncPW_repeat_password').val()) {
$('#editEncPW_password, #editEncPW_repeat_password').parent().addClass('has-error');
return;
}
_this.password = new_password;
_this.updateData(function() {
$('#formEncPWClose').click();
return alert('Your encryption password has been changed. Keep this in mind for later.');
});
};
})(this));
};
return CloudKeys;
})();
window.CloudKeys = new CloudKeys();
$('#importLink').click((function(_this) {
return function() {
return $('#importContainer').toggle(500);
};
})(this));
$('#importContainer button').click((function(_this) {
return function() {
return window.CloudKeys["import"]($('#import').val());
};
})(this));
}).call(this);

View file

@ -1,54 +0,0 @@
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
font-size: 16px;
height: auto;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.container.login .form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.container.register .form-signin input[name="password"] {
border-top-left-radius: 0;
border-top-right-radius: 0;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
margin-bottom: -1px;
}
.container.register .form-signin input[name="password_repeat"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}

View file

@ -1 +0,0 @@
body{padding-top:70px}input{outline:0}.navbar a{cursor:pointer}.navbar a.active_account{font-weight:bold}#importContainer{display:none}#importContainer #importer{border:1px solid #111111;border-radius:5px;background-image:linear-gradient(to bottom, #666666 0, #171717 100%);margin:20px 0;padding:20px 20px}#importContainer #importer textarea{border:0;border-radius:5px;display:block;font-size:11px;height:350px;margin:0 auto;padding:0;width:100%}#loader img{display:block;margin:0 auto}#searchbox{border:1px solid #111111;border-radius:5px;background-image:linear-gradient(to bottom, #666666 0, #171717 100%);margin:20px 0;padding:10px}#searchbox input{border:0;border-radius:5px;display:block;font-size:20px;height:40px;margin:0 auto;padding:0 20px;width:100%}#content #resultdescription{margin:15px 0}#content #resultdescription span{font-weight:bold}#content ul#items{list-style:none;padding:0}#content ul#items li.active{background-color:#e5e3e9}#content ul#items li{cursor:pointer;padding:5px 20px}#content ul#items li span{font-size:70%;font-style:italic;padding:0 0 0 20px}#content ul#items li ul{display:none;list-style:none;padding-left:5px}#content ul#items li ul li.last{display:none}@media (min-width:768px){#content ul#items li ul li.last{border-bottom:0;display:block}}#content ul#items li ul li{border-bottom:1px dotted gray}#content ul#items li ul li br{clear:both}#content ul#items li ul li label{display:block;float:left;width:100px}#content ul#items li ul li input,#content ul#items li ul li textarea{background:transparent;border:0;float:left;font-size:11px;min-height:20px;outline:0;padding-left:0;width:300px}#content ul#items li ul li input.password{width:200px}#content ul#items li ul li div.clipboard{background:url('clipboard.png') no-repeat top left;display:inline-block;height:14px;width:14px}#content ul#items li ul li div.clipboard:active{background:url('clipboard_click.png') no-repeat top left}#content ul#items li ul li div.clipboard:hover{background:url('clipboard_hover.png') no-repeat top left}#content ul#items li ul li em{float:left;font-size:70%;width:100px}#content ul#items li ul li span.clippy{display:none}@media (min-width:992px){#content ul#items li ul li span.clippy{display:block;float:left;padding-left:0;width:20px}}#content ul#items li li.odd{background-color:transparent}#content ul#items li:hover{background-color:#e5e3e9}#content ul#items li.odd{background-color:#f6f6f6}

View file

@ -8,7 +8,7 @@ import (
func router() *mux.Router { func router() *mux.Router {
r := mux.NewRouter() r := mux.NewRouter()
r.PathPrefix("/assets/").HandlerFunc(gzipFunc(serveAssets)) r.PathPrefix("/").HandlerFunc(gzipFunc(serveAssets))
registerAPIv2(r.PathPrefix("/v2").Subrouter()) registerAPIv2(r.PathPrefix("/v2").Subrouter())

View file

@ -4,8 +4,6 @@ import (
"net/http" "net/http"
) )
//go:generate go-bindata assets templates
func init() { func init() {
initialize() initialize()
http.Handle("/", router()) http.Handle("/", router())