This repository has been archived by the owner on Sep 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
128 lines (105 loc) · 3.93 KB
/
index.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* w-log Model
*
* @package w-log
* @copyright (C) 2010 John Cox
*
* @subpackage Model
*/
/* This is the only configuration that you need to do.
* Please set the following information with a MySQL user
* That has appropriate permissions to SELECT, TRUNCATE and
* SET GLOBALs
*/
// SET HERE
// Username
$dbuser = 'root';
// Password
$dbpass = 'root';
// HOST
$dbhost = 'localhost';
/* No need to edit anything else. */
include_once 'api/w-log.php';
$w = new wLog($dbuser, $dbpass, $dbhost);
// Determine what we are displaying
if (isset($_GET['phase'])){
$phase = htmlspecialchars($_GET['phase']);
} elseif (isset($_POST['phase'])){
$phase = htmlspecialchars($_POST['phase']);
} else {
$phase = 'load_page';
}
// Display
switch(strtolower($phase)) {
case 'load_page':
$w->setGeneralLog();
$base_url = "http://".$_SERVER['HTTP_HOST']."/";
include_once 'templates/load_page.tpl.php';
break;
case 'display_log':
$gl = $w->getGeneralLog();
if ($gl){
$thread = '';
$db = '';
$count_full = 0;
$count_selects = 0;
foreach ($gl as $key => $var){
if ( $var['command_type'] == 'Connect' ) {
unset($gl[$key]);
} elseif ( $var['command_type'] == 'Init DB' ) {
$db = $var['query'];
$thread = $var['thread_id'];
$gl[$key]['set_db'] = true;
unset($gl[$key]);
} elseif ( (preg_match("/\SELECT\b/i", $var['query'])) AND (!preg_match("/\mysql.general_log\b/i", $var['query'])) AND (!preg_match("/\EXPLAIN\b/i", $var['query'])) ){
$gl[$key]['id'] = 'query_'.$key;
$count_selects = $count_selects + 1;
if ($thread = $var['thread_id']){
$gl[$key]['explain'] = $w->explainQuery($db, $var['query']);
if ($gl[$key]['explain']) {
foreach ($gl[$key]['explain'] as $e){
if ( $e['type'] == 'ALL' ) {
$count_full = $count_full + 1;
}
}
}
}
} elseif (empty($var['query'])){
unset($gl[$key]);
} elseif ( preg_match("/\mysql.general_log\b/i", $var['query']) ) {
unset($gl[$key]);
} elseif ( preg_match("/\EXPLAIN\b/i", $var['query']) ) {
unset($gl[$key]);
} elseif ( preg_match("/\SET NAMES\b/i", $var['query']) ) {
unset($gl[$key]);
} elseif ( preg_match("/\SET GLOBAL\b/i", $var['query']) ) {
unset($gl[$key]);
} else {
$gl[$key]['id'] = 'query_'.$key;
$gl[$key]['explain'] = false;
}
}
}
$truncate = $w->truncateGeneralLog();
include_once 'templates/display_log.tpl.php';
break;
case 'truncate_log':
$truncate = $w->truncateGeneralLog();
echo 'Log is Empty';
return;
break;
case 'disable_log':
$truncate = $w->truncateGeneralLog();
$disable = $w->disableGeneralLog();
echo 'Query Log is Off';
return;
break;
case 'enable_log':
$truncate = $w->truncateGeneralLog();
$enble = $w->setGeneralLog();
echo 'Query Log is On';
return;
break;
}
?>