Commit 8d07244c authored by Guillaume Bury's avatar Guillaume Bury

Fixed ip from cert in vifibnet.py

parent bf262697
#!/usr/bin/env python #!/usr/bin/env python
import argparse, errno, os, select, sqlite3, subprocess, sys, time, xmlrpclib import argparse, errno, math, os, select, sqlite3, subprocess, sys, time, xmlrpclib
from OpenSSL import crypto from OpenSSL import crypto
import traceback import traceback
import upnpigd import upnpigd
...@@ -56,8 +56,9 @@ class PeersDB: ...@@ -56,8 +56,9 @@ class PeersDB:
log.log('Updating peers database : unusing peer ' + str(id), 5) log.log('Updating peers database : unusing peer ' + str(id), 5)
self.db.execute("UPDATE peers SET used = 0 WHERE id = ?", (id,)) self.db.execute("UPDATE peers SET used = 0 WHERE id = ?", (id,))
def ipFromPrefix(prefix): def ipFromPrefix(prefix, prefix_len):
tmp = hex(int(prefix, 2))[2:] tmp = hex(int(prefix))[2:]
tmp = tmp.rjust(int((math.ceil(float(prefix_len) / 4))), '0')
ip = VIFIB_NET ip = VIFIB_NET
for i in xrange(0, len(tmp), 4): for i in xrange(0, len(tmp), 4):
ip += tmp[i:i+4] + ':' ip += tmp[i:i+4] + ':'
...@@ -113,6 +114,7 @@ def getConfig(): ...@@ -113,6 +114,7 @@ def getConfig():
_('--cert', required=True, _('--cert', required=True,
help='Path to the certificate file') help='Path to the certificate file')
# Temporary args - to be removed # Temporary args - to be removed
# Can be removed, should ip be a global variable ?
_('--ip', required=True, _('--ip', required=True,
help='IPv6 of the server') help='IPv6 of the server')
# Openvpn options # Openvpn options
...@@ -123,8 +125,8 @@ def getConfig(): ...@@ -123,8 +125,8 @@ def getConfig():
with open(config.cert, 'r') as f: with open(config.cert, 'r') as f:
cert = crypto.load_certificate(crypto.FILETYPE_PEM, f.read()) cert = crypto.load_certificate(crypto.FILETYPE_PEM, f.read())
subject = cert.get_subject() subject = cert.get_subject()
prefix, _ = subject.serialNumber.split('/') prefix, prefix_len = subject.serialNumber.split('/')
ip = ipFromPrefix(prefix) ip = ipFromPrefix(prefix, int(prefix_len))
print ip print ip
log.log('Intranet ip : %s' % (ip,), 4) log.log('Intranet ip : %s' % (ip,), 4)
if config.openvpn_args[0] == "--": if config.openvpn_args[0] == "--":
...@@ -198,7 +200,7 @@ def main(): ...@@ -198,7 +200,7 @@ def main():
# Get arguments # Get arguments
getConfig() getConfig()
log.verbose = config.verbose log.verbose = config.verbose
# TODO: get proto to use ? # TODO: how do we decide which protocol we use ?
(externalIp, externalPort) = upnpigd.GetExternalInfo(1194) (externalIp, externalPort) = upnpigd.GetExternalInfo(1194)
# Setup database # Setup database
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment