summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLassulus <Lassulus@googlemail.com>2011-05-11 13:10:49 +0200
committerLassulus <Lassulus@googlemail.com>2011-05-11 13:10:49 +0200
commit0957c10c6b866657e747e2bbdb6b54cc9b80e1e9 (patch)
treeff71d5f3ad781a1d473542d497454e89373c3eb8
parent735b9995877d12cced345e3369dca123bd7fea41 (diff)
added md5 stuff and better wget alternative
-rwxr-xr-x.scripts/retiolum.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/.scripts/retiolum.py b/.scripts/retiolum.py
index 15e229a0..6314c689 100755
--- a/.scripts/retiolum.py
+++ b/.scripts/retiolum.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2
-import sys, os, time, socket, subprocess, thread, random, Queue, binascii, logging #these should all be in the stdlib
+import sys, os, time, socket, subprocess, thread, random, Queue, binascii, logging, hashlib, urllib2 #these should all be in the stdlib
from optparse import OptionParser
def pub_encrypt(netname, hostname_t, text): #encrypt data with public key
@@ -42,6 +42,22 @@ def getHostname(netname):
print("hostname not found!")
return -1 #nothing found
+def get_hostfiles(netname, url_files, url_md5sum):
+ try:
+ get_hosts_tar = urllib2.urlopen(url_files)
+ get_hosts_md5 = urllib2.urlopen(url_md5sum)
+ hosts_tar = get_hosts_tar.read()
+ hosts_md5 = get_hosts_md5.read()
+
+ if str(hosts_md5) == str(hashlib.md5(hosts_tar).hexdigest() + " hosts.tar.gz\n"):
+ hosts = open("/etc/tinc/" + netname + "/hosts/hosts.tar.gz", "w")
+ hosts.write(hosts_tar)
+ hosts.close()
+ else:
+ logging.error("hosts.tar.gz md5sum check failed!")
+ except:
+ logging.error("hosts file download failed!")
+
####Thread functions
@@ -254,8 +270,9 @@ level_name = option.debug
level = LEVELS.get(level_name, logging.NOTSET)
logging.basicConfig(level=level)
-wget = subprocess.call(["wget vpn.miefda.org/hosts.tar.gz -O /etc/tinc/" + netname + "/hosts/hosts.tar.gz"], shell=True)
-wget = subprocess.call(["tar -xvzf /etc/tinc/" + netname + "/hosts/hosts.tar.gz -C /etc/tinc/" + netname + "/hosts/"], shell=True)
+get_hostfiles(netname, "http://vpn.miefda.org/hosts.tar.gz", "http://vpn.miefda.org/hosts.md5")
+
+tar = subprocess.call(["tar -xzf /etc/tinc/" + netname + "/hosts/hosts.tar.gz -C /etc/tinc/" + netname + "/hosts/"], shell=True)
start_tincd = subprocess.call(["tincd -n " + netname ],shell=True)
sendfifo = Queue.Queue() #sendtext