X-Git-Url: https://git.sesse.net/?p=letsencrypt-varnish-plugin;a=blobdiff_plain;f=varnish.py;h=15ca47543a03820d418019e6e56d43c1e815c1f2;hp=87abf22f9bd75c568f9e7ae7f82116cb3d0b69b3;hb=refs%2Fheads%2Fmaster;hpb=f282688a47568c825ddf3c68fa3b6c62b7c48d5a diff --git a/varnish.py b/varnish.py index 87abf22..15ca475 100644 --- a/varnish.py +++ b/varnish.py @@ -4,28 +4,28 @@ import logging import re import subprocess -import zope.component import zope.interface +from zope.interface import implementer, provider from acme import challenges -from letsencrypt import errors -from letsencrypt import interfaces -from letsencrypt.plugins import common +from certbot import errors +from certbot import interfaces +from certbot.plugins import common logger = logging.getLogger(__name__) def vcl_recv_line(achall): # Don't bother checking for the right host, we could be coming in through a redirect. - return 'if (req.url == "/%s/%s") { return (synth(999, "Challenge")); } # Added by letsencrypt Varnish plugin for authentication\n' % (achall.URI_ROOT_PATH, achall.chall.encode("token")) + return 'if (req.url == "/%s/%s") { return (synth(999, "Challenge")); } # Added by certbot Varnish plugin for authentication\n' % (achall.URI_ROOT_PATH, achall.chall.encode("token")) def vcl_synth_line(validation): - return 'if (resp.status == 999) { set resp.status = 200; set resp.http.Content-Type = "text/plain"; synthetic("%s"); return (deliver); } # Added by letsencrypt Varnish plugin for authentication\n' % (validation); + return 'if (resp.status == 999) { set resp.status = 200; set resp.http.Content-Type = "text/plain"; synthetic("%s"); return (deliver); } # Added by certbot Varnish plugin for authentication\n' % (validation); +@implementer(interfaces.IAuthenticator) +@provider(interfaces.IPluginFactory) class Authenticator(common.Plugin): - zope.interface.implements(interfaces.IAuthenticator) - zope.interface.classProvides(interfaces.IPluginFactory) hidden = True description = "Manual configuration, authentication via Varnish VCL" @@ -50,6 +50,10 @@ class Authenticator(common.Plugin): responses.append(self._perform_single(achall)) return responses + @classmethod + def add_parser_arguments(cls, add): + pass + def _perform_single(self, achall): # same path for each challenge response would be easier for # users, but will not work if multiple domains point at the @@ -65,7 +69,7 @@ class Authenticator(common.Plugin): found_vcl_synth = False new_content = [] for line in content: - if re.search("# Added by letsencrypt Varnish plugin", line): + if re.search("# Added by certbot Varnish plugin", line): # Don't include this line; left by a previous run. continue new_content.append(line) @@ -77,14 +81,14 @@ class Authenticator(common.Plugin): found_vcl_synth = True if not found_vcl_recv: - new_content.append("sub vcl_recv { # Added by letsencrypt Varnish plugin for authentication\n") + new_content.append("sub vcl_recv { # Added by certbot Varnish plugin for authentication\n") new_content.append(vcl_recv_line(achall)) - new_content.append("} # Added by letsencrypt Varnish plugin for authentication\n") + new_content.append("} # Added by certbot Varnish plugin for authentication\n") if not found_vcl_synth: - new_content.append("sub vcl_synth { # Added by letsencrypt Varnish plugin for authentication\n") + new_content.append("sub vcl_synth { # Added by certbot Varnish plugin for authentication\n") new_content.append(vcl_synth_line(validation)) - new_content.append("} # Added by letsencrypt Varnish plugin for authentication\n") + new_content.append("} # Added by certbot Varnish plugin for authentication\n") with open("/etc/varnish/default.vcl", "w") as vcl: vcl.writelines(new_content)