Skip to content

Commit

Permalink
add more of collector-rbl, but validations are broken and i dont know…
Browse files Browse the repository at this point in the history
… why. The validation seperator | does not work in feeds, but do in config??????
  • Loading branch information
kruisdraad committed Dec 24, 2015
1 parent 58a304c commit a2b106e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 22 deletions.
39 changes: 34 additions & 5 deletions config/Rbl.php
Expand Up @@ -18,10 +18,10 @@
* Mode setting
*/
'modes' => [
//'asns',
'asns',
//'netblocks',
//'ipaddresses',
'tickets',
//'tickets',
],

/*
Expand All @@ -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' => '',
],
],
];
74 changes: 57 additions & 17 deletions src/Rbl.php
Expand Up @@ -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
*/
Expand All @@ -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
*
Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand Down

0 comments on commit a2b106e

Please sign in to comment.