Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	admin-tools-core/README.md
#	admin-tools-core/pom.xml
#	admin-tools-dbbrowser/README.md
#	admin-tools-dbbrowser/pom.xml
#	admin-tools-demo-core/pom.xml
#	admin-tools-demo-jar/pom.xml
#	admin-tools-demo-war/pom.xml
#	admin-tools-filebrowser/README.md
#	admin-tools-filebrowser/pom.xml
#	admin-tools-jminix/README.md
#	admin-tools-jminix/pom.xml
#	admin-tools-log4j2/README.md
#	admin-tools-log4j2/pom.xml
#	admin-tools-melody/README.md
#	admin-tools-melody/pom.xml
#	admin-tools-properties/README.md
#	admin-tools-properties/pom.xml
#	admin-tools-quartz/README.md
#	admin-tools-quartz/pom.xml
#	admin-tools-security/admin-tools-security-simple/pom.xml
#	pom.xml
  • Loading branch information
andrehertwig committed Mar 19, 2018
2 parents 1dd93cd + c802d13 commit 4157247
Show file tree
Hide file tree
Showing 17 changed files with 1,733 additions and 1,629 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This is just a spare-time project. The usage of this tool (especially in production systems) is at your own risk.

Last Release: 1.1.6.1 - 18.01.2018
Prev Release: 1.1.6.1 - 18.01.2018
Last Release: 1.1.6.2 - 20.03.2018

[![Maven Central](https://img.shields.io/maven-central/v/de.chandre.admin-tools/admin-tools-core.svg)](https://mvnrepository.com/artifact/de.chandre.admin-tools)
[![GitHub issues](https://img.shields.io/github/issues/andrehertwig/admintool.svg)](https://github.com/andrehertwig/admintool/issues)
Expand Down Expand Up @@ -79,7 +80,7 @@ Include the dependencies in your dependency management. You can find it in [Mave
<dependency>
<groupId>de.chandre.admin-tools</groupId>
<artifactId>admin-tools-core</artifactId>
<version>1.1.6.1</version>
<version>1.1.6.2</version>
</dependency>
...
```
Expand Down
2 changes: 1 addition & 1 deletion admin-tools-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>de.chandre.admin-tools</groupId>
<artifactId>admin-tools-core</artifactId>
<version>1.1.6.1</version>
<version>1.1.6.2</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions admin-tools-dbbrowser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ Result will be displayed via jquery.datatables
<dependency>
<groupId>de.chandre.admin-tools</groupId>
<artifactId>admin-tools-core</artifactId>
<version>1.1.6.1</version>
<version>1.1.6.2</version>
</dependency>
<dependency>
<groupId>de.chandre.admin-tools</groupId>
<artifactId>admin-tools-dbbrowser</artifactId>
<version>1.1.6.1</version>
<version>1.1.6.2</version>
</dependency>
```

Expand Down
8 changes: 6 additions & 2 deletions admin-tools-filebrowser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<dependency>
<groupId>de.chandre.admin-tools</groupId>
<artifactId>admin-tools-core</artifactId>
<version>1.1.6.1</version>
<version>1.1.6.2</version>
</dependency>
<dependency>
<groupId>de.chandre.admin-tools</groupId>
<artifactId>admin-tools-filebrowser</artifactId>
<version>1.1.6.1</version>
<version>1.1.6.2</version>
</dependency>
```

Expand Down Expand Up @@ -118,6 +118,10 @@ admintool.filebrowser.createFolderAllowed=false
# boolean: to enable action to delete folders
admintool.filebrowser.delteFolderAllowed=false

#since 1.1.6.2
# boolean: if set to true and file/folder to delete has no write permission, it's not allowed to delete them
admintool.filebrowser.notDeletableIfNotWriteable=true

#since 1.1.6
# boolean: to enable action to delete files
admintool.filebrowser.delteFileAllowed=false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,74 @@
package de.chandre.admintool.filebrowser;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

/**
*
* @author Andre
*
*/
public abstract class AbstractFileBrowserService {

@Autowired
private AdminToolFilebrowserConfig config;

public String encodeURL(String path) throws UnsupportedEncodingException {
return URLEncoder.encode(path, "UTF-8");
}

/**
*
* @param path
* @param write
* @param configReadOnly
* @return
* @throws IOException
*/
public boolean isAllowed(File path, boolean write, boolean configReadOnly) throws IOException {
try {
if (configReadOnly && write) return false;
if (config.isRestrictedBrowsing()) {
if (null != config.getRestrictedPaths() && null != path) {
for (String restricedPath : config.getRestrictedPaths()) {
if(path.getCanonicalPath().startsWith(restricedPath)) {
return config.isRestrictedBrowsingIsWhitelist();
}
}
}
return !config.isRestrictedBrowsingIsWhitelist();
}
} catch (IOException e) {
throw new IOException("Could not check if path '" + path.getAbsolutePath() + "' is allowed ", e);
}
return true;
}

public String getExtension(File file) {
return getExtension(file.getName());
}

public String getExtension(String fileName) {
if (fileName.lastIndexOf('.') > -1) {
return (fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length())).toLowerCase();
}
return null;
}

}
package de.chandre.admintool.filebrowser;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.springframework.beans.factory.annotation.Autowired;

/**
*
* @author Andre
*
*/
public abstract class AbstractFileBrowserService {

@Autowired
private AdminToolFilebrowserConfig config;

public String encodeURL(String path) throws UnsupportedEncodingException {
return URLEncoder.encode(path, "UTF-8");
}

/**
* checks file against configured path restrictions and read-write configuration<br>
* doesn't check file permissions
*
* @param path the file to show/manipulate
* @param write if current action want to change the file
* @param configReadOnly if configuration value read-only is true
* @return true if accessible
* @throws IOException
*/
public boolean isAllowed(File path, boolean write, boolean configReadOnly) throws IOException {
try {
if (configReadOnly && write) return false;
if (config.isRestrictedBrowsing()) {
if (null != config.getRestrictedPaths() && null != path) {
for (String restricedPath : config.getRestrictedPaths()) {
if(path.getCanonicalPath().startsWith(restricedPath)) {
return config.isRestrictedBrowsingIsWhitelist();
}
}
}
return !config.isRestrictedBrowsingIsWhitelist();
}
} catch (IOException e) {
throw new IOException("Could not check if path '" + path.getAbsolutePath() + "' is allowed ", e);
}
return true;
}

/**
* returns the file extension by filename separated by last dot
* @param file
* @return null or extension
*/
public String getExtension(File file) {
return getExtension(file.getName());
}

/**
* returns the file extension by filename separated by last dot
* @param fileName
* @return null or extension
*/
public String getExtension(String fileName) {
if (fileName.lastIndexOf('.') > -1) {
return (fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length())).toLowerCase();
}
return null;
}

}
Loading

0 comments on commit 4157247

Please sign in to comment.