diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbd34c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,53 @@ +# +# Git ignore for fsim +# + +### Forbidden +*.log +*.cache +*.class +*.so +*.dll + +### Temp +*~ +.tmp +*.bak +*.swp +.~lock.* +.kate-swp + +### Eclipse +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA +.idea +*.iws +*.iml +*.ipr + +### NetBeans +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code +.vscode/ + +# mac finder +.DS_Store + +# windows exploder +Thumbs.db + +# kde dolphin +.directory diff --git a/README.md b/README.md index 9889a9c..2226305 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # fsim +Old ftp search engine + diff --git a/WebRoot/META-INF/MANIFEST.MF b/WebRoot/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/WebRoot/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/WebRoot/META-INF/context.xml b/WebRoot/META-INF/context.xml new file mode 100644 index 0000000..a00a104 --- /dev/null +++ b/WebRoot/META-INF/context.xml @@ -0,0 +1,74 @@ + + + + + + + + mail.smtp.host + localhost + + + + + + + \ No newline at end of file diff --git a/WebRoot/WEB-INF/classes/com/idca/fsim/resources/i18n/fsim_en_US.properties b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/i18n/fsim_en_US.properties new file mode 100644 index 0000000..008b9bd --- /dev/null +++ b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/i18n/fsim_en_US.properties @@ -0,0 +1,36 @@ + +fsim.title = FSIM: File Search Index Machine + +fsim.logo.alt = fsim-logo +fsim.logo.title = FSIM Searcher + +fsim.header.title = File Search + +fsim.topbar.results = Results: +fsim.topbar.resultsin = found in: +fsim.topbar.inms = ms. + +fsim.search.button = Search + + +fsim.bottombar.rendered = Rendered in: +fsim.bottombar.inms = ms. + +fsim.copyright =
Fsim is a product of idca.nl
(c)2005 idca + +fsim.tech.vcss.alt = Valid CSS +fsim.tech.vcss.title = This page has an valid css file. +fsim.tech.xhtml11.alt = Valid XHML 1.1 +fsim.tech.xhtml11.title = This page is build with XHTML technolocy. +fsim.tech.debian.alt = debian-logo +fsim.tech.debian.title = This service runs on Debian. +fsim.tech.java.alt = java-logo +fsim.tech.java.title = This service is written in java. +fsim.tech.postgres.alt = postgresql-logo +fsim.tech.postgres.title= This service uses an PostgreSQL DB. +fsim.tech.linux.alt = linux-logo +fsim.tech.linux.title = The OS runs Linux. +fsim.tech.tomcat.alt = tomcat-logo +fsim.tech.tomcat.title = Tomcat 5 J2EE WebServer. + +fsim.text = foo {0} bar \ No newline at end of file diff --git a/WebRoot/WEB-INF/classes/com/idca/fsim/resources/i18n/fsim_nl.properties b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/i18n/fsim_nl.properties new file mode 100644 index 0000000..c2cae3a --- /dev/null +++ b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/i18n/fsim_nl.properties @@ -0,0 +1,9 @@ + + +fsim.test = Mmmm dit is een test + + +fsim.copyright = Fsim is a product of idca.nl
(c)2005 idca + + + diff --git a/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/.cvsignore b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/.cvsignore new file mode 100644 index 0000000..0111248 --- /dev/null +++ b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/.cvsignore @@ -0,0 +1 @@ +logging-development.properties diff --git a/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/logging-development-example.properties b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/logging-development-example.properties new file mode 100644 index 0000000..011d7c1 --- /dev/null +++ b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/logging-development-example.properties @@ -0,0 +1,26 @@ +# +# COPY THIS FILE TO: logging-development.properties +# and set the properties correctly +# + +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = ALL + +# Set the default formatter for new ConsoleHandler instances ( was java.util.logging.SimpleFormatter) +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Set the default logging level for the root logger +.level = INFO + +#org.apache.tomcat.level = ALL +#org.apache.catalina.level = ALL +#org.apache.jasper.level = ALL +#org.apache.commons.level = ALL +#org.apache.myfaces.level = ALL +#org.hibernate.level = ALL +#com.opensymphony.oscache.level = ALL diff --git a/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/logging.properties b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/logging.properties new file mode 100644 index 0000000..fb0e579 --- /dev/null +++ b/WebRoot/WEB-INF/classes/com/idca/fsim/resources/logging/logging.properties @@ -0,0 +1,29 @@ +# +# THIS ARE THE LIVE logging properties +# when the context parameter "DEVELOPMENT" on true is set +# then we will try to read logging-development.properties. +# this parameter should be set in web-override.xml +# + +# +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = INFO + +# Set the default formatter for new ConsoleHandler instances ( was java.util.logging.SimpleFormatter) +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Set the default logging level for the root logger +.level = INFO + +#org.apache.tomcat.level = ALL +#org.apache.catalina.level = ALL +#org.apache.jasper.level = ALL +#org.apache.commons.level = ALL +#org.apache.myfaces.level = ALL +#org.hibernate.level = ALL +#com.opensymphony.oscache.level = ALL diff --git a/WebRoot/WEB-INF/fsim.xml b/WebRoot/WEB-INF/fsim.xml new file mode 100644 index 0000000..ac6329d --- /dev/null +++ b/WebRoot/WEB-INF/fsim.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebRoot/WEB-INF/lib/commons-beanutils-core.jar b/WebRoot/WEB-INF/lib/commons-beanutils-core.jar new file mode 100644 index 0000000..ce79cbe Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-beanutils-core.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-beanutils-src.jar b/WebRoot/WEB-INF/lib/commons-beanutils-src.jar new file mode 100644 index 0000000..eea346f Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-beanutils-src.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-codec.jar b/WebRoot/WEB-INF/lib/commons-codec.jar new file mode 100644 index 0000000..957b675 Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-codec.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-collections-3.1.jar b/WebRoot/WEB-INF/lib/commons-collections-3.1.jar new file mode 100644 index 0000000..41e230f Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-collections-3.1.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-digester.jar b/WebRoot/WEB-INF/lib/commons-digester.jar new file mode 100644 index 0000000..c2a7d9d Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-digester.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-el.jar b/WebRoot/WEB-INF/lib/commons-el.jar new file mode 100644 index 0000000..608ed79 Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-el.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-lang.jar b/WebRoot/WEB-INF/lib/commons-lang.jar new file mode 100644 index 0000000..87b80ab Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-lang.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-logging.jar b/WebRoot/WEB-INF/lib/commons-logging.jar new file mode 100644 index 0000000..ef43682 Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-logging.jar differ diff --git a/WebRoot/WEB-INF/lib/commons-validator.jar b/WebRoot/WEB-INF/lib/commons-validator.jar new file mode 100644 index 0000000..bf76e86 Binary files /dev/null and b/WebRoot/WEB-INF/lib/commons-validator.jar differ diff --git a/WebRoot/WEB-INF/lib/dom.jar b/WebRoot/WEB-INF/lib/dom.jar new file mode 100644 index 0000000..f722180 Binary files /dev/null and b/WebRoot/WEB-INF/lib/dom.jar differ diff --git a/WebRoot/WEB-INF/lib/foei-xml.jar b/WebRoot/WEB-INF/lib/foei-xml.jar new file mode 100644 index 0000000..81fb233 Binary files /dev/null and b/WebRoot/WEB-INF/lib/foei-xml.jar differ diff --git a/WebRoot/WEB-INF/lib/jaxen-full.jar b/WebRoot/WEB-INF/lib/jaxen-full.jar new file mode 100644 index 0000000..9f5227e Binary files /dev/null and b/WebRoot/WEB-INF/lib/jaxen-full.jar differ diff --git a/WebRoot/WEB-INF/lib/jaxp-api.jar b/WebRoot/WEB-INF/lib/jaxp-api.jar new file mode 100644 index 0000000..c8a4138 Binary files /dev/null and b/WebRoot/WEB-INF/lib/jaxp-api.jar differ diff --git a/WebRoot/WEB-INF/lib/jstl.jar b/WebRoot/WEB-INF/lib/jstl.jar new file mode 100644 index 0000000..a02abec Binary files /dev/null and b/WebRoot/WEB-INF/lib/jstl.jar differ diff --git a/WebRoot/WEB-INF/lib/mail.jar b/WebRoot/WEB-INF/lib/mail.jar new file mode 100644 index 0000000..5de02f9 Binary files /dev/null and b/WebRoot/WEB-INF/lib/mail.jar differ diff --git a/WebRoot/WEB-INF/lib/myfaces-all-src.jar b/WebRoot/WEB-INF/lib/myfaces-all-src.jar new file mode 100644 index 0000000..59ff1da Binary files /dev/null and b/WebRoot/WEB-INF/lib/myfaces-all-src.jar differ diff --git a/WebRoot/WEB-INF/lib/myfaces-all.jar b/WebRoot/WEB-INF/lib/myfaces-all.jar new file mode 100644 index 0000000..efb4805 Binary files /dev/null and b/WebRoot/WEB-INF/lib/myfaces-all.jar differ diff --git a/WebRoot/WEB-INF/lib/objectprofiler.jar b/WebRoot/WEB-INF/lib/objectprofiler.jar new file mode 100644 index 0000000..a3d4594 Binary files /dev/null and b/WebRoot/WEB-INF/lib/objectprofiler.jar differ diff --git a/WebRoot/WEB-INF/lib/oscache-2.1.jar b/WebRoot/WEB-INF/lib/oscache-2.1.jar new file mode 100644 index 0000000..4496a88 Binary files /dev/null and b/WebRoot/WEB-INF/lib/oscache-2.1.jar differ diff --git a/WebRoot/WEB-INF/lib/pg74jdbc3.jar b/WebRoot/WEB-INF/lib/pg74jdbc3.jar new file mode 100644 index 0000000..f8e09ac Binary files /dev/null and b/WebRoot/WEB-INF/lib/pg74jdbc3.jar differ diff --git a/WebRoot/WEB-INF/lib/sax.jar b/WebRoot/WEB-INF/lib/sax.jar new file mode 100644 index 0000000..301a9da Binary files /dev/null and b/WebRoot/WEB-INF/lib/sax.jar differ diff --git a/WebRoot/WEB-INF/lib/saxpath.jar b/WebRoot/WEB-INF/lib/saxpath.jar new file mode 100644 index 0000000..43cccc6 Binary files /dev/null and b/WebRoot/WEB-INF/lib/saxpath.jar differ diff --git a/WebRoot/WEB-INF/lib/standard.jar b/WebRoot/WEB-INF/lib/standard.jar new file mode 100644 index 0000000..bc528ac Binary files /dev/null and b/WebRoot/WEB-INF/lib/standard.jar differ diff --git a/WebRoot/WEB-INF/lib/xalan.jar b/WebRoot/WEB-INF/lib/xalan.jar new file mode 100644 index 0000000..a58b997 Binary files /dev/null and b/WebRoot/WEB-INF/lib/xalan.jar differ diff --git a/WebRoot/WEB-INF/lib/xercesImpl.jar b/WebRoot/WEB-INF/lib/xercesImpl.jar new file mode 100644 index 0000000..bde11f7 Binary files /dev/null and b/WebRoot/WEB-INF/lib/xercesImpl.jar differ diff --git a/WebRoot/WEB-INF/lib_src/commons-collections-3.1-src.jar b/WebRoot/WEB-INF/lib_src/commons-collections-3.1-src.jar new file mode 100644 index 0000000..05b5a69 Binary files /dev/null and b/WebRoot/WEB-INF/lib_src/commons-collections-3.1-src.jar differ diff --git a/WebRoot/WEB-INF/lib_src/objectprofiler-src.jar b/WebRoot/WEB-INF/lib_src/objectprofiler-src.jar new file mode 100644 index 0000000..f317d52 Binary files /dev/null and b/WebRoot/WEB-INF/lib_src/objectprofiler-src.jar differ diff --git a/WebRoot/WEB-INF/web.xml b/WebRoot/WEB-INF/web.xml new file mode 100644 index 0000000..eabbb90 --- /dev/null +++ b/WebRoot/WEB-INF/web.xml @@ -0,0 +1,175 @@ + + + + + + + FSIM + FSIM: File Search Index Machine + + + 1 + + + + + + /index.jsp + + + + The fsimcontext xml file + FSIM_CONFIG_FILE + /WEB-INF/fsim.xml + + + + + All servlets / listeners and filters use + this context. + + FsimContextName + WTH-SEARCH + + + + + The page when a host is blocked. + note: should be on other server ivm DDOS + + hostBlockedRedirectURL + /denied/host_blocked.jsp + + + + + + + + com.idca.fsim.core.FsimListener + + + + com.idca.fsim.core.indexer.IndexerManagerListener + + + + + + + + + Fsim Search Servlet + Fsim Search Servlet + searchServlet + com.idca.fsim.web.SearchServlet + + + searchServlet + /search + + + + Fsim Admin Servlet + Fsim Admin Servlet + adminServlet + com.idca.fsim.web.AdminServlet + + + + When an hosts session is not an admin session then + hosty is blocked, time is increased with this value in minutes. + + hostBlockedNoAdminPeneltyTime + 1 + + + + + adminServlet + /admin + + + + Fsim Redirect Servlet + Fsim Redirect Servlet + redirectServlet + com.idca.fsim.web.RedirectServlet + + + when click is done send to this url. + pluginPageRedirectURL + /ppage + + + blocked time im mins when parameter(s) is wrong + hostBlockedParameterPeneltyTime + 0 + + + + redirectServlet + /redirect + + + + Fsim Plugin Page Servlet + Fsim Plugin Page Servlet + pluginPageServlet + com.idca.fsim.web.PluginPageServlet + + + blocked time im mins when parameter(s) is wrong + hostBlockedParameterPeneltyTime + 0 + + + + pluginPageServlet + /ppage + + + + + + + + Manages user inlog/output + authenticationFilter + com.idca.fsim.web.filters.AuthenticationFilter + + The page where a user comes when he logs out. + logoutRedirectURL + /search + + + + authenticationFilter + /* + + + + diff --git a/WebRoot/css/fsim-layout-default.css b/WebRoot/css/fsim-layout-default.css new file mode 100644 index 0000000..46f7717 --- /dev/null +++ b/WebRoot/css/fsim-layout-default.css @@ -0,0 +1,54 @@ +/* ---- THIS STYLE SHEETS ONLY HANDLES STYLE CLASSES --- */ + + + +#top { + height: 100px; +} + +#topLogo { + float: left; + width: 150px; + height: 95%; +} +#topSearchBox { + float: left; + width: 450px; + /*height: 95%;*/ +} + +#topFsimLinks { + float: right; + width: 15%; + height: 95%; +} + +#topBar { + +} + +#results { + min-height: 100px; +} + +#bottomBar { +} + +#bottom { +} + +#fsimKeywordsPopup { + position: absolute; + width: 365px; + left: 160px; + top: 68px; + visibility: hidden; + z-index: 1; + + /* strange it wont do the class ??? */ + font-size: 60%; + border-style: solid; + border-color: green; + border-width: 2px; + background-color:#C4D8FD; +} diff --git a/WebRoot/css/fsim-style-default.css b/WebRoot/css/fsim-style-default.css new file mode 100644 index 0000000..9fd68af --- /dev/null +++ b/WebRoot/css/fsim-style-default.css @@ -0,0 +1,140 @@ +/* ---- THIS STYLE SHEETS ONLY HANDLES STYLE CLASSES --- */ + + +* { + margin: 0; + padding: 0; + font-family: arial,sans-serif; +} + +body { + /* nice border around site */ + margin: 5px; +} + +img { + border: 0px; +} + +/* makes div visable for devv */ +/* +div,span { + border: 1px solid #f00; + margin: 1px; +} +*/ + +.top { + +} + +.topSearchBox { + padding-left: 5px; + padding-right: 5px; +} + +.topOptions { + font-size: 12pt; + color: #aa6ea6; +} + +.topBar { + background-color: #C4D8FD; + + border-top-style: solid; + border-top-width: 1px; + border-top-color: #FE3061; + + border-bottom-style:solid; + border-bottom-width:1px; + border-bottom-color:#B4C8DD; +} + +.topBarSearchStats { + font-size: 90%; + text-align: right; +} + +.topSearchBoxTitle { + text-align: center; + font-weight: bold; +} + +.results { + width: 100%; + max-width: 100%; +} + +.resultsURL { + font-size: 80%; +} + +.resultsKeywordHighLight { + font-size: 120%; + color: #FE3061; + font-weight: bold; +} + +.resultDetails { + font-size: 70%; + color: #018001; +} + +.bottomBar { + background-color: #C4D8FD; + + border-top-style: solid; + border-top-width: 1px; + border-top-color: #FE3061; + + border-bottom-style:solid; + border-bottom-width:1px; + border-bottom-color:#FE3061; + + padding: 2px; +} + +.bottomBarPages { + text-align: center; + font-weight: bold; +} + +.bottomBarRender { + font-size: 90%; + text-align: right; +} + +.bottom { +} + +.bottomCopy { + font-size: 66%; + text-align: center; +} + + +/* see the ID in layout this didn't work :? */ +.fsimKeywordsPopup { +} + +.fsimCompleteBinderNormal { + /* height: 14px; */ + background-color: #C4D8FD; +} +.fsimCompleteBinderHighlight { + /* height: 14px; */ + background-color: #FE3061; +} + +.fsimCompleteWords { + width: 80%; + font-size: 90%; + /* float: left; */ +} + +.fsimCompleteHits { + /* float: right; */ + width: 15%; + font-size: 10px; + color: #018001; +} diff --git a/WebRoot/denied/host_blocked.jsp b/WebRoot/denied/host_blocked.jsp new file mode 100644 index 0000000..b33c625 --- /dev/null +++ b/WebRoot/denied/host_blocked.jsp @@ -0,0 +1,54 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> + + + + HOST BLOCKED + + +

HOST BLOCKED

+
+
+
+ You IP: has been + +
+ temperaly blocked.
+ Time to unblock:    in ms.
+
+
+
+
+ + You are permenent blocked.
+
+
+ Please consult the IDCA crew howto unblock if u think its not your fault.
+ (Bring some cold drinks. ;-)
+
+
+
+
+ Last reason: +
+ + + + \ No newline at end of file diff --git a/WebRoot/denied/max_sessions.jsp b/WebRoot/denied/max_sessions.jsp new file mode 100644 index 0000000..e34e9a8 --- /dev/null +++ b/WebRoot/denied/max_sessions.jsp @@ -0,0 +1,19 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> + + + + Max users reached. + + +
+
+
+ Sorry, but our max concurrent users limit is rearched.
+
+ Please try again in a 5 minutes.
+
+
+
+ + diff --git a/WebRoot/denied/real_error.jsp b/WebRoot/denied/real_error.jsp new file mode 100644 index 0000000..d829b2c --- /dev/null +++ b/WebRoot/denied/real_error.jsp @@ -0,0 +1,20 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> + + + + Real error encountered. + + +
+
+
+ Sorry, but there was een error.
+
+ Please try again.
+ FSIM +
+
+
+ + diff --git a/WebRoot/fragments/fsim_bottom.jsp b/WebRoot/fragments/fsim_bottom.jsp new file mode 100644 index 0000000..22f974b --- /dev/null +++ b/WebRoot/fragments/fsim_bottom.jsp @@ -0,0 +1,107 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> + + +
  + +
+ + + + + + "> +   + +
+
+ + + +
+
+
+ +
+
+
+ FSIM: Is a pluggable DataBae search engine.
+ Very customizable. To fit all needs.
+
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/WebRoot/fragments/fsim_httphosts.jsp b/WebRoot/fragments/fsim_httphosts.jsp new file mode 100644 index 0000000..de8f4e5 --- /dev/null +++ b/WebRoot/fragments/fsim_httphosts.jsp @@ -0,0 +1,51 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +
+
+
+ IP: + Reason: + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IPstartDatelastMessageblockedblockedTimelastRequestpermenent
+
+ + + "/> +
+
+
+ + + + "/> +
+
+
\ No newline at end of file diff --git a/WebRoot/fragments/fsim_sessions.jsp b/WebRoot/fragments/fsim_sessions.jsp new file mode 100644 index 0000000..63c32af --- /dev/null +++ b/WebRoot/fragments/fsim_sessions.jsp @@ -0,0 +1,43 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="com.idca.fsim.web.session.SearchBean" %> +<%@ page import="java.util.Enumeration" %> +
+ + + + + + + + + + + + + + + + + + + +
SESSIONIDcreatedlast accessobjects
+ <% + Enumeration sessionNames = session.getAttributeNames(); + while (sessionNames.hasMoreElements()) { + String sessionName = (String)sessionNames.nextElement(); + String className = session.getAttribute( sessionName ).getClass().getName(); + out.println(sessionName+"("+className+")
"); + + Object object = session.getAttribute(sessionName); + if(object instanceof SearchBean) + { + SearchBean sb = (SearchBean)object; + out.println("searched: "+sb.getSearchQuery()+"
"); + } + } + + %> +
+
\ No newline at end of file diff --git a/WebRoot/fragments/fsim_sources.jsp b/WebRoot/fragments/fsim_sources.jsp new file mode 100644 index 0000000..1c29ce6 --- /dev/null +++ b/WebRoot/fragments/fsim_sources.jsp @@ -0,0 +1,48 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +
+ + + + + + + + + + + + + + + + + + + + + + +
nametablesearch columnlast indexhitslast id +
+ +
+ + + "/> +
+
+
+
+ Update path cache: +
+ + +
+
+ Dump wordLists info in log. +
+ + +
+
\ No newline at end of file diff --git a/WebRoot/fragments/fsim_top.jsp b/WebRoot/fragments/fsim_top.jsp new file mode 100644 index 0000000..2d9dcac --- /dev/null +++ b/WebRoot/fragments/fsim_top.jsp @@ -0,0 +1,137 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Collection" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="java.net.URLEncoder" %> +<%@ page import="com.idca.fsim.core.plugins.SearchSource" %> + + + + + <fmt:message key="fsim.title" bundle="${fsim}"/> + + + + + + + + + + + +
+
+ + +
+

+
+ "/> +   + "/> +
+
+
+ +
+
+ + + Welcome admin user  + sessions host monitoring sources +
+
+ +
  + +
+ + + + + + "> +   + +
+
+ + +
+
+
+ + +
+
+ \ No newline at end of file diff --git a/WebRoot/fragments/searchers/files/file_mirrors.jsp b/WebRoot/fragments/searchers/files/file_mirrors.jsp new file mode 100644 index 0000000..c902e60 --- /dev/null +++ b/WebRoot/fragments/searchers/files/file_mirrors.jsp @@ -0,0 +1,4 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> + +SEE MIRROR LIST diff --git a/WebRoot/fragments/searchers/files/file_redirect.jsp b/WebRoot/fragments/searchers/files/file_redirect.jsp new file mode 100644 index 0000000..b68a3b1 --- /dev/null +++ b/WebRoot/fragments/searchers/files/file_redirect.jsp @@ -0,0 +1,24 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="com.idca.fsim.searchers.files.models.File" %> +<%@ page import="com.idca.fsim.searchers.files.models.Path" %> +<%@ page import="java.net.URLEncoder" %> + +<% + File file = (File)session.getAttribute("model"); + String url = file.getPath().getPath()+"/"+file.getName(); + url = file.getPath().getHost().getProtocol()+file.getPath().getHost().getHostName()+url;//URLEncoder.encode(url, "UTF-8"); + request.setAttribute("url",url); +%> + + + + "/> + + + Going to path now. + + + + + diff --git a/WebRoot/fragments/searchers/files/host_browse.jsp b/WebRoot/fragments/searchers/files/host_browse.jsp new file mode 100644 index 0000000..a23db6d --- /dev/null +++ b/WebRoot/fragments/searchers/files/host_browse.jsp @@ -0,0 +1,39 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="java.util.Collection" %> +<%@ page import="com.idca.fsim.searchers.files.models.Host" %> +<%@ page import="com.idca.fsim.searchers.files.FilesListener" %> +<%@ page import="com.idca.fsim.searchers.files.PathManager" %> +<% + Collection hosts = FilesListener.getPathManager().getHosts(); + request.setAttribute("hosts",hosts); +%> + + + + + + + + + + + + + + + + + +
> + + <% + Host host = (Host)request.getAttribute("host"); + out.println(host.getRootPaths().size()); + %> + + + + + +
\ No newline at end of file diff --git a/WebRoot/fragments/searchers/files/host_redirect.jsp b/WebRoot/fragments/searchers/files/host_redirect.jsp new file mode 100644 index 0000000..2bfac21 --- /dev/null +++ b/WebRoot/fragments/searchers/files/host_redirect.jsp @@ -0,0 +1,19 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="com.idca.fsim.searchers.files.models.Host" %> +<%@ page import="java.net.URLEncoder" %> + +<% + Host host = (Host)session.getAttribute("model"); + String url = host.getProtocol()+host.getHostName(); + //url = URLEncoder.encode(url, "UTF-8"); + request.setAttribute("url",url); +%> + + + "/> + + + Going to host now. + + \ No newline at end of file diff --git a/WebRoot/fragments/searchers/files/path_browse.jsp b/WebRoot/fragments/searchers/files/path_browse.jsp new file mode 100644 index 0000000..6c71478 --- /dev/null +++ b/WebRoot/fragments/searchers/files/path_browse.jsp @@ -0,0 +1,150 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Collection" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="java.net.URLEncoder" %> +<%@ page import="com.idca.fsim.searchers.files.models.Host" %> +<%@ page import="com.idca.fsim.searchers.files.models.File" %> +<%@ page import="com.idca.fsim.searchers.files.models.Path" %> +<%@ page import="com.idca.fsim.searchers.files.FilesListener" %> +<% + Object model = session.getAttribute("model"); + Path path = null; + Host host = null; + + Collection paths = null; + List files = null; + + if(model instanceof File) + { + File file = (File)model; + path = file.getPath(); + paths = path.getChilderen(); + files = FilesListener.getPathManager().getFiles(path); + } + + if(model instanceof Path) + { + path = (Path)model; + paths = path.getChilderen(); + files = FilesListener.getPathManager().getFiles(path); + } + if(model instanceof Host) + { + host = (Host)model; + if (host.getRootPaths().iterator().hasNext()) { + paths = ((Path)(host.getRootPaths().iterator().next())).getChilderen(); + files = FilesListener.getPathManager().getFiles(((Path)(host.getRootPaths().iterator().next()))); + } else { + paths = new ArrayList(); + files = new ArrayList(); + } + } + + request.setAttribute("paths",paths); + request.setAttribute("files",files); +%> + + + + + + + + + + <% if (path!=null && path.getParent()!=null) { %> + + + + + + <% } %> + + + + + <% if (host!=null) { + %> + + + + + + <% } + + // + Iterator p = paths.iterator(); + while(p.hasNext()) + { + Path pp = (Path)p.next(); + request.setAttribute("path",pp); + %> + + + + + +<% } + + // + Iterator f = files.iterator(); + while(f.hasNext()) + { + request.setAttribute("file",f.next()); + File file = (File)request.getAttribute("file"); + + + //redirect?ss="+hit.source.getName()+"&rid="+hit.id+"&up=path_browse"+"\">browse"); + + String url = "redirect/"+file.getPath()+file.getName(); + + url = file.getPath().getHost().getProtocol()+file.getPath().getHost().getHostName()+URLEncoder.encode(url, "UTF-8"); + + %> + + + + + + <% + } + // + %> + +
">..
/(root)
> "> + + <% + Path path2 = (Path)request.getAttribute("path"); + //if(path2!=null) { + out.println(path2.getChilderen().size()); + //} else { + // out.println("path2 null"); + //} + + + %> + + + + + +
+ <% + //File file = (File)request.getAttribute("file"); + //if(file!=null) { + out.println(File.printSize(file)); + //} else { + // out.println("file is null"); + //} + %> + + + + +
\ No newline at end of file diff --git a/WebRoot/fragments/searchers/files/path_redirect.jsp b/WebRoot/fragments/searchers/files/path_redirect.jsp new file mode 100644 index 0000000..376d8cf --- /dev/null +++ b/WebRoot/fragments/searchers/files/path_redirect.jsp @@ -0,0 +1,22 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ page import="com.idca.fsim.searchers.files.models.File" %> +<%@ page import="com.idca.fsim.searchers.files.models.Path" %> +<%@ page import="java.net.URLEncoder" %> + +<% + Path path = (Path)session.getAttribute("model"); + String url = path.getPath(); + //url = URLEncoder.encode(url, "UTF-8"); + request.setAttribute("url",path.getHost().getProtocol()+path.getHost().getHostName()+url); + // + // +%> + + + "/> + + + Downloading file now. + + \ No newline at end of file diff --git a/WebRoot/images/fsim.png b/WebRoot/images/fsim.png new file mode 100644 index 0000000..bc74824 Binary files /dev/null and b/WebRoot/images/fsim.png differ diff --git a/WebRoot/images/tech/.svn/all-wcprops b/WebRoot/images/tech/.svn/all-wcprops new file mode 100644 index 0000000..672d5a5 --- /dev/null +++ b/WebRoot/images/tech/.svn/all-wcprops @@ -0,0 +1,47 @@ +K 25 +svn:wc:ra_dav:version-url +V 56 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech +END +duke.gif +K 25 +svn:wc:ra_dav:version-url +V 65 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/duke.gif +END +vcss.png +K 25 +svn:wc:ra_dav:version-url +V 65 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/vcss.png +END +tomcat.gif +K 25 +svn:wc:ra_dav:version-url +V 67 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/tomcat.gif +END +debian.gif +K 25 +svn:wc:ra_dav:version-url +V 67 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/debian.gif +END +tux.gif +K 25 +svn:wc:ra_dav:version-url +V 64 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/tux.gif +END +valid-xhtml11.png +K 25 +svn:wc:ra_dav:version-url +V 74 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/valid-xhtml11.png +END +postgres.gif +K 25 +svn:wc:ra_dav:version-url +V 69 +/svn/idca/!svn/ver/3/fsim/trunk/fsim/WebRoot/images/tech/postgres.gif +END diff --git a/WebRoot/images/tech/.svn/entries b/WebRoot/images/tech/.svn/entries new file mode 100644 index 0000000..84d7b80 --- /dev/null +++ b/WebRoot/images/tech/.svn/entries @@ -0,0 +1,266 @@ +9 + +dir +115 +https://decaid.idca.nl/svn/idca/fsim/trunk/fsim/WebRoot/images/tech +https://decaid.idca.nl/svn/idca + + + +2005-08-08T22:22:39.000000Z +3 +willemc + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +623d4b01-600f-0410-8ed7-89934cd2f745 + +debian.gif +file + + + + +2009-08-11T18:38:40.000000Z +8ff7f09386f6937371ff2e31e3bf5a7e +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +2596 + +duke.gif +file + + + + +2009-08-11T18:38:40.000000Z +70263cae8e43a375c7f260b6d731b7ce +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +6310 + +postgres.gif +file + + + + +2009-08-11T18:38:40.000000Z +3bdb0172fbc3e28067700488f4a8a1a0 +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +9296 + +tomcat.gif +file + + + + +2009-08-11T18:38:40.000000Z +b8ebd781db53b856efa8e873fa4d2f6e +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +1934 + +tux.gif +file + + + + +2009-08-11T18:38:39.000000Z +e5b3348e57a2212dfac480d21074fa4c +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +4972 + +valid-xhtml11.png +file + + + + +2009-08-11T18:38:40.000000Z +6b1146d15bc3a499567953020fd14204 +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +1917 + +vcss.png +file + + + + +2009-08-11T18:38:39.000000Z +35986567c8c46ef7fe2fd6f769f8eab3 +2005-08-08T22:22:39.000000Z +3 +willemc +has-props + + + + + + + + + + + + + + + + + + + + +1134 + diff --git a/WebRoot/images/tech/.svn/format b/WebRoot/images/tech/.svn/format new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/WebRoot/images/tech/.svn/format @@ -0,0 +1 @@ +9 diff --git a/WebRoot/images/tech/.svn/prop-base/debian.gif.svn-base b/WebRoot/images/tech/.svn/prop-base/debian.gif.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/debian.gif.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/prop-base/duke.gif.svn-base b/WebRoot/images/tech/.svn/prop-base/duke.gif.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/duke.gif.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/prop-base/postgres.gif.svn-base b/WebRoot/images/tech/.svn/prop-base/postgres.gif.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/postgres.gif.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/prop-base/tomcat.gif.svn-base b/WebRoot/images/tech/.svn/prop-base/tomcat.gif.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/tomcat.gif.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/prop-base/tux.gif.svn-base b/WebRoot/images/tech/.svn/prop-base/tux.gif.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/tux.gif.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/prop-base/valid-xhtml11.png.svn-base b/WebRoot/images/tech/.svn/prop-base/valid-xhtml11.png.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/valid-xhtml11.png.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/prop-base/vcss.png.svn-base b/WebRoot/images/tech/.svn/prop-base/vcss.png.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/WebRoot/images/tech/.svn/prop-base/vcss.png.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/WebRoot/images/tech/.svn/text-base/debian.gif.svn-base b/WebRoot/images/tech/.svn/text-base/debian.gif.svn-base new file mode 100644 index 0000000..92cbdf1 Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/debian.gif.svn-base differ diff --git a/WebRoot/images/tech/.svn/text-base/duke.gif.svn-base b/WebRoot/images/tech/.svn/text-base/duke.gif.svn-base new file mode 100644 index 0000000..e2c7a64 Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/duke.gif.svn-base differ diff --git a/WebRoot/images/tech/.svn/text-base/postgres.gif.svn-base b/WebRoot/images/tech/.svn/text-base/postgres.gif.svn-base new file mode 100644 index 0000000..64c89fe Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/postgres.gif.svn-base differ diff --git a/WebRoot/images/tech/.svn/text-base/tomcat.gif.svn-base b/WebRoot/images/tech/.svn/text-base/tomcat.gif.svn-base new file mode 100644 index 0000000..6175673 Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/tomcat.gif.svn-base differ diff --git a/WebRoot/images/tech/.svn/text-base/tux.gif.svn-base b/WebRoot/images/tech/.svn/text-base/tux.gif.svn-base new file mode 100644 index 0000000..9d95b17 Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/tux.gif.svn-base differ diff --git a/WebRoot/images/tech/.svn/text-base/valid-xhtml11.png.svn-base b/WebRoot/images/tech/.svn/text-base/valid-xhtml11.png.svn-base new file mode 100644 index 0000000..2c63d93 Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/valid-xhtml11.png.svn-base differ diff --git a/WebRoot/images/tech/.svn/text-base/vcss.png.svn-base b/WebRoot/images/tech/.svn/text-base/vcss.png.svn-base new file mode 100644 index 0000000..9b2f596 Binary files /dev/null and b/WebRoot/images/tech/.svn/text-base/vcss.png.svn-base differ diff --git a/WebRoot/images/tech/debian.gif b/WebRoot/images/tech/debian.gif new file mode 100644 index 0000000..92cbdf1 Binary files /dev/null and b/WebRoot/images/tech/debian.gif differ diff --git a/WebRoot/images/tech/duke.gif b/WebRoot/images/tech/duke.gif new file mode 100644 index 0000000..e2c7a64 Binary files /dev/null and b/WebRoot/images/tech/duke.gif differ diff --git a/WebRoot/images/tech/postgres.gif b/WebRoot/images/tech/postgres.gif new file mode 100644 index 0000000..64c89fe Binary files /dev/null and b/WebRoot/images/tech/postgres.gif differ diff --git a/WebRoot/images/tech/tomcat.gif b/WebRoot/images/tech/tomcat.gif new file mode 100644 index 0000000..6175673 Binary files /dev/null and b/WebRoot/images/tech/tomcat.gif differ diff --git a/WebRoot/images/tech/tux.gif b/WebRoot/images/tech/tux.gif new file mode 100644 index 0000000..9d95b17 Binary files /dev/null and b/WebRoot/images/tech/tux.gif differ diff --git a/WebRoot/images/tech/valid-xhtml11.png b/WebRoot/images/tech/valid-xhtml11.png new file mode 100644 index 0000000..2c63d93 Binary files /dev/null and b/WebRoot/images/tech/valid-xhtml11.png differ diff --git a/WebRoot/images/tech/vcss.png b/WebRoot/images/tech/vcss.png new file mode 100644 index 0000000..9b2f596 Binary files /dev/null and b/WebRoot/images/tech/vcss.png differ diff --git a/WebRoot/index.jsp b/WebRoot/index.jsp new file mode 100644 index 0000000..ee3ec85 --- /dev/null +++ b/WebRoot/index.jsp @@ -0,0 +1,2 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + \ No newline at end of file diff --git a/WebRoot/js/fsim.js b/WebRoot/js/fsim.js new file mode 100644 index 0000000..fee499e --- /dev/null +++ b/WebRoot/js/fsim.js @@ -0,0 +1,253 @@ + + + //if(window.url.indexOf("divv")!=-1) { + // alert("turning on divv devv mode"); + //div,span { + //border: 1px solid #f00; + //margin: 1px; + //} + //} + + + var IE = document.all?true:false; + var req = null; + if (!IE) { + document.captureEvents(Event.KEYBOARD); + } + + // full autocomplete off AND XHTML compatible + for(i=0;i'; + + } + + function initRequest() { + if (window.XMLHttpRequest) { + req = new XMLHttpRequest(); + } else if (window.ActiveXObject) { + IE = true; + req = new ActiveXObject("Microsoft.XMLHTTP"); + } + } + + function sendRequest(url,oDiv) { + + if(req.readyState==1) { + // not while loading. + return; + } + + req.table = oDiv; + req.onreadystatechange=callBack; + req.open("GET",url,true); + req.send(null); + + } + + function callBack() + { + // if xmlhttp shows "loaded" + if(req && req.readyState==4) + { + // if "OK" + if (req.status==200) + { + //alert("just got: "+xmlhttp.responseText); + //document.write(xmlhttp.responseText); + ac = req.table; + oDiv = ac.oDiv; + + // clear the popup div. + while ( oDiv.hasChildNodes() ) + { + oDiv.removeChild(oDiv.firstChild); + } + + var items = req.responseXML.getElementsByTagName("item"); + //alert("just got items:"+items); + var to = ""; + for (loop = 0; loop < items.length; loop++) + { + var item = items.item(loop).firstChild.nodeValue; + var hits = items.item(loop).getAttribute('hits'); + + var oDivBinder = document.createElement('div'); + oDivBinder.id = loop; + oDivBinder.className = 'fsimCompleteBinderNormal'; + + var oDivItem = document.createElement('div'); + oDivItem.innerHTML = item; + oDivItem.className = 'fsimCompleteWords'; + + oDivBinder.onmousedown = AutoComplete.prototype.onDivMouseDown; + oDivBinder.onmouseover = AutoComplete.prototype.onDivMouseOver; + oDivBinder.onmouseout = AutoComplete.prototype.onDivMouseOut; + + //var oSpanHits = document.createElement('div'); + //oSpanHits.className = 'fsimCompleteHits'; + //oSpanHits.innerHTML = 'hits: '+hits; + + oDivBinder.appendChild(oDivItem); + //oDivBinder.appendChild(oSpanHits); + + oDiv.AutoComplete = ac; + oDiv.appendChild(oDivBinder); + } + //alert("got: "+to); + oDiv.style.visibility = "visible"; + //oDiv.stlyeClass = "pop"; + oDiv.className = "pop"; + } + else + { + alert("Problem retrieving XML data status:"+req.statusText); + } + } + } + + function AutoComplete(url, oText, oDiv) + { + // initialize member variables + this.oText = oText; // the text box + this.oDiv = oDiv; // a hidden
for the popup auto-complete + this.url=url; + this.selectedItem = null; + + this.preKeyword = ""; + + + initRequest(); + + //if(IE) { + // turn of autocompletion in IE for this field ! + oText.autocomplete = 'off'; + //} + + // attach handlers to the text-box + oText.AutoComplete = this; + oText.onkeyup = AutoComplete.prototype.onTextChange; + oText.onblur = AutoComplete.prototype.onTextBlur; + } + + AutoComplete.prototype.onTextBlur = function() + { + this.AutoComplete.onblur(); + } + + AutoComplete.prototype.onblur = function() + { + this.oDiv.style.visibility = "hidden"; + } + + AutoComplete.prototype.onTextChange = function(e) + { + if(IE) { + var e = window.event; + } + //debug('keycode='+e.keyCode); + var keyCode = e.keyCode; + + if(32 === keyCode) { + this.AutoComplete.preKeyword = this.AutoComplete.oText.value; + return; + } + + if(40 === keyCode || 38 === keyCode) { + + if(this.AutoComplete.selectedItem !== null) { + this.AutoComplete.selectedItem.className = "fsimCompleteBinderNormal"; + var currentID = this.AutoComplete.selectedItem.id; + //debug("curID="+currentID); + } + var nextItem = null; + if(40 === keyCode) { + if(!currentID) { + var currentID = -1; + } + currentID++; + nextItem = this.AutoComplete.oDiv.childNodes.item(currentID); + nextItem.className = "fsimCompleteBinderHighlight"; + this.AutoComplete.selectedItem = nextItem; + + this.AutoComplete.oText.value = this.AutoComplete.preKeyword+nextItem.firstChild.innerHTML; + + } + if(38 === keyCode) { + if(!currentID) { + var currentID = this.AutoComplete.oDiv.childNodes.lenght+1; + } + currentID--; + nextItem = this.AutoComplete.oDiv.childNodes.item(currentID); + nextItem.className = "fsimCompleteBinderHighlight"; + this.AutoComplete.selectedItem = nextItem; + + this.AutoComplete.oText.value = this.parentNode.AutoComplete.preKeyword+nextItem.firstChild.innerHTML; + } + + } else { + this.AutoComplete.onchange(); + } + } + + AutoComplete.prototype.selectRange = function (iStart, iLength) + { + if (this.oText.createTextRange) { + var oRange = this.oText.createTextRange(); + oRange.moveStart("character", iStart); + oRange.moveEnd("character", iLength - this.textbox.value.length); + oRange.select(); + } else if (this.oText.setSelectionRange) { + this.oText.setSelectionRange(iStart, iLength); + } + + this.oText.focus(); + } + + + AutoComplete.prototype.onchange = function() + { + var txt = this.oText.value; + if(""!=txt) { + this.selectedItem = null; + sendRequest(this.url+txt,this); + } else { + // hide ! + this.oDiv.style.visibility = "hidden"; + this.oText.focus(); + } + } + + AutoComplete.prototype.onDivMouseDown = function() + { + this.parentNode.AutoComplete.oText.value = this.parentNode.AutoComplete.preKeyword+this.firstChild.innerHTML; + this.parentNode.AutoComplete.selectedItem = null; + } + + AutoComplete.prototype.onDivMouseOver = function() + { + if(this.parentNode.AutoComplete.selectedItem !== null) { + this.parentNode.AutoComplete.selectedItem.className = "fsimCompleteBinderNormal"; + } + this.className = 'fsimCompleteBinderHighlight'; + this.parentNode.AutoComplete.selectedItem = this; + + this.parentNode.AutoComplete.oText.value = this.parentNode.AutoComplete.preKeyword+this.firstChild.innerHTML; + } + + AutoComplete.prototype.onDivMouseOut = function() + { + this.className = 'fsimCompleteBinderNormal'; + } + + + function createAutoComplete() + { + new AutoComplete('/search?m=1&l=', + document.getElementById('q'), + document.getElementById('fsimKeywordsPopup')); + } + \ No newline at end of file diff --git a/doc/README.txt b/doc/README.txt new file mode 100644 index 0000000..2240119 --- /dev/null +++ b/doc/README.txt @@ -0,0 +1,6 @@ + +== FSIM == + +The File Search Index Machine + +TEST COMMIT \ No newline at end of file diff --git a/fsimcrawl/.buildpath b/fsimcrawl/.buildpath new file mode 100644 index 0000000..ea8b440 --- /dev/null +++ b/fsimcrawl/.buildpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/fsimcrawl/fsimcrawl.py b/fsimcrawl/fsimcrawl.py new file mode 100644 index 0000000..33c9380 --- /dev/null +++ b/fsimcrawl/fsimcrawl.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python2.4 +""" +fsimcrawl.py - a crawler for fsim + +this file is really only the launcher for the crawler +""" + +import sys + +from core import FsimCrawl + +def startup(): + # here we start running fsimcrawl + #FsimCrawl.FsimCrawl().start() + pass + +if __name__=="__main__": + startup() diff --git a/fsimcrawl/tests/__init__.py b/fsimcrawl/tests/__init__.py new file mode 100644 index 0000000..c84cc99 --- /dev/null +++ b/fsimcrawl/tests/__init__.py @@ -0,0 +1,3 @@ +""" +tests +""" \ No newline at end of file diff --git a/fsimcrawl/tests/test_ftplib.py b/fsimcrawl/tests/test_ftplib.py new file mode 100644 index 0000000..35116b9 --- /dev/null +++ b/fsimcrawl/tests/test_ftplib.py @@ -0,0 +1,460 @@ +#!/usr/bin/env python2.4 + +import sys +reload (sys) # enables the setencoding +sys.setdefaultencoding('utf-8') +import os +import socket +socket.setdefaulttimeout(3600) +from ftplib import FTP +import Queue +import threading +import time +import gzip +import cPickle + +#from pyPgSQL import PgSQL +import psycopg2 + +class FsimDBPathException(Exception): pass + +class FsimDB(threading.Thread): + def __init__(self, host, dbq): + threading.Thread.__init__(self) + self.host = host + self.ip = socket.gethostbyname(host) + self.dbq = dbq + print time.strftime("%H:%M:%S"), "FsimDB: pgsql connect" + self.db = psycopg2.connect("dbname=fsim user=fsim host=localhost password=fsim") + self.db.set_isolation_level(0) + print time.strftime("%H:%M:%S"), "FsimDB: pgsql cursor" + self.curs = self.db.cursor() + print time.strftime("%H:%M:%S"), "FsimDB: update host and spider" + spiderid, hostid = self.updateHostAndSpider(self.host, self.ip) + self.spiderid = spiderid + self.hostid = hostid + #self.findRootId() + + self.curs.execute("COMMIT;") + + self.__die = False + self.running = True + + self.curs.execute("COMMIT;") + + + def die(self): + self.__die = True + + def shutdown(self): + self.running = False + + def cursor(self): + return self.db.cursor() + + def getHostId(self, host): + self.curs.execute("SELECT id FROM host WHERE host = '%s'" % (host)) + retval = self.curs.fetchone() + if not retval: + return False + return int(retval[0]) + + def insertSpider(self): + self.curs.execute("INSERT INTO spider (udate) VALUES (now())") + self.curs.execute("SELECT currval('spider_id_seq')") + retval = self.curs.fetchone() + if not retval: + return False + return int(retval[0]) + + def insertHost(self, hostname, ip, spiderid): + query = "INSERT INTO host (hostname, host, insert_date, last_spider_id) VALUES" + query += " ('%s', '%s', now(), %i)" % (hostname, ip, spiderid) + print time.strftime("%H:%M:%S"), "inserting host" + self.curs.execute(query) + print time.strftime("%H:%M:%S"), "inserting done" + + def updateHost(self, hostid, spiderid): + query = "UPDATE host SET last_spider_id=%(spider_id)s WHERE id=%(host_id)s" + self.curs.execute(query, dict(spider_id=spiderid, host_id=hostid)) + + def createRootDir(self,hostid): + query = "INSERT INTO path (host_id, directory) VALUES (%(host_id)s,%(dir_id)s)" + self.curs.execute(query, dict(host_id=hostid,dir_id="/")) + + def updateHostAndSpider(self, hostname, ip): + spiderid = self.insertSpider() + print 'spiderid:', spiderid + hostid = self.getHostId(hostname) + if not hostid: + print time.strftime("%H:%M:%S"), "insert host" + self.insertHost(hostname, ip, spiderid) + print time.strftime("%H:%M:%S"), "select host" + hostid = self.getHostId(ip) + print "got host:",hostid + self.createRootDir(hostid) + else: + print time.strftime("%H:%M:%S"), "update host" + self.updateHost(hostid, spiderid) + return spiderid, hostid + + def findRoot(self,path): + path2 = "/".join(path) + if not path2: path2="/" + + try: + path2 = path2.encode("utf-8","replace"); + except: + return None; + + query = "SELECT id FROM path WHERE host_id=%(host_id)s AND directory=%(dir)s" + self.curs.execute(query, dict(host_id=self.hostid,dir=path2)) + rootid = self.curs.fetchone() + if not rootid: + raise FsimDBPathException, "Invalid path %s" % path2 + return rootid[0] + + def updateDir(self,rootid,path2,name): + + path = "/".join(path2) + if name: + path = path+"/"+name + + if not path: + path = "/"+name + + try: + path = path.encode('utf-8','replace'); + except: + print "Encode error in directory: ",path; + return; + #path = path.encode('utf-8','ignore') + + query = "Select id from path where host_id=%(host_id)s and directory=%(dir)s" + self.curs.execute(query, dict(host_id=self.hostid,dir=path)) + result = self.curs.fetchone() + if result: return + + query = "INSERT INTO path (host_id, directory,parent_id) VALUES (%(host_id)s,%(dir)s,%(parent_id)s)" + #print time.strftime("%H:%M:%S"), "updateDir SQL:",query + self.curs.execute(query, dict(host_id=self.hostid,dir=path,parent_id=rootid)) + + def updateFile(self, rootid, name, size): + #print time.strftime("%H:%M:%S"), "updateFile file:", rootid, name, size, "-" + + try: + name = name.encode('utf-8','replace'); + except: + print "Encode error in name: ",name ; + return; + #name.encode('utf-8','ignore'); + + query = "select id from file where path_id=%(path_id)s and name=%(name)s and size=%(size)s"; + self.curs.execute(query, dict(path_id=rootid,name=name,size=long(size))); + result = self.curs.fetchone(); + if result: return; + + query = "INSERT INTO file (path_id, name, size, insert_date) VALUES (%(path_id)s, %(name)s, %(size)s, now())"; + self.curs.execute(query, dict(path_id=int(rootid),name=name,size=long(size))); + query = "select id from file where name=%(name)s and size=%(size)s and path_id=%(path_id)s"; + self.curs.execute(query, dict(name=name,size=long(size),path_id=int(rootid))); + new_file_id = self.curs.fetchone(); + + # Search for mirrors + query = "select id from file where name=%(name)s and size=%(size)s and path_id!=%(path_id)s"; + self.curs.execute(query, dict(name=name,size=long(size),path_id=int(rootid))); + mirror_id = self.curs.fetchone(); + if not mirror_id: + # no same file found.. do nothing + return; + + # get the new id + if not new_file_id: + print "ERROR: no file id found of new file"; + + # test if we need to add ourself + query = "select id from file_mirror where first_file_id=%(first_id)s"; + self.curs.execute(query, dict(first_id=int(mirror_id[0])) ); + result = self.curs.fetchone(); + if not result: + print "Adding mirror record"; + query = "insert into file_mirror (file_id,first_file_id) values (%(file_id)s,%(first_id)s)"; + self.curs.execute(query, dict(file_id=int(mirror_id[0]),first_id=int(mirror_id[0]))); + query = "insert into file_mirror (file_id,first_file_id) values (%(file_id)s,%(first_id)s)"; + self.curs.execute(query, dict(file_id=int(new_file_id[0]),first_id=int(mirror_id[0]))); + return; + + def process(self, hit): + type, path, name, size = hit; + #print time.strftime("%H:%M:%S"), "hit:",hit + + rootid = self.findRoot(path); + + if type=="DIR": + # hit is directory + self.updateDir(rootid,path,name); + else: + # hit is file + rootid = self.findRoot(path); + if not rootid: return; + self.updateFile(rootid, name, size); + + def runner(self): + c=0 + while (not self.__die): + hit = None + try: + hit = self.dbq.get(timeout=0.2) + except Queue.Empty, e: + # queue is empty + #print time.strftime("%H:%M:%S"), "FsimDB: Queue empty waiting" + if (not self.running or self.__die): + # queue is empty and we are done running the crawl + break + else: + self.process(hit) + + if c<32: + c+=1 + else: + print time.strftime("%H:%M:%S"), "FsimDB:", self.dbq.qsize(), hit + c=0 + #self.curs.execute("COMMIT;") + + def run(self): + print time.strftime("%H:%M:%S"), "FsimDB: run" + try: + self.runner() + except KeyboardInterrupt, err: + print time.strftime("%H:%M:%S"), "KeyboardInterrupt:", str(err) + self.dbthread.die() + self.curs.execute("COMMIT;") + self.db.close() + +class cpickle_test: + def __init__(self, ip): + self.ip = ip + self.dbq = Queue.Queue() + print "loading map" + f = ((os.path.isfile(ip) and file(ip)) or gzip.open(ip+".pickle")) + self.fmap = cPickle.load(f) + self.dbthread = FsimDB(self.ip, self.dbq) + + def crawl(self): + c=0 + while (self.fmap): + if (not self.dbthread.isAlive()): + break + path, lines = self.fmap.popitem() + print time.strftime("%H:%M:%S"), "FsimCrawler path: %s" % path + pre, post = os.path.split(path) + pre = pre.split("/") + if not pre[0]=="": + pre.insert(0, "") + # FIXME: dirty hack to ensure all directories exists + for i in range(len(pre)): + self.dbq.put(["DIR", pre[:i], pre[i], 0]) + # insert directory + self.dbq.put(["DIR", pre, post, 0]) + for line in lines: + #print len(pathlines), path, line + fullmode, links, owner, group, size, month, day, hour, name = line + size = int(size) + #isdir = fullmode[0]=='d' + isdir = 0 + islink = fullmode[0]=='l' + #mode = fullmode[1:] + + if (c<256): + c+=1 + else: + print time.strftime("%H:%M:%S"), "FsimCrawler:", len(self.fmap) + c=0 + + if name=="." or name=="..": + continue + + #if (isdir): + # # record directory and scanit + # print time.strftime("%H:%M:%S"), "FsimCrawler path: %s/%s" % ("/".join(path), name) + # self.dbq.put(["DIR", path, name, size]) + if (islink): + # ignoring links FIXME later + pass + else: + # is file + #print time.strftime("%H:%M:%S"), "found file:", "/".join(path), name + self.dbq.put(["FILE", pre+[post], name, size]) + + def run(self): + print time.strftime("%H:%M:%S"), "FsimCrawl: run" + # start test + self.dbthread.start() + + try: + self.crawl() + except KeyboardInterrupt, err: + self.dbthread.die() + print time.strftime("%H:%M:%S"), "KeyboardInterrupt:", str(err) + except Exception, e: + self.dbthread.die() + print time.strftime("%H:%M:%S"), "Exception:", e + raise + + # done scanning ftp + print time.strftime("%H:%M:%S"), "calling dbthread shutdown" + self.dbthread.shutdown() + while (self.dbthread.isAlive()): + print time.strftime("%H:%M:%S"), "waiting on db thread" + try: + time.sleep(5) + except Exception, e: + print time.strftime("%H:%M:%S"), "Exception:",e + self.dbthread.die() + + print time.strftime("%H:%M:%S"), "joining dbthread" + self.dbthread.join(timeout=5) + print time.strftime("%H:%M:%S"), "done" + +class ftplib_test: + def __init__(self, host): + self.host = host + self.dbq = Queue.Queue() + + self.dbthread = FsimDB(self.host, self.dbq) + + print time.strftime("%H:%M:%S"), "FsimCrawl: ftp instance" + self.ftp = FTP(host) + print time.strftime("%H:%M:%S"), "FsimCrawl: login" + self.ftp.login() + + def list_dir(self, path, dir): + assert dir + newpath = list(path)+list([dir]) + lines = [] + fulldir = '/'.join(newpath) + self.ftp.cwd(fulldir) + #self.ftp.retrlines("LIST %s" % fulldir, lines.append) + self.ftp.retrlines("LIST", lines.append) + if newpath==['/']: + newpath=[""] + return (newpath, lines) + + def crawl(self): + pathlines = [] + toscan = [] + pathlines.append(self.list_dir([], "/")) + c = 0 + fc = 0 + while (pathlines): + if not self.dbthread.isAlive(): + print time.strftime("%H:%M:%S"), "dbthread is dead ! exiting now!" + break + + + path, lines = pathlines.pop(0) + for line in lines: + #print len(pathlines), path, line + try: + fullmode, links, owner, group, size, rest = line.split(None, 5) + except ValueError, e: + if "total" in line: continue + + print time.strftime("%H:%M:%S"), "FsimCrawl: ftp error:", e + print time.strftime("%H:%M:%S"), " in line:", line + continue + + try: + size = int(size) + except ValueError, e: + # trying to include badly behaving ftp servers + # that only have one field for ownership + rest = size+" "+rest + size = int(group) + + isdir = fullmode[0]=='d' + islink = fullmode[0]=='l' + mode = fullmode[1:] + date = rest[:12] + name = rest[13:] + + if (c<256): + c+=1 + else: + print time.strftime("%H:%M:%S"), "FsimCrawler:", len(pathlines) + c=0 + + if (fc<2048): + fc+=1 + else: + # make sure ftp doesn't timeout + print time.strftime("%H:%M:%S"), "ftp anti-timeout" + fc = 0 + self.ftp.cwd("/") + + if name=="." or name=="..": + continue + + if (isdir): + self.dbq.put(["DIR", path, name, size]) + print time.strftime("%H:%M:%S"), "FsimCrawler scan: %s/%s" % ("/".join(path), name) + try: + toscan.append(self.list_dir(path, name)) + except: + print "Dir List Error"; + elif (islink): + # ignoring links FIXME later + pass + else: + # is file + self.dbq.put(["FILE", path, name, size]) + #endfor + for todo in toscan: + #print time.strftime("%H:%M:%S"), "FsimCrawler scan: %s/%s" % ("/".join(path), todo) + #pathlines.append(self.list_dir(path, todo)) + pathlines.append(todo) + toscan = [] + + def run(self): + print time.strftime("%H:%M:%S"), "FsimCrawl: run" + # start test + self.dbthread.start() + + try: + self.crawl() + except KeyboardInterrupt, err: + self.dbthread.die() + print time.strftime("%H:%M:%S"), "KeyboardInterrupt:", str(err) + except Exception, e: + self.dbthread.die() + print time.strftime("%H:%M:%S"), "Exception:", e + raise + + # done scanning ftp + print time.strftime("%H:%M:%S"), "calling dbthread shutdown" + self.dbthread.shutdown() + while (self.dbthread.isAlive()): + print time.strftime("%H:%M:%S"), "waiting on db thread" + try: + time.sleep(5) + except Exception, e: + print time.strftime("%H:%M:%S"), "Exception:",e + self.dbthread.die() + + print time.strftime("%H:%M:%S"), "joining dbthread" + self.dbthread.join(timeout=5) + print time.strftime("%H:%M:%S"), "done" + +if __name__=="__main__": + # feed ip's only at this time + if (len(sys.argv)!=3): + print "usage: %s [crawl][file] ip_address" % sys.argv[0] + sys.exit() + if sys.argv[1]=="crawl": + ftplib_test(str(sys.argv[2])).run() + elif sys.argv[1]=="file": + cpickle_test(str(sys.argv[2])).run() + else: + print "invalid command line." + + diff --git a/src/com/idca/fsim/core/FsimContext.java b/src/com/idca/fsim/core/FsimContext.java new file mode 100644 index 0000000..be047d7 --- /dev/null +++ b/src/com/idca/fsim/core/FsimContext.java @@ -0,0 +1,114 @@ +/* + * + * + */ + +package com.idca.fsim.core; + +import com.idca.fsim.core.jdbc.ConnectionFactory; +import com.idca.fsim.core.plugins.SearchSource; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.List; +import java.util.Iterator; +import java.util.Collection; +import java.util.EventListener; +import java.util.logging.Logger; + +import java.sql.Connection; +import java.sql.SQLException; + + +/** + * An FsimContext + * + * Note: because we use here only the non-synchronized Collections + * we must synchronize this objectes are stuctural changed (add/remove) !! + * + * @author Willem Cazander + * @version 1.0 + */ +public class FsimContext +{ + /** */ + private Logger logger = Logger.getLogger(FsimContext.class.getName()); + private Map searchSources = new HashMap(); + private List listeners = new ArrayList(1); + private String name = null; + + private Map jspIncludePages = new HashMap(3); + + // ============ jspIncludePages + + public void addJSPIncludePage(String name,String file) + { + synchronized(jspIncludePages) + { + jspIncludePages.put(name,file); + } + logger.info("Adding plugin page: "+name+" file: "+file); + } + public String getJSPIncludePage(String name) + { + return (String)jspIncludePages.get(name); + } + + // ============== the name of this search context. + + public void setName(String name) + { + this.name = name; + } + public String getName() + { + return name; + } + + + // ================ listeners + + public List getListeners() + { + return listeners; + } + + public void addListener(EventListener eventListener) + { + logger.info("Adding EventListener"); + synchronized(listeners) + { + listeners.add(eventListener); + } + } + + + // ================= search sources + + public Collection getSearchSources() + { + return searchSources.values(); + } + public SearchSource getSearchSource(String name) + { + return (SearchSource)searchSources.get(name); + } + public void addSearchSource(SearchSource searchSource) + { + logger.info("Adding dataSearchSource: "+searchSource.getName()); + synchronized(searchSources) + { + searchSources.put(searchSource.getName(),searchSource); + } + } + + + // ================== the db functions. + + public Connection getConnectionByName(String dbName) throws SQLException + { + return ConnectionFactory.getConnection(dbName); + } +} diff --git a/src/com/idca/fsim/core/FsimListener.java b/src/com/idca/fsim/core/FsimListener.java new file mode 100644 index 0000000..0104e9e --- /dev/null +++ b/src/com/idca/fsim/core/FsimListener.java @@ -0,0 +1,132 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.core; + +import com.idca.fsim.core.config.ConfigParser; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import java.io.InputStream; +import java.util.logging.LogManager; +import java.util.logging.Logger; + +/** + * Starts fsim from a web context. + * @author Willem Cazander + * @version 1.0 28/06/2005 + */ +public class FsimListener implements ServletContextListener +{ + /** */ + private Logger logger = Logger.getLogger(FsimListener.class.getName()); + + /** + * This method is called when the servlet context is
+ * initialized(when the Web application is deployed).
+ * You can initialize servlet context related data here.
+ */ + public void contextInitialized(ServletContextEvent event) + { + initLogging(); + + ServletContext sc = event.getServletContext(); + String file = sc.getRealPath(sc.getInitParameter("FSIM_CONFIG_FILE")); + if(file==null) + { + logger.warning("No config file given!! giving up, set parameter: "+"FSIM_CONFIG_FILE"); + // return; + } + try { + startFsim(file); + + } catch (Exception e) { + logger.warning("Fsim could not be started: "+e.getMessage()); + e.printStackTrace(); + } + } + + private void initLogging() + { + + try { + InputStream loggingProperties = null; + String dev = "false"; //ApplicationSettings.getSetting("DEVELOPMENT"); + + if("true".equalsIgnoreCase(dev)) + { + // 1st try to load the non-cvs properties + try + { + loggingProperties = this.getClass().getResourceAsStream("/com/idca/fsim/resources/logging/logging-development.properties"); + } catch (Throwable overrideT) { + } + } + // else the default properties + if(loggingProperties==null) + { + loggingProperties = this.getClass().getResourceAsStream("/com/idca/fsim/resources/logging/logging.properties"); + logger.info("Loaded default logging properties"); + } else { + logger.info("Loaded development logging properties"); + } + + LogManager.getLogManager().readConfiguration( loggingProperties ); + loggingProperties.close(); + } catch (Throwable logT) { + // PRINT AS STACKTRACE because when we fuck the logging there is no log message + logT.printStackTrace(); + } + //reinit logger for new levels + logger = Logger.getLogger(this.getClass().getName()); + + checkLogLevels(); + } + + private void checkLogLevels() + { + // TEST all log levels + logger.info ("TESTING LOG LEVELS:\n"); + logger.finest ("LOGLEVEL ENABLED"); + logger.finer ("LOGLEVEL ENABLED"); + logger.fine ("LOGLEVEL ENABLED"); + logger.config ("LOGLEVEL ENABLED"); + logger.warning ("LOGLEVEL ENABLED"); + logger.info ("LOGLEVEL ENABLED\n"); + } + + + + + /** + * This method is invoked when the Servlet Context.
+ * (the Web application) is undeployed or
+ * the J2EE Server shuts down.
+ */ + public void contextDestroyed(ServletContextEvent event) + { + } + + + private void startFsim(String fileName) + { + try { + FsimContext fc = ConfigParser.parse(fileName); + FsimServer.addFsimContext(fc); + } catch (Exception e) { + logger.warning("Error while loading: "+fileName+" message: "+e.getMessage()); + e.printStackTrace(); + } + + logger.info("done starting fsim"); + } + + + +} diff --git a/src/com/idca/fsim/core/FsimServer.java b/src/com/idca/fsim/core/FsimServer.java new file mode 100644 index 0000000..98b4190 --- /dev/null +++ b/src/com/idca/fsim/core/FsimServer.java @@ -0,0 +1,60 @@ +/* + * + * + */ + +package com.idca.fsim.core; + +import com.idca.fsim.core.plugins.SearchSource; +import com.idca.fsim.core.plugins.listeners.FsimContextListener; +import com.idca.fsim.core.plugins.listeners.FsimContextEvent; + +import java.util.Hashtable; +import java.util.Collection; +import java.util.Iterator; + +/** + * Manages the different Fsim contexts + * + * @author Willem Cazander + * @version 1.0 20/07/2005 + */ +public class FsimServer +{ + static private Hashtable contexts = new Hashtable(1); + + static public void addFsimContext(FsimContext fsimContext) + { + if(contexts.get(fsimContext.getName())!=null) + { + System.out.println("Can't add an FsimContext with an already loaded name: "+fsimContext.getName()); + return; + } + contexts.put(fsimContext.getName(),fsimContext); + + // send events + System.out.println("sending events of "+fsimContext.getName()); + Iterator i = fsimContext.getListeners().iterator(); + while(i.hasNext()) + { + Object object = i.next(); + System.out.println("Object == "+object); + if(object instanceof FsimContextListener) + { + FsimContextListener fcl = (FsimContextListener)object; + fcl.contextInitialized(new FsimContextEvent(fsimContext)); + } + } + } + + static public FsimContext getFsimContext(String name) { + if(name==null) { + return null; + } + return (FsimContext)contexts.get(name); + } + + static public Collection getFsimContexts() { + return contexts.values(); + } +} diff --git a/src/com/idca/fsim/core/LetterMap.java b/src/com/idca/fsim/core/LetterMap.java new file mode 100644 index 0000000..7f9a421 --- /dev/null +++ b/src/com/idca/fsim/core/LetterMap.java @@ -0,0 +1,55 @@ +/* + * + */ + +package com.idca.fsim.core; + +import com.idca.fsim.models.Word; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; + +/** + * An LetterMAp + * + * @author Willem Cazander + * @version 1.0 + */ +public class LetterMap +{ + /** */ + private Map wordSets = new Hashtable(240); + + /** + * + * @param ch + * @param word + */ + public synchronized void addWord(Character ch,Word word) + { + Collection words = (Collection)wordSets.get(ch); + if(words==null) { + words = new HashSet(); + wordSets.put(ch,words); + } + words.add(word); + } + + + /** + * + * @param ch + * @return + */ + public Collection getWords(Character ch) + { + return (Collection)wordSets.get(ch); + } + + protected Map getWordSet() + { + return wordSets; + } +} diff --git a/src/com/idca/fsim/core/Searcher.java b/src/com/idca/fsim/core/Searcher.java new file mode 100644 index 0000000..698f607 --- /dev/null +++ b/src/com/idca/fsim/core/Searcher.java @@ -0,0 +1,114 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.core; + +import com.idca.fsim.core.comparators.WordListComparator; +import com.idca.fsim.core.comparators.WordComparator; +import com.idca.fsim.models.*; + +import java.util.logging.Logger; + +import java.util.List; +import java.util.HashSet; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import javax.servlet.ServletException; + +/** + * Searches + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + */ +public class Searcher +{ + private WordLists wl = null; + private Logger logger = Logger.getLogger(Searcher.class.getName()); + private ArrayList searchSources = new ArrayList(3); + + public Searcher(WordLists wl) + { + this.wl=wl; + } + + public Collection searchWords(String word,boolean inWord) + { + String[] keyWords = word.split(" "); + + + + + //List result = null; + List last = new ArrayList(19); + for(int i=0;i> "+word+" << found "+last.size()+" results."); + + // sort on hist list size and Keywords + WordComparator wc =new WordComparator(); + wc.setKeywords(keyWords); + Collections.sort(last,wc); + + // Collections.sort(last,new WordClickedComperator()); + return last; + } + + public Collection searchHits(String text,boolean inWord) + { + Collection last = searchWords(text,inWord); + + ArrayList hists = new ArrayList(100); + Iterator x = last.iterator(); + while(x.hasNext()) { + Word word = (Word)x.next(); + hists.addAll(word.hits); + } + + return hists; + } + + public void setSearchSources(String searchSources) + { + addSearchSources(this.searchSources,searchSources); + } + + public boolean hasSearchSource(String searchSource) + { + if(searchSources.contains(searchSource)) { + return true; + } + return false; + } + + private void addSearchSources(List list,String sources) + { + String[] pathsA=sources.split(";"); + for(int i=0;i te+ex+xt = returned. + * @param text + * @return + */ + public Collection getWords(String text) + { + //logger.info("Starting search on "+text); + // no spaces should be in text + int textLength = text.length(); + List allWords = new ArrayList(6); + for(int i=0;iword2.clicked) + { + return 1; + } + if(word1.clickedw2b) + { + return -1; + } + if(w1b()); + } + + // ===== methodes + + public ThreadPoolExecutor getThreadPoolExecutor() { + return threadPoolExecutor; + } +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/indexer/IndexerManagerListener.java b/src/com/idca/fsim/core/indexer/IndexerManagerListener.java new file mode 100644 index 0000000..7c40b09 --- /dev/null +++ b/src/com/idca/fsim/core/indexer/IndexerManagerListener.java @@ -0,0 +1,73 @@ + +package com.idca.fsim.core.indexer; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +/** + * Manages the indexing + * + * @author Willem Cazander + * @version 1.0 Jan 14, 2006 + */ +public class IndexerManagerListener implements ServletContextListener { + + /** The logger to log to. */ + private Logger logger = Logger.getLogger(IndexerManagerListener.class.getName()); + + /** + * The name of the initparameter where to register the jmx bean to. + * Set to "" or "null" to no register bean. + * */ + static public final String INDEXER_MANANGER_OBJECT_NAME = "IndexerManager.OBJECT_NAME"; + + static private IndexerManager indexerManager = null; + + /** + * Starts Hibernate + */ + public void contextInitialized(ServletContextEvent event) { + logger.info("Creating the IndexerManager."); + try { + indexerManager = new IndexerManager(); + String objectName=event.getServletContext().getInitParameter(INDEXER_MANANGER_OBJECT_NAME); + if(objectName==null) + { + //indexerManager.setObjectName("M4N:type=datafeeds,name=ParserThreadPoolManager"); + //indexerManager.register(); + } else { + if("".equals(objectName) | "null".equals(objectName)) + { + logger.info("Not registrating IndexerManager by user command"); + } else { + //indexerManager.setObjectName(objectName); + //indexerManager.register(); + } + } + } catch (Exception e) { + logger.log(Level.SEVERE,"Error while configing IndexerManager.",e); + } + } + + /** + * Shutdowns Hibernate + */ + public void contextDestroyed(ServletContextEvent event) { + try { + logger.info("Shutdowing the IndexerManager."); + indexerManager.getThreadPoolExecutor().shutdown(); + } catch (Exception e) { + logger.warning("Error while shutdowning the IndexerManager"); + } + } + + /** + * Returns the IndexManager + * @return + */ + static public IndexerManager getIndexerManager() { + return indexerManager; + } +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/jdbc/ConnectionFactory.java b/src/com/idca/fsim/core/jdbc/ConnectionFactory.java new file mode 100644 index 0000000..212c68d --- /dev/null +++ b/src/com/idca/fsim/core/jdbc/ConnectionFactory.java @@ -0,0 +1,36 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.core.jdbc; + +import java.sql.SQLException; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.Connection; +import java.util.Enumeration; +import java.util.logging.Logger; +import java.util.Hashtable; + +/** + * + * + * @author Willem Cazander + * @version 1.0 + * + * Code can get here its DB connections + * + */ +public class ConnectionFactory +{ + + static JndiDataSourceProvider j = new JndiDataSourceProvider("fsim_dba"); + + static public Connection getConnection(String name) + { + return j.getConnection(); + } +} diff --git a/src/com/idca/fsim/core/jdbc/ConnectionProvider.java b/src/com/idca/fsim/core/jdbc/ConnectionProvider.java new file mode 100644 index 0000000..669f8c1 --- /dev/null +++ b/src/com/idca/fsim/core/jdbc/ConnectionProvider.java @@ -0,0 +1,33 @@ + +package com.idca.fsim.core.jdbc; + +import java.sql.Connection; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 4, 2006 + * + * The ConnectionProvider is an interface which + * lets objects returns a Connection. + * + * We normally registrates an ConnectionProvider to the + * ConnectionProviderManager so fsim can use it. + * + */ +public interface ConnectionProvider +{ + /** + * Gets the connection name for which this + * ConnectionProvider handles connections. + * @return Returns the connection name. + */ + public String getConnectionName(); + + /** + * Gets an connection of this ConnectionProvider. + * @return Returns an Connection + */ + public Connection getConnection(); +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/jdbc/ConnectionProviderManager.java b/src/com/idca/fsim/core/jdbc/ConnectionProviderManager.java new file mode 100644 index 0000000..6410f99 --- /dev/null +++ b/src/com/idca/fsim/core/jdbc/ConnectionProviderManager.java @@ -0,0 +1,74 @@ + +package com.idca.fsim.core.jdbc; + +import java.sql.Connection; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 4, 2006 + * + * Manages the different ConnectionProviders. + * + */ +public class ConnectionProviderManager +{ + /** The logger to log to */ + private Logger logger = null; + /** The map with all connection providers */ + private Map connectionProviders = null; + + /** + * Creates an ConnectionProviderManager + * + */ + public ConnectionProviderManager() { + logger = Logger.getLogger(ConnectionProviderManager.class.getName()); + logger.fine("Creating an ConnectionProviderManager"); + connectionProviders = new HashMap(3); + } + + + /** + * Gets an Connection by its connectionName + * @param connectionName The connection name. + * @return Returns the Connection + */ + public Connection getConnection(String connectionName) { + return getConnectionProvider(connectionName).getConnection(); + } + + /** + * Adds an ConnectionProvider + * @param connectionProvider The ConnectionProvider to add. + */ + public void addConnectionProvider(ConnectionProvider connectionProvider) { + if(connectionProvider==null) { + throw new NullPointerException("connectionProvider may not be null."); + } + logger.fine("Adding ConnnectionProvider for connection: "+connectionProvider.getConnectionName()); + connectionProviders.put(connectionProvider.getConnectionName(),connectionProvider); + } + + /** + * Gets an ConnectionProvider by its connectionName + * @param connectionName The connection name + * @return Returns the ConnectionProvider for this connectionName. + */ + public ConnectionProvider getConnectionProvider(String connectionName) { + return connectionProviders.get(connectionName); + } + + /** + * Gets all ConnectionProviders + * @return Returns all ConnectionProviders. + */ + public Collection getConnectionProviders() { + return connectionProviders.values(); + } +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/jdbc/JndiDataSourceProvider.java b/src/com/idca/fsim/core/jdbc/JndiDataSourceProvider.java new file mode 100644 index 0000000..e6868a1 --- /dev/null +++ b/src/com/idca/fsim/core/jdbc/JndiDataSourceProvider.java @@ -0,0 +1,124 @@ + +package com.idca.fsim.core.jdbc; + +import java.sql.Connection; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 4, 2006 + * + */ +public class JndiDataSourceProvider implements ConnectionProvider +{ + /** The context in which database datasources are found. */ + private static final String DATASOURCE_CONTEXT = "java:comp/env/jdbc/"; + /** The connectionName for this Provider */ + private String connectionName = null; + /** The jndi context to search for the dataSource. */ + private String dataSourceContext = null; + /** The logger to log to. */ + private Logger logger = null; + + /** + * Creates an JndiDataSourceProvider and inits the Logger + */ + public JndiDataSourceProvider() { + logger = Logger.getLogger(JndiDataSourceProvider.class.getName()); + } + + /** + * Creates JndiDataSourceProvider and sets its connectionName. + * @param connectionName + */ + public JndiDataSourceProvider(String connectionName) { + super(); + setConnectionName(connectionName); + } + + + /** + * Gets an DataSource out of the jndi context. + * @param name The name of the datasource in the jndi context. + * @return The datasource. + */ + static public DataSource getDataSource(String name) { + + try { + Context initialContext = new InitialContext(); + if(initialContext == null) { + throw new RuntimeException("Init: Cannot get Initial Context"); + } + DataSource datasource = (DataSource) initialContext.lookup(name); + if(datasource == null) { + throw new RuntimeException("Init: Cannot lookup datasource: '"+name+"'"); + } + return datasource; + } catch (NamingException ex) { + throw new RuntimeException("Init: Cannot get connection " + ex); + } + } + + //========= ConnectionProvider + + /** + * Gets the connection name for which this + * ConnectionProvider handles connections. + * @return Returns the connection name. + * @see ConnectionProvider#getConnectionName() + */ + public String getConnectionName() { + return connectionName; + } + + /** + * Gets an connection of this ConnectionProvider. + * @return Returns an Connection + * @see ConnectionProvider#getConnection() + */ + public Connection getConnection() { + try { + if(dataSourceContext==null) { + dataSourceContext=DATASOURCE_CONTEXT; + } + return getDataSource(dataSourceContext+connectionName).getConnection(); + } catch (Exception e) { + logger.log(Level.WARNING,"Error while getting DataSource",e); + throw new NullPointerException("No datasource"); + } + } + + // ==== set/getter + + /** + * Sets the connectionName. + * @param connectionName The connectionName to set. + */ + public void setConnectionName(String connectionName) { + this.connectionName=connectionName; + } + + /** + * @return Returns the dataSourceContext. + */ + public String getDataSourceContext() { + return dataSourceContext; + } + + /** + * When set to null(default) then + * DATASOURCE_CONTEXT is used. ("java:comp/env/jdbc/") + * @param dataSourceContext The dataSourceContext to set. + */ + public void setDataSourceContext(String dataSourceContext) { + this.dataSourceContext = dataSourceContext; + } +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/plugins/AbstractResultCollector.java b/src/com/idca/fsim/core/plugins/AbstractResultCollector.java new file mode 100644 index 0000000..b898a9a --- /dev/null +++ b/src/com/idca/fsim/core/plugins/AbstractResultCollector.java @@ -0,0 +1,23 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.core.plugins; + +/** + * + * + * @author Willem Cazander + * @version 1.0 + * + * + */ +abstract public class AbstractResultCollector implements ResultCollector +{ + + + +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/plugins/AbstractResultRenderer.java b/src/com/idca/fsim/core/plugins/AbstractResultRenderer.java new file mode 100644 index 0000000..b1251ab --- /dev/null +++ b/src/com/idca/fsim/core/plugins/AbstractResultRenderer.java @@ -0,0 +1,24 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.core.plugins; + +/** + * + * + * @author Willem Cazander + * @version 1.0 + * + * + */ +abstract public class AbstractResultRenderer implements ResultRenderer +{ + + + + +} \ No newline at end of file diff --git a/src/com/idca/fsim/core/plugins/DBIndexer.java b/src/com/idca/fsim/core/plugins/DBIndexer.java new file mode 100644 index 0000000..ae88347 --- /dev/null +++ b/src/com/idca/fsim/core/plugins/DBIndexer.java @@ -0,0 +1,151 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.core.plugins; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.models.Word; +import com.idca.fsim.models.Hit; + +import java.util.Date; +import java.util.logging.Logger; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +/** + * An DataBase indexer + * + * @author Willem Cazander + * @version 1.0 + */ +public class DBIndexer implements Indexer +{ + /** */ + private FsimContext fc = null; + /** */ + private Logger logger = Logger.getLogger(DBIndexer.class.getName()); + + private long queryLimit = 50000; + + private long queryOffset = 0; + + /** + * + * @param fc + */ + public void setFsimContext(FsimContext fc) + { + this.fc=fc; + } + + public void index(SearchSource searchSource) + { + DBSearchSource source = (DBSearchSource)searchSource; + + + + try + { + logger.info("start indexing... at startIndex="+queryOffset); + Connection connection = fc.getConnectionByName(source.getDBName()); + Statement stmt = connection.createStatement(); + + + String sql = "select * from "+source.getTableName()+" where "+source.getIDColumnName()+" >= "+queryOffset+" order by "+source.getIDColumnName()+" ASC limit "+queryLimit; + logger.info("SQL:"+sql); + ResultSet rs = stmt.executeQuery(sql); + source.setLastIndexed(new Date()); + int sleep = 0; + long records = 0; + + while(rs.next()) + { + records++; + int id = rs.getInt(source.getIDColumnName()); + String columnName = source.getSearchColumnName(); + + String text = rs.getString(columnName); + String words[] = text.split(" "); + for(int i=0;i100) + { + /* + try { + Thread.sleep(100); + } catch (Exception e) { + e.printStackTrace(); + } + */ + sleep=0; + + if(connection.isClosed()) + { + logger.info("Lost connection going futher at index: "+(id+1)); + // maybe somethimes happens. + //index(source,id+1); + break; + } + } + } + rs.close(); + if(stmt!=null) + { + // after slepp.. + stmt.close(); + } + connection.close(); + + + if (recordsFsim is a product of idca.nl
(c)2005 idca + +fsim.tech.vcss.alt = Valid CSS +fsim.tech.vcss.title = This page has an valid css file. +fsim.tech.xhtml11.alt = Valid XHML 1.1 +fsim.tech.xhtml11.title = This page is build with XHTML technolocy. +fsim.tech.debian.alt = debian-logo +fsim.tech.debian.title = This service runs on Debian. +fsim.tech.java.alt = java-logo +fsim.tech.java.title = This service is written in java. +fsim.tech.postgres.alt = postgresql-logo +fsim.tech.postgres.title= This service uses an PostgreSQL DB. +fsim.tech.linux.alt = linux-logo +fsim.tech.linux.title = The OS runs Linux. +fsim.tech.tomcat.alt = tomcat-logo +fsim.tech.tomcat.title = Tomcat 5 J2EE WebServer. + +fsim.text = foo {0} bar \ No newline at end of file diff --git a/src/com/idca/fsim/resources/i18n/fsim_nl.properties b/src/com/idca/fsim/resources/i18n/fsim_nl.properties new file mode 100644 index 0000000..c2cae3a --- /dev/null +++ b/src/com/idca/fsim/resources/i18n/fsim_nl.properties @@ -0,0 +1,9 @@ + + +fsim.test = Mmmm dit is een test + + +fsim.copyright = Fsim is a product of idca.nl
(c)2005 idca + + + diff --git a/src/com/idca/fsim/resources/logging/.cvsignore b/src/com/idca/fsim/resources/logging/.cvsignore new file mode 100644 index 0000000..0111248 --- /dev/null +++ b/src/com/idca/fsim/resources/logging/.cvsignore @@ -0,0 +1 @@ +logging-development.properties diff --git a/src/com/idca/fsim/resources/logging/logging-development-example.properties b/src/com/idca/fsim/resources/logging/logging-development-example.properties new file mode 100644 index 0000000..011d7c1 --- /dev/null +++ b/src/com/idca/fsim/resources/logging/logging-development-example.properties @@ -0,0 +1,26 @@ +# +# COPY THIS FILE TO: logging-development.properties +# and set the properties correctly +# + +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = ALL + +# Set the default formatter for new ConsoleHandler instances ( was java.util.logging.SimpleFormatter) +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Set the default logging level for the root logger +.level = INFO + +#org.apache.tomcat.level = ALL +#org.apache.catalina.level = ALL +#org.apache.jasper.level = ALL +#org.apache.commons.level = ALL +#org.apache.myfaces.level = ALL +#org.hibernate.level = ALL +#com.opensymphony.oscache.level = ALL diff --git a/src/com/idca/fsim/resources/logging/logging.properties b/src/com/idca/fsim/resources/logging/logging.properties new file mode 100644 index 0000000..fb0e579 --- /dev/null +++ b/src/com/idca/fsim/resources/logging/logging.properties @@ -0,0 +1,29 @@ +# +# THIS ARE THE LIVE logging properties +# when the context parameter "DEVELOPMENT" on true is set +# then we will try to read logging-development.properties. +# this parameter should be set in web-override.xml +# + +# +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = INFO + +# Set the default formatter for new ConsoleHandler instances ( was java.util.logging.SimpleFormatter) +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Set the default logging level for the root logger +.level = INFO + +#org.apache.tomcat.level = ALL +#org.apache.catalina.level = ALL +#org.apache.jasper.level = ALL +#org.apache.commons.level = ALL +#org.apache.myfaces.level = ALL +#org.hibernate.level = ALL +#com.opensymphony.oscache.level = ALL diff --git a/src/com/idca/fsim/searchers/files/FilesListener.java b/src/com/idca/fsim/searchers/files/FilesListener.java new file mode 100644 index 0000000..f4b315d --- /dev/null +++ b/src/com/idca/fsim/searchers/files/FilesListener.java @@ -0,0 +1,53 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files; + +import com.idca.fsim.core.plugins.listeners.FsimContextListener; +import com.idca.fsim.core.plugins.listeners.FsimContextEvent; +import com.idca.fsim.core.FsimContext; + +import java.util.logging.Logger; + +/** + * Does caching of the hosts an paths. + * + * @author Willem Cazander + * @version 1.0 19/07/2005 + */ +public class FilesListener implements FsimContextListener +{ + /** */ + static PathManager pathManager = null; + /** */ + private Logger logger = Logger.getLogger(FilesListener.class.getName()); + + /** + * + * @return + */ + static public PathManager getPathManager() + { + return pathManager; + } + + public void contextInitialized(FsimContextEvent contextEvent) + { + FsimContext fc = contextEvent.getFsimContext(); + if(pathManager==null) + { + pathManager = new PathManager(fc,"fsim_dba"); + } + pathManager.updatePaths(); + + } + + public void contextDestroyed(FsimContextEvent contextEvent) + { + FsimContext fc = contextEvent.getFsimContext(); + logger.info(".... JUST got destry event "+fc.getName()); + } + +} diff --git a/src/com/idca/fsim/searchers/files/PathManager.java b/src/com/idca/fsim/searchers/files/PathManager.java new file mode 100644 index 0000000..82e04bd --- /dev/null +++ b/src/com/idca/fsim/searchers/files/PathManager.java @@ -0,0 +1,220 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.searchers.files.models.*; + + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import java.util.Collection; +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; +import java.util.Hashtable; +import java.util.HashSet; +import java.util.logging.Logger; +import java.util.Map; +import java.util.List; + +/** + * Caches the paths. + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + */ +public class PathManager +{ + private Map paths = new Hashtable(2000); + private Map hosts = new Hashtable(50); + private Logger logger = Logger.getLogger(PathManager.class.getName()); + private FsimContext fsimContext = null; + private String dbName = null; + + public PathManager(FsimContext fsimContext,String dbName) + { + this.fsimContext=fsimContext; + this.dbName=dbName; + } + + + // ===== update cache. + + public void updatePaths() + { + try + { + logger.info("Building path cache of db: "+dbName); + Connection connection = fsimContext.getConnectionByName(dbName); + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery( + "SELECT path.id,path.directory,path.parent_id,host.id as host_id,host.hostname,spider.udate"+ + " FROM path"+ + " LEFT JOIN host ON path.host_id = host.id"+ + " LEFT JOIN spider ON host.last_spider_id = spider.id"+ + " WHERE path.id>="+paths.size()+" ORDER BY id ASC"); + + while(rs.next()) + { + long id = rs.getLong("id"); + + if(paths.containsKey(new Long(id))) + { + continue; + } + + Path path = new Path(); + path.setID(id); + path.setPath(rs.getString("directory")); + + Host host = getHost(rs.getString("hostname")); + if(host==null) { + host = new Host(); + host.setID(rs.getLong("host_id")); + host.setHostName(rs.getString("hostname")); + host.setLastScanned(rs.getDate("udate")); + host.setRootPaths(new HashSet(4)); + host.setProtocol("ftp://"); // rs.getString("url")); + hosts.put(host.getHostName(),host); + } + path.setHost(host); + + //int parentID = rs.getInt("parent"); + if(rs.getObject("parent_id")==null) { + host.getRootPaths().add(path); + } else { + Path parent = (Path)paths.get(new Long(rs.getLong("parent_id"))); + path.setParent(parent); + parent.getChilderen().add(path); + } + path.setChilderen(new HashSet(4)); + paths.put(new Long(path.getID()),path); + } + logger.info("cached total of paths: "+paths.size()); + logger.info("cached total of hosts: "+hosts.size()); + + rs.close(); + stmt.close(); + connection.close(); + } + catch (Exception sx) + { + System.err.println("error in Paths: "+sx.getMessage()); + sx.printStackTrace(); + } + } + + // ======= paths. + + public Path getPath(long pathID) + { + return (Path)paths.get(new Long(pathID)); + } + + // ======= path browsing. + + public Collection getPaths(Path path) + { + return path.getChilderen(); + } + public List getFiles(Path path) + { + List result = new ArrayList(20); + try + { + Connection connection = fsimContext.getConnectionByName(dbName); + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery( + "SELECT file.name,file.size,file.insert_date "+ + " FROM file"+ + " WHERE file.path_id = "+path.getID()+" ORDER BY file.id ASC"); + + while(rs.next()) + { + File file = new File(); + file.setName(rs.getString("name")); + file.setPath(path); + file.setSize(rs.getInt("size")); + result.add(file); + } + + rs.close(); + stmt.close(); + connection.close(); + } catch (Exception sx) { + System.err.println("error in Paths: "+sx.getMessage()); + sx.printStackTrace(); + } + System.out.println("FILES "+result); + return result; + } + + /** + * note: the file objects have no path !! + * @param host + * @return + */ + public List getRootFiles(Host host) + { + List result = new ArrayList(20); + try + { + Connection connection = fsimContext.getConnectionByName(dbName); + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery( + "SELECT file.name,file.size,file.insert_date,path.id as path_id "+ + " FROM file"+ + " LEFT JOIN path ON file.path_id = path.id"+ + " LEFT JOIN host ON path.host_id = host.id"+ + " WHERE host.id ="+host.getID()+" AND path.parent_id = null ORDER BY file.id ASC"); + + while(rs.next()) + { + File file = new File(); + file.setName(rs.getString("name")); + Path path =(Path)paths.get(new Long(rs.getLong("path_id"))); + file.setPath(path); + file.setSize(rs.getInt("size")); + result.add(file); + } + } + catch (Exception sx) + { + System.err.println("error in Paths: "+sx.getMessage()); + sx.printStackTrace(); + } + System.out.println("ROOT FILES "+result); + return result; + } + + // ====== hosts + + public Collection getHosts() + { + return hosts.values(); + } + public Host getHost(String name) + { + return (Host)hosts.get(name); + } + public Host getHost(long hostID) + { + Iterator i = hosts.values().iterator(); + while(i.hasNext()) + { + Host host =(Host)i.next(); + if(host.getID()==hostID) + { + return host; + } + } + return null; + } +} diff --git a/src/com/idca/fsim/searchers/files/collectors/FileResultCollector.java b/src/com/idca/fsim/searchers/files/collectors/FileResultCollector.java new file mode 100644 index 0000000..8773ccf --- /dev/null +++ b/src/com/idca/fsim/searchers/files/collectors/FileResultCollector.java @@ -0,0 +1,100 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.collectors; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.plugins.AbstractResultCollector; +import com.idca.fsim.models.Hit; +import com.idca.fsim.models.ModelHitTuble; +import com.idca.fsim.searchers.files.PathManager; +import com.idca.fsim.searchers.files.FilesListener; +import com.idca.fsim.searchers.files.models.File; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; +import java.util.Iterator; + +/** + * Returns the File search results + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + */ +public class FileResultCollector extends AbstractResultCollector +{ + public List getResults(List hits,FsimContext fsimContext,List result) + { + PathManager pm = FilesListener.getPathManager(); + + if(hits.size()==0) { + return result; + } + + + String sql = "SELECT file.path_id,file.id as file_id,file.name,file.size,host.hostname,spider.udate"+ + " FROM file"+ + " LEFT JOIN path ON file.path_id = path.id"+ + " LEFT JOIN host ON path.host_id = host.id"+ + " LEFT JOIN spider ON host.last_spider_id = spider.id"+ + " WHERE file.id in ("; //62,248,566,3907,4195,3726)"; + + + //System.out.print("Getting FileResults total="+hits.size()); + Iterator i = hits.iterator(); + while(i.hasNext()) + { + Hit hit = (Hit)i.next(); + sql+=hit.id; + if(i.hasNext()) { + sql+=","; + } else { + sql+=")"; + } + } + + //TODO: what to do with deleted records... delete the hits ?? + // now we skip them. + + try + { + Connection connection = fsimContext.getConnectionByName("fsim_dba"); + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + int h = 0; + while(rs.next()) + { + File file = new File(); + file.setName(rs.getString("name")); + file.setSize(rs.getInt("size")); + file.setPath(pm.getPath(rs.getInt("path_id"))); + + int id = rs.getInt("file_id"); + i = hits.iterator(); + while(i.hasNext()) + { + Hit hit = (Hit)i.next(); + if(hit.id==id) + { + result.add(new ModelHitTuble(hit,file)); + break; + } + } + + } + rs.close(); + stmt.close(); + connection.close(); + } + catch (SQLException sx) + { + System.err.println("SQL error: "+sx.getMessage()); + } + return result; + } +} diff --git a/src/com/idca/fsim/searchers/files/collectors/HostResultCollector.java b/src/com/idca/fsim/searchers/files/collectors/HostResultCollector.java new file mode 100644 index 0000000..3b9358c --- /dev/null +++ b/src/com/idca/fsim/searchers/files/collectors/HostResultCollector.java @@ -0,0 +1,45 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.collectors; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.plugins.AbstractResultCollector; +import com.idca.fsim.models.Hit; +import com.idca.fsim.models.ModelHitTuble; + +import com.idca.fsim.searchers.files.PathManager; +import com.idca.fsim.searchers.files.FilesListener; +import com.idca.fsim.searchers.files.models.Host; + +import java.util.List; +import java.util.Iterator; + +/** + * Returns the Host search results + * + * @author Willem Cazander + * @version 1.0 27/05/2005 + */ +public class HostResultCollector extends AbstractResultCollector +{ + public List getResults(List hits,FsimContext fsimContext,List result) + { + PathManager pm = FilesListener.getPathManager(); + if(hits.size()==0) { + return result; + } + + Iterator i = hits.iterator(); + while(i.hasNext()) + { + Hit hit = (Hit)i.next(); + Host host = pm.getHost(hit.id); + result.add(new ModelHitTuble(hit,host)); + + } + return result; + } +} diff --git a/src/com/idca/fsim/searchers/files/collectors/PathResultCollector.java b/src/com/idca/fsim/searchers/files/collectors/PathResultCollector.java new file mode 100644 index 0000000..50734fa --- /dev/null +++ b/src/com/idca/fsim/searchers/files/collectors/PathResultCollector.java @@ -0,0 +1,53 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.collectors; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.plugins.AbstractResultCollector; +import com.idca.fsim.models.Hit; +import com.idca.fsim.models.ModelHitTuble; +import com.idca.fsim.searchers.files.PathManager; +import com.idca.fsim.searchers.files.FilesListener; +import com.idca.fsim.searchers.files.models.Path; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +/** + * Returns the Path search results. + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + * + */ +public class PathResultCollector extends AbstractResultCollector +{ + public List getResults(List hits,FsimContext fsimContext,List result) + { + PathManager pm = FilesListener.getPathManager(); + if(hits.size()==0) { + return result; + } + + Iterator i = hits.iterator(); + while(i.hasNext()) + { + Hit hit = (Hit)i.next(); + Path path = pm.getPath(hit.id); + if(path!=null) + { + result.add(new ModelHitTuble(hit,path)); + } + else + { + // mm non valid path ID ... + } + } + return result; + } +} diff --git a/src/com/idca/fsim/searchers/files/models/File.java b/src/com/idca/fsim/searchers/files/models/File.java new file mode 100644 index 0000000..f408bc5 --- /dev/null +++ b/src/com/idca/fsim/searchers/files/models/File.java @@ -0,0 +1,77 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.models; + +import java.util.Date; + +/** + * A File on the network. + * + * @author Willem Cazander + * @version 1.0 18/07/2005 + */ +public class File +{ + private String name = null; + private int size = 0; + private Path path = null; + + public void setName(String name) { + this.name = name; + } + public String getName() { + return name; + } + + public void setSize(int size) { + this.size=size; + } + public int getSize() { + return size; + } + + public void setPath(Path path) { + this.path=path; + } + public Path getPath() { + return path; + } + + static public String printSize(File file) + { + String size = Float.toString(new Float(file.getSize()).floatValue()/1024/1000); + if(size.length()>4) + { + size = size.substring(0,4); + } + + if(0==(int)(file.getSize()/1024/1000)) + { + size = Integer.toString((int)new Float(file.getSize()).floatValue()/1024); + if(size.equals("0")) + { + size = ""+file.getSize(); + } + } + if(size.endsWith(".")) + { + size = size.substring(0,size.length()-1); + } + + String sizeType = "MegaByte"; + if(0==(int)(file.getSize()/1024/1000)) + { + sizeType = "KiloByte"; + if(0==(int)(file.getSize()/1024)) + { + sizeType = "Byte"; + } + } + + return size+" "+sizeType; + + } +} diff --git a/src/com/idca/fsim/searchers/files/models/Host.java b/src/com/idca/fsim/searchers/files/models/Host.java new file mode 100644 index 0000000..1e6df0f --- /dev/null +++ b/src/com/idca/fsim/searchers/files/models/Host.java @@ -0,0 +1,69 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.models; + +import java.util.Date; +import java.util.Collection; + +/** + * A Host on the network + * + * @author Willem Cazander + * @version 1.0 20/07/2005 + */ +public class Host +{ + private long id = 0; + private String hostName = null; + private Date lastScanned = null; + private Collection rootPaths = null; + private String protocol = null; + + public void setID(long id) + { + this.id=id; + } + public long getID() + { + return id; + } + + public void setHostName(String hostName) + { + this.hostName = hostName; + } + public String getHostName() + { + return hostName; + } + + public void setLastScanned(Date lastScanned) + { + this.lastScanned = lastScanned; + } + public Date getLastScanned() + { + return lastScanned; + } + + public void setRootPaths(Collection rootPaths) + { + this.rootPaths=rootPaths; + } + public Collection getRootPaths() + { + return rootPaths; + } + + public void setProtocol(String protocol) + { + this.protocol=protocol; + } + public String getProtocol() + { + return protocol; + } +} diff --git a/src/com/idca/fsim/searchers/files/models/Path.java b/src/com/idca/fsim/searchers/files/models/Path.java new file mode 100644 index 0000000..2b2e0c0 --- /dev/null +++ b/src/com/idca/fsim/searchers/files/models/Path.java @@ -0,0 +1,68 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.models; + +import java.util.Collection; + +/** + * A Path on the network + * + * @author Willem Cazander + * @version 1.0 20/07/2005 + */ +public class Path +{ + private long id = 0; + private String path = null; + private Collection childeren = null; + private Path parent = null; + private Host host = null; + + public void setID(long id) + { + this.id = id; + } + public long getID() + { + return id; + } + + public void setPath(String path) + { + this.path = path; + } + public String getPath() + { + return path; + } + + public void setChilderen(Collection childeren) + { + this.childeren = childeren; + } + public Collection getChilderen() + { + return childeren; + } + + public void setParent(Path parent) + { + this.parent = parent; + } + public Path getParent() + { + return parent; + } + + public void setHost(Host host) + { + this.host = host; + } + public Host getHost() + { + return host; + } +} diff --git a/src/com/idca/fsim/searchers/files/renderers/FileResultRenderer.java b/src/com/idca/fsim/searchers/files/renderers/FileResultRenderer.java new file mode 100644 index 0000000..424864b --- /dev/null +++ b/src/com/idca/fsim/searchers/files/renderers/FileResultRenderer.java @@ -0,0 +1,48 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.renderers; + +import com.idca.fsim.core.plugins.ResultRenderer; +import com.idca.fsim.models.Hit; +import com.idca.fsim.searchers.files.models.*; +import com.idca.fsim.web.URLMarker; + +import java.io.PrintWriter; + +/** + * Renders a File result + * + * @author Willem Cazander + * @version 1.0 18/07/2005 + */ +public class FileResultRenderer implements ResultRenderer +{ + + /** + * + */ + public void buildXML(PrintWriter out,Hit hit,Object model,String keywords) + { + File file = (File)model; + } + + /** + * + */ + public void buildHTML(PrintWriter out,Hit hit,Object model,String keywords) + { + File file = (File)model; + out.print("
"); + out.print(URLMarker.markURL(file.getPath().getHost().getProtocol()+file.getPath().getHost().getHostName()+file.getPath().getPath()+file.getName(),keywords)); + out.println("
"); + out.println("Size: "+File.printSize(file)+" - Indexed: "+hit.source.getLastIndexed()+" - Scanned: "+file.getPath().getHost().getLastScanned()); + out.println(""); + out.println("browse"); + //out.println(""); + out.println("
"); + out.println("

"); + } +} diff --git a/src/com/idca/fsim/searchers/files/renderers/HostResultRenderer.java b/src/com/idca/fsim/searchers/files/renderers/HostResultRenderer.java new file mode 100644 index 0000000..933e8e8 --- /dev/null +++ b/src/com/idca/fsim/searchers/files/renderers/HostResultRenderer.java @@ -0,0 +1,41 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.renderers; + +import com.idca.fsim.core.plugins.ResultRenderer; +import com.idca.fsim.models.Hit; +import com.idca.fsim.searchers.files.models.*; +import com.idca.fsim.web.URLMarker; + +import java.io.PrintWriter; + +/** + * Renders an Host result + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + */ +public class HostResultRenderer implements ResultRenderer +{ + + + public void buildXML(PrintWriter out,Hit hit,Object model,String keywords) + { + Host host = (Host)model; + } + + public void buildHTML(PrintWriter out,Hit hit,Object model,String keywords) + { + Host host = (Host)model; + out.print("
"); + out.print(URLMarker.markURL(host.getProtocol()+host.getHostName(),keywords)); + out.println("
"); + out.println("Scanned: "+host.getLastScanned()); + out.println(""); + out.println("browse"); + out.println("

"); + } +} \ No newline at end of file diff --git a/src/com/idca/fsim/searchers/files/renderers/PathResultRenderer.java b/src/com/idca/fsim/searchers/files/renderers/PathResultRenderer.java new file mode 100644 index 0000000..b6670c9 --- /dev/null +++ b/src/com/idca/fsim/searchers/files/renderers/PathResultRenderer.java @@ -0,0 +1,42 @@ +/* + * + * + */ + +package com.idca.fsim.searchers.files.renderers; + +import com.idca.fsim.core.plugins.ResultRenderer; +import com.idca.fsim.models.Hit; +import com.idca.fsim.searchers.files.models.*; +import com.idca.fsim.web.URLMarker; + +import java.io.PrintWriter; + +/** + * Renders a Path result + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + */ +public class PathResultRenderer implements ResultRenderer +{ + + + public void buildXML(PrintWriter out,Hit hit,Object model,String keywords) + { + Path path = (Path)model; + } + + public void buildHTML(PrintWriter out,Hit hit,Object model,String keywords) + { + Path path = (Path)model; + out.print("
"); + out.print(URLMarker.markURL(path.getHost().getProtocol()+path.getHost().getHostName()+path.getPath(),keywords)); + out.println("
"); + out.println("Directories: "+path.getChilderen().size()+" - Scanned: "+hit.source.getLastIndexed()+"- Scanned: "+path.getHost().getLastScanned()); + out.println(""); + out.println(""); + out.println("browse

"); + } + +} diff --git a/src/com/idca/fsim/web/AdminServlet.java b/src/com/idca/fsim/web/AdminServlet.java new file mode 100644 index 0000000..42fa289 --- /dev/null +++ b/src/com/idca/fsim/web/AdminServlet.java @@ -0,0 +1,231 @@ +/* + * + */ + +package com.idca.fsim.web; + +import java.io.IOException; +import java.util.Date; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.FsimServer; +import com.idca.fsim.core.indexer.IndexRequest; +import com.idca.fsim.core.plugins.SearchSource; +import com.idca.fsim.searchers.files.FilesListener; + +/** + * Proves the access for the admin pages. + * + * @author Willem Cazander + * @version 1.0 23/07/2005 + */ +public class AdminServlet extends HttpServlet +{ + /** */ + private FsimContext fsimContext = null; + /** */ + private String hostBlockedRedirectURL = null; + /** */ + private int hostBlockedNoAdminPeneltyTime = 0; + + + /** + * The service method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try { + + HttpSession session = request.getSession(); + + boolean isAdmin = false; + Boolean admin = (Boolean)session.getAttribute("admin"); + if(admin!=null) + { + if(admin.booleanValue()) + { + isAdmin = true; + } + } + if(!isAdmin) + { + /* + MonitoredHttpHost host = new MonitoredHttpHost(); + host.setHostAddress(request.getRemoteAddr()); + host.setMonitorStartDate(new Date()); + host.addRequest(RequestLoggerFilter.printNotificationURL(request)); + host.addMessage("Trying to get admin page while not being admin."); + fsimContext.addMonitoredHTTPHost(host); + host.addBlockedTime(hostBlockedNoAdminPeneltyTime*60*1000); + SendBlockedRedirect.sendBlockedRedirect(response,host,hostBlockedRedirectURL); + return; + */ + return; + } + + + String mode = request.getParameter("m"); + int m = 0; + if(mode!=null) + { + try { + m = new Integer(mode).intValue(); + } catch (Exception e) { + m = 0; + } + } + + + request.setAttribute("drawSearch",new Boolean(false)); + request.setAttribute("drawPageResults",new Boolean(false)); + + RequestDispatcher top = request.getRequestDispatcher("fragments/fsim_top.jsp"); + top.include(request, response); + + switch(m) + { + default: + case 0: + //request.setAttribute("sessions",fsimContext.getHttpSessions()); + // RequestDispatcher sessionsPage = request.getRequestDispatcher("fragments/fsim_sessions.jsp"); + // sessionsPage.include(request, response); + break; + case 1: + + String hostAddress = request.getParameter("host_address"); + + if(request.getParameter("host_add")!=null) + { + /* + String reason = request.getParameter("host_reason"); + MonitoredHttpHost host = new MonitoredHttpHost(); + host.setHostAddress(hostAddress); + host.setMonitorStartDate(new Date()); + host.addMessage("ADDED BY ADMIN: "+reason); + host.addRequest("ADDED BY ADMIN"); + fsimContext.addMonitoredHTTPHost(host); + */ + } + if(request.getParameter("host_monitoring_remove")!=null) + { + //fsimContext.removeMonitoring(hostAddress); + } + if(request.getParameter("host_permanent_add")!=null) + { + //MonitoredHttpHost host = fsimContext.getMonitoredHTTPHost(hostAddress); + // host.setPermenent(true); + } + if(request.getParameter("host_permanent_remove")!=null) + { + // MonitoredHttpHost host = fsimContext.getMonitoredHTTPHost(hostAddress); + // host.setPermenent(false); + } + + ////request.setAttribute("httpHosts",fsimContext.getMonitoredHTTPHosts()); + //RequestDispatcher httpHostsPage = request.getRequestDispatcher("fragments/fsim_httphosts.jsp"); + /// httpHostsPage.include(request, response); + break; + case 2: + + if(request.getParameter("source_index")!=null) + { + // do indeing + SearchSource ss = fsimContext.getSearchSource(request.getParameter("source_name")); + IndexRequest indexRequest = new IndexRequest(ss,fsimContext); + indexRequest.execute(); + } + if(request.getParameter("path_update")!=null) + { + FilesListener.getPathManager().updatePaths(); + } + if(request.getParameter("wordlists_info")!=null) + { + SearchSource ss = fsimContext.getSearchSource("fsim-files"); + System.out.println(ss.getWordLists().dumpInfo()); + } + + request.setAttribute("sources",fsimContext.getSearchSources()); + RequestDispatcher sourcesPage = request.getRequestDispatcher("fragments/fsim_sources.jsp"); + sourcesPage.include(request, response); + break; + } + + RequestDispatcher bottom = request.getRequestDispatcher("fragments/fsim_bottom.jsp"); + bottom.include(request, response); + + + } catch (Exception e) { + RequestDispatcher sessionsPage = request.getRequestDispatcher("denied/real_error.jsp"); + sessionsPage.include(request, response); + } + } + + /** + * + */ + public void init(ServletConfig servletConfig) throws ServletException + { + fsimContext = FsimServer.getFsimContext(servletConfig.getServletContext().getInitParameter("FsimContextName")); + if(fsimContext==null) { + throw new ServletException("could not find fsimContextName: "+servletConfig.getServletContext().getInitParameter("FsimContextName")); + } + String hostBlockedNoAdminPeneltyTimeString = servletConfig.getInitParameter("hostBlockedNoAdminPeneltyTime"); + if(hostBlockedNoAdminPeneltyTimeString == null) + { + throw new ServletException("Could not find hostBlockedNoAdminPeneltyTime in ServletConfig."); + } + try { + hostBlockedNoAdminPeneltyTime = new Integer(hostBlockedNoAdminPeneltyTimeString).intValue(); + } catch(Exception e) { + throw new ServletException("hostBlockedNoAdminPeneltyTime is not an Integer"); + } + + hostBlockedRedirectURL = servletConfig.getServletContext().getInitParameter("hostBlockedRedirectURL"); + if(hostBlockedRedirectURL==null) + { + throw new ServletException("could not find hostBlockedRedirectURL in ServletContext."); + } + } + + + public long getLastModified(HttpServletRequest request) + { + return System.currentTimeMillis(); + } + + /** + * Returns information about the servlet, such as + * author, version, and copyright. + * + * @return String information about this servlet + */ + public String getServletInfo() + { + return "The FSIM admin servlet (c)2005 IDCA"; + } + + /** + * Destruction of the servlet.
+ */ + public void destroy() + { + super.destroy(); + } + + +} diff --git a/src/com/idca/fsim/web/PluginPageServlet.java b/src/com/idca/fsim/web/PluginPageServlet.java new file mode 100644 index 0000000..3d30e68 --- /dev/null +++ b/src/com/idca/fsim/web/PluginPageServlet.java @@ -0,0 +1,162 @@ +/* + * + */ + +package com.idca.fsim.web; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.FsimServer; +import com.idca.fsim.core.plugins.ResultRenderer; +import com.idca.fsim.models.ModelHitTuble; +import com.idca.fsim.models.Hit; + +import java.io.IOException; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Include an plugin page + * + * @author Willem Cazander + * @version 1.0 23/07/2005 + */ +public class PluginPageServlet extends HttpServlet +{ + /** */ + private FsimContext fsimContext = null; + /** */ + private String hostBlockedRedirectURL = null; + /** */ + private int hostBlockedParameterPeneltyTime = 0; + + /** + * The service method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try { + + String up = request.getParameter("up"); + if(up==null) + { + /* + MonitoredHttpHost host = new MonitoredHttpHost(); + host.setHostAddress(request.getRemoteAddr()); + host.setMonitorStartDate(new Date()); + host.addMessage("Parameter 'up' not given."); + fsimContext.addMonitoredHTTPHost(host); + host.addBlockedTime(hostBlockedParameterPeneltyTime*60*1000); + SendBlockedRedirect.sendBlockedRedirect(response,host,hostBlockedRedirectURL); + */ + return; + } + String page = fsimContext.getJSPIncludePage(up); + if(page==null) + { + /* + MonitoredHttpHost host = new MonitoredHttpHost(); + host.setHostAddress(request.getRemoteAddr()); + host.setMonitorStartDate(new Date()); + host.addMessage("page could not be found in specefied plugin pages."); + fsimContext.addMonitoredHTTPHost(host); + host.addBlockedTime(hostBlockedParameterPeneltyTime*60*1000); + SendBlockedRedirect.sendBlockedRedirect(response,host,hostBlockedRedirectURL); + */ + return; + } + boolean drawFPD = true; + if("false".equals(request.getParameter("fpd"))) + { + drawFPD = false; + } + + response.setHeader("Cache-Control", "no-cache"); + response.setContentType("text/html; charset=UTF-8"); + + request.setAttribute("drawSearch",new Boolean(false)); + request.setAttribute("drawPageResults",new Boolean(false)); + + System.out.println("hit:"+request.getSession().getAttribute("hit")+" model:"+request.getSession().getAttribute("model")); + + if(drawFPD) + { + RequestDispatcher top = request.getRequestDispatcher("fragments/fsim_top.jsp"); + top.include(request, response); + } + + RequestDispatcher ppage = request.getRequestDispatcher(page); + ppage.include(request, response); + + if(drawFPD) + { + RequestDispatcher bottom = request.getRequestDispatcher("fragments/fsim_bottom.jsp"); + bottom.include(request, response); + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("WE HAVE EN ERROR IN PLUNGIN"); + } + } + + /** + * + */ + public void init(ServletConfig servletConfig) throws ServletException + { + fsimContext = FsimServer.getFsimContext(servletConfig.getServletContext().getInitParameter("FsimContextName")); + if(fsimContext==null) { + throw new ServletException("could not find fsimContextName: "+servletConfig.getServletContext().getInitParameter("FsimContextName")); + } + String hostBlockedParameterPeneltyTimeString = servletConfig.getInitParameter("hostBlockedParameterPeneltyTime"); + if(hostBlockedParameterPeneltyTimeString == null) + { + throw new ServletException("Could not find hostBlockedParameterPeneltyTime in ServletConfig."); + } + try { + hostBlockedParameterPeneltyTime = new Integer(hostBlockedParameterPeneltyTimeString).intValue(); + } catch(Exception e) { + throw new ServletException("hostBlockedParameterPeneltyTime is not an Integer"); + } + + hostBlockedRedirectURL = servletConfig.getServletContext().getInitParameter("hostBlockedRedirectURL"); + if(hostBlockedRedirectURL==null) + { + throw new ServletException("could not find hostBlockedRedirectURL in ServletContext."); + } + } + + /** + * prevents caching + */ + public long getLastModified(HttpServletRequest request) + { + return System.currentTimeMillis(); + } + + /** + * Returns information about the servlet, such as + * author, version, and copyright. + * + * @return String information about this servlet + */ + public String getServletInfo() + { + return "The FSIM plugin servlet (c)2005 IDCA"; + } +} diff --git a/src/com/idca/fsim/web/RedirectServlet.java b/src/com/idca/fsim/web/RedirectServlet.java new file mode 100644 index 0000000..d70cece --- /dev/null +++ b/src/com/idca/fsim/web/RedirectServlet.java @@ -0,0 +1,165 @@ +/* + * + */ + +package com.idca.fsim.web; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.FsimServer; +import com.idca.fsim.core.plugins.SearchSource; +import com.idca.fsim.models.Hit; +import com.idca.fsim.models.ModelHitTuble; + +import java.util.Date; +import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; + +import java.io.IOException; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * Redirect to other includes pages. + * + * @author Willem Cazander + * @version 1.0 23/07/2005 + */ +public class RedirectServlet extends HttpServlet +{ + /** */ + private FsimContext fsimContext = null; + /** */ + private String hostBlockedRedirectURL = null; + /** */ + private int hostBlockedParameterPeneltyTime = 0; + /** */ + private String pluginPageRedirectURL = null; + + /** + * The service method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try { + String ssString = request.getParameter("ss"); + if(ssString==null) + { + return; + } + SearchSource ss = fsimContext.getSearchSource(ssString); + if(ss==null) + { + return; + } + + Integer recordID = null; + try { + recordID = new Integer(request.getParameter("rid")); + } catch(Exception e) { + return; + } + + Hit hit = ss.getHit(recordID); + if(hit==null) + { + return; + } + // increase the value of this hit... !!!! + hit.clicked++; + + String up = request.getParameter("up"); + if(up==null) + { + return; + } + List hits = new ArrayList(); + hits.add(hit); + List tu = hit.source.getResultCollector().getResults(hits,fsimContext,new ArrayList(1)); + + Iterator t = tu.iterator(); + if(!t.hasNext()) + { + return; + } + ModelHitTuble modelHit = (ModelHitTuble)t.next(); + + HttpSession session = request.getSession(); + session.setAttribute("hit",modelHit.getHit()); + session.setAttribute("model",modelHit.getModel()); + + // door naar page + response.sendRedirect(pluginPageRedirectURL+"?up="+up+"&rid="+recordID+"&ss="+ss.getName()+"&fpd="+request.getParameter("fpd")); + + } catch (Exception e) { + e.printStackTrace(); + System.out.println("ERROR IN REDIRECT SERVLET"); + } + } + + /** + * + */ + public void init(ServletConfig servletConfig) throws ServletException + { + fsimContext = FsimServer.getFsimContext(servletConfig.getServletContext().getInitParameter("FsimContextName")); + if(fsimContext==null) { + throw new ServletException("could not find fsimContextName: "+servletConfig.getServletContext().getInitParameter("FsimContextName")); + } + + String hostBlockedParameterPeneltyTimeString = servletConfig.getInitParameter("hostBlockedParameterPeneltyTime"); + if(hostBlockedParameterPeneltyTimeString == null) + { + throw new ServletException("Could not find hostBlockedParameterPeneltyTime in ServletConfig."); + } + try { + hostBlockedParameterPeneltyTime = new Integer(hostBlockedParameterPeneltyTimeString).intValue(); + } catch(Exception e) { + throw new ServletException("hostBlockedParameterPeneltyTime is not an Integer"); + } + + hostBlockedRedirectURL = servletConfig.getServletContext().getInitParameter("hostBlockedRedirectURL"); + if(hostBlockedRedirectURL==null) + { + throw new ServletException("could not find hostBlockedRedirectURL in ServletContext."); + } + + pluginPageRedirectURL = servletConfig.getInitParameter("pluginPageRedirectURL"); + if(pluginPageRedirectURL==null) + { + throw new ServletException("coudl not find pluginPageRedirectURL in ServletContext"); + } + } + + + /** + * prevents caching + */ + public long getLastModified(HttpServletRequest request) + { + return System.currentTimeMillis(); + } + + /** + * Returns information about the servlet, such as + * author, version, and copyright. + * + * @return String information about this servlet + */ + public String getServletInfo() + { + return "The FSIM redirect servlet (c)2005 IDCA"; + } +} diff --git a/src/com/idca/fsim/web/SearchServlet.java b/src/com/idca/fsim/web/SearchServlet.java new file mode 100644 index 0000000..04ddb94 --- /dev/null +++ b/src/com/idca/fsim/web/SearchServlet.java @@ -0,0 +1,235 @@ +/* + * Created on jul 16, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.web; + +import com.idca.fsim.core.*; +import com.idca.fsim.core.plugins.*; +import com.idca.fsim.models.*; +import com.idca.fsim.web.session.SearchBean; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.RequestDispatcher; + +import com.idca.fsim.searchers.files.collectors.*; + +import java.util.*; +import java.util.logging.Logger; + +/** + * The contoll servlet for the search pages + * + * @author Willem Cazander + * @version 1.0 + */ +public class SearchServlet extends HttpServlet +{ + /** */ + private FsimContext fsimContext = null; + /** */ + private Logger logger = Logger.getLogger(SearchServlet.class.getName()); + + + /** + * + */ + public void init(ServletConfig servletConfig) throws ServletException + { + fsimContext = FsimServer.getFsimContext(servletConfig.getServletContext().getInitParameter("FsimContextName")); + if(fsimContext==null) { + throw new ServletException("could not find fsimContextName: "+servletConfig.getServletContext().getInitParameter("FsimContextName")); + } + } + + + /** + * The service method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request the request send by the client to the server + * @param response the response send by the server to the client + * @throws ServletException if an error occurred + * @throws IOException if an error occurred + */ + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try { + HttpServletRequest httpRequest = (HttpServletRequest)request; + HttpServletResponse httpResponse = (HttpServletResponse)response; + HttpSession session = httpRequest.getSession(false); + + response.setHeader("Cache-Control", "no-cache"); + PrintWriter out = response.getWriter(); + + SearchBean searchBean = (SearchBean)session.getAttribute("searchbean"); + + String mode = request.getParameter("m"); + int m = 0; + if(mode!=null) { + m = new Integer(mode).intValue(); + } + + String sources = (String)session.getAttribute("searchSources"); + if(sources==null) { + sources = "fsim-files;fsim-paths;fsim-hosts"; // default search all + session.setAttribute("searchSources",sources); + } else { + sources = ""; + if(request.getParameter("fsim-files")!=null) { + sources = "fsim-files"; + } + if(request.getParameter("fsim-paths")!=null) { + sources += ";fsim-paths"; + } + if(request.getParameter("fsim-hosts")!=null) { + sources += ";fsim-hosts"; + } + session.setAttribute("searchSources",sources); + } + + + + switch(m) + { + + + default: + case 0: + // an normal full page search + response.setContentType("text/html; charset=UTF-8"); + request.setAttribute("searchSources2",fsimContext.getSearchSources()); + long start = System.currentTimeMillis(); + + int p = 0; + String page = request.getParameter("p"); + if(page!=null) + { + try { + p = new Integer(page).intValue(); + } catch (Exception e) { + // block fukker. + p = 0; + } + } + searchBean.setSearchSources(sources); + + String q = request.getParameter("q"); + if(q==null) { + q = ""; + } + if(q.length()>40) { + q = "max query size"; + } + + searchBean.setSearchQuery(q); + searchBean.doSearch(); + + searchBean.setPageIndex(p); + + long searchTime = System.currentTimeMillis(); + + request.setAttribute("searchBean",searchBean); + request.setAttribute("resultSize",new Integer(searchBean.getSearchHits().size())); + request.setAttribute("searchTime",new Long(searchTime-start)); + + request.setAttribute("drawSearch",new Boolean(true)); + request.setAttribute("drawPageResults",new Boolean(true)); + + RequestDispatcher top = request.getRequestDispatcher("fragments/fsim_top.jsp"); + top.include(request, response); + + Collection pageResults = searchBean.getModelHitTublePageResults(); + if(pageResults.size()>0) + { + Iterator i = pageResults.iterator(); + while(i.hasNext()) { + ModelHitTuble modelHit = (ModelHitTuble)i.next(); + //System.out.println("source="+modelHit.getHit().source.getName()+" model="+modelHit.getModel().getClass().getName()); + modelHit.getHit().source.getResultRenderer().buildHTML(out,modelHit.getHit(),modelHit.getModel(),searchBean.getSearchQuery()); + } + } + long renderTime = System.currentTimeMillis(); + request.setAttribute("renderTime",new Long(renderTime-searchTime)); + RequestDispatcher bottom = request.getRequestDispatcher("fragments/fsim_bottom.jsp"); + bottom.include(request, response); + + break; + case 1: + // THE XML keywords + //System.out.println("mode 1 building xml list"); + response.setContentType("text/xml; charset=UTF-8"); + + String letters = request.getParameter("l"); + // small hack :) + String[] wd = letters.split(" "); + letters = wd[wd.length-1]; + if(letters!=null) { + + Searcher searcher = new Searcher(fsimContext.getSearchSource("fsim-files").getWordLists()); + searcher.setSearchSources(sources); + Collection result = searcher.searchWords(letters,false); + + Iterator i = result.iterator(); + int max = 20; + out.println(""); + while(i.hasNext()) { + Word word = (Word)i.next(); + out.println(""); + max--; + if(max==0) { + break; + } + } + + out.println(""); + + } + + break; + } + + //out.flush(); + // out.close(); + } catch (Exception e) { + e.printStackTrace(); + + } + } + + + public long getLastModified(HttpServletRequest request) { + return System.currentTimeMillis(); + } + + /** + * Returns information about the servlet, such as + * author, version, and copyright. + * + * @return String information about this servlet + */ + public String getServletInfo() { + return "The FSIM search servlet (c)2005 IDCA"; + } + + /** + * Destruction of the servlet.
+ */ + public void destroy() { + super.destroy(); // Just puts "destroy" string in log + } + +} diff --git a/src/com/idca/fsim/web/URLMarker.java b/src/com/idca/fsim/web/URLMarker.java new file mode 100644 index 0000000..badcb3a --- /dev/null +++ b/src/com/idca/fsim/web/URLMarker.java @@ -0,0 +1,113 @@ +/* + * + * + */ + +package com.idca.fsim.web; + +import java.util.ArrayList; +import java.util.Iterator; + +/** + * Marks the keywords in the link url. + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2006 + */ +public class URLMarker +{ + static public String markURL(String url,String keywords) + { + url = ""+url.toLowerCase()+""; + String[] keywordsList = keywords.split(" "); + + for(int i=0;i"+keywordsList[i]+""); + url = url.replaceAll(keywordsList[i],""+keywordsList[i]+""); + + + if(!keyword.equals(keywordsList[i])) { + + url = url.replaceAll(keywordsList[i],""+keywordsList[i]+""); + url = url.replaceAll(keywordsList[i].toLowerCase(),""+keywordsList[i]+""); + } + + } + + return url; + } +} + + + /* + + if(true) + { + return url; + } + + boolean shorting = false; + if(url.length()>70) + { + shorting = true; + } + System.out.println(url); + + String[] webQs = keywords.toLowerCase().split(" "); + ArrayList segments = new ArrayList(7); + + int lastIndex = 0; + for(int index=0;index!=-1;) + { + int i =0; + for(;i<=webQs.length && index!=-1;i++) + { + index = url.toLowerCase().indexOf(webQs[i]); + //System.out.println("checked: "+webQs[i]+" lasti:"+lastIndex+" index: "+index+" word="+webQs[i]+" checking="+url.substring(lastIndex)); + if(index!=-1 & index!=lastIndex+1) + { + System.out.println("index="+index+" li="+lastIndex); + System.out.println("add seg= "+url.substring(lastIndex,index)); + segments.add(url.substring(lastIndex,index)); + System.out.println("add HIGH seg= "+url.substring(index,index+webQs[i].length())); + segments.add(""+url.substring(index,index+webQs[i].length())+""); + + lastIndex = 0; + url = url.substring(index+webQs[i].length()); + index = 0; + break; + } + } + + if(url.length()>0) { + segments.add(url); + + } + + } + + + Iterator i2 = segments.iterator(); + String result = ""; + while(i2.hasNext()) + { + String segment = (String)i2.next(); + + if(shorting && segment.indexOf("tsKeywordHi")==-1 && segment.length()>70) + { + segment = segment.substring(0,20)+"..."+segment.substring(segment.length()-20); + } + result+=segment; + } + + System.out.println(result); + System.out.println(url); + + return result; + } + + + */ \ No newline at end of file diff --git a/src/com/idca/fsim/web/filters/AuthenticationFilter.java b/src/com/idca/fsim/web/filters/AuthenticationFilter.java new file mode 100644 index 0000000..1330b50 --- /dev/null +++ b/src/com/idca/fsim/web/filters/AuthenticationFilter.java @@ -0,0 +1,98 @@ +/* + * Created on jul 23, 2005 + * + * Copyright 2004 IDCA. All rights reserved. + * IDCA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +package com.idca.fsim.web.filters; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.FsimServer; +import com.idca.fsim.web.session.SearchBean; + +import java.util.logging.Logger; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * Checks if our user is logedin. + * + * @author Willem Cazander + * @version 1.0 23/07/2005 + */ +public class AuthenticationFilter implements Filter +{ + /** */ + private Logger logger = Logger.getLogger(AuthenticationFilter.class.getName()); + /** */ + private FsimContext fsimContext = null; + /** */ + private String logoutRedirectURL = null; + + /** + * + */ + public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws ServletException + { + try + { + // l'amore e bienco, ma il matromonio gla rida la vista + HttpServletRequest httpRequest = (HttpServletRequest)request; + HttpServletResponse httpResponse = (HttpServletResponse)response; + HttpSession session = httpRequest.getSession(); + + // check for user login brrrrr + if("ffssimm".equals(request.getParameter("fsimpass")) && "fsimadmin".equals(request.getParameter("fsimuser"))) { + session.setAttribute("admin",new Boolean(true)); + session.setMaxInactiveInterval(1200); + } + // check logout + if("true".equals(request.getParameter("logout"))) { + session.invalidate(); + httpResponse.sendRedirect(logoutRedirectURL); + return; + } + + SearchBean searchBean = (SearchBean)session.getAttribute("searchbean"); + if(searchBean==null) { + // user should always have an searchBean !!. + searchBean = new SearchBean(fsimContext); + searchBean.setLocale(request.getLocale()); + //searchBean.s(new ArrayList(1)); + session.setAttribute("searchbean",searchBean); + logger.info("USER session searchBean created from: "+httpRequest.getRequestURL()+" to "+httpRequest.getRemoteAddr()); + } + filterChain.doFilter(request,response); + } + catch (Exception ex) { + throw new ServletException(ex); + } + } + + + public void init(FilterConfig filterConfig) throws ServletException + { + fsimContext = FsimServer.getFsimContext(filterConfig.getServletContext().getInitParameter("FsimContextName")); + if(fsimContext==null) { + throw new ServletException("could not find fsimContextName: "+filterConfig.getServletContext().getInitParameter("FsimContextName")); + } + + logoutRedirectURL = filterConfig.getInitParameter("logoutRedirectURL"); + if(logoutRedirectURL==null) + { + throw new ServletException("could not find logoutRedirectURL"); + } + } + + public void destroy() + { + } +} \ No newline at end of file diff --git a/src/com/idca/fsim/web/session/SearchBean.java b/src/com/idca/fsim/web/session/SearchBean.java new file mode 100644 index 0000000..cd86d3c --- /dev/null +++ b/src/com/idca/fsim/web/session/SearchBean.java @@ -0,0 +1,300 @@ +/* + * + */ + +package com.idca.fsim.web.session; + +import com.idca.fsim.core.FsimContext; +import com.idca.fsim.core.Searcher; +import com.idca.fsim.core.plugins.ResultCollector; +import com.idca.fsim.core.plugins.SearchSource; +import com.idca.fsim.models.Hit; +import com.idca.fsim.models.ModelHitTuble; + +import java.util.Collection; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Hashtable; +import java.util.Map; +import java.util.HashMap; +import java.util.Locale; + +/** + * Provides the logic backend for the + * web searcher + * + * @author Willem Cazander + * @version 1.0 25/07/2005 + */ +public class SearchBean +{ + /** */ + private FsimContext fsimContext = null; + // some user var. + private Locale locale = null; + private int resultsPageSize = 250; + private int keywordsListSize = 25; + + // search data + private String searchQuery = ""; + private String lastSearchQuery = ""; + private Map searchSources = new Hashtable(2); + private String searchSources2 = ""; + private String searchSources3 = ""; + private List searchHits = new ArrayList(1); + private Collection searchPageHits = null; + private int pageIndex = 0; + private int pagePageIndex = 0; + private int maxPages = 13; + private List modelHitTublePageResults = new ArrayList(1); + + public SearchBean(FsimContext fsimContext) + { + this.fsimContext=fsimContext; + } + + + // =================== user prefences + + public void setLocale(Locale locale) + { + this.locale = locale; + } + public Locale getLocale() + { + return locale; + } + + public void setResultsPageSize(int resultsPageSize) + { + this.resultsPageSize = resultsPageSize; + } + public int getResultsPageSize() + { + return resultsPageSize; + } + + public void setKeywordsListSize(int keywordsListSize) + { + this.keywordsListSize=keywordsListSize; + } + public int getKeywordsListSize() + { + return keywordsListSize; + } + + // ================= search logic. + + public void setSearchSources(String ss) + { + searchSources2 = ss; + } + + + public void addSearchSource(SearchSource searchSource) + { + searchSources.put(searchSource.getName(),searchSource); + } + public void removeSearchSource(String searchSourceName) + { + searchSources.remove(searchSourceName); + } + public Collection getSearchSources() + { + return searchSources.values(); + } + + //==== + + public void setSearchQuery(String searchQuery) + { + if(searchQuery==null) + { + searchQuery=""; + } + this.searchQuery=searchQuery; + } + public String getSearchQuery() + { + return searchQuery; + } + + // ==== + + public void setPageIndex(int pageIndex) + { + this.pageIndex = pageIndex*resultsPageSize; + if(getHasMorePages()) + { + pagePageIndex = pageIndex; + } + + } + public int getPageIndex() + { + return pageIndex; + } + + + // ========== The real search + + public void doSearch() + { + //fsimContext.getSearchSource("fsim-files").getWordLists().dumpInfo(); + + if("".equals(searchQuery)) + { + // clear results. + searchHits = new ArrayList(1); + lastSearchQuery = ""; + pageIndex = 0; + modelHitTublePageResults = new ArrayList(); + return; + } + + // reset search on change + if (searchSources2.equals(searchSources3)==false) { + searchSources3 = searchSources2; + lastSearchQuery = "old"; + } + + + // only search when new search query is given. + if(!lastSearchQuery.equals(searchQuery)) + { + + searchHits= new ArrayList(400); + for (Object ss1:fsimContext.getSearchSources()) { + SearchSource ss = (SearchSource)ss1; + if (searchSources2.contains(ss.getName())) { + Searcher searcher = new Searcher(fsimContext.getSearchSource(ss.getName()).getWordLists()); + //searcher.setSearchSources(searchSources2); + Collection hits = searcher.searchHits(searchQuery,true); + searchHits.addAll(hits); + } + } + + + lastSearchQuery=searchQuery; + } + + // build pageHits + if(pageIndex>searchHits.size()) + { + pageIndex=searchHits.size(); + pagePageIndex=(searchHits.size()/resultsPageSize)-maxPages; + if(pagePageIndex<0) { + pagePageIndex = 0; + } + } + if(pageIndex<0) + { + pageIndex=0; + pagePageIndex=0; + } + int toIndex = pageIndex+resultsPageSize; + if(toIndex>searchHits.size()) + { + toIndex=searchHits.size(); + } + searchPageHits = searchHits.subList(pageIndex,toIndex); + + // build l + modelHitTublePageResults = new ArrayList(resultsPageSize); + if(searchPageHits.size()==0) + { + // nothing to get. + return; + } + + // split page results into different lists of same source.name. + HashMap collectors = new HashMap(2); + Iterator i = searchPageHits.iterator(); + while(i.hasNext()) + { + Hit hit = (Hit)i.next(); + List list = (List)collectors.get(hit.source); + if(list==null) + { + list = new ArrayList(); + collectors.put(hit.source,list); + } + list.add(hit); + } + // run all collectors + i = collectors.keySet().iterator(); + while(i.hasNext()) + { + SearchSource ss = (SearchSource)i.next(); + List hits = (List)collectors.get(ss); + modelHitTublePageResults = ss.getResultCollector().getResults(hits,fsimContext,modelHitTublePageResults); + } + + // last sort to the searchPageHits. + List sorted = new ArrayList(resultsPageSize); + i = searchPageHits.iterator(); + while(i.hasNext()) + { + Hit hit = (Hit)i.next(); + //TODO: add some speed improment here + // (its only for page 10-100 page result on the screen.) + Iterator t = modelHitTublePageResults.iterator(); + while(t.hasNext()) + { + ModelHitTuble modelHit = (ModelHitTuble)t.next(); + if(modelHit.getHit().equals(hit)) + { + sorted.add(modelHit); + break; + } + } + } + modelHitTublePageResults = sorted; + } + + // ======== Get the search results. + + public Collection getModelHitTublePageResults() + { + return modelHitTublePageResults; + } + + + public List getSearchHits() + { + return searchHits; + } + + + /** + * geeft alleen de viewable pages weer. + * @return + */ + public List getPages() + { + // calc number of pages + ArrayList pages = new ArrayList(2); + int p = searchHits.size()/resultsPageSize; + p++; + //System.out.println("pages p="+p+" maxp="+maxPages+" ppi="+pagePageIndex); + for(int page=pagePageIndex;page<(maxPages+pagePageIndex) & p>page && p>1;page++) { + //System.out.println("page="+page+" < "+(maxPages+pagePageIndex)); + pages.add(new Integer(page)); + } + return pages; + } + public boolean getHasMorePages() + { + //System.out.println("sh="+searchHits.size()+"rps="+resultsPageSize); + int p = searchHits.size()/resultsPageSize; + p++; + //System.out.println("has more p="+p+" maxp="+maxPages+" ppi="+pagePageIndex); + if(p-maxPages>pagePageIndex) + { + //System.out.println("has more pages -- true"); + return true; + } + return false; + } +}