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-ssl-management-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-ssl-management-menu.php
219 lines
1 <?php
2
3 class EHSSL_SSL_MGMT_Menu extends EHSSL_Admin_Menu
4 {
5 public $menu_page_slug = EHSSL_SSL_MGMT_MENU_SLUG;
6
7 // Specify all the tabs of this menu in the following array.
8 public $dashboard_menu_tabs = array('get-ssl' => 'Get SSL', 'install-ssl' => 'Install SSL');
9
10 public function __construct()
11 {
12 $this->render_menu_page();
13 }
14
15 public function get_current_tab()
16 {
17 $tab = isset($_GET['tab']) ? $_GET['tab'] : array_keys($this->dashboard_menu_tabs)[0];
18 return $tab;
19 }
20
21 /**
22 * Renders our tabs of this menu as nav items
23 */
24 public function render_page_tabs()
25 {
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 {
38 $tab = $this->get_current_tab();
39 ?>
40 <div class="wrap">
41 <h2><?php _e("SSL Management", '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 'install-ssl':
48 //include_once('file-to-handle-this-tab-rendering.php');//If you want to include a file
49 $this->render_tab_2();
50 break;
51 case 'get-ssl':
52 default:
53 //include_once('file-to-handle-this-tab-rendering.php');//If you want to include a file
54 $this->render_tab_1();
55 break;
56 }
57 ?>
58 </div>
59 </div>
60 </div><!-- end or wrap -->
61 <?php
62 }
63
64 public function render_tab_1()
65 {
66 //Render tab 1
67 if (EHSSL_Utils::get_domain() == "localhost" || filter_var(EHSSL_Utils::get_domain(), FILTER_VALIDATE_IP)) {
68 _e("The SSL Certificates required for HTTPS cannot be issued for WordPress sites that are based on 'localhost' or use an IP address. To effectively utilize SSL certificates, and hence to make the most from our plugin, you should operate your WordPress site on a standard domain. This limitation is not specific from our plugin but is a general rule in the issuance of SSL certificates.", 'https-redirection');
69 wp_die();
70 }
71
72 global $httpsrdrctn_options;
73
74 // Save data for tab 1
75 if (isset($_POST['ehssl_get_ssl_form_submit']) && check_admin_referer('ehssl_get_ssl_nonce')) {
76 $httpsrdrctn_options['ehssl_email_for_ssl_certificate'] = isset($_POST['ehssl_email_for_ssl_certificate']) ? sanitize_email($_POST['ehssl_email_for_ssl_certificate']) : get_option('admin_email');
77 $httpsrdrctn_options['ehssl_ssl_certificate_mode'] = isset($_POST['ehssl_ssl_certificate_mode']) ? sanitize_text_field($_POST['ehssl_ssl_certificate_mode']) : '';
78 update_option('httpsrdrctn_options', $httpsrdrctn_options);
79
80 $is_live_ssl_mode = $httpsrdrctn_options['ehssl_ssl_certificate_mode'] === 'live';
81
82 //EHSSL_SSL_Certificate
83 $ssl_certificate = new EHSSL_SSL_Certificate();
84 $ssl_certificate_status = $ssl_certificate->handle_ssl_installation($httpsrdrctn_options['ehssl_email_for_ssl_certificate'], $is_live_ssl_mode);
85
86 if (is_wp_error($ssl_certificate_status)) {
87 $certificate_error = $ssl_certificate_status->get_error_message();
88 if (stripos($certificate_error, '429 Too many Requests') !== false) {
89 $certificate_error = "Too many certificate requests, try again in few hours";
90 }
91 ?>
92 <div class="notice notice-error">
93 <p><?php _e("Error getting SSL:", 'https-redirection'); ?> <?php echo $certificate_error; ?></p>
94 </div>
95 <?php
96 } else { ?>
97 <div class="notice notice-success">
98 <p><?php _e($ssl_certificate_status, 'https-redirection'); ?> </p>
99 <?php
100 $certificate_urls = EHSSL_SSL_Certificate::get_certificate_urls();
101
102 echo "<ul>";
103 foreach ($certificate_urls as $key => $url) {
104 echo "<li><a href='{$url}'>{$key}</a></li>";
105 }
106 echo "</ul>";
107 ?>
108 </div>
109 <?php
110 }
111 ?>
112 <?php
113 }
114
115 $ehssl_ssl_certificate_generator_email = isset($httpsrdrctn_options['ehssl_email_for_ssl_certificate']) ? sanitize_email($httpsrdrctn_options['ehssl_email_for_ssl_certificate']) : '';
116 $ehssl_ssl_certificate_mode = isset($httpsrdrctn_options['ehssl_ssl_certificate_mode']) ? sanitize_text_field($httpsrdrctn_options['ehssl_ssl_certificate_mode']) : 'staging';
117
118
119 ?>
120 <div class="postbox">
121 <h3 class="hndle"><label for="title">Get SSL</label></h3>
122 <div class="inside">
123 <form method="post" action="">
124 <p>
125 SSL certificate will be generated for the domain:<br>
126 <b><?php echo EHSSL_Utils::get_domain(); ?></b>
127 <?php
128 $domain_variant = EHSSL_Utils::get_domain_variant(EHSSL_Utils::get_domain());
129 if (EHSSL_Utils::is_domain_accessible($domain_variant)) {
130 echo "<br><b>" . $domain_variant . "</b>";
131 }
132 ?>
133 </p>
134
135 <table class="form-table">
136 <!-- Certificate mode field -->
137 <tr valign="top">
138 <th scope="row">
139 <span><?php _e('SSL certificate mode:', 'https-redirection'); ?></span>
140 </th>
141 <td>
142 <label><input type="radio" name="ehssl_ssl_certificate_mode" value="staging" style="margin-left: 12px;" <?php if ('staging' == $ehssl_ssl_certificate_mode) {echo "checked=\"checked\" ";}?>><?php _e('Staging', 'https-redirection') ?></label>
143 <label><input type="radio" name="ehssl_ssl_certificate_mode" value="live" style="margin-left: 12px;" <?php if ('live' == $ehssl_ssl_certificate_mode) {echo "checked=\"checked\" ";}?>><?php _e('Live', 'https-redirection') ?></label>
144 </td>
145 </tr>
146 <!-- Email address field -->
147 <tr valign="top">
148 <th scope="row">
149 <label for="ehssl_email_for_ssl_certificate"><?php _e('Email Address:', 'https-redirection'); ?></label>
150 </th>
151 <td>
152 <input type="email" id="ehssl_email_for_ssl_certificate" value="<?php echo esc_attr($ehssl_ssl_certificate_generator_email) ?>" name="ehssl_email_for_ssl_certificate" style="margin-left: 12px;" required>
153 </td>
154 </tr>
155 </table>
156
157 <!-- Submit button -->
158 <input type="submit" name="ehssl_get_ssl_form_submit" class="button-primary" value="<?php _e('Generate SSL Certificate', 'https-redirection') ?>" />
159 <?php wp_nonce_field('ehssl_get_ssl_nonce'); ?>
160
161 </form>
162 </div><!-- end of inside -->
163 </div><!-- end of postbox -->
164 <?php
165 }
166
167 public function render_tab_2()
168 {
169 //Render tab 1
170 ?>
171 <div class="postbox">
172 <h3 class="hndle"><label for="title">Install SSL</label></h3>
173 <?php
174 global $httpsrdrctn_options;
175 $certificate_urls = EHSSL_SSL_Certificate::get_certificate_urls();
176 ?>
177 <div class="inside">
178 <?php if (is_wp_error($certificate_urls)) { ?>
179 <div class="ehssl-yellow-box">
180 <?php echo $certificate_urls->get_error_message();?>
181 </div>
182 <?php } else { ?>
183 <p>Please follow <a href="">this guide</a> to install SSL certificate</p>
184 <p>Certificate Expiry: <?php echo isset($httpsrdrctn_options['ehssl_expiry_ssl_certificate']) ? esc_attr($httpsrdrctn_options['ehssl_expiry_ssl_certificate']) : "" ?></p>
185 <ol>
186 <li>
187 <h4><?php _e('Get Certificate Files', 'https-redirection')?></h4>
188 <p><?php _e('Some documentation goes here...' , 'https-redirection') ?></p>
189 <table class="form-table">
190 <?php foreach ($certificate_urls as $key => $file) { ?>
191 <tr>
192 <th><?php esc_attr_e($key) ?></th>
193 <td>
194 <input type="text" style="width: 80%; margin-right: 4px" readonly value="<?php echo esc_url($file['path']); ?>" /><button class="button-primary"><?php _e('Copy File Path', 'https-redirection') ?></button>
195 </td>
196 <td>
197 <a href='<?php echo esc_url($file['url'])?>' class="button-secondary"><?php _e('Download File', 'https-redirection') ?></a>
198 <a href='#' class="button-secondary"><?php _e('Copy File Content', 'https-redirection') ?></a>
199 </td>
200 </tr>
201 <?php } ?>
202 </table>
203 </li>
204 <li>
205 <h4><?php _e('Add the certificate file paths', 'https-redirection')?></h4>
206 <p><?php _e('Some documentation goes here...' , 'https-redirection') ?></p>
207 </li>
208 <li>
209 <h4><?php _e('Restart the server', 'https-redirection')?></h4>
210 <p><?php _e('Some documentation goes here...' , 'https-redirection') ?></p>
211 </li>
212 </ol>
213 <?php } ?>
214
215 </div><!-- end of inside -->
216 </div><!-- end of postbox -->
217 <?php
218 }
219 } // End class