Changeset View
Changeset View
Standalone View
Standalone View
src/app/Policy/Greylist/Request.php
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | public function headerGreylist() | ||||
); | ); | ||||
} | } | ||||
return "Received-Greylist: no opinion here"; | return "Received-Greylist: no opinion here"; | ||||
} | } | ||||
public function shouldDefer() | public function shouldDefer() | ||||
{ | { | ||||
$deferIfPermit = true; | |||||
list($this->netID, $this->netType) = \App\Utils::getNetFromAddress($this->request['client_address']); | list($this->netID, $this->netType) = \App\Utils::getNetFromAddress($this->request['client_address']); | ||||
if (!$this->netID) { | if (!$this->netID) { | ||||
return true; | return true; | ||||
} | } | ||||
$recipient = $this->recipientFromRequest(); | $recipient = $this->recipientFromRequest(); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public function shouldDefer() | ||||
)->first(); | )->first(); | ||||
if (!$setting) { | if (!$setting) { | ||||
$domain = $recipient->domain(); | $domain = $recipient->domain(); | ||||
if ($domain) { | if ($domain) { | ||||
$setting = Setting::where( | $setting = Setting::where( | ||||
[ | [ | ||||
'object_id' => $recipient->domain()->id, | 'object_id' => $domain->id, | ||||
'object_type' => \App\Domain::class, | 'object_type' => \App\Domain::class, | ||||
'key' => 'greylist_enabled' | 'key' => 'greylist_enabled' | ||||
] | ] | ||||
)->first(); | )->first(); | ||||
if (!$setting) { | if (!$setting) { | ||||
$enabled = true; | $enabled = true; | ||||
} else { | } else { | ||||
if ($setting->{'value'} !== 'false') { | if ($setting->{'value'} !== 'false') { | ||||
$enabled = true; | $enabled = true; | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
$enabled = true; | $enabled = true; | ||||
} | } | ||||
} else { | } else { | ||||
if ($setting->{'value'} !== 'false') { | if ($setting->{'value'} !== 'false') { | ||||
$enabled = true; | $enabled = true; | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
$enabled = true; | $enabled = true; | ||||
} | } | ||||
// the following block is to maintain statistics and state ... | // the following block is to maintain statistics and state ... | ||||
mollekopf: I would say if there is no recipient set $enabled = false so we bail out after capturing the… | |||||
$entries = Connect::where( | $entries = Connect::where( | ||||
[ | [ | ||||
'sender_domain' => $this->senderDomain, | 'sender_domain' => $this->senderDomain, | ||||
'net_id' => $this->netID, | 'net_id' => $this->netID, | ||||
'net_type' => $this->netType | 'net_type' => $this->netType | ||||
] | ] | ||||
) | ) | ||||
->whereDate('updated_at', '>=', $this->timestamp->copy()->subDays(7)); | ->whereDate('updated_at', '>=', $this->timestamp->copy()->subDays(7)); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public function shouldDefer() | ||||
'net_id' => $this->netID, | 'net_id' => $this->netID, | ||||
'net_type' => $this->netType, | 'net_type' => $this->netType, | ||||
] | ] | ||||
) | ) | ||||
->whereDate('updated_at', '>=', $this->timestamp->copy()->subMonthsWithoutOverflow(1)) | ->whereDate('updated_at', '>=', $this->timestamp->copy()->subMonthsWithoutOverflow(1)) | ||||
->orderBy('updated_at') | ->orderBy('updated_at') | ||||
->first(); | ->first(); | ||||
if (!$connect) { | $deferIfPermit = true; | ||||
$connect = Connect::create( | |||||
if ($connect) { | |||||
$connect->connect_count += 1; | |||||
// TODO: The period of time for which the greylisting persists is configurable. | |||||
if ($connect->created_at < $this->timestamp->copy()->subMinutes(5)) { | |||||
$deferIfPermit = false; | |||||
$connect->greylisting = false; | |||||
} | |||||
$connect->save(); | |||||
} else { | |||||
Connect::create( | |||||
[ | [ | ||||
'sender_local' => $this->senderLocal, | 'sender_local' => $this->senderLocal, | ||||
'sender_domain' => $this->senderDomain, | 'sender_domain' => $this->senderDomain, | ||||
'net_id' => $this->netID, | 'net_id' => $this->netID, | ||||
'net_type' => $this->netType, | 'net_type' => $this->netType, | ||||
'recipient_hash' => $this->recipientHash, | 'recipient_hash' => $this->recipientHash, | ||||
'recipient_id' => $this->recipientID, | 'recipient_id' => $this->recipientID, | ||||
'recipient_type' => $this->recipientType, | 'recipient_type' => $this->recipientType, | ||||
'connect_count' => 0, | |||||
'created_at' => $this->timestamp, | 'created_at' => $this->timestamp, | ||||
'updated_at' => $this->timestamp | 'updated_at' => $this->timestamp | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
$connect->connect_count += 1; | |||||
// TODO: The period of time for which the greylisting persists is configurable. | |||||
if ($connect->created_at < $this->timestamp->copy()->subMinutes(5)) { | |||||
$deferIfPermit = false; | |||||
$connect->greylisting = false; | |||||
} | |||||
$connect->save(); | |||||
return $deferIfPermit; | return $deferIfPermit; | ||||
} | } | ||||
private function findConnectsCollection() | private function findConnectsCollection() | ||||
{ | { | ||||
$collection = Connect::where( | $collection = Connect::where( | ||||
[ | [ | ||||
'sender_local' => $this->senderLocal, | 'sender_local' => $this->senderLocal, | ||||
Show All 10 Lines | class Request | ||||
private function findConnectsCollectionRecent() | private function findConnectsCollectionRecent() | ||||
{ | { | ||||
return $this->findConnectsCollection() | return $this->findConnectsCollection() | ||||
->where('updated_at', '>=', $this->timestamp->copy()->subDays(7)); | ->where('updated_at', '>=', $this->timestamp->copy()->subDays(7)); | ||||
} | } | ||||
private function recipientFromRequest() | private function recipientFromRequest() | ||||
{ | { | ||||
$recipient = null; | |||||
$recipients = \App\Utils::findObjectsByRecipientAddress($this->request['recipient']); | $recipients = \App\Utils::findObjectsByRecipientAddress($this->request['recipient']); | ||||
if (sizeof($recipients) > 1) { | if (sizeof($recipients) > 1) { | ||||
\Log::warning( | \Log::warning( | ||||
"Only taking the first recipient from the request for {$this->request['recipient']}" | "Only taking the first recipient from the request for {$this->request['recipient']}" | ||||
); | ); | ||||
} | } | ||||
Show All 22 Lines |
I would say if there is no recipient set $enabled = false so we bail out after capturing the sender statistics?
@vanmeeuwen Should we capture sender statistics if the recipient is not found,? should we greylist if the recipient is not found?