//echo "Recording abuse for address ", $srv_pat->argument, "\n Log entry:\n ";
//echo $logentry->rawdata, "\n Pattern:\n ", $srv_pat->pattern, "\n\n";
- if (record_abuse($logentry->logid, $logentry->objectid, $srv_pat->argument, 1) >= 32)
+ $nr_abuses = record_abuse($logentry->logid, $logentry->objectid, $srv_pat->argument, 1);
+ if ($nr_abuses < 0)
+ {
+ echo "ERROR in recording abuse for address ", $srv_pat->argument, "\n Log entry:\n ";
+ echo $logentry->rawdata, "\n Pattern:\n ", $srv_pat->pattern, "\n\n";
+ }
+ if ($nr_abuses >= 32)
{
$source_ip = gethostbyname($srv_pat->argument);
$notif = 'abuses exceeded';
$abres = $dbms->query("SELECT * FROM object_abuse WHERE objectid='$objectid' AND source='$sourceip'");
- if (pg_numrows($abres) == 0 && $points > 0)
+ if ($abres == false)
{
- //echo "$sourceip is new.\n";
- $dbms->query("INSERT INTO object_abuse VALUES ('$objectid', '$sourceip', '$points', '', NOW())");
- $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
+ $abuse_points = -1; // return an error
}
- else if (pg_numrows($abres) != 0)
+ else
{
- $abuse = $dbms->fetch_object($abres, 0);
- if ($abuse->status == '' || $abuse->status == 'dropped')
+ if (pg_numrows($abres) == 0 && $points > 0)
+ {
+ //echo "$sourceip is new.\n";
+ $dbms->query("INSERT INTO object_abuse VALUES ('$objectid', '$sourceip', '$points', '', NOW())");
+ $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
+ }
+ else if (pg_numrows($abres) != 0)
{
- $abuse_points = $abuse->nr_abuses + $points;
- if ($abuse_points < 0)
+ $abuse = $dbms->fetch_object($abres, 0);
+ if ($abuse->status == '' || $abuse->status == 'dropped')
{
- $abuse_points = 0;
- }
- //echo $sourceip . " will get " . $abuse_points . " abuse points, ";
- //echo "Status was " . $abuse->status . "\n";
- $dbms->query("UPDATE object_abuse SET nr_abuses='$abuse_points'" .
- ", last_change=NOW() WHERE objectid='$objectid' AND source='$sourceip'");
+ $abuse_points = $abuse->nr_abuses + $points;
+ if ($abuse_points < 0)
+ {
+ $abuse_points = 0;
+ }
+ //echo $sourceip . " will get " . $abuse_points . " abuse points, ";
+ //echo "Status was " . $abuse->status . "\n";
+ $dbms->query("UPDATE object_abuse SET nr_abuses='$abuse_points'" .
+ ", last_change=NOW() WHERE objectid='$objectid' AND source='$sourceip'");
- if ($points > 0)
- {
- $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
- }
- if ($abuse_points >= 32)
- {
- //echo " BLOCK IP adrress $sourceip on the firewall.\n";
- $dbms->query("UPDATE object_abuse SET status='dropped'" .
- " WHERE objectid='$objectid' AND source='$sourceip'");
+ if ($points > 0)
+ {
+ $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
+ }
+ if ($abuse_points >= 32)
+ {
+ //echo " BLOCK IP adrress $sourceip on the firewall.\n";
+ $dbms->query("UPDATE object_abuse SET status='dropped'" .
+ " WHERE objectid='$objectid' AND source='$sourceip'");
+ }
}
}
}
--- /dev/null
+#!/bin/bash
+
+#
+# Create an object 'test.gnucomo.org' in the database and
+# and read several filesystems report created by df.
+
+rm -f gcm_input.log
+
+createdb gnucomo_test
+result=1
+
+if psql gnucomo_test -q <../src/database/create.sql >/dev/null
+then
+ psql gnucomo_test -q -c "insert into object (objectname) values ('test.gnucomo.org')"
+
+ # read the output from 'df -k'
+ echo "Read output from 'df -k'"
+ ../src/gcm_input/gcm_input -v -c gnucomo_test -h test.gnucomo.org -d 'sep 7 2007 13:20:45' <df-k.out
+ result=$?
+ if [[ $result -eq 0 ]]
+ then
+ NR_PARS=`psql gnucomo_test -q -t -c "select count(*) from parameter"`
+ echo $NR_PARS parameters in the datebase
+ NR_PROP=`psql gnucomo_test -q -t -c "select count(*) from property"`
+ echo $NR_PROP parameter properties in the datebase
+ if [[ $NR_PARS -ne 7 ]]
+ then
+ result=2
+ fi
+ if [[ $NR_PROP -ne 28 ]]
+ then
+ result=3
+ fi
+ fi
+
+ psql gnucomo_test -f ../src/database/destroy.sql -q
+else
+ echo Can not create test database
+ result=1
+fi
+
+dropdb gnucomo_test
+exit $result