From 55b409cfb4c95a18ee3183c99a7133e51395d454 Mon Sep 17 00:00:00 2001 From: zapata Date: Sat, 15 Mar 2003 15:35:56 +0000 Subject: [PATCH] - anti-abuse features created - old config functions removed --- bundles/admin_en.properties | 43 +- etc/bundles/open_en.properties | 6 + etc/config.properties-dist | 3 - etc/log4j.properties | 14 +- etc/open/comment.template | 9 +- etc/open/posting.template | 7 +- source/Mir.java | 9 +- source/default.properties | 15 +- source/mir/misc/PDFUtil.java | 58 +- source/mir/util/GeneratorHTMLFunctions.java | 11 +- source/mir/util/HTMLRoutines.java | 117 +- source/mir/util/InternetFunctions.java | 66 + source/mir/util/StringRoutines.java | 57 + source/mircoders/global/Abuse.java | 598 ++++++ source/mircoders/global/MirGlobal.java | 52 +- .../basic/MirBasicDataModelLocalizer.java | 10 +- .../basic/MirBasicGeneratorLocalizer.java | 12 +- .../basic/MirBasicOpenPostingLocalizer.java | 4 +- .../basic/MirBasicProducerAssistantLocalizer.java | 32 +- .../localizer/basic/MirBasicProducerLocalizer.java | 6 +- source/mircoders/servlet/ServletModuleAbuse.java | 150 ++ source/mircoders/servlet/ServletModuleContent.java | 6 +- .../mircoders/servlet/ServletModuleLocalizer.java | 3 +- .../mircoders/servlet/ServletModuleOpenIndy.java | 2006 ++++++++++---------- templates/admin/abuse.filters.template | 67 + templates/admin/abuse.log.template | 46 + templates/admin/abuse.template | 108 ++ templates/admin/superusermenu.template | 3 + 28 files changed, 2358 insertions(+), 1160 deletions(-) create mode 100755 source/mir/util/InternetFunctions.java create mode 100755 source/mircoders/global/Abuse.java create mode 100755 source/mircoders/servlet/ServletModuleAbuse.java create mode 100755 templates/admin/abuse.filters.template create mode 100755 templates/admin/abuse.log.template create mode 100755 templates/admin/abuse.template diff --git a/bundles/admin_en.properties b/bundles/admin_en.properties index 15305c02..dd455082 100755 --- a/bundles/admin_en.properties +++ b/bundles/admin_en.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: english -# $Id: admin_en.properties,v 1.38 2003/03/09 05:52:12 zapata Exp $ +# $Id: admin_en.properties,v 1.39 2003/03/15 15:35:56 zapata Exp $ languagename=English @@ -101,6 +101,9 @@ comment.html=HTML? comment.status=Status comment.language=Language +comment.operation.hide=Hide +comment.operation.unhide=Unhide + commentlist.htmltitle=Comments commentsearch.field = Field @@ -177,6 +180,11 @@ content.viewparent=view content.clearparent=de-select content.selectparent=select +content.operation.hide=Hide +content.operation.unhide=Unhide +content.operation.newswire=Newswire + + contentsearch.value = value contentsearch.field = field contentsearch.field.title = Title @@ -359,8 +367,35 @@ superusermenu.topics = Manage topics superusermenu.articletypes = Manage article types superusermenu.comment_statuses = Manage comment status values superusermenu.users = Manage users -superusermenu.languages = Manage languages -superusermenu.imcs = Manage IMCS (obsolete) +superusermenu.languages = Manage languages +superusermenu.abuse = Apply anti-abuse measures +superusermenu.imcs = Manage IMCS (obsolete) + + +abuse.setting = Setting +abuse.value = Value + +abuse.disableopenpostings=Turn off open posting +abuse.openpostingpassword=Require a password for open postings +abuse.logpostings=Log IPs for open postings +abuse.logsize=Logging buffer size +abuse.cookies=Use cookies for blocked users +abuse.articleaction=Action for blocked article +abuse.commentaction=Action for blocked comment + +abuse.showlog=Show the IP log +abuse.showfilters=Manage filters + +abuse.log.time=Time +abuse.log.address=IP number +abuse.log.object=Object +abuse.log.browser=Browser + +abuse.filters = Filters +abuse.filter.type = Type +abuse.filtertype.ip = IP Number +abuse.filtertype.regexp = Regular expression +abuse.filter.expression = Expression @@ -386,6 +421,8 @@ articletypes.startspecial=Startpage-special commentstatus.normal=Normal + + ########## error ########## error.htmltitle=the system caused an error diff --git a/etc/bundles/open_en.properties b/etc/bundles/open_en.properties index 5a246314..c03158fe 100755 --- a/etc/bundles/open_en.properties +++ b/etc/bundles/open_en.properties @@ -58,6 +58,12 @@ postingdupe.explanation=You probably clicked on the reload button or submitted y postingdupe.no_panic=Don't panic postingdupe.back=Back +postingdisabled.info=Open posting is not possible at this moment.
We apologize for any inconvenience this may cause you. +postingdisabled.htmltitle=Mir | Open posting disabled +postingdisabled.title=Open posting disabled +postingdisabled.back=Back + + comment.htmltitle=Mir | comment comment.header=Adding a coment to an article comment.password=Password diff --git a/etc/config.properties-dist b/etc/config.properties-dist index 19715602..27084f6a 100755 --- a/etc/config.properties-dist +++ b/etc/config.properties-dist @@ -97,9 +97,6 @@ Mir.Localizer.Producer.AllNewProducers= media.new;articles.changed;startpage.run GenerateFO=yes GeneratePDF=yes -#on-time-password-protection -PasswdProtection=no - #use rsync to mirror the website to a remote-host Rsync=no Rsync.Script.Path=/var/www/bin/rsync-copy diff --git a/etc/log4j.properties b/etc/log4j.properties index d1e8d4b0..626088a0 100755 --- a/etc/log4j.properties +++ b/etc/log4j.properties @@ -1,4 +1,6 @@ log4j.rootLogger= WARN, A1 +log4j.logger.Utility= INFO, UtilityA +log4j.logger.Global= INFO, GlobalA log4j.logger.Servlet= INFO, ServletA log4j.logger.Database= INFO, DatabaseA log4j.logger.Entity= INFO, EntityA @@ -54,6 +56,16 @@ log4j.appender.LocalizerA.layout=org.apache.log4j.PatternLayout log4j.appender.LocalizerA.layout.ConversionPattern=%d [%p] %c %x %m%n log4j.appender.TemplateEngineA=org.apache.log4j.RollingFileAppender -log4j.appender.TemplateEngineA.File=${log.home}/localizer.log +log4j.appender.TemplateEngineA.File=${log.home}/template.log log4j.appender.TemplateEngineA.layout=org.apache.log4j.PatternLayout log4j.appender.TemplateEngineA.layout.ConversionPattern=%d [%p] %c %x %m%n + +log4j.appender.GlobalA=org.apache.log4j.RollingFileAppender +log4j.appender.GlobalA.File=${log.home}/global.log +log4j.appender.GlobalA.layout=org.apache.log4j.PatternLayout +log4j.appender.GlobalA.layout.ConversionPattern=%d [%p] %c %x %m%n + +log4j.appender.UtilityA=org.apache.log4j.RollingFileAppender +log4j.appender.UtilityA.File=${log.home}/global.log +log4j.appender.UtilityA.layout=org.apache.log4j.PatternLayout +log4j.appender.UtilityA.layout.ConversionPattern=%d [%p] %c %x %m%n diff --git a/etc/open/comment.template b/etc/open/comment.template index f846af46..f6d9bccc 100755 --- a/etc/open/comment.template +++ b/etc/open/comment.template @@ -16,7 +16,10 @@

${lang("comment.note")} -
${data.passwd} + +
+ ${data.passwd} +

@@ -27,12 +30,12 @@ ${lang("comment.formtitle")} - + ${lang("comment.password")}: - + ${lang("comment.title")}: diff --git a/etc/open/posting.template b/etc/open/posting.template index 0ce23730..67e2f476 100755 --- a/etc/open/posting.template +++ b/etc/open/posting.template @@ -32,7 +32,10 @@ + +
${data.passwd} +


@@ -52,12 +55,12 @@
${lang("posting.form.title")}
- + ${lang("posting.password")} - + ${lang("posting.title")}:
diff --git a/source/Mir.java b/source/Mir.java index e7f306c6..ce3de041 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -79,8 +79,8 @@ import freemarker.template.TemplateModel; /** * Mir.java - main servlet, that dispatches to servletmodules * - * @author $Author: idfx $ - * @version $Id: Mir.java,v 1.39 2003/03/15 02:07:35 idfx Exp $ + * @author $Author: zapata $ + * @version $Id: Mir.java,v 1.40 2003/03/15 15:35:56 zapata Exp $ * */ public class Mir extends AbstractServlet { @@ -102,8 +102,7 @@ public class Mir extends AbstractServlet { MessageResources messageResources = MessageResources.getMessageResources("bundles.adminlocal"); List languages = - StringRoutines.splitString(MirGlobal.getConfigPropertyWithDefault( - "Mir.Login.Languages", "en"), ";"); + StringRoutines.splitString(MirGlobal.config().getString("Mir.Login.Languages", "en"), ";"); loginLanguages = new Vector(); @@ -141,7 +140,7 @@ public class Mir extends AbstractServlet { // OpenMir as well -mh protected String getDefaultLanguage(HttpServletRequest aRequest) { String defaultlanguage = - MirGlobal.getConfigPropertyWithDefault("Mir.Login.DefaultLanguage", ""); + MirGlobal.config().getString("Mir.Login.DefaultLanguage", ""); if (defaultlanguage.length() == 0) { Locale locale = aRequest.getLocale(); diff --git a/source/default.properties b/source/default.properties index 3455052e..d89e0552 100755 --- a/source/default.properties +++ b/source/default.properties @@ -47,6 +47,17 @@ Mir.Version=1.1beta StandardLanguage=de DirectOpenposting=yes +# The name of the abuse config file (relative to the WEB-INF dir) +Abuse.Config=abuse.properties +# The name of the cookie that can be used to thwart trolls +# (The name is deliberately misleading) +Abuse.CookieName=SessionIdentifier + +# The time the cookie will remain active in hours +# 168 = 1 week +Abuse.CookieMaxAge=168 + + #where to put the lucene index IndexPath=/tmp/index @@ -92,9 +103,6 @@ Mir.Localizer.Producer.AllNewProducers= media.new;articles.changed;startpage.run GenerateFO=yes GeneratePDF=yes -#on-time-password-protection -PasswdProtection=no - #use rsync to mirror the website to a remote-host Rsync=no Rsync.Script.Path=/var/www/bin/rsync-copy @@ -263,6 +271,7 @@ ServletModule.OpenIndy.CommentDupeTemplate=etc/open/comment_dupe.template ServletModule.OpenIndy.PostingTemplate=etc/open/posting.template ServletModule.OpenIndy.PostingDoneTemplate=etc/open/posting_done.template ServletModule.OpenIndy.PostingDupeTemplate=etc/open/posting_dupe.template +ServletModule.OpenIndy.PostingDisabledTemplate=etc/open/posting_disabled.template ServletModule.OpenIndy.SearchResultsTemplate=etc/open/search_results.template ServletModule.OpenIndy.PrepareMailTemplate=etc/open/prepare_mail.template ServletModule.OpenIndy.SentMailTemplate=etc/open/sent_mail.template diff --git a/source/mir/misc/PDFUtil.java b/source/mir/misc/PDFUtil.java index 2ef9fe64..7279f728 100755 --- a/source/mir/misc/PDFUtil.java +++ b/source/mir/misc/PDFUtil.java @@ -48,63 +48,63 @@ import org.apache.log.Priority; import org.xml.sax.XMLReader; public class PDFUtil { - + public static void makePDF(String foFilePath,Object pdfDestination,String stylesheetPath) throws Exception { try{ Driver driver = new Driver(); - + //stupid logging that fop wants to use, needs to be changed Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); Logger fopLog=null; fopLog = hierarchy.getLoggerFor("fop"); fopLog.setPriority(Priority.WARN); driver.setLogger(fopLog); - + driver.setRenderer(Driver.RENDER_PDF); - + File foFile=new File(foFilePath); - + String html2foStyleSheetPath; if (stylesheetPath == "FROMCONFIG"){ - html2foStyleSheetPath=MirGlobal.getConfigProperty("Home") - + MirGlobal.getConfigProperty("HTMLTemplateProcessor.Dir") - + "/" - + MirGlobal.getConfigProperty("Producer.PrintableContent.html2foStyleSheetName"); + html2foStyleSheetPath=MirGlobal.config().getString("Home") + + MirGlobal.config().getString("HTMLTemplateProcessor.Dir") + + File.separator + + MirGlobal.config().getString("Producer.PrintableContent.html2foStyleSheetName"); } else { - html2foStyleSheetPath=stylesheetPath; + html2foStyleSheetPath=stylesheetPath; } File html2foStyleSheet=new File(html2foStyleSheetPath); InputHandler inputHandler = - new XSLTInputHandler(foFile, html2foStyleSheet); + new XSLTInputHandler(foFile, html2foStyleSheet); XMLReader parser = inputHandler.getParser(); - + if (pdfDestination instanceof String) { - String filePath = (String) pdfDestination; - driver.setOutputStream(new FileOutputStream(filePath)); - driver.render(parser, inputHandler.getInputSource()); + String filePath = (String) pdfDestination; + driver.setOutputStream(new FileOutputStream(filePath)); + driver.render(parser, inputHandler.getInputSource()); } else if (pdfDestination instanceof HttpServletResponse){ - HttpServletResponse res = (HttpServletResponse) pdfDestination; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - driver.setOutputStream(out); - res.setContentType("application/pdf"); - - driver.render(parser, inputHandler.getInputSource()); - - byte[] content = out.toByteArray(); - res.setContentLength(content.length); - res.getOutputStream().write(content); - res.getOutputStream().flush(); + HttpServletResponse res = (HttpServletResponse) pdfDestination; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + driver.setOutputStream(out); + res.setContentType("application/pdf"); + + driver.render(parser, inputHandler.getInputSource()); + + byte[] content = out.toByteArray(); + res.setContentLength(content.length); + res.getOutputStream().write(content); + res.getOutputStream().flush(); } else { - throw new Exception("I'm sorry but I don't know how to output a pdf to an object of type" + pdfDestination.getClass().getName()); + throw new Exception("I'm sorry but I don't know how to output a pdf to an object of type" + pdfDestination.getClass().getName()); } } - + catch (Exception ex){ - throw(ex); + throw(ex); } } } diff --git a/source/mir/util/GeneratorHTMLFunctions.java b/source/mir/util/GeneratorHTMLFunctions.java index 8afeb232..b5e0bf6d 100755 --- a/source/mir/util/GeneratorHTMLFunctions.java +++ b/source/mir/util/GeneratorHTMLFunctions.java @@ -43,10 +43,15 @@ public class GeneratorHTMLFunctions { public static class encodeURIGeneratorFunction implements Generator.GeneratorFunction { public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure { try { - if (aParameters.size()!=1) - throw new GeneratorExc("encodeURIGeneratorFunction: only 1 parameter expected"); + if (aParameters.size()<1 || aParameters.size()>2) + throw new GeneratorExc("encodeURIGeneratorFunction []: only 1 or 2 parameters expected"); + + if (aParameters.size()>=2) + return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aParameters.get(0)), (StringRoutines.interpretAsString(aParameters.get(1)))); + else + return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aParameters.get(0))); + - return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aParameters.get(0))); } catch (GeneratorExc e) { throw e; diff --git a/source/mir/util/HTMLRoutines.java b/source/mir/util/HTMLRoutines.java index 3bb4a1c6..ee23557a 100755 --- a/source/mir/util/HTMLRoutines.java +++ b/source/mir/util/HTMLRoutines.java @@ -1,55 +1,64 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mir.util; - -import java.net.URLEncoder; - -public class HTMLRoutines { - - public static String encodeURL(String aString) { - return URLEncoder.encode(aString); - } - - public static String encodeHTML(String aText) { - final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"' }; - final String[] ESCAPE_CODES = { "&", "<", ">", """ }; - - return StringRoutines.replaceStringCharacters(aText, CHARACTERS_TO_ESCAPE, ESCAPE_CODES); - } - - public static String encodeXML(String aText) { - final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' }; - final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" }; - - return StringRoutines.replaceStringCharacters(aText, CHARACTERS_TO_ESCAPE, ESCAPE_CODES); - } +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mir.util; + +import java.net.URLEncoder; + +public class HTMLRoutines { + + public static String encodeURL(String aString) { + return URLEncoder.encode(aString); + } + + public static String encodeURL(String aString, String anEncoding) { + try { + return URLEncoder.encode(aString, anEncoding); + } + catch (Throwable t) { + throw new RuntimeException(t.getMessage()); + } + } + + public static String encodeHTML(String aText) { + final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"' }; + final String[] ESCAPE_CODES = { "&", "<", ">", """ }; + + return StringRoutines.replaceStringCharacters(aText, CHARACTERS_TO_ESCAPE, ESCAPE_CODES); + } + + public static String encodeXML(String aText) { + final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' }; + final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" }; + + return StringRoutines.replaceStringCharacters(aText, CHARACTERS_TO_ESCAPE, ESCAPE_CODES); + } } \ No newline at end of file diff --git a/source/mir/util/InternetFunctions.java b/source/mir/util/InternetFunctions.java new file mode 100755 index 00000000..5193daa0 --- /dev/null +++ b/source/mir/util/InternetFunctions.java @@ -0,0 +1,66 @@ +package mir.util; + +import java.util.List; + +public class InternetFunctions { + private InternetFunctions() { + } + + public static boolean isIpAddressInNetwork(String anIpAddress, String aNetwork) throws Exception { + long ipAddress = parseIPAddress(anIpAddress); + long network = 0; + long netMask = (1L<<32)-1; + List networkParts = StringRoutines.separateString(aNetwork, "/"); + + network = parseIPAddress((String) networkParts.get(0)); + if (networkParts.size()>=2) { + netMask=parseNetmask((String) networkParts.get(1)); + } + + return (ipAddress & netMask ) == (network & netMask); + } + + public static long parseIPAddress(String anIpAddress) throws Exception { + int[] parts = {0,0,0,0}; + int i; + long result; + List stringParts = StringRoutines.splitString(anIpAddress, "."); + + if (stringParts.size()!=4) + throw new Exception("Not a valid IP Address: " + anIpAddress); + + try { + for (i=0; i<4; i++) { + parts[i] = Integer.parseInt((String) stringParts.get(i)); + } + } + catch (Throwable t) { + throw new Exception("Not a valid IP Address: " + anIpAddress); + } + for (i=0; i<4; i++) { + if (parts[i]<0 || parts[i]>255) + throw new Exception("Not a valid IP Address: " + anIpAddress); + } + + return parts[0]<<24 | parts[1]<<16 | parts[2]<<8 | parts[3]; + } + + public static long parseNetmask(String anIpAddress) throws Exception { + try { + return parseIPAddress(anIpAddress); + } + catch (Throwable t) { + } + + try { + int size = Integer.parseInt(anIpAddress); + + if (size<=32) + return ((1L<seperateString("a:b:c", ":"); will lead to + * a List with 3 Strings: "a", "b" and "c" + * + * @param aString The string to split + * @param aSeparator + * @return + */ + public static List splitString(String aString, String aSeparator) { List result= new Vector(); int previousPosition = 0; @@ -150,4 +175,36 @@ public class StringRoutines { return result; } + + /** + * Separates a String into at most 2 parts based on a separator: + *
    + *
  • + * seperateString("a:b:c", ":"); will lead to + * a List with 2 Strings: "a" and "b:c" + *
  • + * seperateString("abc", ":"); will lead to + * a List with a single String: "abc" + *
+ * + * + * @param aString + * @param aSeparator + * @return + */ + public static List separateString(String aString, String aSeparator) { + List result= new Vector(); + int previousPosition = 0; + int position; + int endOfNamePosition; + + if((position = aString.indexOf(aSeparator, previousPosition))>=0) { + result.add(aString.substring(previousPosition, position)); + previousPosition = position + aSeparator.length(); + } + + result.add(aString.substring(previousPosition, aString.length())); + + return result; + } } \ No newline at end of file diff --git a/source/mircoders/global/Abuse.java b/source/mircoders/global/Abuse.java new file mode 100755 index 00000000..dd1a4ede --- /dev/null +++ b/source/mircoders/global/Abuse.java @@ -0,0 +1,598 @@ +package mircoders.global; + +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; +import java.util.Random; +import java.io.*; +import javax.servlet.http.*; + +import org.apache.commons.collections.*; +import gnu.regexp.RE; + +import mir.log.LoggerWrapper; +import mir.util.DateToMapAdapter; +import mir.util.StringRoutines; +import mir.util.*; +import mir.entity.*; + +import mircoders.entity.EntityComment; +import mircoders.entity.EntityContent; +import mircoders.localizer.MirAdminInterfaceLocalizer; + + +public class Abuse { + private List filters; + private int maxIdentifier; + private LoggerWrapper logger; + private int logSize; + private boolean logEnabled; + private boolean openPostingDisabled; + private boolean openPostingPassword; + private boolean cookieOnBlock; + private String articleBlockAction; + private String commentBlockAction; + private List log; + private String configFile = MirGlobal.config().getStringWithHome("Abuse.Config"); + + + private static final String IP_FILTER_TYPE="ip"; + private static final String REGEXP_FILTER_TYPE="regexp"; + private static String cookieName=MirGlobal.config().getString("Abuse.CookieName"); + private static int cookieMaxAge = 60*60*MirGlobal.config().getInt("Abuse.CookieMaxAge"); + + public Abuse() { + logger = new LoggerWrapper("Global.Abuse"); + filters = new Vector(); + maxIdentifier = 0; + log = new Vector(); + + logSize = 100; + logEnabled = false; + articleBlockAction = ""; + commentBlockAction = ""; + openPostingPassword = false; + openPostingDisabled = false; + cookieOnBlock = false; + + load(); + } + + public boolean checkIpFilter(String anIpAddress) { + synchronized (filters) { + Iterator i = filters.iterator(); + + while (i.hasNext()) { + Filter filter = (Filter) i.next(); + + try { + if ( (filter.getType().equals(IP_FILTER_TYPE)) && + InternetFunctions.isIpAddressInNetwork(anIpAddress, filter.getExpression())) { + logger.debug("ip match on " + filter.getExpression()); + return true; + } + } + catch (Throwable t) { + logger.warn("error while checking ip address " + anIpAddress + " over network " + filter.expression + ": " + t.getMessage()); + } + } + + return false; + } + } + + private boolean checkRegExpFilter(Entity anEntity) { + synchronized (filters) { + Iterator i = filters.iterator(); + + while (i.hasNext()) { + Filter filter = (Filter) i.next(); + + if (filter.getType().equals(REGEXP_FILTER_TYPE)) { + try { + RE regularExpression = new RE(filter.getExpression()); + + Iterator j = anEntity.getFields().iterator(); + while (j.hasNext()) { + String field = anEntity.getValue( (String) j.next()); + + if (field != null && regularExpression.isMatch(field.toLowerCase())) { + logger.debug("regexp match on " + filter.getExpression()); + return true; + } + } + } + catch (Throwable t) { + logger.warn("error while checking entity with regexp " + filter.getExpression() + ": " + t.getMessage()); + } + } + } + + return false; + } + } + + private void setCookie(HttpServletResponse aResponse) { + Random random = new Random(); + + Cookie cookie = new Cookie(cookieName, Integer.toString(random.nextInt(1000000000))); + cookie.setMaxAge(cookieMaxAge); + cookie.setPath("/"); + aResponse.addCookie(cookie); + } + + private boolean checkCookie(List aCookies) { + if (getCookieOnBlock()) { + Iterator i = aCookies.iterator(); + + while (i.hasNext()) { + Cookie cookie = (Cookie) i.next(); + + if (cookie.getName().equals(cookieName)) { + logger.debug("cookie match"); + return true; + } + } + } + + return false; + } + + public void checkComment(EntityComment aComment, HttpServletRequest aRequest, HttpServletResponse aResponse) { + try { + long time = System.currentTimeMillis(); + + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(commentBlockAction); + + if (checkCookie(Arrays.asList(aRequest.getCookies())) || checkIpFilter(aRequest.getRemoteAddr()) || checkRegExpFilter(aComment)) { + operation.perform(null, MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment)); + setCookie(aResponse); + } + + logger.info("checkComment: " + (System.currentTimeMillis()-time) + "ms"); + + } + catch (Throwable t) { + logger.error("Abuse.checkComment: " + t.toString()); + } + } + + public void checkArticle(EntityContent anArticle, HttpServletRequest aRequest, HttpServletResponse aResponse) { + try { + long time = System.currentTimeMillis(); + + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(commentBlockAction); + + if (checkCookie(Arrays.asList(aRequest.getCookies())) || checkIpFilter(aRequest.getRemoteAddr()) || checkRegExpFilter(anArticle)) { + operation.perform(null, MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle)); + setCookie(aResponse); + } + + logger.info("checkArticle: " + (System.currentTimeMillis()-time) + "ms"); + } + catch (Throwable t) { + logger.error("Abuse.checkArticle: " + t.toString()); + } + } + + public boolean getLogEnabled() { + return logEnabled; + } + + public void setLogEnabled(boolean anEnabled) { + logEnabled = anEnabled; + truncateLog(); + } + + public int getLogSize() { + return logSize; + } + + public void setLogSize(int aSize) { + logSize = aSize; + truncateLog(); + } + + public boolean getOpenPostingDisabled() { + return openPostingDisabled; + } + + public void setOpenPostingDisabled(boolean anOpenPostingDisabled) { + openPostingDisabled = anOpenPostingDisabled; + } + + public boolean getOpenPostingPassword() { + return openPostingPassword; + } + + public void setOpenPostingPassword(boolean anOpenPostingPassword) { + openPostingPassword = anOpenPostingPassword; + } + + public boolean getCookieOnBlock() { + return cookieOnBlock; + } + + public void setCookieOnBlock(boolean aCookieOnBlock) { + cookieOnBlock = aCookieOnBlock; + } + + public String getArticleBlockAction() { + return articleBlockAction; + } + + public void setArticleBlockAction(String anAction) { + articleBlockAction = anAction; + } + + public String getCommentBlockAction() { + return commentBlockAction; + } + + public void setCommentBlockAction(String anAction) { + commentBlockAction = anAction; + } + + + public List getLog() { + synchronized(log) { + List result = new Vector(); + + Iterator i = log.iterator(); + while (i.hasNext()) { + LogEntry logEntry = (LogEntry) i.next(); + Map entry = new HashMap(); + + entry.put("ip", logEntry.getIpNumber()); + entry.put("id", logEntry.getId()); + entry.put("timestamp", new DateToMapAdapter(logEntry.getTimeStamp())); + if (logEntry.getIsArticle()) + entry.put("type", "content"); + else + entry.put("type", "comment"); + entry.put("browser", logEntry.getBrowserString()); + + result.add(entry); + } + + return result; + } + } + + public void logComment(String anIp, String anId, Date aTimeStamp, String aBrowser) { + appendLog(new LogEntry(aTimeStamp, anIp, aBrowser, anId, false)); + } + + public void logArticle(String anIp, String anId, Date aTimeStamp, String aBrowser) { + appendLog(new LogEntry(aTimeStamp, anIp, aBrowser, anId, true)); + } + + public void load() { + try { + ExtendedProperties configuration = new ExtendedProperties(); + + try { + configuration = new ExtendedProperties(configFile); + } + catch (FileNotFoundException e) { + } + + getFilterConfig(filters, "abuse.filter", configuration); + + setOpenPostingDisabled(configuration.getString("abuse.openPostingDisabled", "0").equals("1")); + setOpenPostingPassword(configuration.getString("abuse.openPostingPassword", "0").equals("1")); + setCookieOnBlock(configuration.getString("abuse.cookieOnBlock", "0").equals("1")); + setLogEnabled(configuration.getString("abuse.logEnabled", "0").equals("1")); + setLogSize(configuration.getInt("abuse.logSize", 10)); + setArticleBlockAction(configuration.getString("abuse.articleBlockAction", "")); + setCommentBlockAction(configuration.getString("abuse.commentBlockAction", "")); + } + catch (Throwable t) { + throw new RuntimeException(t.toString()); + } + } + public void save() { + try { + ExtendedProperties configuration = new ExtendedProperties(); + + setFilterConfig(filters, "abuse.filter", configuration); + + configuration.addProperty("abuse.openPostingDisabled", getOpenPostingDisabled()?"1":"0"); + configuration.addProperty("abuse.openPostingPassword", getOpenPostingPassword()?"1":"0"); + configuration.addProperty("abuse.cookieOnBlock", getCookieOnBlock()?"1":"0"); + configuration.addProperty("abuse.logEnabled", getLogEnabled()?"1":"0"); + configuration.addProperty("abuse.logSize", Integer.toString(getLogSize())); + configuration.addProperty("abuse.articleBlockAction", getArticleBlockAction()); + configuration.addProperty("abuse.commentBlockAction", getCommentBlockAction()); + + configuration.save(new FileOutputStream(new File(configFile)), "Anti abuse configuration"); + } + catch (Throwable t) { + throw new RuntimeException(t.toString()); + } + } + + public List getFilterTypes() { + List result = new Vector(); + + Map entry = new HashMap(); + entry.put("resource", "abuse.filtertype.ip"); + entry.put("id", IP_FILTER_TYPE); + result.add(entry); + + entry = new HashMap(); + entry.put("resource", "abuse.filtertype.regexp"); + entry.put("id", REGEXP_FILTER_TYPE); + result.add(entry); + + return result; + } + + public List getArticleActions() { + try { + List result = new Vector(); + + Iterator i = MirGlobal.localizer().adminInterface().simpleArticleOperations().iterator(); + while (i.hasNext()) { + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = + (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next(); + + Map action = new HashMap(); + action.put("resource", "content.operation."+operation.getName()); + action.put("identifier", operation.getName()); + + result.add(action); + } + + return result; + } + catch (Throwable t) { + throw new RuntimeException("can't get article actions"); + } + } + + public List getCommentActions() { + try { + List result = new Vector(); + + Iterator i = MirGlobal.localizer().adminInterface().simpleCommentOperations().iterator(); + while (i.hasNext()) { + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = + (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next(); + + Map action = new HashMap(); + action.put("resource", "comment.operation."+operation.getName()); + action.put("identifier", operation.getName()); + + result.add(action); + } + + return result; + } + catch (Throwable t) { + throw new RuntimeException("can't get comment actions"); + } + } + + public List getFilters() { + return getFiltersAsMaps(filters); + } + + public void addFilter(String aType, String anExpression) { + addFilter(filters, aType, anExpression); + } + + public void setFilter(String anIdentifier, String aType, String anExpression) { + setFilter(filters, anIdentifier, aType, anExpression); + } + + public void deleteFilter(String anIdentifier) { + deleteFilter(filters, anIdentifier); + } + + public void validateIpFilter(String anIdentifier, String anArticleAction, String aCommentAction) throws Exception { + } + + private List getFiltersAsMaps(List aFilters) { + synchronized(aFilters) { + List result = new Vector(); + + Iterator i = aFilters.iterator(); + while (i.hasNext()) { + Filter filter = (Filter) i.next(); + Map map = new HashMap(); + + map.put("id", filter.getId()); + map.put("expression", filter.getExpression()); + map.put("type", filter.getType()); + + result.add(map); + } + return result; + } + } + + private void addFilter(List aFilters, String aType, String anExpression) { + Filter filter = new Filter(); + + filter.setId(generateId()); + filter.setExpression(anExpression); + filter.setType(aType); + + synchronized (aFilters) { + aFilters.add(filter); + } + } + + private void setFilter(List aFilters, String anIdentifier, String aType, String anExpression) { + synchronized (aFilters) { + Filter filter = findFilter(aFilters, anIdentifier); + + if (filter!=null) { + filter.setExpression(anExpression); + filter.setType(aType); + } + } + } + + private Filter findFilter(List aFilters, String anIdentifier) { + synchronized (aFilters) { + Iterator i = aFilters.iterator(); + while (i.hasNext()) { + Filter filter = (Filter) i.next(); + + if (filter.getId().equals(anIdentifier)) { + return filter; + } + } + } + + return null; + } + + private void deleteFilter(List aFilters, String anIdentifier) { + synchronized (aFilters) { + Filter filter = findFilter(aFilters, anIdentifier); + + if (filter!=null) { + aFilters.remove(filter); + } + } + } + + private String generateId() { + synchronized(this) { + maxIdentifier = maxIdentifier+1; + + return Integer.toString(maxIdentifier); + } + } + + private static class Filter { + private String identifier; + private String expression; + private String type; + + public Filter() { + expression=""; + type=""; + identifier=""; + } + + public String getId() { + return identifier; + } + + public void setId(String anId) { + identifier = anId; + } + + public String getExpression() { + return expression; + } + + public void setExpression(String anExpression) { + expression = anExpression; + } + + public String getType() { + return type; + } + + public void setType(String aType) { + type = aType; + } + } + + private void setFilterConfig(List aFilters, String aConfigKey, ExtendedProperties aConfiguration) { + synchronized(aFilters) { + Iterator i = aFilters.iterator(); + + while (i.hasNext()) { + Filter filter = (Filter) i.next(); + + aConfiguration.addProperty(aConfigKey, filter.getType()+":"+filter.getExpression()); + } + } + } + + private void getFilterConfig(List aFilters, String aConfigKey, ExtendedProperties aConfiguration) { + synchronized(aFilters) { + aFilters.clear(); + + Iterator i = Arrays.asList(aConfiguration.getStringArray(aConfigKey)).iterator(); + + while (i.hasNext()) { + String filter = (String) i.next(); + List parts = StringRoutines.separateString(filter, ":"); + + if (parts.size()==2) { + addFilter( (String) parts.get(0), (String) parts.get(1)); + } + } + } + } + + private static class LogEntry { + private String ipNumber; + private String browserString; + private String id; + private Date timeStamp; + private boolean isArticle; + + public LogEntry(Date aTimeStamp, String anIpNumber, String aBrowserString, String anId, boolean anIsArticle) { + ipNumber = anIpNumber; + browserString = aBrowserString; + id = anId; + isArticle = anIsArticle; + timeStamp=aTimeStamp; + } + + public String getIpNumber() { + return ipNumber; + } + + public String getBrowserString() { + return browserString; + } + + public String getId() { + return id; + } + + public Date getTimeStamp() { + return timeStamp; + } + + public boolean getIsArticle() { + return isArticle; + } + } + + private void truncateLog() { + synchronized(log) { + if (!logEnabled) + log.clear(); + else { + while (log.size()>0 && log.size()>logSize) { + log.remove(0); + } + } + } + }; + + private void appendLog(LogEntry anEntry) { + synchronized (log) { + if (logEnabled) { + log.add(anEntry); + truncateLog(); + } + } + } + +} \ No newline at end of file diff --git a/source/mircoders/global/MirGlobal.java b/source/mircoders/global/MirGlobal.java index 6641b1d6..2e29c9db 100755 --- a/source/mircoders/global/MirGlobal.java +++ b/source/mircoders/global/MirGlobal.java @@ -41,6 +41,7 @@ public class MirGlobal { static private MirPropertiesConfiguration configuration; static private MirLocalizer localizer; static private ProducerEngine producerEngine; + static private Abuse abuse; public static MirLocalizer localizer() { String localizerClassName; @@ -49,7 +50,7 @@ public class MirGlobal { if (localizer == null ) { synchronized(MirGlobal.class) { if (localizer == null ) { - localizerClassName = getConfigPropertyWithDefault("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer"); + localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer"); try { localizerClass = Class.forName(localizerClassName); @@ -74,6 +75,17 @@ public class MirGlobal { return localizer; } + public static Abuse abuse() { + if (abuse==null) { + synchronized(MirGlobal.class) { + if (abuse==null) + abuse = new Abuse(); + } + } + + return abuse; + } + public static MirPropertiesConfiguration config() { try { return MirPropertiesConfiguration.instance(); @@ -90,42 +102,4 @@ public class MirGlobal { return producerEngine; } - - public static String getConfigPropertyWithDefault(String aPropertyName, String aDefault) { - String result; - - //this try-catch is sort of a hack, if we make everything use MirGlobal - //instead of MirConfig, we can get rid of the Runtime exception we through - //in getProp, and deal with it here.. needs more thinking.. -mh - try { - result = config().getString(aPropertyName); - } catch (Throwable t) { - result = aDefault; - } - - - if (result==null) - result = aDefault; - - return result; - } - - public static String getConfigProperty(String aPropertyName) { - String result; - - result = config().getString(aPropertyName); - - if (result==null) - throw new ConfigException("Property '" + aPropertyName + "' not present"); - - return result; - } - - public static int getConfigIntegerProperty(String aPropertyName) { - return config().getInt(aPropertyName); - } - - public static boolean getConfigBooleanProperty(String aPropertyName) { - return config().getBoolean(aPropertyName); - } } diff --git a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java index 0e124d46..fd9bf478 100755 --- a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java @@ -375,7 +375,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { iterator = (RewindableIterator) (anEntityAdapter.get("to_uploaded_media")); iterator.rewind(); - tinyIcon = MirGlobal.getConfigProperty("Producer.Icon.TinyText"); + tinyIcon = MirGlobal.config().getString("Producer.Icon.TinyText"); iconAlt = "Text"; if (iterator.hasNext()) { @@ -385,15 +385,15 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { mediaHandler = MediaHelper.getHandler( mediaType ); if (mediaHandler.isVideo()) { - tinyIcon = MirGlobal.getConfigProperty("Producer.Icon.TinyVideo"); + tinyIcon = MirGlobal.config().getString("Producer.Icon.TinyVideo"); iconAlt = "Video"; } else if (mediaHandler.isAudio()) { - tinyIcon = MirGlobal.getConfigProperty("Producer.Icon.TinyAudio"); + tinyIcon = MirGlobal.config().getString("Producer.Icon.TinyAudio"); iconAlt = "Audio"; } else if (mediaHandler.isImage()) { - tinyIcon = MirGlobal.getConfigProperty("Producer.Icon.TinyImage"); + tinyIcon = MirGlobal.config().getString("Producer.Icon.TinyImage"); iconAlt = "Image"; } else { @@ -409,7 +409,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } result = new HashMap(); - result.put("tiny_icon", MirGlobal.getConfigProperty("Producer.ImageRoot") + "/" + tinyIcon); + result.put("tiny_icon", MirGlobal.config().getString("Producer.ImageRoot") + "/" + tinyIcon); result.put("icon_alt", iconAlt); return result; diff --git a/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java b/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java index f6f67102..10995ba4 100755 --- a/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java @@ -54,12 +54,14 @@ public class MirBasicGeneratorLocalizer implements MirGeneratorLocalizer { } protected void buildRepository(GeneratorLibraryRepository aRepository) { - aRepository.registerLibraryFactory("freemarker", new FreemarkerGenerator.FreemarkerGeneratorLibraryFactory( MirGlobal.getConfigProperty("Home") ) ); + aRepository.registerLibraryFactory("freemarker", + new FreemarkerGenerator.FreemarkerGeneratorLibraryFactory( + MirGlobal.config().getString("Home") ) ); } public Generator.GeneratorLibrary makeProducerGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure { try { - return repository.constructCompositeLibrary(MirGlobal.getConfigProperty("Mir.Localizer.Producer.GeneratorLibrary")); + return repository.constructCompositeLibrary(MirGlobal.config().getString("Mir.Localizer.Producer.GeneratorLibrary")); } catch (Throwable t) { throw new MirLocalizerFailure(t); @@ -68,7 +70,7 @@ public class MirBasicGeneratorLocalizer implements MirGeneratorLocalizer { public Generator.GeneratorLibrary makeAdminGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure { try { - return repository.constructCompositeLibrary(MirGlobal.getConfigProperty("Mir.Localizer.Admin.GeneratorLibrary")); + return repository.constructCompositeLibrary(MirGlobal.config().getString("Mir.Localizer.Admin.GeneratorLibrary")); } catch (Throwable t) { throw new MirLocalizerFailure(t); @@ -77,7 +79,7 @@ public class MirBasicGeneratorLocalizer implements MirGeneratorLocalizer { public Generator.GeneratorLibrary makeOpenPostingGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure { try { - return repository.constructCompositeLibrary(MirGlobal.getConfigProperty("Mir.Localizer.OpenPosting.GeneratorLibrary")); + return repository.constructCompositeLibrary(MirGlobal.config().getString("Mir.Localizer.OpenPosting.GeneratorLibrary")); } catch (Throwable t) { throw new MirLocalizerFailure(t); @@ -85,6 +87,6 @@ public class MirBasicGeneratorLocalizer implements MirGeneratorLocalizer { }; public WriterEngine makeWriterEngine() throws MirLocalizerExc, MirLocalizerFailure { - return new MirBasicWriterEngine(MirGlobal.getConfigProperty("Mir.DefaultEncoding")); + return new MirBasicWriterEngine(MirGlobal.config().getString("Mir.DefaultEncoding")); } } diff --git a/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java b/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java index 5f0655ec..ad7dae97 100755 --- a/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java @@ -54,8 +54,8 @@ public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer { logger = new LoggerWrapper("Localizer.Basic.OpenPosting"); try { - String contentProducers = MirGlobal.getConfigProperty("Mir.Localizer.OpenPosting.ContentProducers"); - String commentProducers = MirGlobal.getConfigProperty("Mir.Localizer.OpenPosting.CommentProducers"); + String contentProducers = MirGlobal.config().getString("Mir.Localizer.OpenPosting.ContentProducers"); + String commentProducers = MirGlobal.config().getString("Mir.Localizer.OpenPosting.CommentProducers"); afterContentProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(contentProducers); afterCommentProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(commentProducers); diff --git a/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java index b46f76df..58b193fb 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java @@ -67,19 +67,19 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL logger = new LoggerWrapper("Localizer.ProducerAssistant"); // obsolete: - configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot")); - configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot")); - configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost")); - configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction")); - configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri")); - configMap.put("actionRoot", MirGlobal.getConfigProperty("RootUri")+"/servlet/Mir"); + configMap.put("producerDocRoot", MirGlobal.config().getString("Producer.DocRoot")); + configMap.put("storageRoot", MirGlobal.config().getString("Producer.StorageRoot")); + configMap.put("productionHost", MirGlobal.config().getString("Producer.ProductionHost")); + configMap.put("openAction", MirGlobal.config().getString("Producer.OpenAction")); + configMap.put("docRoot", MirGlobal.config().getString("RootUri")); + configMap.put("actionRoot", MirGlobal.config().getString("RootUri")+"/servlet/Mir"); configMap.put("now", new DateToMapAdapter((new GregorianCalendar()).getTime())); - configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host")); - configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host")); - configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host")); - configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path")); - configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version")); - configMap.put("defEncoding", MirGlobal.getConfigProperty("Mir.DefaultEncoding")); + configMap.put("videoHost", MirGlobal.config().getString("Producer.Video.Host")); + configMap.put("audioHost", MirGlobal.config().getString("Producer.Audio.Host")); + configMap.put("imageHost", MirGlobal.config().getString("Producer.Image.Host")); + configMap.put("imagePath", MirGlobal.config().getString("Producer.Image.Path")); + configMap.put("mirVersion", MirGlobal.config().getString("Mir.Version")); + configMap.put("defEncoding", MirGlobal.config().getString("Mir.DefaultEncoding")); // "new": try { @@ -163,10 +163,10 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL public String filterText(String aText) { return StringUtil.createHTML( StringUtil.deleteForbiddenTags(aText), - MirGlobal.getConfigProperty("Producer.ImageRoot"), - MirGlobal.getConfigProperty("Producer.MailLinkName"), - MirGlobal.getConfigProperty("Producer.ExtLinkName"), - MirGlobal.getConfigProperty("Producer.IntLinkName") + MirGlobal.config().getString("Producer.ImageRoot"), + MirGlobal.config().getString("Producer.MailLinkName"), + MirGlobal.config().getString("Producer.ExtLinkName"), + MirGlobal.config().getString("Producer.IntLinkName") ); } } diff --git a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java index 018eb2d8..ad0be4cb 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java @@ -70,7 +70,7 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { try { logger = new LoggerWrapper("Localizer.Basic.Producer"); - String allNewProducers = MirGlobal.getConfigProperty("Mir.Localizer.Producer.AllNewProducers"); + String allNewProducers = MirGlobal.config().getString("Mir.Localizer.Producer.AllNewProducers"); allNewProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(allNewProducers); producerFactories = new Vector(); @@ -115,7 +115,7 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { try { DefaultProducerNodeBuilders.registerBuilders( aLibrary, model, generatorLibrary, writerEngine, - MirGlobal.getConfigProperty("Home"), MirGlobal.getConfigProperty("Producer.StorageRoot")); + MirGlobal.config().getString("Home"), MirGlobal.config().getString("Producer.StorageRoot")); SupplementalProducerNodeBuilders.registerBuilders(aLibrary, model); } catch (Throwable t) { @@ -132,7 +132,7 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { aFileMonitor.clear(); reader = new ProducerConfigReader(); - reader.parseFile(MirGlobal.getConfigProperty("Home") + File.separatorChar + MirGlobal.getConfigProperty("Mir.Localizer.ProducerConfigFile"), library, aFactories, usedFiles); + reader.parseFile(MirGlobal.config().getString("Home") + File.separatorChar + MirGlobal.config().getString("Mir.Localizer.ProducerConfigFile"), library, aFactories, usedFiles); i = usedFiles.iterator(); while (i.hasNext()) diff --git a/source/mircoders/servlet/ServletModuleAbuse.java b/source/mircoders/servlet/ServletModuleAbuse.java new file mode 100755 index 00000000..1cf01251 --- /dev/null +++ b/source/mircoders/servlet/ServletModuleAbuse.java @@ -0,0 +1,150 @@ +package mircoders.servlet; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import mir.log.LoggerWrapper; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleFailure; +import mir.util.URLBuilder; +import mir.util.HTTPRequestParser; +import mircoders.global.*; + +public class ServletModuleAbuse extends ServletModule { + private static ServletModuleAbuse instance = new ServletModuleAbuse(); + public static ServletModule getInstance() { return instance; } + + private ServletModuleAbuse() { + logger = new LoggerWrapper("ServletModule.Abuse"); + defaultAction = "showsettings"; + } + + public void editfilter(HttpServletRequest aRequest, HttpServletResponse aResponse) { + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + + String type=requestParser.getParameterWithDefault("type", ""); + String id=requestParser.getParameterWithDefault("id", ""); + String expression=requestParser.getParameterWithDefault("expression", ""); + + if (id.equals("")) { + MirGlobal.abuse().addFilter(type, expression); + } + else { + MirGlobal.abuse().setFilter(id, type, expression); + } + + MirGlobal.abuse().save(); + + showfilters(aRequest, aResponse); + } + + public void deletefilter(HttpServletRequest aRequest, HttpServletResponse aResponse) { + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + + String id=requestParser.getParameterWithDefault("id", ""); + MirGlobal.abuse().deleteFilter(id); + + MirGlobal.abuse().save(); + + showfilters(aRequest, aResponse); + } + + public void showfilters(HttpServletRequest aRequest, HttpServletResponse aResponse) { + URLBuilder urlBuilder = new URLBuilder(); + + try { + Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest)); + + urlBuilder.setValue("module", "Abuse"); + urlBuilder.setValue("do", "showfilters"); + responseData.put("thisurl", urlBuilder.getQuery()); + + responseData.put("filters", MirGlobal.abuse().getFilters()); + responseData.put("filtertypes", MirGlobal.abuse().getFilterTypes()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, "abuse.filters.template"); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } + + + public void showsettings(HttpServletRequest aRequest, HttpServletResponse aResponse) { + URLBuilder urlBuilder = new URLBuilder(); + + try { + Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest)); + + urlBuilder.setValue("module", "Abuse"); + urlBuilder.setValue("do", "showsettings"); + + responseData.put("thisurl", urlBuilder.getQuery()); + + responseData.put("articleactions", MirGlobal.abuse().getArticleActions()); + responseData.put("commentactions", MirGlobal.abuse().getCommentActions()); + + responseData.put("disableop", new Boolean(MirGlobal.abuse().getOpenPostingDisabled())); + responseData.put("passwordop", new Boolean(MirGlobal.abuse().getOpenPostingPassword())); + responseData.put("logenabled", new Boolean(MirGlobal.abuse().getLogEnabled())); + responseData.put("logsize", Integer.toString(MirGlobal.abuse().getLogSize())); + responseData.put("usecookies", new Boolean(MirGlobal.abuse().getCookieOnBlock())); + responseData.put("articleaction", MirGlobal.abuse().getArticleBlockAction()); + responseData.put("commentaction", MirGlobal.abuse().getCommentBlockAction()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, "abuse.template"); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } + + public void savesettings(HttpServletRequest aRequest, HttpServletResponse aResponse) { + try { + HTTPRequestParser parser = new HTTPRequestParser(aRequest); + + MirGlobal.abuse().setOpenPostingDisabled(parser.getParameterWithDefault("disableop", "").equals("1")); + MirGlobal.abuse().setOpenPostingPassword(parser.getParameterWithDefault("passwordop", "").equals("1")); + MirGlobal.abuse().setLogEnabled(parser.getParameterWithDefault("logenabled", "").equals("1")); + + try { + MirGlobal.abuse().setLogSize(parser.getIntegerWithDefault("logsize", MirGlobal.abuse().getLogSize())); + } + catch (Throwable t) { + } + + MirGlobal.abuse().setCookieOnBlock(parser.getParameterWithDefault("usecookies", "").equals("1")); + + MirGlobal.abuse().setArticleBlockAction(parser.getParameter("articleaction")); + MirGlobal.abuse().setCommentBlockAction(parser.getParameter("commentaction")); + + MirGlobal.abuse().save(); + + showsettings(aRequest, aResponse); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } + + public void showlog(HttpServletRequest aRequest, HttpServletResponse aResponse) { + URLBuilder urlBuilder = new URLBuilder(); + int count; + + try { + Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest)); + urlBuilder.setValue("module", "Abuse"); + urlBuilder.setValue("do", "showlog"); + responseData.put("thisurl", urlBuilder.getQuery()); + + responseData.put("log", MirGlobal.abuse().getLog()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, "abuse.log.template"); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } +} \ No newline at end of file diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index bb666740..7f4dccf1 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -71,7 +71,7 @@ import freemarker.template.SimpleHash; * ServletModuleContent - * deliver html for the article admin form. * - * @version $Id: ServletModuleContent.java,v 1.43 2003/03/09 19:14:21 idfx Exp $ + * @version $Id: ServletModuleContent.java,v 1.44 2003/03/15 15:35:57 zapata Exp $ * @author rk, mir-coders * */ @@ -95,8 +95,8 @@ public class ServletModuleContent extends ServletModule mainModule = new ModuleContent(DatabaseContent.getInstance()); } - catch (StorageObjectFailure e) { - logger.error("servletmodulecontent konnte nicht initialisiert werden"); + catch (Throwable e) { + logger.fatal("ServletModuleContent could not be initialized: " + e.toString()); } } diff --git a/source/mircoders/servlet/ServletModuleLocalizer.java b/source/mircoders/servlet/ServletModuleLocalizer.java index 6f122b24..363af6cf 100755 --- a/source/mircoders/servlet/ServletModuleLocalizer.java +++ b/source/mircoders/servlet/ServletModuleLocalizer.java @@ -181,8 +181,7 @@ public class ServletModuleLocalizer extends ServletModule { List parts = StringRoutines.splitString(operations[i], ";"); if (parts.size() != 2) { - logger.error("articleoperationbatch: operation string invalid: " + - operations[i]); + logger.error("articleoperationbatch: operation string invalid: " + operations[i]); } else { String articleIdString = (String) parts.get(0); diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 1c6c76fc..b0a4d9df 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -1,979 +1,1027 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.servlet; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Locale; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.log.LoggerWrapper; -import mir.misc.FileHandler; -import mir.misc.HTMLTemplateProcessor; -import mir.misc.StringUtil; -import mir.misc.WebdbMultipartRequest; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleExc; -import mir.servlet.ServletModuleFailure; -import mir.servlet.ServletModuleUserExc; -import mir.storage.StorageObjectFailure; -import mir.util.ExceptionFunctions; -import mir.util.StringRoutines; -import mircoders.entity.EntityComment; -import mircoders.entity.EntityContent; -import mircoders.global.MirGlobal; -import mircoders.media.MediaRequest; -import mircoders.media.UnsupportedMediaFormatExc; -import mircoders.module.ModuleComment; -import mircoders.module.ModuleContent; -import mircoders.module.ModuleImages; -import mircoders.module.ModuleTopics; -import mircoders.search.AudioSearchTerm; -import mircoders.search.ContentSearchTerm; -import mircoders.search.ImagesSearchTerm; -import mircoders.search.KeywordSearchTerm; -import mircoders.search.TextSearchTerm; -import mircoders.search.TopicSearchTerm; -import mircoders.search.UnIndexedSearchTerm; -import mircoders.search.VideoSearchTerm; -import mircoders.storage.DatabaseComment; -import mircoders.storage.DatabaseContent; -import mircoders.storage.DatabaseContentToMedia; -import mircoders.storage.DatabaseContentToTopics; -import mircoders.storage.DatabaseImages; -import mircoders.storage.DatabaseLanguage; -import mircoders.storage.DatabaseTopics; - -import org.apache.commons.net.smtp.SMTPClient; -import org.apache.commons.net.smtp.SMTPReply; -import org.apache.fop.apps.Driver; -import org.apache.fop.apps.XSLTInputHandler; -import org.apache.log.Hierarchy; -import org.apache.log.Priority; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.queryParser.QueryParser; -import org.apache.lucene.search.Hits; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.Searcher; - -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModelRoot; - -/* - * ServletModuleOpenIndy - - * is the open-access-servlet, which is responsible for - * adding comments to articles & - * open-postings to the newswire - * - * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.67 2003/03/09 19:14:21 idfx Exp $ - * - */ - -public class ServletModuleOpenIndy extends ServletModule -{ - - private String commentFormTemplate, commentFormDoneTemplate, commentFormDupeTemplate; - private String postingFormTemplate, postingFormDoneTemplate, postingFormDupeTemplate; - private String searchResultsTemplate; - private String prepareMailTemplate,sentMailTemplate; - private ModuleContent contentModule; - private ModuleComment commentModule; - private ModuleImages imageModule; - private ModuleTopics topicsModule; - private String directOp ="yes"; - private String passwdProtection ="yes"; - // Singelton / Kontruktor - private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy(); - public static ServletModule getInstance() { return instance; } - - private ServletModuleOpenIndy() { - super(); - try { - logger = new LoggerWrapper("ServletModule.OpenIndy"); - - commentFormTemplate = configuration.getString("ServletModule.OpenIndy.CommentTemplate"); - commentFormDoneTemplate = configuration.getString("ServletModule.OpenIndy.CommentDoneTemplate"); - commentFormDupeTemplate = configuration.getString("ServletModule.OpenIndy.CommentDupeTemplate"); - postingFormTemplate = configuration.getString("ServletModule.OpenIndy.PostingTemplate"); - postingFormDoneTemplate = configuration.getString("ServletModule.OpenIndy.PostingDoneTemplate"); - postingFormDupeTemplate = configuration.getString("ServletModule.OpenIndy.PostingDupeTemplate"); - searchResultsTemplate = configuration.getString("ServletModule.OpenIndy.SearchResultsTemplate"); - prepareMailTemplate = configuration.getString("ServletModule.OpenIndy.PrepareMailTemplate"); - sentMailTemplate = configuration.getString("ServletModule.OpenIndy.SentMailTemplate"); - directOp = configuration.getString("DirectOpenposting").toLowerCase(); - passwdProtection = configuration.getString("PasswdProtection").toLowerCase(); - mainModule = new ModuleComment(DatabaseComment.getInstance()); - contentModule = new ModuleContent(DatabaseContent.getInstance()); - topicsModule = new ModuleTopics(DatabaseTopics.getInstance()); - imageModule = new ModuleImages(DatabaseImages.getInstance()); - defaultAction="addposting"; - } - catch (StorageObjectFailure e) { - logger.error("servletmoduleopenindy could not be initialized: " + e.getMessage()); - } - } - - - /** - * Method for making a comment - */ - - public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure - { - String aid = req.getParameter("aid"); // the article id the comment will belong to - String language = req.getParameter("language"); - - if (aid!=null && !aid.equals("")) { - try { - SimpleHash mergeData = new SimpleHash(); - - // onetimepasswd - if (passwdProtection.equals("yes")) { - String passwd = this.createOneTimePasswd(); - HttpSession session = req.getSession(false); - session.setAttribute("passwd", passwd); - mergeData.put("passwd", passwd); - } - - if (language != null) { - HttpSession session = req.getSession(false); - session.setAttribute("Locale", new Locale(language, "")); - session.setAttribute("passwd", language); - } - - mergeData.put("aid", aid); - - SimpleHash extraInfo = new SimpleHash(); - extraInfo.put("languagePopUpData", DatabaseLanguage.getInstance().getPopupData()); - - deliver(req, res, mergeData, extraInfo, commentFormTemplate); - } - catch (Throwable t) { - throw new ServletModuleFailure("ServletModuleOpenIndy.addcomment: " + t.getMessage(), t); - } - } - else throw new ServletModuleExc("aid not set!"); - } - - /** - * Method for inserting a comment into the Database and delivering - * the commentDone Page - */ - - public void inscomment(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure - { - String aid = req.getParameter("to_media"); // the article id the comment will belong to - if (aid!=null && !aid.equals("")) - { - // ok, collecting data from form - try { - Map withValues = getIntersectingValues(req, DatabaseComment.getInstance()); - - //no html in comments(for now) - for (Iterator i=withValues.keySet().iterator(); i.hasNext(); ){ - String k=(String)i.next(); - String v=(String)withValues.get(k); - - withValues.put(k,StringUtil.removeHTMLTags(v)); - } - withValues.put("is_published","1"); - withValues.put("to_comment_status","1"); - - //checking the onetimepasswd - if(passwdProtection.equals("yes")){ - HttpSession session = req.getSession(false); - String sessionPasswd = (String)session.getAttribute("passwd"); - if ( sessionPasswd == null){ - throw new ServletModuleExc("Lost password"); - } - String passwd = req.getParameter("passwd"); - if ( passwd == null || passwd.length()==0) { - throw new ServletModuleUserExc("comment.error.missingpassword", new String[] {}); - } - if (!sessionPasswd.equals(passwd)) { - throw new ServletModuleUserExc("comment.error.invalidpassword", new String[] {}); - } - session.invalidate(); - } - - // inserting into database - String id = mainModule.add(withValues); - logger.debug("id: "+id); - //insert was not successfull - if(id==null){ - deliver(req, res, new SimpleHash(), commentFormDupeTemplate); - } - else { - DatabaseContent.getInstance().setUnproduced("id="+aid); - - try { - EntityComment comment = (EntityComment) DatabaseComment.getInstance().selectById(id); - MirGlobal.localizer().openPostings().afterCommentPosting(comment); - } - catch (Throwable t) { - throw new ServletModuleExc(t.getMessage()); - } - } - - // redirecting to url - // should implement back to article - SimpleHash mergeData = new SimpleHash(); - deliver(req, res, mergeData, commentFormDoneTemplate); - } - catch (Throwable e) { - throw new ServletModuleFailure(e); - } - } - else throw new ServletModuleExc("aid not set!"); - - } - - /** - * Method for delivering the form-Page for open posting - */ - - public void addposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure - { - SimpleHash mergeData = new SimpleHash(); - - // onetimepasswd - if(passwdProtection.equals("yes")){ - String passwd = this.createOneTimePasswd(); - HttpSession session = req.getSession(false); - session.setAttribute("passwd",passwd); - mergeData.put("passwd", passwd); - } - - String maxMedia = configuration.getString("ServletModule.OpenIndy.MaxMediaUploadItems"); - String defaultMedia = configuration.getString("ServletModule.OpenIndy.DefaultMediaUploadItems"); - String numOfMedia = req.getParameter("medianum"); - - if(numOfMedia==null||numOfMedia.equals("")){ - numOfMedia=defaultMedia; - } - else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) { - numOfMedia = maxMedia; - } - - int mediaNum = Integer.parseInt(numOfMedia); - SimpleList mediaFields = new SimpleList(); - for(int i =0; i 0) { - try{ - DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr); - setTopic = true; - } - catch (Throwable e) { - logger.error("setting content_x_topic failed"); - contentModule.deleteById(cid); - throw new ServletModuleFailure("smod - openindy :: insposting: setting content_x_topic failed: "+e.toString(), e); - } //end try - } //end if - - //if we're here all is ok... associate the media to the article - for(int i=0;i= totalHits) - newPosition=totalHits-1; - session.setAttribute("positionInResults",new Integer(newPosition)); - } - else { - if (searchForwardValue != null){ - int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue(); - int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()+increment; - if (newPosition<0) - newPosition=0; - if (newPosition >= totalHits) - newPosition=totalHits-1; - - session.setAttribute("positionInResults",new Integer(newPosition)); - } - else { - String indexPath=configuration.getString("IndexPath"); - - - String creatorFragment = creatorTerm.makeTerm(req); - if (creatorFragment != null){ - queryString = queryString + " +" + creatorFragment; - } - - // search title, description, and content for something - // the contentTerm uses param "search_boolean" to combine its terms - String contentFragment = contentTerm.makeTerm(req); - if (contentFragment != null){ - logger.debug("contentFragment: " + contentFragment); - queryString = queryString + " +" + contentFragment; - } - - String topicFragment = topicTerm.makeTerm(req); - if (topicFragment != null){ - queryString = queryString + " +" + topicFragment; - } - - String imagesFragment = imagesTerm.makeTerm(req); - if (imagesFragment != null){ - queryString = queryString + " +" + imagesFragment; - } - - String audioFragment = audioTerm.makeTerm(req); - if (audioFragment != null){ - queryString = queryString + " +" + audioFragment; - } - - String videoFragment = videoTerm.makeTerm(req); - if (videoFragment != null){ - queryString = queryString + " +" + videoFragment; - } - - if (queryString == null || queryString == ""){ - queryString = ""; - } - else{ - try{ - Searcher searcher = null; - try { - searcher = new IndexSearcher(indexPath); - } - catch(IOException e) { - logger.debug("Can't open indexPath: " + indexPath); - throw new ServletModuleExc("Problem with Search Index! : "+ e.toString()); - } - - Query query = null; - try { - query = QueryParser.parse(queryString, "content", new StandardAnalyzer()); - } - catch(Exception e) { - searcher.close(); - logger.debug("Query don't parse: " + queryString); - throw new ServletModuleExc("Problem with Query String! (was '"+queryString+"')"); - } - - Hits hits = null; - try { - hits = searcher.search(query); - } - catch(IOException e) { - searcher.close(); - logger.debug("Can't get hits: " + e.toString()); - throw new ServletModuleExc("Problem getting hits!"); - } - - int start = 0; - int end = hits.length(); - - String sortBy=req.getParameter("search_sort"); - if (sortBy == null || sortBy.equals("")){ - throw new ServletModuleExc("Please let me sort by something!(missing search_sort)"); - } - - // here is where the documents will go for storage across sessions - ArrayList theDocumentsSorted = new ArrayList(); - - if (sortBy.equals("score")){ - for(int i = start; i < end; i++) { - theDocumentsSorted.add(hits.doc(i)); - } - } - else{ - // then we'll sort by date! - Map dateToPosition = new HashMap(end,1.0F); //we know how big it will be - for(int i = start; i < end; i++) { - String creationDate=(hits.doc(i)).get("creationDate"); - // do a little dance in case two contents created at the same second! - if (dateToPosition.containsKey(creationDate)){ - ((ArrayList) (dateToPosition.get(creationDate))).add(new Integer(i)); - } - else{ - ArrayList thePositions = new ArrayList(); - thePositions.add(new Integer(i)); - dateToPosition.put(creationDate,thePositions); - } - } - Set keys = dateToPosition.keySet(); - ArrayList keyList= new ArrayList(keys); - Collections.sort(keyList); - if (sortBy.equals("date_desc")){ - Collections.reverse(keyList); - } - else{ - if (!sortBy.equals("date_asc")){ - throw new ServletModuleExc("don't know how to sort by: "+ sortBy); - } - } - ListIterator keyTraverser = keyList.listIterator(); - while (keyTraverser.hasNext()){ - ArrayList positions = (ArrayList)dateToPosition.get((keyTraverser.next())); - ListIterator positionsTraverser=positions.listIterator(); - while (positionsTraverser.hasNext()){ - theDocumentsSorted.add(hits.doc(((Integer)(positionsTraverser.next())).intValue())); - } - } - } - - try{ - searcher.close(); - } - catch (IOException e){ - logger.debug("Can't close searcher: " + e.toString()); - throw new ServletModuleFailure("Problem closing searcher(normal):" + e.getMessage(), e); - } - - - session.removeAttribute("numberOfHits"); - session.removeAttribute("theDocumentsSorted"); - session.removeAttribute("positionInResults"); - - session.setAttribute("numberOfHits",new Integer(end)); - session.setAttribute("theDocumentsSorted",theDocumentsSorted); - session.setAttribute("positionInResults",new Integer(0)); - - } - catch (IOException e){ - logger.debug("Can't close searcher: " + e.toString()); - throw new ServletModuleFailure("Problem closing searcher: " + e.getMessage(), e); - } - } - } - } - - try { - ArrayList theDocs = (ArrayList)session.getAttribute("theDocumentsSorted"); - if (theDocs != null){ - - mergeData.put("numberOfHits", ((Integer)session.getAttribute("numberOfHits")).toString()); - SimpleList theHits = new SimpleList(); - int pIR=((Integer)session.getAttribute("positionInResults")).intValue(); - int terminus; - int numHits=((Integer)session.getAttribute("numberOfHits")).intValue(); - - if (!(pIR+increment>=numHits)){ - mergeData.put("hasNext","y"); - } - if (pIR>0){ - mergeData.put("hasPrevious","y"); - } - - if ((pIR+increment)>numHits){ - terminus=numHits; - } - else { - terminus=pIR+increment; - } - for(int i = pIR; i < terminus; i++) { - SimpleHash h = new SimpleHash(); - Document theHit = (Document)theDocs.get(i); - whereTerm.returnMeta(h,theHit); - creatorTerm.returnMeta(h,theHit); - titleTerm.returnMeta(h,theHit); - descriptionTerm.returnMeta(h,theHit); - dateTerm.returnMeta(h,theHit); - imagesTerm.returnMeta(h,theHit); - audioTerm.returnMeta(h,theHit); - videoTerm.returnMeta(h,theHit); - theHits.add(h); - } - mergeData.put("hits",theHits); - } - } - catch (Throwable e) { - logger.error("Can't iterate over hits: " + e.toString()); - - throw new ServletModuleFailure("Problem getting hits: " + e.getMessage(), e); - } - - mergeData.put("queryString",queryString); - deliver(req,res,mergeData,searchResultsTemplate); - } - catch (NullPointerException n){ - throw new ServletModuleFailure("Null Pointer: "+n.toString(), n); - } - } - - /* - * Method for dynamically generating a pdf from a fo file - */ - public void getpdf(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { - String ID_REQUEST_PARAM = "id"; - String language = req.getParameter("language"); - String generateFO=configuration.getString("GenerateFO"); - String generatePDF=configuration.getString("GeneratePDF"); - - - //don't do anything if we are not making FO files, or if we are - //pregenerating PDF's - if (generateFO.equals("yes") && generatePDF.equals("no")){ - //fop complains unless you do the logging this way - org.apache.log.Logger log = null; - Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); - log = hierarchy.getLoggerFor("fop"); - log.setPriority(Priority.WARN); - - String producerStorageRoot=configuration.getString("Producer.StorageRoot"); - String producerDocRoot=configuration.getString("Producer.DocRoot"); - // String templateDir=MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir"); - String xslSheet=configuration.getString("Producer.HTML2FOStyleSheet"); - try { - String idParam = req.getParameter(ID_REQUEST_PARAM); - if (idParam != null) { - EntityContent contentEnt = - (EntityContent)contentModule.getById(idParam); - String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date")); - String foFile; - - if (language == null){ - foFile = producerStorageRoot + producerDocRoot + "/" - + publishPath + idParam + ".fo"; - } - else{ - foFile = producerStorageRoot + producerDocRoot + "/" - + language + publishPath + idParam + ".fo"; - } - logger.debug("USING FILES" + foFile + " and " + xslSheet); - XSLTInputHandler input = new XSLTInputHandler(new File(foFile), - new File(xslSheet)); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - res.setContentType("application/pdf"); - - Driver driver = new Driver(); - driver.setLogger(log); - driver.setRenderer(Driver.RENDER_PDF); - driver.setOutputStream(out); - driver.render(input.getParser(), input.getInputSource()); - - byte[] content = out.toByteArray(); - res.setContentLength(content.length); - res.getOutputStream().write(content); - res.getOutputStream().flush(); - } - else { - throw new ServletModuleExc("Missing id."); - } - } - catch (Exception ex) { - logger.error(ex.toString()); - throw new ServletModuleFailure(ex); - } - } else { - throw new ServletModuleExc("Can't generate a PDF because the config tells me not to."); - } - } - - protected String createOneTimePasswd(){ - Random r = new Random(); - int random = r.nextInt(); - long l = System.currentTimeMillis(); - l = (l*l*l*l)/random; - if(l<0) l = l * -1; - String returnString = ""+l; - return returnString.substring(5); - } - - - /* this is an overwritten method of ServletModule in order - to use different bundles for open and admin */ - public void deliver(HttpServletRequest req, HttpServletResponse res, - TemplateModelRoot rtm, TemplateModelRoot popups, - String templateFilename) throws ServletModuleFailure - { - if (rtm == null) rtm = new SimpleHash(); - try { - PrintWriter out = res.getWriter(); - HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, - getLocale(req), "bundles.open"); - out.close(); - } - catch (Throwable e) { - throw new ServletModuleFailure(e); - } - } -} - - - +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.servlet; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Enumeration; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.ListIterator; +import java.util.Locale; +import java.util.Map; +import java.util.Random; +import java.util.Set; + + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import mir.entity.Entity; +import mir.entity.EntityList; +import mir.log.LoggerWrapper; +import mir.misc.FileHandler; +import mir.misc.HTMLTemplateProcessor; +import mir.misc.StringUtil; +import mir.misc.WebdbMultipartRequest; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; +import mir.servlet.ServletModuleUserExc; +import mir.storage.StorageObjectFailure; +import mir.util.ExceptionFunctions; +import mir.util.StringRoutines; + +import mircoders.entity.EntityComment; +import mircoders.entity.EntityContent; +import mircoders.global.MirGlobal; +import mircoders.global.Abuse; +import mircoders.media.MediaRequest; +import mircoders.media.UnsupportedMediaFormatExc; +import mircoders.module.ModuleComment; +import mircoders.module.ModuleContent; +import mircoders.module.ModuleImages; +import mircoders.module.ModuleTopics; +import mircoders.search.AudioSearchTerm; +import mircoders.search.ContentSearchTerm; +import mircoders.search.ImagesSearchTerm; +import mircoders.search.KeywordSearchTerm; +import mircoders.search.TextSearchTerm; +import mircoders.search.TopicSearchTerm; +import mircoders.search.UnIndexedSearchTerm; +import mircoders.search.VideoSearchTerm; +import mircoders.storage.DatabaseComment; +import mircoders.storage.DatabaseContent; +import mircoders.storage.DatabaseContentToMedia; +import mircoders.storage.DatabaseContentToTopics; +import mircoders.storage.DatabaseImages; +import mircoders.storage.DatabaseLanguage; +import mircoders.storage.DatabaseTopics; +import mircoders.global.*; + +import org.apache.commons.net.smtp.SMTPClient; +import org.apache.commons.net.smtp.SMTPReply; +import org.apache.fop.apps.Driver; +import org.apache.fop.apps.XSLTInputHandler; +import org.apache.log.Hierarchy; +import org.apache.log.Priority; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.Hits; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Searcher; + +import freemarker.template.SimpleHash; +import freemarker.template.SimpleList; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModelRoot; + +/* + * ServletModuleOpenIndy - + * is the open-access-servlet, which is responsible for + * adding comments to articles & + * open-postings to the newswire + * + * @author mir-coders group + * @version $Id: ServletModuleOpenIndy.java,v 1.68 2003/03/15 15:35:57 zapata Exp $ + * + */ + +public class ServletModuleOpenIndy extends ServletModule +{ + + private String commentFormTemplate, commentFormDoneTemplate, commentFormDupeTemplate; + private String postingFormTemplate, postingFormDoneTemplate, postingFormDupeTemplate; + private String searchResultsTemplate; + private String prepareMailTemplate,sentMailTemplate; + private ModuleContent contentModule; + private ModuleComment commentModule; + private ModuleImages imageModule; + private ModuleTopics topicsModule; + private String directOp ="yes"; + // Singelton / Kontruktor + private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy(); + public static ServletModule getInstance() { return instance; } + + private ServletModuleOpenIndy() { + super(); + try { + logger = new LoggerWrapper("ServletModule.OpenIndy"); + + commentFormTemplate = configuration.getString("ServletModule.OpenIndy.CommentTemplate"); + commentFormDoneTemplate = configuration.getString("ServletModule.OpenIndy.CommentDoneTemplate"); + commentFormDupeTemplate = configuration.getString("ServletModule.OpenIndy.CommentDupeTemplate"); + postingFormTemplate = configuration.getString("ServletModule.OpenIndy.PostingTemplate"); + postingFormDoneTemplate = configuration.getString("ServletModule.OpenIndy.PostingDoneTemplate"); + postingFormDupeTemplate = configuration.getString("ServletModule.OpenIndy.PostingDupeTemplate"); + searchResultsTemplate = configuration.getString("ServletModule.OpenIndy.SearchResultsTemplate"); + prepareMailTemplate = configuration.getString("ServletModule.OpenIndy.PrepareMailTemplate"); + sentMailTemplate = configuration.getString("ServletModule.OpenIndy.SentMailTemplate"); + directOp = configuration.getString("DirectOpenposting").toLowerCase(); + mainModule = new ModuleComment(DatabaseComment.getInstance()); + contentModule = new ModuleContent(DatabaseContent.getInstance()); + topicsModule = new ModuleTopics(DatabaseTopics.getInstance()); + imageModule = new ModuleImages(DatabaseImages.getInstance()); + defaultAction="addposting"; + } + catch (StorageObjectFailure e) { + logger.error("servletmoduleopenindy could not be initialized: " + e.getMessage()); + } + } + + /** + * Method to return an "apology" when open postings are disabled + * + * @param aRequest + * @param aResponse + * @throws ServletModuleExc + * @throws ServletModuleUserExc + * @throws ServletModuleFailure + */ + public void openPostingDisabled(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { + deliver(aRequest, aResponse, new SimpleHash(), + configuration.getString("ServletModule.OpenIndy.PostingDisabledTemplate")); + } + + + /** + * Method for making a comment + */ + + public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + { + if (MirGlobal.abuse().getOpenPostingDisabled()) { + openPostingDisabled(req, res); + + return; + } + + String aid = req.getParameter("aid"); // the article id the comment will belong to + String language = req.getParameter("language"); + + if (aid!=null && !aid.equals("")) { + try { + SimpleHash mergeData = new SimpleHash(); + + // onetimepasswd + if (MirGlobal.abuse().getOpenPostingPassword()) { + String passwd = this.createOneTimePasswd(); + HttpSession session = req.getSession(false); + session.setAttribute("passwd", passwd); + mergeData.put("passwd", passwd); + } + else { + mergeData.put("passwd", (String) null); + } + + if (language != null) { + HttpSession session = req.getSession(false); + session.setAttribute("Locale", new Locale(language, "")); + session.setAttribute("language", language); + } + + mergeData.put("aid", aid); + + SimpleHash extraInfo = new SimpleHash(); + extraInfo.put("languagePopUpData", DatabaseLanguage.getInstance().getPopupData()); + + deliver(req, res, mergeData, extraInfo, commentFormTemplate); + } + catch (Throwable t) { + throw new ServletModuleFailure("ServletModuleOpenIndy.addcomment: " + t.getMessage(), t); + } + } + else throw new ServletModuleExc("aid not set!"); + } + + /** + * Method for inserting a comment into the Database and delivering + * the commentDone Page + */ + + public void inscomment(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + { + if (MirGlobal.abuse().getOpenPostingDisabled()) { + openPostingDisabled(req, res); + + return; + } + + String aid = req.getParameter("to_media"); // the article id the comment will belong to + if (aid!=null && !aid.equals("")) + { + // ok, collecting data from form + try { + Map withValues = getIntersectingValues(req, DatabaseComment.getInstance()); + + //no html in comments(for now) + for (Iterator i=withValues.keySet().iterator(); i.hasNext(); ){ + String k=(String)i.next(); + String v=(String)withValues.get(k); + + withValues.put(k,StringUtil.removeHTMLTags(v)); + } + withValues.put("is_published","1"); + withValues.put("to_comment_status","1"); + + //checking the onetimepasswd + HttpSession session = req.getSession(false); + String sessionPasswd = (String) session.getAttribute("passwd"); + if ( sessionPasswd != null){ + String passwd = req.getParameter("passwd"); + if ( passwd == null || passwd.length()==0) { + throw new ServletModuleUserExc("comment.error.missingpassword", new String[] {}); + } + if (!sessionPasswd.equals(passwd)) { + throw new ServletModuleUserExc("comment.error.invalidpassword", new String[] {}); + } + session.invalidate(); + } + + String id = mainModule.add(withValues); + + if(id==null){ + deliver(req, res, new SimpleHash(), commentFormDupeTemplate); + } + else { + MirGlobal.abuse().logComment(req.getRemoteAddr(), id, new Date(), (String) req.getHeader("User-Agent")); + + DatabaseContent.getInstance().setUnproduced("id="+aid); + + try { + EntityComment comment = (EntityComment) DatabaseComment.getInstance().selectById(id); + MirGlobal.abuse().checkComment(comment, req, res); + MirGlobal.localizer().openPostings().afterCommentPosting(comment); + } + catch (Throwable t) { + throw new ServletModuleExc(t.getMessage()); + } + } + + // redirecting to url + // should implement back to article + SimpleHash mergeData = new SimpleHash(); + deliver(req, res, mergeData, commentFormDoneTemplate); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } + else throw new ServletModuleExc("aid not set!"); + + } + + /** + * Method for delivering the form-Page for open posting + */ + + public void addposting(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + { + if (MirGlobal.abuse().getOpenPostingDisabled()) { + openPostingDisabled(req, res); + + return; + } + + SimpleHash mergeData = new SimpleHash(); + + // onetimepasswd + if (MirGlobal.abuse().getOpenPostingPassword()) { + String passwd = this.createOneTimePasswd(); + HttpSession session = req.getSession(false); + session.setAttribute("passwd",passwd); + mergeData.put("passwd", passwd); + } + else { + mergeData.put("passwd", (String) null); + } + + + String maxMedia = configuration.getString("ServletModule.OpenIndy.MaxMediaUploadItems"); + String defaultMedia = configuration.getString("ServletModule.OpenIndy.DefaultMediaUploadItems"); + String numOfMedia = req.getParameter("medianum"); + + if(numOfMedia==null||numOfMedia.equals("")){ + numOfMedia=defaultMedia; + } + else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) { + numOfMedia = maxMedia; + } + + int mediaNum = Integer.parseInt(numOfMedia); + SimpleList mediaFields = new SimpleList(); + for(int i =0; i 0) { + try{ + DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr); + setTopic = true; + } + catch (Throwable e) { + logger.error("setting content_x_topic failed"); + contentModule.deleteById(cid); + throw new ServletModuleFailure("smod - openindy :: insposting: setting content_x_topic failed: "+e.toString(), e); + } //end try + } //end if + + //if we're here all is ok... associate the media to the article + for(int i=0;i= totalHits) + newPosition=totalHits-1; + session.setAttribute("positionInResults",new Integer(newPosition)); + } + else { + if (searchForwardValue != null){ + int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue(); + int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()+increment; + if (newPosition<0) + newPosition=0; + if (newPosition >= totalHits) + newPosition=totalHits-1; + + session.setAttribute("positionInResults",new Integer(newPosition)); + } + else { + String indexPath=configuration.getString("IndexPath"); + + + String creatorFragment = creatorTerm.makeTerm(req); + if (creatorFragment != null){ + queryString = queryString + " +" + creatorFragment; + } + + // search title, description, and content for something + // the contentTerm uses param "search_boolean" to combine its terms + String contentFragment = contentTerm.makeTerm(req); + if (contentFragment != null){ + logger.debug("contentFragment: " + contentFragment); + queryString = queryString + " +" + contentFragment; + } + + String topicFragment = topicTerm.makeTerm(req); + if (topicFragment != null){ + queryString = queryString + " +" + topicFragment; + } + + String imagesFragment = imagesTerm.makeTerm(req); + if (imagesFragment != null){ + queryString = queryString + " +" + imagesFragment; + } + + String audioFragment = audioTerm.makeTerm(req); + if (audioFragment != null){ + queryString = queryString + " +" + audioFragment; + } + + String videoFragment = videoTerm.makeTerm(req); + if (videoFragment != null){ + queryString = queryString + " +" + videoFragment; + } + + if (queryString == null || queryString == ""){ + queryString = ""; + } + else{ + try{ + Searcher searcher = null; + try { + searcher = new IndexSearcher(indexPath); + } + catch(IOException e) { + logger.debug("Can't open indexPath: " + indexPath); + throw new ServletModuleExc("Problem with Search Index! : "+ e.toString()); + } + + Query query = null; + try { + query = QueryParser.parse(queryString, "content", new StandardAnalyzer()); + } + catch(Exception e) { + searcher.close(); + logger.debug("Query don't parse: " + queryString); + throw new ServletModuleExc("Problem with Query String! (was '"+queryString+"')"); + } + + Hits hits = null; + try { + hits = searcher.search(query); + } + catch(IOException e) { + searcher.close(); + logger.debug("Can't get hits: " + e.toString()); + throw new ServletModuleExc("Problem getting hits!"); + } + + int start = 0; + int end = hits.length(); + + String sortBy=req.getParameter("search_sort"); + if (sortBy == null || sortBy.equals("")){ + throw new ServletModuleExc("Please let me sort by something!(missing search_sort)"); + } + + // here is where the documents will go for storage across sessions + ArrayList theDocumentsSorted = new ArrayList(); + + if (sortBy.equals("score")){ + for(int i = start; i < end; i++) { + theDocumentsSorted.add(hits.doc(i)); + } + } + else{ + // then we'll sort by date! + Map dateToPosition = new HashMap(end,1.0F); //we know how big it will be + for(int i = start; i < end; i++) { + String creationDate=(hits.doc(i)).get("creationDate"); + // do a little dance in case two contents created at the same second! + if (dateToPosition.containsKey(creationDate)){ + ((ArrayList) (dateToPosition.get(creationDate))).add(new Integer(i)); + } + else{ + ArrayList thePositions = new ArrayList(); + thePositions.add(new Integer(i)); + dateToPosition.put(creationDate,thePositions); + } + } + Set keys = dateToPosition.keySet(); + ArrayList keyList= new ArrayList(keys); + Collections.sort(keyList); + if (sortBy.equals("date_desc")){ + Collections.reverse(keyList); + } + else{ + if (!sortBy.equals("date_asc")){ + throw new ServletModuleExc("don't know how to sort by: "+ sortBy); + } + } + ListIterator keyTraverser = keyList.listIterator(); + while (keyTraverser.hasNext()){ + ArrayList positions = (ArrayList)dateToPosition.get((keyTraverser.next())); + ListIterator positionsTraverser=positions.listIterator(); + while (positionsTraverser.hasNext()){ + theDocumentsSorted.add(hits.doc(((Integer)(positionsTraverser.next())).intValue())); + } + } + } + + try{ + searcher.close(); + } + catch (IOException e){ + logger.debug("Can't close searcher: " + e.toString()); + throw new ServletModuleFailure("Problem closing searcher(normal):" + e.getMessage(), e); + } + + + session.removeAttribute("numberOfHits"); + session.removeAttribute("theDocumentsSorted"); + session.removeAttribute("positionInResults"); + + session.setAttribute("numberOfHits",new Integer(end)); + session.setAttribute("theDocumentsSorted",theDocumentsSorted); + session.setAttribute("positionInResults",new Integer(0)); + + } + catch (IOException e){ + logger.debug("Can't close searcher: " + e.toString()); + throw new ServletModuleFailure("Problem closing searcher: " + e.getMessage(), e); + } + } + } + } + + try { + ArrayList theDocs = (ArrayList)session.getAttribute("theDocumentsSorted"); + if (theDocs != null){ + + mergeData.put("numberOfHits", ((Integer)session.getAttribute("numberOfHits")).toString()); + SimpleList theHits = new SimpleList(); + int pIR=((Integer)session.getAttribute("positionInResults")).intValue(); + int terminus; + int numHits=((Integer)session.getAttribute("numberOfHits")).intValue(); + + if (!(pIR+increment>=numHits)){ + mergeData.put("hasNext","y"); + } + if (pIR>0){ + mergeData.put("hasPrevious","y"); + } + + if ((pIR+increment)>numHits){ + terminus=numHits; + } + else { + terminus=pIR+increment; + } + for(int i = pIR; i < terminus; i++) { + SimpleHash h = new SimpleHash(); + Document theHit = (Document)theDocs.get(i); + whereTerm.returnMeta(h,theHit); + creatorTerm.returnMeta(h,theHit); + titleTerm.returnMeta(h,theHit); + descriptionTerm.returnMeta(h,theHit); + dateTerm.returnMeta(h,theHit); + imagesTerm.returnMeta(h,theHit); + audioTerm.returnMeta(h,theHit); + videoTerm.returnMeta(h,theHit); + theHits.add(h); + } + mergeData.put("hits",theHits); + } + } + catch (Throwable e) { + logger.error("Can't iterate over hits: " + e.toString()); + + throw new ServletModuleFailure("Problem getting hits: " + e.getMessage(), e); + } + + mergeData.put("queryString",queryString); + deliver(req,res,mergeData,searchResultsTemplate); + } + catch (NullPointerException n){ + throw new ServletModuleFailure("Null Pointer: "+n.toString(), n); + } + } + + /* + * Method for dynamically generating a pdf from a fo file + */ + public void getpdf(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { + String ID_REQUEST_PARAM = "id"; + String language = req.getParameter("language"); + String generateFO=configuration.getString("GenerateFO"); + String generatePDF=configuration.getString("GeneratePDF"); + + + //don't do anything if we are not making FO files, or if we are + //pregenerating PDF's + if (generateFO.equals("yes") && generatePDF.equals("no")){ + //fop complains unless you do the logging this way + org.apache.log.Logger log = null; + Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); + log = hierarchy.getLoggerFor("fop"); + log.setPriority(Priority.WARN); + + String producerStorageRoot=configuration.getString("Producer.StorageRoot"); + String producerDocRoot=configuration.getString("Producer.DocRoot"); + // String templateDir=MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir"); + String xslSheet=configuration.getString("Producer.HTML2FOStyleSheet"); + try { + String idParam = req.getParameter(ID_REQUEST_PARAM); + if (idParam != null) { + EntityContent contentEnt = + (EntityContent)contentModule.getById(idParam); + String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date")); + String foFile; + + if (language == null){ + foFile = producerStorageRoot + producerDocRoot + "/" + + publishPath + idParam + ".fo"; + } + else{ + foFile = producerStorageRoot + producerDocRoot + "/" + + language + publishPath + idParam + ".fo"; + } + logger.debug("USING FILES" + foFile + " and " + xslSheet); + XSLTInputHandler input = new XSLTInputHandler(new File(foFile), + new File(xslSheet)); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + res.setContentType("application/pdf"); + + Driver driver = new Driver(); + driver.setLogger(log); + driver.setRenderer(Driver.RENDER_PDF); + driver.setOutputStream(out); + driver.render(input.getParser(), input.getInputSource()); + + byte[] content = out.toByteArray(); + res.setContentLength(content.length); + res.getOutputStream().write(content); + res.getOutputStream().flush(); + } + else { + throw new ServletModuleExc("Missing id."); + } + } + catch (Exception ex) { + logger.error(ex.toString()); + throw new ServletModuleFailure(ex); + } + } else { + throw new ServletModuleExc("Can't generate a PDF because the config tells me not to."); + } + } + + protected String createOneTimePasswd(){ + Random r = new Random(); + int random = r.nextInt(); + long l = System.currentTimeMillis(); + l = (l*l*l*l)/random; + if(l<0) l = l * -1; + String returnString = ""+l; + return returnString.substring(5); + } + + + /* this is an overwritten method of ServletModule in order + to use different bundles for open and admin */ + public void deliver(HttpServletRequest req, HttpServletResponse res, + TemplateModelRoot rtm, TemplateModelRoot popups, + String templateFilename) throws ServletModuleFailure + { + if (rtm == null) rtm = new SimpleHash(); + try { + PrintWriter out = res.getWriter(); + HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, + getLocale(req), "bundles.open"); + out.close(); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } +} + + + diff --git a/templates/admin/abuse.filters.template b/templates/admin/abuse.filters.template new file mode 100755 index 00000000..23b00ace --- /dev/null +++ b/templates/admin/abuse.filters.template @@ -0,0 +1,67 @@ + +
+ + + + + + + + + + + + + + + + ${lang("delete")} +   + + + + + + + +
+
+ + + ${config["Mir.Name"]} | ${lang("userlist.htmltitle")} + + + + + +

+ ${lang("back")} +

+ + + + + + + + + + + + + +
${lang("abuse.filter.type")}${lang("abuse.filter.expression")} 
+ +

+ ${lang("back")} +

+ + + + + + diff --git a/templates/admin/abuse.log.template b/templates/admin/abuse.log.template new file mode 100755 index 00000000..a0cc9b8c --- /dev/null +++ b/templates/admin/abuse.log.template @@ -0,0 +1,46 @@ + + + ${config["Mir.Name"]} | ${lang("abuse.log.htmltitle")} + + + + + +

+ ${lang("back")} +

+ + + + + + + + + + + + + + + + + + +
${lang("abuse.log.time")}${lang("abuse.log.address")}${lang("abuse.log.object")}${lang("abuse.log.browser")}
${l.timestamp["yyyy-MM-dd HH:mm"]}${l.ip} + + Article + + Comment + + ${l.browser}
+ +

+ ${lang("back")} +

+ + + + + + diff --git a/templates/admin/abuse.template b/templates/admin/abuse.template new file mode 100755 index 00000000..34296695 --- /dev/null +++ b/templates/admin/abuse.template @@ -0,0 +1,108 @@ + + + ${config["Mir.Name"]} | ${lang("userlist.htmltitle")} + + + + + +

+ ${lang("back")} +

+

+ ${lang("abuse.showlog")} +

+

+ ${lang("abuse.showfilters")} +

+

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
${lang("abuse.setting")}${lang("abuse.value")}
+ ${lang("abuse.disableopenpostings")} + + checked="1"> +
+ ${lang("abuse.openpostingpassword")} + + checked="1"> +
+ ${lang("abuse.logpostings")} + + checked="1"> +
+ ${lang("abuse.logsize")}' + + +
+ ${lang("abuse.cookies")} + + checked="1"> +
+ ${lang("abuse.articleaction")} + + +
+ ${lang("abuse.commentaction")} + + +
+

+ +

+ + ${lang("abuse.showfilters")} +

+ +

+ ${lang("back")} +

+ + + + + + diff --git a/templates/admin/superusermenu.template b/templates/admin/superusermenu.template index a9b8583b..d79d8910 100755 --- a/templates/admin/superusermenu.template +++ b/templates/admin/superusermenu.template @@ -22,6 +22,9 @@ ${lang("superusermenu.languages")}

+ ${lang("superusermenu.abuse")} + +

${lang("superusermenu.imcs")} -- 2.11.0