# Core schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/*
Priorities...
0 - System policy priority (fallthrough)
1-50 - System policies
50-100 - Custom policies
*/
/* Policies */
CREATE TABLE policies (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name VARCHAR(255) NOT NULL,
Priority SMALLINT NOT NULL,
Description TEXT,
Disabled SMALLINT NOT NULL DEFAULT '0'
) ;
INSERT INTO policies (Name,Priority,Description) VALUES ('Default',0,'Default System Policy');
INSERT INTO policies (Name,Priority,Description) VALUES ('Default Outbound',10,'Default Outbound System Policy');
INSERT INTO policies (Name,Priority,Description) VALUES ('Default Inbound',10,'Default Inbound System Policy');
INSERT INTO policies (Name,Priority,Description) VALUES ('Default Internal',20,'Default Internal System Policy');
INSERT INTO policies (Name,Priority,Description) VALUES ('Test',50,'Test policy');
/* Member list for policies */
CREATE TABLE policy_members (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
/*
Format of key:
NULL = any
a.b.c.d/e = IP address with optional /e
@domain = domain specification,
%xyz = xyz group,
abc@domain = abc user specification
all options support negation using !<key>
*/
Source TEXT,
Destination TEXT,
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
/* Default System Policy */
INSERT INTO policy_members (PolicyID,Source,Destination) VALUES
(1,NULL,NULL);
/* Default Outbound System Policy */
INSERT INTO policy_members (PolicyID,Source,Destination) VALUES
(2,'%internal_ips,%internal_domains','!%internal_domains');
/* Default Inbound System Policy */
INSERT INTO policy_members (PolicyID,Source,Destination) VALUES
(3,'!%internal_ips,!%internal_domains','%internal_domains');
/* Default Internal System Policy */
INSERT INTO policy_members (PolicyID,Source,Destination) VALUES
(4,'%internal_ips,%internal_domains','%internal_domains');
/* Test Policy */
INSERT INTO policy_members (PolicyID,Source,Destination) VALUES
(5,'@example.net',NULL);
/* Groups usable in ACL */
CREATE TABLE policy_groups (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name VARCHAR(255) NOT NULL,
Disabled SMALLINT NOT NULL DEFAULT '0',
Comment VARCHAR(1024),
UNIQUE (Name)
) ;
INSERT INTO policy_groups (Name) VALUES ('internal_ips');
INSERT INTO policy_groups (Name) VALUES ('internal_domains');
/* Group members */
CREATE TABLE policy_group_members (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyGroupID INT8,
/* Format of member: a.b.c.d/e = ip, @domain = domain, %xyz = xyz group, abc@domain = abc user */
Member VARCHAR(255) NOT NULL,
Disabled SMALLINT NOT NULL DEFAULT '0',
Comment VARCHAR(1024),
FOREIGN KEY (PolicyGroupID) REFERENCES policy_groups(ID)
) ;
INSERT INTO policy_group_members (PolicyGroupID,Member) VALUES (1,'10.0.0.0/8');
INSERT INTO policy_group_members (PolicyGroupID,Member) VALUES (2,'@example.org');
INSERT INTO policy_group_members (PolicyGroupID,Member) VALUES (2,'@example.com');
/* Message session tracking */
CREATE TABLE session_tracking (
Instance VARCHAR(255),
QueueID VARCHAR(255),
UnixTimestamp BIGINT NOT NULL,
ClientAddress VARCHAR(64),
ClientName VARCHAR(255),
ClientReverseName VARCHAR(255),
Protocol VARCHAR(255),
EncryptionProtocol VARCHAR(255),
EncryptionCipher VARCHAR(255),
EncryptionKeySize VARCHAR(255),
SASLMethod VARCHAR(255),
SASLSender VARCHAR(255),
SASLUsername VARCHAR(255),
Helo VARCHAR(255),
Sender VARCHAR(255),
Size UNSIGNED BIG INT,
RecipientData TEXT, /* Policy state information */
UNIQUE (Instance)
) ;
CREATE INDEX session_tracking_idx1 ON session_tracking (QueueID,ClientAddress,Sender);
CREATE INDEX session_tracking_idx2 ON session_tracking (UnixTimestamp);
# Amavis module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Amavisd-new integration for Policyd */
CREATE TABLE amavis_rules (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
/*
Mode of operation (the _m columns):
This is done with the _m column names
0 - Inherit
1 - Merge (only valid for lists)
2 - Overwrite
*/
/* Bypass options */
bypass_virus_checks SMALLINT,
bypass_virus_checks_m SMALLINT NOT NULL DEFAULT '0',
bypass_banned_checks SMALLINT,
bypass_banned_checks_m SMALLINT NOT NULL DEFAULT '0',
bypass_spam_checks SMALLINT,
bypass_spam_checks_m SMALLINT NOT NULL DEFAULT '0',
bypass_header_checks SMALLINT,
bypass_header_checks_m SMALLINT NOT NULL DEFAULT '0',
/* Anti-spam options: NULL = inherit */
spam_tag_level FLOAT,
spam_tag_level_m SMALLINT NOT NULL DEFAULT '0',
spam_tag2_level FLOAT,
spam_tag2_level_m SMALLINT NOT NULL DEFAULT '0',
spam_tag3_level FLOAT,
spam_tag3_level_m SMALLINT NOT NULL DEFAULT '0',
spam_kill_level FLOAT,
spam_kill_level_m SMALLINT NOT NULL DEFAULT '0',
spam_dsn_cutoff_level FLOAT,
spam_dsn_cutoff_level_m SMALLINT NOT NULL DEFAULT '0',
spam_quarantine_cutoff_level FLOAT,
spam_quarantine_cutoff_level_m SMALLINT NOT NULL DEFAULT '0',
spam_modifies_subject SMALLINT,
spam_modifies_subject_m SMALLINT NOT NULL DEFAULT '0',
spam_tag_subject VARCHAR(255), /* _SCORE_ is the score, _REQD_ is the required score */
spam_tag_subject_m SMALLINT NOT NULL DEFAULT '0',
spam_tag2_subject VARCHAR(255),
spam_tag2_subject_m SMALLINT NOT NULL DEFAULT '0',
spam_tag3_subject VARCHAR(255),
spam_tag3_subject_m SMALLINT NOT NULL DEFAULT '0',
/* General checks: NULL = inherit */
max_message_size BIGINT, /* in Kbyte */
max_message_size_m SMALLINT NOT NULL DEFAULT '0',
banned_files TEXT,
banned_files_m SMALLINT NOT NULL DEFAULT '0',
/* Whitelist & blacklist */
sender_whitelist TEXT,
sender_whitelist_m SMALLINT NOT NULL DEFAULT '0',
sender_blacklist TEXT,
sender_blacklist_m SMALLINT NOT NULL DEFAULT '0',
/* Admin notifications */
notify_admin_newvirus VARCHAR(255),
notify_admin_newvirus_m SMALLINT NOT NULL DEFAULT '0',
notify_admin_virus VARCHAR(255),
notify_admin_virus_m SMALLINT NOT NULL DEFAULT '0',
notify_admin_spam VARCHAR(255),
notify_admin_spam_m SMALLINT NOT NULL DEFAULT '0',
notify_admin_banned_file VARCHAR(255),
notify_admin_banned_file_m SMALLINT NOT NULL DEFAULT '0',
notify_admin_bad_header VARCHAR(255),
notify_admin_bad_header_m SMALLINT NOT NULL DEFAULT '0',
/* Quarantine options */
quarantine_virus VARCHAR(255),
quarantine_virus_m SMALLINT NOT NULL DEFAULT '0',
quarantine_banned_file VARCHAR(255),
quarantine_banned_file_m SMALLINT NOT NULL DEFAULT '0',
quarantine_bad_header VARCHAR(255),
quarantine_bad_header_m SMALLINT NOT NULL DEFAULT '0',
quarantine_spam VARCHAR(255),
quarantine_spam_m SMALLINT NOT NULL DEFAULT '0',
/* Interception options */
bcc_to VARCHAR(255),
bcc_to_m SMALLINT NOT NULL DEFAULT '0',
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
INSERT INTO amavis_rules
(
PolicyID,
Name,
max_message_size,max_message_size_m,
bypass_banned_checks, bypass_banned_checks_m
)
VALUES
(
1,
'Default system amavis policy',
100000,2,
1,2
);
# AccessControl module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Plain and simple access control */
CREATE TABLE access_control (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
Verdict VARCHAR(255),
Data TEXT,
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
/* INSERT INTO access_control (PolicyID,Verdict,Data) VALUES (5,'REJECT','POP,SNAPPLE,CRAK'); */
# CheckSPF module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* SPF checking */
/*
NULL means to inherit
*/
CREATE TABLE checkspf (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
/* Do we want to use SPF? 1 or 0 */
UseSPF SMALLINT,
/* Reject when SPF fails */
RejectFailedSPF SMALLINT,
/* Add SPF header */
AddSPFHeader SMALLINT,
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
# CheckHelo module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Helo checking */
/*
NULL means to inherit
*/
CREATE TABLE checkhelo (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
/* Blacklisting, we want to reject people impersonating us */
UseBlacklist SMALLINT, /* Checks blacklist table */
BlacklistPeriod UNSIGNED BIG INT, /* Period to keep the host blacklisted for, if not set or 0
the check will be live */
/* Random helo prevention */
UseHRP SMALLINT, /* Use helo randomization prevention */
HRPPeriod UNSIGNED BIG INT, /* Period/window we check for random helo's */
HRPLimit UNSIGNED BIG INT, /* Our limit for the number of helo's is this */
/* RFC compliance options */
RejectInvalid SMALLINT, /* Reject invalid HELO */
RejectIP SMALLINT, /* Reject if HELO is an IP */
RejectUnresolvable SMALLINT, /* Reject unresolvable HELO */
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
/* Blacklisted HELO's */
CREATE TABLE checkhelo_blacklist (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Helo VARCHAR(255) NOT NULL,
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
UNIQUE (Helo)
) ;
INSERT INTO checkhelo_blacklist (Helo,Comment) VALUES
('127.0.0.1','Blacklist hosts claiming to be 127.0.0.1');
INSERT INTO checkhelo_blacklist (Helo,Comment) VALUES
('[127.0.0.1]','Blacklist hosts claiming to be [127.0.0.1]');
INSERT INTO checkhelo_blacklist (Helo,Comment) VALUES
('localhost','Blacklist hosts claiming to be localhost');
INSERT INTO checkhelo_blacklist (Helo,Comment) VALUES
('localhost.localdomain','Blacklist hosts claiming to be localhost.localdomain');
/* Whitelisted CIDR's */
CREATE TABLE checkhelo_whitelist (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Source VARCHAR(512) NOT NULL, /* Valid format is: SenderIP:a.b.c.d[/e] */
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
UNIQUE (Source)
) ;
/* Helo tracking table */
CREATE TABLE checkhelo_tracking (
Address VARCHAR(64) NOT NULL,
Helo VARCHAR(255) NOT NULL,
LastUpdate UNSIGNED BIG INT NOT NULL,
UNIQUE (Address,Helo)
) ;
CREATE INDEX checkhelo_tracking_idx1 ON checkhelo_tracking (LastUpdate);
# Accounting module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Main accounting table, this defines the period the accounting items are over and how to track it */
CREATE TABLE accounting (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
/* Tracking Options */
Track VARCHAR(255) NOT NULL, /* Format: <type>:<spec>
SenderIP - This takes a bitmask to mask the IP with. A good default is /24
Sender & Recipient - Either "user@domain" (default), "user@" or "@domain" for the entire
email addy or email addy domain respectively.
*/
/* Period over which to account traffic */
AccountingPeriod SMALLINT NOT NULL, /* 0 - Track by day, 1 - Track by week, 2 - Track by month */
/* Limits for this period */
MessageCountLimit UNSIGNED BIG INT, /* Limit is in Kbyte, NULL means no limit */
MessageCumulativeSizeLimit UNSIGNED BIG INT, /* LImit is in Kbyte, NULL means no limit */
/* Verdict if limits are exceeded */
Verdict VARCHAR(255), /* Verdict when limit is exceeded */
Data TEXT, /* Data sent along with verdict */
LastAccounting SMALLINT NOT NULL DEFAULT '0',
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
/* This table is used for tracking the accounting */
CREATE TABLE accounting_tracking (
AccountingID INT8,
TrackKey VARCHAR(512),
PeriodKey VARCHAR(512),
/* Last time this record was update */
LastUpdate UNSIGNED BIG INT, /* NULL means not updated yet */
MessageCount UNSIGNED BIG INT,
MessageCumulativeSize UNSIGNED BIG INT, /* Counter is in Kbyte */
UNIQUE (AccountingID,TrackKey,PeriodKey),
FOREIGN KEY (AccountingID) REFERENCES accounting(ID)
) ;
CREATE INDEX accounting_tracking_idx1 ON accounting_tracking (LastUpdate);
# Greylisting module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Greylisting */
/*
NULL means to inherit
*/
CREATE TABLE greylisting (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
/* General greylisting settings */
UseGreylisting SMALLINT, /* Actually use greylisting */
GreylistPeriod UNSIGNED BIG INT, /* Period in seconds to greylist for */
/* Record tracking */
Track VARCHAR(255) NOT NULL, /* Format: <type>:<spec>
SenderIP - This takes a bitmask to mask the IP with, A good default is /24
*/
/* Bypass greylisting: sender+recipient level */
GreylistAuthValidity UNSIGNED BIG INT, /* Period for which last authenticated greylist entry is valid for.
This effectively bypasses greylisting for the second email a sender
sends a recipient. */
GreylistUnAuthValidity UNSIGNED BIG INT, /* Same as above but for unauthenticated entries */
/* Auto-whitelisting: sending server level */
UseAutoWhitelist SMALLINT, /* Use auto-whitelisting */
AutoWhitelistPeriod UNSIGNED BIG INT, /* Period to look back to find authenticated triplets */
AutoWhitelistCount UNSIGNED BIG INT, /* Count of authenticated triplets after which we auto-whitelist */
AutoWhitelistPercentage UNSIGNED BIG INT, /* Percentage of at least Count triplets that must be authenticated
before auto-whitelisting. This changes the behaviour or Count */
/* Auto-blacklisting: sending server level */
UseAutoBlacklist SMALLINT, /* Use auto-blacklisting */
AutoBlacklistPeriod UNSIGNED BIG INT, /* Period to look back to find unauthenticated triplets */
AutoBlacklistCount UNSIGNED BIG INT, /* Count of authenticated triplets after which we auto-whitelist */
AutoBlacklistPercentage UNSIGNED BIG INT, /* Percentage of at least Count triplets that must be authenticated
before auto-whitelisting. This changes the behaviour or Count */
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
/* Whitelisted */
CREATE TABLE greylisting_whitelist (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Source VARCHAR(255) NOT NULL, /* Either CIDR a.b.c.d, a.b.c.d/x, or reversed host*-*.whatever.com */
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
UNIQUE (Source)
) ;
/* Auto-whitelistings */
CREATE TABLE greylisting_autowhitelist (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
TrackKey VARCHAR(512) NOT NULL,
Added UNSIGNED BIG INT NOT NULL,
LastSeen UNSIGNED BIG INT NOT NULL,
Comment VARCHAR(1024),
UNIQUE (TrackKey)
) ;
/* Auto-blacklistings */
CREATE TABLE greylisting_autoblacklist (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
TrackKey VARCHAR(512) NOT NULL,
Added UNSIGNED BIG INT NOT NULL,
Comment VARCHAR(1024),
UNIQUE (TrackKey)
) ;
/* Greylist triplet tracking table */
CREATE TABLE greylisting_tracking (
TrackKey VARCHAR(512) NOT NULL, /* The address really, masked with whatever */
Sender VARCHAR(255) NOT NULL,
Recipient VARCHAR(255) NOT NULL,
FirstSeen UNSIGNED BIG INT NOT NULL,
LastUpdate UNSIGNED BIG INT NOT NULL,
Tries UNSIGNED BIG INT NOT NULL, /* Authentication tries */
Count UNSIGNED BIG INT NOT NULL, /* Authenticated count */
UNIQUE(TrackKey,Sender,Recipient)
) ;
CREATE INDEX greylisting_tracking_idx1 ON greylisting_tracking (LastUpdate,Count);
# Quotas module schema
# Copyright (C) 2009-2011, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Main quotas table, this defines the period the quota is over and how to track it */
CREATE TABLE quotas (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PolicyID INT8,
Name VARCHAR(255) NOT NULL,
/* Tracking Options */
Track VARCHAR(255) NOT NULL, /* Format: <type>:<spec>
SenderIP - This takes a bitmask to mask the IP with. A good default is /24
Sender & Recipient - Either "user@domain" (default), "user@" or "@domain" for the entire
email addy or email addy domain respectively.
*/
/* Period over which this policy is valid, this is in seconds */
Period UNSIGNED BIG INT,
Verdict VARCHAR(255),
Data TEXT,
LastQuota SMALLINT NOT NULL DEFAULT '0',
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (PolicyID) REFERENCES policies(ID)
) ;
INSERT INTO quotas (PolicyID,Name,Track,Period,Verdict) VALUES (5,'Recipient quotas','Recipient:user@domain',3600,'REJECT');
INSERT INTO quotas (PolicyID,Name,Track,Period,Verdict) VALUES (5,'Quota on all /24s','SenderIP:/24',3600,'REJECT');
/* Limits for the quota */
CREATE TABLE quotas_limits (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
QuotasID INT8,
Type VARCHAR(255), /* "MessageCount" or "MessageCumulativeSize" */
CounterLimit UNSIGNED BIG INT,
Comment VARCHAR(1024),
Disabled SMALLINT NOT NULL DEFAULT '0',
FOREIGN KEY (QuotasID) REFERENCES quotas(ID)
) ;
INSERT INTO quotas_limits (QuotasID,Type,CounterLimit) VALUES (1,'MessageCount',10);
INSERT INTO quotas_limits (QuotasID,Type,CounterLimit) VALUES (1,'MessageCumulativeSize',8000);
INSERT INTO quotas_limits (QuotasID,Type,CounterLimit) VALUES (2,'MessageCount',12);
/* This table is used for tracking the quotas */
CREATE TABLE quotas_tracking (
QuotasLimitsID INT8,
TrackKey VARCHAR(512),
/* Last time this record was update */
LastUpdate UNSIGNED BIG INT, /* NULL means not updated yet */
Counter NUMERIC(10,4),
UNIQUE (QuotasLimitsID,TrackKey),
FOREIGN KEY (QuotasLimitsID) REFERENCES quotas_limits(ID)
) ;
CREATE INDEX quotas_tracking_idx1 ON quotas_tracking (LastUpdate);
|