2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with any library licensed under the Apache Software License,
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23 * (or with modified versions of the above that use the same license as the above),
24 * and distribute linked combinations including the two. You must obey the
25 * GNU General Public License in all respects for all of the code used other than
26 * the above mentioned libraries. If you modify this file, you may extend this
27 * exception to your version of the file, but you are not obligated to do so.
28 * If you do not wish to do so, delete this exception statement from your version.
31 package mircoders.servlet;
33 import java.util.Locale;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
39 import mir.log.LoggerWrapper;
40 import mir.servlet.ServletModule;
41 import mir.servlet.ServletModuleFailure;
42 import mir.util.HTTPRequestParser;
43 import mir.util.URLBuilder;
44 import mircoders.global.MirGlobal;
46 public class ServletModuleAbuse extends ServletModule {
47 private static ServletModuleAbuse instance = new ServletModuleAbuse();
48 public static ServletModule getInstance() { return instance; }
50 private ServletModuleAbuse() {
51 logger = new LoggerWrapper("ServletModule.Abuse");
52 defaultAction = "showsettings";
55 public void editfilter(HttpServletRequest aRequest, HttpServletResponse aResponse) {
56 HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
58 String type=requestParser.getParameterWithDefault("type", "");
59 String id=requestParser.getParameterWithDefault("id", "");
60 String expression=requestParser.getParameterWithDefault("expression", "");
63 MirGlobal.abuse().addFilter(type, expression);
66 MirGlobal.abuse().setFilter(id, type, expression);
69 MirGlobal.abuse().save();
71 showfilters(aRequest, aResponse);
74 public void deletefilter(HttpServletRequest aRequest, HttpServletResponse aResponse) {
75 HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
77 String id=requestParser.getParameterWithDefault("id", "");
78 MirGlobal.abuse().deleteFilter(id);
80 MirGlobal.abuse().save();
82 showfilters(aRequest, aResponse);
85 public void showfilters(HttpServletRequest aRequest, HttpServletResponse aResponse) {
86 URLBuilder urlBuilder = new URLBuilder();
89 Map responseData = ServletHelper.makeGenerationData(new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
91 urlBuilder.setValue("module", "Abuse");
92 urlBuilder.setValue("do", "showfilters");
93 responseData.put("thisurl", urlBuilder.getQuery());
95 responseData.put("filters", MirGlobal.abuse().getFilters());
96 responseData.put("filtertypes", MirGlobal.abuse().getFilterTypes());
98 ServletHelper.generateResponse(aResponse.getWriter(), responseData, "abuse.filters.template");
100 catch (Throwable e) {
101 throw new ServletModuleFailure(e);
106 public void showsettings(HttpServletRequest aRequest, HttpServletResponse aResponse) {
107 URLBuilder urlBuilder = new URLBuilder();
110 Map responseData = ServletHelper.makeGenerationData(new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
112 urlBuilder.setValue("module", "Abuse");
113 urlBuilder.setValue("do", "showsettings");
115 responseData.put("thisurl", urlBuilder.getQuery());
117 responseData.put("articleactions", MirGlobal.abuse().getArticleActions());
118 responseData.put("commentactions", MirGlobal.abuse().getCommentActions());
120 responseData.put("disableop", new Boolean(MirGlobal.abuse().getOpenPostingDisabled()));
121 responseData.put("passwordop", new Boolean(MirGlobal.abuse().getOpenPostingPassword()));
122 responseData.put("logenabled", new Boolean(MirGlobal.abuse().getLogEnabled()));
123 responseData.put("logsize", Integer.toString(MirGlobal.abuse().getLogSize()));
124 responseData.put("usecookies", new Boolean(MirGlobal.abuse().getCookieOnBlock()));
125 responseData.put("articleaction", MirGlobal.abuse().getArticleBlockAction());
126 responseData.put("commentaction", MirGlobal.abuse().getCommentBlockAction());
128 ServletHelper.generateResponse(aResponse.getWriter(), responseData, "abuse.template");
130 catch (Throwable e) {
131 throw new ServletModuleFailure(e);
135 public void savesettings(HttpServletRequest aRequest, HttpServletResponse aResponse) {
137 HTTPRequestParser parser = new HTTPRequestParser(aRequest);
139 MirGlobal.abuse().setOpenPostingDisabled(parser.getParameterWithDefault("disableop", "").equals("1"));
140 MirGlobal.abuse().setOpenPostingPassword(parser.getParameterWithDefault("passwordop", "").equals("1"));
141 MirGlobal.abuse().setLogEnabled(parser.getParameterWithDefault("logenabled", "").equals("1"));
144 MirGlobal.abuse().setLogSize(parser.getIntegerWithDefault("logsize", MirGlobal.abuse().getLogSize()));
146 catch (Throwable t) {
149 MirGlobal.abuse().setCookieOnBlock(parser.getParameterWithDefault("usecookies", "").equals("1"));
151 MirGlobal.abuse().setArticleBlockAction(parser.getParameter("articleaction"));
152 MirGlobal.abuse().setCommentBlockAction(parser.getParameter("commentaction"));
154 MirGlobal.abuse().save();
156 showsettings(aRequest, aResponse);
158 catch (Throwable e) {
159 throw new ServletModuleFailure(e);
163 public void showlog(HttpServletRequest aRequest, HttpServletResponse aResponse) {
164 URLBuilder urlBuilder = new URLBuilder();
168 Map responseData = ServletHelper.makeGenerationData(new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
169 urlBuilder.setValue("module", "Abuse");
170 urlBuilder.setValue("do", "showlog");
171 responseData.put("thisurl", urlBuilder.getQuery());
173 responseData.put("log", MirGlobal.abuse().getLog());
175 ServletHelper.generateResponse(aResponse.getWriter(), responseData, "abuse.log.template");
177 catch (Throwable e) {
178 throw new ServletModuleFailure(e);