Server
in package
implements
ActionInterface
Uses
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 firey 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
- $settings_backup_fail : bool
- $settings_not_writable : bool
- $subaction : string
- $subactions : array<string|int, mixed>
- $loadAverageDisabled : bool
- $obj : object
- $backcompat : array<string|int, mixed>
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.
- 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.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- 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.
- load() : object
- 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.
- modifyCacheSettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the cache sub-action.
- modifyCookieSettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the cookie sub-action.
- modifyDatabaseSettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the database sub-action.
- modifyExportSettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the export sub-action.
- modifyGeneralSecuritySettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the security sub-action.
- modifyGeneralSettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the general sub-action.
- modifyLoadBalancingSettings() : void|array<string|int, mixed>
- Backward compatibility wrapper for the loads sub-action.
- phpinfo() : void
- Allows us to see the server's PHP settings
- prepareServerSettingsContext() : mixed
- 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.
- showPHPinfoSettings() : void
- Backward compatibility wrapper for the phpinfo sub-action.
- __construct() : mixed
- Constructor. Protected to force instantiation via self::load().
- alignURLsWithSSLSetting() : mixed
- Align URLs with SSL Setting.
- boardurlMatch() : bool
- Config::$boardurl Match.
- registerSMStats() : mixed
- 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
$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 object
$obj
An instance of this class. This is used by the load() method to prevent mulitple instantiations.
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['call' => 'ModifySettings', 'getLoadAverageDisabled' => 'getLoadAverageDisabled', 'prepareServerSettingsContext' => 'prepareServerSettingsContext', 'checkSettingsFileWriteSafe' => 'checkSettingsFileWriteSafe', 'modifyGeneralSettings' => 'ModifyGeneralSettings', 'modifyDatabaseSettings' => 'ModifyDatabaseSettings', 'modifyCookieSettings' => 'ModifyCookieSettings', 'modifyGeneralSecuritySettings' => 'ModifyGeneralSecuritySettings', 'modifyCacheSettings' => 'ModifyCacheSettings', 'modifyExportSettings' => 'ModifyExportSettings', 'modifyLoadBalancingSettings' => 'ModifyLoadBalancingSettings', 'showPHPinfoSettings' => 'ShowPHPinfoSettings']]
BackwardCompatibility settings for this class.
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
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.
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.
Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
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.
load()
Static wrapper for constructor.
public
static load() : object
Return values
object —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.
modifyCacheSettings()
Backward compatibility wrapper for the cache sub-action.
public
static modifyCacheSettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
modifyCookieSettings()
Backward compatibility wrapper for the cookie sub-action.
public
static modifyCookieSettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
modifyDatabaseSettings()
Backward compatibility wrapper for the database sub-action.
public
static modifyDatabaseSettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
modifyExportSettings()
Backward compatibility wrapper for the export sub-action.
public
static modifyExportSettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
modifyGeneralSecuritySettings()
Backward compatibility wrapper for the security sub-action.
public
static modifyGeneralSecuritySettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
modifyGeneralSettings()
Backward compatibility wrapper for the general sub-action.
public
static modifyGeneralSettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
modifyLoadBalancingSettings()
Backward compatibility wrapper for the loads sub-action.
public
static modifyLoadBalancingSettings([bool $return_config = false ]) : void|array<string|int, mixed>
Parameters
- $return_config : bool = false
-
Whether to return the config_vars array.
Return values
void|array<string|int, mixed> —Returns nothing or returns the config_vars array.
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) : mixed
- 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.
showPHPinfoSettings()
Backward compatibility wrapper for the phpinfo sub-action.
public
static showPHPinfoSettings() : void
__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 ]) : mixed
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() : mixed