-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring.php
108 lines (98 loc) · 3.65 KB
/
monitoring.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* This file provides monitoring functionality...
* Returns time of execution in ms
* Available arguments: number (if defined and true script will return 999999 on any error), type (session, database, data_directory - run only one test)
* @author Paul Bukowski <pbukowski@telaxus.com>
* @copyright Copyright © 2006, Telaxus LLC
* @license MIT
* @version 1.0
* @package epesi-base
*/
define('CID',1);
define('SET_SESSION',false);
if (php_sapi_name() == 'cli') {
define('EPESI_DIR', '/');
if (isset($argv[1])) {
define('DATA_DIR', $argv[1]);
}
} elseif (!isset($_GET['token'])) {
die('Missing token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
} else {
defined("_VALID_ACCESS") || define("_VALID_ACCESS", true);
require_once('include/include_path.php');
require_once('include/data_dir.php');
if(!file_exists(DATA_DIR.'/cron_token.php'))
die('Invalid token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
require_once(DATA_DIR.'/cron_token.php');
if(CRON_TOKEN!=$_GET['token'])
die('Invalid token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
}
try {
require_once('include.php');
ModuleManager::load_modules();
Base_AclCommon::set_sa_user();
} catch(Exception $e) {
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: init');
}
class MonitoringErrorObserver extends ErrorObserver {
public function update_observer($type, $message,$errfile,$errline,$errcontext, $backtrace) {
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: '.$type.'# '.$message);
}
}
$err = new MonitoringErrorObserver();
ErrorHandler::add_observer($err);
function test_database() {
$up = epesi_requires_update();
if($up===null) {
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: database');
} elseif($up===true) {
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: version');
}
}
function test_session() {
$tag = microtime(1);
$session_id = 'monitoring_'.md5(DATABASE_NAME.'#'.DATABASE_HOST.'#'.DATABASE_DRIVER);
$_SESSION = EpesiSession::get($session_id);
$_SESSION['monitoring'] = $tag;
$_SESSION['client']['monitoring'] = $tag;
EpesiSession::set($session_id, $_SESSION);
$_SESSION = EpesiSession::get($session_id);
if(!isset($_SESSION['monitoring']) || !isset($_SESSION['client']['monitoring']) || $_SESSION['monitoring'] != $tag || $_SESSION['client']['monitoring'] != $tag) {
EpesiSession::set($session_id, $_SESSION);
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: session');
}
EpesiSession::set($session_id, $_SESSION);
}
function test_data_directory() {
$tag = (string)microtime(1);
if(!is_writable(DATA_DIR)) {
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: data directory now writable');
}
$test_file = DATA_DIR.'/monitoring_test_file.txt';
@file_put_contents($test_file, $tag);
if(@file_get_contents($test_file) != $tag) {
if(isset($_GET['number']) && $_GET['number']) die('999999');
die('error: data directory write/read error');
}
unlink($test_file);
}
$t = microtime(1);
if(isset($_GET['type'])) {
if(in_array($_GET['type'],array('database','session','data_directory'))) {
call_user_func('test_'.$_GET['type']);
} else {
die('Invalid test type: '.$_GET['type']);
}
} else {
test_database();
test_session();
test_data_directory();
}
die(round((microtime(1)-$t)*1000));