diff --git a/basic/srv/spotter/appmgr/__init__.py b/basic/srv/spotter/appmgr/__init__.py index dce96a5..0506b8f 100644 --- a/basic/srv/spotter/appmgr/__init__.py +++ b/basic/srv/spotter/appmgr/__init__.py @@ -108,7 +108,7 @@ ISSUE_TEMPLATE = ''' - Pro přístup k aplikacím otevřete URL \x1b[1mhttps://{host}\x1b[0m ve Vašem + Pro přístup k aplikacím otevřete URL \x1b[1m{url}\x1b[0m ve Vašem internetovém prohlížeči. @@ -254,25 +254,21 @@ class AppMgr: def rebuild_issue(self): # Compile the HTTPS host displayed in terminal banner - host = self.domain + domain = self.domain # If the dummy host is used, take an IP address of a primary interface instead - if self.domain == 'spotter.vm': - host = tools.get_local_ipv4() - if not host: - host = tools.get_local_ipv6() - if not host: - host = '127.0.0.1' - # Show port number only when using the non-default HTTPS port - if self.port != '443': - host += ':{}'.format(self.port) + if domain == 'spotter.vm': + domain = tools.get_local_ipv4() + if not domain: + domain = tools.get_local_ipv6() + if not domain: + domain = '127.0.0.1' # Rebuild the terminal banner with open(ISSUE_FILE, 'w') as f: - f.write(ISSUE_TEMPLATE.format(host=host)) + f.write(ISSUE_TEMPLATE.format(url=tools.compile_url(domain, self.port))) def update_apps_urls(self): # Update configuration for respective applications - host = '{}:{}'.format(self.domain, self.port) if self.port != '443' else self.domain - confupdater.update_url(host) + confupdater.update_url(tools.compile_url(self.domain, self.port)) # Restart currently running apps in order to update config and re-register nginx proxy for app in self.conf['apps']: if tools.is_service_started(app): diff --git a/basic/srv/spotter/appmgr/tools.py b/basic/srv/spotter/appmgr/tools.py index 55e6816..4d420e8 100644 --- a/basic/srv/spotter/appmgr/tools.py +++ b/basic/srv/spotter/appmgr/tools.py @@ -11,6 +11,10 @@ import subprocess NULL_IP = '[100::1]' +def compile_url(domain, port, proto='https'): + port = ':{}'.format(port) if (proto == 'https' and port != '443') or (proto == 'http' and port != '80') else '' + return '{}://{}{}'.format(proto, domain, port) + def get_container_ip(app): # Return an IP address of a container. If the container is not running, return address from IPv6 discard prefix instead try: @@ -37,7 +41,7 @@ def get_external_ip(family): allowed_gai_family = requests.packages.urllib3.util.connection.allowed_gai_family try: requests.packages.urllib3.util.connection.allowed_gai_family = lambda: family - return requests.get('http://tools.dasm.cz/myip.php', timeout=5).text + return requests.get('https://tools.dasm.cz/myip.php', timeout=5).text except: return None finally: @@ -67,7 +71,7 @@ def resolve_ip(domain, type): def ping_url(url): try: - return requests.post('http://tools.dasm.cz/spotter-ping.php', data = {'url': url}, timeout=5).text == 'spotter-pong' + return requests.post('https://tools.dasm.cz/spotter-ping.php', data = {'url': url}, timeout=5).text == 'spotter-pong' except requests.exceptions.Timeout: raise except: diff --git a/basic/srv/spotter/appmgr/wsgiapp.py b/basic/srv/spotter/appmgr/wsgiapp.py index fb0b7d3..547ac8b 100644 --- a/basic/srv/spotter/appmgr/wsgiapp.py +++ b/basic/srv/spotter/appmgr/wsgiapp.py @@ -129,13 +129,13 @@ class WSGIApp(object): return self.render_template('setup-apps.html', request) def update_host_action(self, request): - # Update domain and port, then restart nginx (done via ClosingIterator in self.wsgi_app()) + # Update domain and port, then restart nginx try: domain = request.form['domain'] port = request.form['port'] request.mgr.update_host(domain, port, False) server_name = request.environ['HTTP_X_FORWARDED_SERVER_NAME'] - url = 'https://{}/setup-host'.format('{}:{}'.format(server_name, port) if port != '443' else server_name) + url = '{}/setup-host'.format(tools.compile_url(server_name, port)) response = self.render_json({'ok': request.session.lang.host_updated(url, url)}) response.call_on_close(tools.restart_nginx) return response @@ -171,16 +171,16 @@ class WSGIApp(object): # Check if all applications are accessible from the internet using 3rd party ping service proto = kwargs['proto'] mgr = request.mgr + port = mgr.port if proto == 'https' else '80' domains = [mgr.domain]+['{}.{}'.format(mgr.conf['apps'][app]['host'], mgr.domain) for app in mgr.conf['apps']] for domain in domains: - host = '{}:{}'.format(domain, mgr.port) if proto == 'https' and mgr.port != '443' else domain - url = '{}://{}/'.format(proto, host) + url = tools.compile_url(domain, port, proto) try: if not tools.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()}) - return self.render_json({'ok': request.session.lang.http_hosts_ok(mgr.port if proto == 'https' else '80')}) + return self.render_json({'ok': request.session.lang.http_hosts_ok(port)}) def update_cert_action(self, request): # Update certificate - either request via Let's Encrypt or manually upload files @@ -203,7 +203,8 @@ class WSGIApp(object): return self.render_json({'error': request.session.lang.malformed_request()}) except: return self.render_json({'error': request.session.lang.cert_request_error()}) - return self.render_json({'ok': request.session.lang.cert_installed()}) + url = tools.compile_url(request.mgr.domain, request.mgr.port) + return self.render_json({'ok': request.session.lang.cert_installed(url, url)}) def update_common_action(self, request): # Update common settings shared between apps - admin e-mail address, Google Maps API key diff --git a/basic/srv/spotter/appmgr/wsgilang.py b/basic/srv/spotter/appmgr/wsgilang.py index 98a2d0a..65b892c 100644 --- a/basic/srv/spotter/appmgr/wsgilang.py +++ b/basic/srv/spotter/appmgr/wsgilang.py @@ -16,7 +16,7 @@ class WSGILang: 'cert_file_missing': 'Nebyl vybrán soubor s certifikátem.', 'key_file_missing': 'Nebyl vybrán soubor se soukromým klíčem.', 'cert_request_error': 'Došlo k chybě při žádosti o certifikát. Zkontrolujte, zda je virtuální stroj dostupný z internetu na portu 80.', - 'cert_installed': 'Certifikát byl úspěšně nainstalován. Obnovte stránku nebo restartujte webový prohlížeč pro jeho načtení.', + 'cert_installed': 'Certifikát byl úspěšně nainstalován. Přejděte na URL {} nebo restartujte webový prohlížeč pro jeho načtení.', 'common_updated': 'Nastavení aplikací bylo úspěšně změněno.', 'app_started': 'Spuštěna (zastavit)', 'app_stopped': 'Zastavena (spustit)', diff --git a/basic/srv/spotter/static/js/admin.js b/basic/srv/spotter/static/js/admin.js index 3c5b03a..3ea833b 100644 --- a/basic/srv/spotter/static/js/admin.js +++ b/basic/srv/spotter/static/js/admin.js @@ -25,6 +25,8 @@ function update_host() { $('#host-submit').show(); } else { $('#host-message').attr('class','info').html(data.ok).show(); + $('input').prop('disabled', true); + $('.setup-box').slice(1).css('opacity', '0.5'); } }); return false; @@ -85,10 +87,10 @@ function update_cert() { $.ajax({url: '/update-cert', type: 'POST', data: new FormData($('#update-cert')[0]), cache: false, contentType: false, processData: false, success: function(data) { $('#cert-wait').hide(); if (data.error) { - $('#cert-message').attr('class','error').text(data.error).show(); + $('#cert-message').attr('class','error').html(data.error).show(); $('#cert-submit').show(); } else { - $('#cert-message').attr('class','info').text(data.ok).show(); + $('#cert-message').attr('class','info').html(data.ok).show(); } }}); return false; diff --git a/basic/srv/spotter/templates/portal-admin.html b/basic/srv/spotter/templates/portal-admin.html index 4a1391a..d2e54aa 100644 --- a/basic/srv/spotter/templates/portal-admin.html +++ b/basic/srv/spotter/templates/portal-admin.html @@ -78,7 +78,7 @@

Open Data KitODK Build

Sběr dat s pomocí smartphone.
Aplikace pro návrh formulářů
-

XLSForm - online konverter XLS.
+

XLSForm - online konverter XLS.
ODK Form UploaderODK Form Uploader
ODK ValidateODK Validate

@@ -333,7 +333,7 @@
-

OpenIDOpenID

+

OpenIDOpenID

Pro ověření identity budete potřebovat účet OpenID. Zaregistrujte se. Registraci využijete v software Sahana EDEN.