Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions app/Http/Controllers/CDash.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace App\Http\Controllers;

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\ResponseTrait;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use League\Flysystem\Adapter\AbstractAdapter;
use Storage;

/**
Expand Down Expand Up @@ -154,11 +152,8 @@ public function isRequestForExport()
*/
public function getRequestContents()
{
/** @var AbstractAdapter $adapter */
$adapter = $this->getDiskAdapter();
$file = $this->getAbsolutePath();

chdir($adapter->getPathPrefix());
chdir($this->disk->path(''));

ob_start();
$redirect = require $file;
Expand Down Expand Up @@ -287,19 +282,11 @@ public function getPath()
*/
public function getAbsolutePath()
{
/** @var AbstractAdapter $adapter */
$adapter = $this->getDiskAdapter();
$path = $this->getPath();

$file = $adapter->applyPathPrefix($path);
$file = $this->disk->path($path);
return $file;
}

public function getDiskAdapter()
{
return $this->disk->getDriver()->getAdapter();
}

/**
* Returns the blade view with CDash layout
*
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
Expand All @@ -19,5 +19,10 @@ class TrustProxies extends Middleware
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}
2 changes: 0 additions & 2 deletions app/cdash/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
// host for Selenium testing
$CDASH_SELENIUM_HUB='localhost';

// If CDash should use the SendGrid API for email
$CDASH_USE_SENDGRID = false;
// API Key for SendGrid
$CDASH_SENDGRID_API_KEY = null;
// Using HTTPS protocol to access CDash
Expand Down

This file was deleted.

79 changes: 32 additions & 47 deletions app/cdash/include/Messaging/Notification/Email/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@

namespace CDash\Messaging\Notification\Email;

use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\SendmailTransport;
use Symfony\Component\Mime\Email;

use CDash\Log;
use CDash\Messaging\Notification\NotificationInterface;
use CDash\Singleton;

class Mail extends Singleton
{
protected $swift;
protected $mailer;
protected $recipient;
protected $defaultSender;
protected $defaultReplyTo;
protected $emails;

/**
* TODO: probably better implemented with DI
* (e.g.: __construct(Swift_)
* Mail constructor.
*/
public function __construct()
Expand Down Expand Up @@ -71,74 +74,56 @@ public function getDefaultReplyTo()
}

/**
* @return null|\Swift_Mailer
* @return null|Mailer
*/
public function getSwiftMailer()
public function getMailer()
{
if (!$this->swift) {
if (config('mail.driver') != 'stmp') {
// TODO:
/* @see https://github.com/swiftmailer/swiftmailer/issues/866#issuecomment-289291228
* If we want to enable the ability to send via php's native mail() function
* then we should create our own Transport implementing Swift_Transport
* that guarantees proper sanitization of vulnerable input, namely email addresses
*/
// $transport = \Swift_MailTransport::newInstance();
$transport = new \Swift_SendmailTransport();
} else {
if (!$this->mailer) {
if (config('mail.driver') == 'stmp') {
$smtp_host = config('mail.host');
$smtp_port = config('mail.port');
$smtp_user = config('mail.username');
$smtp_pswd = config('mail.password');

$transport = new \Swift_SmtpTransport($smtp_host, $smtp_port);
if ($smtp_host && $smtp_pswd) {
$transport
->setUsername($smtp_user)
->setPassword($smtp_pswd);
if ($smtp_user && $smtp_pswd) {
$smtp_dsn = "smtp://{$smtp_user}:{$smtp_pswd}@{$smtp_host}:{$smtp_port}";
} else {
$smtp_dsn = "smtp://{$smtp_host}:{$smtp_port}";
}
$transport = Transport::fromDsn($dsn);
} else {
$transport = new SendmailTransport();
}

$this->swift = new \Swift_Mailer($transport);

if (config('app.debug')) {
$listener = new EmailSendListener($this);
$this->swift->registerPlugin($listener);
}
$this->mailer = new Mailer($transport);
}
return $this->swift;
return $this->mailer;
}

public function send(EmailMessage $message)
{
if (config('app.debug')) {
return;
}
$sender = $message->getSender() ?: $this->getDefaultSender();
$swift_mailer = $this->getSwiftMailer();
$swift_message = new \Swift_Message();
$mailer = $this->getMailer();

try {
$swift_message->setTo($this->recipient)
->setFrom($sender)
->setSubject($message->getSubject())
->setBody($message->getBody());
$email = (new Email())
->from($sender)
->to($this->recipient)
->subject($message->getSubject())
->text($message->getBody());
} catch (\Exception $e) {
$log = Log::getInstance();
$log->add_log($e->getMessage(), __METHOD__);
}
$failed_recipients = [];

try {
$status = $swift_mailer->send($swift_message, $failed_recipients);
$mailer->send($email);
} catch (\Exception $e) {
$status = 0;
$log = Log::getInstance();
$log->add_log($e->getMessage(), __METHOD__);
}

if (!empty($failed_recipients)) {
$log = Log::getInstance();
$message = "Failed to send message titled {$message->getSubject()} to {$failed_recipients[0]}";
$log->add_log($message, __METHOD__);
}
return $status;
}

public static function to($address)
Expand All @@ -148,9 +133,9 @@ public static function to($address)
return $mail;
}

public function addEmail(\Swift_Message $message)
public function addEmail(Email $email)
{
$this->emails[] = $message;
$this->emails[] = $email;
}

public function getEmails()
Expand Down
32 changes: 0 additions & 32 deletions app/cdash/include/cdashmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,6 @@
use CDash\Config;
use Illuminate\Support\Facades\Mail;

function _cdashsendgrid($to, $subject, $body)
{
$config = Config::getInstance();

$sg = new \SendGrid($config->get('CDASH_SENDGRID_API_KEY'));

$mail = new SendGrid\Mail();
$mail->setFrom(new SendGrid\Email(null, config('mail.from.address')));
$mail->setSubject($subject);
$mail->setReplyTo(new SendGrid\Email(null, config('mail.reply_to.address')));
$mail->addContent(new SendGrid\Content('text/plain', $body));

foreach (explode(', ', $to) as $recipient) {
$personalization = new SendGrid\Personalization();
$personalization->addTo(new SendGrid\Email(null, $recipient));
$mail->addPersonalization($personalization);
}

$response = $sg->client->mail()->send()->post($mail);

if ($response->statusCode() === 202) {
return true;
} else {
add_log('Failed to send email via sendgrid status code: ' . $response->statusCode(), '_cdashsendgrid', LOG_ERR);
return false;
}
}

function cdashmail($to, $subject, $body, $headers = false)
{
$config = Config::getInstance();
Expand All @@ -53,10 +25,6 @@ function cdashmail($to, $subject, $body, $headers = false)
return false;
}

if ($config->get('CDASH_USE_SENDGRID')) {
return _cdashsendgrid($to, $subject, $body);
}

if (config('app.debug')) {
add_log($to, 'TESTING: EMAIL', LOG_DEBUG);
add_log($subject, 'TESTING: EMAILTITLE', LOG_DEBUG);
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
"adldap2/adldap2-laravel": "6.*",
"aws/aws-sdk-php": "^3.57",
"doctrine/dbal": "^3.1.4",
"fideloper/proxy": "^4.0",
"friendsofphp/php-cs-fixer": "^3.4",
"guzzlehttp/guzzle": "^7.0.1",
"http-interop/http-factory-guzzle": "^1.0",
"iron-io/iron_mq": "~2.0",
"knplabs/github-api": "^3.0",
"laravel/framework": "^8.0",
"laravel/framework": "^9.0",
"laravel/legacy-factories": "^1.3",
"laravel/ui": "^3.0",
"lcobucci/jwt": "4.1.5",
Expand All @@ -39,8 +38,7 @@
"pear/archive_tar": "~1.4",
"php-di/php-di": "6.3.2",
"predis/predis": "~0.8",
"ramsey/uuid": "^4",
"sendgrid/sendgrid": "5.0.4"
"ramsey/uuid": "^4"
},
"require-dev": {
"ext-dom": "*",
Expand Down
Loading