commit | author | age
|
6fa2f1
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
44d2a7
|
4 |
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh |
6fa2f1
|
5 |
All rights reserved. |
T |
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
8cf78b
|
31 |
//* Enable gzip compression for the interface |
T |
32 |
ob_start('ob_gzhandler'); |
|
33 |
|
|
34 |
//* Set timezone |
|
35 |
if(isset($conf['timezone']) && $conf['timezone'] != '') date_default_timezone_set($conf['timezone']); |
|
36 |
|
|
37 |
//* Set error reporting level when we are not on a developer system |
|
38 |
if(DEVSYSTEM == 0) { |
|
39 |
@ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|
40 |
} |
|
41 |
|
6fa2f1
|
42 |
/* |
T |
43 |
Application Class |
|
44 |
*/ |
|
45 |
class app { |
|
46 |
|
|
47 |
private $_language_inc = 0; |
|
48 |
private $_wb; |
|
49 |
private $_loaded_classes = array(); |
|
50 |
private $_conf; |
357679
|
51 |
|
MC |
52 |
public $loaded_plugins = array(); |
6fa2f1
|
53 |
|
ae3a8a
|
54 |
public function __construct() { |
6fa2f1
|
55 |
global $conf; |
ae3a8a
|
56 |
|
6fa2f1
|
57 |
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']) || isset($_REQUEST['s']) || isset($_REQUEST['s_old']) || isset($_REQUEST['conf'])) { |
T |
58 |
die('Internal Error: var override attempt detected'); |
|
59 |
} |
357679
|
60 |
|
6fa2f1
|
61 |
$this->_conf = $conf; |
T |
62 |
if($this->_conf['start_db'] == true) { |
|
63 |
$this->load('db_'.$this->_conf['db_type']); |
|
64 |
$this->db = new db; |
|
65 |
} |
ae3a8a
|
66 |
|
6fa2f1
|
67 |
//* Start the session |
T |
68 |
if($this->_conf['start_session'] == true) { |
7fe908
|
69 |
|
a2d572
|
70 |
$this->uses('session'); |
e20f18
|
71 |
$sess_timeout = $this->conf('interface', 'session_timeout'); |
MC |
72 |
if($sess_timeout) { |
de0256
|
73 |
/* check if user wants to stay logged in */ |
MC |
74 |
if(isset($_POST['s_mod']) && isset($_POST['s_pg']) && $_POST['s_mod'] == 'login' && $_POST['s_pg'] == 'index' && isset($_POST['stay']) && $_POST['stay'] == '1') { |
|
75 |
/* check if staying logged in is allowed */ |
9540ba
|
76 |
$this->uses('ini_parser'); |
TB |
77 |
$tmp = $this->db->queryOneRecord('SELECT config FROM sys_ini WHERE sysini_id = 1'); |
|
78 |
$tmp = $this->ini_parser->parse_ini_string(stripslashes($tmp['config'])); |
de0256
|
79 |
if(!isset($tmp['misc']['session_allow_endless']) || $tmp['misc']['session_allow_endless'] != 'y') { |
e20f18
|
80 |
$this->session->set_timeout($sess_timeout); |
efdd1a
|
81 |
session_set_cookie_params(3600 * 24 * 365); // cookie timeout is never updated, so it must not be short |
de0256
|
82 |
} else { |
MC |
83 |
// we are doing login here, so we need to set the session data |
|
84 |
$this->session->set_permanent(true); |
|
85 |
$this->session->set_timeout(365 * 24 * 3600); // one year |
efdd1a
|
86 |
session_set_cookie_params(3600 * 24 * 365); // cookie timeout is never updated, so it must not be short |
de0256
|
87 |
} |
MC |
88 |
} else { |
e20f18
|
89 |
$this->session->set_timeout($sess_timeout); |
efdd1a
|
90 |
session_set_cookie_params(3600 * 24 * 365); // cookie timeout is never updated, so it must not be short |
de0256
|
91 |
} |
a2d572
|
92 |
} else { |
MC |
93 |
session_set_cookie_params(0); // until browser is closed |
c951bb
|
94 |
} |
MC |
95 |
|
7fe908
|
96 |
session_set_save_handler( array($this->session, 'open'), |
MC |
97 |
array($this->session, 'close'), |
|
98 |
array($this->session, 'read'), |
|
99 |
array($this->session, 'write'), |
|
100 |
array($this->session, 'destroy'), |
|
101 |
array($this->session, 'gc')); |
|
102 |
|
6fa2f1
|
103 |
session_start(); |
a2d572
|
104 |
|
6fa2f1
|
105 |
//* Initialize session variables |
T |
106 |
if(!isset($_SESSION['s']['id']) ) $_SESSION['s']['id'] = session_id(); |
|
107 |
if(empty($_SESSION['s']['theme'])) $_SESSION['s']['theme'] = $conf['theme']; |
|
108 |
if(empty($_SESSION['s']['language'])) $_SESSION['s']['language'] = $conf['language']; |
|
109 |
} |
ae3a8a
|
110 |
|
7fe908
|
111 |
$this->uses('functions'); // we need this before all others! |
65ea2e
|
112 |
$this->uses('auth,plugin'); |
6fa2f1
|
113 |
} |
7fe908
|
114 |
|
357679
|
115 |
public function __get($prop) { |
MC |
116 |
if(property_exists($this, $prop)) return $this->{$prop}; |
|
117 |
|
|
118 |
$this->uses($prop); |
|
119 |
if(property_exists($this, $prop)) return $this->{$prop}; |
|
120 |
else return null; |
|
121 |
} |
|
122 |
|
b55e2b
|
123 |
public function __destruct() { |
T |
124 |
session_write_close(); |
|
125 |
} |
6fa2f1
|
126 |
|
ae3a8a
|
127 |
public function uses($classes) { |
V |
128 |
$cl = explode(',', $classes); |
6fa2f1
|
129 |
if(is_array($cl)) { |
ae3a8a
|
130 |
foreach($cl as $classname) { |
6fa2f1
|
131 |
$classname = trim($classname); |
ae3a8a
|
132 |
//* Class is not loaded so load it |
357679
|
133 |
if(!array_key_exists($classname, $this->_loaded_classes) && is_file(ISPC_CLASS_PATH."/$classname.inc.php")) { |
7fe908
|
134 |
include_once ISPC_CLASS_PATH."/$classname.inc.php"; |
6fa2f1
|
135 |
$this->$classname = new $classname(); |
T |
136 |
$this->_loaded_classes[$classname] = true; |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
|
ae3a8a
|
142 |
public function load($files) { |
6fa2f1
|
143 |
$fl = explode(',', $files); |
T |
144 |
if(is_array($fl)) { |
ae3a8a
|
145 |
foreach($fl as $file) { |
6fa2f1
|
146 |
$file = trim($file); |
7fe908
|
147 |
include_once ISPC_CLASS_PATH."/$file.inc.php"; |
6fa2f1
|
148 |
} |
T |
149 |
} |
|
150 |
} |
e20f18
|
151 |
|
MC |
152 |
public function conf($plugin, $key, $value = null) { |
|
153 |
if(is_null($value)) { |
|
154 |
$tmpconf = $this->db->queryOneRecord("SELECT `value` FROM `sys_config` WHERE `group` = '" . $this->db->quote($plugin) . "' AND `name` = '" . $this->db->quote($key) . "'"); |
|
155 |
if($tmpconf) return $tmpconf['value']; |
|
156 |
else return null; |
|
157 |
} else { |
|
158 |
if($value === false) { |
|
159 |
$this->db->query("DELETE FROM `sys_config` WHERE `group` = '" . $this->db->quote($plugin) . "' AND `name` = '" . $this->db->quote($key) . "'"); |
|
160 |
return null; |
|
161 |
} else { |
|
162 |
$this->db->query("REPLACE INTO `sys_config` (`group`, `name`, `value`) VALUES ('" . $this->db->quote($plugin) . "', '" . $this->db->quote($key) . "', '" . $this->db->quote($value) . "')"); |
|
163 |
return $value; |
|
164 |
} |
|
165 |
} |
|
166 |
} |
6fa2f1
|
167 |
|
T |
168 |
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */ |
7fe908
|
169 |
|
MC |
170 |
|
ae3a8a
|
171 |
public function log($msg, $priority = 0) { |
da1da4
|
172 |
global $conf; |
6fa2f1
|
173 |
if($priority >= $this->_conf['log_priority']) { |
da1da4
|
174 |
// $server_id = $conf["server_id"]; |
T |
175 |
$server_id = 0; |
65ea2e
|
176 |
$priority = $this->functions->intval($priority); |
da1da4
|
177 |
$tstamp = time(); |
T |
178 |
$msg = $this->db->quote('[INTERFACE]: '.$msg); |
|
179 |
$this->db->query("INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES ($server_id,0,$priority,$tstamp,'$msg')"); |
|
180 |
/* |
6fa2f1
|
181 |
if (is_writable($this->_conf['log_file'])) { |
T |
182 |
if (!$fp = fopen ($this->_conf['log_file'], 'a')) { |
|
183 |
$this->error('Unable to open logfile.'); |
|
184 |
} |
|
185 |
if (!fwrite($fp, date('d.m.Y-H:i').' - '. $msg."\r\n")) { |
|
186 |
$this->error('Unable to write to logfile.'); |
|
187 |
} |
|
188 |
fclose($fp); |
|
189 |
} else { |
|
190 |
$this->error('Unable to write to logfile.'); |
|
191 |
} |
da1da4
|
192 |
*/ |
ae3a8a
|
193 |
} |
V |
194 |
} |
6fa2f1
|
195 |
|
ae3a8a
|
196 |
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */ |
V |
197 |
public function error($msg, $next_link = '', $stop = true, $priority = 1) { |
6fa2f1
|
198 |
//$this->uses("error"); |
T |
199 |
//$this->error->message($msg, $priority); |
ae3a8a
|
200 |
if($stop == true) { |
903ede
|
201 |
/* |
V |
202 |
* We always have a error. So it is better not to use any more objects like |
|
203 |
* the template or so, because we don't know why the error occours (it could be, that |
|
204 |
* the error occours in one of these objects..) |
|
205 |
*/ |
|
206 |
/* |
|
207 |
* Use the template inside the user-template - Path. If it is not found, fallback to the |
|
208 |
* default-template (the "normal" behaviour of all template - files) |
|
209 |
*/ |
|
210 |
if (file_exists(dirname(__FILE__) . '/../web/themes/' . $_SESSION['s']['theme'] . '/templates/error.tpl.htm')) { |
|
211 |
$content = file_get_contents(dirname(__FILE__) . '/../web/themes/' . $_SESSION['s']['theme'] . '/templates/error.tpl.htm'); |
|
212 |
} else { |
|
213 |
$content = file_get_contents(dirname(__FILE__) . '/../web/themes/default/templates/error.tpl.htm'); |
|
214 |
} |
6fa2f1
|
215 |
if($next_link != '') $msg .= '<a href="'.$next_link.'">Next</a>'; |
ae3a8a
|
216 |
$content = str_replace('###ERRORMSG###', $msg, $content); |
V |
217 |
die($content); |
6fa2f1
|
218 |
} else { |
T |
219 |
echo $msg; |
|
220 |
if($next_link != '') echo "<a href='$next_link'>Next</a>"; |
|
221 |
} |
|
222 |
} |
|
223 |
|
ae3a8a
|
224 |
/** Translates strings in current language */ |
V |
225 |
public function lng($text) { |
c161ea
|
226 |
global $conf; |
6fa2f1
|
227 |
if($this->_language_inc != 1) { |
e83dd1
|
228 |
$language = (isset($_SESSION['s']['language']))?$_SESSION['s']['language']:$conf['language']; |
2eff06
|
229 |
//* loading global Wordbook |
e83dd1
|
230 |
$this->load_language_file('lib/lang/'.$language.'.lng'); |
2eff06
|
231 |
//* Load module wordbook, if it exists |
e83dd1
|
232 |
if(isset($_SESSION['s']['module']['name'])) { |
T |
233 |
$lng_file = 'web/'.$_SESSION['s']['module']['name'].'/lib/lang/'.$language.'.lng'; |
1ca823
|
234 |
if(!file_exists(ISPC_ROOT_PATH.'/'.$lng_file)) $lng_file = '/web/'.$_SESSION['s']['module']['name'].'/lib/lang/en.lng'; |
44d2a7
|
235 |
$this->load_language_file($lng_file); |
6fa2f1
|
236 |
} |
T |
237 |
$this->_language_inc = 1; |
ae3a8a
|
238 |
} |
6fa2f1
|
239 |
if(!empty($this->_wb[$text])) { |
T |
240 |
$text = $this->_wb[$text]; |
ef3719
|
241 |
} else { |
T |
242 |
if($this->_conf['debug_language']) { |
|
243 |
$text = '#'.$text.'#'; |
|
244 |
} |
6fa2f1
|
245 |
} |
T |
246 |
return $text; |
|
247 |
} |
ae3a8a
|
248 |
|
44d2a7
|
249 |
//** Helper function to load the language files. |
T |
250 |
public function load_language_file($filename) { |
|
251 |
$filename = ISPC_ROOT_PATH.'/'.$filename; |
7fe908
|
252 |
if(substr($filename, -4) != '.lng') $this->error('Language file has wrong extension.'); |
44d2a7
|
253 |
if(file_exists($filename)) { |
7fe908
|
254 |
@include $filename; |
44d2a7
|
255 |
if(is_array($wb)) { |
T |
256 |
if(is_array($this->_wb)) { |
7fe908
|
257 |
$this->_wb = array_merge($this->_wb, $wb); |
44d2a7
|
258 |
} else { |
T |
259 |
$this->_wb = $wb; |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
} |
6fa2f1
|
264 |
|
ae3a8a
|
265 |
public function tpl_defaults() { |
6fa2f1
|
266 |
$this->tpl->setVar('app_title', $this->_conf['app_title']); |
b09c9a
|
267 |
if(isset($_SESSION['s']['user'])) { |
T |
268 |
$this->tpl->setVar('app_version', $this->_conf['app_version']); |
7fe908
|
269 |
// get pending datalog changes |
MC |
270 |
$datalog = $this->db->datalogStatus(); |
|
271 |
$this->tpl->setVar('datalog_changes_txt', $this->lng('datalog_changes_txt')); |
|
272 |
$this->tpl->setVar('datalog_changes_end_txt', $this->lng('datalog_changes_end_txt')); |
|
273 |
$this->tpl->setVar('datalog_changes_count', $datalog['count']); |
|
274 |
$this->tpl->setLoop('datalog_changes', $datalog['entries']); |
b09c9a
|
275 |
} else { |
T |
276 |
$this->tpl->setVar('app_version', ''); |
|
277 |
} |
6fa2f1
|
278 |
$this->tpl->setVar('app_link', $this->_conf['app_link']); |
02bf99
|
279 |
/* |
ae3a8a
|
280 |
if(isset($this->_conf['app_logo']) && $this->_conf['app_logo'] != '' && @is_file($this->_conf['app_logo'])) { |
6fa2f1
|
281 |
$this->tpl->setVar('app_logo', '<img src="'.$this->_conf['app_logo'].'">'); |
T |
282 |
} else { |
|
283 |
$this->tpl->setVar('app_logo', ' '); |
|
284 |
} |
02bf99
|
285 |
*/ |
T |
286 |
$this->tpl->setVar('app_logo', $this->_conf['logo']); |
6fa2f1
|
287 |
|
T |
288 |
$this->tpl->setVar('phpsessid', session_id()); |
|
289 |
|
|
290 |
$this->tpl->setVar('theme', $_SESSION['s']['theme']); |
|
291 |
$this->tpl->setVar('html_content_encoding', $this->_conf['html_content_encoding']); |
|
292 |
|
|
293 |
$this->tpl->setVar('delete_confirmation', $this->lng('delete_confirmation')); |
ae3a8a
|
294 |
//print_r($_SESSION); |
6fa2f1
|
295 |
if(isset($_SESSION['s']['module']['name'])) { |
T |
296 |
$this->tpl->setVar('app_module', $_SESSION['s']['module']['name']); |
|
297 |
} |
|
298 |
if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') { |
|
299 |
$this->tpl->setVar('is_admin', 1); |
|
300 |
} |
|
301 |
if(isset($_SESSION['s']['user']) && $this->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
302 |
$this->tpl->setVar('is_reseller', 1); |
|
303 |
} |
955391
|
304 |
/* Show username */ |
V |
305 |
if(isset($_SESSION['s']['user'])) { |
|
306 |
$this->tpl->setVar('cpuser', $_SESSION['s']['user']['username']); |
8cf78b
|
307 |
$this->tpl->setVar('logout_txt', $this->lng('logout_txt')); |
5c4200
|
308 |
/* Show search field only for normal users, not mail users */ |
7fe908
|
309 |
if(stristr($_SESSION['s']['user']['username'], '@')){ |
5c4200
|
310 |
$this->tpl->setVar('usertype', 'mailuser'); |
F |
311 |
} else { |
|
312 |
$this->tpl->setVar('usertype', 'normaluser'); |
|
313 |
} |
955391
|
314 |
} |
7fe908
|
315 |
|
59118c
|
316 |
/* Global Search */ |
F |
317 |
$this->tpl->setVar('globalsearch_resultslimit_of_txt', $this->lng('globalsearch_resultslimit_of_txt')); |
|
318 |
$this->tpl->setVar('globalsearch_resultslimit_results_txt', $this->lng('globalsearch_resultslimit_results_txt')); |
|
319 |
$this->tpl->setVar('globalsearch_noresults_text_txt', $this->lng('globalsearch_noresults_text_txt')); |
|
320 |
$this->tpl->setVar('globalsearch_noresults_limit_txt', $this->lng('globalsearch_noresults_limit_txt')); |
|
321 |
$this->tpl->setVar('globalsearch_searchfield_watermark_txt', $this->lng('globalsearch_searchfield_watermark_txt')); |
ae3a8a
|
322 |
} |
V |
323 |
|
6fa2f1
|
324 |
} // end class |
T |
325 |
|
|
326 |
//** Initialize application (app) object |
|
327 |
//* possible future = new app($conf); |
|
328 |
$app = new app(); |
|
329 |
|
f5b0ca
|
330 |
?> |