Skip to content

Commit

Permalink
Merge pull request #74 from ammopt/ammo_smtp_server_24.07.00
Browse files Browse the repository at this point in the history
SMTP setting
  • Loading branch information
AlexanderBlanchardAC authored Jun 12, 2024
2 parents 2e8d431 + a6e9e35 commit b90171a
Show file tree
Hide file tree
Showing 78 changed files with 10,662 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/web/release_notes/24.07.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// jacob

// pedro
- Added a new feature: SMTP setting. This allows for SMTP configuration to be utilized when sending e-mails from Aspen.

// other

Expand Down
81 changes: 81 additions & 0 deletions code/web/services/Admin/SMTPSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

require_once ROOT_DIR . '/Action.php';
require_once ROOT_DIR . '/services/Admin/ObjectEditor.php';
require_once ROOT_DIR . '/sys/Email/SMTPSetting.php';

class Admin_SMTPSettings extends ObjectEditor {
function getObjectType(): string {
return 'SMTPSetting';
}

function getToolName(): string {
return 'SMTPSettings';
}

function getModule(): string {
return 'Admin';
}

function getPageTitle(): string {
return 'SMTP Settings';
}

function getAllObjects($page, $recordsPerPage): array {
$object = new SMTPSetting();
$object->limit(($page - 1) * $recordsPerPage, $recordsPerPage);
$this->applyFilters($object);
$object->find();
$objectList = [];
while ($object->fetch()) {
$objectList[$object->id] = clone $object;
}
return $objectList;
}

function getDefaultSort(): string {
return 'id asc';
}

function canSort(): bool {
return false;
}

function getObjectStructure($context = ''): array {
return SMTPSetting::getObjectStructure($context);
}

function getPrimaryKeyColumn(): string {
return 'id';
}

function getIdKeyColumn(): string {
return 'id';
}

function getAdditionalObjectActions($existingObject): array {
return [];
}

function getInstructions(): string {
return '';
}

function getBreadcrumbs(): array {
$breadcrumbs = [];
$breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home');
$breadcrumbs[] = new Breadcrumb('/Admin/Home#system_admin', 'System Administration');
$breadcrumbs[] = new Breadcrumb('/Admin/SMTPSettings', 'SMTP Settings');
return $breadcrumbs;
}

function getActiveAdminSection(): string {
return 'email';
}

function canView(): bool {
return UserAccount::userHasPermission('Administer SMTP');
}


}
1 change: 1 addition & 0 deletions code/web/sys/Account/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,7 @@ public function getAdminActions() {
$sections['email']->addAction(new AdminAction('Email Templates', 'Templates for various emails sent from Aspen Discovery.', '/Admin/EmailTemplates'), ['Administer All Email Templates', 'Administer Library Email Templates']);
$sections['email']->addAction(new AdminAction('Amazon SES Settings', 'Settings to allow Aspen Discovery to send emails via Amazon SES.', '/Admin/AmazonSesSettings'), 'Administer Amazon SES');
$sections['email']->addAction(new AdminAction('Send Grid Settings', 'Settings to allow Aspen Discovery to send emails via SendGrid.', '/Admin/SendGridSettings'), 'Administer SendGrid');
$sections['email']->addAction(new AdminAction('SMTP Settings', 'Settings to allow Aspen Discovery to send emails via an SMTP server.', '/Admin/SMTPSettings'), 'Administer SMTP');

$sections['ils_integration'] = new AdminSection('ILS Integration');
$indexingProfileAction = new AdminAction('Indexing Profiles', 'Define how records from the ILS are loaded into Aspen Discovery.', '/ILS/IndexingProfiles');
Expand Down
1 change: 1 addition & 0 deletions code/web/sys/DBMaintenance/user_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ function getUserUpdates() {
,('System Administration', 'Administer Permissions', '', 15, 'Allows configuration of the roles within Aspen Discovery and what each role can do. <i>Give to trusted users, this has security implications.</i>')
,('System Administration', 'Run Database Maintenance', '', 20, 'Controls if the user can run database maintenance or not.')
,('System Administration', 'Administer SendGrid', '', 30, 'Controls if the user can change SendGrid settings. <em>This has potential security and cost implications.</em>')
,('System Administration', 'Administer SMTP', '', 30, 'Controls if the user can change SMTP settings.')
,('System Administration', 'Administer System Variables','', 40, 'Controls if the user can change system variables.')
,('Reporting', 'View System Reports', '', 0, 'Controls if the user can view System Reports that show how Aspen Discovery performs and how background tasks are operating. Includes Indexing Logs and Dashboards.')
,('Reporting', 'View Indexing Logs', '', 10, 'Controls if the user can view Indexing Logs for the ILS and eContent.')
Expand Down
28 changes: 28 additions & 0 deletions code/web/sys/DBMaintenance/version_updates/24.07.00.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ function getUpdates24_07_00(): array {

//katherine - ByWater

//pedro - PTFS-Europe
'smtp_settings' => [
'title' => 'SMTP Settings',
'description' => 'Allow configuration of SMTP to send mail from',
'sql' => [
"CREATE TABLE smtp_settings (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(80) NOT NULL,
host varchar(80) NOT NULL DEFAULT 'localhost',
port int(11) NOT NULL DEFAULT 25,
ssl_mode enum('disabled','ssl','tls') NOT NULL,
from_address varchar(80) DEFAULT NULL,
user_name varchar(80) DEFAULT NULL,
password varchar(80) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB",
],
], //smtp_settings

'permissions_create_administer_smtp' => [
'title' => 'Create Administer SMTP Permission',
'description' => 'Controls if the user can change SMTP settings',
'sql' => [
"INSERT INTO permissions (sectionName, name, requiredModule, weight, description) VALUES ('Primary Configuration', 'Administer SMTP', '', 30, 'Controls if the user can change SMTP settings.')",
"INSERT INTO role_permissions(roleId, permissionId) VALUES ((SELECT roleId from roles where name='opacAdmin'), (SELECT id from permissions where name='Administer SMTP'))",
],
], //permissions_create_administer_smtp

//other


Expand Down
10 changes: 9 additions & 1 deletion code/web/sys/Email/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public function send($to, $subject, $body, $replyTo = null, $htmlBody = null, $a

require_once ROOT_DIR . '/sys/Email/SendGridSetting.php';
require_once ROOT_DIR . '/sys/Email/AmazonSesSetting.php';
require_once ROOT_DIR . '/sys/Email/SMTPSetting.php';
require_once ROOT_DIR . '/sys/CurlWrapper.php';
//TODO: Do validation of the address
$amazonSesSettings = new AmazonSesSetting();
$smtpServerSettings = new SMTPSetting();

if ($amazonSesSettings->find(true)) {
if($smtpServerSettings->find(true)) {
$result = $this->sendViaSMTP($smtpServerSettings, $to, $replyTo, $subject, $body, $htmlBody, $attachments);
}elseif ($amazonSesSettings->find(true)) {
$result = $this->sendViaAmazonSes($amazonSesSettings, $to, $replyTo, $subject, $body, $htmlBody, $attachments);
} else {
$sendGridSettings = new SendGridSetting();
Expand Down Expand Up @@ -137,4 +141,8 @@ private function sendViaAmazonSes(AmazonSesSetting $amazonSesSettings, string $t
}
}
}

private function sendViaSMTP(SMTPSetting $smtpSettings, string $to, ?string $replyTo, string $subject, ?string $body, ?string $htmlBody, ?array $attachments): bool {
return $smtpSettings->sendEmail($to, $replyTo, $subject, $body, $htmlBody, $attachments);
}
}
15 changes: 15 additions & 0 deletions code/web/sys/Email/PHPMailer-6.9.1/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
46 changes: 46 additions & 0 deletions code/web/sys/Email/PHPMailer-6.9.1/COMMITMENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GPL Cooperation Commitment
Version 1.0

Before filing or continuing to prosecute any legal proceeding or claim
(other than a Defensive Action) arising from termination of a Covered
License, we commit to extend to the person or entity ('you') accused
of violating the Covered License the following provisions regarding
cure and reinstatement, taken from GPL version 3. As used here, the
term 'this License' refers to the specific Covered License being
enforced.

However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly
and finally terminates your license, and (b) permanently, if the
copyright holder fails to notify you of the violation by some
reasonable means prior to 60 days after the cessation.

Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you
have received notice of violation of this License (for any work)
from that copyright holder, and you cure the violation prior to 30
days after your receipt of the notice.

We intend this Commitment to be irrevocable, and binding and
enforceable against us and assignees of or successors to our
copyrights.

Definitions

'Covered License' means the GNU General Public License, version 2
(GPLv2), the GNU Lesser General Public License, version 2.1
(LGPLv2.1), or the GNU Library General Public License, version 2
(LGPLv2), all as published by the Free Software Foundation.

'Defensive Action' means a legal proceeding or claim that We bring
against you in response to a prior proceeding or claim initiated by
you or your affiliate.

'We' means each contributor to this repository as of the date of
inclusion of this file, including subsidiaries of a corporate
contributor.

This work is available under a Creative Commons Attribution-ShareAlike
4.0 International license (https://creativecommons.org/licenses/by-sa/4.0/).
Loading

0 comments on commit b90171a

Please sign in to comment.