Skip to content

Commit

Permalink
Update signed file using the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed May 16, 2016
1 parent d2d2967 commit fc9c604
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plugins/Sidebar/media/Sidebar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ class Sidebar extends Class

if wrapper.site_info.privatekey
# Privatekey stored in users.json
wrapper.ws.cmd "siteSign", ["stored", inner_path], (res) =>
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000

else
# Ask the user for privatekey
wrapper.displayPrompt "Enter your private key:", "password", "Sign", (privatekey) => # Prompt the private key
wrapper.ws.cmd "siteSign", [privatekey, inner_path], (res) =>
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
if res == "ok"
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000

Expand Down
15 changes: 11 additions & 4 deletions src/Ui/UiWebsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def actionServerInfo(self, to):
self.response(to, ret)

# Sign content.json
def actionSiteSign(self, to, privatekey=None, inner_path="content.json", response_ok=True):
def actionSiteSign(self, to, privatekey=None, inner_path="content.json", response_ok=True, update_changed_files=False):
self.log.debug("Signing: %s" % inner_path)
site = self.site
extend = {} # Extended info for signing
Expand All @@ -293,15 +293,20 @@ def actionSiteSign(self, to, privatekey=None, inner_path="content.json", respons
privatekey = self.user.getAuthPrivatekey(self.site.address)

# Signing
site.content_manager.loadContent(inner_path, add_bad_files=False, force=True) # Reload content.json, ignore errors to make it up-to-date
signed = site.content_manager.sign(inner_path, privatekey, extend=extend) # Sign using private key sent by user
# Reload content.json, ignore errors to make it up-to-date
site.content_manager.loadContent(inner_path, add_bad_files=False, force=True)
# Sign using private key sent by user
signed = site.content_manager.sign(inner_path, privatekey, extend=extend, update_changed_files=update_changed_files)
if not signed:
self.cmd("notification", ["error", "Content sign failed: invalid private key."])
self.response(to, {"error": "Site sign failed"})
return

site.content_manager.loadContent(inner_path, add_bad_files=False) # Load new content.json, ignore errors

if update_changed_files:
self.site.updateWebsocket(file_done=inner_path)

if response_ok:
self.response(to, "ok")

Expand Down Expand Up @@ -485,7 +490,9 @@ def actionCertAdd(self, to, domain, auth_type, auth_user_name, cert):
# Display confirmation of change
cert_current = self.user.certs[domain]
body = "You current certificate: <b>%s/%s@%s</b>" % (cert_current["auth_type"], cert_current["auth_user_name"], domain)
self.cmd("confirm", [body, "Change it to %s/%s@%s" % (auth_type, auth_user_name, domain)],
self.cmd(
"confirm",
[body, "Change it to %s/%s@%s" % (auth_type, auth_user_name, domain)],
lambda (res): self.cbCertAddConfirm(to, domain, auth_type, auth_user_name, cert)
)
else:
Expand Down

0 comments on commit fc9c604

Please sign in to comment.