Classes

File phpboost/config/ServerEnvironmentConfig.class.php

File phpboost/config/ServerEnvironmentConfig.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Config
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Benoit SAUTEL <ben.popeye@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2017 06 11
 * @since       PHPBoost 3.0 - 2010 07 08
 * @contributor Arnaud GENET <elenwii@phpboost.com>
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor janus57 <janus57@janus57.fr>
*/

class ServerEnvironmentConfig extends AbstractConfigData
{
    const URL_REWRITING_ENABLED       = 'url_rewriting_enabled';
    const REDIRECTION_WWW_ENABLED     = 'redirection_www_enabled';
    const REDIRECTION_WWW_MODE        = 'redirection_www_mode';
    const REDIRECTION_WWW_WITH_WWW    = 'with_www';
    const REDIRECTION_WWW_WITHOUT_WWW = 'without_www';
    const REDIRECTION_HTTPS_ENABLED   = 'redirection_https_enabled';
    const HSTS_SECURITY_ENABLED       = 'hsts_security_enabled';
    const HSTS_SECURITY_SUBDOMAIN_ENABLED   = 'hsts_security_subdomain_enabled';
    const HSTS_SECURITY_DURATION      = 'hsts_security_duration';
    const HTACCESS_MANUAL_CONTENT     = 'htaccess_manual_content';
    const OUTPUT_GZIPING_ENABLED      = 'output_gziping_enabled';

    public function is_url_rewriting_enabled()
    {
        return $this->get_property(self::URL_REWRITING_ENABLED);
    }

    public function set_url_rewriting_enabled($enabled)
    {
        $this->set_property(self::URL_REWRITING_ENABLED, $enabled);
    }

    public function is_redirection_www_enabled()
    {
        return $this->get_property(self::REDIRECTION_WWW_ENABLED);
    }

    public function enable_redirection_www()
    {
        return $this->set_property(self::REDIRECTION_WWW_ENABLED, true);
    }

    public function disable_redirection_www()
    {
        return $this->set_property(self::REDIRECTION_WWW_ENABLED, false);
    }

    public function get_redirection_www_mode()
    {
        return $this->get_property(self::REDIRECTION_WWW_MODE);
    }

    public function is_redirection_www_mode_with_www()
    {
        return $this->get_property(self::REDIRECTION_WWW_MODE) == self::REDIRECTION_WWW_WITH_WWW;
    }

    public function set_redirection_www_mode($value)
    {
        return $this->set_property(self::REDIRECTION_WWW_MODE, $value);
    }

    public function is_redirection_https_enabled()
    {
        return $this->get_property(self::REDIRECTION_HTTPS_ENABLED);
    }

    public function enable_redirection_https()
    {
        return $this->set_property(self::REDIRECTION_HTTPS_ENABLED, true);
    }

    public function disable_redirection_https()
    {
        return $this->set_property(self::REDIRECTION_HTTPS_ENABLED, false);
    }

    public function is_hsts_security_enabled()
    {
        return $this->get_property(self::HSTS_SECURITY_ENABLED);
    }

    public function enable_hsts_security()
    {
        return $this->set_property(self::HSTS_SECURITY_ENABLED, true);
    }

    public function disable_hsts_security()
    {
        return $this->set_property(self::HSTS_SECURITY_ENABLED, false);
    }

    public function get_hsts_security_duration()
    {
        return $this->get_property(self::HSTS_SECURITY_DURATION);
    }

    public function set_hsts_security_duration($value)
    {
        return $this->set_property(self::HSTS_SECURITY_DURATION, ($value * (24 * 60 * 60))); // hour, minute, second
    }

    public function get_config_hsts_security_duration()
    {
        return ($this->get_property(self::HSTS_SECURITY_DURATION) / (24 * 60 * 60));
    }

    public function is_hsts_security_subdomain_enabled()
    {
        return $this->get_property(self::HSTS_SECURITY_SUBDOMAIN_ENABLED);
    }

    public function enable_hsts_subdomain_security()
    {
        return $this->set_property(self::HSTS_SECURITY_SUBDOMAIN_ENABLED, true);
    }

    public function disable_hsts_subdomain_security()
    {
        return $this->set_property(self::HSTS_SECURITY_SUBDOMAIN_ENABLED, false);
    }

    private function htaccess_exists()
    {
        $file = new File(PATH_TO_ROOT . '/.htaccess');
        return $file->exists();
    }

    public function get_htaccess_manual_content()
    {
        return $this->get_property(self::HTACCESS_MANUAL_CONTENT);
    }

    public function set_htaccess_manual_content($content)
    {
        $this->set_property(self::HTACCESS_MANUAL_CONTENT, $content);
    }

    public function is_output_gziping_enabled()
    {
        return $this->get_property(self::OUTPUT_GZIPING_ENABLED);
    }

    public function set_output_gziping_enabled($enabled)
    {
        $this->set_property(self::OUTPUT_GZIPING_ENABLED, $enabled);
    }

    public function get_default_values()
    {
        return array(
            self::URL_REWRITING_ENABLED     => false,
            self::REDIRECTION_WWW_ENABLED   => false,
            self::REDIRECTION_WWW_MODE      => self::REDIRECTION_WWW_WITH_WWW,
            self::REDIRECTION_HTTPS_ENABLED => false,
            self::HSTS_SECURITY_ENABLED     => false,
            self::HSTS_SECURITY_SUBDOMAIN_ENABLED   => false,
            self::HSTS_SECURITY_DURATION    => 2592000, // 30 days per default
            self::HTACCESS_MANUAL_CONTENT   => '',
            self::OUTPUT_GZIPING_ENABLED    => false
        );
    }

    /**
     * Returns the configuration.
     * @return ServerEnvironmentConfig
     */
    public static function load()
    {
        return ConfigManager::load(__CLASS__, 'kernel', 'server-environment-config');
    }

    /**
     * Saves the configuration in the database. Has it become persistent.
     */
    public static function save()
    {
        ConfigManager::save('kernel', self::load(), 'server-environment-config');
    }
}
?>