示例#1
0
 /**
  * Revokes a certificate with Let's Encrypt.
  *
  * This method is called through one of the action callbacks.
  *
  * @since 1.0.0
  * @access protected
  *
  * @param array $data         The request data for the action.
  * @param bool  $network_wide Whether this action should be performed network-wide.
  * @return string|WP_Error The success message or an error object.
  */
 protected function revoke_certificate($data = array(), $network_wide = false)
 {
     $filesystem_check = $this->maybe_request_filesystem_credentials($network_wide);
     if (false === $filesystem_check) {
         return new WP_Error('invalid_filesystem_credentials', __('Invalid or missing filesystem credentials.', 'wp-encrypt'), 'error');
     }
     $domain = $network_wide ? Util::get_network_domain() : Util::get_site_domain();
     $manager = CertificateManager::get();
     $response = $manager->revoke_certificate($domain);
     if (is_wp_error($response)) {
         return $response;
     }
     Util::delete_registration_info('certificate');
     if (Util::get_option('autogenerate_certificate')) {
         Util::unschedule_autogenerate_event();
     }
     return __('Certificate revoked.', 'wp-encrypt');
 }
示例#2
0
        /**
         * Shows a warning in the admin if the current certificate is close to expiration.
         *
         * Whether a warning like this should be shown or not can be specified through a setting,
         * as well as how many days before expiration it should start to show.
         *
         * Let's Encrypt certificates are valid for 90 days. The plugin may autogenerate the
         * certificate prior to expiration, but it is recommended to have this message show to keep
         * that in mind.
         *
         * @since 1.0.0
         * @access public
         */
        public function maybe_show_expire_warning()
        {
            if (!Util::get_option('show_warning')) {
                return;
            }
            if (!current_user_can('manage_certificates')) {
                return;
            }
            $certificate_registration_info = Util::get_registration_info('certificate');
            if (!isset($certificate_registration_info['_wp_time'])) {
                return;
            }
            $expire = strtotime($certificate_registration_info['_wp_time']) + 90 * DAY_IN_SECONDS;
            $now = current_time('timestamp');
            $diff = absint(($expire - $now) / DAY_IN_SECONDS);
            $trigger = Util::get_option('show_warning_days');
            if ($diff > $trigger) {
                return;
            }
            $url = App::get_admin_url($this->context);
            if (Util::get_option('autogenerate_certificate')) {
                $text = _n('The Let&rsquo;s Encrypt certificate will expire in %1$s day. It will be automatically renewed prior to expiration, but you can also manually renew it <a href="%2$s">here</a>.', 'The Let&rsquo;s Encrypt certificate will expire in %1$s days. It will be automatically renewed prior to expiration, but you can also manually renew it <a href="%2$s">here</a>.', $diff, 'wp-encrypt');
            } else {
                $text = _n('The Let&rsquo;s Encrypt certificate will expire in %1$s day. Please renew it soon <a href="%2$s">here</a>.', 'The Let&rsquo;s Encrypt certificate will expire in %1$s days. Please renew it soon <a href="%2$s">here</a>.', $diff, 'wp-encrypt');
            }
            ?>
			<div id="wp-encrypt-expire-warning" class="notice notice-warning">
				<p><?php 
            printf($text, number_format_i18n($diff), $url);
            ?>
</p>
			</div>
			<?php 
        }