Skip to content

Commit

Permalink
Added selector deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Aug 18, 2023
1 parent f5ccf63 commit 4eecae7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
59 changes: 45 additions & 14 deletions dkim.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
redirect($baseurl, get_string('selectoractivated', 'tool_emailutils'), null, \core\output\notification::NOTIFY_SUCCESS);
}

if ($action == 'deactivate') {
require_sesskey();
$selector = required_param('selector', PARAM_TEXT);
add_to_config_log('emaildkimselector', $CFG->emaildkimselector, '', '');
set_config('emaildkimselector', '');
redirect($baseurl, get_string('selectordeactivated', 'tool_emailutils'), null, \core\output\notification::NOTIFY_WARNING);
}

$form = new \tool_emailutils\form\create_dkim();
if ($form->is_cancelled()) {
redirect($prevurl);
Expand All @@ -63,7 +71,7 @@
}

$dkimdir = $CFG->dataroot . '/dkim/';
$domains = scandir($dkimdir);
$domains = scandir($dkimdir, SCANDIR_SORT_DESCENDING);
$domaincount = 0;
$noreplydomain = substr($CFG->noreplyaddress, strpos($CFG->noreplyaddress, '@') + 1);

Expand Down Expand Up @@ -106,6 +114,11 @@


$selectors = scandir($dkimdir . $domain);

// We want newer date based selectors to be at the top.
natsort($selectors);
$selectors = array_reverse($selectors);

$selectorcount = 0;

foreach ($selectors as $file) {
Expand Down Expand Up @@ -135,24 +148,42 @@
$context['selectoractive'] = true;
}

if ($CFG->emaildkimselector !== $selector) {
// Only give the option to delete if it is not being used.
$isactive = $CFG->emaildkimselector == $selector;

// Only give the option to delete if it is not being used.
$confirmation = new \confirm_action(
get_string('selectordeleteconfirm', 'tool_emailutils'),
null,
get_string('selectordelete', 'tool_emailutils')
);
$context['selectordelete'] = $OUTPUT->action_link(
new moodle_url('/admin/tool/emailutils/dkim.php', [
'domain' => $domain,
'selector' => $selector,
'action' => 'delete',
'sesskey' => sesskey()]),
get_string('selectordelete', 'tool_emailutils'),
$confirmation,
[ 'class' => 'btn btn-sm ' . ($isactive ? 'btn-secondary disabled' : 'btn-outline-danger') ],
new pix_icon('i/delete', ''));

if ($isactive) {
// Only give the option to make it the active select if it is not being used.
$confirmation = new \confirm_action(
get_string('selectordeleteconfirm', 'tool_emailutils'),
get_string('selectordeactivateconfirm', 'tool_emailutils'),
null,
get_string('selectordelete', 'tool_emailutils')
get_string('selectordeactivate', 'tool_emailutils')
);
$context['selectordelete'] = $OUTPUT->action_link(
$context['selectordeactivate'] = $OUTPUT->action_link(
new moodle_url('/admin/tool/emailutils/dkim.php', [
'domain' => $domain,
'selector' => $selector,
'action' => 'delete',
'action' => 'deactivate',
'sesskey' => sesskey()]),
get_string('selectordelete', 'tool_emailutils'),
get_string('selectordeactivate', 'tool_emailutils'),
$confirmation,
['class' => 'btn btn-secondary btn-sm'],
new pix_icon('i/delete', ''));

[ 'class' => 'btn btn-sm btn-secondary' ],
new pix_icon('i/show', ''));
} else {
// Only give the option to make it the active select if it is not being used.
$confirmation = new \confirm_action(
get_string('selectoractivateconfirm', 'tool_emailutils'),
Expand All @@ -166,8 +197,8 @@
'sesskey' => sesskey()]),
get_string('selectoractivate', 'tool_emailutils'),
$confirmation,
['class' => 'btn btn-secondary btn-sm'],
new pix_icon('i/star', ''));
[ 'class' => 'btn btn-sm btn-primary' ],
new pix_icon('t/hide', ''));
}

print $OUTPUT->render_from_template('tool_emailutils/dkimselector', $context);
Expand Down
8 changes: 6 additions & 2 deletions lang/en/tool_emailutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@

$string['mxtoolbox'] = 'MXtoolbox links';
$string['selectoractive'] = 'Active selector';
$string['selectoractivate'] = 'Activate selector';
$string['selectoractiveactions'] = 'You cannot';
$string['selectoractivate'] = 'Activate key pair';
$string['selectoractivated'] = 'Selector was activated';
$string['selectoractivateconfirm'] = 'This will set $CFG->emaildkimselector to this selector and it will be used for signing outgoing emails.';
$string['selectorcreate'] = 'Create a new domain:selector certificate pair';
$string['selectorcreatesubmit'] = 'Create new selector';
$string['selectorcreated'] = 'A new certificate pair has been created';
$string['selectordefault'] = '%Y-%m';
$string['selectordeactivate'] = 'Deactivate key pair';
$string['selectordeactivated'] = 'Email signing has been turned off';
$string['selectordeactivateconfirm'] = 'This will unset $CFG->emaildkimselector so emails will no longer be signed.';
$string['selectormissing'] = 'No DKIM selector certificates found';
$string['selectordelete'] = 'Delete inactive selector';
$string['selectordelete'] = 'Delete key pair';
$string['selectordeleted'] = 'Inactive selector has been deleted';
$string['selectordeleteconfirm'] = 'This will permanently delete this selector\'s private and public keys and is irreversable.';

Expand Down
6 changes: 5 additions & 1 deletion templates/dkimselector.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@
<li><a href='{{dkimurl}}' target='_blank'>DKIM</a>
<li><a href='{{dkimrawurl}}' target='_blank'>Raw TXT</a>
</ul>
<p>{{{selectordelete}}}</p>
{{#selectoractive}}
{{#str}} selectoractiveactions, tool_emailutils {{/str}}
{{/selectoractive}}
<p>{{{selectoractivate}}}</p>
<p>{{{selectordeactivate}}}</p>
<p>{{{selectordelete}}}</p>
</td>
</tr>

0 comments on commit 4eecae7

Please sign in to comment.