Compare commits
5
Commits
11fe088b64
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4464d0e66
|
||
|
|
778b3808a8
|
||
|
|
ea44183531
|
||
|
|
241b8d48fc
|
||
|
|
e8b44ac1a9
|
No files matched your search
@@ -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.
|
||||
|
||||
+85
-1
@@ -9,7 +9,7 @@ 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"
|
||||
@@ -40,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'],
|
||||
@@ -113,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;
|
||||
|
||||
@@ -85,6 +85,8 @@ 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 {
|
||||
@@ -95,3 +97,4 @@ try {
|
||||
echo _('Error synchronizing DKIM signing keys:') . PHP_EOL;
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
}
|
||||
require_once __DIR__ . '/tools/dead_man_switch.php';
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+9
-9
@@ -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-redis 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
|
||||
|
||||
@@ -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
|
||||
@@ -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;",
|
||||
|
||||
@@ -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 ) ] );
|
||||
+174
-19
@@ -109,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' ] . ',';
|
||||
@@ -523,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
|
||||
@@ -537,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>
|
||||
@@ -546,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>
|
||||
@@ -562,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 ) ) {
|
||||
@@ -613,18 +625,99 @@ function sync_admin_dkim_keys_alert(): string
|
||||
}
|
||||
}
|
||||
|
||||
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> ';
|
||||
@@ -646,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">
|
||||
@@ -672,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
|
||||
@@ -838,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();
|
||||
@@ -849,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">
|
||||
@@ -873,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
|
||||
@@ -963,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();
|
||||
@@ -974,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">
|
||||
@@ -994,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
|
||||
@@ -1067,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">
|
||||
@@ -1101,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
|
||||
@@ -1182,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">
|
||||
@@ -1219,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
@@ -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
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user