1

Search for viruses

antivirus

POST https://tesseractor.com/api/v1/antivirus?login=&password=

loginYour identification code.
passwordYour password.
multipart/form-data
fileContent of the PDF in binary.
$ curl -D - -X POST "https://tesseractor.com/api/v1/antivirus?login=abcdef&password=ABCDEF" -F "file=@file.pdf"

NOTE: The service accepts to search for viruses only in a PDF.

Download the code of the sendpost and file_mime_type functions from the iZend library. Copy the files in the space of your application.

NOTE: See the page Call the service API for a description of the sendpost and file_mime_type functions.

Add the file antivirus.php with the following content:

  1. require_once 'sendhttp.php';
  2. require_once 'filemimetype.php';

Loads the code of the sendpost and file_mime_type functions.

  1. function antivirus($login, $password, $file) {

Defines the function antivirus. $login is your identification code. $password is your password. $file is the pathname of the PDF file to validate.

  1.     $curl = 'https://tesseractor.com/api/v1/antivirus' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);

Sets $curl to the URL of the antivirus action with the identification code and the password of the user's account. $login and $password must be escaped.

  1.     $files=array('file' => array('name' => basename($file), 'tmp_name' => $file, 'type' => file_mime_type($file)));

Prepares the list of files attached to the POST: file - the PDF to scan with the name of the file, the pathname of the file and its MIME type.

  1.     $response=sendpost($curl, false, $files);

Sends the HTTP request with sendpost. The arguments login and password are already in $curl.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

If $response is false, the server is unreachable. If $response[0] doesn't contain the HTTP return code 200 Ok, an execution error has occurred. In case of error, antivirus returns false.

  1.     $r=json_decode($response[2], true);

Decodes the data returned in JSON.

  1.     if ($r['status'] == 'success') {
  2.         return true;
  3.     }

Returns true if no virus was detected in the PDF.

  1.     if ($r['status'] == 'fail') {
  2.         return $r['data']['names'];
  3.     }

Returns an array of the names of the viruses which were detected if the PDF is infected.

  1.     return false;
  2. }

Returns false in case of error.

EXAMPLE

Test the program with the files provided by the EICAR:

Assuming you have saved the files sendhttp.php, filemimetype.php and antivirus.php in the current directory, run PHP in interactive mode, load the antivirus function and call it with your identification code and password, the pathname of a PDF file:

$ php -a
php > require_once 'antivirus.php';
php > print_r(antivirus('abcdef', 'ABCDEF', 'eicar.pdf'));
Array
(
    [0] => Pdf.Dropper.Agent-6299277-0
)
php > quit

The document is infected by the virus Pdf.Dropper.Agent-6299277-0.

Call the service API, Validate a PDF/A, Make a PDF/A

Comments

To add a comment, click here.