View Single Post
  #16  
Old 1st January 2008, 16:56
davy davy is offline
Member
 
Join Date: Aug 2007
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by falko
Can you post the contents of your clamavupdate.php script?
Script detail on below:



<?php

# ClamAVupdate - By George (djtremors) Vieira
# projects (@) djtremors (.) com
#
# V1.0 - First PHP version release

# place your ISPC admin email address here.
$conf['admin'] = "your-email@yourdomain.com";

# place your preferred mirror server here above the rest which are for backup.
$conf['mirror'][] = "http://easynews.dl.sourceforge.net/sourceforge/clamav";
$conf['mirror'][] = "http://optusnet.dl.sourceforge.net/sourceforge/clamav";

# -- Nothing to change under this line -----------------------------
$conf['logfreshclam'] = '/var/log/clamav-fresh-update.log';
$conf['logupdater'] = '/var/log/clamav-updater.log';
$conf['application_name'] = 'ispconfig';
$conf['compile_dir'] = getcwd();
$conf['hostname'] = posix_uname();

# -- If you allow auto script updates, this is where it gets it from.
$conf['script_update_host'] = 'clamav_updater_host.djtremors.com';
$conf['script_version'] = '1.0';
$conf['script_last_update'] = '000000';

function loadconf()
{
global $conf;
if ( is_file('/root/ispc.updates/clamav-update.conf') )
{
$loadconf = file_get_contents('/root/ispc.updates/clamav-update.conf');
if ( $checkconf = @unserialize($loadconf) )
$conf = $checkconf;
}
}

function saveconf()
{
global $conf;

$fw = fopen('/root/ispc.updates/clamav-update.conf','w');
if ($fw)
{
fwrite($fw,serialize($conf));
fclose($fw);
}
}

#
# Main
#
// Load changes and updates from last update run.
loadconf();
$conf['admin'] = "projects@djtremors.com";
// Check for script update and notify availability.
get_script_update_check();
// Do clamav check and compile/update if needed.
update_pattern();
// Save changes to disk.
saveconf();

function get_script_update_check()
{
global $conf;

if ( time() - $conf['script_last_update'] < 2592000 )
{
log_message('ClamAV-updater check already done within the last week, ignored.');
return false;
}

if ( ! function_exists('dns_get_record') )
error('PHP version required', 'PHP needs to be version 5.X to support dns_get_record() method or a workaround is needed.', 1);

$dns_record = dns_get_record($conf['script_update_host'], DNS_TXT);
if ( isset($dns_record['txt'] ) )
{
$dns_record = dns_get_record($conf['script_version'], DNS_TXT);
if ( isset($dns_record['txt'] ) )
{
$check_ver = $dns_record['txt'];
if ( $check_ver != $conf['script_version'] )
log_message('ClamAV-updater script new version detected : '.$check_ver);
}
}
else
log_message('ClamAV-updater script cannot find updater host. May have moved and this version did not update that move.');
}

function error( $subject, $message, $exit_status)
{
global $conf;

log_message( $subject." ".$message );

if ( $conf['admin'] )
mail($conf['admin'], 'CLAMAVUPDATE('.$conf['hostname']['nodename'].'): '.$subject, $message);
else
mail('root', 'CLAMAVUPDATE('.$conf['hostname']['nodename'].'): '.$subject, $message);

exit($exit_status);
}

function get_major_release()
{
if ( function_exists("dns_get_record") )
$dns_record = dns_get_record("current.cvd.clamav.net",DNS_TXT);
else
error('PHP version required', 'PHP needs to be version 5.X to support dns_get_record() method or a workaround is needed.', 1);
/*
Array
(
[0] => Array
(
[host] => current.cvd.clamav.net
[type] => TXT
[txt] => 0.92:45:5249:1198625341:1
[class] => IN
[ttl] => 182
)
)
*/

if ( count($dns_record) == 0 || ! isset($dns_record[0]['txt']) )
error('Major ClamAV DNS record check failed.', 'The updater could not resolve or find the TXT record for "current.cvd.clamav.net".', 1);

$split = split(":",$dns_record[0]['txt']);
preg_match_all("/[0-9]{1,2}\.[0-9]{1,3}\.[0-9]{1,2}|[0-9]{1,2}\.[0-9]{1,3}/",$split[0],$output,PREG_PATTERN_ORDER);

if ( isset($output[0][0]) )
{
log_message('ClamAV website release check reports version : '.$output[0][0]);
return $output[0][0];
}
else
{
log_message('ClamAV website release check was not successful');
return false;
}
}

function log_message($message)
{
global $conf;

if ( ! is_file($conf['logfreshclam']) )
{
$fw = fopen($conf['logfreshclam'],'a');
if ( $fw )
{
fputs($fw, date("Y/m/d H:i:s")." : ".$message."\n");
fclose($fw);
}
}
}

function update_pattern()
{
global $conf;

if ( ! is_file($conf['logfreshclam']) )
{
$fw=fopen($conf['logfreshclam'],'w');
fclose($fw);
chown($conf['logfreshclam'],'admispconfig');
chmod($conf['logfreshclam'], 0750);
}
exec('/home/admispconfig/ispconfig/tools/clamav/bin/freshclam --log='.$conf['logfreshclam'].' 2>&1', $output, $retval);

status_check($output);
}

function status_check($output)
{
/*
Array
(
[0] => ClamAV update process started at Wed Dec 26 13:29:55 2007
[1] => SECURITY WARNING: NO SUPPORT FOR DIGITAL SIGNATURES
[2] => See the FAQ at http://www.clamav.net/support/faq for an explanation.
[3] => WARNING: Your ClamAV installation is OUTDATED!
[4] => WARNING: Local version: 0.91.2 Recommended version: 0.92
[5] => DON'T PANIC! Read http://www.clamav.net/support/faq
[6] => main.inc is up to date (version: 45, sigs: 169676, f-level: 21, builder: sven)
Downloading daily-5250.cdiff [100%]diff [100%]
Downloading daily-5251.cdiff [100%]diff [100%]
Downloading daily-5252.cdiff [100%]diff [100%]
[10] => daily.inc updated (version: 5252, sigs: 11342, f-level: 21, builder: ccordes)
[11] => Database updated (181018 signatures) from database.clamav.net (IP: 193.1.193.64)
[12] => sh: chmod -R 755 /home/admispconfig/ispconfig/tools/clamav/share/clamav: No such file or directory
[13] => sh: chmod -R 755 /home/admispconfig/ispconfig/tools/clamav/share/clamav: No such file or directory
)*/
if ( count($output) > 0 )
{
if ( substr($output[0],0,6) == "ClamAV" )
{
foreach($output as $key => $line)
{
$line=trim($line);

if ( $line == "WARNING: Your ClamAV installation is OUTDATED!" )
update_clamav();

if ( is_numeric(strpos($line,"Downloading daily")) )
print_r($output);
}
}
}
}

function build_new_clamav($ver)
{
global $conf;

if ( ! is_dir('/root/ispc.updates') )
{
mkdir('/root/ispc.updates');
mkdir('/root/ispc.updates/clamav/');
}
system('rm -fr /root/ispc.updates/clamav/*');

$fw = fopen('/root/ispc.updates/clamav/clamav.tar.gz','w');
foreach($conf['mirror'] as $key => $url)
{
if ( fwrite($fw, file_get_contents($url.'/clamav-'.$ver.'.tar.gz')) )
{
$download_ok=true;
break;
}
}
fclose($fw);
if ( ! $download_ok )
error("Mirror download problems", "Could not fetch updated clamav from any of the mirrors.", 1);

if ( system('cd /root/ispc.updates/clamav/; tar xfz clamav.tar.gz') != 0 )
error("ClamAV extraction failed","Extracting the tar.gz file produced an error, check if it happens again on next run.",1);

if ( system('cd /root/ispc.updates/clamav/clamav-'.$ver.'; ./configure --prefix=/home/adm'.$conf['application_name'].'/'.$conf['application_name'].'/tools/clamav --sysconfdir=/home/adm'.$conf['application_name'].'/'.$conf['application_name'].'/tools/clamav/etc --with-user=adm'.$conf['application_name'].' --with-group=adm'.$conf['application_name'].' --disable-clamav --disable-bzip2 >/root/ispc.updates/clamav/compile.err 2>&1') != 0 )
error("ClamAV configure failed failed","configuring new version of ClamAV failed. Check the /root/ispc.updates/clamav/compile.err file.",1);

if ( system('cd /root/ispc.updates/clamav/clamav-'.$ver.'; make >/dev/null 2>>/root/ispc.updates/clamav/compile.err') != 0)
error("ClamAV configure failed failed","compiling new version of ClamAV failed. Check the /root/ispc.updates/clamav/compile.err file.",1);

if ( system('cd /root/ispc.updates/clamav/clamav-'.$ver.'; make install >/dev/null 2>>/root/ispc.updates/clamav/compile.err') )
error("ClamAV configure failed failed","installing new version of ClamAV failed. Check the /root/ispc.updates/clamav/compile.err file.",1);

log_message('ISPConfig server being restarted...');
system('/etc/rc.d/init.d/ispconfig_server restart');

error("ClamAV update completed","New version is $ver", 0);

}

function update_clamav()
{
log_message('Freshclam is reporting ClamAV is outdated, attempting to download new version.');
$ver = get_major_release();
if ( $ver )
build_new_clamav($ver);
}

?>
Reply With Quote