diff options
-rw-r--r-- | backend/auth/QmUaJyTXpo2mQ9x3AW5xM6T8mTrXkmxTtTYYrD8LspJjoV.ipfs-key | bin | 0 -> 1195 bytes | |||
-rw-r--r-- | backend/resilient/__init__.py | 63 | ||||
-rw-r--r-- | backend/resilient/freenet.py | 6 | ||||
-rwxr-xr-x | backend/update.py | 24 |
4 files changed, 66 insertions, 27 deletions
diff --git a/backend/auth/QmUaJyTXpo2mQ9x3AW5xM6T8mTrXkmxTtTYYrD8LspJjoV.ipfs-key b/backend/auth/QmUaJyTXpo2mQ9x3AW5xM6T8mTrXkmxTtTYYrD8LspJjoV.ipfs-key Binary files differnew file mode 100644 index 0000000..5dac8b0 --- /dev/null +++ b/backend/auth/QmUaJyTXpo2mQ9x3AW5xM6T8mTrXkmxTtTYYrD8LspJjoV.ipfs-key diff --git a/backend/resilient/__init__.py b/backend/resilient/__init__.py index 490ff3f..135c47d 100644 --- a/backend/resilient/__init__.py +++ b/backend/resilient/__init__.py @@ -1,7 +1,13 @@ -import os, urllib +import fileinput +import os +import shutil +import subprocess +import tempfile +import urllib __all__ = ["freenet"] +## Set to change default title name = 'A Wiki for Targeted Individuals' backend_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) @@ -26,9 +32,9 @@ class git: print("ERROR: git not found") exit(1) - def __init__(self, remote, push_remote = None): + def __init__(self, remote, push_remote = ""): self.remote = remote - if push_remote == None: + if push_remote == "": push_remote = remote self.push_remote = push_remote @@ -63,22 +69,23 @@ class ikiwiki: if ikiwiki.synced: return True - html_git_path = os.path.join(html_path, '.git') - os.system("rm -rf '%s'" % html_path) - os.system("mkdir -p '%s'" % html_git_path) + shutil.rmtree(html_path) + os.mkdir(html_path) status = os.system("ikiwiki --wikiname '%s' --rebuild '%s' '%s'" % (name.replace("'","'\"'\"'"), wiki_src_path, html_path)) - ikiwiki.synced = status == 0 + ikiwiki.synced = (status == 0) if ikiwiki.synced: os.system('git gc') os.system('git update-server-info') + html_git_path = os.path.join(html_path, '.git') + os.mkdir(html_git_path) for path in ['objects', 'refs', 'HEAD', 'info', 'packed-refs']: - os.system("cp -r '%s' '%s'" % (os.path.join(git_path, path), html_git_path)) + shutil.copytree(os.path.join(git_path, path), os.path.join(html_git_path, path)) return ikiwiki.synced -class zeronet(): +class zeronet: running = url200('http://127.0.0.1:43110/1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D') if not running: print("WARNING: ZeroNet not running, won't be used") @@ -96,12 +103,46 @@ class zeronet(): self.key = key def push(self): - if not ikiwiki.synced: + if not ikiwiki.synced or not zeronet.found: return False zitedir = os.path.join(zeronet.zn_datadir, self.addr) - status = os.system('cp -r %s %s' % (os.path.join(html_path, '.'), os.path.join(zitedir, '.'))) + shutil.rmtree(zitedir, True) + shutil.copytree(html_path, zitedir) if status != 0: return False status = os.system('%s siteSign %s %s' % (zeronet.zn_script, self.addr, self.key)) return status == 0 +class ipfs: + found = (os.system('ipfs version') == 0) + if not found: + print("WARNING: ipfs not found, ipfs content won't be updated") + else: + found = (os.system('ipns-pub --version') == 0) + if not found: + print ("WARNING: ipns-pub not found, ipfs content won't be updated") + + synced = False + + def __init__(self, keyfile): + self.keyfile = keyfile + + def push(self): + if not ikiwiki.synced or not ipfs.found: + return False + + # add files to ipfs + if not ipfs.synced: + proc = subprocess.Popen(['ipfs', 'add', '-rH', html_path], stdout=subprocess.PIPE) + for line in proc.stdout: + print line[0:-1] + ipfs.hash = line[6:52] + ipfs.synced = True + + # publish hash to private key + proc = subprocess.Popen(['ipns-pub', '-key=%s' % self.keyfile, ipfs.hash]) + status = proc.wait() + if status != 0: + print 'NOTE: ipns-pub failed to run under python as is common, try running by hand.' + print 'CMDLINE: ipns-pub -key=%s %s' % (self.keyfile, ipfs.hash) + return status == 0 diff --git a/backend/resilient/freenet.py b/backend/resilient/freenet.py index ea72760..0f5e741 100644 --- a/backend/resilient/freenet.py +++ b/backend/resilient/freenet.py @@ -10,10 +10,6 @@ class gitocalypse(git): if not found: print("WARNING: gitocalypse not found, changes won't be synced with freenet") - def __init__(self, pull_remote, push_remote = None): - self.remote = pull_remote - self.push_remote = push_remote - class freesitemgr(): found = (os.system("freesitemgr --version") == 0) if not found: @@ -23,7 +19,7 @@ class freesitemgr(): pass def push(self): - if not ikiwiki.synced: + if not ikiwiki.synced or not found or not running: return False config_path = os.path.join(auth_path, 'freesitemgr') status = os.system("freesitemgr -c '%s' -v -r 1 update" % config_path) diff --git a/backend/update.py b/backend/update.py index 47b05c4..0e9bcce 100755 --- a/backend/update.py +++ b/backend/update.py @@ -11,23 +11,24 @@ git_repos = [ resilient.git('fairlystable-guest:/srv/git/standingwithresilience') ] -if resilient.freenet.gitocalypse.found and resilient.freenet.running: - git_repos.extend([ - #### public freenet #### - resilient.freenet.gitocalypse('freenet://USK@hCLgfaINNSNAl4do-PapEincQP5Lxa72d8mFrzHqzqU,jjuBPGO~oCByVoZ5f4Bny0Gp-l3kuDOtf3m-QBT4ekA,AQACAAE/Standing%20With%20Resilience%20Public.git.R1/0', 'freenet://USK@AKL0griFs7T25yw6-JR3Wk7vocvNBelOLg3RwtIL6aTp,jjuBPGO~oCByVoZ5f4Bny0Gp-l3kuDOtf3m-QBT4ekA,AQECAAE/Standing%20With%20Resilience%20Public.git.R1/0'), - #### private freenet #### - resilient.freenet.gitocalypse('freenet://USK@PSY0YngeDtGbj60hjEoilQiY9oKzVrptRC0rG4BEVPg,e6ZEjT4KvbsltPBJOeKNpIdty2oGzbLCdk4fsDA5Vdk,AQACAAE/Standing%20With%20Resilience.git.R1/0') - ]) - zeronet_urls = ['http://bit.no.com:43110'] if resilient.zeronet.running: zeronet_urls.append('http://127.0.0.1:43110') for host in zeronet_urls: git_repos.extend([ #### public zeronet #### - resilient.git('%s/1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4/.git' % host), + resilient.git('%s/1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4/.git' % host, None), #### private zeronet #### - resilient.git('%s/1L363bqJnCG63SnV83kfV7izZXbmentctD/.git' % host) + resilient.git('%s/1L363bqJnCG63SnV83kfV7izZXbmentctD/.git' % host, None) + ]) + +if resilient.freenet.gitocalypse.found and resilient.freenet.running: + git_repos.extend([ + #### public freenet #### + resilient.freenet.gitocalypse('freenet://USK@hCLgfaINNSNAl4do-PapEincQP5Lxa72d8mFrzHqzqU,jjuBPGO~oCByVoZ5f4Bny0Gp-l3kuDOtf3m-QBT4ekA,AQACAAE/Standing%20With%20Resilience%20Public.git.R1/0', + 'freenet://USK@AKL0griFs7T25yw6-JR3Wk7vocvNBelOLg3RwtIL6aTp,jjuBPGO~oCByVoZ5f4Bny0Gp-l3kuDOtf3m-QBT4ekA,AQECAAE/Standing%20With%20Resilience%20Public.git.R1/0'), + #### private freenet #### + resilient.freenet.gitocalypse('freenet://USK@PSY0YngeDtGbj60hjEoilQiY9oKzVrptRC0rG4BEVPg,e6ZEjT4KvbsltPBJOeKNpIdty2oGzbLCdk4fsDA5Vdk,AQACAAE/Standing%20With%20Resilience.git.R1/0') ]) @@ -63,7 +64,8 @@ if not resilient.ikiwiki().push(): hosts = [] if resilient.zeronet.found: - hosts.append(resilient.zeronet('1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4', '5JzZACCELsT4bx66qmV9JDaWhEQ6Sx6j7LzeucsxJGA9H7nuoRr')) + hosts.append(resilient.zeronet('1GtQ8bkFkhYtKerSdXHKe1z4j9VTmFR5d4', + '5JzZACCELsT4bx66qmV9JDaWhEQ6Sx6j7LzeucsxJGA9H7nuoRr')) if resilient.freenet.freesitemgr.found and resilient.freenet.running: hosts.append(resilient.freenet.freesitemgr()) # keys for freesitemgr are in auth/freesitemgr |