/
CrawlResults.java
309 lines (273 loc) · 14.9 KB
/
CrawlResults.java
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
// CrawlResults.java
// (C) 2005 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 09.03.2005 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// LICENSE
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import net.yacy.cora.document.ASCII;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.federate.solr.YaCySchema;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.crawler.data.ResultURLs;
import net.yacy.crawler.data.ResultURLs.EventOrigin;
import net.yacy.crawler.data.ResultURLs.InitExecEntry;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataNode;
import net.yacy.kelondro.logging.Log;
import net.yacy.peers.Seed;
import net.yacy.search.Switchboard;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
import net.yacy.utils.nxTools;
public class CrawlResults {
public static serverObjects respond(final RequestHeader header, serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
int lines = 500;
boolean showCollection = sb.index.fulltext().getSolrSchema().isEmpty() || sb.index.fulltext().getSolrSchema().contains(YaCySchema.collection_sxt);
boolean showInit = env.getConfigBool("IndexMonitorInit", false);
boolean showExec = env.getConfigBool("IndexMonitorExec", false);
boolean showDate = env.getConfigBool("IndexMonitorDate", true);
boolean showWords = env.getConfigBool("IndexMonitorWords", true);
boolean showTitle = env.getConfigBool("IndexMonitorTitle", true);
boolean showCountry = env.getConfigBool("IndexMonitorCountry", false);
boolean showIP = env.getConfigBool("IndexMonitorIP", false);
boolean showURL = env.getConfigBool("IndexMonitorURL", true);
if (post == null) {
post = new serverObjects();
post.put("process", "0");
}
// find process number
EventOrigin tabletype;
try {
tabletype = EventOrigin.getEvent(post.getInt("process", 0));
} catch (final NumberFormatException e) {
tabletype = EventOrigin.UNKNOWN;
}
if (
post != null &&
post.containsKey("autoforward") &&
tabletype == EventOrigin.LOCAL_CRAWLING &&
ResultURLs.getStackSize(EventOrigin.LOCAL_CRAWLING) == 0) {
// the main menu does a request to the local crawler page, but in case this table is empty, the overview page is shown
tabletype = (ResultURLs.getStackSize(EventOrigin.SURROGATES) == 0) ? EventOrigin.UNKNOWN : EventOrigin.SURROGATES;
}
// check if authorization is needed and/or given
if (tabletype != EventOrigin.UNKNOWN ||
(post != null && (post.containsKey("clearlist") ||
post.containsKey("deleteentry")))) {
final String authorization = (header.get(RequestHeader.AUTHORIZATION, "xxxxxx"));
if (authorization.length() != 0) {
if (! sb.verifyAuthentication(header)){
// force log-in (again, because wrong password was given)
prop.authenticationRequired();
return prop;
}
} else {
// force log-in
prop.authenticationRequired();
return prop;
}
}
if (post != null) {
// custom number of lines
if (post.containsKey("count")) {
lines = post.getInt("count", 500);
}
// do the commands
if (post.containsKey("clearlist")) ResultURLs.clearStack(tabletype);
if (post.containsKey("deleteentry")) {
final String hash = post.get("hash", null);
if (hash != null) {
// delete from database
sb.index.fulltext().remove(hash.getBytes());
}
}
if (post.containsKey("deletedomain")) {
final String domain = post.get("domain", null);
if (domain != null) {
sb.index.fulltext().deleteDomainHostname(domain, null, false);
ResultURLs.deleteDomain(tabletype, domain);
}
}
if (post.containsKey("moreIndexed")) {
lines = post.getInt("showIndexed", 500);
}
if (post.get("si") != null) showInit = !("0".equals(post.get("si")));
if (post.get("se") != null) showExec = !("0".equals(post.get("se")));
if (post.get("sd") != null) showDate = !("0".equals(post.get("sd")));
if (post.get("sw") != null) showWords = !("0".equals(post.get("sw")));
if (post.get("st") != null) showTitle = !("0".equals(post.get("st")));
if (post.get("sc") != null) showCountry = !("0".equals(post.get("sc")));
if (post.get("sp") != null) showIP = !("0".equals(post.get("sp")));
if (post.get("su") != null) showURL = !("0".equals(post.get("su")));
} // end != null
// create table
if (tabletype == EventOrigin.UNKNOWN) {
prop.put("table", "2");
} else if (ResultURLs.getStackSize(tabletype) == 0 && ResultURLs.getDomainListSize(tabletype) == 0) {
prop.put("table", "0");
} else {
prop.put("table", "1");
if (lines > ResultURLs.getStackSize(tabletype)) lines = ResultURLs.getStackSize(tabletype);
if (lines == ResultURLs.getStackSize(tabletype)) {
prop.put("table_size", "0");
} else {
prop.put("table_size", "1");
prop.put("table_size_count", lines);
}
prop.put("table_size_all", ResultURLs.getStackSize(tabletype));
prop.putHTML("table_feedbackpage", "CrawlResults.html");
prop.put("table_tabletype", tabletype.getCode());
prop.put("table_showCollection", (showCollection) ? "1" : "0");
prop.put("table_showInit", (showInit) ? "1" : "0");
prop.put("table_showExec", (showExec) ? "1" : "0");
prop.put("table_showDate", (showDate) ? "1" : "0");
prop.put("table_showWords", (showWords) ? "1" : "0");
prop.put("table_showTitle", (showTitle) ? "1" : "0");
prop.put("table_showCountry", (showCountry) ? "1" : "0");
prop.put("table_showIP", (showIP) ? "1" : "0");
prop.put("table_showURL", (showURL) ? "1" : "0");
boolean dark = true;
String urlstr, urltxt;
Seed initiatorSeed, executorSeed;
URIMetadataNode urle;
int cnt = 0;
final Iterator<Map.Entry<String, InitExecEntry>> i = ResultURLs.results(tabletype);
Map.Entry<String, InitExecEntry> entry;
while (i.hasNext()) {
entry = i.next();
try {
urle = sb.index.fulltext().getMetadata(UTF8.getBytes(entry.getKey()));
if (urle == null) {
Log.logWarning("PLASMA", "CrawlResults: URL not in index with url hash " + entry.getKey());
urlstr = null;
urltxt = null;
continue;
}
urlstr = urle.url().toNormalform(true);
urltxt = nxTools.shortenURLString(urlstr, 72); // shorten the string text like a URL
initiatorSeed = entry.getValue() == null || entry.getValue().initiatorHash == null ? null : sb.peers.getConnected(ASCII.String(entry.getValue().initiatorHash));
executorSeed = entry.getValue() == null || entry.getValue().executorHash == null ? null : sb.peers.getConnected(ASCII.String(entry.getValue().executorHash));
prop.put("table_indexed_" + cnt + "_dark", (dark) ? "1" : "0");
prop.put("table_indexed_" + cnt + "_feedbackpage", "CrawlResults.html");
prop.put("table_indexed_" + cnt + "_tabletype", tabletype.getCode());
prop.put("table_indexed_" + cnt + "_urlhash", entry.getKey());
if (showCollection) {
prop.put("table_indexed_" + cnt + "_showCollection", "1");
prop.put("table_indexed_" + cnt + "_showCollection_collection", Arrays.toString(urle.collections()));
} else
prop.put("table_indexed_" + cnt + "_showCollection", "0");
if (showInit) {
prop.put("table_indexed_" + cnt + "_showInit", "1");
prop.put("table_indexed_" + cnt + "_showInit_initiatorSeed", (initiatorSeed == null) ? "unknown" : initiatorSeed.getName());
} else
prop.put("table_indexed_" + cnt + "_showInit", "0");
if (showExec) {
prop.put("table_indexed_" + cnt + "_showExec", "1");
prop.put("table_indexed_" + cnt + "_showExec_executorSeed", (executorSeed == null) ? "unknown" : executorSeed.getName());
} else
prop.put("table_indexed_" + cnt + "_showExec", "0");
if (showDate && urle != null) {
prop.put("table_indexed_" + cnt + "_showDate", "1");
prop.put("table_indexed_" + cnt + "_showDate_modified", daydate(urle.moddate()));
} else
prop.put("table_indexed_" + cnt + "_showDate", "0");
if (showWords && urle != null) {
prop.put("table_indexed_" + cnt + "_showWords", "1");
prop.put("table_indexed_" + cnt + "_showWords_count", urle.wordCount());
} else
prop.put("table_indexed_" + cnt + "_showWords", "0");
if (showTitle) {
prop.put("table_indexed_" + cnt + "_showTitle", (showTitle) ? "1" : "0");
prop.put("table_indexed_" + cnt + "_showTitle_available", "1");
if (urle.dc_title() == null || urle.dc_title().trim().isEmpty())
prop.put("table_indexed_" + cnt + "_showTitle_available_nodescr", "0");
else {
prop.put("table_indexed_" + cnt + "_showTitle_available_nodescr", "1");
prop.putHTML("table_indexed_" + cnt + "_showTitle_available_nodescr_urldescr", urle.dc_title());
}
prop.put("table_indexed_" + cnt + "_showTitle_available_urlHash", entry.getKey());
prop.putHTML("table_indexed_" + cnt + "_showTitle_available_urltitle", urlstr);
} else
prop.put("table_indexed_" + cnt + "_showTitle", "0");
if (showCountry && urle != null) {
prop.put("table_indexed_" + cnt + "_showCountry", "1");
prop.put("table_indexed_" + cnt + "_showCountry_country", urle.url().getLocale().getCountry());
} else
prop.put("table_indexed_" + cnt + "_showCountry", "0");
if (showIP && urle != null) {
prop.put("table_indexed_" + cnt + "_showIP", "1");
prop.put("table_indexed_" + cnt + "_showIP_ip", urle.url().getHost() == null ? "" : urle.url().getInetAddress().getHostAddress());
} else
prop.put("table_indexed_" + cnt + "_showIP", "0");
if (showURL) {
prop.put("table_indexed_" + cnt + "_showURL", "1");
prop.put("table_indexed_" + cnt + "_showURL_available", "1");
prop.put("table_indexed_" + cnt + "_showURL_available_urlHash", entry.getKey());
prop.putHTML("table_indexed_" + cnt + "_showURL_available_urltitle", urlstr);
prop.put("table_indexed_" + cnt + "_showURL_available_url", urltxt);
} else
prop.put("table_indexed_" + cnt + "_showURL", "0");
dark = !dark;
cnt++;
} catch (final Exception e) {
Log.logSevere("PLASMA", "genTableProps", e);
}
}
prop.put("table_indexed", cnt);
cnt = 0;
dark = true;
final Iterator<String> j = ResultURLs.domains(tabletype);
String domain;
while (j.hasNext() && cnt < 100) {
domain = j.next();
if (domain == null) break;
prop.put("table_domains_" + cnt + "_dark", (dark) ? "1" : "0");
prop.put("table_domains_" + cnt + "_feedbackpage", "CrawlResults.html");
prop.put("table_domains_" + cnt + "_tabletype", tabletype.getCode());
prop.put("table_domains_" + cnt + "_domain", domain);
prop.put("table_domains_" + cnt + "_count", ResultURLs.domainCount(tabletype, domain));
dark = !dark;
cnt++;
}
prop.put("table_domains", cnt);
}
prop.put("process", tabletype.getCode());
// return rewrite properties
return prop;
}
private static SimpleDateFormat dayFormatter = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
private static String daydate(final Date date) {
if (date == null) {
return "";
}
return dayFormatter.format(date);
}
}