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] Fix some transport verifications
79ab962d
data/web/admin.php | 2 +-
data/web/edit.php | 2 +-
data/web/inc/ajax/transport_check.php | 30 +++++++++++++++++++++++++++++-
data/web/inc/functions.transports.inc.php | 6 ++++++
4 files changed, 37 insertions(+), 3 deletions(-)
Diff
diff --git a/data/web/admin.php b/data/web/admin.php
index 9d6543fd..d8da73fe 100644
--- a/data/web/admin.php
+++ b/data/web/admin.php
@@ -272,7 +272,7 @@ if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CAC
<form class="form" data-id="rlyhost" role="form" method="post">
<div class="form-group">
<label for="hostname"><?=$lang['admin']['host'];?></label>
- <input class="form-control input-sm" name="hostname" placeholder='host:25, host, [host]:25, [0.0.0.0]:25' required>
+ <input class="form-control input-sm" name="hostname" placeholder='[0.0.0.0], [0.0.0.0]:25, host:25, host, [host]:25' required>
</div>
<div class="form-group">
<label for="username"><?=$lang['admin']['username'];?></label>
diff --git a/data/web/edit.php b/data/web/edit.php
index 7d3c60da..75eca4c4 100644
--- a/data/web/edit.php
+++ b/data/web/edit.php
@@ -843,7 +843,7 @@ if (isset($_SESSION['mailcow_cc_role'])) {
<div class="form-group">
<label class="control-label col-sm-2" for="nexthop"><?=$lang['edit']['nexthop'];?></label>
<div class="col-sm-10">
- <input type="text" class="form-control" name="nexthop" value="<?=htmlspecialchars($result['nexthop'], ENT_QUOTES, 'UTF-8');?>" required>
+ <input type="text" class="form-control" name="nexthop" placeholder='[0.0.0.0], [0.0.0.0]:25, host:25, host, [host]:25' value="<?=htmlspecialchars($result['nexthop'], ENT_QUOTES, 'UTF-8');?>" required>
</div>
</div>
<div class="form-group">
diff --git a/data/web/inc/ajax/transport_check.php b/data/web/inc/ajax/transport_check.php
index f959ee35..2eec022c 100644
--- a/data/web/inc/ajax/transport_check.php
+++ b/data/web/inc/ajax/transport_check.php
@@ -23,9 +23,37 @@ if (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == "admi
if (!empty($transport_details)) {
// Remove [ and ]
$hostname_w_port = preg_replace('/\[|\]/', '', $nexthop);
+ preg_match('/\[.+\](:.+)/', $nexthop, $hostname_port_match);
+ preg_match('/\[\d\.\d\.\d\.\d\](:.+)/', $nexthop, $ipv4_port_match);
+ $has_bracket_and_port = (isset($hostname_port_match[1])) ? true : false;
+ $is_ipv4_and_has_port = (isset($ipv4_port_match[1])) ? true : false;
$skip_lookup_mx = strpos($nexthop, '[');
// Explode to hostname and port
- list($hostname, $port) = explode(':', $hostname_w_port);
+ if ($has_bracket_and_port) {
+ $port = substr($hostname_w_port, strrpos($hostname_w_port, ':') + 1);
+ $hostname = rtrim($hostname_w_port, ':' . $port);
+ if (filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
+ $hostname = '[' . $hostname . ']:';
+ }
+ }
+ else {
+ if ($is_ipv4_and_has_port) {
+ $port = substr($hostname_w_port, strrpos($hostname_w_port, ':') + 1);
+ $hostname = rtrim($hostname_w_port, ':' . $port);
+ }
+ if (filter_var($hostname_w_port, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
+ $hostname = $hostname_w_port;
+ $port = null;
+ }
+ elseif (filter_var($hostname_w_port, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
+ $hostname = '[' . $hostname_w_port . ']';
+ $port = null;
+ }
+ else {
+ echo "Invalid transport";
+ die();
+ }
+ }
// Try to get MX if host is not [host]
if ($skip_lookup_mx === false) {
getmxrr($hostname, $mx_records, $mx_weight);
diff --git a/data/web/inc/functions.transports.inc.php b/data/web/inc/functions.transports.inc.php
index 95bc726d..e28b10a4 100644
--- a/data/web/inc/functions.transports.inc.php
+++ b/data/web/inc/functions.transports.inc.php
@@ -190,6 +190,9 @@ function transport($_action, $_data = null) {
$active = intval($_data['active']);
$lookup_mx = intval($_data['lookup_mx']);
$nexthop = trim($_data['nexthop']);
+ if (filter_var($nexthop, FILTER_VALIDATE_IP)) {
+ $nexthop = '[' . $nexthop . ']';
+ }
preg_match('/\[(.+)\].*/', $nexthop, $next_hop_matches);
$next_hop_clean = (isset($next_hop_matches[1])) ? $next_hop_matches[1] : $nexthop;
$username = str_replace(':', '\:', trim($_data['username']));
@@ -323,6 +326,9 @@ function transport($_action, $_data = null) {
continue;
}
preg_match('/\[(.+)\].*/', $nexthop, $next_hop_matches);
+ if (filter_var($nexthop, FILTER_VALIDATE_IP)) {
+ $nexthop = '[' . $nexthop . ']';
+ }
$next_hop_clean = (isset($next_hop_matches[1])) ? $next_hop_matches[1] : $nexthop;
$transports = transport('get');
if (!empty($transports)) {