public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
[Web, Dovecot] Allow empty/unlimited quota
49492dff
data/web/edit.php | 3 ++-
data/web/inc/functions.inc.php | 8 ++++++++
data/web/inc/functions.mailbox.inc.php | 29 ++++++++---------------------
data/web/js/site/mailbox.js | 3 ++-
data/web/modals/mailbox.php | 4 ++--
5 files changed, 22 insertions(+), 25 deletions(-)
Diff
diff --git a/data/web/edit.php b/data/web/edit.php
index c44464df..9aa79269 100644
--- a/data/web/edit.php
+++ b/data/web/edit.php
@@ -521,7 +521,8 @@ if (isset($_SESSION['mailcow_cc_role'])) {
<br /><span id="quotaBadge" class="badge">max. <?=intval($result['max_new_quota'] / 1048576)?> MiB</span>
</label>
<div class="col-sm-10">
- <input type="number" name="quota" style="width:100%" min="1" max="<?=intval($result['max_new_quota'] / 1048576);?>" value="<?=intval($result['quota']) / 1048576;?>" class="form-control">
+ <input type="number" name="quota" style="width:100%" min="0" max="<?=intval($result['max_new_quota'] / 1048576);?>" value="<?=intval($result['quota']) / 1048576;?>" class="form-control">
+ <small class="help-block">0 = ∞</small>
</div>
</div>
<div class="form-group">
diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php
index c869c122..ebce5819 100644
--- a/data/web/inc/functions.inc.php
+++ b/data/web/inc/functions.inc.php
@@ -1,4 +1,12 @@
<?php
+function isset_has_content($var) {
+ if (isset($var) && $var != "") {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
function hash_password($password) {
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
return "{SSHA256}".base64_encode(hash('sha256', $password . $salt_str, true) . $salt_str);
diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php
index b9129f83..6ecb3a94 100644
--- a/data/web/inc/functions.mailbox.inc.php
+++ b/data/web/inc/functions.mailbox.inc.php
@@ -756,7 +756,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
$password = $_data['password'];
$password2 = $_data['password2'];
$name = ltrim(rtrim($_data['name'], '>'), '<');
- $quota_m = filter_var($_data['quota'], FILTER_SANITIZE_NUMBER_FLOAT);
+ $quota_m = intval($_data['quota']);
if (empty($name)) {
$name = $local_part;
}
@@ -844,14 +844,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
);
return false;
}
- if (!is_numeric($quota_m) || $quota_m == "0") {
- $_SESSION['return'][] = array(
- 'type' => 'danger',
- 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
- 'msg' => 'quota_not_0_not_numeric'
- );
- return false;
- }
if (!empty($password) && !empty($password2)) {
if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password)) {
$_SESSION['return'][] = array(
@@ -1993,9 +1985,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int'];
(int)$force_pw_update = (isset($_data['force_pw_update'])) ? intval($_data['force_pw_update']) : intval($is_now['attributes']['force_pw_update']);
(int)$sogo_access = (isset($_data['sogo_access'])) ? intval($_data['sogo_access']) : intval($is_now['attributes']['sogo_access']);
+ (int)$quota_m = (isset_has_content($_data['quota'])) ? intval($_data['quota']) : ($is_now['quota'] / 1048576);
$name = (!empty($_data['name'])) ? ltrim(rtrim($_data['name'], '>'), '<') : $is_now['name'];
$domain = $is_now['domain'];
- $quota_m = (!empty($_data['quota'])) ? $_data['quota'] : ($is_now['quota'] / 1048576);
$quota_b = $quota_m * 1048576;
$password = (!empty($_data['password'])) ? $_data['password'] : null;
$password2 = (!empty($_data['password2'])) ? $_data['password2'] : null;
@@ -2021,14 +2013,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
);
continue;
}
- if (!is_numeric($quota_m) || $quota_m == "0") {
- $_SESSION['return'][] = array(
- 'type' => 'danger',
- 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
- 'msg' => array('quota_not_0_not_numeric', htmlspecialchars($quota_m))
- );
- continue;
- }
if ($quota_m > $DomainData['maxquota']) {
$_SESSION['return'][] = array(
'type' => 'danger',
@@ -3016,15 +3000,18 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
$mailboxdata['quota'] = $row['quota'];
$mailboxdata['attributes'] = json_decode($row['attributes'], true);
$mailboxdata['quota_used'] = intval($row['bytes']);
- $mailboxdata['percent_in_use'] = round((intval($row['bytes']) / intval($row['quota'])) * 100);
+ $mailboxdata['percent_in_use'] = ($row['quota'] == 0) ? '- ' : round((intval($row['bytes']) / intval($row['quota'])) * 100);
$mailboxdata['messages'] = $row['messages'];
$mailboxdata['spam_aliases'] = $SpamaliasUsage['sa_count'];
- if ($mailboxdata['percent_in_use'] >= 90) {
- $mailboxdata['percent_class'] = "danger";
+ if ($mailboxdata['percent_in_use'] === '- ') {
+ $mailboxdata['percent_class'] = "info";
}
elseif ($mailboxdata['percent_in_use'] >= 75) {
$mailboxdata['percent_class'] = "warning";
}
+ elseif ($mailboxdata['percent_in_use'] >= 90) {
+ $mailboxdata['percent_class'] = "danger";
+ }
else {
$mailboxdata['percent_class'] = "success";
}
diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js
index f8aacac7..ba49892c 100644
--- a/data/web/js/site/mailbox.js
+++ b/data/web/js/site/mailbox.js
@@ -312,7 +312,8 @@ jQuery(function($){
{"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
{"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
res = value.split("/");
- return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
+ var of_q = (res[1] == 0 ? "∞" : humanFileSize(res[1]));
+ return humanFileSize(res[0]) + " / " + of_q;
},
"sortValue": function(value){
res = value.split("/");
diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php
index 11abbc58..aeb88cca 100644
--- a/data/web/modals/mailbox.php
+++ b/data/web/modals/mailbox.php
@@ -43,8 +43,8 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
<br /><span id="quotaBadge" class="badge">max. - MiB</span>
</label>
<div class="col-sm-10">
- <input type="text" class="form-control" name="quota" min="1" max="" id="addInputQuota" disabled value="<?=$lang['add']['select_domain'];?>" required>
- <small class="help-block">min. 1</small>
+ <input type="text" class="form-control" name="quota" min="0" max="" id="addInputQuota" disabled value="<?=$lang['add']['select_domain'];?>" required>
+ <small class="help-block">0 = ∞</small>
</div>
</div>
<div class="form-group">