Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpallotta committed Sep 8, 2018
2 parents 78b01f5 + 10cc700 commit c679297
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# php-clamav #
Package to check files against ClamAV. You can pass a file via UNIX and TCP sockets. It ClamAV is installed locally you can also use clamscan/clamdscan.
PHP library to check files against ClamAV. You can pass a file via UNIX and TCP sockets. If ClamAV is installed locally you can also use clamscan/clamdscan.

## Install ##
Assumes you already have ClamAV installed locally or on a secured remote server.
You should have ClamAV installed locally or on a secured remote server.

### Composer ###

Expand Down
47 changes: 33 additions & 14 deletions src/Adapter/ClamavScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function scan($fileHandle, $fileSize, $options) {

$socket = new ClamavSocket();
$openSocket = $socket->openSocket($options);
/*
* Check if clamav is available if not return message
*/
$checkSocket = $socket->checkSocket($options);
if ($checkSocket['message'] != "ClamAV is Alive!") {
return $checkSocket;
}

$sendResponse['instream'] = $socket->send($openSocket, $zInstream);

Expand All @@ -45,20 +52,32 @@ public function scan($fileHandle, $fileSize, $options) {
fseek($fileHandle, $chunkDataSent);
$chunk = fread($fileHandle, $options['clamavChunkSize']);
$chunkLength = pack("N", strlen($chunk));
$chunkLengthResponse = $socket->send($openSocket, $chunkLength);
$chunkDataResponse = $socket->send($openSocket, $chunk);
$chunkDataSent += $chunkDataResponse['written'];
/*
* Check if clamav is available if not return message
*/
if ($checkSocket['message'] != "ClamAV is Alive!") {
return $checkSocket;
$chunkLengthResponse = $socket->send($openSocket, $chunkLength);
$chunkDataResponse = $socket->send($openSocket, $chunk);
$chunkDataSent += $chunkDataResponse['written'];
}
/*
* Currently do not need to send zero string to Clamav with this code.
* Leaving it here for the time being for update to how a file is sent to clamvav host socket.
*/
$endInstream = pack("N", strlen("")) . "";
/*
* Check if clamav is available if not return message
*/
$checkSocket = $socket->checkSocket($options);
if ($checkSocket['message'] != "ClamAV is Alive!") {
return $checkSocket;
}
$response = $socket->send($openSocket, $endInstream, 1);
$socket->closeSocket($openSocket);
}
/*
* Currently do not need to send zero string to Clamav with this code.
* Leaving it here for the time being for update to how a file is sent to clamvav host socket.
*/
$endInstream = pack("N", strlen("")) . "";
$response = $socket->send($openSocket, $endInstream, 1);
$socket->closeSocket($openSocket);
}
return $response;
return $response;

}
}

}
}

0 comments on commit c679297

Please sign in to comment.