From 3ca75f77ca7cb539573ca559b6cfc9a0bec6b1c0 Mon Sep 17 00:00:00 2001 From: ulrich <not disclosed> Date: Sun, 19 Mar 2017 09:19:26 +0000 Subject: [PATCH] Fehlerseite 'nicht erlaubt' --- src/java/de/uhilger/filecms/api/FileMgr.java | 82 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java index 3e1073c..8fb1ea3 100644 --- a/src/java/de/uhilger/filecms/api/FileMgr.java +++ b/src/java/de/uhilger/filecms/api/FileMgr.java @@ -46,10 +46,16 @@ public class FileMgr extends Api { private static final Logger logger = Logger.getLogger(FileMgr.class.getName()); + public static final String WBX_DATA_PATH = "daten/"; public static final String PUB_DIR_PATH = "www/"; public static final String HOME_DIR_PATH = "home/"; public static final String PUB_DIR_NAME = "Oeffentlich"; - public static final String HOME_DIR_NAME = "Persoenlicher Ordner"; + //public static final String HOME_DIR_NAME = "Persoenlicher Ordner"; + public static final String HOME_DIR_NAME = "Persoenlich"; + public static final String WBX_ADMIN_ROLE = "wbxAdmin"; + + public static final String WBX_BASE = "$basis"; + public static final String WBX_DATA = "$daten"; public static final int OP_COPY = 1; public static final int OP_MOVE = 2; @@ -58,7 +64,18 @@ return "Hallo Welt!"; } + /** + * Inhalte der WebBox listen. Hier wird nur der relative Pfad + * ausgehend von www oder home ausgegeben sowie zudem ausgehend + * von $daten und $basis, sofern der Benutzer die Rolle wbxAdmin hat. + * + * Andere Inhalte werden nicht ausgegeben. + * + * @param relPath + * @return + */ public List<FileRef> list(String relPath) { + Bild bild = new Bild(); List<FileRef> files = new ArrayList(); if(relPath.length() == 0) { FileRef namedPublicFolder = new FileRef(PUB_DIR_NAME, true); @@ -67,7 +84,13 @@ logger.finer(namedHomeFolder.getAbsolutePath()); files = new ArrayList(); files.add(namedHomeFolder); - files.add(namedPublicFolder); + files.add(namedPublicFolder); + if(getRequest().isUserInRole(WBX_ADMIN_ROLE)) { + FileRef namedBaseFolder = new FileRef(WBX_BASE, true); + FileRef namedDataFolder = new FileRef(WBX_DATA, true); + files.add(namedBaseFolder); + files.add(namedDataFolder); + } } else { String path = getTargetDir(relPath).getAbsolutePath(); logger.fine("listing path: " + path); @@ -81,7 +104,9 @@ fname = fname.substring(0, fname.length() - 1); } logger.fine(fname); - files.add(new FileRef(fname, fileArray[i].isDirectory())); + FileRef ref = new FileRef(fname, fileArray[i].isDirectory()); + ref.setMimetype(bild.getMimeType(fileArray[i])); + files.add(ref); } } } @@ -333,7 +358,7 @@ File newImgFile = new File(dir, buf.toString()); if(!newImgFile.exists()) { logger.fine(original.getAbsolutePath() + " " + newImgFile.getAbsolutePath()); - bild.writeImageFile(image, bild.getVariantenGroesse(i), bild.getMimeType(original), original.getAbsolutePath(), newImgFile.getAbsolutePath()); + bild.writeImageFile(image, bild.getVariantenGroesse(i), bild.getMimeType(original), newImgFile.getAbsolutePath()); //bild.writeImageFile(image, photo.getVariantenGroesse(i), photo.getMimetype(), photo.getAbsolutePath(basisPfad), photo.getVariantenName(basisPfad, i)); } } @@ -347,19 +372,52 @@ /* ---- Hilfsfunktionen ---- */ + /** + * Einen relativen Pfad in einen absoluten Pfad der WebBox + * aufloesen. + * + * Nur die absoluten Pfade zu PUB_DIR_NAME, HOME_DIR_NAME + * sowie WBX_BASE und WBX_DATA werden ausgegeben. Letztere + * beiden nur fuer Nutzer mit der Rolle WBX_ADMIN_ROLE. + * + * D.h., es werden nur Pfade aufgeloest, die sich innerhalb + * des Ordners der WeBox befinden. + * + * @param relPath + * @return + */ private File getTargetDir(String relPath) { logger.fine(relPath); + File targetDir; String targetPath = null; if(relPath.startsWith(PUB_DIR_NAME)) { targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length()); + targetDir = new File(getBase().getAbsolutePath(), targetPath); } else if(relPath.startsWith(HOME_DIR_NAME)) { targetPath = HOME_DIR_PATH + getUserName() + relPath.substring(HOME_DIR_NAME.length()); + targetDir = new File(getBase().getAbsolutePath(), targetPath); + } else if(getRequest().isUserInRole(WBX_ADMIN_ROLE)) { + if(relPath.startsWith(WBX_BASE)) { + targetPath = getCatalinaBase(); + targetDir = new File(targetPath, relPath.substring(WBX_BASE.length())); + } else if(relPath.startsWith(WBX_DATA)) { + targetPath = getWbxDataDir(); + targetDir = new File(targetPath, relPath.substring(WBX_BASE.length())); + } else { + targetDir = getDefaultDir(relPath); + } } else { // kann eigentlich nicht sein.. + targetDir = getDefaultDir(relPath); } logger.fine(targetPath); - File targetDir = new File(getBase().getAbsolutePath(), targetPath); + //File targetDir = new File(getBase().getAbsolutePath(), targetPath); return targetDir; + } + + private File getDefaultDir(String relPath) { + String targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length()); + return new File(getBase().getAbsolutePath(), targetPath); } private FileRef getBase() { @@ -382,4 +440,18 @@ } return userName; } + + private String getCatalinaBase() { + String path = getServletContext().getRealPath("/"); + logger.fine("getRealPath: " + path); // file-cms in webapps + File file = new File(path); + file = file.getParentFile().getParentFile(); + return file.getAbsolutePath(); + } + + private String getWbxDataDir() { + String wbxBase = getBase().getAbsolutePath(); + File file = new File(wbxBase); + return file.getAbsolutePath(); + } } \ No newline at end of file -- Gitblit v1.9.3