4 |
--- Setup and common functions include file. |
--- Setup and common functions include file. |
5 |
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
6 |
--- rabit, 04:31 24.08.2004 |
--- rabit, 04:31 24.08.2004 |
7 |
--- $$id$$ |
--- $Id$ |
8 |
------------------------------------------------------------------------------*/ |
------------------------------------------------------------------------------*/ |
9 |
|
|
10 |
|
//------------------------------------------------------------------------------ |
11 |
|
//- Benchmarking: |
12 |
|
|
13 |
|
// Create the benchmark steps array inside "$common": |
14 |
|
$common['benchmark'] = array(); |
15 |
|
|
16 |
|
function common_benchmark_addstep($caption) { |
17 |
|
|
18 |
|
global $common; |
19 |
|
|
20 |
|
$step = array($caption, microtime()); |
21 |
|
|
22 |
|
array_push($common['benchmark'], $step); |
23 |
|
|
24 |
|
} |
25 |
|
|
26 |
|
// The starting entry in the benchmark steps list: |
27 |
|
common_benchmark_addstep('common: start'); |
28 |
|
|
29 |
//---------------------------------------------------------- |
//---------------------------------------------------------- |
30 |
//- Developer host setup: |
//- Developer host setups: |
31 |
|
|
32 |
$cfg['hostsetups'] = array( |
$hostsetups = array( |
33 |
|
|
34 |
'default' => array( |
'default' => array( |
35 |
'urlrel' => '/nfo/', |
'urlrel' => '/nfo/', |
36 |
|
'devstate' => false, |
37 |
|
'mysql_host' => 'localhost', |
38 |
|
'mysql_user' => 'nfo', |
39 |
|
'mysql_pass' => 'b2-cV5RF', |
40 |
|
'mysql_db' => 'nfo' |
41 |
), |
), |
42 |
|
|
43 |
'psl.no-ip.com' => array( |
'psl.no-ip.com' => array( |
44 |
'urlrel' => '/work/www.netfrag.org/', |
'urlrel' => '/work/www.netfrag.org/', |
45 |
|
'devstate' => true, |
46 |
|
'mysql_host' => 'localhost', |
47 |
|
'mysql_user' => 'php', |
48 |
|
'mysql_pass' => 'A289tpQ1', |
49 |
|
'mysql_db' => 'nfo' |
50 |
), |
), |
51 |
|
|
52 |
); |
); |
53 |
|
|
54 |
if(isset($cfg['hostsetups'][$_SERVER['SERVER_NAME']])) { |
// Set the default host setup: |
55 |
|
$common['hostsetup'] = $hostsetups['default']; |
56 |
|
|
57 |
$cfg['hostsetup'] = $cfg['hostsetups'][$_SERVER['SERVER_NAME']]; |
// Set the host setup if a listed host name is given: |
58 |
|
if(isset($hostsetups[$_SERVER['SERVER_NAME']])) $common['hostsetup'] = $hostsetups[$_SERVER['SERVER_NAME']]; |
59 |
|
|
60 |
} else { |
unset($hostsetups); |
61 |
|
|
62 |
|
common_benchmark_addstep('common: host setup'); |
63 |
|
|
64 |
|
//---------------------------------------------------------- |
65 |
|
//- Site variable setups: |
66 |
|
|
67 |
$cfg['hostsetup'] = $cfg['hostsetups']['default']; |
// Paths: |
68 |
|
$common['site']['docroot'] = $_SERVER['DOCUMENT_ROOT'] . $common['hostsetup']['urlrel']; |
69 |
|
$common['site']['incroot'] = $common['site']['docroot'] . 'inc/'; |
70 |
|
$common['site']['libroot'] = $common['site']['docroot'] . 'libs/'; |
71 |
|
|
72 |
|
// URLs: |
73 |
|
$common['site']['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $common['hostsetup']['urlrel']; |
74 |
|
$common['site']['gfxurl'] = $common['site']['url'] . 'gfx/'; |
75 |
|
|
76 |
|
//---------------------------------------------------------- |
77 |
|
//- Page variable setups: |
78 |
|
|
79 |
|
$common['page']['filename'] = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1); |
80 |
|
$common['page']['url'] = $_SERVER['PHP_SELF']; |
81 |
|
|
82 |
|
common_benchmark_addstep('common: site/page setup'); |
83 |
|
|
84 |
|
//------------------------------------------------------------------------------ |
85 |
|
//- Includes: |
86 |
|
|
87 |
|
//common_include('cfg/cfg.php.inc'); |
88 |
|
//common_benchmark_addstep('common: CFG included'); |
89 |
|
|
90 |
|
include($common['site']['incroot'] . 'xmlcp/xmlcp.php.inc'); |
91 |
|
common_benchmark_addstep('common: XMLCP included'); |
92 |
|
|
93 |
|
include($common['site']['incroot'] . 'cms/cms.php.inc'); |
94 |
|
common_benchmark_addstep('common: CMS included'); |
95 |
|
|
96 |
|
//------------------------------------------------------------------------------ |
97 |
|
//- MySQL connection: |
98 |
|
|
99 |
|
common_dbc_connectdb(); |
100 |
|
common_benchmark_addstep('common: connect database'); |
101 |
|
|
102 |
|
//------------------------------------------------------------------------------ |
103 |
|
//- Session setup: |
104 |
|
|
105 |
|
if ($common['client']['session_enabled']) { |
106 |
|
|
107 |
|
// Neither proxies, nor the clients are allowed to cache session data: |
108 |
|
session_cache_limiter('nocache'); |
109 |
|
|
110 |
|
// This is neccessary to make the $_SESSION global available: |
111 |
|
session_start(); |
112 |
|
|
113 |
} |
} |
114 |
|
|
115 |
$documentroot = $_SERVER['DOCUMENT_ROOT'] . $cfg['hostsetup']['urlrel']; |
common_benchmark_addstep('common: session init'); |
116 |
|
|
117 |
|
if(!isset($_SESSION['common_sessiondata'])) { |
118 |
|
|
119 |
|
// The session variable isn't set, create it: |
120 |
|
|
121 |
|
common_benchmark_addstep('common: New session: start'); |
122 |
|
|
123 |
|
$common_sessiondata = array( |
124 |
|
|
125 |
|
'birthtime' => time(), |
126 |
|
'firstrequest' => 1, // Mark the very first page request. |
127 |
|
|
128 |
|
// Empty user data sub array: |
129 |
|
'userdata' => array( |
130 |
|
'name' => '', |
131 |
|
'password' => '', |
132 |
|
'authorised' => false, |
133 |
|
), |
134 |
|
|
135 |
|
// Content related additional data: |
136 |
|
'additionaldata' => array() |
137 |
|
|
138 |
|
); |
139 |
|
|
140 |
|
common_benchmark_addstep('common: New session: create session'); |
141 |
|
|
142 |
|
// Protocol the visitors hit and store the columns insertion ID: |
143 |
|
$common_sessiondata['hit_id'] = common_protocolhit(); |
144 |
|
|
145 |
|
common_benchmark_addstep('common: New session: protocol hit'); |
146 |
|
|
147 |
|
// Store a reference to the session data array: |
148 |
|
$_SESSION['common_sessiondata'] = &$common_sessiondata; |
149 |
|
|
150 |
|
common_benchmark_addstep('common: New session: store session/end'); |
151 |
|
|
152 |
|
} else { |
153 |
|
|
154 |
|
// Restore the session data array reference: |
155 |
|
$common_sessiondata = &$_SESSION['common_sessiondata']; |
156 |
|
|
157 |
|
// Reset the first page request flag: |
158 |
|
$common_sessiondata['firstrequest'] = null; |
159 |
|
|
160 |
|
// Update the request count in the "hits" table: |
161 |
|
|
162 |
|
$sql = "UPDATE hits SET requestcount=requestcount+1 WHERE id='" . $common_sessiondata['hit_id'] . "';"; |
163 |
|
|
164 |
|
common_dbc_query($sql); |
165 |
|
|
166 |
|
common_benchmark_addstep('common: session/hit data updated'); |
167 |
|
|
168 |
|
} |
169 |
|
|
170 |
//------------------------------------------------------------------------------ |
//------------------------------------------------------------------------------ |
171 |
//- Configuration include file: |
//- URL parameter flags and variables: |
172 |
|
|
173 |
|
if(isset($_GET['devstate'])) $common_sessiondata['userdata']['devstate'] = $_GET['devstate']; |
174 |
|
|
175 |
include($documentroot . 'inc/cfg/cfg.php.inc'); |
if(isset($common_sessiondata['userdata']['devstate'])) $common['hostsetup']['devstate'] = $common_sessiondata['userdata']['devstate']; |
176 |
|
|
177 |
//------------------------------------------------------------------------------ |
//------------------------------------------------------------------------------ |
178 |
//- Functions: |
//- Functions: |
179 |
|
|
180 |
function common_headline($caption) { |
function common_checkauthorisation() { |
181 |
|
|
182 |
echo '<h5>' . $caption . '</h5> |
global $common_sessiondata; |
183 |
|
|
184 |
'; |
$username = $common_sessiondata['userdata']['name']; |
185 |
|
$password = $common_sessiondata['userdata']['password']; |
186 |
|
|
187 |
} |
if((strlen($username) < 2) || (strlen($password) < 2)) return false; |
188 |
|
|
189 |
//---------------------------------------------------------- |
$sql = "SELECT id, rights, logincount, lastlogin FROM users WHERE name='$username' AND password='$password';"; |
190 |
|
|
191 |
function common_pageheader() { |
$res = common_dbc_query($sql); |
192 |
|
|
193 |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
if(!$res) return false; |
194 |
|
|
195 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
if(!($row = mysql_fetch_row($res))) return false; |
196 |
|
|
197 |
<head> |
// Congratulations - authorisation suxxessful! |
|
<title>www.netfrag.org</title> |
|
|
<style type="text/css"><!-- |
|
|
body { font: 10pt tahoma, serif; } |
|
|
h2, .box, .hl { background-color:#e0e0e0; padding:8px; } |
|
|
h2, .box { border:1px solid #a0a0a0; } |
|
|
--></style> |
|
|
</head> |
|
198 |
|
|
199 |
<body> |
$logintime = time(); |
200 |
|
|
201 |
<h2>www.netfrag.org</h2> |
$userid = $row[0]; |
202 |
|
$rights = $row[1]; |
203 |
|
$logincount = $row[2] + 1; |
204 |
|
$lastlogin = $row[3]; |
205 |
|
|
206 |
<h3>• Home</h3> |
$common_sessiondata['userdata']['authorised'] = true; |
207 |
|
|
208 |
'; |
$common_sessiondata['userdata']['id'] = $userid; |
209 |
|
$common_sessiondata['userdata']['lastlogin'] = $lastlogin; |
210 |
|
$common_sessiondata['userdata']['rights'] = $rights; |
211 |
|
|
212 |
|
// Break if the user already has authorised in this session: |
213 |
|
if(isset($common_sessiondata['userdata']['logintime'])) return false; |
214 |
|
|
215 |
|
$common_sessiondata['userdata']['logincount'] = $logincount; |
216 |
|
$common_sessiondata['userdata']['logintime'] = $logintime; |
217 |
|
|
218 |
|
// print_r($common_sessiondata['userdata']); |
219 |
|
|
220 |
|
$sql = "UPDATE users SET logincount='$logincount', lastlogin=FROM_UNIXTIME('$logintime') WHERE id='$userid';"; |
221 |
|
|
222 |
|
$res = common_dbc_query($sql); |
223 |
|
|
224 |
|
if(!$res) return false; |
225 |
|
|
226 |
|
return true; |
227 |
|
|
228 |
} |
} |
229 |
|
|
230 |
//---------------------------------------------------------- |
//------------------------------------------------------------------------------ |
231 |
|
|
232 |
function common_pagefooter() { |
function common_protocolhit() { |
233 |
|
|
234 |
echo '<p align="center" class="box"> |
global $common, $common_sessiondata; |
|
(foot notes) |
|
|
</p> |
|
235 |
|
|
236 |
</body> |
$address = $_SERVER['REMOTE_ADDR'] . ':' . $_SERVER["REMOTE_PORT"]; |
237 |
|
$entryurl = $_SERVER['REQUEST_URI']; |
238 |
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); |
239 |
|
$sessionid = session_id(); |
240 |
|
$unixtime = $common_sessiondata['birthtime']; |
241 |
|
$useragent = $_SERVER['HTTP_USER_AGENT']; |
242 |
|
|
243 |
</html> |
$sql = "INSERT INTO hits (id, timestamp, address, entryurl, referer, sessionid, useragent, requestcount) VALUES (NULL, FROM_UNIXTIME('$unixtime'), '$address', '$entryurl', '$referer', '$sessionid', '$useragent', '1');"; |
244 |
'; |
|
245 |
|
$res = common_dbc_query($sql); |
246 |
|
|
247 |
|
if(!$res) return false; |
248 |
|
|
249 |
|
return mysql_insert_id($common['dbc']['h_myqsllink']); |
250 |
|
|
251 |
} |
} |
252 |
|
|
253 |
//---------------------------------------------------------- |
//---------------------------------------------------------- |
254 |
|
//- Database functions: |
255 |
|
|
256 |
|
function common_dbc_connect() { |
257 |
|
|
258 |
|
global $common; |
259 |
|
|
260 |
|
$common['dbc']['connected'] = false; |
261 |
|
|
262 |
|
$h_myqsllink = mysql_pconnect( |
263 |
|
$common['hostsetup']['mysql_host'], |
264 |
|
$common['hostsetup']['mysql_user'], |
265 |
|
$common['hostsetup']['mysql_pass'] |
266 |
|
); |
267 |
|
|
268 |
|
if(!$h_myqsllink) return false; |
269 |
|
|
270 |
|
$common['dbc']['connected'] = true; |
271 |
|
$common['dbc']['h_myqsllink'] = $h_myqsllink; |
272 |
|
|
273 |
|
return true; |
274 |
|
|
275 |
|
} |
276 |
|
|
277 |
|
function common_dbc_selectdb() { |
278 |
|
|
279 |
|
global $common; |
280 |
|
|
281 |
function common_paragraph($contents, $class = '') { |
$common['dbc']['dbselected'] = false; |
282 |
|
|
283 |
echo '<p align="justify"' . ($class ? ' class="' . $class . '"' : '') . '> |
if( |
284 |
' . $contents . ' |
!mysql_selectdb($common['hostsetup']['mysql_db']) |
285 |
</p> |
) return false; |
286 |
|
|
287 |
|
$common['dbc']['dbselected'] = true; |
288 |
|
|
289 |
|
return true; |
290 |
|
|
291 |
|
} |
292 |
|
|
293 |
|
function common_dbc_connectdb() { |
294 |
|
|
295 |
|
global $common; |
296 |
|
|
297 |
|
$common['dbc']['dbconnected'] = (common_dbc_connect() && common_dbc_selectdb()); |
298 |
|
|
299 |
|
return $common['dbc']['dbconnected']; |
300 |
|
|
301 |
|
} |
302 |
|
|
303 |
|
function common_dbc_query($sql) { |
304 |
|
|
305 |
|
global $common; |
306 |
|
|
307 |
|
if(!$common['dbc']['dbconnected']) return false; |
308 |
|
|
309 |
|
$res = mysql_query($sql); |
310 |
|
|
311 |
|
if($errormsg = mysql_error()) { |
312 |
|
|
313 |
|
// >>> MTC <<< |
314 |
|
|
315 |
|
echo $errormsg . '<br /> |
316 |
|
<br /> |
317 |
'; |
'; |
318 |
|
|
319 |
|
} |
320 |
|
|
321 |
|
if(!$res) return false; |
322 |
|
|
323 |
|
return $res; |
324 |
|
|
325 |
} |
} |
326 |
|
|
327 |
|
//---------------------------------------------------------- |
328 |
|
//- File functions: |
329 |
|
|
330 |
|
//---------------------------------------------------------- |
331 |
|
//- Utility functions: |
332 |
|
function common_get_baseurl() { |
333 |
|
$baseurl = "http://" . $_SERVER['SERVER_NAME'] . "" . $_SERVER['SCRIPT_NAME'] . "/"; |
334 |
|
return $baseurl; |
335 |
|
} |
336 |
|
|
337 |
|
//------------------------------------------------------------------------------ |
338 |
|
|
339 |
|
common_benchmark_addstep('common: end'); |
340 |
|
|
341 |
//------------------------------------------------------------------------------ |
//------------------------------------------------------------------------------ |
342 |
|
|
|
?> |
|
343 |
|
?> |