Try to recover site privatekey from master seed when site owned switch enabled
This commit is contained in:
parent
e14f5bf847
commit
e97236201c
2 changed files with 37 additions and 3 deletions
|
@ -737,10 +737,35 @@ class UiWebsocketPlugin(object):
|
||||||
@flag.no_multiuser
|
@flag.no_multiuser
|
||||||
def actionSiteSetOwned(self, to, owned):
|
def actionSiteSetOwned(self, to, owned):
|
||||||
if self.site.address == config.updatesite:
|
if self.site.address == config.updatesite:
|
||||||
return self.response(to, "You can't change the ownership of the updater site")
|
return {"error": "You can't change the ownership of the updater site"}
|
||||||
|
|
||||||
self.site.settings["own"] = bool(owned)
|
self.site.settings["own"] = bool(owned)
|
||||||
self.site.updateWebsocket(owned=owned)
|
self.site.updateWebsocket(owned=owned)
|
||||||
|
return "ok"
|
||||||
|
|
||||||
|
@flag.admin
|
||||||
|
@flag.no_multiuser
|
||||||
|
def actionSiteRecoverPrivatekey(self, to):
|
||||||
|
from Crypt import CryptBitcoin
|
||||||
|
|
||||||
|
site_data = self.user.sites[self.site.address]
|
||||||
|
if site_data.get("privatekey"):
|
||||||
|
return {"error": "This site already has saved privated key"}
|
||||||
|
|
||||||
|
address_index = self.site.content_manager.get("content.json", {}).get("address_index")
|
||||||
|
if not address_index:
|
||||||
|
return {"error": "No address_index in content.json"}
|
||||||
|
|
||||||
|
privatekey = CryptBitcoin.hdPrivatekey(self.user.master_seed, address_index)
|
||||||
|
privatekey_address = CryptBitcoin.privatekeyToAddress(privatekey)
|
||||||
|
|
||||||
|
if privatekey_address == self.site.address:
|
||||||
|
site_data["privatekey"] = privatekey
|
||||||
|
self.user.save()
|
||||||
|
self.site.updateWebsocket(recover_privatekey=True)
|
||||||
|
return "ok"
|
||||||
|
else:
|
||||||
|
return {"error": "Unable to deliver private key for this site from current user's master_seed"}
|
||||||
|
|
||||||
@flag.admin
|
@flag.admin
|
||||||
@flag.no_multiuser
|
@flag.no_multiuser
|
||||||
|
|
|
@ -441,9 +441,18 @@ class Sidebar extends Class
|
||||||
|
|
||||||
# Owned checkbox
|
# Owned checkbox
|
||||||
@tag.find("#checkbox-owned").off("click touchend").on "click touchend", =>
|
@tag.find("#checkbox-owned").off("click touchend").on "click touchend", =>
|
||||||
@wrapper.ws.cmd "siteSetOwned", [@tag.find("#checkbox-owned").is(":checked")]
|
owned = @tag.find("#checkbox-owned").is(":checked")
|
||||||
|
@wrapper.ws.cmd "siteSetOwned", [owned], (res_set_owned) =>
|
||||||
|
@log "Owned", owned
|
||||||
|
if owned
|
||||||
|
@wrapper.ws.cmd "siteRecoverPrivatekey", [], (res_recover) =>
|
||||||
|
if res_recover == "ok"
|
||||||
|
@wrapper.notifications.add("recover", "done", "Private key recovered from master seed")
|
||||||
|
else
|
||||||
|
@log "Unable to recover private key: #{res_recover.error}"
|
||||||
|
|
||||||
# Owned checkbox
|
|
||||||
|
# Owned auto download checkbox
|
||||||
@tag.find("#checkbox-autodownloadoptional").off("click touchend").on "click touchend", =>
|
@tag.find("#checkbox-autodownloadoptional").off("click touchend").on "click touchend", =>
|
||||||
@wrapper.ws.cmd "siteSetAutodownloadoptional", [@tag.find("#checkbox-autodownloadoptional").is(":checked")]
|
@wrapper.ws.cmd "siteSetAutodownloadoptional", [@tag.find("#checkbox-autodownloadoptional").is(":checked")]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue