SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

842 lines
31 KiB

package de.superx.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Date;
import java.util.Enumeration;
import java.util.Set;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.apache.log4j.Logger;
import org.dom4j.DocumentException;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DataSourceProviderFactory;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.KettleLogStore;
import org.xml.sax.SAXException;
import de.memtext.db.NichtAngemeldetException;
import de.memtext.tree.KeyParentEqualException;
import de.memtext.util.DateUtils;
import de.memtext.util.ServletHelper;
import de.memtext.util.TimeUtils;
import de.memtext.util.TransletUtils;
import de.memtext.util.XMLUtils;
import de.superx.common.DBServletException;
import de.superx.common.SxUser;
import de.superx.common.TransletCache;
import de.superx.sec.HttpGetAccessGuard;
import de.superx.sec.HttpGetAccessListParser;
import de.superx.sec.InputCheckRegistry;
import de.superx.util.SqlStringUtils;
/**
* A servlet which can be advised to reload static resources
*/
public class SuperXManager extends HttpServlet {
private static Logger logger = Logger.getLogger(SuperXManager.class);
public static final String QIS_CONTEXT = "QIS_CONTEXT";
private static final long serialVersionUID = 2L;
public static final long maxMillisWaitingTime = 60000 * 15; // 15 minutes should be sufficient
public static String his1_refapp="";
private SuperXInitThread initThread;
public static boolean isZukuenftigerStandErlaubt = true;
public static int maxRows = 20000;
public static String defaultMaskXsl = "maske_html.xsl";
public static String defaultTableHtmlXsl = "tabelle_html.xsl";
public static String defaultTableXlsXsl = "tabelle_xls.xsl";
public static String defaultTablePdfXsl = "tabelle_fo_pdf.xsl";
public static String csvEncoding = null;
public static String sharedSecret = "";
private static String xmenu, xmask, xtablehtml, xtablexsl, xtablepdf;
public static boolean isSichtenCachingWanted = true;
public static String sxversion="@version@";
public static String builddatum="@sxtimestamp@";
public static HttpGetAccessGuard httpGetAccessGuard;
private static final String ADMIN_ONLY = de.superx.servlet.SuperXManager.htmlPageHead("Admin-Bereich")+"<center><h3>Hier ist ein Login nur für Administratoren m&ouml;glich.</h3>(Cookies m&uuml;ssen aktiviert sein)"
+ "<FORM ACTION=\"SuperXManager\" METHOD=\"post\"><p><p>Kennung: <br /><INPUT TYPE=\"Text\" NAME=\"kennung\" VALUE=\"superx\"></p><p><p>Passwort: <br /><INPUT TYPE=\"Password\" NAME=\"passwort\" value=\"\">"
+ "</p><p>MandantenID<br><input type=\"text\" name=\"MandantenID\" value=\"default\"></p><br><INPUT TYPE=\"Submit\" NAME=\"Abschicken\" VALUE=\"Anmelden\"></FORM></center></body></html>";
private static String pageBeginning = htmlPageHead("Webanwendung Manager")+"<h1 align=center>SuperX Manager</h1><center>"
+ "SuperX @version@ (build:@sxtimestamp@)" + "</center>";
public static String pageEnd = "</div></body></html>";
public static StringBuffer activityLog = new StringBuffer();
// letzter maskensql bevor FreeMarker loslegte
private static String lastFMMaskenSql;
private static String lastMaskenSql = "--";
private static String lastXml = "--";
private static String lastMaskenSqlMandantid = "";
private static String lastXmlMandantid = "--";
// siehe SxSql_server.executeAll
public static boolean isDevelopmentMode = true;
private static boolean isLastSqlExtraPageWanted = true;
// private static ResourceBundle rb =
// ResourceBundle.getBundle("LocalStrings");
static public boolean isXMLReturnLinkWanted = true;
static String refererstart = null;
public static String field1Cache;
private static CacheUpdater cashUpdater = new CacheUpdater();
public static boolean isHis1 = false;
private static String webinfPfad = ".";
private static String moduleDir=""; //
public static boolean isResponseCompressionWanted=true;
public static String sendBackLocalizedHtml="";
private static String noSessionFieldDefaults;
private static Date start = null;
private static boolean isStandaloneLdapActive = false;
// public static String userField1Cache;//in UserInitializer sind Ansaetze -
// (noch) nicht umgesetzt
public static String getMaxRowsHinweis() {
return " Die Datenbank lieferte eine große Menge an Datensätzen. Es werden generell nur die ersten "
+ SuperXManager.maxRows
+ " dargestellt, in Datenblatt-Abfragen ggf. sogar weniger. Schränken Sie Ihre Abfrage ggfs. weiter ein oder nutzen den Excelexport";
}
public static boolean isSessionFieldDefaultsWanted(String mandantenID)
{
if (noSessionFieldDefaults==null) noSessionFieldDefaults="";
return noSessionFieldDefaults.indexOf(","+mandantenID+",")==-1;
}
public void init(ServletConfig config) throws ServletException {
super.init(config);
logger.debug("SuperXManager start.");
start = new Date();
//tomcat8 verlangt einen virtual Path separator / vor WEB-INF
//vergl. http://stackoverflow.com/questions/25555541/getservletcontext-getrealpath-in-tomcat-8-returns-wrong-path
webinfPfad = getServletConfig().getServletContext().getRealPath(
"/WEB-INF");
//System.out.println("WEB-INF Pfad : "+webinfPfad);
// are we running in a HISinOne env?
// init Prozess wird in eigenem Thread gestaretet, damit HIs1-init
// weiterläuft während superx wartet
try {
//MB provisorisch an dieser Stelle für Kern4.9 eingebaut
//Kern5 bzw HisMaster ab 2021.06 ist woanders
initLdapPasswordCheckingIfConfigured();
initThread = new SuperXInitThread(config);
initThread.start();
} catch (Exception e) {
throw new ServletException(e.getMessage());
}
}
public static String getWEB_INFPfad() {
return webinfPfad;
}
public static void setWEB_INFPfad(String p) {
webinfPfad=p;
}
private void initXSLFilenames() {
//tomcat8 verlangt einen virtual Path separator / vor xml
//vergl. http://stackoverflow.com/questions/25555541/getservletcontext-getrealpath-in-tomcat-8-returns-wrong-path
xmenu = "file:///"
+ getServletConfig().getServletContext().getRealPath(
"/xml/" + "menue_html.xsl");
xmask = "file:///"
+ getServletConfig().getServletContext().getRealPath(
"/xml/" + SuperXManager.defaultMaskXsl);
xtablehtml = "file:///"
+ getServletConfig().getServletContext().getRealPath(
"/xml/" + SuperXManager.defaultTableHtmlXsl);
xtablexsl = "file:///"
+ getServletConfig().getServletContext().getRealPath(
"/xml/" + SuperXManager.defaultTableXlsXsl);
xtablepdf = "file:///"
+ getServletConfig().getServletContext().getRealPath(
"/xml/" + SuperXManager.defaultTablePdfXsl);
}
public static void initStandardXsl()
throws TransformerConfigurationException, DBServletException {
TransletCache.getTransformer(null, xmenu);
TransletCache.getTransformer(null, xmask);
TransletCache.getTransformer(null, xtablehtml);
TransletCache.getTransformer(null, xtablexsl);
// TransletCache.getTransformer("default", xtablepdf);
}
public void destroy() {
super.destroy();
try {
if (initThread != null)
initThread.destroy();
SxPools.closeAll();
cashUpdater.setActive(false);
cashUpdater.interrupt();
} catch (Exception e) {
e.printStackTrace();
}
try {
for (Enumeration en = DriverManager.getDrivers(); en
.hasMoreElements();) {
Driver d = (Driver) en.nextElement();
try {
DriverManager.deregisterDriver(d);
logger.info(new java.util.Date() + "{} deregister {}" + d);
} catch (Exception e) {
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// System.setProperty("SuperX-DB-PROPERTIES-SET", "false");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
AbstractSuperXServlet.setEncoding(request);
response.setContentType("text/html; charset="
+ SqlStringUtils.getEncoding());
if (ServletHelper.getParameter(request, "kennung") != null
&& ServletHelper.getParameter(request, "passwort") != null) {
UserInitializer ui = new UserInitializer(request, false);
try {
ui.perform();
} catch (Exception e) {
throw new ServletException("Authentifizierung für "
+ ServletHelper.getParameter(request, "kennung")
+ " fehlgeschlagen");
}
}
if (request.getParameter("xupdater") != null) {
XUpdaterServlet xu = new XUpdaterServlet();
xu.doPost(request, response);
} else {
SxUser user = (SxUser) request.getSession().getAttribute("user");
if (user == null || !user.isAdmin()) {
PrintWriter output = response.getWriter();
output.write(ADMIN_ONLY);
output.flush();
} else {
SxManager m = new SxManager(request, response);
m.run(false);
}
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset="
+ SqlStringUtils.getEncoding());
SxUser user = (SxUser) request.getSession().getAttribute("user");
if (user == null || !user.isAdmin()) {
PrintWriter output = response.getWriter();
output.write(ADMIN_ONLY);
output.flush();
output.close();
} else {
if (request.getParameter("xupdater") != null) {
XUpdaterServlet xu = new XUpdaterServlet();
xu.doGet(request, response);
} else {
PrintWriter output = response.getWriter();
String showLastSqlXml = ServletHelper.getParameter(request,
"showlastsqlxml");
boolean isLastSqlXmlWantend = showLastSqlXml != null
&& showLastSqlXml.equals("true");
if (isLastSqlXmlWantend) {
output.write(pageBeginning + getLastSqlXml(request) + pageEnd);
} else {
output.write(getStandardPage(request, "") + pageEnd);
}
output.flush();
output.close();
}
}
}
private String getLastSqlXml(HttpServletRequest currentreq) {
StringBuffer result = new StringBuffer("<br>");
String m = ServletUtils.getMandantenID(currentreq);
if(m.equalsIgnoreCase(lastMaskenSqlMandantid))
{
// <br> Stand:"+new Date()+"
result.append("<center><table><tr>");
result.append("<td><p align=center><b>letzter Masken sql (vom XML-Frontend)<br>vor FreeMarker-Transformation</b></p><textarea name=\"sql\" rows=20 cols=50>"
+ lastFMMaskenSql + "</textarea></td>");
result.append("<td><p align=center><b>letzter Masken sql (vom XML-Frontend)</b></p><textarea name=\"sql\" rows=20 cols=50>"
+ lastMaskenSql
+ "</textarea></td>"
+ "<td><p align=center><b>letztes XML</b></p><textarea name=\"xml\" rows=20 cols=50>"
+ lastXml + "</textarea></td></tr></table></center>");
}
else
result.append("Bitte wiederholen Sie den Aufruf mit dem jew. Mandant");
return result.toString();
}
public String getStandardPage(HttpServletRequest request, String comment) {
String m = ServletUtils.getMandantenID(request);
StringBuffer result = new StringBuffer(
pageBeginning
+ (m.equals("default") ? "" : "<center>(Mandant: " + m
+ ")<br>\n")
+ "\n<br>"
+ "<center><form action=\"SuperXManager\" method=post>"
+ comment
+ "\n<br><br><input type=submit name=\"cache\" value=\"Server-Cache aktualisieren\">&nbsp;<input type=submit name=\"clearStylesheets\" value=\"nur Stylesheet-Cache leeren\"></font><br>"
+ "<font>Es werden Erl&auml;uterungen und &Uuml;bersetzungen (captions) gecacht.<br>F&uuml;rs XML-Frontend auch: User,Userrechte und Sichten,<br> und auch Abfragen wenn in der db.properties eingetragen</font> <br><br>"
+ "<font size=+1>Entwicklungsmodus ist "
+ (isDevelopmentMode ? "AN" : "AUS")
+ " <input type=radio name=\"Entwicklungsmodus\" value=\"an\""
+ (isDevelopmentMode ? "checked" : "")
+ ">an\n<input type=radio name=\"Entwicklungsmodus\" value=\"aus\""
+ (!isDevelopmentMode ? "checked" : "")
+ ">aus\n"
+ "\n</font><input type=submit value=\"&Uuml;bernehmen\"><br>"
+ "(Im Entwicklungsmodus werden alle SQL-Befehle von Abfragen einzeln an die Datenbank geschickt.<br>Das dauert l&auml;nger, erm&ouml;glicht aber bessere Fehlermeldungen.)<br><br>"
+ "Achtung: bei Informix sollten Sie den Entwicklungsmodus nicht ausschalten, der JDBC-Treiber arbeitet dann instabil.<br><br>"
+
"\n<br><br><input type=submit name=\"clearlogfiles\" value=\"Log-Dateien leeren\"><br>\n");
result.append("</form>");
if (isLastSqlExtraPageWanted) {
result.append(getLastSqlXml(request));
} else {
result.append("<a href=\"SuperXManager?showlastsqlxml=true\" target=\"_blank\">letzter SQL / XML</a><br><br><hr>");
}
result.append("<center><h2>LOG <a href=\"SuperXManager\">aktualisieren<a/></h2><br>"
+ // <textarea name=\"xml\"
// rows=30 cols=80>"
activityLog
+ "<br><hr><a href=\"SuperXManager\">LOG aktualisieren<a/>");// +
result.append("<br><br>" + SxPools.getPoolFinRechteInfos());
// "</textarea></center>");
result.append(pageEnd);
return result.toString();
}
public static void setLastMaskenSql(String sql) {
lastMaskenSql = sql;
}
public static String getLastMaskenSql() {
return lastMaskenSql;
}
public static void setLastXml(String xml) {
lastXml = xml;
}
public static String getLastXml() {
return lastXml;
}
public static String getLastMaskenSqlMandantid() {
return lastMaskenSqlMandantid;
}
public static void setLastMaskenSqlMandantid(String lastMaskenSqlMandantid) {
SuperXManager.lastMaskenSqlMandantid = lastMaskenSqlMandantid;
}
public static String getLastXmlMandantid() {
return lastXmlMandantid;
}
public static void setLastXmlMandantid(String lastXmlMandantid) {
SuperXManager.lastXmlMandantid = lastXmlMandantid;
}
/**
* Alles neu einlesen Immer nur ein Thread darf zugreifen
*
* @param request
* darf null sein
*
* @throws KeyParentEqualException
* @throws NichtAngemeldetException
* @throws ParseException
* @throws ParserConfigurationException
* @throws FactoryConfigurationError
* @throws SAXException
* @throws DocumentException
* @throws SQLException
* @throws DBServletException
* @throws TransformerException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws SecurityException
* @throws IllegalArgumentException
*/
static synchronized void initAll() throws KeyParentEqualException,
NichtAngemeldetException, ParseException,
ParserConfigurationException, FactoryConfigurationError,
SAXException, DocumentException, IllegalArgumentException,
SecurityException, InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException, SQLException,
DBServletException, TransformerException {
SxPools.resetAllPools();
logger.debug(" using encoding: " + SqlStringUtils.getEncoding());
clearTransletStylesheets();
}
public static void initPool(HttpServletRequest request, String mandantenID)
throws TransformerConfigurationException, SQLException,
DBServletException, IOException {
logger.debug(de.memtext.util.DateUtils.getNowString()
+ " Server Cache wird neu geladen für :" + mandantenID);
MaskenContainer mc = MaskenContainer.getFromRequest(request);
mc.clear();
if (mandantenID.equals("default"))
SxPools.resetAllPools();
else
SxPools.get(mandantenID).init();
logger.debug(" using encoding: " + SqlStringUtils.getEncoding());
clearTransletStylesheets();
initStandardXsl();
}
public static void clearTransletStylesheets()
throws TransformerConfigurationException, DBServletException {
logger.debug(DateUtils.getNowString() + " Stylesheet-Cache geleert");
TransletCache.clear();
}
public String getServletInfo() {
return "SuperXManager";
}
public static void clearLog() {
activityLog.setLength(0);
}
public static void logActivity(java.util.logging.Level level, String log) {
if (level == null)
level = java.util.logging.Level.INFO;
activityLog.append(TimeUtils.getNowString() + " " + log + "<br>");
}
/**
* Als innere Klasse hat SxManager auch Zugriff auf die initAll-Methode
*/
private class SxManager extends SuperXServletHelper {
public SxManager(HttpServletRequest request,
HttpServletResponse response) throws IOException {
super(request, response);
}
protected void perform() throws IOException, IllegalArgumentException,
SecurityException, KeyParentEqualException,
NichtAngemeldetException, ParseException,
ParserConfigurationException, FactoryConfigurationError,
SAXException, DocumentException, InstantiationException,
IllegalAccessException, InvocationTargetException,
NoSuchMethodException, SQLException, DBServletException,
TransformerException {
String comment = "";
if (request.getParameterMap().containsKey("cache")) {
initPool(request, getMandantenID());
initStandardXsl();
comment = "Resources neu geladen: "
+ DateUtils.getTodayString() + " "
+ DateUtils.getNowString();
}
if (request.getParameterMap().containsKey("clearStylesheets")) {
clearTransletStylesheets();
comment = "Stylesheet-Cache geleert: "
+ DateUtils.getTodayString() + " "
+ DateUtils.getNowString();
}
if (request.getParameterMap().containsKey("clearlogfiles")) {
SxPools.clearLogFiles();
comment = "LogDateien geleert";
}
if (ServletHelper.getParameter(request, "Entwicklungsmodus") != null)
isDevelopmentMode = ServletHelper.getParameter(request,
"Entwicklungsmodus").equals("an");
PrintWriter output = response.getWriter();
response.setContentType("text/html; charset="
+ SqlStringUtils.getEncoding());
output.write(getStandardPage(request, comment));
output.write(pageEnd);
output.flush();
}
}
/**
* @return Returns the lastFMMaskenSql.
*/
public static String getLastFMMaskenSql() {
return lastFMMaskenSql;
}
/**
* @param lastFMMaskenSql
* The lastFMMaskenSql to set.
*/
public static void setLastFMMaskenSql(String lastFMMaskenSql) {
SuperXManager.lastFMMaskenSql = lastFMMaskenSql;
}
public static void main(String args[]) {
System.out.println("SuperX @version@ (build:@sxtimestamp@)");
System.out.println(SqlStringUtils.getEncoding());
}
class SuperXInitThread extends Thread {
private ServletConfig config;
private boolean isDestroyWanted = false;
public SuperXInitThread(ServletConfig config) throws SecurityException,
IOException {
this.config = config;
}
public void destroy() {
isDestroyWanted = true;
}
public void run() {
logger.debug("SuperXInit thread start.");
while (!isDestroyWanted
&& (System.getProperty("SuperX-DB-PROPERTIES-SET") == null || !System
.getProperty("SuperX-DB-PROPERTIES-SET")
.equalsIgnoreCase("true"))) {
long totalTimeWaiting = System.currentTimeMillis() - start.getTime();
try {
Thread.sleep(4000);
logger.info("SuperXInit waiting. Total: " + Long.valueOf(totalTimeWaiting) + "millis");
if (totalTimeWaiting > maxMillisWaitingTime) {
throw new InterruptedException("*** SuperXManager timeout!\n"
+ "Java System-Property SuperX-DB-PROPERTIES-SET not set!\n"
+ "HISinOne Business Intelligence may not be usable!\n"
+ "Please check if Module EDUSTORE in modules.xml is active\n"
+ "and EdustoreManager has run correctly on HISinOne startup! ***");
}
} catch (InterruptedException e) {
logger.warn("SuperXinit interrupted!", e);
throw new RuntimeException(e);
}
}
isHis1 = true;
logger.debug("Webanwendung Manager startet - SuperX-DB-PROPERTIES-SET=true gefunden");
try {
doInit();
} catch (ServletException e) {
e.printStackTrace();
throw new IllegalStateException("SuperX Init fehlgeschlagen " + e.getMessage());
}
}
private void doInit() throws ServletException {
initHttpGetAccessGuard();
InputCheckRegistry.registerDefaultChecks();
his1_refapp=System.getProperty(QIS_CONTEXT);
if(his1_refapp==null)
his1_refapp="";
else
logger.debug("SuperX found HisInOne webapp: " + his1_refapp);
XMLUtils.getExceptionHandler().setWithGui(false);
XMLUtils.getExceptionHandler().setExitWanted(false);
ServletUtils.setPath(getServletConfig().getServletContext()
.getRealPath("xml"));
initXSLFilenames();
refererstart = config.getInitParameter("referer_start");
if (refererstart != null && !refererstart.trim().equals(""))
logger.debug("Referer wird kontrolliert auf "
+ refererstart);
String zukuenftigerStandErlaubt = config
.getInitParameter("zukünftigerStandErlaubt");
if (zukuenftigerStandErlaubt != null
&& zukuenftigerStandErlaubt.equals("false"))
isZukuenftigerStandErlaubt = false;
// Link zur Neuanmeldung beim XML-Frontend, Freiburg will abschalten
String xmlReturnLink = config.getInitParameter("xml_return_link");
if (xmlReturnLink != null && xmlReturnLink.equals("false"))
isXMLReturnLinkWanted = false;
String last_sql_extra_page = config
.getInitParameter("last_sql_extra_page");
if (last_sql_extra_page != null
&& last_sql_extra_page.equals("false"))
isLastSqlExtraPageWanted = false;
String xsl_parser = config.getInitParameter("xsl_processor");
if (xsl_parser != null)
TransletUtils.initFactory(xsl_parser,
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
else
TransletUtils.initFactory(
"net.sf.saxon.TransformerFactoryImpl", null);
logger.debug("Using xsl processor: " +
TransletUtils.getUsedProcessor());
SuperXManager.sharedSecret = config
.getInitParameter("sharedSecret");
if (SuperXManager.sharedSecret == null) {
SuperXManager.sharedSecret = "";
}
String mxr = config.getInitParameter("maxRows");
if (mxr != null && !mxr.equals(""))
SuperXManager.maxRows = (Integer.parseInt(mxr));
logger.warn("SuperXManager: maxRows: " + Integer.valueOf(SuperXManager.maxRows) + " (wenn mehr geliefert wird, werden die zusaetzlichen Datenzeilen ignoriert)");
String defaultXsl;
String moduleDir="";
defaultXsl = config.getInitParameter("defaultMaskXsl");
if (defaultXsl != null && !defaultXsl.trim().equals("")) {
SuperXManager.defaultMaskXsl = defaultXsl;
logger.debug("SuperXManager: defaultMaskXsl: " + SuperXManager.defaultMaskXsl);
if(defaultXsl.equals("maske_html_his1.xsl"))
{isHis1=true;
moduleDir=SuperXManager.getWEB_INFPfad()+ File.separator + "conf" + File.separator + "edustore"
+ File.separator + "db" + File.separator + "module" ;
}
else
{isHis1=false;
if(System.getProperty("MODULE_PFAD") != null
&& !System.getProperty("MODULE_PFAD").toString().equals(""))
moduleDir=System.getProperty("MODULE_PFAD").toString();
else
moduleDir=SuperXManager.getWEB_INFPfad()+ File.separator + ".." + File.separator
+ ".." + File.separator
+ ".." + File.separator
+ ".." + File.separator
+ ".." + File.separator
+ "db" + File.separator + "module" ; //default kann durch setModuleDir überschrieben werden (KettleExecutor)
}
logger.debug("SuperXManager: MODULE_PFAD: " +moduleDir);
setModuleDir(moduleDir);
}
defaultXsl = config.getInitParameter("defaultTableHtmlXsl");
if (defaultXsl != null && !defaultXsl.trim().equals("")) {
SuperXManager.defaultTableHtmlXsl = defaultXsl;
logger.debug("SuperXManager: defaultTableHtmlXsl: " +
SuperXManager.defaultTableHtmlXsl);
}
defaultXsl = config.getInitParameter("defaultTableXlsXsl");
if (defaultXsl != null && !defaultXsl.trim().equals("")) {
SuperXManager.defaultTableXlsXsl = defaultXsl;
logger.debug("SuperXManager: defaultTableXlsXsl: " +
SuperXManager.defaultTableXlsXsl);
}
defaultXsl = config.getInitParameter("defaultTablePdfXsl");
if (defaultXsl != null && !defaultXsl.trim().equals("")) {
SuperXManager.defaultTablePdfXsl = defaultXsl;
logger.debug("SuperXManager: defaultTablePdfXsl: " +
SuperXManager.defaultTablePdfXsl);
}
String f1 = config.getInitParameter("field1Cache");
if (f1 != null && !f1.equals(""))
field1Cache = f1;
String rc=config.getInitParameter("isResponseCompressionWanted");
if (rc!=null&&rc.equalsIgnoreCase("false")) isResponseCompressionWanted=false;
String lh=config.getInitParameter("sendBackLocalizedHtml");
if (lh!=null&&!lh.equalsIgnoreCase("")) sendBackLocalizedHtml=lh;
String sichtcache = config.getInitParameter("sichtenCaching");
if (sichtcache != null && sichtcache.equalsIgnoreCase("false"))
isSichtenCachingWanted = false;
// f1=config.getInitParameter("userField1Cache");
// if (f1!=null&&!f1.equals(""))
// userField1Cache=f1;
noSessionFieldDefaults=","+config.getInitParameter("noSessionFieldDefaults")+",";
if (noSessionFieldDefaults==null) noSessionFieldDefaults="";
csvEncoding=config.getInitParameter("CSV-Encoding");
if (csvEncoding==null || csvEncoding.equalsIgnoreCase(""))
csvEncoding=SqlStringUtils.getEncoding();
else
csvEncoding=csvEncoding.trim();
try {
initKettleEnv();
} catch (Exception e) {
e.printStackTrace();
System.err.println("Kettle konnte nicht initialisiert werden.DETAILS:" + e.getMessage());
}
try {
SxPools.init();
initAll();
initStandardXsl();
cashUpdater.start();
} catch (Exception e) {
e.printStackTrace();
throw new ServletException(
"SuperX konnte nicht initialisiert werden.DETAILS:" + e.getMessage());
}
logger.debug("SuperXInit finished after " + ((new Date()).getTime() - start.getTime()) + " millis");
}
}
public static void initKettleEnv() {
// init kettle environment
try {
KettleEnvironment.init();
KettleLogStore.init();
logger.debug("Kettle environment sucessfully initialized.");
} catch (KettleException e) {
logger.error("Couldn't initialize KettleEnvironment!", e);
}
// DBHandlerDataSourceProviderInterface to access HIS1 DBHandler as DataSources
//hatte für Mandanten nicht funktioniert
//DataSourceProviderFactory.setDataSourceProviderInterface(new KettleDataSourceProvider("default",logger));
// init KettleLogStore
}
private final static class CacheUpdater extends Thread {
private java.util.Date lastUpdate;
private boolean isActive = true;
public void run() {
while (isActive) {
java.util.Date now = new java.util.Date();
try {
Thread.sleep(30 * 60 * 1000);
} catch (InterruptedException e) {
// e.printStackTrace();
}
if (now.getHours() == 7
&& (lastUpdate == null || lastUpdate.getDay() != now
.getDay())) {
try {
logger.info(DateUtils.getTodayString() + " " + DateUtils.getNowString() + " Server-Cache-Aktualisierung");
SuperXManager.initAll();
lastUpdate = now;
} catch (Exception e) {
logger.error("Server-Cache-Aktualisierung fehlgeschlagen:", e);
}
}
// else System.out.println(DateUtils.getNowString()+
// " keine Server-Cache akt.");
}
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
}
/**
* Seitenkopf für html-Seiten, die direkt ohne xslt ausgegeben werden
* @param titel Titel für die html- Seite
* @return html-Schnipsel vom head bis Anfang body-Tag
*/
public static String htmlPageHead(String title) {
//TODO: Seiten Kopf dynamisch aus web.xml oder besser sx_captions:
String ret="<html><head><title>"+title+"</title><link rel=\"stylesheet\" type=\"text/css\" href=\"../style/superx.css\" />" +
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/superx/xml/his1/css/HISinOneErrorMessages.css\" />"+
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/bulma.css\" />" +
"<META HTTP-EQUIV=\"CACHE-CONTROL\" CONTENT=\"NO-CACHE\" />"
+ " <META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\" />"
+ " <META HTTP-EQUIV=\"EXPIRES\" CONTENT=\"0\"/>"+
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../xml/superxml_html.css\" /></head>\n<body><div class=\"box\">\n";
if (isHis1) {
ret += "<link rel='stylesheet' type='text/css' href='/superx/xml/his1/css/HISinOne.css'>\n"
+"<a href='/superx/servlet/SuperXmlAbmeldung' target='_parent' style='cursor:pointer; font-weight: bold;' class='ui-link'>Abmelden von Standardberichte</a>";
}
return ret;
}
public static void setModuleDir(String md)
{
moduleDir=md;
}
public static String getModuleDir()
{
return moduleDir ;
}
private void initLdapPasswordCheckingIfConfigured() {
File superxStandaloneLdapConfigFile = new File(
SuperXManager.webinfPfad + File.separator + "superx_standalone_ldap.properties");
if (superxStandaloneLdapConfigFile.exists()) {
System.out.println(" Passwortkontrolle via LDAP wird aktiviert");
isStandaloneLdapActive = true;
try {
LdapPasswordChecker.setup(superxStandaloneLdapConfigFile);
} catch (Exception e) {
System.out.println(" Konfiguration Passwordkontrolle via LDAP fehlgeschlagen " + e);
e.printStackTrace();
}
}
}
public static boolean isStandaloneLdapActive() {
return isStandaloneLdapActive;
}
private void initHttpGetAccessGuard() {
httpGetAccessGuard = new HttpGetAccessGuard();
String blacklist_filename = SuperXManager.getWEB_INFPfad() + File.separator +
"http_get_masken_blacklist.txt";
String blacklist_custom_filename = SuperXManager.getWEB_INFPfad() + File.separator +
"http_get_masken_blacklist_custom.txt";
String whitelist_filename = SuperXManager.getWEB_INFPfad() + File.separator +
"http_get_masken_whitelist.txt";
httpGetAccessGuard.setBlacklist(parseWhiteBlacklistFile(blacklist_filename));
httpGetAccessGuard.setBlacklist_custom(parseWhiteBlacklistFile(blacklist_custom_filename));
httpGetAccessGuard.setWhitelist(parseWhiteBlacklistFile(whitelist_filename));
}
private Set<Integer> parseWhiteBlacklistFile(String list_filename) {
File list_file = new File(list_filename);
if (list_file.exists()) {
try {
String content = de.memtext.util.StringUtils.readFile(list_file);
return HttpGetAccessListParser.parseList(content);
} catch (IOException e) {
logger.error("could not read file '" + list_file.getAbsolutePath());
} catch (NumberFormatException e) {
logger.error("could not parse file '" + list_file.getAbsolutePath(), e);
}
}
return null;
}
}