Servlet IndexBroser_p add button "Add to blacklist"

allows to add the displayed host to add to the default blacklist
pull/461/head
reger24 3 years ago
parent 7ca7495b19
commit 6a5f0b3684

@ -240,7 +240,7 @@ public class Blacklist_p {
WorkTables.TABLE_API_TYPE_CONFIGURATION, WorkTables.TABLE_API_TYPE_CONFIGURATION,
"add to blacklist '" + blacklistToUse + "': " + blentry); "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", true);
prop.put(DISABLED + EDIT + "addError_entry", blentry); prop.put(DISABLED + EDIT + "addError_entry", blentry);
} }
@ -281,7 +281,7 @@ public class Blacklist_p {
return prop; return prop;
} }
if (!BlacklistHelper.addBlacklistEntry(targetBlacklist, selectedBlacklistEntry, header)) { if (!BlacklistHelper.addBlacklistEntry(targetBlacklist, selectedBlacklistEntry)) {
prop.put(DISABLED + EDIT + "moveError", true); prop.put(DISABLED + EDIT + "moveError", true);
break; break;
} }
@ -322,7 +322,7 @@ public class Blacklist_p {
if (!normalizeEntry(selectedEntry.getValue()).equals(preparedNewEntry)) { if (!normalizeEntry(selectedEntry.getValue()).equals(preparedNewEntry)) {
/* Add first, to detect any eventual syntax errors before removing the old entry */ /* 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); selected2EditedErrors.put(selectedEntry.getValue(), editedEntryValue);
} else if ((temp = BlacklistHelper.deleteBlacklistEntry(blacklistToUse, selectedEntry.getValue(), header)) != null) { } else if ((temp = BlacklistHelper.deleteBlacklistEntry(blacklistToUse, selectedEntry.getValue(), header)) != null) {
prop.put(serverObjects.ACTION_LOCATION, temp); 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)# #(/hostanalysis)#
#(files)#:: #(files)#::
<fieldset><legend>Browser for <a href="#[path]#" target="_blank">#[path]#</a></legend> <fieldset>
<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)#--> <legend style="display: inline">Browser for <a href="#[path]#" target="_blank">#[path]#</a>
</p> <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"> <table class="sortable" style="float:left; border-width: 0">
<thead> <thead>
<tr> <tr>

@ -18,6 +18,7 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -58,6 +59,8 @@ import net.yacy.crawler.data.NoticedURL.StackType;
import net.yacy.crawler.retrieval.Request; import net.yacy.crawler.retrieval.Request;
import net.yacy.kelondro.data.meta.URIMetadataNode; import net.yacy.kelondro.data.meta.URIMetadataNode;
import net.yacy.peers.graphics.WebStructureGraph.StructureEntry; 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.Switchboard;
import net.yacy.search.SwitchboardConstants; import net.yacy.search.SwitchboardConstants;
import net.yacy.search.index.Fulltext; import net.yacy.search.index.Fulltext;
@ -653,6 +656,17 @@ public class IndexBrowser_p {
} catch (final Throwable e) { } catch (final Throwable e) {
ConcurrentLog.logException(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 // return rewrite properties

@ -31,7 +31,7 @@ public class add_entry_p {
WorkTables.TABLE_API_TYPE_CONFIGURATION, WorkTables.TABLE_API_TYPE_CONFIGURATION,
"add to blacklist '" + blacklistToUse + "': " + entry); "add to blacklist '" + blacklistToUse + "': " + entry);
if (BlacklistHelper.addBlacklistEntry(blacklistToUse, entry, header)) { if (BlacklistHelper.addBlacklistEntry(blacklistToUse, entry)) {
prop.put(XML_ITEM_STATUS, RESULT_SUCCESS); prop.put(XML_ITEM_STATUS, RESULT_SUCCESS);
Switchboard.urlBlacklist.clear(); Switchboard.urlBlacklist.clear();

@ -789,11 +789,24 @@ public class Blacklist {
return BlacklistError.NO_ERROR; 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) { public static String defaultBlacklist(final File listsPath) {
final List<String> dirlist = FileUtils.getDirListing(listsPath, Blacklist.BLACKLIST_FILENAME_FILTER); final List<String> dirlist = FileUtils.getDirListing(listsPath, Blacklist.BLACKLIST_FILENAME_FILTER);
if (dirlist.isEmpty()) { if (dirlist.isEmpty()) {
return null; return null;
} }
for (String name : dirlist) {
if (name.contains(".default.")) {
return name;
}
}
return dirlist.get(0); return dirlist.get(0);
} }

@ -58,18 +58,16 @@ public final class BlacklistHelper {
* Adds a new entry to the chosen blacklist. * Adds a new entry to the chosen blacklist.
* @param blacklistToUse the name of the blacklist the entry is to be added to * @param blacklistToUse the name of the blacklist the entry is to be added to
* @param entry the entry that is to be added * @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 * @return true when no error occurred and the entry was successfully added
*/ */
public static boolean addBlacklistEntry( public static boolean addBlacklistEntry(
final String blacklistToUse, final String blacklistToUse,
final String entry, final String entry) {
final RequestHeader header) { String newEntry = entry;
String newEntry = entry;
if (blacklistToUse == null || blacklistToUse.isEmpty() || newEntry == null || newEntry.isEmpty()) { if (blacklistToUse == null || blacklistToUse.isEmpty() || newEntry == null || newEntry.isEmpty()) {
return false; return false;
} }
newEntry = prepareEntry(newEntry); newEntry = prepareEntry(newEntry);
@ -77,7 +75,7 @@ public final class BlacklistHelper {
String host = newEntry.substring(0, pos); String host = newEntry.substring(0, pos);
String path = newEntry.substring(pos + 1); String path = newEntry.substring(pos + 1);
boolean success = false; boolean success = false;
for (final BlacklistType supportedBlacklistType : BlacklistType.values()) { for (final BlacklistType supportedBlacklistType : BlacklistType.values()) {
if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklistToUse)) { if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklistToUse)) {
try { try {

Loading…
Cancel
Save