Ir al contenido
Otras versiones

Cargando…

Crear su propio plugin de Antivirus Analyzer

Puede crear su propio Antivirus Analyzer.

Condiciones:

  • La nueva clase Antivirus Analyzer debe implementar la interfaz “Antivirus”.
  • La nueva clase Antivirus Analyzer debe declararse en el paquete “com.openkm.plugin.antivirus”.
  • La nueva clase Antivirus Analyzer debe estar anotada con@PluginImplementation”.
  • La nueva clase Antivirus Analyzer debe extender “BasePlugin”.

Interfaz de Antivirus Analyzer:

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 porque el sistema de plugins de la aplicación intentará cargarla desde ahí.

Method Type Description
detect(File file) String El método comprueba si el fichero contiene virus. Si el valor devuelto no es nulo, 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 com.openkm.core.Config;
import com.openkm.plugin.BasePlugin;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
/**
* Default implementation of an antivirus.
*
*/
@PluginImplementation
public class ClamavAntivirus extends BasePlugin 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 | IOException e) {
log.warn("Failed to check for viruses", e);
}
return "Failed to check for viruses";
}
}