diff --git a/plugins/Sidebar/SidebarPlugin.py b/plugins/Sidebar/SidebarPlugin.py index 473b9f9e..f3d97f3d 100644 --- a/plugins/Sidebar/SidebarPlugin.py +++ b/plugins/Sidebar/SidebarPlugin.py @@ -126,7 +126,7 @@ class UiWebsocketPlugin(object): <li> <label> {_[Peers]} - <small><a href='{copy_link}' id='link-copypeers' class='link-right'>{_[Copy to clipboard]}</a></small> + <small class="label-right"><a href='{copy_link}' id='link-copypeers' class='link-right'>{_[Copy to clipboard]}</a></small> </label> <ul class='graph'> <li style='width: 100%' class='total back-black' title="{_[Total peers]}"></li> @@ -174,7 +174,7 @@ class UiWebsocketPlugin(object): <li> <label> {_[Files]} - <small><a href='#Site+directory' id='link-directory' class='link-right'>{_[Open site directory]}</a> + <small class="label-right"><a href='#Site+directory' id='link-directory' class='link-right'>{_[Open site directory]}</a> <a href='/ZeroNet-Internal/Zip?address={site.address}' id='link-zip' class='link-right' download='site.zip'>{_[Save as .zip]}</a></small> </label> <ul class='graph graph-stacked'> @@ -480,9 +480,15 @@ class UiWebsocketPlugin(object): """)) def sidebarRenderContents(self, body, site): + has_privatekey = bool(self.user.getSiteData(site.address).get("privatekey")) + if has_privatekey: + tag_privatekey = _(u"{_[Private key saved.]} <a href='#Forgot+private+key' id='privatekey-forgot' class='link-right'>{_[Forgot]}</a>") + else: + tag_privatekey = _(u"<a href='#Add+private+key' id='privatekey-add' class='link-right'>{_[Add saved private key]}</a>") + body.append(_(u""" <li> - <label>{_[Content publishing]}</label> + <label>{_[Content publishing]} <small class='label-right'>{tag_privatekey}</small></label> """)) # Choose content you want to sign @@ -709,6 +715,17 @@ class UiWebsocketPlugin(object): self.site.settings["own"] = bool(owned) self.site.updateWebsocket(owned=owned) + def actionUserSetSitePrivatekey(self, to, privatekey): + permissions = self.getPermissions(to) + if "ADMIN" not in permissions: + return self.response(to, "You don't have permission to run this command") + + site_data = self.user.sites[self.site.address] + site_data["privatekey"] = privatekey + self.site.updateWebsocket(set_privatekey=bool(privatekey)) + + return "ok" + def actionSiteSetAutodownloadoptional(self, to, owned): permissions = self.getPermissions(to) if "ADMIN" not in permissions: diff --git a/plugins/Sidebar/media/Sidebar.coffee b/plugins/Sidebar/media/Sidebar.coffee index 7f5c8f1d..fb78370b 100644 --- a/plugins/Sidebar/media/Sidebar.coffee +++ b/plugins/Sidebar/media/Sidebar.coffee @@ -202,6 +202,19 @@ class Sidebar extends Class return true } + # Save and forgot privatekey for site signing + @tag.find("#privatekey-add").off("click, touchend").on "click touchend", (e) => + @wrapper.displayPrompt "Enter your private key:", "password", "Save", "", (privatekey) => + @wrapper.ws.cmd "userSetSitePrivatekey", [privatekey], (res) => + @wrapper.notifications.add "privatekey", "done", "Private key saved for site signing", 5000 + return false + + @tag.find("#privatekey-forgot").off("click, touchend").on "click touchend", (e) => + @wrapper.ws.cmd "userSetSitePrivatekey", [""], (res) => + @wrapper.notifications.add "privatekey", "done", "Saved private key removed", 5000 + return false + + animDrag: (e) => mousex = e.pageX diff --git a/plugins/Sidebar/media/Sidebar.css b/plugins/Sidebar/media/Sidebar.css index 660b1bab..58b2582e 100644 --- a/plugins/Sidebar/media/Sidebar.css +++ b/plugins/Sidebar/media/Sidebar.css @@ -12,7 +12,8 @@ .body-sidebar iframe { transform: rotateY(5deg); opacity: 0.8; pointer-events: none; outline: 1px solid transparent } .body-internals iframe { transform: rotateX(5deg); opacity: 0.8; pointer-events: none; outline: 1px solid transparent } -.sidebar .link-right { color: white; text-decoration: none; border-bottom: 1px solid #666; text-transform: uppercase; float: right; margin-right: 7px; margin-top: 1px; } +.sidebar .label-right { float: right; margin-right: 7px; margin-top: 1px; float: right; } +.sidebar .link-right { color: white; text-decoration: none; border-bottom: 1px solid #666; text-transform: uppercase; } .sidebar .link-right:hover { border-color: #CCC; } .sidebar .link-right:active { background-color: #444 } /* SIDEBAR */ diff --git a/plugins/Sidebar/media/all.css b/plugins/Sidebar/media/all.css index fcf00618..5e81feb2 100644 --- a/plugins/Sidebar/media/all.css +++ b/plugins/Sidebar/media/all.css @@ -113,7 +113,8 @@ .body-sidebar iframe { -webkit-transform: rotateY(5deg); -moz-transform: rotateY(5deg); -o-transform: rotateY(5deg); -ms-transform: rotateY(5deg); transform: rotateY(5deg) ; opacity: 0.8; pointer-events: none; outline: 1px solid transparent } .body-internals iframe { -webkit-transform: rotateX(5deg); -moz-transform: rotateX(5deg); -o-transform: rotateX(5deg); -ms-transform: rotateX(5deg); transform: rotateX(5deg) ; opacity: 0.8; pointer-events: none; outline: 1px solid transparent } -.sidebar .link-right { color: white; text-decoration: none; border-bottom: 1px solid #666; text-transform: uppercase; float: right; margin-right: 7px; margin-top: 1px; } +.sidebar .label-right { float: right; margin-right: 7px; margin-top: 1px; float: right; } +.sidebar .link-right { color: white; text-decoration: none; border-bottom: 1px solid #666; text-transform: uppercase; } .sidebar .link-right:hover { border-color: #CCC; } .sidebar .link-right:active { background-color: #444 } /* SIDEBAR */ diff --git a/plugins/Sidebar/media/all.js b/plugins/Sidebar/media/all.js index 79124e3a..1a9725a9 100644 --- a/plugins/Sidebar/media/all.js +++ b/plugins/Sidebar/media/all.js @@ -584,9 +584,9 @@ window.initScrollable = function () { this.log("Creating content"); this.container.addClass("loaded"); morphdom(this.tag.find(".content")[0], '<div class="content">' + res + '</div>'); - return this.when_loaded.resolve(); + this.when_loaded.resolve(); } else { - return morphdom(this.tag.find(".content")[0], '<div class="content">' + res + '</div>', { + morphdom(this.tag.find(".content")[0], '<div class="content">' + res + '</div>', { onBeforeMorphEl: function(from_el, to_el) { if (from_el.className === "globe" || from_el.className.indexOf("noupdate") >= 0) { return false; @@ -596,6 +596,24 @@ window.initScrollable = function () { } }); } + this.tag.find("#privatekey-add").off("click, touchend").on("click touchend", (function(_this) { + return function(e) { + _this.wrapper.displayPrompt("Enter your private key:", "password", "Save", "", function(privatekey) { + return _this.wrapper.ws.cmd("userSetSitePrivatekey", [privatekey], function(res) { + return _this.wrapper.notifications.add("privatekey", "done", "Private key saved for site signing", 5000); + }); + }); + return false; + }; + })(this)); + return this.tag.find("#privatekey-forgot").off("click, touchend").on("click touchend", (function(_this) { + return function(e) { + _this.wrapper.ws.cmd("userSetSitePrivatekey", [""], function(res) { + return _this.wrapper.notifications.add("privatekey", "done", "Saved private key removed", 5000); + }); + return false; + }; + })(this)); }; Sidebar.prototype.animDrag = function(e) {