Minor and temp. workaround for panel

master
andryyy 2017-04-23 19:37:45 +02:00
parent 686df83a34
commit 53b6662aea
3 changed files with 59 additions and 156 deletions

View File

@ -1,91 +0,0 @@
#!/bin/bash
# Postfix smtp_tls_security_level should be set to "may" to try an
# encrypted connection.
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
# Find script directory and move to base directory of mailcow-dockerized
# so docker-compose is executed from the right location
DIR=$(echo $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | sed 's/data\/misc.*//')
cd $DIR
if [[ ${1} == "reset" ]]; then
# Reset modified values to their defaults
sed -i "s/^relayhost\ \=.*/relayhost\ \=/" data/conf/postfix/main.cf
sed -i "s/^smtp\_sasl\_password\_maps.*/smtp\_sasl\_password\_maps\ \=/" data/conf/postfix/main.cf
sed -i "s/^smtp\_sasl\_security\_options.*/smtp\_sasl\_security\_options\ \=\ noplaintext\,\ noanonymous/" data/conf/postfix/main.cf
sed -i "s/^smtp\_sasl\_auth\_enable.*/smtp\_sasl\_auth\_enable\ \=\ no/" data/conf/postfix/main.cf
# Also delete the plaintext password file
rm -f data/conf/postfix/smarthost_passwd*
docker-compose exec postfix-mailcow postfix reload
# Exit last exit code
exit $?
elif [[ ${1} == "restore-string" ]]; then
# Set parameter value of smtp_sasl_password_maps
SMTPSASLPWDMAP="data/conf/postfix/smarthost_passwd"
# Get parameter value of relayhost
RELAYHOSTCFG=$(grep "relayhost\ =" data/conf/postfix/main.cf | awk '{print $3}')
# Exit if empty/unset
[[ -z ${RELAYHOSTCFG} ]] && exit 0
# Replace ':' by ' ' (white space)
RELAYHOSTCFG=${RELAYHOSTCFG//\:/ }
# Replace '[' by '' (empty)
RELAYHOSTCFG=${RELAYHOSTCFG//\[/}
# Replace ']' by '' (empty) and create array of result
RELAYHOSTCFGARR=(${RELAYHOSTCFG//\]/})
# Get 'username:password' from SASL password maps
# Grep relayhost without port and '[', ']' or ':' from SASL password map file without map type (e.g. 'hash:')
USRPWD=$(grep ${RELAYHOSTCFGARR[0]} $SMTPSASLPWDMAP | awk {'print $2'})
# Replace ':' by ' ' and create array of result
USRPWDARR=(${USRPWD//:/ })
# Echo script name, all values in RELAYHOSTCFGARR, first and second value in USRPWDARR
# Why?
# Host and port are required, so we can print the whole array RELAYHOSTCFGARR.
# Password might be empty, so we print them separately.
echo ${0} ${RELAYHOSTCFGARR[@]} \'${USRPWDARR[0]}\' \'${USRPWDARR[1]}\'
exit 0
elif [[ -z ${1} ]] || [[ -z ${2} ]]; then
# Exit with code 1 if host and port are missing
echo "Usage: ${0} relayhost port (username) (password)"
echo "Username and password are optional parameters."
exit 1
else
# Try a simple connection to host:port but don't recieve any data
# Abort after 3 seconds
if ! nc -z -v -w3 ${1} ${2} 2>/dev/null; then
echo "Connection to relayhost ${1} failed, aborting..."
exit 1
fi
# Use exact hostname as relayhost, don't lookup the MX record of relayhost
sed -i "s/relayhost\ \=.*/relayhost\ \=\ \[${1}\]\:${2}/" data/conf/postfix/main.cf
if grep -q "smtp_sasl_password_maps" data/conf/postfix/main.cf
then
sed -i "s/^smtp\_sasl\_password\_maps.*/smtp\_sasl\_password\_maps\ \=\ hash\:\/opt\/postfix\/conf\/smarthost\_passwd/" data/conf/postfix/main.cf
else
echo "smtp_sasl_password_maps = hash:/opt/postfix/conf/smarthost_passwd" >> data/conf/postfix/main.cf
fi
if grep -q "smtp_sasl_auth_enable" data/conf/postfix/main.cf
then
sed -i "s/^smtp\_sasl\_auth\_enable.*/smtp\_sasl\_auth\_enable\ \=\ yes/" data/conf/postfix/main.cf
else
echo "smtp_sasl_auth_enable = yes" >> data/conf/postfix/main.cf
fi
if grep -q "smtp_sasl_security_options" data/conf/postfix/main.cf
then
sed -i "s/^smtp\_sasl\_security\_options.*/smtp\_sasl\_security\_options\ \=/" data/conf/postfix/main.cf
else
echo "smtp_sasl_security_options =" >> data/conf/postfix/main.cf
fi
if [[ ! -z ${3} ]]; then
echo ${1} ${3}:${4} > data/conf/postfix/smarthost_passwd
docker-compose exec postfix-mailcow postmap /opt/postfix/conf/smarthost_passwd
fi
docker-compose exec postfix-mailcow chown root:postfix /opt/postfix/conf/smarthost_passwd /opt/postfix/conf/smarthost_passwd.db
docker-compose exec postfix-mailcow chmod 660 /opt/postfix/conf/smarthost_passwd /opt/postfix/conf/smarthost_passwd.db
docker-compose exec postfix-mailcow postfix reload
exit $?
fi

View File

@ -183,11 +183,11 @@ $tfa_data = get_tfa();
</div> </div>
<h4><span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> <?=$lang['admin']['configuration'];?></h4> <h4><span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> <?=$lang['admin']['configuration'];?></h4>
<div class="panel-group" id="accordion_access"> <div class="panel-group" id="accordion_access">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><?=$lang['admin']['dkim_keys'];?></div> <div class="panel-heading"><?=$lang['admin']['dkim_keys'];?></div>
<div id="collapseDKIM" class="panel-collapse">
<div class="panel-body"> <div class="panel-body">
<p style="margin-bottom:40px"><?=$lang['admin']['dkim_key_hint'];?></p> <p style="margin-bottom:40px"><?=$lang['admin']['dkim_key_hint'];?></p>
<?php <?php
@ -299,78 +299,72 @@ $tfa_data = get_tfa();
</form> </form>
</div> </div>
</div> </div>
</div>
<div class="panel panel-default"> <div class="panel panel-default">
<div style="cursor:pointer;" class="panel-heading" data-toggle="collapse" data-parent="#accordion_access" data-target="#collapseForwardingHosts"> <div class="panel-heading"><?=$lang['admin']['forwarding_hosts'];?></div>
<span class="accordion-toggle"><?=$lang['admin']['forwarding_hosts'];?></span> <div class="panel-body">
</div> <p style="margin-bottom:40px"><?=$lang['admin']['forwarding_hosts_hint'];?></p>
<div id="collapseForwardingHosts" class="panel-collapse collapse"> <form method="post">
<div class="panel-body"> <div class="table-responsive">
<p style="margin-bottom:40px"><?=$lang['admin']['forwarding_hosts_hint'];?></p> <table class="table table-striped" id="forwardinghoststable">
<form method="post"> <thead>
<div class="table-responsive"> <tr>
<table class="table table-striped" id="forwardinghoststable"> <th style="min-width: 100px;"><?=$lang['edit']['host'];?></th>
<thead> <th style="min-width: 100px;"><?=$lang['edit']['source'];?></th>
<tr> <th style="text-align: right; min-width: 200px;"><?=$lang['admin']['action'];?></th>
<th style="min-width: 100px;"><?=$lang['edit']['host'];?></th> </tr>
<th style="min-width: 100px;"><?=$lang['edit']['source'];?></th> </thead>
<th style="text-align: right; min-width: 200px;"><?=$lang['admin']['action'];?></th> <tbody>
</tr> <?php
</thead> $forwarding_hosts = get_forwarding_hosts();
<tbody> if ($forwarding_hosts) {
<?php foreach ($forwarding_hosts as $host) {
$forwarding_hosts = get_forwarding_hosts(); $source = $host->source;
if ($forwarding_hosts) { $host = $host->host;
foreach ($forwarding_hosts as $host) {
$source = $host->source;
$host = $host->host;
?>
<tr id="data">
<td><?=htmlspecialchars(strtolower($host));?></td>
<td><?=htmlspecialchars(strtolower($source));?></td>
<td style="text-align: right;">
<div class="btn-group">
<a href="delete.php?forwardinghost=<?=$host;?>" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> <?=$lang['admin']['remove'];?></a>
</div>
</td>
</td>
</tr>
<?php
}
} else {
?> ?>
<tr id="no-data"><td colspan="4" style="text-align: center; font-style: italic;"><?=$lang['admin']['no_record'];?></td></tr> <tr id="data">
<td><?=htmlspecialchars(strtolower($host));?></td>
<td><?=htmlspecialchars(strtolower($source));?></td>
<td style="text-align: right;">
<div class="btn-group">
<a href="delete.php?forwardinghost=<?=$host;?>" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> <?=$lang['admin']['remove'];?></a>
</div>
</td>
</td>
</tr>
<?php <?php
} }
?> } else {
</tbody> ?>
</table> <tr id="no-data"><td colspan="4" style="text-align: center; font-style: italic;"><?=$lang['admin']['no_record'];?></td></tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>
<legend><?=$lang['admin']['add_forwarding_host'];?></legend>
<p class="help-block"><?=$lang['admin']['forwarding_hosts_add_hint'];?></p>
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label class="control-label col-sm-2" for="hostname"><?=$lang['edit']['host'];?>:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="hostname" id="hostname" required>
</div> </div>
</form> </div>
<small> <div class="form-group">
<legend><?=$lang['admin']['add_forwarding_host'];?></legend> <div class="col-sm-offset-2 col-sm-10">
<p style="margin-bottom:10px"><?=$lang['admin']['forwarding_hosts_add_hint'];?></p> <button type="submit" name="add_forwarding_host" class="btn btn-default"><?=$lang['admin']['add'];?></button>
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label class="control-label col-sm-2" for="hostname"><?=$lang['edit']['host'];?>:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="hostname" id="hostname" required>
</div>
</div> </div>
<div class="form-group"> </div>
<div class="col-sm-offset-2 col-sm-10"> </form>
<button type="submit" name="add_forwarding_host" class="btn btn-default"><?=$lang['admin']['add'];?></button>
</div>
</div>
</form>
</small>
</div>
</div>
</div> </div>
</div> </div>
</div>
</div> <!-- /container --> </div> <!-- /container -->
<script type='text/javascript'> <script type='text/javascript'>
<?php <?php

View File

@ -3,7 +3,7 @@ function init_db_schema() {
try { try {
global $pdo; global $pdo;
$db_version = "20042017_1926"; $db_version = "23042017_1807";
$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));