Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    Okay I've been looking into sockets all morning... I learned how to check how many messages I have in my email account by using a pop server and a socket but I do not know how to open a socket for clamscan.

    I also found a class for clamd that works with cakePHP...
    http://www.jejik.com/articles/2009/0..._from_cakephp/
    http://svn.jejik.com/viewvc.cgi/cake...d.php?view=log
    but that didn't help much on figuring out how to get the correct host info and anything past fsockopen...

    I keep getting a unable to connect message... Stupid inexperience with sockets... ggrrrrrr... hehehehe

    Does any one know an example of directly connecting to clamav using a socket without a class? Thanks.

  2. #17
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    Okay so here is my conclusion after dealing with this for two days. I can't figure out how to go through sockets to connect to ClamAV but I moved the scan to next step and placed all of the files into a temp directory then scanned all of the files at once from there.

    PHP Code:
        // Set the allowed types for reading and upload.
        
    $types = array ('jpg''jpeg''txt');
        
        
    // Start a variable.
        
    $dir_files = array();
        
        
    // If it is a directory add all the files.
        
    if (is_dir ($dir)) {
            
    // Open the directory.
            
    if ($handle opendir($dir)) {
                
    // Read the file names of all the files available.
                
    while (false !== ($file readdir($handle))) {
                    
    // Make sure the file is not this directory or its parent and not the .DS_Store file.
                    
    if ($file != "." && $file != ".." && $file != '.DS_Store') {
                        
    // Get the file parts.
                        
    $file_parts  pathinfo($file);
                        
    // Make sure the extension is allowed.
                        
    if (in_array(strtolower ($file_parts['extension']),$types)) {
                            
    // Add the file to the array.
                            
    $dir_files[] = array ('original_name'=>$file'type'=>$file_parts['extension']);
                        }
                    }
                }
                
    // Close the handle.
                
    closedir ($handle);
            }
        }

        
    // If any files exist in the upload directory check them for viruses.
        
    if (count ($dir_files) > 0) {
            
    // Get the dir and prepare it for the command line.
            
    $real_path realpath ($dir);
            
    $safe_path escapeshellarg($real_path);
            
    // Set the variables for the cmd.
            
    $return = -1;
            
    $out ='';
            
    $cmd '/usr/local/clamXav/bin/clamscan ' $safe_path;
            
    // Execute the cmd.
            
    exec ($cmd$out$return);
            
    // If a virus is found loop through each of the files and delete the virus, write the user a message, and add them to a db table.
            
    if ($return != 0) {
                
    // Loop through the files.
                
    foreach ($dir_files as $k=>$v) {
                    
    // Get the dir and prepare it for the command line.
                    
    $real_path realpath ($dir $v['original_name']);
                    
    $safe_path escapeshellarg($real_path);
                    
    // Reset the values.
                    
    $return = -1;
                    
    $out ='';
                    
    $cmd '/usr/local/clamXav/bin/clamscan ' $safe_path;
                    
    // Execute the command.
                    
    exec ($cmd$out$return);
                    
    // If the file is clean do nothing.
                    
    if ($return == 0){}
                    
    // If the file contains a virus remove it and add a note to the db.
                    
    else if ($return == 1) {
                        
    // Delete the file.
                        
    unlink ($dir $v['original_name']);
                        
    // Unset the file from the records.
                        
    unset ($dir_files[$k]);
                        
    // Notify the user.
                        
    $message .= "The file {$v['original_name']} contained a known virus.  It has been deleted from the server.<br />";
                        
    $message_class 'error';
                        
    // Add the user who uploaded the file to the db and a time and date.
                        // Query the db to record who uploaded the file, not necessary but fun info to have.
                    
    }
                    else {
                        
    // Delete the file.
                        
    unlink ($dir $v['original_name']);
                        
    // Unset the file from the records.
                        
    unset ($dir_files[$k]);
                        
    // Notify the user.
                        
    $message .= "The file {$v['original_name']} caused an unknown error and was removed from the server.<br />";
                        
    $message_class 'minor_error';
                    }
                }
            }
        } 
    Thanks for everyone who helped me with this.
    Last edited by Coyote6; 02-04-2010 at 05:14 AM.

  3. #18
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Are you trying to connect to Clam via a TCP socket, perchance? They are not enabled by default in the clamd.conf file. Defaults to unix sockets, if I recall.


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •