Compare commits

...
7 Commits
18 changed files with 573 additions and 84 deletions

No files matched your search

+3 -1
View File
@@ -80,7 +80,7 @@ Each mailbox receives a unique 15-character Feedback Loop sender ID. Rspamd adds
Google FBL reporting requires mail to be DKIM-signed by a domain verified in Google Postmaster Tools. Publish the sending IPs in SPF and ensure the IPs have valid PTR records; FBL reports apply only to Gmail recipients.
Configure DKIM signing maps by replacing the example hostname and token in `/etc/rspamd/local.d/arc.conf` and `/etc/rspamd/local.d/dkim_signing.conf` with the same hostname and token used for the other Rspamd maps. An RSA DKIM key is generated automatically when a domain is added. The domain editor shows the selector and public DNS TXT record to publish; regenerating the key changes the selector and requires updating that record. Private keys are stored in the database and should be protected accordingly.
Configure the DKIM signing map by replacing the example hostname and token in `/etc/rspamd/local.d/dkim_signing.conf` with the same hostname and token used for the other Rspamd maps. ARC/DKIM signing uses the local Redis instance (`127.0.0.1:6379`) via the `php-redis` extension, with Redis hashes `dkim_keys` and `dkim_selectors`; the installation script installs the extension. ARC signing is enabled for authenticated, local, and inbound messages, using the recipient's hosted domain for inbound ARC seals. The database-backed ARC hashes are synchronized during setup, when a domain is added/updated or a key is regenerated, and by the five-minute cron job. An RSA DKIM key is generated automatically when a domain is added. The domain editor shows the selector and public DNS TXT record to publish; regenerating the key changes the selector and requires updating that record. Private keys are stored in the database and Redis and should be protected accordingly.
The authenticated-user ratelimit map is configured in `/etc/rspamd/custom_ratelimit.lua`; replace its example hostname and token with your map endpoint settings. Accounts registered within the last 14 days receive lower sending limits. A mailbox marked as trusted in the admin editor receives higher limits; other authenticated mailboxes receive the default limits.
@@ -90,6 +90,8 @@ Mailbox owners can add identity addresses on their mailbox domain from account s
Registering a mailbox on `CLEARNET_SERVER` automatically creates its matching `local_part@ONION_SERVER` identity. The database upgrade backfills this identity for existing clearnet mailboxes.
When `INVITE_CODES_ENABLED` is true, public mailbox registration requires an unused invite code and admins can generate unlimited codes from the admin interface. User accounts can generate up to `INVITE_CODE_LIMIT` codes after `INVITE_WAIT_PERIOD_MONTHS` months; each redeemed user-generated code makes one replacement available after the same wait from its redemption date. Set `INVITE_CODE_LIMIT` to 0 to hide user invite management while retaining admin-generated codes and invite-required registration. Set `INVITE_CODES_ENABLED` to false to hide invite management and allow registration without an invite. These settings are in `common_config.php`. Running `php setup.php` creates the invite-code table on existing installations.
Rspamd rejects unauthenticated inbound messages using a hosted envelope-sender domain unless SPF passes or DMARC passes for a hosted From domain. Configure the hosted-domain map URL and token in `/etc/rspamd/rspamd.local.lua` alongside the other Rspamd map settings.
Create a password used for your TURN server and replace all `YOUR_SECRET` in `/etc/prosody/prosody.cfg.lua` with it.
+87 -1
View File
@@ -9,11 +9,13 @@ const DBHOST = 'localhost'; // Database host
const DBUSER = 'postfix'; // Database user
const DBPASS = 'YOUR_PASSWORD'; // Database password
const DBNAME = 'postfix'; // Database
const DBVERSION = 13; // Database schema version
const DBVERSION = 14; // Database schema version
const INACTIVITY_PERIOD_MONTHS = [1, 6, 12, 24]; // Allowed inactivity periods in months - don't forget to update get_inactivity_period_options on changes here and if an option is removed, you should also update accounts in the database mailbox table
const DEFAULT_INACTIVITY_PERIOD = 12; // Default inactivity period in months
const ALLOW_ACCOUNT_NEVER_DELETE = false; // Whether to allow users to set their inactivity period to "never delete"
const RSPAMD_SETTINGS_MAP_TOKEN = 'CHANGE_ME_TO_A_LONG_RANDOM_SECRET'; // Token used to authenticate requests to the Rspamd settings map endpoint
const RSPAMD_REDIS_HOST = '127.0.0.1'; // Redis server used by Rspamd
const RSPAMD_REDIS_PORT = 6379; // Redis port used by Rspamd
const SPAM_REJECT_SCORE_OPTIONS = [0, 5, 8, 10, 12, 15, 20, 25, 30]; // Allowed spam reject scores
const DEFAULT_SPAM_REJECT_SCORE = 15; // Default spam reject score
const CUSTOM_RSPAMD_SETTINGS = ''; // Custom Rspamd settings to be added to the Rspamd settings map
@@ -38,6 +40,40 @@ const DEFAULT_QUOTA = 50 * 1024 * 1024; // Default mailbox quota in bytes
const POSTMASTER_EMAIL = 'postmaster@danwin1210.de'; // Email address of the postmaster account receiving TLS and DMARC reports
const POSTMASTER_PASSWORD = 'YOUR_PASSWORD'; // Password of the postmaster account receiving TLS and DMARC reports
const ADMIN_LIST_PAGE_SIZE = 50; // Number of entries per page in the admin list
const INVITE_CODES_ENABLED = false; // Require invite codes for public registration and enable invite management
const INVITE_CODE_LIMIT = 3; // Number of invite codes a user may have generated before replacements become available
const INVITE_WAIT_PERIOD_MONTHS = 1; // Months to wait after account creation and invite redemption
const INVITE_CODE_EXPIRATION_MONTHS = 6; // Months after which an invite code expires and is removed from the database
const DEAD_MAN_SWITCH_ENABLED = false; // Enable staged inactivity notifications
const DEAD_MAN_SWITCH_MAILBOX = 'admin@example.com'; // Mailbox whose account activity resets the switch
const DEAD_MAN_SWITCH_TRUSTED_CONTACTS = ['trusted@example.com', 'trusted2@example.com']; // Email addresses of trusted contacts to be notified
const DEAD_MAN_SWITCH_CUSTOMER_CONTACTS = ['customer@example.com', 'customer2@example.com']; // Customer email addresses to be notified
const DEAD_MAN_SWITCH_STAGES = [
1 => [
'after' => 24 * 60 * 60,
'recipients' => [ DEAD_MAN_SWITCH_MAILBOX ],
'subject' => 'Dead man switch: please check in',
'body' => "No account activity has been recorded for 24 hours. Please sign in to your monitored mailbox to reset the dead man switch.\n",
],
2 => [
'after' => 48 * 60 * 60,
'recipients' => DEAD_MAN_SWITCH_TRUSTED_CONTACTS,
'subject' => 'Dead man switch: please contact me',
'body' => "No account activity has been recorded for 48 hours. Please try to contact me directly. If I am okay, signing in to " . DEAD_MAN_SWITCH_MAILBOX . " will reset the switch.\n",
],
3 => [
'after' => 72 * 60 * 60,
'recipients' => DEAD_MAN_SWITCH_TRUSTED_CONTACTS,
'subject' => 'Dead man switch: project handover instructions',
'body' => "No account activity has been recorded for 72 hours. The following are my instructions for taking over my projects:\n\nEDIT_ME\n",
],
4 => [
'after' => 96 * 60 * 60,
'recipients' => DEAD_MAN_SWITCH_CUSTOMER_CONTACTS,
'subject' => 'Important: your contact has changed',
'body' => "I have been unavailable for an extended period and something may have happened to me. For ongoing matters, please contact EDIT_ME.\n",
],
];
const LANGUAGES = [
'cs' => ['name' => 'čeština', 'locale' => 'cs_CZ', 'flag' => '🇨🇿', 'show_in_menu' => true, 'dir' => 'ltr'],
@@ -111,6 +147,56 @@ function generate_feedback_id( PDO $db ): string
return $feedback_id;
}
function get_user_invite_status( PDO $db, string $username ): array
{
if ( ! INVITE_CODES_ENABLED || INVITE_CODE_LIMIT <= 0 ) {
return [ 'available' => 0, 'eligible' => false ];
}
$stmt = $db->prepare( 'SELECT created <= DATE_SUB(NOW(), INTERVAL ' . (int) INVITE_WAIT_PERIOD_MONTHS . ' MONTH) FROM mailbox WHERE username = ? AND active = 1;' );
$stmt->execute( [ $username ] );
$eligible = (bool) $stmt->fetchColumn();
if ( $eligible === false ) {
return [ 'available' => 0, 'eligible' => false ];
}
$stmt = $db->prepare( 'SELECT COUNT(*), SUM(redeemed_at <= DATE_SUB(NOW(), INTERVAL ' . (int) INVITE_WAIT_PERIOD_MONTHS . ' MONTH)) FROM invite_codes WHERE generated_by = ?;' );
$stmt->execute( [ $username ] );
$counts = $stmt->fetch( PDO::FETCH_NUM );
$total = (int) $counts[ 0 ];
$matured_redemptions = (int) ( $counts[ 1 ] ?? 0 );
return [
'available' => $eligible ? max( 0, INVITE_CODE_LIMIT + $matured_redemptions - $total ) : 0,
'eligible' => $eligible,
];
}
function create_user_invite_code( PDO $db, string $username ): ?string
{
if ( ! INVITE_CODES_ENABLED || INVITE_CODE_LIMIT <= 0 ) {
return null;
}
$status = get_user_invite_status( $db, $username );
if( ! $status[ 'eligible' ] || $status[ 'available' ] <= 0 ) {
return null;
}
$code = bin2hex( random_bytes( 24 ) );
$stmt = $db->prepare( 'INSERT INTO invite_codes (code, generated_by, created_at) VALUES (?, ?, NOW());' );
$stmt->execute( [ $code, $username ] );
return $code;
}
function create_admin_invite_code( PDO $db, string $admin ): ?string
{
if ( ! INVITE_CODES_ENABLED ) {
return null;
}
$code = bin2hex( random_bytes( 24 ) );
$stmt = $db->prepare( 'INSERT INTO invite_codes (code, generated_by_admin, created_at) VALUES (?, ?, NOW());' );
$stmt->execute( [ $code, $admin ] );
return $code;
}
function get_db_instance(): PDO
{
static $db = null;
+1
View File
@@ -4,6 +4,7 @@
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-openssl": "*",
"ext-redis": "*",
"ext-gnupg": "*",
"ext-gettext": "*",
"ext-intl": "*",
+12
View File
@@ -4,6 +4,7 @@ if ( php_sapi_name() !== 'cli' ) {
}
require_once 'common_config.php';
require_once 'tools/sync_rspamd_dkim_keys.php';
$db = get_db_instance();
try {
$db_prosody = new PDO( 'mysql:host=' . DBHOST_PROSODY . ';dbname=' . DBNAME_PROSODY, DBUSER_PROSODY, DBPASS_PROSODY, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ] );
@@ -84,5 +85,16 @@ while ( $tmp = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
$del_domain->execute( [ $tmp[ 'domain' ] ] );
}
}
// delete expired invite codes
$db->exec( 'DELETE FROM invite_codes WHERE created_at <= DATE_SUB(NOW(), INTERVAL ' . (int) INVITE_CODE_EXPIRATION_MONTHS . ' MONTH);' );
// delete squirrelmail attachments older than an hour
exec( 'find /var/local/squirrelmail/attach/ -type f -cmin +60 -delete' );
try {
$count = sync_rspamd_dkim_keys( $db );
echo sprintf( "Synchronized %d DKIM signing keys to Redis.\n", $count );
} catch ( PDOException | RuntimeException $exception ) {
error_log( 'Failed to synchronize DKIM signing keys: ' . $exception->getMessage() );
echo _('Error synchronizing DKIM signing keys:') . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
}
require_once __DIR__ . '/tools/dead_man_switch.php';
+4 -4
View File
@@ -28,13 +28,13 @@ server {
add_header Cross-Origin-Opener-Policy same-origin always;
add_header Cross-Origin-Resource-Policy same-origin always;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
expires off;
}
location ~ \.php$ {
add_header Referrer-Policy no-referrer always;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
expires off;
}
}
@@ -74,7 +74,7 @@ server {
add_header Cross-Origin-Opener-Policy same-origin always;
add_header Cross-Origin-Resource-Policy same-origin always;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
expires off;
}
location ~ \.php$ {
@@ -82,7 +82,7 @@ server {
add_header Onion-Location http://danielas3rtn54uwmofdo3x2bsdifr47huasnmbgqzfrec5ubupvtpid.onion$request_uri always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
expires off;
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ server {
rewrite /.well-known/openpgpkey/(.*)/hu /mail/openpgpkey_wkd.php?domain=$1 last;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
expires off;
}
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
+6 -2
View File
@@ -1,4 +1,8 @@
sign_authenticated = true;
sign_local = true;
signing_table = "https://mail.danwin1210.de/rspamd_dkim_keys.php?token=CHANGE_ME_TO_A_LONG_RANDOM_SECRET";
key_table = "https://mail.danwin1210.de/rspamd_dkim_keys.php?token=CHANGE_ME_TO_A_LONG_RANDOM_SECRET";
sign_inbound = true;
use_domain = "header";
use_domain_sign_inbound = "recipient";
use_redis = true;
key_prefix = "dkim_keys";
selector_prefix = "dkim_selectors";
+3 -3
View File
@@ -3,7 +3,7 @@ use_domain_sign_networks = "header";
use_domain_sign_local = "header";
allow_username_mismatch = true;
allow_hdrfrom_mismatch = true;
try_fallback = false;
sign_headers = "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:resent-to:resent-cc:resent-from:resent-sender:resent-message-id:(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:list-unsubscribe-post:list-subscribe:list-post:(x)openpgp:(x)autocrypt:feedback-id";
signing_table = "https://mail.danwin1210.de/rspamd_dkim_keys.php?token=CHANGE_ME_TO_A_LONG_RANDOM_SECRET";
key_table = "https://mail.danwin1210.de/rspamd_dkim_keys.php?token=CHANGE_ME_TO_A_LONG_RANDOM_SECRET";
use_redis = true;
key_prefix = "dkim_keys";
selector_prefix = "dkim_selectors";
+5 -2
View File
@@ -65,8 +65,6 @@ rspamd_config:register_symbol{
end,
}
rspamd_config:register_dependency('DKIM_SIGNED', 'GOOGLE_FEEDBACK_ID')
rspamd_config:register_symbol{
name = 'ONION_SENDER_RECIPIENT_POLICY',
type = 'prefilter',
@@ -129,6 +127,11 @@ rspamd_config:register_symbol{
return
end
local ip = task:get_ip()
if ip and ip:is_local() then
return
end
local spf_allowed = task:get_symbol('R_SPF_ALLOW') ~= nil
local dmarc_allowed = task:get_symbol('DMARC_POLICY_ALLOW') ~= nil
local dkim_allowed = task:get_symbol('R_DKIM_ALLOW') ~= nil
+9 -9
View File
@@ -8,10 +8,10 @@ workingdir=$(pwd)
# install all required packages
DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y apt-transport-tor bash-completion bind9 ca-certificates clamav-daemon clamav-freshclam curl dovecot-imapd dovecot-lmtpd dovecot-managesieved dovecot-mysql dovecot-pop3d dovecot-sieve git gnupg haveged iptables libnginx-mod-http-brotli-filter libsasl2-modules locales locales-all logrotate lsb-release lua-dbi-mysql lua-event lua-unbound mariadb-server mercurial nano nginx openssl patch php8.2-cli php8.2-curl php8.2-fpm php8.2-gd php8.2-gmp php8.2-gnupg php8.2-imap php8.2-intl php8.2-mbstring php8.2-mysql php8.2-pspell php8.2-readline php8.2-tidy php8.2-uuid php8.2-xml php8.2-zip postfix postfix-mysql prosody redis rng-tools5 rspamd tor vim wget unzip wireguard wireguard-tools
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y apt-transport-tor bash-completion bind9 ca-certificates clamav-daemon clamav-freshclam curl dovecot-imapd dovecot-lmtpd dovecot-managesieved dovecot-mysql dovecot-pop3d dovecot-sieve git gnupg haveged iptables libnginx-mod-http-brotli-filter libsasl2-modules locales locales-all logrotate lsb-release lua-dbi-mysql lua-event lua-unbound mariadb-server mercurial nano nginx openssl patch php8.5-cli php8.5-curl php8.5-fpm php8.5-gd php8.5-gmp php8.5-gnupg php8.5-imap php8.5-intl php8.5-mbstring php8.5-mysql php8.5-pspell php8.5-readline php8.5-redis php8.5-tidy php8.5-uuid php8.5-xml php8.5-zip postfix postfix-mysql prosody redis rng-tools5 rspamd tor vim wget unzip wireguard wireguard-tools
# install composer
curl -sSL https://github.com/composer/composer/releases/download/2.8.3/composer.phar > /usr/bin/composer
curl -sSL https://github.com/composer/composer/releases/download/2.10.3/composer.phar > /usr/bin/composer
chmod +x /usr/bin/composer
composer self-update
@@ -64,7 +64,7 @@ if [ ! -e /var/www/mail/www/squirrelmail ]; then
git clone https://github.com/RealityRipple/squirrelmail .
mkdir -p /var/local/squirrelmail/data /var/local/squirrelmail/attach
chown www-data:www-data -R /var/local/squirrelmail
cd $workingdir
cd "$workingdir"
cp squirrelmail_config.php /var/www/mail/www/squirrelmail/config/config.php
else
cd /var/www/mail/www/squirrelmail
@@ -77,7 +77,7 @@ if [ ! -e /var/www/mail/www/squirrelmail/plugins/check_quota/ ]; then
wget https://www.squirrelmail.org/plugins/check_quota-2.2-1.4.0.tar.gz
tar -zxf check_quota-2.2-1.4.0.tar.gz
rm check_quota-2.2-1.4.0.tar.gz
cd $workingdir
cd "$workingdir"
cp squirrelmail_plugin_hooks.php /var/www/mail/www/squirrelmail/config/plugin_hooks.php
patch -p1 -d /var/www/html/mail/squirrelmail/plugins/check_quota/ < squirrelmail_check_quota.patch
fi
@@ -87,8 +87,8 @@ mkdir -p /var/www/mail/www/snappymail
cd /var/www/mail/www/snappymail
VERSION=$(curl -s https://api.github.com/repos/the-djmaze/snappymail/releases/latest | grep tag_name | cut -d '"' -f 4)
wget https://github.com/the-djmaze/snappymail/releases/download/${VERSION}/snappymail-${VERSION:1}.zip
unzip -o snappymail-${VERSION:1}.zip
rm snappymail-${VERSION:1}.zip
unzip -o "snappymail-${VERSION:1}.zip"
rm "snappymail-${VERSION:1}.zip"
mkdir -p /var/local/snappymail
chown www-data:www-data -R /var/local/snappymail
if [ ! -e include.php ]; then
@@ -103,8 +103,8 @@ mkdir -p /srv/conversejs
cd /srv/conversejs
VERSION=$(curl -s https://api.github.com/repos/conversejs/converse.js/releases/latest | grep tag_name | cut -d '"' -f 4)
wget https://github.com/conversejs/converse.js/releases/download/${VERSION}/converse.js-${VERSION:1}.tgz
tar xzf converse.js-${VERSION:1}.tgz --strip-components=1
rm converse.js-${VERSION:1}.tgz
tar xzf "converse.js-${VERSION:1}.tgz" --strip-components=1
rm "converse.js-${VERSION:1}.tgz"
rm -f /etc/nginx/sites-enabled/default
@@ -117,7 +117,7 @@ else
fi
# copy configuration file
cd $workingdir
cd "$workingdir"
if [ ! -e /var/www/mail/common_config.php ]; then
cp common_config.php /var/www/mail/
else
+2 -4
View File
@@ -8,10 +8,8 @@ DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y bash-completion bind9 ca-certificates coturn curl git gnupg haveged iptables libnginx-mod-stream libnginx-mod-http-brotli-filter libsasl2-modules logrotate lsb-release nano nginx openssl postfix postfix-mysql postfix-mta-sts-resolver rng-tools5 vim wget wireguard wireguard-tools
# dhparams
for file in /etc/nginx/dh4096.pem; do
if [ ! -e "$file" ]; then
openssl dhparam -out "$file" 4096
if [ ! -e "/etc/nginx/dh4096.pem" ]; then
openssl dhparam -out "/etc/nginx/dh4096.pem" 4096
fi
done
rm -f /etc/nginx/sites-enabled/default
+2 -1
View File
@@ -3,7 +3,7 @@ if(!extension_loaded('gettext')){
die('The gettext extension of PHP is required. Please install it first.' . PHP_EOL);
}
require('common_config.php');
foreach(['pdo_mysql', 'mbstring', 'pcre', 'gnupg', 'intl', 'openssl'] as $required_extension) {
foreach(['pdo_mysql', 'mbstring', 'pcre', 'gnupg', 'intl', 'openssl', 'redis'] as $required_extension) {
if ( ! extension_loaded( $required_extension ) ) {
die( sprintf( _( 'The %s extension of PHP is required. Please install it first.' ), $required_extension ) . PHP_EOL );
}
@@ -30,6 +30,7 @@ $createTableStatements = [
'alias' => "CREATE TABLE IF NOT EXISTS `alias` (`address` varchar(255) NOT NULL, `goto` text NOT NULL, `domain` varchar(255) NOT NULL, `created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `active` tinyint(1) NOT NULL DEFAULT 1, `enforce_tls_in` tinyint(1) NOT NULL DEFAULT 1, `identity` varchar(255) DEFAULT NULL, PRIMARY KEY (`address`), KEY `domain` (`domain`), KEY `active` (`active`), KEY `identity` (`identity`), CONSTRAINT `alias_ibfk_1` FOREIGN KEY (`domain`) REFERENCES `domain` (`domain`) ON UPDATE CASCADE, CONSTRAINT `alias_identity_ibfk_1` FOREIGN KEY (`identity`) REFERENCES `mailbox` (`username`) ON DELETE CASCADE ON UPDATE CASCADE) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
'alias_domain' => "CREATE TABLE IF NOT EXISTS `alias_domain` (`alias_domain` varchar(255) NOT NULL DEFAULT '', `target_domain` varchar(255) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `active` tinyint(1) NOT NULL DEFAULT 1, PRIMARY KEY (`alias_domain`), KEY `active` (`active`), KEY `target_domain` (`target_domain`)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
'captcha' => "CREATE TABLE IF NOT EXISTS `captcha` (`id` bigint(20) NOT NULL AUTO_INCREMENT, `time` int(11) NOT NULL, `code` char(5) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;",
'invite_codes' => "CREATE TABLE IF NOT EXISTS `invite_codes` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `code` varchar(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, `generated_by` varchar(255) DEFAULT NULL, `generated_by_admin` varchar(255) DEFAULT NULL, `created_at` datetime NOT NULL, `redeemed_by` varchar(255) DEFAULT NULL, `redeemed_at` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), KEY `generated_by_redeemed_at` (`generated_by`,`redeemed_at`), KEY `generated_by_admin` (`generated_by_admin`), KEY `redeemed_by` (`redeemed_by`)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
'dmarc_report' => "CREATE TABLE IF NOT EXISTS `dmarc_report` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `report_id` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `org_name` varchar(255) NOT NULL, `begin` datetime NOT NULL, `end` datetime NOT NULL, `domain` varchar(255) NOT NULL, `adkim` char(1) NOT NULL, `aspf` char(1) NOT NULL, `policy` varchar(10) NOT NULL, `subdomain_policy` varchar(10) NOT NULL, `pct` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `report_id_org_name` (`report_id`,`org_name`), KEY `begin_end` (`begin`,`end`), KEY `domain` (`domain`), CONSTRAINT `dmarc_report_ibfk_1` FOREIGN KEY (`domain`) REFERENCES `domain` (`domain`) ON DELETE CASCADE) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
'dmarc_report_errors' => "CREATE TABLE IF NOT EXISTS `dmarc_report_errors` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `report_id` bigint(20) unsigned NOT NULL, `error` text NOT NULL, PRIMARY KEY (`id`), KEY `report_id` (`report_id`), CONSTRAINT `dmarc_report_errors_ibfk_1` FOREIGN KEY (`id`) REFERENCES `dmarc_report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
'dmarc_report_records' => "CREATE TABLE IF NOT EXISTS `dmarc_report_records` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `report_id` bigint(20) unsigned NOT NULL, `source_ip` varchar(255) NOT NULL, `count` int(11) NOT NULL, `policy_evaluated_disposition` varchar(10) NOT NULL, `policy_evaluated_dkim` char(4) NOT NULL, `policy_evaluated_spf` char(4) NOT NULL, `identifier_envelope_to` varchar(255) NOT NULL, `identifier_envelope_from` varchar(255) NOT NULL, `identifier_header_from` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `report_id` (`report_id`), CONSTRAINT `dmarc_report_records_ibfk_2` FOREIGN KEY (`report_id`) REFERENCES `dmarc_report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
+83
View File
@@ -0,0 +1,83 @@
<?php
require_once __DIR__ . '/../common_config.php';
if ( ! DEAD_MAN_SWITCH_ENABLED ) {
return;
}
function dead_man_switch_validate_email( string $email ): void
{
if ( filter_var( $email, FILTER_VALIDATE_EMAIL ) === false ) {
throw new RuntimeException( sprintf( _('Invalid email address in dead man switch configuration: %s'), $email ) );
}
}
dead_man_switch_validate_email( DEAD_MAN_SWITCH_MAILBOX );
if ( empty(DEAD_MAN_SWITCH_TRUSTED_CONTACTS) ) {
throw new RuntimeException( _('At least one trusted contact must be configured.') );
}
foreach ( DEAD_MAN_SWITCH_TRUSTED_CONTACTS as $contact ) {
dead_man_switch_validate_email( $contact );
}
foreach ( DEAD_MAN_SWITCH_CUSTOMER_CONTACTS as $customer ) {
dead_man_switch_validate_email( $customer );
}
$db = get_db_instance();
$stmt = $db->prepare( 'SELECT `last_login`, UNIX_TIMESTAMP(`created`) AS `created_at` FROM `mailbox` WHERE `username` = ? AND `active` = 1;' );
$stmt->execute( [ DEAD_MAN_SWITCH_MAILBOX ] );
$monitored_mailbox = $stmt->fetch( PDO::FETCH_ASSOC );
if ( ! $monitored_mailbox ) {
throw new RuntimeException( sprintf( _('The configured dead man switch mailbox does not exist or is inactive: %s'), DEAD_MAN_SWITCH_MAILBOX ) );
}
$last_activity = (int) ( $monitored_mailbox['last_login'] ?? $monitored_mailbox['created_at'] );
$settings_key = 'dead_man_switch';
$stmt = $db->prepare( 'SELECT `value` FROM `settings` WHERE `setting` = ?;' );
$stmt->execute( [ $settings_key ] );
$stored_state = $stmt->fetchColumn();
if ( $stored_state === false ) {
$state = [
'mailbox' => DEAD_MAN_SWITCH_MAILBOX,
'last_activity' => $last_activity,
'notified_stage' => 0,
'last_run' => 0,
];
} else {
$state = json_decode( $stored_state, true, 512, JSON_THROW_ON_ERROR );
if ( !is_array($state) || $state['mailbox'] !== DEAD_MAN_SWITCH_MAILBOX || $state['last_activity'] !== $last_activity ) {
$state = [
'mailbox' => DEAD_MAN_SWITCH_MAILBOX,
'last_activity' => $last_activity,
'notified_stage' => 0,
'last_run' => 0,
];
}
}
$notified_stage = $state['notified_stage'];
$elapsed = time() - $last_activity;
$stage = $notified_stage + 1;
$notification = DEAD_MAN_SWITCH_STAGES[$stage] ?? null;
$stage_interval = $notification !== null && $stage > 1
? $notification['after'] - DEAD_MAN_SWITCH_STAGES[$notified_stage]['after']
: 0;
if (
$notification !== null
&& $elapsed >= $notification['after']
&& ( $state['last_run'] === 0 || time() - $state['last_run'] >= $stage_interval )
) {
foreach ( $notification['recipients'] as $recipient ) {
if ( ! mail( $recipient, $notification['subject'], $notification['body'], "Content-Type: text/plain; charset=UTF-8\r\n" ) ) {
throw new RuntimeException( sprintf( _('Unable to send dead man switch notification to %s.'), $recipient ) );
}
}
$state['notified_stage'] = $stage;
$state['last_run'] = time();
}
$stmt = $db->prepare( 'INSERT INTO `settings` (`setting`, `value`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`);' );
$stmt->execute( [ $settings_key, json_encode( $state, JSON_THROW_ON_ERROR ) ] );
+75
View File
@@ -0,0 +1,75 @@
<?php
require_once __DIR__ . '/../common_config.php';
function sync_rspamd_dkim_keys( PDO $db ): int
{
if ( ! extension_loaded( 'redis' ) ) {
throw new RuntimeException( 'The php-redis extension is required to synchronize DKIM signing keys.' );
}
$stmt = $db->query( "SELECT domain, dkim_key, dkim_selector FROM `domain` WHERE active = 1 ORDER BY domain;" );
$domains = [];
while ( $domain = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
if ( empty($domain[ 'dkim_key' ]) || empty($domain[ 'dkim_selector' ]) || str_ends_with($domain['domain'], '.onion') ) {
continue;
}
$asciiDomain = idn_to_ascii( $domain[ 'domain' ], IDNA_NONTRANSITIONAL_TO_ASCII );
if ( ! is_string( $asciiDomain ) || ! preg_match( '/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/iD', $asciiDomain ) ) {
throw new RuntimeException( 'Invalid domain configured for DKIM signing: ' . $domain[ 'domain' ] );
}
$asciiDomain = strtolower( $asciiDomain );
if ( isset( $domains[ $asciiDomain ] ) ) {
throw new RuntimeException( 'Duplicate ASCII domain configured for DKIM signing: ' . $asciiDomain );
}
$privateKey = openssl_pkey_get_private( $domain[ 'dkim_key' ] );
$keyDetails = $privateKey === false ? false : openssl_pkey_get_details( $privateKey );
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/D', $domain[ 'dkim_selector' ] ) || $keyDetails === false || $keyDetails[ 'type' ] !== OPENSSL_KEYTYPE_RSA ) {
throw new RuntimeException( 'Invalid DKIM signing selector or private key for domain: ' . $asciiDomain );
}
$domains[ $asciiDomain ] = [
'key' => $domain[ 'dkim_key' ],
'selector' => $domain[ 'dkim_selector' ],
];
}
$redis = new Redis();
try {
if ( ! $redis->connect( RSPAMD_REDIS_HOST, RSPAMD_REDIS_PORT, 3.0 ) ) {
throw new RuntimeException( 'Could not connect to Rspamd Redis.' );
}
if ( ! $redis->setOption( Redis::OPT_READ_TIMEOUT, 5.0 ) ) {
throw new RuntimeException( 'Could not set the Redis read timeout.' );
}
if ( $redis->multi() === false ) {
throw new RuntimeException( 'Redis did not start the DKIM key synchronization transaction.' );
}
$redis->del( 'dkim_keys', 'dkim_selectors' );
foreach ( $domains as $domain => $signingKey ) {
$redis->hSet( 'dkim_keys', $signingKey[ 'selector' ] . '.' . $domain, $signingKey[ 'key' ] );
$redis->hSet( 'dkim_selectors', $domain, $signingKey[ 'selector' ] );
}
$results = $redis->exec();
if ( ! is_array( $results ) || count( $results ) !== 1 + ( count( $domains ) * 2 ) || array_filter( $results, 'is_int' ) !== $results ) {
throw new RuntimeException( 'Redis did not complete DKIM key synchronization.' );
}
} catch ( RedisException $exception ) {
throw new RuntimeException( 'Failed to synchronize DKIM signing keys with Redis: ' . $exception->getMessage(), 0, $exception );
} finally {
$redis->close();
}
return count( $domains );
}
if ( PHP_SAPI === 'cli' && realpath( $_SERVER[ 'SCRIPT_FILENAME' ] ?? '' ) === __FILE__ ) {
try {
$count = sync_rspamd_dkim_keys( get_db_instance() );
echo sprintf( "Synchronized %d DKIM signing keys to Redis.\n", $count );
} catch ( PDOException | RuntimeException $exception ) {
fwrite( STDERR, 'Failed to synchronize DKIM signing keys: ' . $exception->getMessage() . PHP_EOL );
exit( 1 );
}
}
+190 -20
View File
@@ -4,6 +4,7 @@ use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailParser;
require_once( '../common_config.php' );
require_once( __DIR__ . '/../tools/sync_rspamd_dkim_keys.php' );
global $language, $dir, $locale;
session_start();
if ( empty( $_SESSION[ 'csrf_token' ] ) ) {
@@ -108,7 +109,14 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Invalid TOTP code')).'</div>';
}
} elseif ( ! empty( $_SESSION[ 'email_admin_user' ] ) ) {
if ( $_POST[ 'action' ] === 'update_alias' ) {
if ( INVITE_CODES_ENABLED && $_POST[ 'action' ] === 'create_admin_invite_code' ) {
$invite_code = create_admin_invite_code( $db, $_SESSION[ 'email_admin_user' ] );
if( $invite_code === null ) {
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Unable to create invite code.')).'</div>';
} else {
$msg .= '<div class="green" role="status">'.sprintf(htmlspecialchars(_('Invite code created: %s')), '<code>'.htmlspecialchars( $invite_code ).'</code>').'</div>';
}
} elseif ( $_POST[ 'action' ] === 'update_alias' ) {
$alias_goto = '';
if ( isset( $_POST[ 'alias_keep_copy' ] ) ) {
$alias_goto .= $_SESSION[ 'email_admin_user' ] . ',';
@@ -270,6 +278,7 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
$stmt = $db->prepare( 'UPDATE domain SET dkim_key = ?, dkim_selector = ?, modified = NOW() WHERE domain = ?;' );
$stmt->execute( [ $dkim[ 'key' ], $dkim[ 'selector' ], $_POST[ 'domain' ] ] );
$msg .= '<div class="green" role="alert">'.htmlspecialchars(_('Successfully regenerated DKIM key.')).'</div>';
$msg .= sync_admin_dkim_keys_alert();
} catch ( RuntimeException $exception ) {
error_log( 'Failed to regenerate DKIM key for ' . $_POST[ 'domain' ] . ': ' . $exception->getMessage() );
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Unable to generate a new DKIM key.')).'</div>';
@@ -285,8 +294,9 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
$stmt = $db->prepare( 'UPDATE domain SET active = ?, modified = NOW() WHERE domain = ?;' );
$stmt->execute( [ $active, $_POST[ 'domain' ] ] );
$msg .= '<div class="green" role="alert">'.htmlspecialchars(_('Successfully updated domain.')).'</div>';
$msg .= sync_admin_dkim_keys_alert();
}
} elseif ( $_POST[ 'action' ] === 'save_edit_alis_domain' && ! empty( $_POST[ 'alias_domain' ] ) && $_SESSION[ 'email_admin_superadmin' ] ) {
} elseif ( $_POST[ 'action' ] === 'save_edit_alias_domain' && ! empty( $_POST[ 'alias_domain' ] ) && $_SESSION[ 'email_admin_superadmin' ] ) {
$stmt = $db->prepare( 'SELECT null FROM alias_domain WHERE alias_domain = ?;' );
$stmt->execute( [ $_POST[ 'alias_domain' ] ] );
if ( ! $stmt->fetch() ) {
@@ -321,6 +331,7 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
$stmt->execute( [ $ascii_domain, $utf8_domain ] );
}
$msg .= '<div class="green" role="alert">'.htmlspecialchars(_('Successfully created domain.')).'</div>';
$msg .= sync_admin_dkim_keys_alert();
}
}
} elseif ( $_POST[ 'action' ] === 'save_new_alias_domain' && ! empty( $_POST[ 'alias_domain' ] ) && $_SESSION[ 'email_admin_superadmin' ] ) {
@@ -519,6 +530,9 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
?> | <a href="?action=admins"><?php echo htmlspecialchars(_('Manage admins')); ?></a><?php
?> | <a href="?action=alias_domains"><?php echo htmlspecialchars(_('Manage alias domains')); ?></a><?php
}
if ( INVITE_CODES_ENABLED ) {
?> | <a href="?action=invite_codes"><?php echo htmlspecialchars(_('Manage invite codes')); ?></a><?php
}
?> | <a href="?action=edit_admin"><?php echo htmlspecialchars(_('Manage your admin account')); ?></a><?php
?> | <a href="?action=domains"><?php echo htmlspecialchars(_('Manage domains')); ?></a><?php
?> | <a href="?action=alias"><?php echo htmlspecialchars(_('Manage aliases')); ?></a><?php
@@ -533,7 +547,7 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
<input type="hidden" name="action" value="verify_admin_totp">
<div class="row">
<div class="col"><label for="totp_code"><?php echo htmlspecialchars(_('Authentication code')); ?></label></div>
<div class="col"><input type="text" name="totp_code" id="totp_code" inputmode="numeric" pattern="[0-9]{6}" autocomplete="one-time-code" required></div>
<div class="col"><input type="text" name="totp_code" id="totp_code" inputmode="numeric" pattern="[0-9]{6}" autocomplete="one-time-code" required autofocus></div>
</div>
<button type="submit"><?php echo htmlspecialchars(_('Confirm')); ?></button>
</form>
@@ -542,7 +556,7 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<div class="row">
<div class="col"><label for="user"><?php echo htmlspecialchars(_('Username')); ?></label></div>
<div class="col"><input type="text" name="user" id="user" autocomplete="username" required></div>
<div class="col"><input type="text" name="user" id="user" autocomplete="username" required autofocus></div>
</div>
<div class="row">
<div class="col"><label for="pwd"><?php echo htmlspecialchars(_('Password')); ?></label></div>
@@ -558,6 +572,8 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
<?php } else {
if ( empty( $_REQUEST[ 'action' ] ) || in_array( $_REQUEST[ 'action' ], [ 'login', 'verify_admin_totp' ], true ) ) {
?><p><?php echo htmlspecialchars(_('Welcome to the admin management interface. You can configure your domain(s) and accounts here. Please select an option from the menu.')); ?></p><?php
} elseif ( INVITE_CODES_ENABLED && in_array( $_REQUEST[ 'action' ], [ 'invite_codes', 'create_admin_invite_code' ], true ) ) {
send_manage_invite_codes();
} elseif ( in_array( $_REQUEST[ 'action' ], [ 'admins', 'delete_admin2' ], true ) && $_SESSION[ 'email_admin_superadmin' ] ) {
send_manage_admins();
} elseif ( in_array( $_REQUEST[ 'action' ], [ 'domains', 'delete_domain2' ], true ) ) {
@@ -598,18 +614,110 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
<?php
function sync_admin_dkim_keys_alert(): string
{
try {
sync_rspamd_dkim_keys( get_db_instance() );
return '';
} catch ( PDOException | RuntimeException $exception ) {
error_log( 'Failed to synchronize DKIM signing keys after domain update: ' . $exception->getMessage() );
return '<div class="red" role="alert">' . htmlspecialchars(_('The domain was saved, but DKIM keys could not be synchronized to Redis. The scheduled sync will retry.')) . '</div>';
}
}
function send_manage_invite_codes(): void
{
if ( ! INVITE_CODES_ENABLED ) {
return;
}
$db = get_db_instance();
$page = get_admin_list_page();
$search = get_admin_list_search();
$offset = ( $page - 1 ) * ADMIN_LIST_PAGE_SIZE;
$search_pattern = $search !== '' ? '%' . $search . '%' : null;
$search_clause = $search !== '' ? ' WHERE code LIKE :code_search OR generated_by LIKE :user_search OR generated_by_admin LIKE :admin_search OR redeemed_by LIKE :redeemed_search' : '';
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM invite_codes' . $search_clause . ';' );
if ( $search_pattern !== null ) {
$countStmt->execute( [
'code_search' => $search_pattern,
'user_search' => $search_pattern,
'admin_search' => $search_pattern,
'redeemed_search' => $search_pattern,
] );
} else {
$countStmt->execute();
}
$total = (int) $countStmt->fetchColumn();
$totalPages = max( 1, (int) ceil( $total / ADMIN_LIST_PAGE_SIZE ) );
$stmt = $db->prepare( 'SELECT code, generated_by, generated_by_admin, created_at, redeemed_by, redeemed_at FROM invite_codes' . $search_clause . ' ORDER BY created_at DESC, id DESC LIMIT :limit OFFSET :offset;' );
if ( $search_pattern !== null ) {
$stmt->bindValue( ':code_search', $search_pattern, PDO::PARAM_STR );
$stmt->bindValue( ':user_search', $search_pattern, PDO::PARAM_STR );
$stmt->bindValue( ':admin_search', $search_pattern, PDO::PARAM_STR );
$stmt->bindValue( ':redeemed_search', $search_pattern, PDO::PARAM_STR );
}
$stmt->bindValue( ':limit', ADMIN_LIST_PAGE_SIZE, PDO::PARAM_INT );
$stmt->bindValue( ':offset', $offset, PDO::PARAM_INT );
$stmt->execute();
?>
<h2><?php echo htmlspecialchars(_('Invite codes')); ?></h2>
<?php render_admin_search( 'invite_codes', $search ); ?>
<form class="form_limit" action="admin.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<button name="action" value="create_admin_invite_code" type="submit"><?php echo htmlspecialchars(_('Generate invite code')); ?></button>
</form>
<?php
while ( $invite = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
$creator = $invite[ 'generated_by' ] ?? $invite[ 'generated_by_admin' ];
?>
<p><code><?php echo htmlspecialchars( $invite[ 'code' ] ); ?></code> —
<?php echo htmlspecialchars(_('Created by')); ?> <?php echo htmlspecialchars( $creator ); ?> (<?php echo htmlspecialchars( $invite[ 'created_at' ] ); ?>)
<?php if ( $invite[ 'redeemed_by' ] !== null ) { ?>
— <?php echo htmlspecialchars(_('Used by')); ?> <?php echo htmlspecialchars( $invite[ 'redeemed_by' ] ); ?> (<?php echo htmlspecialchars( $invite[ 'redeemed_at' ] ); ?>)
<?php } else { ?>
— <?php echo htmlspecialchars(_('Not yet used')); ?>
<?php } ?>
</p>
<?php
}
render_admin_pagination( 'invite_codes', $page, $totalPages, $search );
}
function get_admin_list_page(): int
{
$page = isset( $_GET[ 'page' ] ) ? (int) $_GET[ 'page' ] : 1;
return max( 1, $page );
}
function render_admin_pagination( string $action, int $page, int $totalPages ): void
function get_admin_list_search(): string
{
return is_string( $_GET[ 'search' ] ?? null ) ? trim( $_GET[ 'search' ] ) : '';
}
function render_admin_search( string $action, string $search ): void
{
?>
<form action="admin.php" method="get">
<input type="hidden" name="action" value="<?php echo htmlspecialchars( $action ); ?>">
<label for="list_search"><?php echo htmlspecialchars(_('Search')); ?></label>
<input type="search" name="search" id="list_search" value="<?php echo htmlspecialchars( $search ); ?>">
<button type="submit"><?php echo htmlspecialchars(_('Search')); ?></button>
<?php if ( $search !== '' ) { ?>
<a href="?action=<?php echo rawurlencode( $action ); ?>"><?php echo htmlspecialchars(_('Clear search')); ?></a>
<?php } ?>
</form>
<?php
}
function render_admin_pagination( string $action, int $page, int $totalPages, string $search = '' ): void
{
if ( $totalPages <= 1 ) {
return;
}
$base = '?action=' . rawurlencode( $action );
if ( $search !== '' ) {
$base .= '&search=' . rawurlencode( $search );
}
echo '<div class="row">';
if ( $page > 1 ) {
echo '<a href="' . $base . '&page=' . ( $page - 1 ) . '">' . htmlspecialchars( _('Previous') ) . '</a> ';
@@ -631,15 +739,28 @@ function send_manage_admins(): void
{
$db = get_db_instance();
$page = get_admin_list_page();
$search = get_admin_list_search();
$offset = ( $page - 1 ) * ADMIN_LIST_PAGE_SIZE;
$total = (int) $db->query( 'SELECT COUNT(*) FROM admin;' )->fetchColumn();
$search_pattern = $search !== '' ? '%' . $search . '%' : null;
$search_clause = $search !== '' ? ' WHERE username LIKE :search' : '';
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM admin' . $search_clause . ';' );
if ( $search_pattern !== null ) {
$countStmt->execute( [ 'search' => $search_pattern ] );
} else {
$countStmt->execute();
}
$total = (int) $countStmt->fetchColumn();
$totalPages = max( 1, (int) ceil( $total / ADMIN_LIST_PAGE_SIZE ) );
$stmt = $db->prepare( 'SELECT username, modified, active FROM admin ORDER BY username LIMIT :limit OFFSET :offset;' );
$stmt = $db->prepare( 'SELECT username, modified, active FROM admin' . $search_clause . ' ORDER BY username LIMIT :limit OFFSET :offset;' );
if ( $search_pattern !== null ) {
$stmt->bindValue( ':search', $search_pattern, PDO::PARAM_STR );
}
$stmt->bindValue( ':limit', ADMIN_LIST_PAGE_SIZE, PDO::PARAM_INT );
$stmt->bindValue( ':offset', $offset, PDO::PARAM_INT );
$stmt->execute();
?>
<p><a href="?action=new_admin"><?php echo htmlspecialchars(_('Create new admin')); ?></a></p>
<?php render_admin_search( 'admins', $search ); ?>
<form class="form_limit" action="admin.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<input type="hidden" name="action" value="edit_admin">
@@ -657,7 +778,7 @@ function send_manage_admins(): void
?></form>
<p><a href="?action=new_admin"><?php echo htmlspecialchars(_('Create new admin')); ?></a></p>
<?php
render_admin_pagination( 'admins', $page, $totalPages );
render_admin_pagination( 'admins', $page, $totalPages, $search );
}
function send_edit_admin(): void
@@ -823,10 +944,22 @@ function send_manage_domains(): void
{
$db = get_db_instance();
$page = get_admin_list_page();
$search = get_admin_list_search();
$offset = ( $page - 1 ) * ADMIN_LIST_PAGE_SIZE;
$total = (int) $db->query( 'SELECT COUNT(*) FROM domain;' )->fetchColumn();
$search_pattern = $search !== '' ? '%' . $search . '%' : null;
$search_clause = $search !== '' ? ' WHERE domain LIKE :search' : '';
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM domain' . $search_clause . ';' );
if ( $search_pattern !== null ) {
$countStmt->execute( [ 'search' => $search_pattern ] );
} else {
$countStmt->execute();
}
$total = (int) $countStmt->fetchColumn();
$totalPages = max( 1, (int) ceil( $total / ADMIN_LIST_PAGE_SIZE ) );
$stmt = $db->prepare( 'SELECT domain, modified, active FROM domain ORDER BY domain LIMIT :limit OFFSET :offset;' );
$stmt = $db->prepare( 'SELECT domain, modified, active FROM domain' . $search_clause . ' ORDER BY domain LIMIT :limit OFFSET :offset;' );
if ( $search_pattern !== null ) {
$stmt->bindValue( ':search', $search_pattern, PDO::PARAM_STR );
}
$stmt->bindValue( ':limit', ADMIN_LIST_PAGE_SIZE, PDO::PARAM_INT );
$stmt->bindValue( ':offset', $offset, PDO::PARAM_INT );
$stmt->execute();
@@ -834,6 +967,7 @@ function send_manage_domains(): void
?>
<p><a href="?action=new_domain"><?php echo htmlspecialchars(_('Create new domain')); ?></a></p>
<?php } ?>
<?php render_admin_search( 'domains', $search ); ?>
<form class="form_limit" action="admin.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<input type="hidden" name="action" value="edit_domain">
@@ -858,7 +992,7 @@ function send_manage_domains(): void
<p><a href="?action=new_domain"><?php echo htmlspecialchars(_('Create new domain')); ?></a></p>
<?php
}
render_admin_pagination( 'domains', $page, $totalPages );
render_admin_pagination( 'domains', $page, $totalPages, $search );
}
function send_new_domain(): void
@@ -948,10 +1082,23 @@ function send_manage_alias_domains(): void
{
$db = get_db_instance();
$page = get_admin_list_page();
$search = get_admin_list_search();
$offset = ( $page - 1 ) * ADMIN_LIST_PAGE_SIZE;
$total = (int) $db->query( 'SELECT COUNT(*) FROM alias_domain;' )->fetchColumn();
$search_pattern = $search !== '' ? '%' . $search . '%' : null;
$search_clause = $search !== '' ? ' WHERE alias_domain LIKE :alias_search OR target_domain LIKE :target_search' : '';
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM alias_domain' . $search_clause . ';' );
if ( $search_pattern !== null ) {
$countStmt->execute( [ 'alias_search' => $search_pattern, 'target_search' => $search_pattern ] );
} else {
$countStmt->execute();
}
$total = (int) $countStmt->fetchColumn();
$totalPages = max( 1, (int) ceil( $total / ADMIN_LIST_PAGE_SIZE ) );
$stmt = $db->prepare( 'SELECT alias_domain, target_domain, modified, active FROM alias_domain ORDER BY alias_domain LIMIT :limit OFFSET :offset;' );
$stmt = $db->prepare( 'SELECT alias_domain, target_domain, modified, active FROM alias_domain' . $search_clause . ' ORDER BY alias_domain LIMIT :limit OFFSET :offset;' );
if ( $search_pattern !== null ) {
$stmt->bindValue( ':alias_search', $search_pattern, PDO::PARAM_STR );
$stmt->bindValue( ':target_search', $search_pattern, PDO::PARAM_STR );
}
$stmt->bindValue( ':limit', ADMIN_LIST_PAGE_SIZE, PDO::PARAM_INT );
$stmt->bindValue( ':offset', $offset, PDO::PARAM_INT );
$stmt->execute();
@@ -959,6 +1106,7 @@ function send_manage_alias_domains(): void
?>
<p><a href="?action=new_alias_domain"><?php echo htmlspecialchars(_('Create new alias domain')); ?></a></p>
<?php } ?>
<?php render_admin_search( 'alias_domains', $search ); ?>
<form class="form_limit" action="admin.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<input type="hidden" name="action" value="edit_alias_domain">
@@ -979,7 +1127,7 @@ function send_manage_alias_domains(): void
<p><a href="?action=new_alias_domain"><?php echo htmlspecialchars(_('Create new alias domain')); ?></a></p>
<?php
}
render_admin_pagination( 'alias_domains', $page, $totalPages );
render_admin_pagination( 'alias_domains', $page, $totalPages, $search );
}
function send_new_alias_domain(): void
@@ -1052,19 +1200,31 @@ function send_manage_aliases(): void
{
$db = get_db_instance();
$page = get_admin_list_page();
$search = get_admin_list_search();
$offset = ( $page - 1 ) * ADMIN_LIST_PAGE_SIZE;
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM alias AS a LEFT JOIN mailbox AS m ON (m.username=a.address AND m.active=1) WHERE a.domain IN (SELECT domain FROM domain_admins WHERE username = :username) AND isnull(m.username) AND a.identity IS NULL;' );
$search_pattern = $search !== '' ? '%' . $search . '%' : null;
$search_clause = $search !== '' ? ' AND (a.address LIKE :address_search OR a.goto LIKE :goto_search)' : '';
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM alias AS a LEFT JOIN mailbox AS m ON (m.username=a.address AND m.active=1) WHERE a.domain IN (SELECT domain FROM domain_admins WHERE username = :username) AND isnull(m.username) AND a.identity IS NULL' . $search_clause . ';' );
$countStmt->bindValue( ':username', $_SESSION[ 'email_admin_user' ], PDO::PARAM_STR );
if ( $search_pattern !== null ) {
$countStmt->bindValue( ':address_search', $search_pattern, PDO::PARAM_STR );
$countStmt->bindValue( ':goto_search', $search_pattern, PDO::PARAM_STR );
}
$countStmt->execute();
$total = (int) $countStmt->fetchColumn();
$totalPages = max( 1, (int) ceil( $total / ADMIN_LIST_PAGE_SIZE ) );
$stmt = $db->prepare( 'SELECT a.address, a.goto, a.modified, a.active FROM alias AS a LEFT JOIN mailbox AS m ON (m.username=a.address AND m.active=1) WHERE a.domain IN (SELECT domain FROM domain_admins WHERE username = :username) AND isnull(m.username) AND a.identity IS NULL ORDER BY a.address LIMIT :limit OFFSET :offset;' );
$stmt = $db->prepare( 'SELECT a.address, a.goto, a.modified, a.active FROM alias AS a LEFT JOIN mailbox AS m ON (m.username=a.address AND m.active=1) WHERE a.domain IN (SELECT domain FROM domain_admins WHERE username = :username) AND isnull(m.username) AND a.identity IS NULL' . $search_clause . ' ORDER BY a.address LIMIT :limit OFFSET :offset;' );
$stmt->bindValue( ':username', $_SESSION[ 'email_admin_user' ], PDO::PARAM_STR );
if ( $search_pattern !== null ) {
$stmt->bindValue( ':address_search', $search_pattern, PDO::PARAM_STR );
$stmt->bindValue( ':goto_search', $search_pattern, PDO::PARAM_STR );
}
$stmt->bindValue( ':limit', ADMIN_LIST_PAGE_SIZE, PDO::PARAM_INT );
$stmt->bindValue( ':offset', $offset, PDO::PARAM_INT );
$stmt->execute();
?>
<p><a href="?action=new_alias"><?php echo htmlspecialchars(_('Create new alias')); ?></a></p>
<?php render_admin_search( 'alias', $search ); ?>
<form class="form_limit" action="admin.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<input type="hidden" name="action" value="edit_alias">
@@ -1086,7 +1246,7 @@ function send_manage_aliases(): void
?></form>
<p><a href="?action=new_alias"><?php echo htmlspecialchars(_('Create new alias')); ?></a></p>
<?php
render_admin_pagination( 'alias', $page, $totalPages );
render_admin_pagination( 'alias', $page, $totalPages, $search );
}
function send_new_alias(): void
@@ -1167,19 +1327,29 @@ function send_manage_mailboxes(): void
{
$db = get_db_instance();
$page = get_admin_list_page();
$search = get_admin_list_search();
$offset = ( $page - 1 ) * ADMIN_LIST_PAGE_SIZE;
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM mailbox WHERE domain IN (SELECT domain FROM domain_admins WHERE username = :username);' );
$search_pattern = $search !== '' ? '%' . $search . '%' : null;
$search_clause = $search !== '' ? ' AND username LIKE :search' : '';
$countStmt = $db->prepare( 'SELECT COUNT(*) FROM mailbox WHERE domain IN (SELECT domain FROM domain_admins WHERE username = :username)' . $search_clause . ';' );
$countStmt->bindValue( ':username', $_SESSION[ 'email_admin_user' ], PDO::PARAM_STR );
if ( $search_pattern !== null ) {
$countStmt->bindValue( ':search', $search_pattern, PDO::PARAM_STR );
}
$countStmt->execute();
$total = (int) $countStmt->fetchColumn();
$totalPages = max( 1, (int) ceil( $total / ADMIN_LIST_PAGE_SIZE ) );
$stmt = $db->prepare( 'SELECT username, modified, active FROM mailbox WHERE domain IN (SELECT domain FROM domain_admins WHERE username = :username) ORDER BY username LIMIT :limit OFFSET :offset;' );
$stmt = $db->prepare( 'SELECT username, modified, active FROM mailbox WHERE domain IN (SELECT domain FROM domain_admins WHERE username = :username)' . $search_clause . ' ORDER BY username LIMIT :limit OFFSET :offset;' );
$stmt->bindValue( ':limit', ADMIN_LIST_PAGE_SIZE, PDO::PARAM_INT );
$stmt->bindValue( ':offset', $offset, PDO::PARAM_INT );
$stmt->bindValue( ':username', $_SESSION[ 'email_admin_user' ], PDO::PARAM_STR );
if ( $search_pattern !== null ) {
$stmt->bindValue( ':search', $search_pattern, PDO::PARAM_STR );
}
$stmt->execute();
?>
<p><a href="?action=new_mailbox"><?php echo htmlspecialchars(_('Create new mailbox')); ?></a></p>
<?php render_admin_search( 'mailbox', $search ); ?>
<form class="form_limit" action="admin.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<input type="hidden" name="action" value="edit_mailbox">
@@ -1204,7 +1374,7 @@ function send_manage_mailboxes(): void
?></form>
<p><a href="?action=new_mailbox"><?php echo htmlspecialchars(_('Create new mailbox')); ?></a></p>
<?php
render_admin_pagination( 'mailbox', $page, $totalPages );
render_admin_pagination( 'mailbox', $page, $totalPages, $search );
}
function send_new_mailbox(): void
+43 -3
View File
@@ -106,6 +106,13 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) {
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Incorrect username or password')).'</div>';
}
}
} elseif ( INVITE_CODES_ENABLED && INVITE_CODE_LIMIT > 0 && ! empty( $_SESSION[ 'email_user' ] ) && $_POST[ 'action' ] === 'create_invite_code' ) {
$invite_code = create_user_invite_code( $db, $_SESSION[ 'email_user' ] );
if ( $invite_code === null ) {
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('No invite code is available yet. New accounts must wait before generating codes, and each used code can be replaced after the waiting period.')).'</div>';
} else {
$msg .= '<div class="green" role="status">'.sprintf(htmlspecialchars(_('Invite code created: %s')), '<code>'.htmlspecialchars( $invite_code ).'</code>').'</div>';
}
} elseif ( ! empty( $_SESSION[ 'email_user' ] ) && $_POST[ 'action' ] === 'update_settings' ) {
$alias_goto = '';
if ( isset( $_POST[ 'alias_keep_copy' ] ) ) {
@@ -310,7 +317,7 @@ if ( isset( $_SESSION[ 'user_totp_pending' ] ) ) {
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<div class="row">
<div class="col"><label for="totp_code"><?php echo htmlspecialchars(_('Authentication code')); ?></label></div>
<div class="col"><input type="text" name="totp_code" id="totp_code" inputmode="numeric" pattern="[0-9]{6}" autocomplete="one-time-code" required></div>
<div class="col"><input type="text" name="totp_code" id="totp_code" inputmode="numeric" pattern="[0-9]{6}" autocomplete="one-time-code" required autofocus></div>
</div>
<button type="submit"><?php echo htmlspecialchars(_('Confirm')); ?></button>
</form>
@@ -352,7 +359,7 @@ if ( isset( $_SESSION[ 'user_totp_pending' ] ) ) {
<form class="form_limit" action="manage_account.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<div class="row">
<div class="col"><input type="text" name="2fa_code" aria-label="<?php echo htmlspecialchars(_('2FA code')); ?>"></div>
<div class="col"><input type="text" name="2fa_code" aria-label="<?php echo htmlspecialchars(_('2FA code')); ?>" autofocus></div>
<div class="col">
<button type="submit"><?php echo htmlspecialchars(_('Confirm')); ?></button>
</div>
@@ -387,7 +394,7 @@ if ( empty( $_SESSION[ 'email_user' ] ) ) { ?>
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<div class="row">
<div class="col"><label for="user"><?php echo htmlspecialchars(_('Username')); ?></label></div>
<div class="col"><input type="text" name="user" id="user" autocomplete="username" required
<div class="col"><input type="text" name="user" id="user" autocomplete="username" required autofocus
value="<?php echo htmlspecialchars( $_POST[ 'user' ] ?? '' ); ?>"></div>
</div>
<div class="row">
@@ -450,6 +457,39 @@ if ( empty( $_SESSION[ 'email_user' ] ) ) { ?>
</div>
</form>
<?php if ( INVITE_CODES_ENABLED && INVITE_CODE_LIMIT > 0 ) {
$invite_status = get_user_invite_status( $db, $_SESSION[ 'email_user' ] );
$inviteStmt = $db->prepare( 'SELECT code, created_at, redeemed_by, redeemed_at FROM invite_codes WHERE generated_by = ? ORDER BY created_at DESC;' );
$inviteStmt->execute( [ $_SESSION[ 'email_user' ] ] );
?>
<h2><?php echo htmlspecialchars(_('Invite codes')); ?></h2>
<p><?php
if ( $invite_status[ 'available' ] > 0 ) {
printf( htmlspecialchars(_('You can create %d invite code(s).')), $invite_status[ 'available' ] );
} elseif ( ! $invite_status[ 'eligible' ] ) {
printf( htmlspecialchars(_('You can generate up to %d invite codes after your account has been active for %d month(s).')), INVITE_CODE_LIMIT, INVITE_WAIT_PERIOD_MONTHS );
} else {
printf( htmlspecialchars(_('You can create more invite codes %d month(s) after one of your existing codes is used.')), INVITE_WAIT_PERIOD_MONTHS );
}
?></p>
<?php if ( $invite_status[ 'available' ] > 0 ) { ?>
<form class="form_limit" action="manage_account.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
<button name="action" value="create_invite_code" type="submit"><?php echo htmlspecialchars(_('Generate invite code')); ?></button>
</form>
<?php }
while ( $invite = $inviteStmt->fetch( PDO::FETCH_ASSOC ) ) { ?>
<p><code><?php echo htmlspecialchars( $invite[ 'code' ] ); ?></code> —
<?php echo htmlspecialchars(_('Created')); ?>: <?php echo htmlspecialchars( $invite[ 'created_at' ] ); ?>
<?php if ( $invite[ 'redeemed_by' ] !== null ) { ?>
— <?php echo htmlspecialchars(_('Used by')); ?> <?php echo htmlspecialchars( $invite[ 'redeemed_by' ] ); ?> (<?php echo htmlspecialchars( $invite[ 'redeemed_at' ] ); ?>)
<?php } else { ?>
— <?php echo htmlspecialchars(_('Not yet used')); ?>
<?php } ?>
</p>
<?php } ?>
<?php } ?>
<h2><?php echo htmlspecialchars(_('Identity addresses')); ?></h2>
<p><?php echo htmlspecialchars(_('Identity addresses receive mail in this mailbox and can be used as a sender for this account. They must use your mailbox domain.')); ?></p>
<?php
+47 -1
View File
@@ -26,6 +26,20 @@ if ( isset( $_POST[ 'user' ] ) ) {
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Invalid captcha')).'</div>';
}
$db = get_db_instance();
$invite_code = is_string( $_POST[ 'invite_code' ] ?? null ) ? strtolower( trim( $_POST[ 'invite_code' ] ) ) : '';
if ( INVITE_CODES_ENABLED ) {
if ( $invite_code === '' ) {
$ok = false;
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('A valid invite code is required.')).'</div>';
} else {
$stmt = $db->prepare( 'SELECT code FROM invite_codes WHERE code = ? AND redeemed_by IS NULL;' );
$stmt->execute( [ $invite_code ] );
if ( ! $stmt->fetchColumn() ) {
$ok = false;
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('The invite code is invalid or has already been used.')).'</div>';
}
}
}
if ( ! preg_match( '/^([^+\/\'"]+?)(@([^@]+))?$/iu', $_POST[ 'user' ], $match ) ) {
$ok = false;
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Invalid username. It may not contain a +, \', " or /.')).'</div>';
@@ -67,17 +81,43 @@ if ( isset( $_POST[ 'user' ] ) ) {
}
if ( $ok ) {
$hash = password_hash( $_POST[ 'pwd' ], PASSWORD_ARGON2ID );
if ( INVITE_CODES_ENABLED ) {
$db->beginTransaction();
$stmt = $db->prepare( 'SELECT id FROM invite_codes WHERE code = ? AND redeemed_by IS NULL FOR UPDATE;' );
$stmt->execute( [ $invite_code ] );
$invite_id = $stmt->fetchColumn();
if ( ! $invite_id ) {
$db->rollBack();
$ok = false;
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('The invite code is invalid or has already been used.')).'</div>';
}
} else {
$db->beginTransaction();
}
}
if ( $ok ) {
$stmt = $db->prepare( 'INSERT INTO alias (address, goto, domain, created, modified) VALUES (?, ?, ?, NOW(), NOW());' );
$stmt->execute( [ "$user@$domain", "$user@$domain", $domain ] );
$stmt = $db->prepare( 'INSERT INTO mailbox (username, password, quota, local_part, domain, created, modified, password_hash_type, openpgpkey_wkd, feedback_id) VALUES(?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?);' );
$stmt->execute( [ "$user@$domain", $hash, DEFAULT_QUOTA, $user, $domain, '{ARGON2ID}', z_base32_encode( hash( 'sha1', mb_strtolower( $user ), true ) ), generate_feedback_id( $db ) ] );
if ( ! create_clearnet_onion_identity( $db, "$user@$domain", $msg ) ) {
$db->rollBack();
} else {
if ( INVITE_CODES_ENABLED ) {
$stmt = $db->prepare( 'UPDATE invite_codes SET redeemed_by = ?, redeemed_at = NOW() WHERE id = ? AND redeemed_by IS NULL;' );
$stmt->execute( [ "$user@$domain", $invite_id ] );
if ( $stmt->rowCount() !== 1 ) {
$db->rollBack();
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('The invite code is invalid or has already been used.')).'</div>';
} else {
$db->commit();
$msg .= '<div class="green" role="alert">'.htmlspecialchars(_('Successfully created new mailbox!')).'</div>';
}
} else {
$db->commit();
$msg .= '<div class="green" role="alert">'.htmlspecialchars(_('Successfully created new mailbox!')).'</div>';
}
}
}
}
}
@@ -112,8 +152,14 @@ if( ! REGISTRATION_ENABLED ) {
<form class="form_limit" action="register.php" method="post"><input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ] ?>">
<div class="row">
<div class="col"><label for="user"><?php echo htmlspecialchars(_('Username')); ?></label></div>
<div class="col"><input type="text" name="user" id="user" autocomplete="username" required value="<?php echo htmlspecialchars( $_POST[ 'user' ] ?? '' ); ?>"></div>
<div class="col"><input type="text" name="user" id="user" autocomplete="username" required value="<?php echo htmlspecialchars( $_POST[ 'user' ] ?? '' ); ?>" autofocus></div>
</div>
<?php if ( INVITE_CODES_ENABLED ) { ?>
<div class="row">
<div class="col"><label for="invite_code"><?php echo htmlspecialchars(_('Invite code')); ?></label></div>
<div class="col"><input type="text" name="invite_code" id="invite_code" autocomplete="off" required value="<?php echo htmlspecialchars( $_POST[ 'invite_code' ] ?? '' ); ?>"></div>
</div>
<?php } ?>
<div class="row">
<div class="col"><label for="pwd"><?php echo htmlspecialchars(_('Password')); ?></label></div>
<div class="col"><input type="password" name="pwd" id="pwd" autocomplete="new-password" required></div>
-32
View File
@@ -1,32 +0,0 @@
<?php
require_once( '../common_config.php' );
header( 'Content-Type: text/plain; charset=utf-8' );
header( 'Cache-Control: no-store' );
header( 'Expires: 600' );
$token = is_string( $_GET[ 'token' ] ?? null ) ? $_GET[ 'token' ] : '';
if ( ! in_array( $_SERVER[ 'REQUEST_METHOD' ], [ 'GET', 'HEAD' ], true ) || ! hash_equals( RSPAMD_SETTINGS_MAP_TOKEN, $token ) ) {
http_response_code( 403 );
exit;
}
$stmt = get_db_instance()->query( "SELECT domain, dkim_key, dkim_selector FROM domain WHERE active = 1 ORDER BY domain;" );
$map_entries = [];
while ( $domain = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
if(empty($domain['dkim_key']) || str_ends_with($domain['domain'], '.onion')) {
continue; // Skip domains without DKIM keys or onion domains
}
$ascii_domain = idn_to_ascii( $domain[ 'domain' ], IDNA_NONTRANSITIONAL_TO_ASCII );
$key = get_rsa_dkim_private_key_base64_der( $domain[ 'dkim_key' ] );
if ( ! is_string( $ascii_domain ) || ! preg_match( '/^[a-z0-9.-]+$/iD', $ascii_domain ) || $key === null || ! preg_match( '/^[a-zA-Z0-9_-]+$/D', $domain[ 'dkim_selector' ] ) ) {
http_response_code( 500 );
error_log( 'Invalid RSA DKIM key, selector, or domain configured for ' . $domain[ 'domain' ] );
exit;
}
$ascii_domain = mb_strtolower( $ascii_domain );
$map_entries[] = $ascii_domain . ' %:' . $domain[ 'dkim_selector' ] . ':' . $key;
$map_entries[] = '*@' . $ascii_domain . ' ' . $ascii_domain;
}
echo implode( "\n", $map_entries ) . ( $map_entries ? "\n" : '' );