2014-05-08 16:59:35 +00:00
|
|
|
import pkgutil
|
2014-10-10 14:39:46 +00:00
|
|
|
import textwrap
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2014-10-24 12:12:20 +00:00
|
|
|
from .. import settings
|
|
|
|
|
2014-10-14 13:50:19 +00:00
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
class WebAppServiceMixin(object):
|
|
|
|
model = 'webapps.WebApp'
|
2014-10-24 12:12:20 +00:00
|
|
|
directive = None
|
|
|
|
|
|
|
|
def valid_directive(self, webapp):
|
|
|
|
return settings.WEBAPPS_TYPES[webapp.type]['directive'][0] == self.directive
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
def create_webapp_dir(self, context):
|
2015-03-04 21:06:16 +00:00
|
|
|
self.append("mkdir -p %(app_path)s" % context)
|
|
|
|
self.append("chown %(user)s:%(group)s %(app_path)s" % context)
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2014-10-14 13:50:19 +00:00
|
|
|
def get_php_init_vars(self, webapp, per_account=False):
|
|
|
|
"""
|
|
|
|
process php options for inclusion on php.ini
|
|
|
|
per_account=True merges all (account, webapp.type) options
|
|
|
|
"""
|
|
|
|
init_vars = []
|
|
|
|
options = webapp.options.all()
|
|
|
|
if per_account:
|
|
|
|
options = webapp.account.webapps.filter(webapp_type=webapp.type)
|
|
|
|
for opt in options:
|
|
|
|
name = opt.name.replace('PHP-', '')
|
|
|
|
value = "%s" % opt.value
|
|
|
|
init_vars.append((name, value))
|
|
|
|
enabled_functions = []
|
2014-11-11 16:59:13 +00:00
|
|
|
for value in options.filter(name='php-enabled_functions').values_list('value', flat=True):
|
2014-10-14 13:50:19 +00:00
|
|
|
enabled_functions += enabled_functions.get().value.split(',')
|
|
|
|
if enabled_functions:
|
|
|
|
disabled_functions = []
|
|
|
|
for function in settings.WEBAPPS_PHP_DISABLED_FUNCTIONS:
|
|
|
|
if function not in enabled_functions:
|
|
|
|
disabled_functions.append(function)
|
|
|
|
init_vars.append(('dissabled_functions', ','.join(disabled_functions)))
|
|
|
|
return init_vars
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
def delete_webapp_dir(self, context):
|
|
|
|
self.append("rm -fr %(app_path)s" % context)
|
|
|
|
|
|
|
|
def get_context(self, webapp):
|
|
|
|
return {
|
2014-10-23 15:38:46 +00:00
|
|
|
'user': webapp.get_username(),
|
|
|
|
'group': webapp.get_groupname(),
|
2015-03-04 21:06:16 +00:00
|
|
|
'app_name': webapp.name,
|
2014-05-08 16:59:35 +00:00
|
|
|
'type': webapp.type,
|
2014-10-10 14:39:46 +00:00
|
|
|
'app_path': webapp.get_path().rstrip('/'),
|
2014-05-08 16:59:35 +00:00
|
|
|
'banner': self.get_banner(),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for __, module_name, __ in pkgutil.walk_packages(__path__):
|
2014-10-14 13:50:19 +00:00
|
|
|
# sorry for the exec(), but Import module function fails :(
|
2014-05-08 16:59:35 +00:00
|
|
|
exec('from . import %s' % module_name)
|