forked from watussi/watussibox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_realtime.php
executable file
·212 lines (163 loc) · 6.17 KB
/
api_realtime.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/* api_realtime.php
* Première version : 2 décembre 2012
* Dernière modification : 6 décembre 2012
.---------------------------------------------------------------------------.
| Software: WatussiBox Free |
| Version: 0.1 |
| Contact: [email protected] |
| Info: http://www.watussi.fr |
| Support: http://www.watussi.fr |
| ------------------------------------------------------------------------- |
| Author: Jean-Benoît MOINGT |
| ------------------------------------------------------------------------- |
| License: Distributed under the Creative Commons license (BY-NC-SA ) |
| http://creativecommons.org/licenses/by-nc-sa/3.0/ |
| |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY. |
| ------------------------------------------------------------------------- |
| Licence: Distribué sous licence Creative Commons (BY-NC-SA) |
| http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ |
| |
| Ce programme est distribué dans l'espoir qu'il sera utile - SANS AUCUNE |
| GARANTIE. |
| ------------------------------------------------------------------------- |
| Nous offrons un certain nombre de services complémentaire : |
| - Versions enrichies en fonctionnalitées |
| - Support |
| - Formation |
| - Conseil |
| - Développements spécifiques |
| --> Contactez-nous : [email protected] |
'---------------------------------------------------------------------------'
*/
set_time_limit(0);
$timestart = microtime(true);
include_once('inc/connect.inc.php');
include_once('inc/fonctions.inc.php');
login();
$mode = $_GET['mode'];
// Nb pages cralwlées dans 60 dernières secondes
if($mode == 2){
// Set the JSON header
header("Content-type: text/json");
// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
$x = time() * 1000;
$qry = 'SELECT COUNT(*) AS nb FROM watussi_log WHERE date >= NOW() - INTERVAL 60 SECOND AND type_id = 0;';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$y = intval($row->nb);
// The y value is a random number
//$y = rand(0, 100);
// Create a PHP array and echo it as JSON
$ret = array($x, $y);
echo json_encode($ret);
$dbh = null;
exit();
}
// Nb pages visitées dans 60 dernières secondes
if($mode == 3){
// Set the JSON header
header("Content-type: text/json");
// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
$x = time() * 1000;
$qry = 'SELECT COUNT(*) AS nb FROM watussi_log WHERE date >= NOW() - INTERVAL 60 SECOND AND type_id = 1;';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$y = intval($row->nb);
// The y value is a random number
//$y = rand(0, 100);
// Create a PHP array and echo it as JSON
$ret = array($x, $y);
echo json_encode($ret);
$dbh = null;
exit();
}
?>
<html>
<head>
<style type="text/css">
#beautiful-tab
{
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
margin: 45px;
width: 1000px;
text-align: left;
border-collapse: collapse;
border: 1px solid #69c;
}
#beautiful-tab th
{
padding: 12px 17px 12px 17px;
font-weight: normal;
font-size: 14px;
color: #039;
border-bottom: 1px dashed #69c;
}
#beautiful-tab td
{
padding: 7px 17px 7px 17px;
color: black;
}
#beautiful-tab tbody tr:hover td
{
color: #339;
background: #d0dafd;
}
#beautiful-tab .error
{
background: #F2DEDE;
}
#beautiful-tab .ok
{
background: #DFF0D8;
}
</style>
</head>
<body>
<?php
// Dernières pages crawlées
if($mode == 0){
$qry = 'SELECT url, res_code, date, response_time FROM watussi_log, watussi_url WHERE type_id = 0 AND watussi_url.url_id = watussi_log.url_id ORDER BY date DESC LIMIT 20;';
$res = $dbh->query($qry);
echo "<table id='beautiful-tab'>";
echo "<thead></thead><tr><th>URL</th><th>Res Code</th><th>Response Time</th><th>Date</th></tr></thead>";
while($row = $res->fetch(PDO::FETCH_OBJ)){
$url = $row->url;
$res_code = $row->res_code;
$date = $row->date;
$ecart = get_ecart($date);
$response_time = number_format($row->response_time, 0, ' ', ' ');
echo "<tr"; if(($res_code !='200')&&($res_code !='304')){ echo " class='error'";}else{ echo " class='ok'";} echo " ><td>$url</td><td>$res_code</td><td>$response_time</td><td>(il y a $ecart)</td></tr>";
}
echo "</table>";
}
// Dernières pages visitées
if($mode == 1){
$qry = 'SELECT url, res_code, keyword, date, response_time
FROM watussi_log, watussi_url, watussi_keywords
WHERE type_id = 1
AND watussi_url.url_id = watussi_log.url_id
AND watussi_log.keyword_id = watussi_keywords.keyword_id
ORDER BY date
DESC LIMIT 20;';
$res = $dbh->query($qry);
echo "<table id='beautiful-tab'>";
echo "<thead></thead><tr><th>URL</th><th>Keyword</th><th>Res Code</th><th>Response Time</th><th>Date</th></tr></thead>";
while($row = $res->fetch(PDO::FETCH_OBJ)){
$url = $row->url;
$res_code = $row->res_code;
$date = $row->date;
$keyword = $row->keyword;
$ecart = get_ecart($date);
$response_time = number_format($row->response_time, 0, ' ', ' ');
echo "<tr"; if(($res_code !='200')&&($res_code !='304')){ echo " class='error'";}else{ echo " class='ok'";} echo " ><td>$url</td><td>$keyword</td><td>$res_code</td><td>$response_time</td><td>(il y a $ecart)</td></tr>";
}
echo "</table>";
}
$dbh = null;
?>
</body>
</html>