From a234cdf90ee0009ff4aae5616c5503e259a9ee57 Mon Sep 17 00:00:00 2001 From: James Kasten Date: Wed, 3 Dec 2014 04:47:41 -0800 Subject: [PATCH 1/2] Safety check: if Apache releases version without a decimal --- letsencrypt/client/apache_configurator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/letsencrypt/client/apache_configurator.py b/letsencrypt/client/apache_configurator.py index f297e1cf9..485a64ba1 100644 --- a/letsencrypt/client/apache_configurator.py +++ b/letsencrypt/client/apache_configurator.py @@ -1299,7 +1299,10 @@ LogLevel warn \n\ num_decimal = matches[0].count(".") # Format return value such as 2.47 rather than 2.4.7 - return float("".join(matches[0].rsplit(".", num_decimal-1))) + if num_decimal > 0: + return float("".join(matches[0].rsplit(".", num_decimal-1))) + + return float(matches[0]) ########################################################################### # Challenges Section From 231f3d5c61bf25e2250fc949eb6fe1ddd293b7fd Mon Sep 17 00:00:00 2001 From: James Kasten Date: Wed, 3 Dec 2014 16:45:06 -0800 Subject: [PATCH 2/2] Remove code without unittests from master (code remains in separate testing branch) --- letsencrypt/client/apache_configurator.py | 49 +---------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/letsencrypt/client/apache_configurator.py b/letsencrypt/client/apache_configurator.py index 485a64ba1..ec35199c1 100644 --- a/letsencrypt/client/apache_configurator.py +++ b/letsencrypt/client/apache_configurator.py @@ -88,13 +88,6 @@ class VH(object): "enabled: %s" % (self.file, self.path, self.addrs, self.names, self.ssl, self.enabled)) - def __eq__(self, other): - if isinstance(other, self.__class__): - return (self.file == other.file and self.path == other.path and - set(self.addrs) == set(other.addrs) and - set(self.names) == set(other.naems) and - self.ssl == other.ssl and self.enabled == other.enabled) - class ApacheConfigurator(augeas_configurator.AugeasConfigurator): """Apache configurator. @@ -133,7 +126,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): :ivar dict assoc: Mapping between domains and vhosts """ - def __init__(self, server_root=CONFIG.SERVER_ROOT, version=None): + def __init__(self, server_root=CONFIG.SERVER_ROOT): """Initialize an Apache Configurator.""" super(ApacheConfigurator, self).__init__() @@ -145,12 +138,6 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): # vhosts self.recovery_routine() - # Set Version - if not version: - self.version = self.get_version() - else: - self.version = version - # Check for errors in parsing files with Augeas self.check_parsing_errors("httpd.aug") # This problem has been fixed in Augeas 1.0 @@ -1270,40 +1257,6 @@ LogLevel warn \n\ return True - def get_version(self): # pylint: disable=no-self-use - """Return version of Apache Server. - - Version is returned as float. (ie. 2.4.7 = 2.47) - - :returns: version - :rtype: float - - """ - try: - proc = subprocess.Popen( - ['sudo', '/usr/sbin/apache2ctl', '-v'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - text = proc.communicate()[0] - except (OSError, ValueError): - raise errors.LetsEncryptConfiguratorError( - "Unable to run /usr/sbin/apache2ctl -v") - - regex = re.compile(r"Apache/([0-9\.]*)", re.IGNORECASE) - matches = regex.findall(text) - - if len(matches) != 1: - raise errors.LetsEncryptConfiguratorError( - "Unable to find Apache version") - - num_decimal = matches[0].count(".") - - # Format return value such as 2.47 rather than 2.4.7 - if num_decimal > 0: - return float("".join(matches[0].rsplit(".", num_decimal-1))) - - return float(matches[0]) - ########################################################################### # Challenges Section ###########################################################################