From 67840131ee4f8a0c43eb66021c5cb8f3a7bcf482 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Mon, 5 Nov 2018 22:56:24 +0100 Subject: [PATCH] Rename tools to net --- usr/lib/python3.6/vmmgr/{tools.py => net.py} | 2 -- usr/lib/python3.6/vmmgr/vmmgr.py | 4 +-- usr/lib/python3.6/vmmgr/wsgiapp.py | 28 ++++++++++---------- 3 files changed, 16 insertions(+), 18 deletions(-) rename usr/lib/python3.6/vmmgr/{tools.py => net.py} (99%) diff --git a/usr/lib/python3.6/vmmgr/tools.py b/usr/lib/python3.6/vmmgr/net.py similarity index 99% rename from usr/lib/python3.6/vmmgr/tools.py rename to usr/lib/python3.6/vmmgr/net.py index 7c376c0..1c530d2 100644 --- a/usr/lib/python3.6/vmmgr/tools.py +++ b/usr/lib/python3.6/vmmgr/net.py @@ -7,8 +7,6 @@ import requests import socket import subprocess -# Network tools - def compile_url(domain, port, proto='https'): port = '' if (proto == 'https' and port == '443') or (proto == 'http' and port == '80') else ':{}'.format(port) return '{}://{}{}'.format(proto, domain, port) diff --git a/usr/lib/python3.6/vmmgr/vmmgr.py b/usr/lib/python3.6/vmmgr/vmmgr.py index 1a6de4a..12833b8 100644 --- a/usr/lib/python3.6/vmmgr/vmmgr.py +++ b/usr/lib/python3.6/vmmgr/vmmgr.py @@ -7,7 +7,7 @@ import subprocess from . import crypto from . import templates -from . import tools +from . import net from .config import Config VERSION = '0.0.1' @@ -53,7 +53,7 @@ class VMMgr: def rebuild_issue(self): # Compile the URLs displayed in terminal banner and rebuild the file with open(ISSUE_FILE, 'w') as f: - f.write(templates.ISSUE.format(url=tools.compile_url(self.domain, self.port), ip=tools.compile_url(tools.get_local_ip(), self.port))) + f.write(templates.ISSUE.format(url=net.compile_url(self.domain, self.port), ip=net.compile_url(net.get_local_ip(), self.port))) def update_password(self, oldpassword, newpassword): # Update LUKS password and adminpwd for WSGI application diff --git a/usr/lib/python3.6/vmmgr/wsgiapp.py b/usr/lib/python3.6/vmmgr/wsgiapp.py index f9b1e2b..3d3d589 100644 --- a/usr/lib/python3.6/vmmgr/wsgiapp.py +++ b/usr/lib/python3.6/vmmgr/wsgiapp.py @@ -13,7 +13,7 @@ from jinja2 import Environment, FileSystemLoader from cryptography.exceptions import InvalidSignature from . import crypto -from . import tools +from . import net from . import validator from .actionqueue import ActionQueue from .appmgr import AppMgr @@ -141,17 +141,17 @@ class WSGIApp(object): def portal_view(self, request): # Default portal view. - host = tools.compile_url(self.conf['host']['domain'], self.conf['host']['port'])[8:] + host = net.compile_url(self.conf['host']['domain'], self.conf['host']['port'])[8:] if request.session['admin']: return self.render_html('portal-admin.html', request, host=host) return self.render_html('portal-user.html', request, host=host) def setup_host_view(self, request): # Host setup view. - ex_ipv4 = tools.get_external_ip(4) - ex_ipv6 = tools.get_external_ip(6) - in_ipv4 = tools.get_local_ip(4) - in_ipv6 = tools.get_local_ip(6) + ex_ipv4 = net.get_external_ip(4) + ex_ipv6 = net.get_external_ip(6) + in_ipv4 = net.get_local_ip(4) + in_ipv6 = net.get_local_ip(6) cert_info = crypto.get_cert_info() return self.render_html('setup-host.html', request, ex_ipv4=ex_ipv4, ex_ipv6=ex_ipv6, in_ipv4=in_ipv4, in_ipv6=in_ipv6, cert_info=cert_info) @@ -242,7 +242,7 @@ class WSGIApp(object): elif not validator.is_valid_port(port): return self.render_json({'error': request.session.lang.invalid_port(port)}) self.vmmgr.update_host(domain, port) - url = '{}/setup-host'.format(tools.compile_url(tools.get_local_ip(), port)) + url = '{}/setup-host'.format(net.compile_url(net.get_local_ip(), port)) response = self.render_json({'ok': request.session.lang.host_updated(url, url)}) response.call_on_close(self.vmmgr.restart_nginx) return response @@ -250,12 +250,12 @@ class WSGIApp(object): def verify_dns_action(self, request): # Check if all FQDNs for all applications are resolvable and point to current external IP domains = [self.vmmgr.domain]+['{}.{}'.format(self.conf['packages'][app]['host'], self.vmmgr.domain) for app in self.conf['apps']] - ipv4 = tools.get_external_ip(4) - ipv6 = tools.get_external_ip(6) + ipv4 = net.get_external_ip(4) + ipv6 = net.get_external_ip(6) for domain in domains: try: - a = tools.resolve_ip(domain, 'A') - aaaa = tools.resolve_ip(domain, 'AAAA') + a = net.resolve_ip(domain, 'A') + aaaa = net.resolve_ip(domain, 'AAAA') if not a and not aaaa: return self.render_json({'error': request.session.lang.dns_record_does_not_exist(domain)}) if a and a != ipv4: @@ -272,9 +272,9 @@ class WSGIApp(object): port = self.vmmgr.port if proto == 'https' else '80' domains = [self.vmmgr.domain]+['{}.{}'.format(self.conf['packages'][app]['host'], self.vmmgr.domain) for app in self.conf['apps']] for domain in domains: - url = tools.compile_url(domain, port, proto) + url = net.compile_url(domain, port, proto) try: - if not tools.ping_url(url): + if not net.ping_url(url): return self.render_json({'error': request.session.lang.http_host_not_reachable(url)}) except: return self.render_json({'error': request.session.lang.http_timeout()}) @@ -298,7 +298,7 @@ class WSGIApp(object): os.unlink('/tmp/private.pem') else: return self.render_json({'error': request.session.lang.cert_request_error()}) - url = tools.compile_url(self.vmmgr.domain, self.vmmgr.port) + url = net.compile_url(self.vmmgr.domain, self.vmmgr.port) return self.render_json({'ok': request.session.lang.cert_installed(url, url)}) def update_common_action(self, request):