PluginProbe ʕ •ᴥ•ʔ
Easy HTTPS Redirection (SSL) / trunk
Easy HTTPS Redirection (SSL) vtrunk
trunk 1.5 1.6 1.8 1.9.1 1.9.2 2.0.0 2.0.1
https-redirection / admin / ehssl-certificate-expiry-menu.php
https-redirection / admin Last commit date
ehssl-admin-init.php 1 year ago ehssl-admin-menu.php 2 days ago ehssl-certificate-expiry-menu.php 2 days ago ehssl-dashboard-menu.php 2 days ago ehssl-settings-menu-old.php 1 year ago ehssl-settings-menu.php 2 days ago ehssl-ssl-management-menu.php 1 year ago index.php 1 year ago
ehssl-certificate-expiry-menu.php
386 lines
1 <?php
2
3 class EHSSL_Certificate_Expiry_Menu extends EHSSL_Admin_Menu {
4 public $menu_page_slug = EHSSL_CERTIFICATE_EXPIRY_MENU_SLUG;
5
6 // Specify all the tabs of this menu in the following array.
7 public $dashboard_menu_tabs = array(
8 'expiring-certificates' => 'Expiring Certificates',
9 'expiry-notification' => 'Expiry Notification',
10 );
11
12 public function __construct() {
13 $this->render_menu_page();
14 }
15
16 public function get_current_tab() {
17 $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : array_keys( $this->dashboard_menu_tabs )[0];
18
19 return $tab;
20 }
21
22 /**
23 * Renders our tabs of this menu as nav items
24 */
25 public function render_page_tabs() {
26 $current_tab = $this->get_current_tab();
27 foreach ( $this->dashboard_menu_tabs as $tab_key => $tab_caption ) {
28 $active = $current_tab == $tab_key ? 'nav-tab-active' : '';
29 echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->menu_page_slug . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
30 }
31 }
32
33 /**
34 * The menu rendering goes here
35 */
36 public function render_menu_page() {
37 $tab = $this->get_current_tab();
38
39 ?>
40 <div class="wrap">
41 <h2><?php _e( "Certificate Expiry", 'https-redirection' ) ?></h2>
42 <h2 class="nav-tab-wrapper"><?php $this->render_page_tabs(); ?></h2>
43 <div id="poststuff">
44 <div id="post-body">
45 <?php
46 switch ( $tab ) {
47 case 'expiring-certificates':
48 $this->render_expiring_certificates_tab();
49 break;
50 case 'expiry-notification':
51 default:
52 $this->render_email_notification_tab();
53 break;
54 }
55 ?>
56 </div>
57 </div>
58 <?php $this->documentation_link_box(); ?>
59 </div><!-- end or wrap -->
60 <?php
61 }
62
63 public function render_expiring_certificates_tab() {
64 if ( isset( $_POST['ehssl_scan_for_ssl_submit'] ) ){
65
66 if (!check_admin_referer('ehssl_scan_for_ssl_nonce')){
67 wp_die('Nonce verification failed!');
68 }
69
70 EHSSL_SSL_Utils::check_and_save_current_cert_info();
71
72 echo '<div class="notice notice-success"><p>'. __('SSL certificate scan completed successfully.', 'https-redirection') .'</p></div>';
73 }
74
75 if ( isset( $_POST['ehssl_delete_all_cert_info_submit'] ) ){
76
77 if (!check_admin_referer('ehssl_delete_all_cert_info_nonce')){
78 wp_die('Nonce verification failed!');
79 }
80
81 $is_deleted = EHSSL_SSL_Utils::delete_all_certificate_info();
82
83 if ($is_deleted){
84 echo '<div class="notice notice-success"><p>'. __('SSL certificate info was deleted successfully.', 'https-redirection') .'</p></div>';
85 } else {
86 echo '<div class="notice notice-info"><p>'. __('No saved SSL certificate info was detected for deletion.', 'https-redirection') .'</p></div>';
87 }
88 }
89
90 $certs_info = EHSSL_SSL_Utils::get_all_saved_certificates_info();
91 ?>
92 <div class="postbox">
93 <h3 class="hndle">
94 <label for="title"><?php _e( "Certificates", 'https-redirection' ); ?></label>
95 </h3>
96 <div class="inside">
97 <?php if (!empty($certs_info)) { ?>
98 <table class="widefat striped">
99 <thead>
100 <tr>
101 <th><?php _e('ID', 'https-redirection') ?></th>
102 <th><?php _e('Label', 'https-redirection') ?></th>
103 <th><?php _e('Issuer', 'https-redirection') ?></th>
104 <th><?php _e('Issued on', 'https-redirection') ?></th>
105 <th><?php _e('Expires on', 'https-redirection') ?></th>
106 <th><?php _e('Status', 'https-redirection') ?></th>
107 </tr>
108 </thead>
109 <?php foreach ($certs_info as $cert){
110 $formatted_issued_on_date = EHSSL_Utils::parse_timestamp( $cert['issued_on'] );
111 $formatted_expires_on = EHSSL_Utils::parse_timestamp( $cert['expires_on'] );
112 $formatted_ssl_status = ucfirst(EHSSL_SSL_Utils::get_certificate_status($cert['expires_on']));
113 ?>
114 <tr>
115 <td><?php esc_attr_e($cert['id']) ?></td>
116 <td><?php esc_attr_e($cert['label']) ?></td>
117 <td><?php esc_attr_e($cert['issuer']) ?></td>
118 <td><?php esc_attr_e($formatted_issued_on_date) ?></td>
119 <td><?php esc_attr_e($formatted_expires_on) ?></td>
120 <td><?php esc_attr_e($formatted_ssl_status) ?></td>
121 </tr>
122 <?php } ?>
123 </table>
124 <?php } else { ?>
125 <p class="description">
126 <?php _e('No SSL certificate information found. Click the Scan button to search for installed certificates.', 'https-redirection') ?>
127 </p>
128 <?php } ?>
129 </div><!-- end of inside -->
130 </div><!-- end of postbox -->
131
132 <div class="postbox">
133 <h3 class="hndle">
134 <label for="title"><?php _e( "Certificate Actions", 'https-redirection' ); ?></label>
135 </h3>
136 <div class="inside">
137 <div class="">
138 <form action="" method="post">
139 <div><?php _e('Click the Scan button to manually scan for available SSL certificates.', 'https-redirection') ?></div>
140 <br>
141 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('ehssl_scan_for_ssl_nonce') ?>">
142 <input type="submit"
143 class="button-primary"
144 value="<?php _e('Scan Now', 'https-redirection') ?>"
145 name="ehssl_scan_for_ssl_submit"
146 >
147 </form>
148 </div>
149
150 <br>
151
152 <div class="">
153 <form action="" method="post" onsubmit="return confirm('<?php _e('Do you really want to delete all saved SSL info?', 'https-redirection') ?>');">
154 <div><?php _e('Delete all SSL certificate records from the table.', 'https-redirection') ?></div>
155 <br>
156 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('ehssl_delete_all_cert_info_nonce') ?>">
157 <input type="submit"
158 class="button-secondary"
159 style="border-color: #CC0000; color: #CC0000"
160 value="<?php _e('Delete All SSL Info', 'https-redirection') ?>"
161 name="ehssl_delete_all_cert_info_submit"
162 >
163 </form>
164 </div>
165
166 </div><!-- end of inside -->
167 </div><!-- end of postbox -->
168 <?php
169 }
170
171 public function render_email_notification_tab() {
172 $settings = get_option('httpsrdrctn_options', array());
173
174 if ( isset( $_POST['ehssl_expiry_notification_settings_form_submit'] ) && check_admin_referer( 'ehssl_expiry_notification_settings_nonce' ) ) {
175 $settings['ehssl_enable_expiry_notification'] = isset( $_POST['ehssl_enable_expiry_notification'] ) ? esc_attr( $_POST['ehssl_enable_expiry_notification'] ) : '';
176 $settings['ehssl_expiry_notification_email_content_type'] = isset( $_POST['ehssl_expiry_notification_email_content_type'] ) ? sanitize_text_field( $_POST['ehssl_expiry_notification_email_content_type'] ) : 'text';
177 $settings['ehssl_expiry_notification_email_before_days'] = isset( $_POST['ehssl_expiry_notification_email_before_days'] ) ? intval( sanitize_text_field( $_POST['ehssl_expiry_notification_email_before_days'] ) ) : 'text';
178 $settings['ehssl_expiry_notification_email_from'] = isset( $_POST['ehssl_expiry_notification_email_from'] ) ? $_POST['ehssl_expiry_notification_email_from'] : '';
179 $settings['ehssl_expiry_notification_email_to'] = isset( $_POST['ehssl_expiry_notification_email_to'] ) ? sanitize_email( $_POST['ehssl_expiry_notification_email_to'] ) : '';
180 $settings['ehssl_expiry_notification_email_subject'] = isset( $_POST['ehssl_expiry_notification_email_subject'] ) ? sanitize_text_field( $_POST['ehssl_expiry_notification_email_subject'] ) : '';
181 $settings['ehssl_expiry_notification_email_body'] = isset( $_POST['ehssl_expiry_notification_email_body'] ) ? wp_kses_post( $_POST['ehssl_expiry_notification_email_body'] ) : '';
182
183 update_option( 'httpsrdrctn_options', $settings )
184
185 ?>
186 <div class="notice notice-success">
187 <p><?php _e( "Settings Saved.", 'https-redirection' ); ?></p>
188 </div>
189 <?php
190 }
191
192 $expiry_notification_enabled = isset( $settings['ehssl_enable_expiry_notification'] ) ? sanitize_text_field( $settings['ehssl_enable_expiry_notification'] ) : 0;
193 $expiry_notification_email_content_type = isset( $settings['ehssl_expiry_notification_email_content_type'] ) ? sanitize_text_field( $settings['ehssl_expiry_notification_email_content_type'] ) : '';
194
195 $expiry_notification_email_before_days = isset( $settings['ehssl_expiry_notification_email_before_days'] ) ? sanitize_text_field( $settings['ehssl_expiry_notification_email_before_days'] ) : '';
196 if (empty($expiry_notification_email_before_days)){
197 $expiry_notification_email_before_days = 7;
198 }
199
200 $expiry_notification_email_from = isset( $settings['ehssl_expiry_notification_email_from'] ) ? $settings['ehssl_expiry_notification_email_from'] : '';
201 if (empty($expiry_notification_email_from)){
202 $default_domain_email_address = 'admin@' . EHSSL_Utils::get_domain();
203 $expiry_notification_email_from = get_bloginfo( 'name' ) . ' <'.$default_domain_email_address.'>';
204 }
205
206 $expiry_notification_email_to = isset( $settings['ehssl_expiry_notification_email_to'] ) ? sanitize_email( $settings['ehssl_expiry_notification_email_to'] ) : '';
207
208 $expiry_notification_email_sub = isset( $settings['ehssl_expiry_notification_email_subject'] ) ? sanitize_text_field( $settings['ehssl_expiry_notification_email_subject'] ) : '';
209 if (empty($expiry_notification_email_sub)){
210 $expiry_notification_email_sub = 'SSL Certificate Expiry Notification';
211 }
212
213 $expiry_notification_email_body = isset( $settings['ehssl_expiry_notification_email_body'] ) ? wp_kses_post( $settings['ehssl_expiry_notification_email_body'] ) : '';
214 if (empty($expiry_notification_email_body)){
215 $expiry_notification_email_body = 'Dear Admin,' . "\r\n\r\n"
216 . 'This is a reminder that your SSL certificate issued by {issuer} '
217 . 'is set to expire on {expiry_datetime}.' . "\r\n\r\n"
218 . 'Please take the necessary steps to renew the certificate to avoid any security or accessibility issues.' . "\r\n\r\n"
219 . 'Thanks';
220 }
221
222 ?>
223 <div class="postbox">
224 <h3 class="hndle">
225 <label for="title"><?php _e( "Notification Email Settings", 'https-redirection' ); ?></label>
226 </h3>
227 <div class="inside">
228 <form method="post" action="">
229 <table class="form-table">
230 <tr valign="top">
231 <th scope="row">
232 <label>
233 <?php _e( 'Enable Certificate Expiry Notification', 'https-redirection' ); ?>
234 </label>
235 </th>
236 <td>
237 <input type="checkbox"
238 name="ehssl_enable_expiry_notification"
239 value="1"
240 <?php echo !empty($expiry_notification_enabled) ? 'checked="checked"' : '' ?>
241 />
242 <br/>
243 <p class="description"><?php _e( "Enable this option to send SSL certificate expiry notifications.", 'https-redirection' ); ?></p>
244 </td>
245 </tr>
246 <tr valign="top">
247 <th scope="row">
248 <label>
249 <?php _e( 'Email Content Type', 'https-redirection' ); ?>
250 </label>
251 </th>
252 <td>
253 <select name="ehssl_expiry_notification_email_content_type">
254 <option value="text" <?php echo ($expiry_notification_email_content_type == 'text') ? 'selected' : '' ?>><?php _e('Plain Text', 'https-redirection') ?></option>
255 <option value="html" <?php echo ($expiry_notification_email_content_type == 'html') ? 'selected' : '' ?>><?php _e('HTML', 'https-redirection') ?></option>
256 </select>
257 <br/>
258 <p class="description"><?php _e( "Choose whether the SSL expiry notification email should be sent in plain text or HTML format.", 'https-redirection' ); ?></p>
259 </td>
260 </tr>
261 <tr valign="top">
262 <th scope="row">
263 <label>
264 <?php _e( 'Notification Email Before Days', 'https-redirection' ); ?>
265 </label>
266 </th>
267 <td>
268 <input type="number"
269 name="ehssl_expiry_notification_email_before_days"
270 class="ehssl-settings-field-cat-1"
271 value="<?php esc_attr_e( $expiry_notification_email_before_days ) ?>"
272 required
273 />
274 <br/>
275 <p class="description"><?php _e( "Set how many days in advance the expiry email should be sent. Default is 7 days.", 'https-redirection' ); ?></p>
276 </td>
277 </tr>
278 <tr valign="top">
279 <th scope="row">
280 <label>
281 <?php _e( 'Notification Email From', 'https-redirection' ); ?>
282 </label>
283 </th>
284 <td>
285 <input type="text"
286 name="ehssl_expiry_notification_email_from"
287 class="ehssl-settings-field-cat-2"
288 value="<?php esc_attr_e( $expiry_notification_email_from ) ?>"
289 />
290 <br/>
291 <p class="description"><?php _e( "The email address used as the 'From' address in the notification email.", 'https-redirection' ); ?></p>
292 </td>
293 </tr>
294 <tr valign="top">
295 <th scope="row">
296 <label>
297 <?php _e( 'Notification Email To', 'https-redirection' ); ?>
298 </label>
299 </th>
300 <td>
301 <input type="email"
302 name="ehssl_expiry_notification_email_to"
303 class="ehssl-settings-field-cat-2"
304 value="<?php esc_attr_e( $expiry_notification_email_to ) ?>"
305 required
306 />
307 <br/>
308 <p class="description"><?php _e( "Email address where expiry notifications will be sent.", 'https-redirection' ); ?></p>
309 </td>
310 </tr>
311 <tr valign="top">
312 <th scope="row">
313 <label>
314 <?php _e( 'Notification Email Subject', 'https-redirection' ); ?>
315 </label>
316 </th>
317 <td>
318 <input type="text"
319 name="ehssl_expiry_notification_email_subject"
320 class="ehssl-settings-field-cat-2"
321 value="<?php esc_attr_e( $expiry_notification_email_sub ) ?>"
322 required
323 />
324 <br/>
325 <p class="description"><?php _e( "Certificate expiry notification email subject.", 'https-redirection' ); ?></p>
326 </td>
327 </tr>
328 <tr valign="top">
329 <th scope="row">
330 <label>
331 <?php _e( 'Notification Email Body', 'https-redirection' ); ?>
332 </label>
333 </th>
334 <td>
335 <?php if ($expiry_notification_email_content_type == 'html') {
336 add_filter( 'wp_default_editor', array( $this, 'set_default_editor' ) );
337 ?>
338 <div class="ehssl-settings-field-cat-3">
339 <?php
340 wp_editor(
341 html_entity_decode( $expiry_notification_email_body ),
342 'ehssl_expiry_notification_email_body',
343 array(
344 'textarea_name' => 'ehssl_expiry_notification_email_body',
345 'teeny' => true,
346 'media_buttons' => false,
347 'textarea_rows' => 12,
348 )
349 );
350 ?>
351 </div>
352 <?php
353 remove_filter( 'wp_default_editor', array( $this, 'set_default_editor' ) );
354 } else { ?>
355 <textarea
356 name="ehssl_expiry_notification_email_body"
357 class="ehssl-settings-field-cat-3"
358 rows="10"
359 required
360 ><?php esc_attr_e( $expiry_notification_email_body ) ?></textarea>
361 <br/>
362 <?php } ?>
363 <p class="description"><?php _e( "Certificate expiry notification email body.", 'https-redirection' ); ?></p>
364 <?php echo EHSSL_Email_handler::get_merge_tags_hints() ?>
365 </td>
366 </tr>
367 </table>
368
369 <?php wp_nonce_field( 'ehssl_expiry_notification_settings_nonce' ); ?>
370 <p class="submit">
371 <input type="submit" name="ehssl_expiry_notification_settings_form_submit"
372 class="button-primary" value="<?php _e( 'Save Changes' ) ?>"/>
373 </p>
374 </form>
375 </div><!-- end of inside -->
376 </div><!-- end of postbox -->
377 <?php
378 }
379
380 public function set_default_editor( $r ) {
381 $r = 'html';
382 return $r;
383 }
384
385
386 } // End class