mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Mail review stage 7a: mail passwords, the OAuth client secret and the mail tokens are stored encrypted with a key from config.php's backup key, kept as typed only when there is no key, with a warning in Admin > Settings > Mail when they can't be read (database 4.3.1); pictures from other sites in client email are held back on a ticket, its quick look and its work order until Show pictures is clicked; the sign-in page no longer loads the mail server's password; 26.12.3 changelog
This commit is contained in:
@@ -89,9 +89,10 @@ function mailGraphToken($permission, $fresh = false) {
|
||||
return null;
|
||||
}
|
||||
$client_id = trim((string) $row['config_mail_oauth_client_id']);
|
||||
$secret = trim((string) $row['config_mail_oauth_client_secret']);
|
||||
// Encrypted in the database (functions/mail_secret.php)
|
||||
$secret = trim(mailSecretOpen($row['config_mail_oauth_client_secret']));
|
||||
$tenant = trim((string) $row['config_mail_oauth_tenant_id']);
|
||||
$refresh_token = trim((string) $row['config_mail_oauth_refresh_token']);
|
||||
$refresh_token = trim(mailSecretOpen($row['config_mail_oauth_refresh_token']));
|
||||
if ($client_id === '' || $secret === '' || $tenant === '' || $refresh_token === '') {
|
||||
return null;
|
||||
}
|
||||
@@ -99,7 +100,7 @@ function mailGraphToken($permission, $fresh = false) {
|
||||
$had = mailGraphScopesOf($row['config_mail_graph_scopes']);
|
||||
$expires = strtotime((string) $row['config_mail_graph_token_expires_at']);
|
||||
if (!$fresh && $expires && $expires - 120 > time()) {
|
||||
$token = (string) $row['config_mail_graph_token'];
|
||||
$token = mailSecretOpen($row['config_mail_graph_token']);
|
||||
return $token !== '' && in_array($permission, $had, true) ? $token : null;
|
||||
}
|
||||
|
||||
@@ -125,11 +126,11 @@ function mailGraphToken($permission, $fresh = false) {
|
||||
// A token without the mail permissions is kept too - it is the answer until it runs out
|
||||
$scope = mb_substr((string) ($response['json']['scope'] ?? ''), 0, 2000);
|
||||
$expires_at = date('Y-m-d H:i:s', time() + max(300, intval($response['json']['expires_in'] ?? 3600)));
|
||||
$set = "config_mail_graph_token = '" . mysqli_real_escape_string($mysqli, $token) . "', config_mail_graph_token_expires_at = '$expires_at',
|
||||
$set = mailSecretSql('config_mail_graph_token', $token) . ", config_mail_graph_token_expires_at = '$expires_at',
|
||||
config_mail_graph_scopes = '" . mysqli_real_escape_string($mysqli, $scope) . "'";
|
||||
// Microsoft hands back a new refresh token each time - the one to keep
|
||||
if (!empty($response['json']['refresh_token'])) {
|
||||
$set .= ", config_mail_oauth_refresh_token = '" . mysqli_real_escape_string($mysqli, (string) $response['json']['refresh_token']) . "'";
|
||||
$set .= ', ' . mailSecretSql('config_mail_oauth_refresh_token', (string) $response['json']['refresh_token']);
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE settings SET $set WHERE company_id = 1");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user