Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Aug 21, 2020
2 parents bb533db + 7de2152 commit 6851a57
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 20 deletions.
7 changes: 5 additions & 2 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
2020-08-21 1.0.0
- Enhanced history

2020 1.0.0
- initial release

2020-08-14 0.9.0
- Initial release

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Features:
* Clam AV
* Health checks

Sample test virus files can be downloaded at [eicar](http://eicar.com/).

<a name="requirements"></a>

# Requirements
Expand All @@ -26,7 +28,7 @@ AVS requires Java 8 and AEM 6.4 or above.

# Installation

You can download the package from [Maven Central](http://repo1.maven.org/maven2/de/valtech/avs/avs.ui.apps/) or our [releases section](https://github.com/valtech/aem-virus-scan/releases). The avs.ui.apps package will install the AVS software.
You can download the package from [Maven Central](https://repo1.maven.org/maven2/de/valtech/avs/avs.ui.apps/) or our [releases section](https://github.com/valtech/aem-virus-scan/releases). The avs.ui.apps package will install the AVS software.

```xml
<dependency>
Expand Down Expand Up @@ -171,7 +173,7 @@ You can access them on the [status page](http://localhost:4502/libs/granite/oper

# API Documentation

TODO
https://valtech.github.io/aem-virus-scan/

<a name="license"></a>

Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.avs</groupId>
<artifactId>avs</artifactId>
<version>0.9.0</version>
<version>1.0.0</version>
</parent>

<artifactId>avs.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import java.io.InputStream;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.osgi.annotation.versioning.ConsumerType;

import de.valtech.avs.api.service.AvsException;
Expand All @@ -36,10 +39,11 @@ public interface AvsScannerEnine {
/**
* Scans the given content for viruses.
*
* @param content content
* @param content content
* @param fileName file name
* @return scan result
* @throws AvsException error during scan
*/
ScanResult scan(InputStream content) throws AvsException;
ScanResult scan(@Nonnull InputStream content, @Nullable String fileName) throws AvsException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roland Gruber
*/
@Version("1.0.0")
@Version("2.0.0")
package de.valtech.avs.api.service.scanner;

import org.osgi.annotation.versioning.Version;
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.avs</groupId>
<artifactId>avs</artifactId>
<version>0.9.0</version>
<version>1.0.0</version>
</parent>

<artifactId>avs.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
try {
Session session = slingRequest.getResourceResolver().adaptTo(Session.class);
String userId = (session != null) ? session.getUserID() : StringUtils.EMPTY;
ScanResult result = avsService.scan(combinedStream, userId);
ScanResult result = avsService.scan(combinedStream, userId, String.join(", ", fileNames));
if (!result.isClean()) {
for (File file : parameterFiles) {
if (!file.delete()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void sendEmail(List<String> emails, String fileName, ScanResult result) {
VelocityContext context = new VelocityContext();
StringWriter writer = new StringWriter();
if (fileName != null) {
context.put("FILE_NAME", fileName);
context.put("FILE_NAME", escape(fileName));
}
context.put("SCAN_OUTPUT", result.getOutput());
context.put("SCAN_OUTPUT", escape(result.getOutput()));
ve.evaluate(context, writer, "AvsNotificationMailer", getBodyText());
String body = writer.toString();
String subject = getSubject();
Expand All @@ -98,6 +98,17 @@ public void sendEmail(List<String> emails, String fileName, ScanResult result) {
}
}

/**
* Escapes HTML special characters.
*
* @param input input data
* @return escaped data
*/
private String escape(String input) {
Html2TextConverter converter = new Html2TextConverter(input);
return converter.getText();
}

/**
* Returns the raw body text incl. wildcards.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2020 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.avs.core.mail;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Converts HTML to plain text.
*
* @author Roland Gruber
*/
public class Html2TextConverter extends HTMLEditorKit.ParserCallback {

private static final Logger LOG = LoggerFactory.getLogger(Html2TextConverter.class);

private StringBuilder text = new StringBuilder();

/**
* Constructor
*
* @param input input text
*/
public Html2TextConverter(String input) {
if (input == null) {
return;
}
ParserDelegator delegator = new ParserDelegator();
Reader reader = new StringReader(input);
try {
delegator.parse(reader, this, true);
} catch (IOException e) {
LOG.error("Unable to convert data", e);
}
}

@Override
public void handleText(char[] data, int pos) {
text.append(data);
}

/**
* Returns the converted value.
*
* @return text
*/
public String getText() {
return text.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ScanResult scan(InputStream content, String userId, String path) throws A
ScanResult result = null;
try (ResourceResolver resolver = serviceResourceResolverService.getServiceResourceResolver()) {
for (AvsScannerEnine engine : engines) {
result = engine.scan(content);
result = engine.scan(content, path);
result.setPath(path);
result.setUserId(userId);
if (!result.isClean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void activate(ClamScannerConfig config) {
}

@Override
public ScanResult scan(InputStream content) throws AvsException {
public ScanResult scan(InputStream content, String fileName) throws AvsException {
try {
File tempFile = createTemporaryFile(content);
Runtime runtime = Runtime.getRuntime();
Expand All @@ -77,7 +77,11 @@ public ScanResult scan(InputStream content) throws AvsException {
String error = IOUtils.toString(err, Charset.forName(StandardCharsets.UTF_8.name()));
in.close();
err.close();
output = output.replace(tempFile.getPath(), "SCANNED_FILE");
if (StringUtils.isBlank(fileName)) {
output = output.replace(tempFile.getPath(), "SCANNED_FILE");
} else {
output = output.replace(tempFile.getPath(), fileName);
}
Files.delete(Paths.get(tempFile.getPath()));
if ((returnCode == 0) && StringUtils.isBlank(error)) {
return new ScanResult(output, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2020 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.avs.core.mail;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* Tests Html2TextConverter
*
* @author Roland Gruber
*/
public class Html2TextConverterTest {

@Test
public void getText_html() {
assertEquals("some test", convert("<b>some<x> test<z>"));
}

@Test
public void getText_noHtml() {
assertEquals("some test", convert("some test"));
}

@Test
public void getText_null() {
assertEquals("", convert(null));
}

private Object convert(String input) {
Html2TextConverter converter = new Html2TextConverter(input);
return converter.getText();
}

}
2 changes: 1 addition & 1 deletion docs/developers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AEM Server Setup

By default AEM is expected to listen on localhost on port 5702. This setting can be overridden by adding parameters:
By default AEM is expected to listen on localhost on port 4502. This setting can be overridden by adding parameters:
* -Daem.port=4502
* -Daem.host=localhost
* -Daem.publish.port=4503
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.avs</groupId>
<artifactId>avs</artifactId>
<version>0.9.0</version>
<version>1.0.0</version>
</parent>

<artifactId>avs.examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.valtech.avs</groupId>
<artifactId>avs</artifactId>
<packaging>pom</packaging>
<version>0.9.0</version>
<version>1.0.0</version>
<name>AVS</name>
<description>AEM Virus Scan</description>
<url>https://github.com/valtech/aem-virus-scan</url>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.structure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.avs</groupId>
<artifactId>avs</artifactId>
<version>0.9.0</version>
<version>1.0.0</version>
</parent>

<artifactId>ui.apps.structure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.avs</groupId>
<artifactId>avs</artifactId>
<version>0.9.0</version>
<version>1.0.0</version>
</parent>

<artifactId>avs.ui.apps</artifactId>
Expand Down

0 comments on commit 6851a57

Please sign in to comment.