[Web, Dovecot] Add sieve and pop3 to protocol access for app passwords

master
andryyy 2021-10-29 06:15:10 +02:00
parent 514340b2a7
commit 15ce95e78d
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
6 changed files with 27 additions and 7 deletions

View File

@ -164,9 +164,9 @@ function auth_password_verify(req, pass)
end end
-- check against app passwds for imap and smtp -- check against app passwds for imap and smtp
-- app passwords are only available for imap and smtp in dovecot -- app passwords are only available for imap, smtp, sieve and pop3 when using sasl
if req.service == "smtp" or req.service == "imap" then if req.service == "smtp" or req.service == "imap" or req.service == "sieve" or req.service == "pop3" then
local cur,errorString = con:execute(string.format([[SELECT app_passwd.id, app_passwd.imap_access, app_passwd.smtp_access, app_passwd.password FROM app_passwd local cur,errorString = con:execute(string.format([[SELECT app_passwd.id, app_passwd.imap_access, app_passwd.smtp_access, app_passwd.sieve_access, app_passwd.pop3_access, app_passwd.password FROM app_passwd
INNER JOIN mailbox ON mailbox.username = app_passwd.mailbox INNER JOIN mailbox ON mailbox.username = app_passwd.mailbox
WHERE mailbox = '%s' WHERE mailbox = '%s'
AND app_passwd.%s_access = '1' AND app_passwd.%s_access = '1'

View File

@ -32,6 +32,8 @@ function app_passwd($_action, $_data = null) {
$dav_access = (in_array('dav_access', $protocols)) ? 1 : 0; $dav_access = (in_array('dav_access', $protocols)) ? 1 : 0;
$smtp_access = (in_array('smtp_access', $protocols)) ? 1 : 0; $smtp_access = (in_array('smtp_access', $protocols)) ? 1 : 0;
$eas_access = (in_array('eas_access', $protocols)) ? 1 : 0; $eas_access = (in_array('eas_access', $protocols)) ? 1 : 0;
$pop3_access = (in_array('pop3_access', $protocols)) ? 1 : 0;
$sieve_access = (in_array('sieve_access', $protocols)) ? 1 : 0;
$domain = mailbox('get', 'mailbox_details', $username)['domain']; $domain = mailbox('get', 'mailbox_details', $username)['domain'];
if (empty($domain)) { if (empty($domain)) {
$_SESSION['return'][] = array( $_SESSION['return'][] = array(
@ -66,8 +68,8 @@ function app_passwd($_action, $_data = null) {
); );
return false; return false;
} }
$stmt = $pdo->prepare("INSERT INTO `app_passwd` (`name`, `mailbox`, `domain`, `password`, `imap_access`, `smtp_access`, `eas_access`, `dav_access`, `active`) $stmt = $pdo->prepare("INSERT INTO `app_passwd` (`name`, `mailbox`, `domain`, `password`, `imap_access`, `smtp_access`, `eas_access`, `dav_access`, `pop3_access`, `sieve_access`, `active`)
VALUES (:app_name, :mailbox, :domain, :password, :imap_access, :smtp_access, :eas_access, :dav_access, :active)"); VALUES (:app_name, :mailbox, :domain, :password, :imap_access, :smtp_access, :eas_access, :dav_access, :pop3_access, :sieve_access, :active)");
$stmt->execute(array( $stmt->execute(array(
':app_name' => $app_name, ':app_name' => $app_name,
':mailbox' => $username, ':mailbox' => $username,
@ -77,6 +79,8 @@ function app_passwd($_action, $_data = null) {
':smtp_access' => $smtp_access, ':smtp_access' => $smtp_access,
':eas_access' => $eas_access, ':eas_access' => $eas_access,
':dav_access' => $dav_access, ':dav_access' => $dav_access,
':pop3_access' => $pop3_access,
':sieve_access' => $sieve_access,
':active' => $active ':active' => $active
)); ));
$_SESSION['return'][] = array( $_SESSION['return'][] = array(
@ -99,12 +103,16 @@ function app_passwd($_action, $_data = null) {
$dav_access = (in_array('dav_access', $protocols)) ? 1 : 0; $dav_access = (in_array('dav_access', $protocols)) ? 1 : 0;
$smtp_access = (in_array('smtp_access', $protocols)) ? 1 : 0; $smtp_access = (in_array('smtp_access', $protocols)) ? 1 : 0;
$eas_access = (in_array('eas_access', $protocols)) ? 1 : 0; $eas_access = (in_array('eas_access', $protocols)) ? 1 : 0;
$pop3_access = (in_array('pop3_access', $protocols)) ? 1 : 0;
$sieve_access = (in_array('sieve_access', $protocols)) ? 1 : 0;
} }
else { else {
$imap_access = $is_now['imap_access']; $imap_access = $is_now['imap_access'];
$smtp_access = $is_now['smtp_access']; $smtp_access = $is_now['smtp_access'];
$dav_access = $is_now['dav_access']; $dav_access = $is_now['dav_access'];
$eas_access = $is_now['eas_access']; $eas_access = $is_now['eas_access'];
$pop3_access = $is_now['pop3_access'];
$sieve_access = $is_now['sieve_access'];
} }
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active']; $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active'];
} }
@ -152,6 +160,8 @@ function app_passwd($_action, $_data = null) {
`smtp_access` = :smtp_access, `smtp_access` = :smtp_access,
`eas_access` = :eas_access, `eas_access` = :eas_access,
`dav_access` = :dav_access, `dav_access` = :dav_access,
`pop3_access` = :pop3_access,
`sieve_access` = :sieve_access,
`active` = :active `active` = :active
WHERE `id` = :id"); WHERE `id` = :id");
$stmt->execute(array( $stmt->execute(array(
@ -161,6 +171,8 @@ function app_passwd($_action, $_data = null) {
':smtp_access' => $smtp_access, ':smtp_access' => $smtp_access,
':eas_access' => $eas_access, ':eas_access' => $eas_access,
':dav_access' => $dav_access, ':dav_access' => $dav_access,
':pop3_access' => $pop3_access,
':sieve_access' => $sieve_access,
':active' => $active, ':active' => $active,
':id' => $id ':id' => $id
)); ));

View File

@ -3,7 +3,7 @@ function init_db_schema() {
try { try {
global $pdo; global $pdo;
$db_version = "28102021_1600"; $db_version = "29102021_0620";
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'"); $stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@ -368,6 +368,8 @@ function init_db_schema() {
"smtp_access" => "TINYINT(1) NOT NULL DEFAULT '1'", "smtp_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
"dav_access" => "TINYINT(1) NOT NULL DEFAULT '1'", "dav_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
"eas_access" => "TINYINT(1) NOT NULL DEFAULT '1'", "eas_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
"pop3_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
"sieve_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
"active" => "TINYINT(1) NOT NULL DEFAULT '1'" "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
), ),
"keys" => array( "keys" => array(

View File

@ -277,7 +277,9 @@ jQuery(function($){
if (item.imap_access == 1) { item.protocols.push("<code>IMAP</code>"); } if (item.imap_access == 1) { item.protocols.push("<code>IMAP</code>"); }
if (item.smtp_access == 1) { item.protocols.push("<code>SMTP</code>"); } if (item.smtp_access == 1) { item.protocols.push("<code>SMTP</code>"); }
if (item.eas_access == 1) { item.protocols.push("<code>EAS/ActiveSync</code>"); } if (item.eas_access == 1) { item.protocols.push("<code>EAS/ActiveSync</code>"); }
if (item.dav_access == 1) { item.protocols.push("<code>DAV</kbd>"); } if (item.dav_access == 1) { item.protocols.push("<code>DAV</code>"); }
if (item.pop3_access == 1) { item.protocols.push("<code>POP3</code>"); }
if (item.sieve_access == 1) { item.protocols.push("<code>Sieve</code>"); }
item.protocols = item.protocols.join(" ") item.protocols = item.protocols.join(" ")
if (acl_data.app_passwds === 1) { if (acl_data.app_passwds === 1) {
item.action = '<div class="btn-group footable-actions">' + item.action = '<div class="btn-group footable-actions">' +

View File

@ -39,6 +39,8 @@
<option value="smtp_access" {% if result.smtp_access == 1 %} selected{% endif %}>SMTP</option> <option value="smtp_access" {% if result.smtp_access == 1 %} selected{% endif %}>SMTP</option>
<option value="eas_access" {% if result.eas_access == 1 %} selected{% endif %}>EAS/ActiveSync</option> <option value="eas_access" {% if result.eas_access == 1 %} selected{% endif %}>EAS/ActiveSync</option>
<option value="dav_access" {% if result.dav_access == 1 %} selected{% endif %}>CardDAV/CalDAV</option> <option value="dav_access" {% if result.dav_access == 1 %} selected{% endif %}>CardDAV/CalDAV</option>
<option value="pop3_access" {% if result.pop3_access == 1 %} selected{% endif %}>POP3</option>
<option value="sieve_access" {% if result.sieve_access == 1 %} selected{% endif %}>Sieve</option>
</select> </select>
</div> </div>
</div> </div>

View File

@ -221,6 +221,8 @@
<option value="smtp_access" selected>SMTP</option> <option value="smtp_access" selected>SMTP</option>
<option value="eas_access" selected>EAS/ActiveSync</option> <option value="eas_access" selected>EAS/ActiveSync</option>
<option value="dav_access" selected>CardDAV/CalDAV</option> <option value="dav_access" selected>CardDAV/CalDAV</option>
<option value="pop3_access" selected>POP3</option>
<option value="sieve_access" selected>Sieve</option>
</select> </select>
</div> </div>
</div> </div>