diff --git a/wo/cli/plugins/info.py b/wo/cli/plugins/info.py index 85fb5b8..705e9f3 100644 --- a/wo/cli/plugins/info.py +++ b/wo/cli/plugins/info.py @@ -9,6 +9,7 @@ from pynginxconfig import NginxConfig from wo.core.aptget import WOAptGet from wo.core.logging import Log from wo.core.shellexec import WOShellExec +from wo.core.variables import WOVar def wo_info_hook(app): @@ -27,28 +28,17 @@ class WOInfoController(CementBaseController): dict(help='Get MySQL configuration information', action='store_true')), (['--php'], - dict(help='Get PHP 7.2 configuration information', - action='store_true')), - (['--php73'], - dict(help='Get PHP 7.3 configuration information', - action='store_true')), - (['--php74'], - dict(help='Get PHP 7.4 configuration information', - action='store_true')), - (['--php80'], - dict(help='Get PHP 8.0 configuration information', - action='store_true')), - (['--php81'], - dict(help='Get PHP 8.1 configuration information', - action='store_true')), - (['--php82'], - dict(help='Get PHP 8.2 configuration information', + dict(help='Get PHP configuration information', action='store_true')), (['--nginx'], dict(help='Get Nginx configuration information', action='store_true')), ] usage = "wo info [options]" + for php_version, php_number in WOVar.wo_php_versions.items(): + arguments.append(([f'--{php_version}'], + dict(help=f'Get PHP {php_number} configuration information', + action='store_true'))) @expose(hide=True) def info_nginx(self): diff --git a/wo/cli/plugins/site_create.py b/wo/cli/plugins/site_create.py index 4be9bd2..c4a5344 100644 --- a/wo/cli/plugins/site_create.py +++ b/wo/cli/plugins/site_create.py @@ -32,19 +32,7 @@ class WOSiteCreateController(CementBaseController): (['--html'], dict(help="create html site", action='store_true')), (['--php'], - dict(help="create php 7.2 site", action='store_true')), - (['--php72'], - dict(help="create php 7.2 site", action='store_true')), - (['--php73'], - dict(help="create php 7.3 site", action='store_true')), - (['--php74'], - dict(help="create php 7.4 site", action='store_true')), - (['--php80'], - dict(help="create php 8.0 site", action='store_true')), - (['--php81'], - dict(help="create php 8.1 site", action='store_true')), - (['--php82'], - dict(help="create php 8.2 site", action='store_true')), + dict(help="create php site", action='store_true')), (['--mysql'], dict(help="create mysql site", action='store_true')), (['--wp'], @@ -73,6 +61,9 @@ class WOSiteCreateController(CementBaseController): dict(help="create WordPress single/multi site " "with redis cache", action='store_true')), + (['--alias'], + dict(help="domain name to redirect to", + action='store', nargs='?')), (['-le', '--letsencrypt'], dict(help="configure letsencrypt ssl for the site", action='store' or 'store_const', @@ -107,6 +98,10 @@ class WOSiteCreateController(CementBaseController): "without installing WordPress", action='store_true')), ] + for php_version, php_number in WOVar.wo_php_versions.items(): + arguments.append(([f'--{php_version}'], + dict(help=f'Create PHP {php_number} site', + action='store_true'))) @expose(hide=True) def default(self): @@ -129,10 +124,17 @@ class WOSiteCreateController(CementBaseController): proxyinfo = proxyinfo.split(':') host = proxyinfo[0].strip() port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip() - elif stype is None and not pargs.proxy: + elif stype is None and not pargs.proxy and not pargs.alias: stype, cache = 'html', 'basic' + elif stype is None and pargs.alias: + stype, cache = 'alias', '' + alias_name = pargs.alias.strip() + if not alias_name: + Log.error(self, "Please provide alias name") elif stype and pargs.proxy: Log.error(self, "proxy should not be used with other site types") + elif stype and pargs.alias: + Log.error(self, "alias should not be used with other site types") if not pargs.site_name: try: @@ -173,6 +175,16 @@ class WOSiteCreateController(CementBaseController): data['port'] = port data['basic'] = True + if stype == 'alias': + data = dict( + site_name=wo_domain, www_domain=wo_www_domain, + static=True, basic=False, wp=False, + wpfc=False, wpsc=False, wprocket=False, wpce=False, + multisite=False, wpsubdir=False, webroot=wo_site_webroot) + data['alias'] = True + data['alias_name'] = alias_name + data['basic'] = True + if (pargs.php72 or pargs.php73 or pargs.php74 or pargs.php80 or pargs.php81 or pargs.php82): data = dict( @@ -218,57 +230,27 @@ class WOSiteCreateController(CementBaseController): else: pass - data['php73'] = False - data['php74'] = False - data['php72'] = False - data['php80'] = False - data['php81'] = False - data['php82'] = False - - if data and pargs.php73: - data['php73'] = True - data['wo_php'] = 'php73' - elif data and pargs.php74: - data['php74'] = True - data['wo_php'] = 'php74' - elif data and pargs.php72: - data['php72'] = True - data['wo_php'] = 'php72' - elif data and pargs.php80: - data['php80'] = True - data['wo_php'] = 'php80' - elif data and pargs.php81: - data['php81'] = True - data['wo_php'] = 'php81' - elif data and pargs.php82: - data['php82'] = True - data['wo_php'] = 'php82' + # Initialize all PHP versions to False + for version in WOVar.wo_php_versions: + data[version] = False + # Check for PHP versions in pargs + for pargs_version, version in WOVar.wo_php_versions.items(): + if data and getattr(pargs, pargs_version, False): + data[pargs_version] = True + data['wo_php'] = pargs_version + php_version = version + break else: if self.app.config.has_section('php'): - config_php_ver = self.app.config.get( - 'php', 'version') - if config_php_ver == '7.2': - data['php72'] = True - data['wo_php'] = 'php72' - elif config_php_ver == '7.3': - data['php73'] = True - data['wo_php'] = 'php73' - elif config_php_ver == '7.4': - data['php74'] = True - data['wo_php'] = 'php74' - elif config_php_ver == '8.0': - data['php80'] = True - data['wo_php'] = 'php80' - elif config_php_ver == '8.1': - data['php81'] = True - data['wo_php'] = 'php81' - elif config_php_ver == '8.2': - data['php82'] = True - data['wo_php'] = 'php82' - else: - data['php73'] = True - data['wo_php'] = 'php73' + config_php_ver = self.app.config.get('php', 'version') + + for wo_key, php_ver in WOVar.wo_php_versions.items(): + if php_ver == config_php_ver: + data[wo_key] = True + data['wo_php'] = wo_key + php_version = php_ver + break if ((not pargs.wpfc) and (not pargs.wpsc) and (not pargs.wprocket) and @@ -331,18 +313,26 @@ class WOSiteCreateController(CementBaseController): " http://{0}".format(wo_domain)) return - if data['php72']: - php_version = "7.2" - elif data['php74']: - php_version = "7.4" - elif data['php80']: - php_version = "8.0" - elif data['php81']: - php_version = "8.1" - elif data['php82']: - php_version = "8.2" - else: - php_version = "7.3" + if 'alias' in data.keys() and data['alias']: + addNewSite(self, wo_domain, stype, cache, wo_site_webroot) + # Service Nginx Reload + if not WOService.reload_service(self, 'nginx'): + Log.info(self, Log.FAIL + + "There was a serious error encountered...") + Log.info(self, Log.FAIL + "Cleaning up afterwards...") + doCleanupAction(self, domain=wo_domain) + deleteSiteInfo(self, wo_domain) + Log.error(self, "service nginx reload failed. " + "check issues with `nginx -t` command") + Log.error(self, "Check the log for details: " + "`tail /var/log/wo/wordops.log` " + "and please try again") + if wo_auth and len(wo_auth): + for msg in wo_auth: + Log.info(self, Log.ENDC + msg, log=False) + Log.info(self, "Successfully created site" + " http://{0}".format(wo_domain)) + return addNewSite(self, wo_domain, stype, cache, wo_site_webroot, php_version=php_version) diff --git a/wo/cli/plugins/site_update.py b/wo/cli/plugins/site_update.py index 9c29896..052d16f 100644 --- a/wo/cli/plugins/site_update.py +++ b/wo/cli/plugins/site_update.py @@ -41,18 +41,6 @@ class WOSiteUpdateController(CementBaseController): dict(help="update to html site", action='store_true')), (['--php'], dict(help="update to php site", action='store_true')), - (['--php72'], - dict(help="update to php72 site", action='store_true')), - (['--php73'], - dict(help="update to php73 site", action='store_true')), - (['--php74'], - dict(help="update to php74 site", action='store_true')), - (['--php80'], - dict(help="update to php80 site", action='store_true')), - (['--php81'], - dict(help="update to php81 site", action='store_true')), - (['--php82'], - dict(help="update to php82 site", action='store_true')), (['--mysql'], dict(help="update to mysql site", action='store_true')), (['--wp'], @@ -104,6 +92,10 @@ class WOSiteUpdateController(CementBaseController): (['--all'], dict(help="update all sites", action='store_true')), ] + for php_version, php_number in WOVar.wo_php_versions.items(): + arguments.append(([f'--{php_version}'], + dict(help=f'Update site to PHP {php_number}', + action='store_true'))) @expose(help="Update site type or cache") def default(self): diff --git a/wo/cli/plugins/sitedb.py b/wo/cli/plugins/sitedb.py index 2ed7aa2..4814f0d 100644 --- a/wo/cli/plugins/sitedb.py +++ b/wo/cli/plugins/sitedb.py @@ -11,7 +11,7 @@ from wo.core.logging import Log def addNewSite(self, site, stype, cache, path, enabled=True, ssl=False, fs='ext4', db='mysql', db_name=None, db_user=None, db_password=None, - db_host='localhost', hhvm=0, php_version='7.2'): + db_host='localhost', hhvm=0, php_version='8.1'): """ Add New Site record information into the wo database. """ diff --git a/wo/cli/plugins/stack.py b/wo/cli/plugins/stack.py index 15ba2f2..df10676 100644 --- a/wo/cli/plugins/stack.py +++ b/wo/cli/plugins/stack.py @@ -41,18 +41,6 @@ class WOStackController(CementBaseController): dict(help='Install Nginx stack', action='store_true')), (['--php'], dict(help='Install PHP 7.2 stack', action='store_true')), - (['--php72'], - dict(help='Install PHP 7.2 stack', action='store_true')), - (['--php73'], - dict(help='Install PHP 7.3 stack', action='store_true')), - (['--php74'], - dict(help='Install PHP 7.4 stack', action='store_true')), - (['--php80'], - dict(help='Install PHP 8.0 stack', action='store_true')), - (['--php81'], - dict(help='Install PHP 8.1 stack', action='store_true')), - (['--php82'], - dict(help='Install PHP 8.2 stack', action='store_true')), (['--mysql'], dict(help='Install MySQL stack', action='store_true')), (['--mariadb'], @@ -106,6 +94,11 @@ class WOStackController(CementBaseController): dict(help='Force install/remove/purge without prompt', action='store_true')), ] + for php_version, php_number in WOVar.wo_php_versions.items(): + arguments.append(([f'--{php_version}'], + dict(help=f'Install PHP {php_number} stack', + action='store_true'))) + usage = "wo stack (command) [options]" @expose(hide=True) diff --git a/wo/cli/plugins/stack_upgrade.py b/wo/cli/plugins/stack_upgrade.py index a859d78..964f4c9 100644 --- a/wo/cli/plugins/stack_upgrade.py +++ b/wo/cli/plugins/stack_upgrade.py @@ -33,18 +33,6 @@ class WOStackUpgradeController(CementBaseController): dict(help='Upgrade Nginx stack', action='store_true')), (['--php'], dict(help='Upgrade PHP 7.2 stack', action='store_true')), - (['--php72'], - dict(help='Upgrade PHP 7.2 stack', action='store_true')), - (['--php73'], - dict(help='Upgrade PHP 7.3 stack', action='store_true')), - (['--php74'], - dict(help='Upgrade PHP 7.4 stack', action='store_true')), - (['--php80'], - dict(help='Upgrade PHP 8.0 stack', action='store_true')), - (['--php81'], - dict(help='Upgrade PHP 8.1 stack', action='store_true')), - (['--php82'], - dict(help='Upgrade PHP 8.2 stack', action='store_true')), (['--mysql'], dict(help='Upgrade MySQL stack', action='store_true')), (['--mariadb'], @@ -77,6 +65,10 @@ class WOStackUpgradeController(CementBaseController): dict(help="Force Packages upgrade without any prompt", action='store_true')), ] + for php_version, php_number in WOVar.wo_php_versions.items(): + arguments.append(([f'--{php_version}'], + dict(help=f'Upgrade PHP {php_number} stack', + action='store_true'))) @expose(hide=True) def default(self, disp_msg=False): @@ -102,7 +94,11 @@ class WOStackUpgradeController(CementBaseController): pargs.mysql = True if pargs.php: - pargs.php81 = True + if self.app.config.has_section('php'): + config_php_ver = self.app.config.get( + 'php', 'version') + current_php = config_php_ver.replace(".", "") + setattr(self.app.pargs, 'php{0}'.format(current_php), True) if pargs.all: pargs.web = True @@ -145,41 +141,23 @@ class WOStackUpgradeController(CementBaseController): else: Log.info(self, "Nginx Stable is not already installed") - # php 7.2 - if pargs.php72: - if WOAptGet.is_installed(self, 'php7.2-fpm'): - apt_packages = apt_packages + WOVar.wo_php72 + \ - WOVar.wo_php_extra + wo_vars = { + 'php72': WOVar.wo_php72, + 'php73': WOVar.wo_php73, + 'php74': WOVar.wo_php74, + 'php80': WOVar.wo_php80, + 'php81': WOVar.wo_php81, + 'php82': WOVar.wo_php82, + } - # php 7.3 - if pargs.php73: - if WOAptGet.is_installed(self, 'php7.3-fpm'): - apt_packages = apt_packages + WOVar.wo_php73 + \ - WOVar.wo_php_extra - - # php 7.4 - if pargs.php74: - if WOAptGet.is_installed(self, 'php7.4-fpm'): - apt_packages = apt_packages + WOVar.wo_php74 + \ - WOVar.wo_php_extra - - # php 8.0 - if pargs.php80: - if WOAptGet.is_installed(self, 'php8.0-fpm'): - apt_packages = apt_packages + WOVar.wo_php80 + \ - WOVar.wo_php_extra - - # php 8.1 - if pargs.php81: - if WOAptGet.is_installed(self, 'php8.1-fpm'): - apt_packages = apt_packages + WOVar.wo_php81 + \ - WOVar.wo_php_extra - - # php 8.2 - if pargs.php82: - if WOAptGet.is_installed(self, 'php8.2-fpm'): - apt_packages = apt_packages + WOVar.wo_php82 + \ - WOVar.wo_php_extra + for parg_version, version in WOVar.wo_php_versions.items(): + if getattr(pargs, parg_version, False): + Log.debug(self, f"Setting apt_packages variable for PHP {version}") + if WOAptGet.is_installed(self, f'php{version}-fpm'): + apt_packages = apt_packages + wo_vars[parg_version] + WOVar.wo_php_extra + else: + Log.debug(self, f"PHP {version} not installed") + Log.info(self, f"PHP {version} not installed") # mysql if pargs.mysql: diff --git a/wo/cli/templates/virtualconf.mustache b/wo/cli/templates/virtualconf.mustache index 396606f..de65b9d 100644 --- a/wo/cli/templates/virtualconf.mustache +++ b/wo/cli/templates/virtualconf.mustache @@ -16,6 +16,11 @@ server { access_log /var/log/nginx/{{site_name}}.access.log {{^wpredis}}{{^static}}rt_cache{{/static}}{{/wpredis}}{{#wpredis}}rt_cache_redis{{/wpredis}}; error_log /var/log/nginx/{{site_name}}.error.log; + {{#alias}} + location / { + return 301 https://{{alias_name}}$request_uri; + } + {{/alias}} {{#proxy}} add_header X-Proxy-Cache $upstream_cache_status; location / { @@ -23,7 +28,7 @@ server { proxy_redirect off; include proxy_params; } - + {{#alias}} # Security settings for better privacy # Deny hidden files location ~ /\.(?!well-known\/) { @@ -35,9 +40,11 @@ server { allow all; auth_basic off; } + {{/alias}} {{/proxy}} {{^proxy}} + {{^alias}} root {{webroot}}/htdocs; index {{^static}}index.php{{/static}} index.html index.htm; @@ -51,7 +58,7 @@ server { {{^static}}include {{#basic}}common/{{wo_php}}.conf;{{/basic}}{{#wpfc}}common/wpfc-{{wo_php}}.conf;{{/wpfc}}{{#wpsc}}common/wpsc-{{wo_php}}.conf;{{/wpsc}}{{#wpredis}}common/redis-{{wo_php}}.conf;{{/wpredis}}{{#wprocket}}common/wprocket-{{wo_php}}.conf;{{/wprocket}}{{#wpce}}common/wpce-{{wo_php}}.conf;{{/wpce}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}{{/static}} {{#wp}}include common/wpcommon-{{wo_php}}.conf;{{/wp}} - include common/locations-wo.conf;{{/proxy}} + include common/locations-wo.conf;{{/alias}}{{/proxy}} include {{webroot}}/conf/nginx/*.conf; }