Skip to content

Instantly share code, notes, and snippets.

@akbertram
Last active December 5, 2019 13:38
Show Gist options
  • Save akbertram/aca0345a9ce629b6881ae4e461a923aa to your computer and use it in GitHub Desktop.
Save akbertram/aca0345a9ce629b6881ae4e461a923aa to your computer and use it in GitHub Desktop.
Malware scanner
# src/main/appengine/app.yaml
runtime: custom
env: flex
service: malware-scanner
automatic_scaling:
min_num_instances: 1
max_num_instances: 2
resources:
cpu: 1
memory_gb: 2
disk_size_gb: 10
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.google.cloud.tools.appengine'
dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
compile libraries.appengine.all
compile libraries.appengine.gcs
compile 'fi.solita.clamav:clamav-client:1.0.1'
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'jetty9' // What App Engine Flexible uses
}
war {
archiveName = 'scanner.war'
}
appengine {
deploy {
project = environment.projectId
stopPreviousVersion = true
promote = true
}
}
FROM gcr.io/google-appengine/jetty
ADD scanner.war $APP_DESTINATION
# generate quickstart-web.xml to speed up startup time
RUN /scripts/jetty/quickstart.sh
RUN apt-get update && \
apt-get install clamav-daemon -y && \
freshclam && \
echo "TCPSocket 3310" >> /etc/clamav/clamd.conf && \
echo "TCPAddr 127.0.0.1" >> /etc/clamav/clamd.conf
import fi.solita.clamav.ClamAVClient;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.logging.Logger;
@WebServlet("/ping")
public class ScannerServlet extends HttpServlet {
private static final Logger LOGGER = Logger.getLogger(ScannerServlet.class.getName());
@Override
public void init() throws ServletException {
super.init();
LOGGER.info("Initializing...");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ClamAVClient cl = new ClamAVClient("127.0.0.1", 3310);
if(cl.ping()) {
resp.setStatus(200);
} else {
resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment