Server
in package
implements
ActionInterface
uses
ActionTrait, BackwardCompatibility
Contains all the functionality required to be able to edit the core server settings. This includes anything from which an error may result in the forum destroying itself in a fiery fury.
Adding options to one of the setting screens isn't hard. Call prepareDBSettingsContext; The basic format for a checkbox is: array('check', 'nameInModSettingsAndSQL'), And for a text box: array('text', 'nameInModSettingsAndSQL') (NOTE: You have to add an entry for this at the bottom!)
In these cases, it will look for Lang::$txt['nameInModSettingsAndSQL'] as the description, and Lang::$helptxt['nameInModSettingsAndSQL'] as the help popup description.
Here's a quick explanation of how to add a new item:
- A text input box. For textual values. array('text', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
- A text input box. For numerical values. array('int', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
- A text input box. For floating point values. array('float', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
- A large text input box. Used for textual values spanning multiple lines. array('large_text', 'nameInModSettingsAndSQL', 'OptionalNumberOfRows'),
- A check box. Either one or zero. (boolean) array('check', 'nameInModSettingsAndSQL'),
- A selection box. Used for the selection of something from a list. array('select', 'nameInModSettingsAndSQL', array('valueForSQL' => Lang::$txt['displayedValue'])), Note that just saying array('first', 'second') will put 0 in the SQL for 'first'.
- A password input box. Used for passwords, no less! array('password', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth'),
- A permission - for picking groups who have a permission. array('permissions', 'manage_groups'),
- A BBC selection box. array('bbc', 'sig_bbc'),
- A list of boards to choose from array('boards', 'likes_boards'), Note that the storage in the database is as 1,2,3,4
For each option: - type (see above), variable name, size/possible values. OR make type '' for an empty string for a horizontal rule.
- SET preinput - to put some HTML prior to the input box.
- SET postinput - to put some HTML following the input box.
- SET invalid - to mark the data as invalid.
- PLUS you can override label and help parameters by forcing their keys in the array, for example: array('text', 'invalidlabel', 3, 'label' => 'Actual Label')
Table of Contents
Interfaces
- ActionInterface
- Interface for all action classes.
Constants
- LOADAVG_DEFAULT_VALUES = ['loadavg_auto_opt' => 1.0, 'loadavg_search' => 2.5, 'loadavg_allunread' => 2.0, 'loadavg_unreadreplies' => 3.5, 'loadavg_show_posts' => 2.0, 'loadavg_userstats' => 10.0, 'loadavg_bbc' => 30.0, 'loadavg_forum' => 40.0]
- Default values for load balancing options.
Properties
- $diskspace_disabled : bool
- $settings_backup_fail : bool
- $settings_not_writable : bool
- $subaction : string
- $subactions : array<string|int, mixed>
- $loadAverageDisabled : bool
- $obj : static
Methods
- cache() : void
- Simply modifying cache functions
- cacheConfigVars() : array<string|int, mixed>
- Gets configuration variables for the cache sub-action.
- call() : void
- Convenience method to load() and execute() an instance of this class.
- canBeLogged() : bool
- Determines whether this action can be logged in the online log.
- canShowDebuggingInfo() : bool
- Determines whether debugging info should be shown.
- canShowInMaintenanceMode() : bool
- Determines whether this action allows access in maintenance mode.
- checkSettingsFileWriteSafe() : bool
- Checks whether it is safe to write to Settings.php.
- cookie() : void
- This function handles cookies settings modifications.
- cookieConfigVars() : array<string|int, mixed>
- Gets configuration variables for the cookie sub-action.
- database() : void
- Basic database and paths settings - database name, host, etc.
- databaseConfigVars() : array<string|int, mixed>
- Gets configuration variables for the database sub-action.
- execute() : void
- This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects the appropriate one based on the sub-action.
- export() : void
- Controls settings for data export functionality
- exportConfigVars() : array<string|int, mixed>
- Gets configuration variables for the export sub-action.
- general() : void
- General forum settings - forum name, maintenance mode, etc.
- generalConfigVars() : array<string|int, mixed>
- Gets configuration variables for the general sub-action.
- getLoadAverageDisabled() : bool
- Figures out whether we can calculate load averages on this server.
- getOutputType() : OutputTypeInterface
- Gets the output type for this action.
- isAgreementAction() : bool
- Determines whether this action can be accessed without accepting the registration agreement and privacy policy.
- isRestrictedGuestAccessAllowed() : bool
- Determines whether this action allows access if guest access is restricted.
- isSimpleAction() : bool
- Determines whether this is a simple action.
- load() : static
- Static wrapper for constructor.
- loadBalancing() : void
- Allows to edit load balancing settings.
- loadBalancingConfigVars() : array<string|int, mixed>
- Gets configuration variables for the loads sub-action.
- phpinfo() : void
- Allows us to see the server's PHP settings
- prepareServerSettingsContext() : void
- Helper function, it sets up the context for the manage server settings.
- security() : void
- Settings really associated with general security aspects.
- securityConfigVars() : array<string|int, mixed>
- Gets configuration variables for the security sub-action.
- subActionProvider() : null|array<string|int, mixed>
- Called by Subs-Compat.php BackwardCompatibility wrapper functions to provide subaction execution for existing mods
- __construct() : mixed
- Constructor. Protected to force instantiation via self::load().
- alignURLsWithSSLSetting() : void
- Align URLs with SSL Setting.
- boardurlMatch() : bool
- Config::$boardurl Match.
- registerSMStats() : bool
- Registers the site with the Simple Machines Stat collection. This function purposely does not use Config::updateModSettings() as it will be called shortly after this process completes by the saveSettings() function.
Constants
LOADAVG_DEFAULT_VALUES
Default values for load balancing options.
public
mixed
LOADAVG_DEFAULT_VALUES
= ['loadavg_auto_opt' => 1.0, 'loadavg_search' => 2.5, 'loadavg_allunread' => 2.0, 'loadavg_unreadreplies' => 3.5, 'loadavg_show_posts' => 2.0, 'loadavg_userstats' => 10.0, 'loadavg_bbc' => 30.0, 'loadavg_forum' => 40.0]
Properties
$diskspace_disabled
public
static bool
$diskspace_disabled
= false
True if the host has disabled checking dispace.
$settings_backup_fail
public
static bool
$settings_backup_fail
True if we are unable to back up Settings.php.
$settings_not_writable
public
static bool
$settings_not_writable
True if Settings.php is not writable.
$subaction
public
string
$subaction
= 'general'
The requested sub-action. This should be set by the constructor.
$subactions
public
static array<string|int, mixed>
$subactions
= ['general' => 'general', 'database' => 'database', 'cookie' => 'cookie', 'security' => 'security', 'cache' => 'cache', 'export' => 'export', 'loads' => 'loadBalancing', 'phpinfo' => 'phpinfo']
Available sub-actions.
$loadAverageDisabled
protected
static bool
$loadAverageDisabled
Whether load averaging is disabled on this server.
$obj
protected
static static
$obj
An instance of this class. This is used by the load() method to prevent multiple instantiations.
Methods
cache()
Simply modifying cache functions
public
cache() : void
cacheConfigVars()
Gets configuration variables for the cache sub-action.
public
static cacheConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
call()
Convenience method to load() and execute() an instance of this class.
public
static call() : void
canBeLogged()
Determines whether this action can be logged in the online log.
public
canBeLogged() : bool
Return values
boolcanShowDebuggingInfo()
Determines whether debugging info should be shown.
public
canShowDebuggingInfo() : bool
Return values
boolcanShowInMaintenanceMode()
Determines whether this action allows access in maintenance mode.
public
canShowInMaintenanceMode() : bool
Return values
bool —True if access is allowed, false otherwise.
checkSettingsFileWriteSafe()
Checks whether it is safe to write to Settings.php.
public
static checkSettingsFileWriteSafe() : bool
Sets self::$settings_not_writable and self::$settings_backup_fail.
Return values
bool —True if Settings.php and Settings_bak.php are both writable.
cookie()
This function handles cookies settings modifications.
public
cookie() : void
cookieConfigVars()
Gets configuration variables for the cookie sub-action.
public
static cookieConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
database()
Basic database and paths settings - database name, host, etc.
public
database() : void
- It shows an interface for the settings in Settings.php to be changed.
- It contains the actual array of settings to show from Settings.php.
- Requires the admin_forum permission.
- Uses the edit_settings administration area.
- Accessed from ?action=admin;area=serversettings;sa=database.
databaseConfigVars()
Gets configuration variables for the database sub-action.
public
static databaseConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
execute()
This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects the appropriate one based on the sub-action.
public
execute() : void
Requires the admin_forum permission. Redirects to the appropriate function based on the sub-action.
Uses edit_settings adminIndex.
export()
Controls settings for data export functionality
public
export() : void
exportConfigVars()
Gets configuration variables for the export sub-action.
public
static exportConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
general()
General forum settings - forum name, maintenance mode, etc.
public
general() : void
Practically, this shows an interface for the settings in Settings.php to be changed.
- Requires the admin_forum permission.
- Uses the edit_settings administration area.
- Contains the actual array of settings to show from Settings.php.
- Accessed from ?action=admin;area=serversettings;sa=general.
generalConfigVars()
Gets configuration variables for the general sub-action.
public
static generalConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
getLoadAverageDisabled()
Figures out whether we can calculate load averages on this server.
public
static getLoadAverageDisabled() : bool
Return values
bool —If true, we can't calculate load averages.
getOutputType()
Gets the output type for this action.
public
getOutputType() : OutputTypeInterface
Return values
OutputTypeInterfaceisAgreementAction()
Determines whether this action can be accessed without accepting the registration agreement and privacy policy.
public
isAgreementAction() : bool
Return values
boolisRestrictedGuestAccessAllowed()
Determines whether this action allows access if guest access is restricted.
public
isRestrictedGuestAccessAllowed() : bool
Return values
bool —True if access is allowed, false otherwise.
isSimpleAction()
Determines whether this is a simple action.
public
isSimpleAction() : bool
Return values
boolload()
Static wrapper for constructor.
public
static load() : static
Return values
static —An instance of this class.
loadBalancing()
Allows to edit load balancing settings.
public
loadBalancing() : void
loadBalancingConfigVars()
Gets configuration variables for the loads sub-action.
public
static loadBalancingConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
phpinfo()
Allows us to see the server's PHP settings
public
phpinfo() : void
- loads the settings into an array for display in a template
- drops cookie values just in case
prepareServerSettingsContext()
Helper function, it sets up the context for the manage server settings.
public
static prepareServerSettingsContext(array<string|int, mixed> &$config_vars) : void
- The basic usage of the six numbered key fields are
- array (0 ,1, 2, 3, 4, 5 0 variable name - the name of the saved variable 1 label - the text to show on the settings page 2 saveto - file or db, where to save the variable name - value pair 3 type - type of data to save, int, float, text, check 4 size - false or field size 5 help - '' or helptxt variable name )
the following named keys are also permitted 'disabled' => A string of code that will determine whether or not the setting should be disabled 'postinput' => Text to display after the input field 'preinput' => Text to display before the input field 'subtext' => Additional descriptive text to display under the field's label 'min' => minimum allowed value (for int/float). Defaults to 0 if not set. 'max' => maximum allowed value (for int/float) 'step' => how much to increment/decrement the value by (only for int/float - mostly used for float values).
Parameters
- $config_vars : array<string|int, mixed>
-
An array of configuration variables
security()
Settings really associated with general security aspects.
public
security() : void
securityConfigVars()
Gets configuration variables for the security sub-action.
public
static securityConfigVars() : array<string|int, mixed>
Return values
array<string|int, mixed> —$config_vars for the sub-action.
subActionProvider()
Called by Subs-Compat.php BackwardCompatibility wrapper functions to provide subaction execution for existing mods
public
static subActionProvider([null|string $sa = null ][, bool $return_config = false ][, string|null $activity = null ]) : null|array<string|int, mixed>
Parameters
- $sa : null|string = null
- $return_config : bool = false
- $activity : string|null = null
Return values
null|array<string|int, mixed>__construct()
Constructor. Protected to force instantiation via self::load().
protected
__construct() : mixed
alignURLsWithSSLSetting()
Align URLs with SSL Setting.
protected
alignURLsWithSSLSetting([int $new_force_ssl = 0 ]) : void
If force_ssl has changed, ensure all URLs are aligned with the new setting. This includes: - Config::$boardurl - Config::$modSettings['smileys_url'] - Config::$modSettings['avatar_url'] - Config::$modSettings['custom_avatar_url'] - if found - theme_url - all entries in the themes table - images_url - all entries in the themes table
This function will NOT overwrite URLs that are not subfolders of $boardurl. The admin must have pointed those somewhere else on purpose, so they must be updated manually.
A word of caution: You can't trust the http/https scheme reflected for these URLs in Config::* or in Config::$modSettings. This is because SMF may change them in memory to comply with the force_ssl setting - a soft redirect may be in effect. Thus, conditional updates to these values do not work. You gotta just brute force overwrite them based on force_ssl.
Parameters
- $new_force_ssl : int = 0
-
is the current force_ssl setting.
boardurlMatch()
Config::$boardurl Match.
protected
boardurlMatch([string $url = '' ]) : bool
Helper function to see if the url being checked is based off of Config::$boardurl. If not, it was overridden by the admin to some other value on purpose, and should not be stepped on by SMF when aligning URLs with the force_ssl setting. The site admin must change URLs that are not aligned with Config::$boardurl manually.
Parameters
- $url : string = ''
-
is the url to check.
Return values
bool —Returns true if the url is based off of Config::$boardurl (without the scheme), false if not
registerSMStats()
Registers the site with the Simple Machines Stat collection. This function purposely does not use Config::updateModSettings() as it will be called shortly after this process completes by the saveSettings() function.
protected
registerSMStats() : bool
Tags
Return values
bool —Returns true if we are registered or successfully registered, otherwise false.