- if [ "$ret" -eq "0" ] ; then
- loop="1"
- if ! cmp -s "$work_dir_yararulesproject/$db_file" "$clam_dbs/$db_file" ; then
- if [ "$?" -eq "0" ] ; then
- db_ext=$(echo "$db_file" | cut -d "." -f2)
-
- xshok_pretty_echo_and_log "Testing updated yararulesproject database file: $db_file"
- if [ -z "$ham_dir" ] || [ "$db_ext" != "ndb" ] ; then
- if $clamscan_bin --quiet -d "$work_dir_yararulesproject/$db_file" "$work_dir_work_configs/scan-test.txt" 2>/dev/null
- then
- xshok_pretty_echo_and_log "Clamscan reports yararulesproject $db_file database integrity tested good"
- true
- else
- xshok_pretty_echo_and_log "Clamscan reports yararulesproject $db_file database integrity tested BAD"
- if [ "$remove_bad_database" == "yes" ] ; then
- if rm -f "$work_dir_yararulesproject/$db_file" ; then
- xshok_pretty_echo_and_log "Removed invalid database: $work_dir_yararulesproject/$db_file"
+ db_file=""
+ loop=""
+ update_interval="$((yararulesproject_update_hours * 3600))"
+ time_interval="$((current_time - last_yararulesproject_update))"
+ if [ "$time_interval" -ge "$((update_interval - 600))" ] ; then
+ echo "$current_time" > "$work_dir_work_configs/last-yararulesproject-update.txt"
+
+ xshok_pretty_echo_and_log "Yara-Rules Database File Updates" "="
+ xshok_pretty_echo_and_log "Checking for yararulesproject updates..."
+ yararulesproject_updates="0"
+ for db_file in "${yararulesproject_dbs[@]}" ; do
+ if echo "$db_file" | $grep_bin -q "/"; then
+ yr_dir="/$(echo "$db_file" | cut -d "/" -f 1)"
+ db_file="$(echo "$db_file" | cut -d "/" -f 2)"
+ else yr_dir=""
+ fi
+ if [ "$loop" == "1" ] ; then
+ xshok_pretty_echo_and_log "---"
+ fi
+ xshok_pretty_echo_and_log "Checking for updated yararulesproject database file: $db_file"
+ yararulesproject_db_update="0"
+ xshok_file_download "$work_dir_yararulesproject/$db_file" "$yararulesproject_url/$yr_dir/$db_file"
+ ret="$?"
+ if [ "$ret" -eq 0 ] ; then
+ loop="1"
+ if ! cmp -s "$work_dir_yararulesproject/$db_file" "$clam_dbs/$db_file" ; then
+ if [ $? -eq 0 ] ; then
+ db_ext="${db_file#*.}"
+
+ xshok_pretty_echo_and_log "Testing updated yararulesproject database file: $db_file"
+ if [ -z "$ham_dir" ] || [ "$db_ext" != "ndb" ] ; then
+ if $clamscan_bin --quiet -d "$work_dir_yararulesproject/$db_file" "$work_dir_work_configs/scan-test.txt" 2>/dev/null
+ then
+ xshok_pretty_echo_and_log "Clamscan reports yararulesproject $db_file database integrity tested good"
+ true
+ else
+ xshok_pretty_echo_and_log "Clamscan reports yararulesproject $db_file database integrity tested BAD"
+ if [ "$remove_bad_database" == "yes" ] ; then
+ if rm -f "$work_dir_yararulesproject/$db_file" ; then
+ xshok_pretty_echo_and_log "Removed invalid database: $work_dir_yararulesproject/$db_file"
+ fi
+ fi
+ false
+ fi && (test "$keep_db_backup" = "yes" && cp -f "$clam_dbs/$db_file" "$clam_dbs/$db_file-bak" 2>/dev/null ; true) && if $rsync_bin -pcqt "$work_dir_yararulesproject/$db_file" "$clam_dbs" 2>/dev/null ; then
+ perms chown -f "$clam_user:$clam_group" "$clam_dbs/$db_file"
+ if [ "$selinux_fixes" == "yes" ] ; then
+ restorecon "$clam_dbs/$db_file"
+ fi
+ xshok_pretty_echo_and_log "Successfully updated yararulesproject production database file: $db_file"
+ yararulesproject_updates=1
+ yararulesproject_db_update=1
+ do_clamd_reload=1
+ else
+ xshok_pretty_echo_and_log "Failed to successfully update yararulesproject production database file: $db_file - SKIPPING"
+ fi
+ else
+ $grep_bin -h -v -f "$work_dir_work_configs/whitelist.hex" "$work_dir_yararulesproject/$db_file" > "$test_dir/$db_file"
+ $clamscan_bin --infected --no-summary -d "$test_dir/$db_file" "$ham_dir"/* | command sed 's/\.UNOFFICIAL FOUND//' | awk '{print $NF}' > "$work_dir_work_configs/whitelist.txt"
+ $grep_bin -h -f "$work_dir_work_configs/whitelist.txt" "$test_dir/$db_file" | cut -d "*" -f 2 | sort | uniq >> "$work_dir_work_configs/whitelist.hex"
+ $grep_bin -h -v -f "$work_dir_work_configs/whitelist.hex" "$test_dir/$db_file" > "$test_dir/$db_file-tmp"
+ mv -f "$test_dir/$db_file-tmp" "$test_dir/$db_file"
+ if $clamscan_bin --quiet -d "$test_dir/$db_file" "$work_dir_work_configs/scan-test.txt" 2>/dev/null ; then
+ xshok_pretty_echo_and_log "Clamscan reports yararulesproject $db_file database integrity tested good"
+ true
+ else
+ xshok_pretty_echo_and_log "Clamscan reports yararulesproject $db_file database integrity tested BAD"
+ if [ "$remove_bad_database" == "yes" ] ; then
+ if rm -f "$work_dir_yararulesproject/$db_file" ; then
+ xshok_pretty_echo_and_log "Removed invalid database: $work_dir_yararulesproject/$db_file"
+ fi
+ fi
+ false
+ fi && (test "$keep_db_backup" = "yes" && cp -f "$clam_dbs/$db_file" "$clam_dbs/$db_file-bak" 2>/dev/null ; true) && if $rsync_bin -pcqt "$test_dir/$db_file" "$clam_dbs" 2>/dev/null ; then
+ perms chown -f "$clam_user:$clam_group" "$clam_dbs/$db_file"
+ if [ "$selinux_fixes" == "yes" ] ; then
+ restorecon "$clam_dbs/$db_file"
+ fi
+ xshok_pretty_echo_and_log "Successfully updated yararulesproject production database file: $db_file"
+ yararulesproject_updates=1
+ yararulesproject_db_update=1
+ do_clamd_reload=1
+ else
+ xshok_pretty_echo_and_log "Failed to successfully update yararulesproject production database file: $db_file - SKIPPING"
+ fi