Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 1869 → Rev 1870

/alcasar.sh
1708,13 → 1708,9
EOF
 
 
# Enabling update for BL/WL categories with rsync
cat << EOF > /etc/cron.d/alcasar-update-cat
# update malware category every twelve hours
* 0-23/12 * * * /usr/local/bin/alcasar-bl.sh --update-cat malware rsync://ftp.ut-capitole.fr/blacklist/dest/malware > /dev/null 2>&1
EOF
 
touch /etc/cron.d/alcasar-update-cat
chown root:apache /etc/cron.d/alcasar-update-cat
chmod 660 /etc/cron.d/alcasar-update-cat
 
# removing the users crons
rm -f /var/spool/cron/*
/scripts/alcasar-bl.sh
104,8 → 104,14
ln -s $DIR_DNS_WL/ossi.conf $DIR_DNS_WL_ENABLED/ossi
fi
 
# update categories with rsync
if [ ! -e $DIR_CONF/update_cat.conf ]
then
touch $DIR_CONF/update_cat.conf
chown root:apache $DIR_CONF/update_cat.conf
chmod 660 $DIR_CONF/update_cat.conf
fi
$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
# process the file $BL_CATEGORIES with the choice of categories
137,7 → 143,7
}
 
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat } & categorie & url_rsync"
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
nb_args=$#
args=$1
if [ $nb_args -eq 0 ]
252,13 → 258,19
#mise a jour d'une categorie avec rsync
-update_cat | --update_cat)
if [ $# -ge 3 ]
then
echo -n "Updating $2 category ..."
echo -n "Updating categories in /usr/local/etc/update_cat.conf ..."
 
PATH_FILE=$(find $DIR_DG_BL/ -type d -name $2) # retrieve directory name of the category
rsync -rv $3 $(dirname $PATH_FILE ) #rsync inside of the blacklist directory
for LIGNE_RSYNC in $(cat /usr/local/etc/update_cat.conf)
do
 
$CATEGORIE=$(echo $LIGNE_RSYNC | cut -d' ' -f0)
$URL=$(echo $LIGNE_RSYNC | cut -d' ' -f1)
PATH_FILE=$(find $DIR_DG_BL/ -type d -name $CATEGORIE) # retrieve directory name of the category
echo "rsync -rv $URL $(dirname $PATH_FILE )" #rsync inside of the blacklist directory
echo $PATH_FILE
# Creation of DNSMASQ and Iptables BL and WL
DOMAINE=$(basename $PATH_FILE)
277,23 → 289,22
$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp
mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
/usr/bin/systemctl restart dnsmasq-blacklist
else
# adapt to the dnsmasq syntax for the whitelist
$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
/usr/bin/systemctl restart dnsmasq-whitelist
fi
rm -f $FILE_tmp $FILE_ip_tmp
 
rm -f $FILE_tmp $FILE_ip_tmp
done
/usr/bin/systemctl restart dnsmasq-whitelist
/usr/bin/systemctl restart dnsmasq-blacklist
/usr/bin/systemctl restart dansguardian
/usr/local/bin/alcasar-iptables.sh
echo "MAJ RSYNC réussie"
else
echo "$usage"
fi
;;
# reload when categories are changed
-reload | --reload)
/web/acc/admin/bl_filter.php
132,6 → 132,11
$l_nbDomainNames="Noms de domaine :";
$l_nbUrl="Url :";
$l_nbIp="Ip :";
$l_update_cat="Mise a jour des catégories automatiquement?";
$l_no_update_cat = "désactiver";
$l_1_update_cat = "toutes les 12 heures";
$l_2_update_cat = "toutes les semaines";
$l_3_update_cat = "tous les mois";
}
else {
$l_bl="BlackList";
178,6 → 183,11
$l_nbDomainNames="Domain names :";
$l_nbUrl="Url :";
$l_nbIp="Ip :";
$l_update_cat="Mise a jour des catégories automatiquement?";
$l_no_update_cat = "Disable";
$l_1_update_cat = "every 12 hours";
$l_2_update_cat = "every weeks";
$l_3_update_cat = "every month";
}
$dir_etc="/usr/local/etc/";
$dir_dg="/etc/dansguardian/lists/";
192,6 → 202,34
$upload_dir_ip = "/usr/local/share/iptables-bl-enabled/";
$upload_dir_domain_names = "/usr/local/share/dnsmasq-bl-enabled/";
$cron_apache = "/etc/cron.d/alcasar-update-cat";
$update_file_cat="/usr/local/etc/update_cat.conf";
if(isset($_POST['update_cat']))
{
 
$fichier=fopen($cron_apache,"w+");
$update_mode = $_POST['update_cat'];
switch($update_mode){
case 0:
fputs($fichier, "#0 update with rsync categories is disabled\n");
break;
case 1:
fputs($fichier, "#1 update with rsync every 12 hours\n");
fputs($fichier, "0 0-23/12 * * * /usr/local/bin/alcasar-bl.sh --update_cat \n");
break;
case 2:
fputs($fichier, "#2 update with rsync every week (Sunday) at 00:00\n");
fputs($fichier, "0 0 * * 0 /usr/local/bin/alcasar-bl.sh --update_cat \n");
break;
case 3:
fputs($fichier, "#3 update with rsync every month (1st) at 00:00\n");
fputs($fichier, "0 0 1 * * /usr/local/bin/alcasar-bl.sh --update_cat \n");
break;
}
 
 
fclose($fichier);
}
 
# default values
if (is_file ($conf_file))
{
227,7 → 265,6
case 'MAJ_cat_bl' :
if (file_exists($bl_categories_enabled))
{
$cron_malware = 0;
$pointeur=fopen($bl_categories_enabled, "w+");
foreach ($_POST as $key => $value)
{
235,20 → 272,13
{
$line=str_replace('chk-','',$key)."\n";
fwrite($pointeur,$line);
if(trim($line) == 'malware')
if(trim($line) == 'malware' && $update_mode > 0)
{
$cron_malware = 1;
$fichier=fopen($cron_apache,"w+");
fputs($fichier, "# update malware categories every 12 hours\n");
fputs($fichier, "* 0-23/12 * * * /usr/local/bin/alcasar-bl.sh --update-cat malware rsync://ftp.ut-capitole.fr/blacklist/dest/malware\n");
$fichier=fopen($update_file_cat,"w+");
fputs($fichier, "malware rsync://ftp.ut-capitole.fr/blacklist/dest/malware\n");
}
}
}
if(!$cron_malware)
{
$fichier=fopen($cron_apache,"w+");
fputs($fichier, "# malware updates disabled\n");
}
fclose($pointeur);
}
409,9 → 439,40
}
else {
echo "$l_error_open_file $bl_categories";
}
}
 
#update categories via rsync
$update_select = array();
$update_select[0] = "";
$update_select[1] = "";
$update_select[2] = "";
$update_select[3] = "";
 
$pointeur=fopen($cron_apache,'r');
while (!feof ($pointeur))
{
$line=fgets($pointeur,1024);
if(explode(' ',$line)[0] === "#0")
$update_select[0]="checked";
if(explode(' ',$line)[0] === "#1")
$update_select[1]="checked";
if(explode(' ',$line)[0] === "#2")
$update_select[2]="checked";
if(explode(' ',$line)[0] === "#3")
$update_select[3]="checked";
}
fclose($pointeur);
 
echo "</td></tr>";
echo "<tr><td valign='middle' align='left' colspan=10>";
echo "<center>$l_update_cat
<input type='radio' name='update_cat' value=0 $update_select[0]> $l_no_update_cat
<input type='radio' name='update_cat' value=1 $update_select[1]> $l_1_update_cat
<input type='radio' name='update_cat' value=2 $update_select[2]> $l_2_update_cat
<input type='radio' name='update_cat' value=3 $update_select[3]> $l_3_update_cat
<input type='submit' value='$l_record'></center>";
echo "</td></tr>";
echo "<tr><td valign='middle' align='left' colspan=10>";
echo "<center><b>$l_maj_rehabilitated</b></center></td></tr>";
echo "<tr><td width=50% colspan=5 align=center>";
echo "<H3>$l_rehabilitated_dns</H3>$l_rehabilitated_dns_explain<BR>$l_one_dns<BR>";
538,3 → 599,4
</BODY>
</HTML>