forked from logical-and/postfix_php_policy_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
34 lines (29 loc) · 811 Bytes
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/php
<?php
require __DIR__ . '/postfix-util.php';
$args = fetchArgs();
// Skip not authenticated
if (!empty($args['sasl_username']))
{
// Check username in virtual table
$virtualPath = '/etc/postfix/virtual';
try {
$table = parseHash($virtualPath, ['email', 'account'], 'account');
}
catch (\Exception $e)
{
sendResult(ACTION_REJECT, 'Error occured: ' . $e->getMessage());
}
if (empty($table[$args['sasl_username']]))
{
sendResult(ACTION_REJECT, "Username \"{$args['sasl_username']}\" is unknown!");
}
elseif ($args['sender'] != $table[$args['sasl_username']]['email'])
{
sendResult(ACTION_REJECT,
'Your account can only send email from "' .
$table[$args['sasl_username']]['email'] . '" email! ' .
"(tried from \"{$args['sender']}\")");
}
}
sendResult(ACTION_ALLOW);