Crear su propio plugin de analizador antivirus
Para crear su propio analizador antivirus debe crear una nueva clase que implemente la interfaz Antivirus:
package com.openkm.plugin.antivirus;
import java.io.File;
import net.xeoh.plugins.base.Plugin;
/** * Antivirus */public interface Antivirus extends Plugin {
/** * Check for viruses in file */ String detect(File file);}La nueva clase debe cargarse en el paquete com.openkm.plugin.antivirus, y el sistema de plugins de la aplicación intentará cargarla desde ahí. Consulte el ejemplo a continuación:
Descripción del método
Sección titulada «Descripción del método»| Método | Tipo | Descripción |
|---|---|---|
| detect(File file) | String | El método para comprobar si el archivo contiene virus. Si el valor devuelto no es null, la aplicación considerará que se ha encontrado un virus. |
Ejemplo de implementación del analizador antivirus clamav
Sección titulada «Ejemplo de implementación del analizador antivirus clamav»package com.openkm.plugin.antivirus;
import java.io.File;import java.io.IOException;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.apache.commons.io.IOUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import com.openkm.core.Config;
/** * Default implementation of an antivirus. * */@PluginImplementationpublic class ClamavAntivirus implements Antivirus { private static Logger log = LoggerFactory.getLogger(ClamavAntivirus.class);
/** * Check for viruses in file */ @Override public String detect(File file) { try { // Performs virus check log.debug("CMD: " + Config.SYSTEM_ANTIVIR + " " + file.getPath()); ProcessBuilder pb = new ProcessBuilder(Config.SYSTEM_ANTIVIR, "--no-summary", file.getPath()); Process process = pb.start(); process.waitFor(); String info = IOUtils.toString(process.getInputStream()); process.destroy();
// Check return code if (process.exitValue() == 1) { log.warn(info); info = info.substring(info.indexOf(':') + 1); return info; } else { return null; } } catch (InterruptedException e) { log.warn("Failed to check for viruses", e); } catch (IOException e) { log.warn("Failed to check for viruses", e); }
return "Failed to check for viruses"; }}