Rename tools to net

This commit is contained in:
Disassembler 2018-11-05 22:56:24 +01:00
parent 3e0363b904
commit 67840131ee
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
3 changed files with 16 additions and 18 deletions

View File

@ -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)

View File

@ -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

View File

@ -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):