mirror of
https://github.com/yacy/yacy_search_server.git
synced 2025-07-22 09:14:38 -04:00
Servlet IndexBroser_p add button "Add to blacklist"
allows to add the displayed host to add to the default blacklist
This commit is contained in:
htroot
source/net/yacy/repository
@ -240,7 +240,7 @@ public class Blacklist_p {
|
||||
WorkTables.TABLE_API_TYPE_CONFIGURATION,
|
||||
"add to blacklist '" + blacklistToUse + "': " + blentry);
|
||||
|
||||
if(!BlacklistHelper.addBlacklistEntry(blacklistToUse, blentry, header)) {
|
||||
if(!BlacklistHelper.addBlacklistEntry(blacklistToUse, blentry)) {
|
||||
prop.put(DISABLED + EDIT + "addError", true);
|
||||
prop.put(DISABLED + EDIT + "addError_entry", blentry);
|
||||
}
|
||||
@ -281,7 +281,7 @@ public class Blacklist_p {
|
||||
return prop;
|
||||
}
|
||||
|
||||
if (!BlacklistHelper.addBlacklistEntry(targetBlacklist, selectedBlacklistEntry, header)) {
|
||||
if (!BlacklistHelper.addBlacklistEntry(targetBlacklist, selectedBlacklistEntry)) {
|
||||
prop.put(DISABLED + EDIT + "moveError", true);
|
||||
break;
|
||||
}
|
||||
@ -322,7 +322,7 @@ public class Blacklist_p {
|
||||
if (!normalizeEntry(selectedEntry.getValue()).equals(preparedNewEntry)) {
|
||||
|
||||
/* Add first, to detect any eventual syntax errors before removing the old entry */
|
||||
if (!BlacklistHelper.addBlacklistEntry(blacklistToUse, editedEntryValue, header)) {
|
||||
if (!BlacklistHelper.addBlacklistEntry(blacklistToUse, editedEntryValue)) {
|
||||
selected2EditedErrors.put(selectedEntry.getValue(), editedEntryValue);
|
||||
} else if ((temp = BlacklistHelper.deleteBlacklistEntry(blacklistToUse, selectedEntry.getValue(), header)) != null) {
|
||||
prop.put(serverObjects.ACTION_LOCATION, temp);
|
||||
|
@ -166,9 +166,17 @@ var solr= $.getJSON("solr/collection1/select?q=*:*&start=0&rows=0&wt=json&facet=
|
||||
#(/hostanalysis)#
|
||||
|
||||
#(files)#::
|
||||
<fieldset><legend>Browser for <a href="#[path]#" target="_blank">#[path]#</a></legend>
|
||||
<p>documents stored for host: #[hostsize]#; documents stored for subpath: #[subpathloadsize]#; unloaded documents detected in subpath: #[subpathdetectedsize]# <!-- #(complete)#;<a href="IndexBrowser_p.html?complete=true&path=#[path]#">get complete list</a>::<a href="IndexBrowser_p.html?path=#[path]#">directory view</a>#(/complete)#-->
|
||||
</p>
|
||||
<fieldset>
|
||||
<legend style="display: inline">Browser for <a href="#[path]#" target="_blank">#[path]#</a>
|
||||
<span style="padding-left: 25px">
|
||||
<form style="display: inline" action="IndexBrowser_p.html?path=#[path]#" id="searchform" method="get" role="search">
|
||||
<button type="submit" name="addtoblacklist" class="btn btn-xs btn-default">Add to blacklist</button>
|
||||
<input type="text" name="path" value="#[path]#" hidden="true"/>
|
||||
</form>
|
||||
</span>
|
||||
</legend>
|
||||
<p>documents stored for host: #[hostsize]#; documents stored for subpath: #[subpathloadsize]#; unloaded documents detected in subpath: #[subpathdetectedsize]# <!-- #(complete)#;<a href="IndexBrowser_p.html?complete=true&path=#[path]#">get complete list</a>::<a href="IndexBrowser_p.html?path=#[path]#">directory view</a>#(/complete)#-->
|
||||
</p>
|
||||
<table class="sortable" style="float:left; border-width: 0">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -18,6 +18,7 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
@ -58,6 +59,8 @@ import net.yacy.crawler.data.NoticedURL.StackType;
|
||||
import net.yacy.crawler.retrieval.Request;
|
||||
import net.yacy.kelondro.data.meta.URIMetadataNode;
|
||||
import net.yacy.peers.graphics.WebStructureGraph.StructureEntry;
|
||||
import net.yacy.repository.Blacklist;
|
||||
import static net.yacy.repository.BlacklistHelper.addBlacklistEntry;
|
||||
import net.yacy.search.Switchboard;
|
||||
import net.yacy.search.SwitchboardConstants;
|
||||
import net.yacy.search.index.Fulltext;
|
||||
@ -653,6 +656,17 @@ public class IndexBrowser_p {
|
||||
} catch (final Throwable e) {
|
||||
ConcurrentLog.logException(e);
|
||||
}
|
||||
|
||||
// for addtoblacklist button
|
||||
if (post.containsKey("addtoblacklist") && sb != null) {
|
||||
final File blacklistsPath = sb.getDataPath(SwitchboardConstants.LISTS_PATH, SwitchboardConstants.LISTS_PATH_DEFAULT);
|
||||
String blacklistname = Blacklist.defaultBlacklist(blacklistsPath);
|
||||
if (blacklistname != null) {
|
||||
addBlacklistEntry(
|
||||
blacklistname,
|
||||
"*." + pathURI.getHost());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return rewrite properties
|
||||
|
@ -31,7 +31,7 @@ public class add_entry_p {
|
||||
WorkTables.TABLE_API_TYPE_CONFIGURATION,
|
||||
"add to blacklist '" + blacklistToUse + "': " + entry);
|
||||
|
||||
if (BlacklistHelper.addBlacklistEntry(blacklistToUse, entry, header)) {
|
||||
if (BlacklistHelper.addBlacklistEntry(blacklistToUse, entry)) {
|
||||
prop.put(XML_ITEM_STATUS, RESULT_SUCCESS);
|
||||
|
||||
Switchboard.urlBlacklist.clear();
|
||||
|
@ -789,11 +789,24 @@ public class Blacklist {
|
||||
return BlacklistError.NO_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default blacklist name default is the first name which
|
||||
* contains ".default." (standard default list name is 'url.default.black')
|
||||
* or if no the first blacklist if no name containing ".default." exists.
|
||||
*
|
||||
* @param listsPath directory containig the blacklists
|
||||
* @return String blacklist name
|
||||
*/
|
||||
public static String defaultBlacklist(final File listsPath) {
|
||||
final List<String> dirlist = FileUtils.getDirListing(listsPath, Blacklist.BLACKLIST_FILENAME_FILTER);
|
||||
if (dirlist.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
for (String name : dirlist) {
|
||||
if (name.contains(".default.")) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return dirlist.get(0);
|
||||
}
|
||||
|
||||
|
@ -58,18 +58,16 @@ public final class BlacklistHelper {
|
||||
* Adds a new entry to the chosen blacklist.
|
||||
* @param blacklistToUse the name of the blacklist the entry is to be added to
|
||||
* @param entry the entry that is to be added
|
||||
* @param header the current HTTP request headers
|
||||
* @return true when no error occurred and the entry was successfully added
|
||||
*/
|
||||
public static boolean addBlacklistEntry(
|
||||
final String blacklistToUse,
|
||||
final String entry,
|
||||
final RequestHeader header) {
|
||||
String newEntry = entry;
|
||||
public static boolean addBlacklistEntry(
|
||||
final String blacklistToUse,
|
||||
final String entry) {
|
||||
String newEntry = entry;
|
||||
|
||||
if (blacklistToUse == null || blacklistToUse.isEmpty() || newEntry == null || newEntry.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (blacklistToUse == null || blacklistToUse.isEmpty() || newEntry == null || newEntry.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
newEntry = prepareEntry(newEntry);
|
||||
|
||||
@ -77,7 +75,7 @@ public final class BlacklistHelper {
|
||||
String host = newEntry.substring(0, pos);
|
||||
String path = newEntry.substring(pos + 1);
|
||||
|
||||
boolean success = false;
|
||||
boolean success = false;
|
||||
for (final BlacklistType supportedBlacklistType : BlacklistType.values()) {
|
||||
if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklistToUse)) {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user