From 9f3942c1c7339b7433aff12a49a617f6c4ebb6ce Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 8 Mar 2020 17:15:00 +0000 Subject: [PATCH] settings to disable or not advertise file feed --- .../groovy/com/muwire/core/MuWireSettings.groovy | 6 ++++++ .../muwire/core/connection/ConnectionAcceptor.groovy | 12 ++++++++++-- .../com/muwire/core/search/ResultsSender.groovy | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index b820ce1e..073d79a5 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -31,6 +31,8 @@ class MuWireSettings { boolean shareHiddenFiles boolean searchComments boolean browseFiles + boolean fileFeed + boolean advertiseFeed boolean startChatServer int maxChatConnections boolean advertiseChat @@ -82,6 +84,8 @@ class MuWireSettings { outBw = Integer.valueOf(props.getProperty("outBw","128")) searchComments = Boolean.valueOf(props.getProperty("searchComments","true")) browseFiles = Boolean.valueOf(props.getProperty("browseFiles","true")) + fileFeed = Boolean.valueOf(props.getProperty("fileFeed","true")) + advertiseFeed = Boolean.valueOf(props.getProperty("advertiseFeed","true")) speedSmoothSeconds = Integer.valueOf(props.getProperty("speedSmoothSeconds","60")) totalUploadSlots = Integer.valueOf(props.getProperty("totalUploadSlots","-1")) uploadSlotsPerUser = Integer.valueOf(props.getProperty("uploadSlotsPerUser","-1")) @@ -137,6 +141,8 @@ class MuWireSettings { props.setProperty("outBw", String.valueOf(outBw)) props.setProperty("searchComments", String.valueOf(searchComments)) props.setProperty("browseFiles", String.valueOf(browseFiles)) + props.setProperty("fileFeed", String.valueOf(fileFeed)) + props.setProperty("advertiseFeed", String.valueOf(advertiseFeed)) props.setProperty("speedSmoothSeconds", String.valueOf(speedSmoothSeconds)) props.setProperty("totalUploadSlots", String.valueOf(totalUploadSlots)) props.setProperty("uploadSlotsPerUser", String.valueOf(uploadSlotsPerUser)) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index 16c67c1c..25266649 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -379,6 +379,9 @@ class ConnectionAcceptor { boolean chat = chatServer.running.get() && settings.advertiseChat os.write("Chat: ${chat}\r\n".getBytes(StandardCharsets.US_ASCII)) + boolean feed = settings.fileFeed && settings.advertiseFeed + os.write("Feed: ${feed}\r\n".getBytes(StandardCharsets.US_ASCII)) + os.write("\r\n".getBytes(StandardCharsets.US_ASCII)) DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(os)) @@ -538,6 +541,7 @@ class ConnectionAcceptor { if (EED != "EED\r\n".getBytes(StandardCharsets.US_ASCII)) throw new Exception("Invalid FEED connection") + OutputStream os = e.getOutputStream() Map headers = DataUtil.readAllHeaders(dis) if (!headers.containsKey("Persona")) @@ -546,7 +550,12 @@ class ConnectionAcceptor { if (requestor.destination != e.destination) throw new Exception("Requestor persona mismatch") - // TODO: check settings if feed is permitted at all + if (!settings.fileFeed) { + os.write("403 Not Allowed\r\n\r\n".getBytes(StandardCharsets.US_ASCII)) + os.flush() + e.close() + return + } long timestamp = 0 if (headers.containsKey("Timestamp")) { @@ -555,7 +564,6 @@ class ConnectionAcceptor { List published = fileManager.getPublishedSince(timestamp) - OutputStream os = e.getOutputStream() os.write("200 OK\r\n".getBytes(StandardCharsets.US_ASCII)) os.write("Count: ${published.size()}\r\n".getBytes(StandardCharsets.US_ASCII)); os.write("\r\n".getBytes(StandardCharsets.US_ASCII)) diff --git a/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy b/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy index b79df77a..c61ebc5a 100644 --- a/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy +++ b/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy @@ -138,6 +138,8 @@ class ResultsSender { os.write("Count: $results.length\r\n".getBytes(StandardCharsets.US_ASCII)) boolean chat = chatServer.running.get() && settings.advertiseChat os.write("Chat: $chat\r\n".getBytes(StandardCharsets.US_ASCII)) + boolean feed = settings.fileFeed && settings.advertiseFeed + os.write("Feed: $feed\r\n".getBytes(StandardCharsets.US_ASCII)) os.write("\r\n".getBytes(StandardCharsets.US_ASCII)) DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(os)) results.each {