source: github/program/include/rcube_config.php @ 2ca388d

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 2ca388d was 2ca388d, checked in by thomascube <thomas@…>, 5 years ago

Call load_host_config() and add reference to Howto_Config (#1485040)

  • Property mode set to 100644
File size: 4.5 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/include/rcube_config.php                                      |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2008, RoundCube Dev. - Switzerland                      |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Class to read configuration settings                                |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id: $
19
20*/
21
22/**
23 * Configuration class for RoundCube
24 *
25 * @package Core
26 */
27class rcube_config
28{
29  private $prop = array();
30
31
32  /**
33   * Object constructor
34   */
35  public function __construct()
36  {
37    $this->load();
38  }
39
40
41  /**
42   * Load config from local config file
43   */
44  private function load()
45  {
46    // start output buffering, we don't need any output yet,
47    // it'll be cleared after reading of config files, etc.
48    ob_start();
49   
50    // load main config file
51    include_once(INSTALL_PATH . 'config/main.inc.php');
52    $this->prop = (array)$rcmail_config;
53
54    // load database config
55    include_once(INSTALL_PATH . 'config/db.inc.php');
56    $this->prop += (array)$rcmail_config;
57   
58    // load host-specific configuration
59    $this->load_host_config();
60
61    // fix paths
62    $this->prop['skin_path'] = $this->prop['skin_path'] ? unslashify($this->prop['skin_path']) : 'skins/default';
63    $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs';
64   
65    // handle aliases
66    if (isset($this->prop['locale_string']) && empty($this->prop['language']))
67      $this->prop['language'] = $this->prop['locale_string'];
68
69    // set PHP error logging according to config
70    if ($this->prop['debug_level'] & 1) {
71      ini_set('log_errors', 1);
72      ini_set('error_log', $this->prop['log_dir'] . '/errors');
73    }
74    if ($this->prop['debug_level'] & 4) {
75      ini_set('display_errors', 1);
76    }
77    else {
78      ini_set('display_errors', 0);
79    }
80   
81    // clear output buffer
82    ob_end_clean();
83  }
84 
85 
86  /**
87   * Load a host-specific config file if configured
88   * This will merge the host specific configuration with the given one
89   */
90  private function load_host_config()
91  {
92    $fname = null;
93
94    if (is_array($this->prop['include_host_config'])) {
95      $fname = $this->prop['include_host_config'][$_SERVER['HTTP_HOST']];
96    }
97    else if (!empty($this->prop['include_host_config'])) {
98      $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php';
99    }
100
101    if ($fname && is_file(INSTALL_PATH . 'config/' . $fname)) {
102      include(INSTALL_PATH . 'config/' . $fname);
103      $this->prop = array_merge($this->prop, (array)$rcmail_config);
104    }
105  }
106 
107 
108  /**
109   * Getter for a specific config parameter
110   *
111   * @param  string Parameter name
112   * @param  mixed  Default value if not set
113   * @return mixed  The requested config value
114   */
115  public function get($name, $def = null)
116  {
117    return isset($this->prop[$name]) ? $this->prop[$name] : $def;
118  }
119 
120 
121  /**
122   * Setter for a config parameter
123   *
124   * @param string Parameter name
125   * @param mixed  Parameter value
126   */
127  public function set($name, $value)
128  {
129    $this->prop[$name] = $value;
130  }
131 
132 
133  /**
134   * Override config options with the given values (eg. user prefs)
135   *
136   * @param array Hash array with config props to merge over
137   */
138  public function merge($prefs)
139  {
140    $this->prop = array_merge($this->prop, $prefs);
141  }
142 
143 
144  /**
145   * Getter for all config options
146   *
147   * @return array  Hash array containg all config properties
148   */
149  public function all()
150  {
151    return $this->prop;
152  }
153 
154 
155  /**
156   * Return a 24 byte key for the DES encryption
157   *
158   * @return string DES encryption key
159   */
160  public function get_des_key()
161  {
162    $key = !empty($this->prop['des_key']) ? $this->prop['des_key'] : 'rcmail?24BitPwDkeyF**ECB';
163    $len = strlen($key);
164
165    // make sure the key is exactly 24 chars long
166    if ($len<24)
167      $key .= str_repeat('_', 24-$len);
168    else if ($len>24)
169      substr($key, 0, 24);
170
171    return $key;
172  }
173 
174 
175}
176
Note: See TracBrowser for help on using the repository browser.