commit | author | age
|
87a4a6
|
1 |
<?php |
436ed8
|
2 |
|
87a4a6
|
3 |
/* |
436ed8
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
87a4a6
|
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 |
//* Set timezone |
T |
32 |
if(isset($conf['timezone']) && $conf['timezone'] != '') date_default_timezone_set($conf['timezone']); |
|
33 |
|
87a4a6
|
34 |
class app { |
7fe908
|
35 |
|
06b7fa
|
36 |
var $loaded_modules = array(); |
J |
37 |
var $loaded_plugins = array(); |
132081
|
38 |
var $_calling_script = ''; |
7fe908
|
39 |
|
1d8f7f
|
40 |
function __construct() { |
87a4a6
|
41 |
|
06b7fa
|
42 |
global $conf; |
J |
43 |
|
7fe908
|
44 |
if($conf['start_db'] == true) { |
MC |
45 |
$this->load('db_'.$conf['db_type']); |
|
46 |
$this->db = new db; |
|
47 |
|
|
48 |
/* |
|
49 |
Initialize the connection to the master DB, |
|
50 |
if we are in a multiserver setup |
|
51 |
*/ |
|
52 |
|
|
53 |
if($conf['dbmaster_host'] != '' && ($conf['dbmaster_host'] != $conf['db_host'] || ($conf['dbmaster_host'] == $conf['db_host'] && $conf['dbmaster_database'] != $conf['db_database']))) { |
82e9b9
|
54 |
$this->dbmaster = new db($conf['dbmaster_host'], $conf['dbmaster_user'], $conf['dbmaster_password'], $conf['dbmaster_database'], $conf['dbmaster_port']); |
7fe908
|
55 |
} else { |
MC |
56 |
$this->dbmaster = $this->db; |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
} |
|
63 |
|
132081
|
64 |
function setCaller($caller) { |
MC |
65 |
$this->_calling_script = $caller; |
|
66 |
} |
|
67 |
|
|
68 |
function getCaller() { |
|
69 |
return $this->_calling_script; |
|
70 |
} |
|
71 |
|
|
72 |
function forceErrorExit($errmsg = 'undefined') { |
|
73 |
global $conf; |
|
74 |
|
|
75 |
if($this->_calling_script == 'server') { |
|
76 |
@unlink($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'); |
|
77 |
} |
|
78 |
die('Exiting because of error: ' . $errmsg); |
|
79 |
} |
|
80 |
|
7fe908
|
81 |
function uses($classes) { |
MC |
82 |
|
|
83 |
global $conf; |
|
84 |
|
|
85 |
$cl = explode(',', $classes); |
06b7fa
|
86 |
if(is_array($cl)) { |
J |
87 |
foreach($cl as $classname) { |
|
88 |
if(!@is_object($this->$classname)) { |
0ea2a5
|
89 |
if(is_file($conf['classpath'].'/'.$classname.'.inc.php') && (DEVSYSTEM || !is_link($conf['classpath'].'/'.$classname.'.inc.php'))) { |
7fe908
|
90 |
include_once $conf['classpath'].'/'.$classname.'.inc.php'; |
06b7fa
|
91 |
$this->$classname = new $classname; |
5f9759
|
92 |
} |
T |
93 |
} |
|
94 |
} |
06b7fa
|
95 |
} |
7fe908
|
96 |
} |
87a4a6
|
97 |
|
7fe908
|
98 |
function load($classes) { |
87a4a6
|
99 |
|
06b7fa
|
100 |
global $conf; |
J |
101 |
|
7fe908
|
102 |
$cl = explode(',', $classes); |
06b7fa
|
103 |
if(is_array($cl)) { |
J |
104 |
foreach($cl as $classname) { |
0ea2a5
|
105 |
if(is_file($conf['classpath'].'/'.$classname.'.inc.php') && (DEVSYSTEM || !is_link($conf['classpath'].'/'.$classname.'.inc.php'))) { |
7fe908
|
106 |
include_once $conf['classpath'].'/'.$classname.'.inc.php'; |
06b7fa
|
107 |
} else { |
J |
108 |
die('Unable to load: '.$conf['classpath'].'/'.$classname.'.inc.php'); |
32b40d
|
109 |
} |
T |
110 |
} |
06b7fa
|
111 |
} |
7fe908
|
112 |
} |
87a4a6
|
113 |
|
7fe908
|
114 |
/* |
87a4a6
|
115 |
0 = DEBUG |
T |
116 |
1 = WARNING |
|
117 |
2 = ERROR |
|
118 |
*/ |
|
119 |
|
7fe908
|
120 |
function log($msg, $priority = 0) { |
MC |
121 |
|
06b7fa
|
122 |
global $conf; |
7fe908
|
123 |
|
615a0a
|
124 |
switch ($priority) { |
7fe908
|
125 |
case 0: |
MC |
126 |
$priority_txt = 'DEBUG'; |
|
127 |
break; |
|
128 |
case 1: |
|
129 |
$priority_txt = 'WARNING'; |
|
130 |
break; |
|
131 |
case 2: |
|
132 |
$priority_txt = 'ERROR'; |
|
133 |
break; |
615a0a
|
134 |
} |
T |
135 |
$log_msg = @date('d.m.Y-H:i').' - '.$priority_txt.' - '. $msg; |
06b7fa
|
136 |
|
J |
137 |
if($priority >= $conf['log_priority']) { |
7fe908
|
138 |
//if (is_writable($conf["log_file"])) { |
MC |
139 |
if (!$fp = fopen($conf['log_file'], 'a')) { |
|
140 |
die('Unable to open logfile.'); |
|
141 |
} |
9eff6c
|
142 |
|
7fe908
|
143 |
if (!fwrite($fp, $log_msg."\r\n")) { |
MC |
144 |
die('Unable to write to logfile.'); |
|
145 |
} |
|
146 |
|
|
147 |
echo $log_msg."\n"; |
|
148 |
fclose($fp); |
|
149 |
|
|
150 |
// Log to database |
|
151 |
if(isset($this->dbmaster)) { |
|
152 |
$server_id = $conf['server_id']; |
|
153 |
$loglevel = $priority; |
2af58c
|
154 |
$message = $msg; |
7fe908
|
155 |
$datalog_id = (isset($this->modules->current_datalog_id) && $this->modules->current_datalog_id > 0)?$this->modules->current_datalog_id:0; |
MC |
156 |
if($datalog_id > 0) { |
cc7a82
|
157 |
$tmp_rec = $this->dbmaster->queryOneRecord("SELECT count(syslog_id) as number FROM sys_log WHERE datalog_id = ? AND loglevel = ?", $datalog_id, LOGLEVEL_ERROR); |
7fe908
|
158 |
//* Do not insert duplicate errors into the web log. |
MC |
159 |
if($tmp_rec['number'] == 0) { |
cc7a82
|
160 |
$sql = "INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES (?, ?, ?, UNIX_TIMESTAMP(), ?)"; |
MC |
161 |
$this->dbmaster->query($sql, $server_id, $datalog_id, $loglevel, $message); |
06b7fa
|
162 |
} |
7fe908
|
163 |
} else { |
cc7a82
|
164 |
$sql = "INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES (?, 0, ?, UNIX_TIMESTAMP(), ?)"; |
MC |
165 |
$this->dbmaster->query($sql, $server_id, $loglevel, $message); |
615a0a
|
166 |
} |
7fe908
|
167 |
} |
87a4a6
|
168 |
|
7fe908
|
169 |
//} else { |
MC |
170 |
// die("Unable to write to logfile."); |
|
171 |
//} |
|
172 |
|
|
173 |
|
|
174 |
} // if |
|
175 |
|
|
176 |
if(isset($conf['admin_notify_priority']) && $priority >= $conf['admin_notify_priority'] && $conf['admin_mail'] != '') { |
|
177 |
// send notification to admin |
|
178 |
$mailBody = $log_msg; |
|
179 |
$mailSubject = substr($log_msg, 0, 50).'...'; |
|
180 |
$mailHeaders = "MIME-Version: 1.0" . "\n"; |
|
181 |
$mailHeaders .= "Content-type: text/plain; charset=utf-8" . "\n"; |
|
182 |
$mailHeaders .= "Content-Transfer-Encoding: 8bit" . "\n"; |
|
183 |
$mailHeaders .= "From: ". $conf['admin_mail'] . "\n"; |
|
184 |
$mailHeaders .= "Reply-To: ". $conf['admin_mail'] . "\n"; |
|
185 |
|
|
186 |
mail($conf['admin_mail'], $mailSubject, $mailBody, $mailHeaders); |
|
187 |
} |
|
188 |
} // func |
|
189 |
|
|
190 |
|
|
191 |
/* |
87a4a6
|
192 |
0 = DEBUG |
T |
193 |
1 = WARNING |
|
194 |
2 = ERROR |
|
195 |
*/ |
|
196 |
|
7fe908
|
197 |
function error($msg) { |
MC |
198 |
$this->log($msg, 3); |
06b7fa
|
199 |
die($msg); |
7fe908
|
200 |
} |
87a4a6
|
201 |
|
T |
202 |
} |
|
203 |
|
|
204 |
/* |
|
205 |
Initialize application (app) object |
|
206 |
*/ |
|
207 |
|
|
208 |
$app = new app; |
|
209 |
|
5f027c
|
210 |
?> |