def _find_apache_config(self): distro = express_utils.determine_platform() apache_command = "`which {0}` -V 2>/dev/null".format( APACHE_SERVICES.get(distro[0])) apache_config = os.popen(apache_command).read() if apache_config: server_config_check = "SERVER_CONFIG_FILE=" httpd_root_check = "HTTPD_ROOT=" server_config_file = apache_config[apache_config. index(server_config_check) + len(server_config_check):-1] server_config_file = server_config_file.replace('"', '') if server_config_file[0] != "/": # get the httpd root to find the server config file path LOGGER.info("Finding Apache configuration files...") httpd_root_dir = apache_config[apache_config. index(httpd_root_check) + len(httpd_root_check):-1] httpd_root_dir = httpd_root_dir[:httpd_root_dir.index("\n")] httpd_root_dir = httpd_root_dir.replace('"', '') if os.path.exists(httpd_root_dir) and os.path.isdir( httpd_root_dir): server_config_file = os.path.join(httpd_root_dir, server_config_file) if os.path.exists(server_config_file): return server_config_file
def verify_requirements(): LOGGER.info("Verifying minimum requirements are met. ") os_name, os_version, code_name = express_utils.determine_platform() python_version = express_utils.determine_python_version() apache_version = express_utils.determine_apache_version(os_name) errors = [] if apache_version: if os_name == 'Ubuntu': if StrictVersion(os_version) < StrictVersion('14.04'): errors.append( "Your version of Ubuntu (%s) is not supported. Ubuntu version 14.04 or higher is required." % os_version) if StrictVersion(python_version) < StrictVersion('2.7'): errors.append( "Your version of Python (%s) is not supported. Python version 2.7 or higher is required." % python_version) if StrictVersion(apache_version) < StrictVersion('2.4'): errors.append( "Your version of Apache (%s) is not supported. Apache version 2.4 or higher is required." % apache_version) elif os_name == 'CentOS': if StrictVersion(os_version) < StrictVersion('6.5'): errors.append( "Your version of CentOS (%s) is not supported. CentOS version 6.5 or higher is required." % os_version) if StrictVersion(python_version) < StrictVersion('2.6'): errors.append( "Your version of Python (%s) is not supported. Python version 2.6 or higher is required." % python_version) if StrictVersion(apache_version) < StrictVersion('2.2'): errors.append( "Your version of Apache (%s) is not supported. Apache version 2.2 or higher is required." % apache_version) else: errors.append( "%s %s is not a supported operating system. Ubuntu 14.04 and CentOS 6.5 are supported." % (os_name, os_version)) else: errors.append( "No Apache version detected, please verify that Apache is installed and running" ) if len(errors) > 0: if 'localhost' not in express_utils.HOST: error_msg = "ERROR: Your system does not meet the minimum requirements to run this program:" LOGGER.info(error_msg) LOGGER.info("\n".join(errors)) for error in errors: error_msg = "%s\n%s" % (error_msg, error) raise Exception(error_msg) else: LOGGER.info("Minimum requirements are met")
def _create_secure_vhost(self, vhost): LOGGER.info("Creating new virtual host %s on port 443" % vhost) secure_vhost = None host_file = "/files{0}".format(get_path_to_file(vhost)) # create a map of the insecure vhost's configuration vhost_map = list() self._create_map_from_vhost(vhost, vhost_map) if express_utils.determine_platform()[0] != "CentOS": # check if there is an IfModule for mod_ssl.c, if not create it if_module = None check_matches = self.aug.match( "{0}/*[label()=~regexp('{1}')]".format( host_file, create_regex("IfModule"))) if check_matches: for check in check_matches: if self.aug.get(check + "/arg") == "mod_ssl.c": if_module = check if not if_module: self.aug.set(host_file + "/IfModule[last()+1]/arg", "mod_ssl.c") if_modules = self.aug.match( host_file + "/*[self::IfModule/arg='mod_ssl.c']") if len(if_modules) > 0: if_module = if_modules[0] host_file = if_module else: raise ParserException( "An error occurred while creating IfModule mod_ssl.c for {0}." .format(self.domain), self.directives) # create a new secure vhost vhost_name = self.aug.get(vhost + "/arg") vhost_name = vhost_name[0:vhost_name.index(":")] + ":443" self.aug.set(host_file + "/VirtualHost[last()+1]/arg", vhost_name) vhosts = self.aug.match("{0}/*[self::VirtualHost/arg='{1}']".format( host_file, vhost_name)) for vhost in vhosts: secure_vhost = vhost # write the insecure vhost configuration into the new secure vhost self._create_vhost_from_map(secure_vhost, vhost_map) self.check_for_parsing_errors() return secure_vhost
def test_platform(self): self.assertEqual(len(express_utils.determine_platform()), 3) self.assertIn(express_utils.determine_platform()[0], express_utils.SUPPORTED_PLATFORMS)
def test_check_for_apache_process(self): distro = express_utils.determine_platform() self.assertTrue(express_utils.check_for_apache_process(distro[0]))
def test_determine_apache_version(self): distro = express_utils.determine_platform() apache_version = express_utils.determine_apache_version(distro[0]) self.assertIsNotNone(apache_version)
def check_for_deps(args): distro = express_utils.determine_platform() if distro[0] == 'CentOS': express_utils.check_for_deps_centos() else: express_utils.check_for_deps_ubuntu()