Add option to add host to default blacklist from search result

- added authorized ikon/button to blacklist a host
- host is added to default blacklist
- insired by https://github.com/yacy/yacy_search_server/issues/213#issuecomment-412485190
pull/461/head
reger24 3 years ago
parent 05d6d0405f
commit a7e93d9328

@ -594,6 +594,10 @@ a.deletelink:hover, a.deletelink:focus, div.searchresults:hover a.deletelink, di
background:url(grafics/minus.gif) center center no-repeat;
}
a.blacklistlink:hover, a.blacklistlink:focus, div.searchresults:hover a.blacklistlink, div.searchresults.hover a.blacklistlink {
background:url(grafics/blkl.gif) center center no-repeat;
}
ul.SubMenu a.MenuItemLink {
margin-top:0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

@ -30,6 +30,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.IDN;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -77,6 +78,8 @@ import net.yacy.kelondro.util.SetTools;
import net.yacy.peers.EventChannel;
import net.yacy.peers.NewsPool;
import net.yacy.peers.graphics.ProfilingGraph;
import net.yacy.repository.Blacklist;
import static net.yacy.repository.BlacklistHelper.addBlacklistEntry;
import net.yacy.search.EventTracker;
import net.yacy.search.SearchAccessRateConstants;
import net.yacy.search.Switchboard;
@ -93,6 +96,7 @@ import net.yacy.search.ranking.RankingProfile;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
import net.yacy.server.servletProperties;
import net.yacy.utils.crypt;
public class yacysearch {
@ -697,6 +701,24 @@ public class yacysearch {
}
}
// if a blacklist-button was hit, add host to default blacklist
if (post != null && post.containsKey("blacklisturl")) {
if (!sb.verifyAuthentication(header)) {
prop.authenticationRequired();
return prop;
}
String blacklisturl = crypt.simpleDecode(post.get("blacklisturl", "")); // url
try {
MultiProtocolURL mpurl = new MultiProtocolURL(blacklisturl);
addBlacklistEntry(
Blacklist.defaultBlacklist(sb.listsPath),
mpurl.getHost() + "/.*");
} catch (MalformedURLException e) {
}
}
// check filters
try {
Pattern.compile(urlmask);

@ -21,6 +21,9 @@
<a href="#[recommendlink]#" class="recommendlink" title="recommend"><img width="11" height="11" src="env/grafics/empty.gif" title="recommend" alt="recommend" class="recommendIcon" /></a>
<a href="#[deletelink]#" title="delete" class="deletelink" ><img width="11" height="11" src="env/grafics/empty.gif" title="delete" alt="delete" class="deleteIcon" /></a>
#(/recommend)#
#(blacklist)#::
<a href="#[blacklistlink]#" title="blacklist host" class="blacklistlink"><img width="11" height="11" src="env/grafics/empty.gif" title="blacklist host" alt="blacklist host" /></a>
#(/blacklist)#
#(/authorized)#
</div>
<p class="url"><a href="#[link]#" id="url#[urlhash]#" target="#[target]#" #(noreferrer)#::rel="noreferrer"#(/noreferrer)#>#[urlname]#</a></p>

@ -105,8 +105,8 @@ public class yacysearchitem {
final String eventID = post.get("eventID", "");
final boolean adminAuthenticated = sb.verifyAuthentication(header);
final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null;
final boolean authenticated = adminAuthenticated || user != null;
final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null;
final boolean authenticated = adminAuthenticated || user != null;
final boolean extendedSearchRights = adminAuthenticated || (user != null && user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT));
@ -668,7 +668,9 @@ public class yacysearchitem {
}
/**
* Add action links reserved to authorized users. All parameters must be non null.
* Add action links reserved to authorized users (adminRights). All
* parameters must be non null.
*
* @param sb the main Switchboard instance
* @param prop properties map to feed
* @param theSearch search event
@ -677,41 +679,44 @@ public class yacysearchitem {
* @param origQ origin query terms
* @param urlhash URL hash of the result item
*/
private static void addAuthorizedActions(final Switchboard sb, final serverObjects prop,
final SearchEvent theSearch, final String resultUrlstring, final String resource, final String origQ,
final String urlhash) {
// check if url exists in bookmarks
boolean bookmarkexists = sb.bookmarksDB.getBookmark(urlhash) != null;
prop.put("content_authorized_bookmark", !bookmarkexists);
final StringBuilder linkBuilder = QueryParams.navurl(RequestHeader.FileType.HTML, theSearch.query.offset / theSearch.query.itemsPerPage(),
theSearch.query, null, false, true);
final int baseUrlLength = linkBuilder.length();
String encodedURLString;
try {
encodedURLString = URLEncoder.encode(crypt.simpleEncode(resultUrlstring), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e1) {
ConcurrentLog.warn("YACY_SEARCH_ITEM", "UTF-8 encoding is not supported!");
encodedURLString = crypt.simpleEncode(resultUrlstring);
}
final String bookmarkLink = linkBuilder.append("&bookmarkurl=").append(encodedURLString).toString();
linkBuilder.setLength(baseUrlLength);
private static void addAuthorizedActions(final Switchboard sb, final serverObjects prop,
final SearchEvent theSearch, final String resultUrlstring, final String resource, final String origQ,
final String urlhash) {
// check if url exists in bookmarks
boolean bookmarkexists = sb.bookmarksDB.getBookmark(urlhash) != null;
prop.put("content_authorized_bookmark", !bookmarkexists);
final StringBuilder linkBuilder = QueryParams.navurl(RequestHeader.FileType.HTML, theSearch.query.offset / theSearch.query.itemsPerPage(),
theSearch.query, null, false, true);
final int baseUrlLength = linkBuilder.length();
String encodedURLString;
try {
encodedURLString = URLEncoder.encode(crypt.simpleEncode(resultUrlstring), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e1) {
ConcurrentLog.warn("YACY_SEARCH_ITEM", "UTF-8 encoding is not supported!");
encodedURLString = crypt.simpleEncode(resultUrlstring);
}
final String bookmarkLink = linkBuilder.append("&bookmarkurl=").append(encodedURLString).toString();
linkBuilder.setLength(baseUrlLength);
String deleteLink = linkBuilder.append("&deleteref=").append(urlhash).toString();
linkBuilder.setLength(baseUrlLength);
String deleteLink = linkBuilder.append("&deleteref=").append(urlhash).toString();
linkBuilder.setLength(baseUrlLength);
String recommendLink = linkBuilder.append("&recommendref=").append(urlhash).toString();
linkBuilder.setLength(baseUrlLength);
String recommendLink = linkBuilder.append("&recommendref=").append(urlhash).toString();
linkBuilder.setLength(baseUrlLength);
prop.put("content_authorized_bookmark_bookmarklink", bookmarkLink);
prop.put("content_authorized_recommend_deletelink", deleteLink);
prop.put("content_authorized_recommend_recommendlink", recommendLink);
final String blacklistLink = linkBuilder.append("&blacklisturl=").append(encodedURLString).toString();
linkBuilder.setLength(baseUrlLength); // cut off - for next new append
prop.put("content_authorized_recommend", (sb.peers.newsPool.getSpecific(NewsPool.OUTGOING_DB, NewsPool.CATEGORY_SURFTIPP_ADD, "url", resultUrlstring) == null) ? "1" : "0");
prop.put("content_authorized_urlhash", urlhash);
}
prop.put("content_authorized_blacklist_blacklistlink", blacklistLink);
prop.put("content_authorized_bookmark_bookmarklink", bookmarkLink);
prop.put("content_authorized_recommend_deletelink", deleteLink);
prop.put("content_authorized_recommend_recommendlink", recommendLink);
prop.put("content_authorized_recommend", (sb.peers.newsPool.getSpecific(NewsPool.OUTGOING_DB, NewsPool.CATEGORY_SURFTIPP_ADD, "url", resultUrlstring) == null) ? "1" : "0");
prop.put("content_authorized_blacklist", "1");
}
/**
* Process search of image type and feed prop object. All parameters must not be null.

@ -451,7 +451,7 @@ public class Blacklist {
}
/**
* appends aN entry to the backlist source file and updates internal blacklist maps.
* appends an entry to the backlist source file and updates internal blacklist maps.
*
* @param blacklistSourcefile name of the blacklist file (LISTS/*.black)
* @param host host or host pattern

Loading…
Cancel
Save