Search for viruses
antivirus
POST https://tesseractor.com/api/v1/antivirus?login=&password=
login | Your identification code. |
---|---|
password | Your password. |
multipart/form-data | |
file | Content 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:
- require_once 'sendhttp.php';
- require_once 'filemimetype.php';
Loads the code of the sendpost
and file_mime_type
functions.
- 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.
- $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.
- $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.
- $response=sendpost($curl, false, $files);
Sends the HTTP request with sendpost
.
The arguments login
and password
are already in $curl
.
- if (!$response or $response[0] != 200) {
- return false;
- }
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.
- $r=json_decode($response[2], true);
Decodes the data returned in JSON.
- if ($r['status'] == 'success') {
- return true;
- }
Returns true
if no virus was detected in the PDF.
- if ($r['status'] == 'fail') {
- return $r['data']['names'];
- }
Returns an array of the names of the viruses which were detected if the PDF is infected.
- return false;
- }
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.
Comments
To add a comment, click here.