|
@@ -192,7 +192,7 @@ function transport($_action, $_data = null) {
|
|
|
}
|
|
|
$destinations = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['destination']));
|
|
|
$active = intval($_data['active']);
|
|
|
- $lookup_mx = intval($_data['lookup_mx']);
|
|
|
+ $is_mx_based = intval($_data['is_mx_based']);
|
|
|
$nexthop = trim($_data['nexthop']);
|
|
|
if (filter_var($nexthop, FILTER_VALIDATE_IP)) {
|
|
|
$nexthop = '[' . $nexthop . ']';
|
|
@@ -238,7 +238,16 @@ function transport($_action, $_data = null) {
|
|
|
continue;
|
|
|
}
|
|
|
// ".domain" is a valid destination, "..domain" is not
|
|
|
- if (empty($dest) || (is_valid_domain_name(preg_replace('/^' . preg_quote('.', '/') . '/', '', $dest)) === false && $dest != '*' && filter_var($dest, FILTER_VALIDATE_EMAIL) === false)) {
|
|
|
+ if ($is_mx_based == 0 && (empty($dest) || (is_valid_domain_name(preg_replace('/^' . preg_quote('.', '/') . '/', '', $dest)) === false && $dest != '*' && filter_var($dest, FILTER_VALIDATE_EMAIL) === false))) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
+ 'msg' => array('invalid_destination', $dest)
|
|
|
+ );
|
|
|
+ unset($destinations[$d_ix]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($is_mx_based == 1 && (empty($dest) || @preg_match('/' . $dest . '/', null) === false)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
@@ -275,14 +284,14 @@ function transport($_action, $_data = null) {
|
|
|
}
|
|
|
}
|
|
|
foreach ($destinations as $insert_dest) {
|
|
|
- $stmt = $pdo->prepare("INSERT INTO `transports` (`nexthop`, `destination`, `username` , `password`, `lookup_mx`, `active`)
|
|
|
- VALUES (:nexthop, :destination, :username, :password, :lookup_mx, :active)");
|
|
|
+ $stmt = $pdo->prepare("INSERT INTO `transports` (`nexthop`, `destination`, `is_mx_based`, `username` , `password`, `active`)
|
|
|
+ VALUES (:nexthop, :destination, :is_mx_based, :username, :password, :active)");
|
|
|
$stmt->execute(array(
|
|
|
':nexthop' => $nexthop,
|
|
|
':destination' => $insert_dest,
|
|
|
+ ':is_mx_based' => $is_mx_based,
|
|
|
':username' => $username,
|
|
|
':password' => str_replace(':', '\:', $password),
|
|
|
- ':lookup_mx' => $lookup_mx,
|
|
|
':active' => $active
|
|
|
));
|
|
|
}
|
|
@@ -318,7 +327,7 @@ function transport($_action, $_data = null) {
|
|
|
$nexthop = (!empty($_data['nexthop'])) ? trim($_data['nexthop']) : $is_now['nexthop'];
|
|
|
$username = (isset($_data['username'])) ? trim($_data['username']) : $is_now['username'];
|
|
|
$password = (isset($_data['password'])) ? trim($_data['password']) : $is_now['password'];
|
|
|
- $lookup_mx = (isset($_data['lookup_mx']) && $_data['lookup_mx'] != '') ? intval($_data['lookup_mx']) : $is_now['lookup_mx'];
|
|
|
+ $is_mx_based = (isset($_data['is_mx_based']) && $_data['is_mx_based'] != '') ? intval($_data['is_mx_based']) : $is_now['is_mx_based'];
|
|
|
$active = (isset($_data['active']) && $_data['active'] != '') ? intval($_data['active']) : $is_now['active'];
|
|
|
}
|
|
|
else {
|
|
@@ -353,6 +362,22 @@ function transport($_action, $_data = null) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if ($is_mx_based == 0 && (empty($destination) || (is_valid_domain_name(preg_replace('/^' . preg_quote('.', '/') . '/', '', $destination)) === false && $destination != '*' && filter_var($destination, FILTER_VALIDATE_EMAIL) === false))) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
+ 'msg' => array('invalid_destination', $destination)
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if ($is_mx_based == 1 && (empty($destination) || @preg_match('/' . $destination . '/', null) === false)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
+ 'msg' => array('invalid_destination', $destination)
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (isset($next_hop_matches[1])) {
|
|
|
if (in_array($next_hop_clean, $existing_nh)) {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -381,19 +406,19 @@ function transport($_action, $_data = null) {
|
|
|
try {
|
|
|
$stmt = $pdo->prepare("UPDATE `transports` SET
|
|
|
`destination` = :destination,
|
|
|
+ `is_mx_based` = :is_mx_based,
|
|
|
`nexthop` = :nexthop,
|
|
|
`username` = :username,
|
|
|
`password` = :password,
|
|
|
- `lookup_mx` = :lookup_mx,
|
|
|
`active` = :active
|
|
|
WHERE `id` = :id");
|
|
|
$stmt->execute(array(
|
|
|
':id' => $id,
|
|
|
':destination' => $destination,
|
|
|
+ ':is_mx_based' => $is_mx_based,
|
|
|
':nexthop' => $nexthop,
|
|
|
':username' => $username,
|
|
|
':password' => $password,
|
|
|
- ':lookup_mx' => $lookup_mx,
|
|
|
':active' => $active
|
|
|
));
|
|
|
$stmt = $pdo->prepare("UPDATE `transports` SET
|
|
@@ -456,7 +481,7 @@ function transport($_action, $_data = null) {
|
|
|
return false;
|
|
|
}
|
|
|
$transports = array();
|
|
|
- $stmt = $pdo->query("SELECT `id`, `destination`, `nexthop`, `username` FROM `transports`");
|
|
|
+ $stmt = $pdo->query("SELECT `id`, `is_mx_based`, `destination`, `nexthop`, `username` FROM `transports`");
|
|
|
$transports = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
return $transports;
|
|
|
break;
|
|
@@ -466,12 +491,12 @@ function transport($_action, $_data = null) {
|
|
|
}
|
|
|
$transportdata = array();
|
|
|
$stmt = $pdo->prepare("SELECT `id`,
|
|
|
+ `is_mx_based`,
|
|
|
`destination`,
|
|
|
`nexthop`,
|
|
|
`username`,
|
|
|
`password`,
|
|
|
`active`,
|
|
|
- `lookup_mx`,
|
|
|
CONCAT(LEFT(`password`, 3), '...') AS `password_short`
|
|
|
FROM `transports`
|
|
|
WHERE `id` = :id");
|