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 |
|
|
31 |
class app { |
62a110
|
32 |
|
06b7fa
|
33 |
var $loaded_modules = array(); |
J |
34 |
var $loaded_plugins = array(); |
62a110
|
35 |
|
06b7fa
|
36 |
function app() { |
87a4a6
|
37 |
|
T |
38 |
global $conf; |
|
39 |
|
5f027c
|
40 |
if($conf['start_db'] == true) { |
J |
41 |
$this->load('db_'.$conf['db_type']); |
87a4a6
|
42 |
$this->db = new db; |
12e3ba
|
43 |
|
T |
44 |
/* |
|
45 |
Initialize the connection to the master DB, |
|
46 |
if we are in a multiserver setup |
|
47 |
*/ |
|
48 |
|
5f027c
|
49 |
if($conf['dbmaster_host'] != '' && $conf['dbmaster_host'] != $conf['db_host']) { |
12e3ba
|
50 |
$this->dbmaster = new db; |
T |
51 |
} else { |
|
52 |
$this->dbmaster = $this->db; |
|
53 |
} |
|
54 |
|
|
55 |
|
87a4a6
|
56 |
} |
T |
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
function uses($classes) { |
|
61 |
|
06b7fa
|
62 |
global $conf; |
J |
63 |
|
|
64 |
$cl = explode(',',$classes); |
|
65 |
if(is_array($cl)) { |
|
66 |
foreach($cl as $classname) { |
|
67 |
if(!@is_object($this->$classname)) { |
0ea2a5
|
68 |
if(is_file($conf['classpath'].'/'.$classname.'.inc.php') && (DEVSYSTEM || !is_link($conf['classpath'].'/'.$classname.'.inc.php'))) { |
06b7fa
|
69 |
include_once($conf['classpath'].'/'.$classname.'.inc.php'); |
J |
70 |
$this->$classname = new $classname; |
5f9759
|
71 |
} |
T |
72 |
} |
|
73 |
} |
06b7fa
|
74 |
} |
87a4a6
|
75 |
} |
T |
76 |
|
32b40d
|
77 |
function load($classes) { |
87a4a6
|
78 |
|
06b7fa
|
79 |
global $conf; |
J |
80 |
|
|
81 |
$cl = explode(',',$classes); |
|
82 |
if(is_array($cl)) { |
|
83 |
foreach($cl as $classname) { |
0ea2a5
|
84 |
if(is_file($conf['classpath'].'/'.$classname.'.inc.php') && (DEVSYSTEM || !is_link($conf['classpath'].'/'.$classname.'.inc.php'))) { |
06b7fa
|
85 |
include_once($conf['classpath'].'/'.$classname.'.inc.php'); |
J |
86 |
} else { |
|
87 |
die('Unable to load: '.$conf['classpath'].'/'.$classname.'.inc.php'); |
32b40d
|
88 |
} |
T |
89 |
} |
06b7fa
|
90 |
} |
87a4a6
|
91 |
} |
T |
92 |
|
|
93 |
/* |
|
94 |
0 = DEBUG |
|
95 |
1 = WARNING |
|
96 |
2 = ERROR |
|
97 |
*/ |
|
98 |
|
|
99 |
function log($msg, $priority = 0) { |
|
100 |
|
06b7fa
|
101 |
global $conf; |
J |
102 |
|
|
103 |
if($priority >= $conf['log_priority']) { |
32b40d
|
104 |
//if (is_writable($conf["log_file"])) { |
5f027c
|
105 |
if (!$fp = fopen ($conf['log_file'], 'a')) { |
J |
106 |
die('Unable to open logfile.'); |
87a4a6
|
107 |
} |
06b7fa
|
108 |
switch ($priority) { |
J |
109 |
case 0: |
|
110 |
$priority_txt = 'DEBUG'; |
87a4a6
|
111 |
break; |
06b7fa
|
112 |
case 1: |
J |
113 |
$priority_txt = 'WARNING'; |
87a4a6
|
114 |
break; |
06b7fa
|
115 |
case 2: |
J |
116 |
$priority_txt = 'ERROR'; |
87a4a6
|
117 |
break; |
06b7fa
|
118 |
} |
87a4a6
|
119 |
|
fb3a98
|
120 |
if (!fwrite($fp, @date('d.m.Y-H:i').' - '.$priority_txt.' - '. $msg."\r\n")) { |
5f027c
|
121 |
die('Unable to write to logfile.'); |
87a4a6
|
122 |
} |
fb3a98
|
123 |
echo @date('d.m.Y-H:i').' - '.$priority_txt.' - '. $msg."\n"; |
06b7fa
|
124 |
fclose($fp); |
9eff6c
|
125 |
|
06b7fa
|
126 |
// Log to database |
J |
127 |
if(isset($this->dbmaster)) { |
|
128 |
$server_id = $conf['server_id']; |
|
129 |
$loglevel = $priority; |
|
130 |
$tstamp = time(); |
|
131 |
$message = $this->dbmaster->quote($msg); |
|
132 |
$datalog_id = (isset($this->modules->current_datalog_id) && $this->modules->current_datalog_id > 0)?$this->modules->current_datalog_id:0; |
|
133 |
if($datalog_id > 0) { |
|
134 |
$tmp_rec = $this->dbmaster->queryOneRecord("SELECT count(syslog_id) as number FROM sys_log WHERE datalog_id = $datalog_id AND loglevel = ".LOGLEVEL_ERROR); |
|
135 |
//* Do not insert duplicate errors into the web log. |
|
136 |
if($tmp_rec['number'] == 0) { |
|
137 |
$sql = "INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES ('$server_id',$datalog_id,'$loglevel','$tstamp','$message')"; |
|
138 |
$this->dbmaster->query($sql); |
eaa00d
|
139 |
} |
06b7fa
|
140 |
} else { |
J |
141 |
$sql = "INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES ('$server_id',0,'$loglevel','$tstamp','$message')"; |
|
142 |
$this->dbmaster->query($sql); |
|
143 |
} |
|
144 |
} |
87a4a6
|
145 |
|
32b40d
|
146 |
//} else { |
T |
147 |
// die("Unable to write to logfile."); |
|
148 |
//} |
87a4a6
|
149 |
} // if |
T |
150 |
} // func |
|
151 |
|
|
152 |
/* |
|
153 |
0 = DEBUG |
|
154 |
1 = WARNING |
|
155 |
2 = ERROR |
|
156 |
*/ |
|
157 |
|
|
158 |
function error($msg) { |
|
159 |
$this->log($msg,3); |
06b7fa
|
160 |
die($msg); |
87a4a6
|
161 |
} |
T |
162 |
|
|
163 |
} |
|
164 |
|
|
165 |
/* |
|
166 |
Initialize application (app) object |
|
167 |
*/ |
|
168 |
|
|
169 |
$app = new app; |
|
170 |
|
5f027c
|
171 |
?> |