Skip to content

Commit d8e0a83

Browse files
authored
Add enable / disable vHost feature (#94)
Provide the option to disable virtual hosts which removed the host from the web server configuration and do not try to create LE certificates. Closes #59
1 parent 2db6d2f commit d8e0a83

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

kumquat/management/commands/letsencrypt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def issue_cert():
111111
# Use or generate new account for ACME API
112112
key, regr = account()
113113

114-
vhosts = [vhost for vhost in VHost.objects.filter(use_letsencrypt=True) if vhost.letsencrypt_state() in ['REQUEST', 'RENEW']]
114+
vhosts = [vhost for vhost in VHost.objects.filter(use_letsencrypt=True, is_enabled=True) if vhost.letsencrypt_state() in ['REQUEST', 'RENEW']]
115115
if not vhosts:
116116
return
117117

kumquat/management/commands/update_vhosts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def write_certs():
1919

2020
def write_vhost_config():
2121
config = ''
22-
for vhost in VHost.objects.all().annotate(is_defaultvhost=Count('defaultvhost')).order_by('is_defaultvhost'):
22+
for vhost in VHost.objects.filter(is_enabled = True).annotate(is_defaultvhost=Count('defaultvhost')).order_by('is_defaultvhost'):
2323
context = {
2424
'vhost': vhost,
2525
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.1.13 on 2024-05-31 10:29
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('web', '0013_vhost_access_logging'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='vhost',
15+
name='is_enabled',
16+
field=models.BooleanField(default=True, verbose_name='Enable virtual host'),
17+
),
18+
]

web/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class VHost(models.Model):
1515
name = models.CharField(max_length=default_length, verbose_name=_('Sub Domain'), help_text=_('Child part of your domain that is used to organize your site content.'), validators=[DomainNameValidator()])
1616
domain = models.ForeignKey(Domain, blank=False, on_delete=models.CASCADE)
1717
cert = models.ForeignKey('SSLCert', blank=True, null=True, on_delete=models.SET_NULL, verbose_name='SSL Certificate')
18+
is_enabled = models.BooleanField(verbose_name=_('Enable virtual host'), default=True)
1819
use_letsencrypt = models.BooleanField(verbose_name=_('SSL Certificate managed by Let\'s Encrypt'), default=False)
1920
access_logging = models.BooleanField(verbose_name=_('Enable web server access log'), default=False)
2021

web/templates/web/vhost_list.html

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ <h1>{% trans "VHosts" %}</h1>
1414
<thead>
1515
<tr>
1616
<th>{% trans "VHost" %}</th>
17+
<th>{% trans "Enabled" %}</th>
1718
<th>{% trans "SSL" %}</th>
1819
<th>{% trans "Catch-All" %}</th>
1920
<th>&nbsp;</th>
@@ -23,6 +24,7 @@ <h1>{% trans "VHosts" %}</h1>
2324
{% for vhost in object_list %}
2425
<tr>
2526
<td><a href="{% url "web_vhost_update" vhost.pk %}">{{ vhost }}</a></td>
27+
<td>{% if vhost.is_enabled %}{% bootstrap_icon "ok" %}{% else %}{% bootstrap_icon "remove" %}{% endif %}</td>
2628
<td>{% if vhost.cert %}{% bootstrap_icon "ok" %}{% else %}{% bootstrap_icon "remove" %}{% endif %}</td>
2729
<td>
2830
{% if vhost.defaultvhost_set.count %}

web/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ class VHostList(LoginRequiredMixin, ListView):
4848

4949
class VHostCreate(LoginRequiredMixin, SuccessMessageMixin, SuccessActionFormMixin, CreateView):
5050
model = VHost
51-
fields = ('name', 'domain', 'cert', 'use_letsencrypt', 'access_logging')
51+
fields = ('name', 'domain', 'cert', 'is_enabled', 'use_letsencrypt', 'access_logging')
5252
success_url = reverse_lazy('web_vhost_list')
5353
success_message = _("%(name)s was created successfully")
5454
success_action = update_vhosts
5555

5656
class VHostUpdate(LoginRequiredMixin, SuccessActionFormMixin, UpdateView):
5757
model = VHost
58-
fields = ['cert', 'use_letsencrypt', 'access_logging']
58+
fields = ['cert', 'is_enabled', 'use_letsencrypt', 'access_logging']
5959
success_url = reverse_lazy('web_vhost_list')
6060
success_action = update_vhosts
6161

0 commit comments

Comments
 (0)