mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-01-04 12:39:15 +00:00
Merge branch 'nightly' into feat/nightly-separated-login
This commit is contained in:
@@ -4,14 +4,14 @@ header('Content-Type: application/json');
|
||||
if (!isset($_SESSION['mailcow_cc_role'])) {
|
||||
exit();
|
||||
}
|
||||
if (isset($_GET['script'])) {
|
||||
if (isset($_REQUEST['script'])) {
|
||||
$sieve = new Sieve\SieveParser();
|
||||
try {
|
||||
if (empty($_GET['script'])) {
|
||||
if (empty($_REQUEST['script'])) {
|
||||
echo json_encode(array('type' => 'danger', 'msg' => $lang['danger']['script_empty']));
|
||||
exit();
|
||||
}
|
||||
$sieve->parse($_GET['script']);
|
||||
$sieve->parse($_REQUEST['script']);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo json_encode(array('type' => 'danger', 'msg' => $e->getMessage()));
|
||||
|
||||
@@ -1023,7 +1023,7 @@ function user_get_alias_details($username) {
|
||||
AND `goto` != :username_goto2
|
||||
AND `address` != :username_address");
|
||||
$stmt->execute(array(
|
||||
':username_goto' => '(^|,)'.$username.'($|,)',
|
||||
':username_goto' => '(^|,)'.preg_quote($username, '/').'($|,)',
|
||||
':username_goto2' => $username,
|
||||
':username_address' => $username
|
||||
));
|
||||
@@ -1071,7 +1071,7 @@ function user_get_alias_details($username) {
|
||||
$data['aliases_send_as_all'] = $row['send_as'];
|
||||
}
|
||||
$stmt = $pdo->prepare("SELECT IFNULL(GROUP_CONCAT(`address` SEPARATOR ', '), '') as `address` FROM `alias` WHERE `goto` REGEXP :username AND `address` LIKE '@%';");
|
||||
$stmt->execute(array(':username' => '(^|,)'.$username.'($|,)'));
|
||||
$stmt->execute(array(':username' => '(^|,)'.preg_quote($username, '/').'($|,)'));
|
||||
$run = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
while ($row = array_shift($run)) {
|
||||
$data['is_catch_all'] = $row['address'];
|
||||
@@ -3360,50 +3360,6 @@ function getGUID() {
|
||||
.substr($charid,16, 4).$hyphen
|
||||
.substr($charid,20,12);
|
||||
}
|
||||
function solr_status() {
|
||||
$curl = curl_init();
|
||||
$endpoint = 'http://solr:8983/solr/admin/cores';
|
||||
$params = array(
|
||||
'action' => 'STATUS',
|
||||
'core' => 'dovecot-fts',
|
||||
'indexInfo' => 'true'
|
||||
);
|
||||
$url = $endpoint . '?' . http_build_query($params);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, 0);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
|
||||
$response_core = curl_exec($curl);
|
||||
if ($response_core === false) {
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
curl_close($curl);
|
||||
$curl = curl_init();
|
||||
$status_core = json_decode($response_core, true);
|
||||
$url = 'http://solr:8983/solr/admin/info/system';
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, 0);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
|
||||
$response_sysinfo = curl_exec($curl);
|
||||
if ($response_sysinfo === false) {
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
curl_close($curl);
|
||||
$status_sysinfo = json_decode($response_sysinfo, true);
|
||||
$status = array_merge($status_core, $status_sysinfo);
|
||||
return (!empty($status['status']['dovecot-fts']) && !empty($status['jvm']['memory'])) ? $status : false;
|
||||
}
|
||||
return (!empty($status['status']['dovecot-fts'])) ? $status['status']['dovecot-fts'] : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function cleanupJS($ignore = '', $folder = '/tmp/*.js') {
|
||||
$now = time();
|
||||
|
||||
@@ -48,6 +48,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
$_data["validity"] = 8760;
|
||||
}
|
||||
$domain = $_data['domain'];
|
||||
$description = $_data['description'];
|
||||
$valid_domains[] = mailbox('get', 'mailbox_details', $username)['domain'];
|
||||
$valid_alias_domains = user_get_alias_details($username)['alias_domains'];
|
||||
if (!empty($valid_alias_domains)) {
|
||||
@@ -62,10 +63,11 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
return false;
|
||||
}
|
||||
$validity = strtotime("+" . $_data["validity"] . " hour");
|
||||
$stmt = $pdo->prepare("INSERT INTO `spamalias` (`address`, `goto`, `validity`) VALUES
|
||||
(:address, :goto, :validity)");
|
||||
$stmt = $pdo->prepare("INSERT INTO `spamalias` (`address`, `description`, `goto`, `validity`) VALUES
|
||||
(:address, :description, :goto, :validity)");
|
||||
$stmt->execute(array(
|
||||
':address' => readable_random_string(rand(rand(3, 9), rand(3, 9))) . '.' . readable_random_string(rand(rand(3, 9), rand(3, 9))) . '@' . $domain,
|
||||
':description' => $description,
|
||||
':goto' => $username,
|
||||
':validity' => $validity
|
||||
));
|
||||
@@ -3926,7 +3928,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
$data['external_sender_aliases'] = array();
|
||||
// Fixed addresses
|
||||
$stmt = $pdo->prepare("SELECT `address` FROM `alias` WHERE `goto` REGEXP :goto AND `address` NOT LIKE '@%'");
|
||||
$stmt->execute(array(':goto' => '(^|,)'.$_data.'($|,)'));
|
||||
$stmt->execute(array(':goto' => '(^|,)'.preg_quote($_data, '/').'($|,)'));
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
while ($row = array_shift($rows)) {
|
||||
$data['fixed_sender_aliases'][] = $row['address'];
|
||||
@@ -4359,6 +4361,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
}
|
||||
$stmt = $pdo->prepare("SELECT `address`,
|
||||
`goto`,
|
||||
`description`,
|
||||
`validity`,
|
||||
`created`,
|
||||
`modified`
|
||||
@@ -5595,25 +5598,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
'msg' => 'Could not move maildir to garbage collector: variables local_part and/or domain empty'
|
||||
);
|
||||
}
|
||||
if (strtolower(getenv('SKIP_SOLR')) == 'n' && strtolower(getenv('FLATCURVE_EXPERIMENTAL')) != 'y') {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, 'http://solr:8983/solr/dovecot-fts/update?commit=true');
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: text/xml'));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, '<delete><query>user:' . $username . '</query></delete>');
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
$response = curl_exec($curl);
|
||||
if ($response === false) {
|
||||
$err = curl_error($curl);
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'warning',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => 'Could not remove Solr index: ' . print_r($err, true)
|
||||
);
|
||||
}
|
||||
curl_close($curl);
|
||||
}
|
||||
$stmt = $pdo->prepare("DELETE FROM `alias` WHERE `goto` = :username");
|
||||
$stmt->execute(array(
|
||||
':username' => $username
|
||||
@@ -5714,7 +5698,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
));
|
||||
$stmt = $pdo->prepare("SELECT `address`, `goto` FROM `alias`
|
||||
WHERE `goto` REGEXP :username");
|
||||
$stmt->execute(array(':username' => '(^|,)'.$username.'($|,)'));
|
||||
$stmt->execute(array(':username' => '(^|,)'.preg_quote($username, '/').'($|,)'));
|
||||
$GotoData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($GotoData as $gotos) {
|
||||
$goto_exploded = explode(',', $gotos['goto']);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
function init_db_schema() {
|
||||
function init_db_schema()
|
||||
{
|
||||
try {
|
||||
global $pdo;
|
||||
|
||||
@@ -489,7 +490,7 @@ function init_db_schema() {
|
||||
"quarantine_category" => "TINYINT(1) NOT NULL DEFAULT '1'",
|
||||
"app_passwds" => "TINYINT(1) NOT NULL DEFAULT '1'",
|
||||
"pw_reset" => "TINYINT(1) NOT NULL DEFAULT '1'",
|
||||
),
|
||||
),
|
||||
"keys" => array(
|
||||
"primary" => array(
|
||||
"" => array("username")
|
||||
@@ -528,6 +529,7 @@ function init_db_schema() {
|
||||
"cols" => array(
|
||||
"address" => "VARCHAR(255) NOT NULL",
|
||||
"goto" => "TEXT NOT NULL",
|
||||
"description" => "TEXT NOT NULL",
|
||||
"created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
|
||||
"modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
|
||||
"validity" => "INT(11)"
|
||||
@@ -693,7 +695,7 @@ function init_db_schema() {
|
||||
"mailbox_relayhost" => "TINYINT(1) NOT NULL DEFAULT '1'",
|
||||
"domain_relayhost" => "TINYINT(1) NOT NULL DEFAULT '1'",
|
||||
"domain_desc" => "TINYINT(1) NOT NULL DEFAULT '0'"
|
||||
),
|
||||
),
|
||||
"keys" => array(
|
||||
"primary" => array(
|
||||
"" => array("username")
|
||||
@@ -1166,7 +1168,7 @@ function init_db_schema() {
|
||||
while ($row = array_shift($rows)) {
|
||||
$pdo->query($row['FKEY_DROP']);
|
||||
}
|
||||
foreach($properties['cols'] as $column => $type) {
|
||||
foreach ($properties['cols'] as $column => $type) {
|
||||
$stmt = $pdo->query("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "'");
|
||||
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
if ($num_results == 0) {
|
||||
@@ -1180,12 +1182,11 @@ function init_db_schema() {
|
||||
}
|
||||
}
|
||||
$pdo->query("ALTER TABLE `" . $table . "` ADD `" . $column . "` " . $type);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$pdo->query("ALTER TABLE `" . $table . "` MODIFY COLUMN `" . $column . "` " . $type);
|
||||
}
|
||||
}
|
||||
foreach($properties['keys'] as $key_type => $key_content) {
|
||||
foreach ($properties['keys'] as $key_type => $key_content) {
|
||||
if (strtolower($key_type) == 'primary') {
|
||||
foreach ($key_content as $key_values) {
|
||||
$fields = "`" . implode("`, `", $key_values) . "`";
|
||||
@@ -1242,18 +1243,18 @@ function init_db_schema() {
|
||||
$keys_to_exist = array();
|
||||
if (isset($properties['keys']['unique']) && is_array($properties['keys']['unique'])) {
|
||||
foreach ($properties['keys']['unique'] as $key_name => $key_values) {
|
||||
$keys_to_exist[] = $key_name;
|
||||
$keys_to_exist[] = $key_name;
|
||||
}
|
||||
}
|
||||
if (isset($properties['keys']['key']) && is_array($properties['keys']['key'])) {
|
||||
foreach ($properties['keys']['key'] as $key_name => $key_values) {
|
||||
$keys_to_exist[] = $key_name;
|
||||
$keys_to_exist[] = $key_name;
|
||||
}
|
||||
}
|
||||
// Index for foreign key must exist
|
||||
if (isset($properties['keys']['fkey']) && is_array($properties['keys']['fkey'])) {
|
||||
foreach ($properties['keys']['fkey'] as $key_name => $key_values) {
|
||||
$keys_to_exist[] = $key_name;
|
||||
$keys_to_exist[] = $key_name;
|
||||
}
|
||||
}
|
||||
// Step 2: Drop all vanished indexes
|
||||
@@ -1270,33 +1271,29 @@ function init_db_schema() {
|
||||
$pdo->query("ALTER TABLE `" . $table . "` DROP PRIMARY KEY");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Create table if it is missing
|
||||
$sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (";
|
||||
foreach($properties['cols'] as $column => $type) {
|
||||
foreach ($properties['cols'] as $column => $type) {
|
||||
$sql .= "`" . $column . "` " . $type . ",";
|
||||
}
|
||||
foreach($properties['keys'] as $key_type => $key_content) {
|
||||
foreach ($properties['keys'] as $key_type => $key_content) {
|
||||
if (strtolower($key_type) == 'primary') {
|
||||
foreach ($key_content as $key_values) {
|
||||
$fields = "`" . implode("`, `", $key_values) . "`";
|
||||
$sql .= "PRIMARY KEY (" . $fields . ")" . ",";
|
||||
}
|
||||
}
|
||||
elseif (strtolower($key_type) == 'key') {
|
||||
} elseif (strtolower($key_type) == 'key') {
|
||||
foreach ($key_content as $key_name => $key_values) {
|
||||
$fields = "`" . implode("`, `", $key_values) . "`";
|
||||
$sql .= "KEY `" . $key_name . "` (" . $fields . ")" . ",";
|
||||
}
|
||||
}
|
||||
elseif (strtolower($key_type) == 'unique') {
|
||||
} elseif (strtolower($key_type) == 'unique') {
|
||||
foreach ($key_content as $key_name => $key_values) {
|
||||
$fields = "`" . implode("`, `", $key_values) . "`";
|
||||
$sql .= "UNIQUE KEY `" . $key_name . "` (" . $fields . ")" . ",";
|
||||
}
|
||||
}
|
||||
elseif (strtolower($key_type) == 'fkey') {
|
||||
} elseif (strtolower($key_type) == 'fkey') {
|
||||
foreach ($key_content as $key_name => $key_values) {
|
||||
@list($table_ref, $field_ref) = explode('.', $key_values['ref']);
|
||||
$sql .= "FOREIGN KEY `" . $key_name . "` (" . $key_values['col'] . ") REFERENCES `" . $table_ref . "` (`" . $field_ref . "`)
|
||||
@@ -1310,7 +1307,6 @@ function init_db_schema() {
|
||||
}
|
||||
// Reset table attributes
|
||||
$pdo->query("ALTER TABLE `" . $table . "` " . $properties['attr'] . ";");
|
||||
|
||||
}
|
||||
|
||||
// Recreate SQL views
|
||||
@@ -1337,12 +1333,12 @@ function init_db_schema() {
|
||||
$stmt = $pdo->query("SELECT NULL FROM `admin`");
|
||||
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
if ($num_results == 0) {
|
||||
$pdo->query("INSERT INTO `admin` (`username`, `password`, `superadmin`, `created`, `modified`, `active`)
|
||||
$pdo->query("INSERT INTO `admin` (`username`, `password`, `superadmin`, `created`, `modified`, `active`)
|
||||
VALUES ('admin', '{SSHA256}K8eVJ6YsZbQCfuJvSUbaQRLr0HPLz5rC9IAp0PAFl0tmNDBkMDc0NDAyOTAxN2Rk', 1, NOW(), NOW(), 1)");
|
||||
$pdo->query("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
|
||||
$pdo->query("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
|
||||
SELECT `username`, 'ALL', NOW(), 1 FROM `admin`
|
||||
WHERE superadmin='1' AND `username` NOT IN (SELECT `username` FROM `domain_admins`);");
|
||||
$pdo->query("DELETE FROM `admin` WHERE `username` NOT IN (SELECT `username` FROM `domain_admins`);");
|
||||
$pdo->query("DELETE FROM `admin` WHERE `username` NOT IN (SELECT `username` FROM `domain_admins`);");
|
||||
}
|
||||
// Insert new DB schema version
|
||||
$pdo->query("REPLACE INTO `versions` (`application`, `version`) VALUES ('db_schema', '" . $db_version . "');");
|
||||
@@ -1370,7 +1366,7 @@ function init_db_schema() {
|
||||
$pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.mailbox_format', \"maildir:\") WHERE JSON_VALUE(`attributes`, '$.mailbox_format') IS NULL;");
|
||||
$pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.quarantine_notification', \"never\") WHERE JSON_VALUE(`attributes`, '$.quarantine_notification') IS NULL;");
|
||||
$pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.quarantine_category', \"reject\") WHERE JSON_VALUE(`attributes`, '$.quarantine_category') IS NULL;");
|
||||
foreach($tls_options as $tls_user => $tls_options) {
|
||||
foreach ($tls_options as $tls_user => $tls_options) {
|
||||
$stmt = $pdo->prepare("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.tls_enforce_in', :tls_enforce_in),
|
||||
`attributes` = JSON_SET(`attributes`, '$.tls_enforce_out', :tls_enforce_out)
|
||||
WHERE `username` = :username");
|
||||
@@ -1449,7 +1445,7 @@ function init_db_schema() {
|
||||
":template" => $default_domain_template["template"]
|
||||
));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (empty($row)){
|
||||
if (empty($row)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
|
||||
VALUES (:type, :template, :attributes)");
|
||||
$stmt->execute(array(
|
||||
@@ -1464,7 +1460,7 @@ function init_db_schema() {
|
||||
":template" => $default_mailbox_template["template"]
|
||||
));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (empty($row)){
|
||||
if (empty($row)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
|
||||
VALUES (:type, :template, :attributes)");
|
||||
$stmt->execute(array(
|
||||
@@ -1486,8 +1482,7 @@ function init_db_schema() {
|
||||
'msg' => 'db_init_complete'
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
if (php_sapi_name() == "cli") {
|
||||
echo "DB initialization failed: " . print_r($e, true) . PHP_EOL;
|
||||
} else {
|
||||
@@ -1525,8 +1520,7 @@ if (php_sapi_name() == "cli") {
|
||||
try {
|
||||
update_sogo_static_view();
|
||||
echo "Fixed _sogo_static_view" . PHP_EOL;
|
||||
}
|
||||
catch ( Exception $e ) {
|
||||
} catch (Exception $e) {
|
||||
// Dunno
|
||||
}
|
||||
}
|
||||
@@ -1534,9 +1528,8 @@ if (php_sapi_name() == "cli") {
|
||||
$m = new Memcached();
|
||||
$m->addServer('memcached', 11211);
|
||||
$m->flush();
|
||||
echo "Cleaned up memcached". PHP_EOL;
|
||||
}
|
||||
catch ( Exception $e ) {
|
||||
echo "Cleaned up memcached" . PHP_EOL;
|
||||
} catch (Exception $e) {
|
||||
// Dunno
|
||||
}
|
||||
init_db_schema();
|
||||
|
||||
@@ -93,6 +93,7 @@ $AVAILABLE_LANGUAGES = array(
|
||||
'gr-gr' => 'Ελληνικά (Greek)',
|
||||
'hu-hu' => 'Magyar (Hungarian)',
|
||||
'it-it' => 'Italiano (Italian)',
|
||||
'ja-jp' => '日本語 (Japanese)',
|
||||
'ko-kr' => '한국어 (Korean)',
|
||||
'lv-lv' => 'latviešu (Latvian)',
|
||||
'lt-lt' => 'Lietuvių (Lithuanian)',
|
||||
|
||||
Reference in New Issue
Block a user