commit | author | age
|
9855c7
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
949e7e
|
4 |
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh |
9855c7
|
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 |
|
|
31 |
/* |
|
32 |
Application Class |
|
33 |
*/ |
|
34 |
|
|
35 |
ob_start('ob_gzhandler'); |
|
36 |
|
|
37 |
class app { |
|
38 |
|
|
39 |
private $_language_inc = 0; |
|
40 |
private $_wb; |
|
41 |
private $_loaded_classes = array(); |
|
42 |
private $_conf; |
|
43 |
|
|
44 |
public function __construct() |
|
45 |
{ |
|
46 |
global $conf; |
|
47 |
|
|
48 |
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']) || isset($_REQUEST['s']) || isset($_REQUEST['s_old']) || isset($_REQUEST['conf'])) { |
|
49 |
die('Internal Error: var override attempt detected'); |
|
50 |
} |
|
51 |
|
|
52 |
$this->_conf = $conf; |
|
53 |
if($this->_conf['start_db'] == true) { |
|
54 |
$this->load('db_'.$this->_conf['db_type']); |
|
55 |
$this->db = new db; |
|
56 |
} |
|
57 |
|
|
58 |
//* Start the session |
|
59 |
if($this->_conf['start_session'] == true) { |
|
60 |
session_start(); |
|
61 |
|
|
62 |
//* Initialize session variables |
|
63 |
if(!isset($_SESSION['s']['id']) ) $_SESSION['s']['id'] = session_id(); |
|
64 |
if(empty($_SESSION['s']['theme'])) $_SESSION['s']['theme'] = $conf['theme']; |
|
65 |
if(empty($_SESSION['s']['language'])) $_SESSION['s']['language'] = $conf['language']; |
|
66 |
} |
|
67 |
|
|
68 |
$this->uses('auth'); |
|
69 |
} |
|
70 |
|
|
71 |
public function uses($classes) |
|
72 |
{ |
|
73 |
$cl = explode(',', $classes); |
|
74 |
if(is_array($cl)) { |
|
75 |
foreach($cl as $classname){ |
|
76 |
$classname = trim($classname); |
|
77 |
//* Class is not loaded so load it |
|
78 |
if(!array_key_exists($classname, $this->_loaded_classes)){ |
|
79 |
include_once(ISPC_CLASS_PATH."/$classname.inc.php"); |
|
80 |
$this->$classname = new $classname(); |
|
81 |
$this->_loaded_classes[$classname] = true; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
public function load($files) |
|
88 |
{ |
|
89 |
$fl = explode(',', $files); |
|
90 |
if(is_array($fl)) { |
|
91 |
foreach($fl as $file){ |
|
92 |
$file = trim($file); |
|
93 |
include_once(ISPC_CLASS_PATH."/$file.inc.php"); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */ |
|
99 |
public function log($msg, $priority = 0) |
|
100 |
{ |
|
101 |
if($priority >= $this->_conf['log_priority']) { |
|
102 |
if (is_writable($this->_conf['log_file'])) { |
|
103 |
if (!$fp = fopen ($this->_conf['log_file'], 'a')) { |
|
104 |
$this->error('Unable to open logfile.'); |
|
105 |
} |
|
106 |
if (!fwrite($fp, date('d.m.Y-H:i').' - '. $msg."\r\n")) { |
|
107 |
$this->error('Unable to write to logfile.'); |
|
108 |
} |
|
109 |
fclose($fp); |
|
110 |
} else { |
|
111 |
$this->error('Unable to write to logfile.'); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */ |
|
117 |
public function error($msg, $next_link = '', $stop = true, $priority = 1) |
|
118 |
{ |
|
119 |
//$this->uses("error"); |
|
120 |
//$this->error->message($msg, $priority); |
|
121 |
if($stop == true){ |
|
122 |
$msg = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
123 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
124 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|
125 |
<head> |
|
126 |
<title>Error</title> |
|
127 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
128 |
<link href="../themes/default/css/central.css" rel="stylesheet" type="text/css" /> |
|
129 |
</head> |
|
130 |
<body> |
|
131 |
<div class="uniForm"> |
|
132 |
<div id="errorMsg"> |
|
133 |
<h3>Error</h3> |
|
134 |
<ol> |
|
135 |
<li>'.$msg; |
|
136 |
if($next_link != '') $msg .= '<a href="'.$next_link.'">Next</a>'; |
|
137 |
$msg .= '</li> |
|
138 |
</ol> |
|
139 |
</div> |
|
140 |
</div> |
|
141 |
</body> |
|
142 |
</html>'; |
|
143 |
die($msg); |
|
144 |
} else { |
|
145 |
echo $msg; |
|
146 |
if($next_link != '') echo "<a href='$next_link'>Next</a>"; |
|
147 |
} |
|
148 |
} |
|
149 |
|
949e7e
|
150 |
/** Translates strings in current language */ |
9855c7
|
151 |
public function lng($text) |
T |
152 |
{ |
|
153 |
if($this->_language_inc != 1) { |
|
154 |
//* loading global and module Wordbook |
|
155 |
// TODO: this need to be made clearer somehow - pedro |
949e7e
|
156 |
//@include_once(ISPC_ROOT_PATH.'/lib/lang/'.$_SESSION['s']['language'].'.lng'); |
T |
157 |
$this->load_language_file('/lib/lang/'.$_SESSION['s']['language'].'.lng'); |
9855c7
|
158 |
if(isset($_SESSION['s']['module']['name']) && isset($_SESSION['s']['language'])) { |
949e7e
|
159 |
$lng_file = '/web/'.$_SESSION['s']['module']['name'].'/lib/lang/'.$_SESSION['s']['language'].'.lng'; |
T |
160 |
if(!file_exists($lng_file)) $lng_file = '/web/'.$_SESSION['s']['module']['name'].'/lib/lang/en.lng'; |
|
161 |
//@include_once($lng_file); |
|
162 |
$this->load_language_file($lng_file); |
9855c7
|
163 |
} |
949e7e
|
164 |
//if(isset($wb)) $this->_wb = $wb; |
9855c7
|
165 |
$this->_language_inc = 1; |
T |
166 |
} |
|
167 |
if(!empty($this->_wb[$text])) { |
|
168 |
$text = $this->_wb[$text]; |
|
169 |
} |
|
170 |
return $text; |
|
171 |
} |
949e7e
|
172 |
|
T |
173 |
//** Helper function to load the language files. |
|
174 |
public function load_language_file($filename) { |
|
175 |
$filename = ISPC_ROOT_PATH.'/'.$filename; |
|
176 |
if(substr($filename,-4) != '.lng') $this->error('Language file has wrong extension.'); |
|
177 |
if(file_exists($filename)) { |
|
178 |
@include_once($filename); |
|
179 |
if(is_array($wb)) { |
|
180 |
if(is_array($this->_wb)) { |
|
181 |
$this->_wb = array_merge($wb,$this->_wb); |
|
182 |
} else { |
|
183 |
$this->_wb = $wb; |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
} |
9855c7
|
188 |
|
T |
189 |
public function tpl_defaults() |
|
190 |
{ |
|
191 |
$this->tpl->setVar('app_title', $this->_conf['app_title']); |
|
192 |
$this->tpl->setVar('app_version', $this->_conf['app_version']); |
|
193 |
$this->tpl->setVar('app_link', $this->_conf['app_link']); |
|
194 |
if(isset($this->_conf['app_logo']) && $this->_conf['app_logo'] != '' && @is_file($this->_conf['app_logo'])){ |
|
195 |
$this->tpl->setVar('app_logo', '<img src="'.$this->_conf['app_logo'].'">'); |
|
196 |
} else { |
|
197 |
$this->tpl->setVar('app_logo', ' '); |
|
198 |
} |
|
199 |
|
|
200 |
$this->tpl->setVar('phpsessid', session_id()); |
|
201 |
|
|
202 |
$this->tpl->setVar('theme', $_SESSION['s']['theme']); |
|
203 |
$this->tpl->setVar('html_content_encoding', $this->_conf['html_content_encoding']); |
|
204 |
|
|
205 |
$this->tpl->setVar('delete_confirmation', $this->lng('delete_confirmation')); |
|
206 |
//print_r($_SESSION); |
|
207 |
if(isset($_SESSION['s']['module']['name'])) { |
|
208 |
$this->tpl->setVar('app_module', $_SESSION['s']['module']['name']); |
|
209 |
} |
|
210 |
if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') { |
|
211 |
$this->tpl->setVar('is_admin', 1); |
|
212 |
} |
|
213 |
if(isset($_SESSION['s']['user']) && $this->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
214 |
$this->tpl->setVar('is_reseller', 1); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
} // end class |
|
219 |
|
|
220 |
//** Initialize application (app) object |
|
221 |
//* possible future = new app($conf); |
|
222 |
$app = new app(); |
|
223 |
|
b5a2f8
|
224 |
?> |