Rename template function

This commit is contained in:
VirtuBox
2019-09-23 16:35:20 +02:00
parent 907d1dc5f5
commit 782cb2e440
5 changed files with 42 additions and 39 deletions

View File

@@ -4,6 +4,7 @@
# in this file in the same way as WOBaseController. # in this file in the same way as WOBaseController.
from cement.core import handler from cement.core import handler
from wo.cli.controllers.base import WOBaseController from wo.cli.controllers.base import WOBaseController

View File

@@ -178,7 +178,7 @@ class WOSecureController(CementBaseController):
sudo_user = '' sudo_user = ''
data = dict(sshport=current_ssh_port, allowpass='no', data = dict(sshport=current_ssh_port, allowpass='no',
user=sudo_user) user=sudo_user)
WOTemplate.render(self, '/etc/ssh/sshd_config', WOTemplate.deploy(self, '/etc/ssh/sshd_config',
'sshd.mustache', data) 'sshd.mustache', data)
WOGit.add(self, ["/etc/ssh"], WOGit.add(self, ["/etc/ssh"],
msg="Adding changed SSH port into Git") msg="Adding changed SSH port into Git")

View File

@@ -159,22 +159,22 @@ def post_pref(self, apt_packages, packages, upgrade=False):
["/etc/nginx"], ["/etc/nginx"],
msg="Adding Nginx into Git") msg="Adding Nginx into Git")
data = dict(tls13=True) data = dict(tls13=True)
WOTemplate.render(self, WOTemplate.deploy(self,
'/etc/nginx/nginx.conf', '/etc/nginx/nginx.conf',
'nginx-core.mustache', data) 'nginx-core.mustache', data)
if not os.path.isfile('{0}/gzip.conf.disabled'.format(ngxcnf)): if not os.path.isfile('{0}/gzip.conf.disabled'.format(ngxcnf)):
data = dict() data = dict()
WOTemplate.render(self, '{0}/gzip.conf'.format(ngxcnf), WOTemplate.deploy(self, '{0}/gzip.conf'.format(ngxcnf),
'gzip.mustache', data) 'gzip.mustache', data)
if not os.path.isfile('{0}/brotli.conf'.format(ngxcnf)): if not os.path.isfile('{0}/brotli.conf'.format(ngxcnf)):
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/brotli.conf.disabled' '{0}/brotli.conf.disabled'
.format(ngxcnf), .format(ngxcnf),
'brotli.mustache', data) 'brotli.mustache', data)
WOTemplate.render(self, '{0}/tweaks.conf'.format(ngxcnf), WOTemplate.deploy(self, '{0}/tweaks.conf'.format(ngxcnf),
'tweaks.mustache', data) 'tweaks.mustache', data)
# Fix for white screen death with NGINX PLUS # Fix for white screen death with NGINX PLUS
@@ -187,26 +187,26 @@ def post_pref(self, apt_packages, packages, upgrade=False):
try: try:
data = dict(php="9000", debug="9001", data = dict(php="9000", debug="9001",
php7="9070", debug7="9170") php7="9070", debug7="9170")
WOTemplate.render( WOTemplate.deploy(
self, '{0}/upstream.conf'.format(ngxcnf), self, '{0}/upstream.conf'.format(ngxcnf),
'upstream.mustache', data, overwrite=True) 'upstream.mustache', data, overwrite=True)
data = dict(phpconf=True if data = dict(phpconf=True if
WOAptGet.is_installed(self, 'php7.2-fpm') WOAptGet.is_installed(self, 'php7.2-fpm')
else False) else False)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/stub_status.conf'.format(ngxcnf), '{0}/stub_status.conf'.format(ngxcnf),
'stub_status.mustache', data) 'stub_status.mustache', data)
data = dict() data = dict()
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/webp.conf'.format(ngxcnf), '{0}/webp.conf'.format(ngxcnf),
'webp.mustache', data, overwrite=False) 'webp.mustache', data, overwrite=False)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/cloudflare.conf'.format(ngxcnf), '{0}/cloudflare.conf'.format(ngxcnf),
'cloudflare.mustache', data) 'cloudflare.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/map-wp-fastcgi-cache.conf'.format( '{0}/map-wp-fastcgi-cache.conf'.format(
ngxcnf), ngxcnf),
'map-wp.mustache', data) 'map-wp.mustache', data)
@@ -223,83 +223,83 @@ def post_pref(self, apt_packages, packages, upgrade=False):
data = dict() data = dict()
# Common Configuration # Common Configuration
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/locations-wo.conf' '{0}/locations-wo.conf'
.format(ngxcom), .format(ngxcom),
'locations.mustache', data) 'locations.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpsubdir.conf' '{0}/wpsubdir.conf'
.format(ngxcom), .format(ngxcom),
'wpsubdir.mustache', data) 'wpsubdir.mustache', data)
data = dict(upstream="php72") data = dict(upstream="php72")
# PHP 7.2 conf # PHP 7.2 conf
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/php72.conf' '{0}/php72.conf'
.format(ngxcom), .format(ngxcom),
'php.mustache', data) 'php.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/redis-php72.conf' '{0}/redis-php72.conf'
.format(ngxcom), .format(ngxcom),
'redis.mustache', data) 'redis.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpcommon-php72.conf' '{0}/wpcommon-php72.conf'
.format(ngxcom), .format(ngxcom),
'wpcommon.mustache', data) 'wpcommon.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpfc-php72.conf' '{0}/wpfc-php72.conf'
.format(ngxcom), .format(ngxcom),
'wpfc.mustache', data) 'wpfc.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpsc-php72.conf' '{0}/wpsc-php72.conf'
.format(ngxcom), .format(ngxcom),
'wpsc.mustache', data) 'wpsc.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wprocket-php72.conf' '{0}/wprocket-php72.conf'
.format(ngxcom), .format(ngxcom),
'wprocket.mustache', data) 'wprocket.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpce-php72.conf' '{0}/wpce-php72.conf'
.format(ngxcom), .format(ngxcom),
'wpce.mustache', data) 'wpce.mustache', data)
# PHP 7.3 conf # PHP 7.3 conf
data = dict(upstream="php73") data = dict(upstream="php73")
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/php73.conf' '{0}/php73.conf'
.format(ngxcom), .format(ngxcom),
'php.mustache', data) 'php.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/redis-php73.conf' '{0}/redis-php73.conf'
.format(ngxcom), .format(ngxcom),
'redis.mustache', data) 'redis.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpcommon-php73.conf' '{0}/wpcommon-php73.conf'
.format(ngxcom), .format(ngxcom),
'wpcommon.mustache', data) 'wpcommon.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpfc-php73.conf' '{0}/wpfc-php73.conf'
.format(ngxcom), .format(ngxcom),
'wpfc.mustache', data) 'wpfc.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpsc-php73.conf' '{0}/wpsc-php73.conf'
.format(ngxcom), .format(ngxcom),
'wpsc.mustache', data) 'wpsc.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wprocket-php73.conf' '{0}/wprocket-php73.conf'
.format(ngxcom), .format(ngxcom),
'wprocket.mustache', data) 'wprocket.mustache', data)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/wpce-php73.conf' '{0}/wpce-php73.conf'
.format(ngxcom), .format(ngxcom),
'wpce.mustache', data) 'wpce.mustache', data)
@@ -315,15 +315,15 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# Following files should not be overwrited # Following files should not be overwrited
data = dict(webroot=ngxroot) data = dict(webroot=ngxroot)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/acl.conf' '{0}/acl.conf'
.format(ngxcom), .format(ngxcom),
'acl.mustache', data, overwrite=False) 'acl.mustache', data, overwrite=False)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/blockips.conf' '{0}/blockips.conf'
.format(ngxcnf), .format(ngxcnf),
'blockips.mustache', data, overwrite=False) 'blockips.mustache', data, overwrite=False)
WOTemplate.render(self, WOTemplate.deploy(self,
'{0}/fastcgi.conf' '{0}/fastcgi.conf'
.format(ngxcnf), .format(ngxcnf),
'fastcgi.mustache', data, overwrite=True) 'fastcgi.mustache', data, overwrite=True)
@@ -361,7 +361,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# 22222 port settings # 22222 port settings
data = dict(webroot=ngxroot) data = dict(webroot=ngxroot)
WOTemplate.render( WOTemplate.deploy(
self, self,
'/etc/nginx/sites-available/22222', '/etc/nginx/sites-available/22222',
'22222.mustache', data, overwrite=True) '22222.mustache', data, overwrite=True)
@@ -466,7 +466,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
if not os.path.isfile("/opt/cf-update.sh"): if not os.path.isfile("/opt/cf-update.sh"):
data = dict() data = dict()
WOTemplate.render(self, '/opt/cf-update.sh', WOTemplate.deploy(self, '/opt/cf-update.sh',
'cf-update.mustache', 'cf-update.mustache',
data, overwrite=False) data, overwrite=False)
WOFileUtils.chmod(self, "/opt/cf-update.sh", 0o775) WOFileUtils.chmod(self, "/opt/cf-update.sh", 0o775)
@@ -868,7 +868,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
inno_buffer=wo_ram_innodb, inno_buffer=wo_ram_innodb,
inno_log_buffer=wo_ram_log_buffer, inno_log_buffer=wo_ram_log_buffer,
innodb_instances=wo_innodb_instance) innodb_instances=wo_innodb_instance)
WOTemplate.render( WOTemplate.deploy(
self, '/etc/mysql/my.cnf', 'my.mustache', data) self, '/etc/mysql/my.cnf', 'my.mustache', data)
# replacing default values # replacing default values
Log.debug(self, "Tuning MySQL configuration") Log.debug(self, "Tuning MySQL configuration")
@@ -892,17 +892,17 @@ def post_pref(self, apt_packages, packages, upgrade=False):
if not os.path.isfile("/etc/fail2ban/jail.d/custom.conf"): if not os.path.isfile("/etc/fail2ban/jail.d/custom.conf"):
Log.info(self, "Configuring Fail2Ban") Log.info(self, "Configuring Fail2Ban")
data = dict() data = dict()
WOTemplate.render( WOTemplate.deploy(
self, self,
'/etc/fail2ban/jail.d/custom.conf', '/etc/fail2ban/jail.d/custom.conf',
'fail2ban.mustache', 'fail2ban.mustache',
data, overwrite=False) data, overwrite=False)
WOTemplate.render( WOTemplate.deploy(
self, self,
'/etc/fail2ban/filter.d/wo-wordpress.conf', '/etc/fail2ban/filter.d/wo-wordpress.conf',
'fail2ban-wp.mustache', 'fail2ban-wp.mustache',
data, overwrite=False) data, overwrite=False)
WOTemplate.render( WOTemplate.deploy(
self, self,
'/etc/fail2ban/filter.d/nginx-forbidden.conf', '/etc/fail2ban/filter.d/nginx-forbidden.conf',
'fail2ban-forbidden.mustache', 'fail2ban-forbidden.mustache',
@@ -984,7 +984,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# check if ufw script is already created # check if ufw script is already created
if not os.path.isfile("/opt/ufw.sh"): if not os.path.isfile("/opt/ufw.sh"):
data = dict() data = dict()
WOTemplate.render(self, '/opt/ufw.sh', WOTemplate.deploy(self, '/opt/ufw.sh',
'ufw.mustache', 'ufw.mustache',
data, overwrite=False) data, overwrite=False)
WOFileUtils.chmod(self, "/opt/ufw.sh", 0o700) WOFileUtils.chmod(self, "/opt/ufw.sh", 0o700)
@@ -1077,7 +1077,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
Log.debug(self, "Setting up freshclam cronjob") Log.debug(self, "Setting up freshclam cronjob")
if not os.path.isfile("/opt/freshclam.sh"): if not os.path.isfile("/opt/freshclam.sh"):
data = dict() data = dict()
WOTemplate.render(self, '/opt/freshclam.sh', WOTemplate.deploy(self, '/opt/freshclam.sh',
'freshclam.mustache', 'freshclam.mustache',
data, overwrite=False) data, overwrite=False)
WOFileUtils.chmod(self, "/opt/freshclam.sh", 0o775) WOFileUtils.chmod(self, "/opt/freshclam.sh", 0o775)

View File

@@ -1,7 +1,8 @@
"""WordOps generic database creation module""" """WordOps generic database creation module"""
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from wo.core.variables import WOVariables from wo.core.variables import WOVariables
# db_path = self.app.config.get('site', 'db_path') # db_path = self.app.config.get('site', 'db_path')

View File

@@ -9,7 +9,8 @@ Render Templates
class WOTemplate(): class WOTemplate():
def render(self, fileconf, template, data, overwrite=True): def deploy(self, fileconf, template, data, overwrite=True):
"""Deploy template with render()"""
data = dict(data) data = dict(data)
if (not os.path.isfile('{0}.custom' if (not os.path.isfile('{0}.custom'
.format(fileconf))): .format(fileconf))):