letsencrypt: Remove old style hooks from all configuration files

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Sunil Mohan Adapa 2019-06-13 12:47:22 -07:00 committed by Joseph Nuthalapati
parent d8647aaf18
commit 486f91d129
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35
2 changed files with 50 additions and 1 deletions

View File

@ -20,12 +20,15 @@ Configuration helper for Let's Encrypt.
"""
import argparse
import glob
import json
import os
import re
import subprocess
import sys
import configobj
from plinth import action_utils
from plinth.modules import letsencrypt as le
@ -141,6 +144,10 @@ def subcommand_setup(arguments):
Nothing to do for first time setup and for newer versions.
"""
if arguments.old_version == 2:
_remove_old_hooks()
return
if arguments.old_version != 1:
return
@ -202,6 +209,48 @@ def subcommand_obtain(arguments):
setup_webserver_config(domain, webserver_change)
def _remove_old_hooks():
"""Remove old style renewal hooks from individual configuration files.
This has been replaced with global hooks by adding script files in directory
/etc/letsencrypt/renewal-hooks/{pre,post,deploy}/.
"""
for file_path in glob.glob(RENEWAL_DIRECTORY + '*.conf'):
try:
_remove_old_hooks_from_file(file_path)
except Exception as exception:
print('Error removing hooks from file:', file_path, exception)
def _remove_old_hooks_from_file(file_path):
"""Remove old style hooks from a single configuration file."""
config = configobj.ConfigObj(file_path)
edited = False
for line in config.initial_comment:
if 'edited by plinth' in line.lower():
edited = True
if not edited:
return
config.initial_comment = [
line for line in config.initial_comment
if 'edited by plinth' not in line.lower()
]
if 'pre_hook' in config['renewalparams']:
del config['renewalparams']['pre_hook']
if 'renew_hook' in config['renewalparams']:
del config['renewalparams']['renew_hook']
if 'post_hook' in config['renewalparams']:
del config['renewalparams']['post_hook']
config.write()
def subcommand_run_pre_hooks(_):
"""Do nothing, kept for legacy LE configuration.

View File

@ -33,7 +33,7 @@ from plinth.utils import format_lazy
from .manifest import backup
version = 2
version = 3
is_essential = True