Переглянути джерело

Add warnings for mailboxes overridden by redirects

ohartl 9 роки тому
батько
коміт
7090bef419

+ 4 - 0
include/css/style.css

@@ -278,6 +278,10 @@ body {
 			background-color: rgba(234, 234, 234, 1);
 		}
 
+		#content .table tbody > tr.warning {
+			background-color: #fcf897;
+		}
+
 		#content .table a {
 			color: rgb(148, 148, 255);
 		}

+ 1 - 1
include/php/global.inc.php

@@ -105,7 +105,7 @@ function stringToEmails($input)
 	$list = explode(
 		'|',
 		str_replace(
-			array(',', ';', "\r\n", "\r", "\n", '|', ':'),
+			array(' ', ',', ';', "\r\n", "\r", "\n", '|', ':'),
 			'|',
 			$input
 		)

+ 56 - 0
include/php/models/AbstractRedirect.php

@@ -14,6 +14,12 @@ abstract class AbstractRedirect extends AbstractModel
 	public static $idAttribute = DBC_ALIASES_ID;
 
 
+	/**
+	 * @var ModelCollection
+	 */
+	protected $conflictingUsers = null;
+
+
 	/**
 	 * @inheritdoc
 	 */
@@ -174,6 +180,56 @@ abstract class AbstractRedirect extends AbstractModel
 	}
 
 
+	/**
+	 * @return ModelCollection
+	 */
+	public function getConflictingUsers()
+	{
+		if(is_null($this->conflictingUsers)){
+			$sources = $this->getSource();
+
+			if(is_string($sources)){
+				$sources = array($sources);
+			}
+
+			$this->conflictingUsers = new ModelCollection();
+			foreach($sources as $source){
+				$user = User::findByEmail($source);
+				if(!is_null($user)){
+					$this->conflictingUsers->add($user);
+				}
+			}
+		}
+
+		return $this->conflictingUsers;
+	}
+
+
+	/**
+	 * @param string $template
+	 *
+	 * @return array|string
+	 */
+	public function getConflictingMarkedSource($template = "<u>%email%</u>")
+	{
+		$conflictingUsers = $this->getConflictingUsers();
+
+		$sources = $this->getSource();
+
+		if(is_string($sources)){
+			$sources = array($sources);
+		}
+
+		foreach($conflictingUsers as $user){
+			if(($key = array_search($user->getEmail(), $sources)) !== false){
+				$sources[$key] = str_replace('%email%', $sources[$key], $template);
+			}
+		}
+
+		return $sources;
+	}
+
+
 	/**
 	 * @inheritdoc
 	 */

+ 21 - 0
include/php/models/User.php

@@ -18,6 +18,12 @@ class User extends AbstractModel
 	const ROLE_ADMIN = 'admin';
 
 
+	/**
+	 * @var AbstractRedirect
+	 */
+	protected $conflictingRedirect = null;
+
+
 	/**
 	 * @inheritdoc
 	 */
@@ -190,6 +196,21 @@ class User extends AbstractModel
 	}
 
 
+	/**
+	 * @return AbstractRedirect
+	 */
+	public function getConflictingRedirect()
+	{
+		if(is_null($this->conflictingRedirect)){
+			$this->conflictingRedirect = AbstractRedirect::findWhereFirst(
+				array(DBC_ALIASES_SOURCE, $this->getEmail())
+			);
+		}
+
+		return $this->conflictingRedirect;
+	}
+
+
 	/**
 	 * Change this users password, throws Exception if password is invalid.
 	 *

+ 5 - 0
include/php/pages/admin/editredirect.php

@@ -225,6 +225,11 @@ if(isset($_GET['id'])){
 	<a class="button" href="<?php echo url('admin/listredirects'); ?>">&#10092; Back to redirects list</a>
 </div>
 
+<div class="notification">
+	Please note that mailservers will prefer to deliver mails to redirects over mailboxes.<br>
+	So make sure you don't accidentally override a mailbox with a redirect.
+</div>
+
 <?php output_messages(); ?>
 
 <form class="form" action="" method="post" autocomplete="off">

+ 12 - 7
include/php/pages/admin/listredirects.php

@@ -33,8 +33,13 @@ $redirects = AbstractRedirect::findMultiAll();
 	</thead>
 	<tbody>
 	<?php foreach($redirects as $redirect): /** @var AbstractRedirect $redirect */ ?>
-		<tr>
-			<td><?php echo formatEmails($redirect->getSource(), str_replace(PHP_EOL, '<br>', FRONTEND_EMAIL_SEPARATOR_TEXT)); ?></td>
+		<tr<?php echo $redirect->getConflictingUsers()->count() > 0 ? ' class="warning"' : ''; ?>>
+			<td>
+			<?php if($redirect->getConflictingUsers()->count() > 0): ?>
+				<strong><?php echo $redirect->getConflictingUsers()->count() === 1 ? 'The marked redirect overrides a mailbox.' : 'The marked redirects override mailboxes.'; ?></strong><br>
+			<?php endif; ?>
+				<?php echo formatEmails($redirect->getConflictingMarkedSource(), str_replace(PHP_EOL, '<br>', FRONTEND_EMAIL_SEPARATOR_TEXT)); ?>
+			</td>
 			<td><?php echo formatEmails($redirect->getDestination(), str_replace(PHP_EOL, '<br>', FRONTEND_EMAIL_SEPARATOR_TEXT)); ?></td>
 			<td>
 				<a href="<?php echo url('admin/editredirect/?id='.$redirect->getId()); ?>">[Edit]</a>
@@ -45,11 +50,11 @@ $redirects = AbstractRedirect::findMultiAll();
 		</tr>
 	<?php endforeach; ?>
 	</tbody>
-<?php if ($redirects->count() > 0): ?>
-		<tfoot>
+<?php if($redirects->count() > 0): ?>
+	<tfoot>
 		<tr>
-			<th><?php echo $redirects->count();?> Redirects</th>
+			<th><?php echo $redirects->count(); ?> Redirects</th>
 		</tr>
-		</tfoot>
-	<?php endif; ?>
+	</tfoot>
+<?php endif; ?>
 </table>

+ 7 - 2
include/php/pages/admin/listusers.php

@@ -40,8 +40,13 @@ $users = User::findAll();
 	</thead>
 	<tbody>
 	<?php foreach($users as $user): /** @var User $user */ ?>
-		<tr>
-			<td><?php echo$user->getUsername(); ?></td>
+		<tr<?php echo !is_null($user->getConflictingRedirect()) ? ' class="warning"' : ''; ?>>
+			<td>
+			<?php if(!is_null($user->getConflictingRedirect())): ?>
+				<strong>This mailbox is overridden by a redirect.</strong><br>
+			<?php endif; ?>
+				<?php echo $user->getUsername(); ?>
+			</td>
 			<td><?php echo $user->getDomain(); ?></td>
 		<?php if(defined('DBC_USERS_MAILBOXLIMIT')): ?>
 			<td style="text-align: right"><?php echo ($user->getMailboxLimit() > 0) ? $user->getMailboxLimit().' MB' : 'No limit'; ?></td>