Skip to content
This repository has been archived by the owner on Jan 22, 2018. It is now read-only.

Commit

Permalink
Dansguardian - fix typos and include more check to install process.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelloc committed Apr 26, 2013
1 parent 2ab6e94 commit e1cc4b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
33 changes: 14 additions & 19 deletions config/dansguardian/dansguardian.inc
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ EOF;
#check blacklist download files
if ($install_process == true){
require_once("/usr/local/www/dansguardian.php");
fetch_blacklist(false);
fetch_blacklist(false,true);
update_output_window("Blacklist check done, continuing package config sync.");
}
else{
if ($dansguardian_blacklist['cron']=="force_download"){
Expand Down Expand Up @@ -961,7 +962,6 @@ EOF;
$daemongroup = 'nobody';
}
$filtergroups=($count > 1?($count -1):1);

$filterip="";
$filterports="";
foreach (explode(",", $dansguardian['interface']) as $i => $iface) {
Expand Down Expand Up @@ -1089,7 +1089,6 @@ EOF;
conf_mount_rw();

write_config();

#update cron
if ($cron_found > 0){
$config['cron']=$new_cron;
Expand All @@ -1113,36 +1112,31 @@ EOF;

#check virus_scanner options
$libexec_dir= DANSGUARDIAN_DIR."/libexec/dansguardian/";
if (preg_match("/clamd/",$dansguardian_config['content_scanners'])){
if ($install_process==true)
update_output_window("Skipping clamav check during package install.");
if (preg_match("/clamd/",$dansguardian_config['content_scanners']) && $install_process==false){

if (!(file_exists('/var/db/clamav/main.cvd')||file_exists('/var/db/clamav/main.cld'))){
file_notice("Dansguardian - No antivirus database found for clamav, running freshclam in background.","");
log_error('No antivirus database found for clamav, running freshclam in background. Content-scanner may not work until freshclam finishes.');
mwexec_bg(DANSGUARDIAN_DIR.'/bin/freshclam && /usr/local/etc/rc.d/clamav-clamd');
}

$match=array();
$match[0]='/NO/';
$replace=array();
$replace[0]='YES';

#clamdscan.conf dansguardian file
$cconf=DANSGUARDIAN_DIR . "/etc/dansguardian/contentscanners/clamdscan.conf";
$cconf_file=file_get_contents($cconf);
if (preg_match('/#clamdudsfile/',$cconf_file)){
$cconf_file=preg_replace('/#clamdudsfile/','clamdudsfile',$cconf_file);
file_put_contents($cconf, $cconf_file, LOCK_EX);
}

#clamd conf file
$cconf=DANSGUARDIAN_DIR."/etc/clamd.conf";
$cconf_file=file_get_contents($cconf);
if (preg_match("/User (\w+)/",$cconf_file,$matches)){
#clamd script file
$script='/usr/local/etc/rc.d/clamav-clamd';
$script_file=file($script);
$clamav_script='/usr/local/etc/rc.d/clamav-clamd';
$script_file=file($clamav_script);
$new_clamav_startup="";
$cpreg_m[0]="/NO/";
$cpreg_m[0]="@NO@";
$cpreg_m[1]="@/usr/local@";
$cpreg_r[0]="YES";
$cpreg_r[1]=DANSGUARDIAN_DIR;
Expand All @@ -1157,11 +1151,12 @@ EOF;
$new_clamav_startup.=$script_line;
}
elseif(!preg_match("/(mkdir|chown|sleep|mailscanner)/",$script_line)) {
$new_clamav_startup.=preg_replace($cpreg_m,$cpreg_p,$script_line);
$new_clamav_startup.=preg_replace($cpreg_m,$cpreg_r,$script_line);
}
}
file_put_contents($script, $new_clamav_startup, LOCK_EX);
file_put_contents($clamav_script, $new_clamav_startup, LOCK_EX);
chmod ($script,0755);

if (file_exists('/var/run/dansguardian.pid') && is_process_running('clamd')){
log_error('Stopping clamav-clamd');
mwexec("$script stop");
Expand All @@ -1173,8 +1168,7 @@ EOF;
mwexec_bg("$script start");
}
}
}

}
#check certificate hashed

$script='/usr/local/etc/rc.d/dansguardian.sh';
Expand Down Expand Up @@ -1209,6 +1203,7 @@ EOF;
#mount read only
conf_mount_ro();


#avoid sync during boot process
if (!isset($boot_process)){
/* Uses XMLRPC to synchronize the changes to a remote node */
Expand Down Expand Up @@ -1419,4 +1414,4 @@ function dansguardian_do_xmlrpc_sync($sync_to_ip,$username,$password,$sync_type,
}
}

?>
?>
34 changes: 23 additions & 11 deletions config/dansguardian/dansguardian.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@
require_once("/etc/inc/globals.inc");
require_once("/usr/local/pkg/dansguardian.inc");

function fetch_blacklist($log_notice=true) {
function fetch_blacklist($log_notice=true,$install_process=false) {
global $config,$g;
$url=$config['installedpackages']['dansguardianblacklist']['config'][0]['url'];
if (is_url($url)) {
conf_mount_rw();
if (is_array($config['installedpackages']['dansguardianblacklist'] && is_array($config['installedpackages']['dansguardianblacklist']['config']))){
$url=$config['installedpackages']['dansguardianblacklist']['config'][0]['url'];
$uw="Found a previouns install, checking Blacklist config...";
}
else{
$uw="Found a clean install, reading default access lists...";
}
conf_mount_rw();
if ($install_process == true)
update_output_window($uw);
if (isset($url) && is_url($url)) {
if ($log_notice==true){
print "file download start..";
unlink_if_exists("/usr/local/pkg/blacklist.tgz");
Expand Down Expand Up @@ -82,11 +90,13 @@ function fetch_blacklist($log_notice=true) {
}
}
else {
if (!empty($url))
if ($install_process==true)
read_lists(false,$uw);
elseif (!empty($url))
file_notice("Dansguardian - Blacklist url is invalid.","");
}
}
function read_lists($log_notice=true){
function read_lists($log_notice=true,$uw=""){
global $config,$g;
$group_type=array();
$dir=DANSGUARDIAN_DIR . "/etc/dansguardian/lists";
Expand Down Expand Up @@ -152,12 +162,14 @@ function read_lists($log_notice=true){
$edit_file=preg_replace('/size.19/','size>5',$edit_file);
file_put_contents("/usr/local/pkg/dansguardian_".$edit_xml."_acl.xml",$edit_file,LOCK_EX);
}
if($log_notice==true)
file_notice("Dansguardian - Blacklist applied, check site and URL access lists for categories","");
#foreach($config['installedpackages'] as $key => $values)
# if (preg_match("/dansguardian(phrase|black|white)lists/",$key))
# print "$key\n";
write_config();
if($log_notice==true && $uw==""){
file_notice("Dansguardian - Blacklist applied, check site and URL access lists for categories","");
}
else{
$uw.="done\n";
update_output_window($uw);
}
}

if ($argv[1]=="update_lists")
Expand Down
2 changes: 1 addition & 1 deletion config/dansguardian/dansguardian_sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<type>listtopic</type>
</field>
<field>
<fielddescr>Automatically sync squid configuration changes</fielddescr>
<fielddescr>Automatically sync dansguardian configuration changes</fielddescr>
<fieldname>synconchanges</fieldname>
<description>Select a sync method for dansguardian.</description>
<type>select</type>
Expand Down

0 comments on commit e1cc4b4

Please sign in to comment.