Commit d5d89296 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Port forwarding is now correctly refreshed

parent a35450fc
...@@ -5,14 +5,9 @@ from email.mime.text import MIMEText ...@@ -5,14 +5,9 @@ from email.mime.text import MIMEText
from OpenSSL import crypto from OpenSSL import crypto
import utils import utils
# To generate server ca and key with serial for 2001:db8:42::/48 # Fix for librpcxml to avoid doing reverse dns on each request
# openssl req -nodes -new -x509 -key ca.key -set_serial 0x120010db80042 -days 365 -out ca.crt # it was causing a 5-10s delay on each request when no reverse DNS was avalaible
# for tis IP
IPV6_V6ONLY = 26
SOL_IPV6 = 41
# Fix for librpcxml to avoid doing reverse dns on each request : it was causing a 5s delay on each request
import BaseHTTPServer import BaseHTTPServer
...@@ -24,6 +19,13 @@ BaseHTTPServer.BaseHTTPRequestHandler.address_string = not_insane_address_string ...@@ -24,6 +19,13 @@ BaseHTTPServer.BaseHTTPRequestHandler.address_string = not_insane_address_string
# end of the fix # end of the fix
# To generate server ca and key with serial for 2001:db8:42::/48
# openssl req -nodes -new -x509 -key ca.key -set_serial 0x120010db80042 -days 365 -out ca.crt
IPV6_V6ONLY = 26
SOL_IPV6 = 41
class RequestHandler(SimpleXMLRPCRequestHandler): class RequestHandler(SimpleXMLRPCRequestHandler):
def _dispatch(self, method, params): def _dispatch(self, method, params):
......
...@@ -48,11 +48,12 @@ class Forwarder: ...@@ -48,11 +48,12 @@ class Forwarder:
int(local_port), 'Vifib openvpn server', ''): int(local_port), 'Vifib openvpn server', ''):
utils.log('Forwarding %s:%s to %s:%s' % (self._external_ip, utils.log('Forwarding %s:%s to %s:%s' % (self._external_ip,
external_port, self._u.lanaddr, local_port), 3) external_port, self._u.lanaddr, local_port), 3)
self._rules.append((external_port, upnp_proto)) self._rules.append((external_port, int(local_port), upnp_proto))
return (self._external_ip, str(external_port), proto) return (self._external_ip, str(external_port), proto)
def Refresh(self): def refresh(self):
for external_port, proto in self._rules: utils.log('Refreshing port forwarding', 3)
for external_port, local_port, proto in self._rules:
self._u.addportmapping(external_port, proto, self._u.lanaddr, self._u.addportmapping(external_port, proto, self._u.lanaddr,
self._local_port, 'Vifib openvpn server', '') local_port, 'Vifib openvpn server', '')
self.next_refresh = time.time() + 3600 self.next_refresh = time.time() + 3600
...@@ -3,6 +3,7 @@ import argparse, errno, os, select, subprocess, time ...@@ -3,6 +3,7 @@ import argparse, errno, os, select, subprocess, time
from argparse import ArgumentParser from argparse import ArgumentParser
import db, plib, upnpigd, utils, tunnel import db, plib, upnpigd, utils, tunnel
class ArgParser(ArgumentParser): class ArgParser(ArgumentParser):
def convert_arg_line_to_args(self, arg_line): def convert_arg_line_to_args(self, arg_line):
...@@ -15,6 +16,7 @@ class ArgParser(ArgumentParser): ...@@ -15,6 +16,7 @@ class ArgParser(ArgumentParser):
if arg.strip(): if arg.strip():
yield arg yield arg
def ovpnArgs(optional_args, ca_path, cert_path): def ovpnArgs(optional_args, ca_path, cert_path):
# Treat openvpn arguments # Treat openvpn arguments
if optional_args[0] == "--": if optional_args[0] == "--":
...@@ -146,6 +148,7 @@ def main(): ...@@ -146,6 +148,7 @@ def main():
# main loop # main loop
try: try:
while True: while True:
utils.log('Sleeping ...', 2)
nextUpdate = min(tunnel_manager.next_refresh, peer_db.next_refresh) nextUpdate = min(tunnel_manager.next_refresh, peer_db.next_refresh)
if forwarder != None: if forwarder != None:
nextUpdate = min(nextUpdate, forwarder.next_refresh) nextUpdate = min(nextUpdate, forwarder.next_refresh)
...@@ -158,6 +161,8 @@ def main(): ...@@ -158,6 +161,8 @@ def main():
peer_db.refresh() peer_db.refresh()
if time.time() >= tunnel_manager.next_refresh: if time.time() >= tunnel_manager.next_refresh:
tunnel_manager.refresh() tunnel_manager.refresh()
if forwarder != None and time.time() > forwarder.next_refresh:
forwarder.refresh()
except KeyboardInterrupt: except KeyboardInterrupt:
return 0 return 0
......
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