diff options
author | Brad Warren <bmw@eff.org> | 2016-10-01 01:12:58 +0300 |
---|---|---|
committer | Brad Warren <bmw@eff.org> | 2016-10-01 01:12:58 +0300 |
commit | a5ba79094b70c0cd7e2beedfc62c7b9804c3adfb (patch) | |
tree | ae92ec4447db2ea363268ba0ffc0b9fb165fd167 | |
parent | 67033a796758ee639c760324cc3038fd0a7b6592 (diff) |
Use relative augeas paths to determine if a file contains multiple virtual hostsbmw_multiple_vhosts
-rw-r--r-- | certbot-apache/certbot_apache/configurator.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/certbot-apache/certbot_apache/configurator.py b/certbot-apache/certbot_apache/configurator.py index 3e951aed7..8f1889743 100644 --- a/certbot-apache/certbot_apache/configurator.py +++ b/certbot-apache/certbot_apache/configurator.py @@ -567,8 +567,9 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): """ # Search base config, and all included paths for VirtualHosts + file_paths = {} + internal_paths = defaultdict(set) vhs = [] - vhost_paths = {} for vhost_path in self.parser.parser_paths.keys(): paths = self.aug.match( ("/files%s//*[label()=~regexp('%s')]" % @@ -579,20 +580,32 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): new_vhost = self._create_vhost(path) if not new_vhost: continue + internal_path = get_internal_aug_path(new_vhost.path) realpath = os.path.realpath(new_vhost.filep) - if realpath not in vhost_paths.keys(): + if realpath not in file_paths: + file_paths[realpath] = new_vhost.filep + internal_paths[realpath].add(internal_path) vhs.append(new_vhost) - vhost_paths[realpath] = new_vhost.filep elif (realpath == new_vhost.filep and - realpath != vhost_paths[realpath]): + realpath != file_paths[realpath]): # Prefer "real" vhost paths instead of symlinked ones # ex: sites-enabled/vh.conf -> sites-available/vh.conf # remove old (most likely) symlinked one - vhs = [v for v in vhs if v.filep != vhost_paths[realpath]] + new_vhs = [] + for v in vhs: + if v.filep == file_paths[realpath]: + internal_paths[realpath].remove( + get_internal_aug_path(v.path)) + else: + new_vhs.append(v) + vhs = new_vhs + + file_paths[realpath] = realpath + internal_paths[realpath].add(internal_path) vhs.append(new_vhost) - vhost_paths[realpath] = realpath - elif new_vhost.path.endswith("]") and new_vhost not in vhs: + elif internal_path not in internal_paths[realpath]: + internal_paths[realpath].add(internal_path) vhs.append(new_vhost) return vhs |