django-orchestra-test/orchestra/contrib/webapps/options.py

384 lines
12 KiB
Python
Raw Normal View History

2016-05-26 08:15:34 +00:00
import os
import re
from functools import lru_cache
2015-03-04 21:06:16 +00:00
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
2015-03-04 21:06:16 +00:00
2016-02-09 12:17:42 +00:00
from orchestra import plugins
2015-03-04 21:06:16 +00:00
from orchestra.utils.python import import_class
from . import settings
2016-02-09 12:17:42 +00:00
class AppOption(plugins.Plugin, metaclass=plugins.PluginMount):
PHP = 'PHP'
PROCESS = 'Process'
FILESYSTEM = 'FileSystem'
2015-03-04 21:06:16 +00:00
help_text = ""
group = None
2015-06-22 22:38:39 +00:00
comma_separated = False
@classmethod
@lru_cache()
2016-02-09 12:17:42 +00:00
def get_plugins(cls, all=False):
if all:
plugins = super().get_plugins()
else:
plugins = []
for cls in settings.WEBAPPS_ENABLED_OPTIONS:
plugins.append(import_class(cls))
return plugins
@classmethod
@lru_cache()
def get_option_groups(cls):
groups = {}
for opt in cls.get_plugins():
try:
groups[opt.group].append(opt)
except KeyError:
groups[opt.group] = [opt]
return groups
def validate(self):
if self.regex and not re.match(self.regex, self.instance.value):
2015-03-04 21:06:16 +00:00
raise ValidationError({
'value': ValidationError(_("'%(value)s' does not match %(regex)s."),
params={
'value': self.instance.value,
2015-03-04 21:06:16 +00:00
'regex': self.regex
}),
})
2015-03-25 17:04:44 +00:00
class PHPAppOption(AppOption):
deprecated = None
group = AppOption.PHP
2016-02-09 12:17:42 +00:00
abstract = True
2015-03-25 17:04:44 +00:00
def validate(self):
2016-05-26 08:15:34 +00:00
super().validate()
2015-03-25 17:04:44 +00:00
if self.deprecated:
2015-04-07 15:14:49 +00:00
php_version = self.instance.webapp.type_instance.get_php_version_number()
2015-04-10 15:03:38 +00:00
if php_version and self.deprecated and float(php_version) > self.deprecated:
2015-03-25 17:04:44 +00:00
raise ValidationError(
2015-10-05 13:31:08 +00:00
_("This option is deprecated since PHP version %s.") % self.deprecated
2015-03-25 17:04:44 +00:00
)
class PublicRoot(AppOption):
name = 'public-root'
verbose_name = _("Public root")
help_text = _("Document root relative to webapps/<webapp>/")
regex = r'[^ ]+'
group = AppOption.FILESYSTEM
2016-05-26 08:15:34 +00:00
def validate(self):
super().validate()
base_path = self.instance.webapp.get_base_path()
path = os.path.join(base_path, self.instance.value)
if not os.path.abspath(path).startswith(base_path):
raise ValidationError(
_("Public root path '%s' outside of webapp base path '%s'") % (path, base_path)
)
class Timeout(AppOption):
name = 'timeout'
2015-03-04 21:06:16 +00:00
# FCGID FcgidIOTimeout
# FPM pm.request_terminate_timeout
# PHP max_execution_time ini
verbose_name = _("Process timeout")
2015-04-10 15:03:38 +00:00
help_text = _("Maximum time in seconds allowed for a request to complete (a number between 0 and 999).<br>"
"Also sets <tt>max_request_time</tt> when php-cgi is used.")
regex = r'^[0-9]{1,3}$'
group = AppOption.PROCESS
2015-03-04 21:06:16 +00:00
class Processes(AppOption):
name = 'processes'
2015-03-04 21:06:16 +00:00
# FCGID MaxProcesses
# FPM pm.max_children
verbose_name = _("Number of processes")
help_text = _("Maximum number of children that can be alive at the same time (a number between 0 and 99).")
regex = r'^[0-9]{1,3}$'
group = AppOption.PROCESS
class PHPEnableFunctions(PHPAppOption):
name = 'enable_functions'
verbose_name = _("Enable functions")
2015-05-22 13:15:06 +00:00
help_text = '<tt>%s</tt>' % ',<br>'.join([
','.join(settings.WEBAPPS_PHP_DISABLED_FUNCTIONS[i:i+10])
for i in range(0, len(settings.WEBAPPS_PHP_DISABLED_FUNCTIONS), 10)
])
regex = r'^[\w\.,-]+$'
2015-06-22 22:38:39 +00:00
comma_separated = True
2015-09-23 12:22:32 +00:00
def validate(self):
# Clean value removing spaces
self.instance.value = self.instance.value.replace(' ', '')
2015-12-02 18:53:20 +00:00
super().validate()
class PHPDisableFunctions(PHPAppOption):
name = 'disable_functions'
verbose_name = _("Disable functions")
help_text = _("This directive allows you to disable certain functions for security reasons. "
"It takes on a comma-delimited list of function names. disable_functions is not "
"affected by Safe Mode. Default disabled fuctions include:<br>"
"<tt>%s</tt>") % ',<br>'.join([
','.join(settings.WEBAPPS_PHP_DISABLED_FUNCTIONS[i:i+10])
for i in range(0, len(settings.WEBAPPS_PHP_DISABLED_FUNCTIONS), 10)
])
regex = r'^[\w\.,-]+$'
comma_separated = True
def validate(self):
# Clean value removing spaces
self.instance.value = self.instance.value.replace(' ', '')
super().validate()
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPAllowURLInclude(PHPAppOption):
name = 'allow_url_include'
verbose_name = _("Allow URL include")
help_text = _("Allows the use of URL-aware fopen wrappers with include, include_once, require, "
2015-12-02 18:53:20 +00:00
"require_once (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPAllowURLFopen(PHPAppOption):
name = 'allow_url_fopen'
verbose_name = _("Allow URL fopen")
help_text = _("Enables the URL-aware fopen wrappers that enable accessing URL object like files (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPAutoAppendFile(PHPAppOption):
name = 'auto_append_file'
verbose_name = _("Auto append file")
help_text = _("Specifies the name of a file that is automatically parsed after the main file.")
regex = r'^[\w\.,-/]+$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPAutoPrependFile(PHPAppOption):
name = 'auto_prepend_file'
verbose_name = _("Auto prepend file")
help_text = _("Specifies the name of a file that is automatically parsed before the main file.")
regex = r'^[\w\.,-/]+$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPDateTimeZone(PHPAppOption):
name = 'date.timezone'
verbose_name = _("date.timezone")
help_text = _("Sets the default timezone used by all date/time functions (Timezone string 'Europe/London').")
regex = r'^\w+/\w+$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPDefaultSocketTimeout(PHPAppOption):
name = 'default_socket_timeout'
verbose_name = _("Default socket timeout")
help_text = _("Number between 0 and 999.")
regex = r'^[0-9]{1,3}$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPDisplayErrors(PHPAppOption):
name = 'display_errors'
verbose_name = _("Display errors")
help_text = _("Determines whether errors should be printed to the screen as part of the output or "
2015-04-10 15:03:38 +00:00
"if they should be hidden from the user (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPExtension(PHPAppOption):
name = 'extension'
verbose_name = _("Extension")
regex = r'^[^ ]+$'
2015-03-04 21:06:16 +00:00
class PHPIncludePath(PHPAppOption):
name = 'include_path'
verbose_name = _("Include path")
regex = r'^[^ ]+$'
class PHPOpenBasedir(PHPAppOption):
name = 'open_basedir'
verbose_name = _("Open basedir")
regex = r'^[^ ]+$'
2015-03-25 17:04:44 +00:00
class PHPMagicQuotesGPC(PHPAppOption):
name = 'magic_quotes_gpc'
verbose_name = _("Magic quotes GPC")
help_text = _("Sets the magic_quotes state for GPC (Get/Post/Cookie) operations (On or Off) "
2015-04-10 15:03:38 +00:00
"<b>DEPRECATED as of PHP 5.3.0</b>.")
regex = r'^(On|Off|on|off)$'
2015-03-25 17:04:44 +00:00
deprecated = 5.3
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPMagicQuotesRuntime(PHPAppOption):
name = 'magic_quotes_runtime'
verbose_name = _("Magic quotes runtime")
help_text = _("Functions that return data from any sort of external source will have quotes escaped "
2015-04-10 15:03:38 +00:00
"with a backslash (On or Off) <b>DEPRECATED as of PHP 5.3.0</b>.")
regex = r'^(On|Off|on|off)$'
2015-03-25 17:04:44 +00:00
deprecated = 5.3
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPMaginQuotesSybase(PHPAppOption):
name = 'magic_quotes_sybase'
verbose_name = _("Magic quotes sybase")
help_text = _("Single-quote is escaped with a single-quote instead of a backslash (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPMaxInputTime(PHPAppOption):
name = 'max_input_time'
verbose_name = _("Max input time")
help_text = _("Maximum time in seconds a script is allowed to parse input data, like POST and GET "
"(Integer between 0 and 999).")
regex = r'^[0-9]{1,3}$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPMaxInputVars(PHPAppOption):
name = 'max_input_vars'
verbose_name = _("Max input vars")
help_text = _("How many input variables may be accepted (limit is applied to $_GET, $_POST "
"and $_COOKIE superglobal separately) (Integer between 0 and 9999).")
regex = r'^[0-9]{1,4}$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPMemoryLimit(PHPAppOption):
name = 'memory_limit'
verbose_name = _("Memory limit")
help_text = _("This sets the maximum amount of memory in bytes that a script is allowed to allocate "
2015-04-10 15:03:38 +00:00
"(Value between 0M and 999M).")
regex = r'^[0-9]{1,3}M$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPMySQLConnectTimeout(PHPAppOption):
name = 'mysql.connect_timeout'
verbose_name = _("Mysql connect timeout")
help_text = _("Number between 0 and 999.")
regex = r'^([0-9]){1,3}$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPOutputBuffering(PHPAppOption):
name = 'output_buffering'
verbose_name = _("Output buffering")
help_text = _("Turn on output buffering (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPRegisterGlobals(PHPAppOption):
name = 'register_globals'
verbose_name = _("Register globals")
help_text = _("Whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) "
2015-04-10 15:03:38 +00:00
"variables as global variables (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPPostMaxSize(PHPAppOption):
name = 'post_max_size'
verbose_name = _("Post max size")
help_text = _("Sets max size of post data allowed (Value between 0M and 999M).")
regex = r'^[0-9]{1,3}M$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPSendmailPath(PHPAppOption):
name = 'sendmail_path'
2015-04-10 15:03:38 +00:00
verbose_name = _("Sendmail path")
help_text = _("Where the sendmail program can be found.")
regex = r'^[^ ]+$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPSessionBugCompatWarn(PHPAppOption):
name = 'session.bug_compat_warn'
2015-04-10 15:03:38 +00:00
verbose_name = _("Session bug compat warning")
help_text = _("Enables an PHP bug on session initialization for legacy behaviour (On or Off).")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
2015-03-25 17:04:44 +00:00
class PHPSessionAutoStart(PHPAppOption):
name = 'session.auto_start'
2015-04-10 15:03:38 +00:00
verbose_name = _("Session auto start")
help_text = _("Specifies whether the session module starts a session automatically on request "
"startup (On or Off).")
regex = r'^(On|Off|on|off)$'
group = AppOption.PHP
2015-03-25 17:04:44 +00:00
class PHPSafeMode(PHPAppOption):
name = 'safe_mode'
verbose_name = _("Safe mode")
help_text = _("Whether to enable PHP's safe mode (On or Off) <b>DEPRECATED as of PHP 5.3.0</b>")
regex = r'^(On|Off|on|off)$'
2015-03-04 21:06:16 +00:00
deprecated=5.3
2015-03-25 17:04:44 +00:00
class PHPSuhosinPostMaxVars(PHPAppOption):
name = 'suhosin.post.max_vars'
verbose_name = _("Suhosin POST max vars")
help_text = _("Number between 0 and 9999.")
regex = r'^[0-9]{1,4}$'
2015-03-25 17:04:44 +00:00
class PHPSuhosinGetMaxVars(PHPAppOption):
name = 'suhosin.get.max_vars'
verbose_name = _("Suhosin GET max vars")
help_text = _("Number between 0 and 9999.")
regex = r'^[0-9]{1,4}$'
2015-03-25 17:04:44 +00:00
class PHPSuhosinRequestMaxVars(PHPAppOption):
name = 'suhosin.request.max_vars'
verbose_name = _("Suhosin request max vars")
help_text = _("Number between 0 and 9999.")
regex = r'^[0-9]{1,4}$'
2015-03-25 17:04:44 +00:00
class PHPSuhosinSessionEncrypt(PHPAppOption):
name = 'suhosin.session.encrypt'
2015-04-10 15:03:38 +00:00
verbose_name = _("Suhosin session encrypt")
help_text = _("On or Off")
regex = r'^(On|Off|on|off)$'
2015-03-25 17:04:44 +00:00
class PHPSuhosinSimulation(PHPAppOption):
name = 'suhosin.simulation'
verbose_name = _("Suhosin simulation")
help_text = _("On or Off")
regex = r'^(On|Off|on|off)$'
2015-03-25 17:04:44 +00:00
class PHPSuhosinExecutorIncludeWhitelist(PHPAppOption):
name = 'suhosin.executor.include.whitelist'
2015-04-10 15:03:38 +00:00
verbose_name = _("Suhosin executor include whitelist")
regex = r'.*$'
2015-03-25 17:04:44 +00:00
class PHPUploadMaxFileSize(PHPAppOption):
name = 'upload_max_filesize'
2015-04-24 11:39:20 +00:00
verbose_name = _("Upload max filesize")
help_text = _("Value between 0M and 999M.")
regex = r'^[0-9]{1,3}M$'
class PHPUploadTmpDir(PHPAppOption):
name = 'upload_tmp_dir'
verbose_name = _("Upload tmp dir")
help_text = _("The temporary directory used for storing files when doing file upload. "
"Must be writable by whatever user PHP is running as. "
"If not specified PHP will use the system's default.<br>"
"If the directory specified here is not writable, PHP falls back to the "
"system default temporary directory. If open_basedir is on, then the system "
"default directory must be allowed for an upload to succeed.")
regex = r'.*$'
2015-03-25 17:04:44 +00:00
class PHPZendExtension(PHPAppOption):
2015-03-18 21:51:12 +00:00
name = 'zend_extension'
verbose_name = _("Zend extension")
regex = r'^[^ ]+$'