Objects
Objects are used to create reusable configuration variables declared using Rhai functions.
Type | Description | Syntax | Comments |
---|---|---|---|
ip4 | IPv4 address | x.y.z.t | Decimal values. |
ip6 | IPv6 address | a:b:c:d:e:f:g:h | Hex values. |
rg4 | IPv4 network | x.y.z.t/rg | Decimal values. |
rg6 | IPv6 prefix | a:b:c:d:e:f:g:h/rg | Hex values. |
address | Email address | identifier@fqdn | String. |
identifier | Local part of an address | user | String. |
fqdn | Fully qualified domain name | my.domain.com | String. |
regex | Regular expression | PERL regular expression. | |
file | A file of objects | Unix file | See file section. |
code | a custom smtp code | See code section. |
All available objects types
Creating objects
Objects can be created via associated functions:
const my_ipv4 = ip4("127.0.0.1");
const my_address = address("john.doe@example.com");
// ...
Declaring objects in scripts
See the Object reference to get an extensive list of objects constructors.
Modules
It is recommended to declare objects inside .vsl
files and importing them via the import
Rhai directive in rule files.
See the Rhai modules documentation for more details.
// Object are accessible trough `import` when declared with the `export` keyword.
export const localhost = ip4("127.0.0.1");
An object file, `objects/network.vsl`
import "objects/network" as network;
#{
connect: [
rule "force accept localhost" || {
if ctx::client_ip() == network::localhost {
state::faccept();
} else {
state::next()
}
}
]
}
A rule in `filter.vsl`
Objects should be stored inside the objects
directory of /etc/vsmtp
if they are used into multiple rules sets.
/etc/vsmtp
┣ vsmtp.vsl
┣ filter.vsl
┣ conf.d/
┃ ┗ config.vsl
┣ domain-available/
┃ ┗ example.com/
┃ ┗ ...
┣ domain-enabled/
┃ ┗ example.com -> ...
┗ objects/
+ ┗ network.vsl
Placing objects files in `/etc/vsmtp/objects/`
However, if objects are used in only a specific rule set, they should be stored directly in a separate file among the rule set.
/etc/vsmtp
┣ vsmtp.vsl
┣ filter.vsl
┣ conf.d/
┃ ┗ config.vsl
┣ domain-available/
┃ ┗ example.com/
+ ┃ ┣ network-objects.vsl
┃ ┣ incoming.vsl
┃ ┣ outgoing.vsl
┃ ┗ internal.vsl
┣ domain-enabled/
┃ ┗ example.com -> ...
┗ objects/
- ┗ network.vsl
Placing objects relative to a domain, renaming it to network-objects.vsl to make it clear that it is an object file
Grouping objects
Objects can be grouped using Rhai Arrays.
const authorized_users = [
address("admin@example.com"),
address("foo@example.com"),
address("bar@example.com"),
];
An array of email address
When used with check operators (
==
,!=
,in
etc …), the whole array will be tested. The test stops when one element of the group matches, or nothing matches.
Different types of objects can be grouped together.
Pre-defined objects
vSL already exposes some objects. Check out the Variable reference to get more details.