Commit 25fcd42c authored by Marco Marinello's avatar Marco Marinello

Remove unuseful stuff (since it's yet managed via Ansible)

parent 1c52ed5b
# -*- coding: utf-8 -*-
# Importazione dell'elenco dei corsi
# Copyright (c) 2019 Marco Marinello <>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
from import BaseCommand
from access_landing import models
import re
class Command(BaseCommand):
help = "Generate virtual hosts for apache"
RE_IP_REGEX = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
RE_FQDN_REGEX = "^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$"
def is_valid_fqdn_or_ip(self, s):
if s == None:
return False
if s.startswith("http://"):
s = s[7:]
elif s.startswith("https://"):
s = s[8:]
return re.match(self.RE_IP_REGEX, s) or re.match(self.RE_FQDN_REGEX, s)
def gen_vhost(self, school):
return f"""<VirtualHost *:443>
\tServerName {school.external_host}
\tServerAdmin webmaster@{school.external_host}
\tDocumentRoot /var/www/html
\tInclude /etc/apache2/ssl.conf
\tSSLProxyEngine on
\tSSLProxyCheckPeerName off
\tProxyVia on
\tProxyPass / {school.internal_host}/
\tProxyPassReverse / {school.internal_host}/
\tProxyPreserveHost on
\t<Location /fra_errors>
\t\tProxyPass !
\tInclude /etc/apache2/fra_erros.conf
def gen_disabled_vhost(self, school):
return f"""<VirtualHost *:443>
\tServerName {school.external_host}
\tServerAdmin webmaster@{school.external_host}
\tDocumentRoot /var/www/fra_disabled
\tInclude /etc/apache2/ssl.conf
def handle(self, *args, **kwargs):
for school in models.Institute.objects.filter():
if self.is_valid_fqdn_or_ip(school.external_host) and \
self.is_valid_fqdn_or_ip(school.internal_host) and \
elif school.external_host:
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