From c35d47c6c6f11b6a44c8fe23b7f6522573810064 Mon Sep 17 00:00:00 2001 From: Daniel Winzen Date: Mon, 8 Jul 2024 15:28:04 +0200 Subject: [PATCH] Add setting for default quota --- common_config.php | 11 +++++++++++ www/admin.php | 6 ++---- www/index.php | 2 +- www/register.php | 4 ++-- www/terms.php | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common_config.php b/common_config.php index 18ab453..e305f13 100644 --- a/common_config.php +++ b/common_config.php @@ -27,6 +27,7 @@ const DBUSER_PROSODY = 'prosody'; // Database user const DBPASS_PROSODY = 'YOUR_PASSWORD'; // Database password const DBNAME_PROSODY = 'prosody'; // Database const REGISTRATION_ENABLED = true; // Whether registration is enabled +const DEFAULT_QUOTA = 50 * 1024 * 1024; // Default mailbox quota in bytes const LANGUAGES = [ 'cs' => ['name' => 'čeština', 'locale' => 'cs_CZ', 'flag' => '🇨🇿', 'show_in_menu' => true, 'dir' => 'ltr'], @@ -351,3 +352,13 @@ function alt_links(): void echo ''; } } + +function bytes_to_human_readable(int $bytes) : string { + $suffix = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; + $size_class=(int) log($bytes, 1024); + if($size_class!==0){ + return sprintf('%1.1f', $bytes / pow(1024, $size_class)) . $suffix[$size_class]; + }else{ + return $bytes . $suffix[0]; + } +} \ No newline at end of file diff --git a/www/admin.php b/www/admin.php index ecfddbc..8b92edb 100644 --- a/www/admin.php +++ b/www/admin.php @@ -289,12 +289,11 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) { $additional = preg_split( "/[\s,]+/", $_POST[ 'alias_to' ] ); $alias_goto .= validate_email_list( $additional, $msg ); } - $quota = 1024 * 1024 * 1024; $alias_goto = rtrim( $alias_goto, ',' ); $stmt = $db->prepare( 'UPDATE alias SET goto = ?, enforce_tls_in = ?, active = ? WHERE address = ?;' ); $stmt->execute( [ $alias_goto, ( isset( $_POST[ 'enforce_tls_in' ] ) ? 1 : 0 ), ( isset( $_POST[ 'active' ] ) ? 1 : 0 ), $_POST[ 'user' ] ] ); $stmt = $db->prepare( 'UPDATE mailbox SET enforce_tls_in = ?, enforce_tls_out = ?, active = ?, quota = ?, modified = NOW() WHERE username = ?;' ); - $stmt->execute( [ ( isset( $_POST[ 'enforce_tls_in' ] ) ? 1 : 0 ), ( isset( $_POST[ 'enforce_tls_out' ] ) ? 1 : 0 ), ( isset( $_POST[ 'active' ] ) ? 1 : 0 ), $quota, $_POST[ 'user' ] ] ); + $stmt->execute( [ ( isset( $_POST[ 'enforce_tls_in' ] ) ? 1 : 0 ), ( isset( $_POST[ 'enforce_tls_out' ] ) ? 1 : 0 ), ( isset( $_POST[ 'active' ] ) ? 1 : 0 ), DEFAULT_QUOTA, $_POST[ 'user' ] ] ); $msg .= ''; } } elseif ( $_POST[ 'action' ] === 'save_new_mailbox' && ! empty( $_POST[ 'user' ] ) ) { @@ -316,7 +315,6 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) { $user = $parser->getLocalPart(); $domain = $parser->getDomainPart(); $hash = password_hash( $_POST[ 'pwd' ], PASSWORD_ARGON2ID ); - $quota = 50 * 1024 * 1024; $alias_goto = ''; if ( isset( $_POST[ 'alias_keep_copy' ] ) ) { $alias_goto .= $email . ','; @@ -329,7 +327,7 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) { $stmt = $db->prepare( 'INSERT INTO alias (address, goto, domain, created, modified, enforce_tls_in, active) VALUES (?, ?, ?, NOW(), NOW(), ?, ?);' ); $stmt->execute( [ $email, $alias_goto, $domain, ( isset( $_POST[ 'enforce_tls_in' ] ) ? 1 : 0 ), ( isset( $_POST[ 'active' ] ) ? 1 : 0 ) ] ); $stmt = $db->prepare( 'INSERT INTO mailbox (username, password, quota, local_part, domain, created, modified, password_hash_type, openpgpkey_wkd, enforce_tls_in, enforce_tls_out, active) VALUES(?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?, ?, ?);' ); - $stmt->execute( [ $email, $hash, $quota, $user, $domain, '{ARGON2ID}', z_base32_encode( hash( 'sha1', mb_strtolower( $user ), true ) ), ( isset( $_POST[ 'enforce_tls_in' ] ) ? 1 : 0 ), ( isset( $_POST[ 'enforce_tls_out' ] ) ? 1 : 0 ), ( isset( $_POST[ 'active' ] ) ? 1 : 0 ) ] ); + $stmt->execute( [ $email, $hash, DEFAULT_QUOTA, $user, $domain, '{ARGON2ID}', z_base32_encode( hash( 'sha1', mb_strtolower( $user ), true ) ), ( isset( $_POST[ 'enforce_tls_in' ] ) ? 1 : 0 ), ( isset( $_POST[ 'enforce_tls_out' ] ) ? 1 : 0 ), ( isset( $_POST[ 'active' ] ) ? 1 : 0 ) ] ); $msg .= ''; } } diff --git a/www/index.php b/www/index.php index e33526c..57d8a2d 100644 --- a/www/index.php +++ b/www/index.php @@ -22,7 +22,7 @@ global $language, $dir, $locale;

| | | | |

-

'.htmlspecialchars(_('contact me')).'', CLEARNET_SERVER); ?>

+

'.htmlspecialchars(_('contact me')).'', CLEARNET_SERVER); ?>

'.htmlspecialchars(_('download GnuPG')).'', ''.htmlspecialchars(_('add it to your account')).''); ?>

'.htmlspecialchars(_('SquirrelMail')).'', ''.htmlspecialchars(_('SnappyMail')).''); ?>

diff --git a/www/register.php b/www/register.php index 880ae34..e0a070d 100644 --- a/www/register.php +++ b/www/register.php @@ -69,8 +69,8 @@ if ( isset( $_POST[ 'user' ] ) ) { $hash = password_hash( $_POST[ 'pwd' ], PASSWORD_ARGON2ID ); $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) VALUES(?, ?, 51200000, ?, ?, NOW(), NOW(), ?, ?);' ); - $stmt->execute( [ "$user@$domain", $hash, $user, $domain, '{ARGON2ID}', z_base32_encode( hash( 'sha1', mb_strtolower( $user ), true ) ) ] ); + $stmt = $db->prepare( 'INSERT INTO mailbox (username, password, quota, local_part, domain, created, modified, password_hash_type, openpgpkey_wkd) VALUES(?, ?, ?, ?, ?, NOW(), NOW(), ?, ?);' ); + $stmt->execute( [ "$user@$domain", $hash, DEFAULT_QUOTA, $user, $domain, '{ARGON2ID}', z_base32_encode( hash( 'sha1', mb_strtolower( $user ), true ) ) ] ); $msg .= ''; } } diff --git a/www/terms.php b/www/terms.php index c111191..e334679 100644 --- a/www/terms.php +++ b/www/terms.php @@ -29,7 +29,7 @@ global $language, $dir, $locale;
  • -
  • '.htmlspecialchars(_('contact me')).''); ?>
  • +
  • '.htmlspecialchars(_('contact me')).''); ?>