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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
/*
* Copyright (C) 2005 - 2014 Alexander Schier, Michael Peter Christen,
* and other YaCy developers (see http://yacy.net/en/Join.html)
*
* This file is part of YaCy.
*
* YaCy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* YaCy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YaCy. If not, see <http://www.gnu.org/licenses/>.
*/
DELETE_STRING="delete";
BAR_IMG1="env/grafics/green-block.png";
BAR_IMG2="env/grafics/red-block.png";
WORDCACHEBAR_LENGTH=1/4;
var statusRPC;
var refreshInterval=2;
var wait=0;
var changing=false; //change the interval
var statusLoaded=true;
/* Running crawls table DOM element */
var crawlsTable;
/* Size of the running crawls table header */
var crawlsHeadLength;
/* Running crawls legend DOM element */
var runningCrawlsLegend;
/* true when debug is enabled */
var debug;
function initCrawler(){
initCrawlProfiles();
refresh();
//loadInterval=window.setInterval("refresh()", refreshInterval*1000);
countInterval=window.setInterval("countdown()", 1000);
}
/**
* Init variables used to refresh the running crawls table
*/
function initCrawlProfiles() {
debug = document.getElementById("headerDebug") != null;
crawlsTable = document.getElementById("crawlProfiles");
if(crawlsTable != null && crawlsTable.rows != null) {
crawlsHeadLength = crawlsTable.tHead != null ? crawlsTable.tHead.rows.length : 0;
}
runningCrawlsLegend = document.getElementById("runningCrawlsLegend");
}
function changeInterval(){
if(!changing){
window.clearInterval(countInterval);
counter=document.getElementById("nextUpdate");
//counter.innerHTML='<input type="text" id="newInterval" onblur="newInterval()" size="2" />';
//document.getElementById("newInterval").focus();
counter.value=refreshInterval;
changing=true;
}
}
function newInterval(){
var newInterval=document.getElementById("nextUpdate").value;
// make sure that only positive intervals can be set
if(newInterval>0){
refreshInterval=newInterval;
}
refresh();
countInterval=window.setInterval("countdown()", 1000);
changing=false;
}
function countdown(){
if(statusLoaded){
wait--;
if (wait == 0) {
refresh();
}
}
}
function refresh(){
wait=refreshInterval;
statusLoaded=false;
requestStatus();
getRSS("api/feed.xml?count=20&set=REMOTEINDEXING,LOCALINDEXING&time=" + (new Date()).getTime());
}
function requestStatus(){
statusRPC=createRequestObject();
statusRPC.open('get', 'api/status_p.xml?html=');
statusRPC.onreadystatechange = handleStatus;
statusRPC.send(null);
}
function handleStatus(){
if(statusRPC.readyState != 4){
return;
}
var statusResponse = statusRPC.responseXML;
var statusTag = getFirstChild(statusResponse, "status");
var ppm = getValue(getFirstChild(statusTag, "ppm"));
var ppmNum = document.getElementById("ppmNum");
removeAllChildren(ppmNum);
ppmNum.appendChild(document.createTextNode(ppm));
// ppmBar start
var ppmBar = document.getElementById("ppmbar");
var ppmBarMaxRead = document.getElementById("customPPM");
var ppmforppmbar = ppm.replace(/\.*/g,"");
ppmBar.setAttribute("value", ppmforppmbar);
ppmBar.setAttribute("max", ppmBarMaxRead.value);
// ppmBar end
// traffic output (no bar up to now)
var traffic = getFirstChild(statusTag, "traffic");
var trafficCrawlerValue = getValue(getFirstChild(traffic, "crawler"));
var trafCrawlerSpan = document.getElementById("trafficCrawler");
removeAllChildren(trafCrawlerSpan);
trafCrawlerSpan.appendChild(document.createTextNode(Math.round((trafficCrawlerValue) / 1024 / 10.24) / 100));
var dbsize = getFirstChild(statusTag, "dbsize");
var urlpublictext = getValue(getFirstChild(dbsize, "urlpublictext"));
var urlpublictextSegmentCount = getValue(getFirstChild(dbsize, "urlpublictextSegmentCount"));
var webgraph = getValue(getFirstChild(dbsize, "webgraph"));
var webgraphSegmentCount = getValue(getFirstChild(dbsize, "webgraphSegmentCount"));
var citation = getValue(getFirstChild(dbsize, "citation"));
var citationSegmentCount = getValue(getFirstChild(dbsize, "citationSegmentCount"));
var rwipublictext = getValue(getFirstChild(dbsize, "rwipublictext"));
var rwipublictextSegmentCount = getValue(getFirstChild(dbsize, "rwipublictextSegmentCount"));
document.getElementById("urlpublictextSize").firstChild.nodeValue=urlpublictext;
document.getElementById("urlpublictextSegmentCount").firstChild.nodeValue=urlpublictextSegmentCount;
document.getElementById("webgraphSize").firstChild.nodeValue=webgraph;
document.getElementById("webgraphSegmentCount").firstChild.nodeValue=webgraphSegmentCount;
document.getElementById("citationSize").firstChild.nodeValue=citation;
document.getElementById("citationSegmentCount").firstChild.nodeValue=citationSegmentCount;
document.getElementById("rwipublictextSize").firstChild.nodeValue=rwipublictext;
document.getElementById("rwipublictextSegmentCount").firstChild.nodeValue=rwipublictextSegmentCount;
refreshRunningCrawls(statusTag);
var postprocessing = getFirstChild(statusTag, "postprocessing");
document.getElementById("postprocessing_status").firstChild.nodeValue=getValue(getFirstChild(postprocessing, "status"));
document.getElementById("postprocessing_collection").firstChild.nodeValue=getValue(getFirstChild(postprocessing, "collectionRemainingCount"));
document.getElementById("postprocessing_webgraph").firstChild.nodeValue=getValue(getFirstChild(postprocessing, "webgraphRemainingCount"));
document.getElementById("postprocessing_remainingTimeMinutes").firstChild.nodeValue=getValue(getFirstChild(postprocessing, "remainingTimeMinutes"));
document.getElementById("postprocessing_remainingTimeSeconds").firstChild.nodeValue=getValue(getFirstChild(postprocessing, "remainingTimeSeconds"));
var postprocessingElapsedTime = parseInt(getValue(getFirstChild(postprocessing, "ElapsedTime")));
var postprocessingRemainingTime = parseInt(getValue(getFirstChild(postprocessing, "RemainingTime")));
var p = 100 * postprocessingElapsedTime / (postprocessingElapsedTime + postprocessingRemainingTime) || 0;
document.getElementById("postprocessing_bar").firstChild.setAttribute("value", p);
//document.getElementById("postprocessing_speed").firstChild.nodeValue=getValue(getFirstChild(postprocessing, "speed"));
var load = getFirstChild(statusTag, "load");
document.getElementById("load").firstChild.nodeValue=getValue(load);
var loaderqueue = getFirstChild(statusTag, "loaderqueue");
var loaderqueue_size = getValue(getFirstChild(loaderqueue, "size"));
var loaderqueue_max = getValue(getFirstChild(loaderqueue, "max"));
document.getElementById("loaderqueuesize").firstChild.nodeValue=loaderqueue_size;
document.getElementById("loaderqueuemax").firstChild.nodeValue=loaderqueue_max;
var localcrawlerqueue = getFirstChild(statusTag, "localcrawlerqueue");
var localcrawlerqueue_size = getValue(getFirstChild(localcrawlerqueue, "size"));
var localcrawlerqueue_state = getValue(getFirstChild(localcrawlerqueue, "state"));
document.getElementById("localcrawlerqueuesize").firstChild.nodeValue=localcrawlerqueue_size;
putQueueState("localcrawler", localcrawlerqueue_state);
var limitcrawlerqueue = getFirstChild(statusTag, "limitcrawlerqueue");
var limitcrawlerqueue_size = getValue(getFirstChild(limitcrawlerqueue, "size"));
var limitcrawlerqueue_state = getValue(getFirstChild(limitcrawlerqueue, "state"));
document.getElementById("limitcrawlerqueuesize").firstChild.nodeValue=limitcrawlerqueue_size;
putQueueState("limitcrawler", limitcrawlerqueue_state);
var remotecrawlerqueue = getFirstChild(statusTag, "remotecrawlerqueue");
var remotecrawlerqueue_size = getValue(getFirstChild(remotecrawlerqueue, "size"));
var remotecrawlerqueue_state = getValue(getFirstChild(remotecrawlerqueue, "state"));
document.getElementById("remotecrawlerqueuesize").firstChild.nodeValue=remotecrawlerqueue_size;
putQueueState("remotecrawler", remotecrawlerqueue_state);
var noloadcrawlerqueue = getFirstChild(statusTag, "noloadcrawlerqueue");
var noloadcrawlerqueue_size = getValue(getFirstChild(noloadcrawlerqueue, "size"));
var noloadcrawlerqueue_state = getValue(getFirstChild(noloadcrawlerqueue, "state"));
document.getElementById("noloadcrawlerqueuesize").firstChild.nodeValue=noloadcrawlerqueue_size;
putQueueState("noloadcrawler", noloadcrawlerqueue_state);
statusLoaded=true;
}
/**
* Insert a new crawl line to the end of the running crawls table
* @param table crawls table HTML DOM node
* @param crawl crawl profile node from status_p.xml
* @param handle {String} identifier of the running crawl profile
* @param status {String} running status of the crawl profile
*/
function insertCrawlRaw(table, crawl, handle, status) {
/* Insert a row in the table at the end */
var newRow = table.insertRow();
newRow.className = ((table.rows.length - crawlsHeadLength) % 2) == 0 ? "TableCellLight" : "TableCellDark";
newRow.id = handle;
/* Insert name cell */
var newCell = newRow.insertCell();
var newText = document.createTextNode(getValue(getFirstChild(crawl, "name")));
newCell.appendChild(newText);
if(debug) {
/* Insert count cell when debug is enabled */
newCell = newRow.insertCell();
newCell.textContent = getValue(getFirstChild(crawl, "count"));
}
/* Insert status cell */
newCell = newRow.insertCell();
newCell.id = handle + "_status_cell";
if(status == "alive") {
var newDiv = document.createElement("div");
newDiv.id = handle + "_status";
newDiv.style = "text-decoration:blink;float:left;";
newText = document.createTextNode("Running");
newDiv.appendChild(newText);
newCell.appendChild(newDiv);
var newForm = document.createElement("form");
newForm.id = handle + "_terminate";
newForm.style = "float:left;";
newForm.action = "Crawler_p.html";
newForm.method = "get";
newForm.enctype="multipart/form-data";
newForm["accept-charset"]="UTF-8";
newDiv = document.createElement("div");
var newInput = document.createElement("input");
newInput.type = "hidden";
newInput.name = "handle";
newInput.value = handle;
newDiv.appendChild(newInput);
newInput = document.createElement("input");
newInput.type = "submit";
newInput.name = "terminate";
newInput.value = "Terminate";
newInput.className = "btn btn-danger btn-xs";
newDiv.appendChild(newInput);
newForm.appendChild(newDiv);
newCell.appendChild(newForm);
}
}
/**
* Refresh status cell text and terminate button presence
* @param handle name of the crawl
* @param status current crawl status label
*/
function refreshStatusCell(handle, status) {
var handleStatus = document.getElementById(handle + "_status");
if(handleStatus != null) {
handleStatus.textContent = status;
}
var terminateForm = document.getElementById(handle + "_terminate");
if(terminateForm != null && terminateForm.parentElement) {
terminateForm.parentElement.removeChild(terminateForm);
}
}
/**
* Refresh the count in running crawls legend
* @param legend the HTML DOM legend element
* @param crawls crawls node from xml api status_p.xml
*/
function refreshCrawlsLegend(legend, crawls) {
var count = crawls.getAttribute("count");
if(count && legend != null) {
legend.textContent = "Running Crawls (" + count + ")";
}
}
/**
* Refresh dark/light rows style
* @param table running crawls table
*/
function refreshRowsStyle(table, headLength) {
for(var i = headLength; i < table.rows.length; i++) {
raw = table.rows[i];
raw.className = ((i - headLength) % 2) == 0 ? "TableCellLight" : "TableCellDark";
}
}
/**
* Refresh running crawls table
*
* @param statusTag
* status tag from xml api status_p.xml
*/
function refreshRunningCrawls(statusTag) {
var crawls = getFirstChild(statusTag, "crawls");
/* crawls node should be present even when no crawl is running */
if(crawls != null) {
/* Update the table when present */
if(crawlsTable != null && crawlsTable.rows != null) {
var processedHandles = {}, crawlNode = getFirstChild(crawls, "crawl");
if(crawlNode) {
var handle, rowIndex, handleCell;
/* Loop on crawl node elements from xml */
for(; crawlNode; crawlNode = getNextSibling(crawlNode, "crawl")) {
handle = getValue(getFirstChild(crawlNode, "handle"));
if(handle != null) {
processedHandles[handle] = crawlNode;
status = getValue(getFirstChild(crawlNode, "status"));
/* Let's try to get the crawls table cell with id prefixed by this handle */
handleCell = document.getElementById(handle + "_status_cell");
if(handleCell == null) {
insertCrawlRaw(crawlsTable, crawlNode, handle, status);
refreshCrawlsLegend(runningCrawlsLegend, crawls);
refreshRowsStyle(crawlsTable, crawlsHeadLength);
} else if(status != "alive"){
refreshStatusCell(handle, status);
}
}
}
}
/* Collect raws to delete */
var raw, rawsToDelete = [];
for(var i = crawlsHeadLength; i < crawlsTable.rows.length; i++) {
raw = crawlsTable.rows[i];
if(processedHandles[raw.id] == null) {
rawsToDelete.push(raw);
}
}
/* Delete raws */
for(var i = 0; i < rawsToDelete.length; i++) {
raw = rawsToDelete[i];
raw.parentElement.removeChild(raw);
}
/* Refresh legend and rows style (dark/light alternate) */
if(rawsToDelete.length > 0) {
refreshCrawlsLegend(runningCrawlsLegend, crawls);
refreshRowsStyle(crawlsTable, crawlsHeadLength);
}
}
}
}
function putQueueState(queue, state) {
a = document.getElementById(queue + "stateA");
img = document.getElementById(queue + "stateIMG");
if (state == "paused") {
a.href = "Crawler_p.html?continue=" + queue;
a.title = "Continue this queue (" + state + ")";
img.src = "env/grafics/start.gif";
img.alt = "Continue this queue";
} else {
a.href = "Crawler_p.html?pause=" + queue;
a.title = "Pause this queue (" + state + ")";
img.src = "env/grafics/pause.gif";
img.alt = "Pause this queue";
}
}
function shortenURL(url) {
if (url.length > 80) {
return url.substr(0, 80) + "...";
} else {
return url;
}
}
function createIndexingRow(queue, profile, initiator, depth, modified, anchor, url, size, deletebutton){
row=document.createElement("tr");
row.setAttribute("height", 10);
row.appendChild(createCol(queue));
row.appendChild(createCol(profile));
row.appendChild(createCol(initiator));
row.appendChild(createCol(depth));
row.appendChild(createCol(modified));
row.appendChild(createCol(anchor));
row.appendChild(createLinkCol(url, shortenURL(url)));
row.appendChild(createCol(size));
row.appendChild(deletebutton);
return row;
}
crawllist_head = "<table cellpadding='2' cellspacing='1' ><tr class='TableHeader'><td width='50%'><strong>Title</strong></td><td width='50%'><strong>URL</strong></td></tr>";
crawllist_body = "";
crawllist_tail = "</table>";
function showRSS(RSS) {
var doc = document.getElementById("crawllist");
if (doc != null) {
if (crawllist_body.length > 100000) crawllist_body = "";
for (var i=0; i<RSS.items.length; i++) {
crawllist_body = "<tr class='TableCellLight'><td><a href='ViewFile.html?action=info&urlHash=" + RSS.items[i].guid.value + "' class='small' target='_blank' title='" + RSS.items[i].link + "'>" + RSS.items[i].description + "</a></td><td><a href='" + RSS.items[i].link + "' class='small' target='_blank' title='" + RSS.items[i].link + "'>" + RSS.items[i].link + "</a></td></tr>" + crawllist_body;
}
doc.innerHTML = crawllist_head + crawllist_body + crawllist_tail;
}
return true;
}
|