From a2b106e9b2da4bd5fce71aa7859bd5194ae7a503 Mon Sep 17 00:00:00 2001 From: Bart Vrancken Date: Thu, 24 Dec 2015 21:26:33 +0100 Subject: [PATCH] add more of collector-rbl, but validations are broken and i dont know why. The validation seperator | does not work in feeds, but do in config?????? --- config/Rbl.php | 39 ++++++++++++++++++++++---- src/Rbl.php | 74 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 91 insertions(+), 22 deletions(-) diff --git a/config/Rbl.php b/config/Rbl.php index 6be13f4..eff0668 100644 --- a/config/Rbl.php +++ b/config/Rbl.php @@ -18,10 +18,10 @@ * Mode setting */ 'modes' => [ - //'asns', + 'asns', //'netblocks', //'ipaddresses', - 'tickets', + //'tickets', ], /* @@ -39,14 +39,43 @@ ], + /* + * Method can be either 'dns' or 'file'. If set to file, the zonefile must be set to the RBLDNSD file + */ 'feeds' => [ - 'Default' => [ - 'class' => 'test', + 'zen.spamhaus.org' => [ + 'name' => 'Spamhaus', + 'class' => 'RBL Listed', 'type' => 'Abuse', 'enabled' => true, 'fields' => [ - 'test' => 'test', + // ], + 'filters' => [ + // + ], + 'information' => [ + 'delisting url' => 'https://www.spamhaus.org/lookup/', + ], + 'method' => 'dns', + 'zonefile' => '', + ], + 'bl.spamcop.net' => [ + 'name' => 'Spamcop', + 'class' => 'RBL Listed', + 'type' => 'Abuse', + 'enabled' => true, + 'fields' => [ + // + ], + 'filters' => [ + // + ], + 'information' => [ + 'delisting url' => 'https://www.spamcop.net/bl.shtml', + ], + 'method' => 'dns', + 'zonefile' => '', ], ], ]; diff --git a/src/Rbl.php b/src/Rbl.php index 0c0fc1c..76538b7 100644 --- a/src/Rbl.php +++ b/src/Rbl.php @@ -2,13 +2,13 @@ namespace AbuseIO\Collectors; -use AbuseIO\Models\Ticket; use Validator; +use AbuseIO\Models\Ticket; class Rbl extends Collector { /** - * The allowed modes of operation of the scanner + * The allowed modes of operation of the scanner with a setting if they required validations * * @var array */ @@ -19,18 +19,46 @@ class Rbl extends Collector 'tickets' => false, ]; + /** + * The allowed methods of operation of the scanner with a setting if they required validations + * + * @var array + */ + protected $allowedMethods = [ + 'dns' => false, + 'file' => true, + ]; + /** * The validations for each mode * * @var array */ - protected $validate = [ + protected $rulesConfig = [ 'asns' => 'required|string', 'netblocks' => 'required|string', 'ipaddresses' => 'required|string', 'tickets' => 'required|string', ]; + /** + * The validations for each feed + * + * @var array + */ + protected $rulesFeed = [ + 'feedname' => 'required|string', + 'name' => 'required|string', + 'class' => 'required|abuseclass', + 'type' => 'required|abusetype', + 'enabled' => 'required|boolean', + 'fields' => 'sometimes|array', + 'filters' => 'sometimes|array', + 'information' => 'sometimes|array', + 'method' => 'required|string', + 'zonefile' => 'sometimes|isfile', + ]; + /** * Create a new Abusehub instance * @@ -59,6 +87,26 @@ public function parse() return $this->failed('No mode of operation configured, or mode config invalid'); } + $feeds = array_change_key_case(config("{$this->configBase}.feeds"), CASE_LOWER); + if (empty($feeds) || !is_array($feeds)) { + return $this->failed('No RBL feeds configured, or feed config invalid'); + } + + foreach ($feeds as $feedName => $feedConfig) { + $validator = Validator::make( + [ array_merge($feedConfig, ['feedname' => $feedName]) ], + [ $this->rulesFeed ] + ); + + if ($validator->fails()) { + return $this->failed(implode(' ', $validator->messages()->all())); + } + } + + /* + * For each configured mode kick of a scanning process. + * Todo: Look into multithreading this in DNS mode + */ foreach($modes as $mode) { if(!array_key_exists($mode, $this->allowedModes)) { return $this->failed("Configuration error detected. Mode {$mode} is not an option"); @@ -75,25 +123,17 @@ public function parse() foreach ($config as $configElement) { $validator = Validator::make( - [ - $mode => $configElement - ], - [ - $mode => $this->validate[$mode] - ] + [ $mode => $configElement ], + [ $mode => $this->rulesConfig[$mode] ] ); if ($validator->fails()) { - $messages = $validator->messages(); - - $message = ''; - foreach ($messages->all() as $messagePart) { - $message .= $messagePart; - } - - return $this->failed($message); + return $this->failed(implode(' ', $validator->messages()->all())); } } + + } else { + continue; } switch($mode) {