|
4 | 4 | import de.interaapps.pastefy.controller.HttpController; |
5 | 5 | import de.interaapps.pastefy.model.database.Paste; |
6 | 6 | import org.apache.commons.text.StringEscapeUtils; |
| 7 | +import org.javawebstack.http.router.Exchange; |
7 | 8 | import org.javawebstack.http.router.router.annotation.params.Path; |
8 | 9 | import org.javawebstack.http.router.router.annotation.verbs.Get; |
9 | 10 | import org.javawebstack.orm.Repo; |
@@ -41,9 +42,12 @@ public class PasteMetaController extends HttpController { |
41 | 42 | } |
42 | 43 |
|
43 | 44 | @Get("/{paste}") |
44 | | - public String pasteTags(@Path("paste") String pasteId) { |
| 45 | + public String pasteTags(Exchange exchange, @Path("paste") String pasteId) { |
| 46 | + if (Pastefy.getInstance().getConfig().get("pastefy.metatags", "false").equalsIgnoreCase("true")) return null; |
45 | 47 | if (html == null || pasteId.length() != 8) return null; |
46 | 48 |
|
| 49 | + if (!isSocialMediaBot(exchange.header("User-Agent"))) return null; |
| 50 | + |
47 | 51 | Paste paste = Paste.get(pasteId); |
48 | 52 |
|
49 | 53 | if (paste == null || paste.isPrivate() || paste.isEncrypted()) return null; |
@@ -80,4 +84,27 @@ private String tagsToHTML(Map<String, String> map){ |
80 | 84 | }); |
81 | 85 | return out.toString(); |
82 | 86 | } |
| 87 | + |
| 88 | + public static boolean isSocialMediaBot(String userAgent) { |
| 89 | + if (userAgent == null) return false; |
| 90 | + |
| 91 | + String[] socialMediaBots = { |
| 92 | + "Twitterbot", // Twitter |
| 93 | + "facebookexternalhit", // Facebook |
| 94 | + "Instagram", // Instagram |
| 95 | + "Googlebot", // Google |
| 96 | + "LinkedInBot", // LinkedIn |
| 97 | + "Pinterest", // Pinterest |
| 98 | + "Slackbot", // Slack |
| 99 | + "WhatsApp" // WhatsApp |
| 100 | + }; |
| 101 | + |
| 102 | + // Check if userAgent contains any social media bot signature |
| 103 | + for (String bot : socialMediaBots) { |
| 104 | + if (userAgent.contains(bot)) { |
| 105 | + return true; // Bot found |
| 106 | + } |
| 107 | + } |
| 108 | + return false; // No bot found |
| 109 | + } |
83 | 110 | } |
0 commit comments