dvadf
File manager - Edit - /home/centroca/public_html/Helpers.tar
Back
DB.php 0000644 00000001511 15253205667 0005553 0 ustar 00 <?php namespace WPMailSMTP\Helpers; /** * Class for Database functionality. * * @since 3.6.0 */ class DB { /** * The function is used to check if the given index exists in the given table. * * @since 3.6.0 * * @param string $table The table name. * @param string $index The index name. * * @return bool If index exists then return true else returns false. */ public static function index_exists( $table, $index ) { global $wpdb; $query = $wpdb->prepare( 'SELECT COUNT(1) IndexIsThere FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema = DATABASE() AND table_name = %s AND index_name = %s', $table, $index ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared $result = $wpdb->get_var( $query ); return $result === '1'; } } UI.php 0000644 00000010435 15253205667 0005610 0 ustar 00 <?php namespace WPMailSMTP\Helpers; /** * Reusable interface components. * * @since 3.10.0 */ class UI { /** * Toggle component. * * @since 3.10.0 * * @param array $args { * Toggle parameters. * * @type string $name Name attribute of the toggle's input element. Default ''. * @type string $value Value attribute of the toggle's input element. Default 'yes'. * @type string|string[] $label Single label, or a 2-elements array of on/off labels. Default ''. * @type string $id ID attribute of the toggle's container element. Default ''. * @type string $class Class attribute of the toggle's container element. Default ''. * @type bool $checked Checked attribute of the toggle's input element. Default false. * @type bool $disabled Disabled attribute of the toggle's input element. Default false. * } */ public static function toggle( $args = [] ) { $args = wp_parse_args( $args, [ 'name' => '', 'value' => 'yes', 'label' => [ esc_html__( 'On', 'wp-mail-smtp' ), esc_html__( 'Off', 'wp-mail-smtp' ), ], 'id' => '', 'class' => '', 'checked' => false, 'disabled' => false, ] ); ?> <label class="wp-mail-smtp-toggle"> <input type="checkbox" name="<?php echo esc_attr( $args['name'] ); ?>" <?php echo empty( $args['class'] ) ? '' : ' class="' . esc_attr( $args['class'] ) . '"'; ?> <?php echo empty( $args['id'] ) ? '' : ' id="' . esc_attr( $args['id'] ) . '"'; ?> value="<?php echo esc_attr( $args['value'] ); ?>" <?php checked( (bool) $args['checked'] ); ?> <?php disabled( (bool) $args['disabled'] ); ?> /> <span class="wp-mail-smtp-toggle__switch"></span> <?php if ( is_array( $args['label'] ) ) : ?> <?php if ( count( $args['label'] ) > 0 ) : ?> <span class="wp-mail-smtp-toggle__label wp-mail-smtp-toggle__label--checked"><?php echo esc_html( $args['label'][0] ); ?></span> <?php endif; ?> <?php if ( count( $args['label'] ) > 1 ) : ?> <span class="wp-mail-smtp-toggle__label wp-mail-smtp-toggle__label--unchecked"><?php echo esc_html( $args['label'][1] ); ?></span> <?php endif; ?> <?php else : ?> <span class="wp-mail-smtp-toggle__label wp-mail-smtp-toggle__label--static"><?php echo esc_html( $args['label'] ); ?></span> <?php endif; ?> </label> <?php } /** * Output an obfuscated password field. * * @since 4.1.0 * * @param array $args Field attributes. * * @return void */ public static function hidden_password_field( $args ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh $args = wp_parse_args( $args, [ 'name' => '', 'id' => '', 'value' => '', 'clear_text' => esc_html__( 'Remove', 'wp-mail-smtp' ), 'clear_url' => '', ] ); $value = str_repeat( '*', strlen( $args['value'] ) ); // phpcs:disable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace ?> <div class="wp-mail-smtp-input-btn-row"> <input type="password" spellcheck="false" autocomplete="new-password" <?php if ( ! empty( $value ) ) : ?>disabled<?php endif; ?> <?php if ( ! empty( $args['name'] && empty( $value ) ) ) : ?>name="<?php echo esc_attr( $args['name'] ); ?>"<?php endif; ?> <?php if ( ! empty( $args['name'] ) ) : ?>data-name="<?php echo esc_attr( $args['name'] ); ?>"<?php endif; ?> <?php if ( ! empty( $args['id'] ) ) : ?>id="<?php echo esc_attr( $args['id'] ); ?>"<?php endif; ?> <?php if ( ! empty( $value ) ) : ?>value="<?php echo esc_attr( $value ); ?>"<?php endif; ?>/> <?php if ( ! empty( $value ) && ! empty( $args['clear_url'] ) ) : ?> <a href="<?php echo esc_url( $args['clear_url'] ); ?>" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-grey"><?php echo esc_html( $args['clear_text'] ); ?></a> <?php elseif ( ! empty( $value ) ) : ?> <button type="button" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-grey" data-clear-field="<?php echo esc_attr( $args['id'] ); ?>"><?php echo esc_html( $args['clear_text'] ); ?></button> <?php endif; ?> </div> <?php // phpcs:enable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace } } Data.php 0000644 00000010421 15253205667 0006137 0 ustar 00 <?php namespace WPMailSMTP\Helpers; use ArrayAccess; /** * Class Data. * * Helper class that allows to get/set value in the nested array by string key. * * @since 4.9.0 */ class Data { /** * Keys string separator. * * @since 4.9.0 * * @var string */ const KEY_SEPARATOR = '.'; /** * Get nested array value by string key. * * @since 4.9.0 * * @param array $array Input array. * @param string $str_key String key. E.g. "level1.level2.level3". * @param mixed $default The default value that should be returned if value by key not found. * * @return mixed */ public static function get( $array, $str_key, $default = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound, Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound if ( is_array( $array ) && array_key_exists( $str_key, $array ) ) { return $array[ $str_key ]; } $keys = self::get_keys_array( $str_key ); foreach ( $keys as $key ) { if ( ! is_array( $array ) && ! $array instanceof ArrayAccess ) { return $default; } if ( ( $array instanceof ArrayAccess && $array->offsetExists( $key ) ) || array_key_exists( $key, $array ) ) { $array = $array[ $key ]; } else { return $default; } } return $array; } /** * Get keys array from keys string. * * @since 4.9.0 * * @param string $keys String key. E.g. "level1.level2.level3". * * @return array */ private static function get_keys_array( $keys ) { return explode( self::KEY_SEPARATOR, $keys ); } /** * Set value in the nested array by string key (by reference). * * @since 4.9.0 * * @param array &$array Input array (passed by reference). * @param string $str_key String key. E.g. "level1.level2.level3". * @param mixed $value Value that should be added to array. * * @return void */ public static function set( array &$array, $str_key, $value ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound // Fast path for non-nested key. if ( strpos( $str_key, self::KEY_SEPARATOR ) === false ) { $array[ $str_key ] = $value; return; } $keys = self::get_keys_array( $str_key ); $tmp = &$array; $keys_count = count( $keys ); while ( $keys_count > 0 ) { $key = array_shift( $keys ); --$keys_count; if ( ! is_array( $tmp ) ) { $tmp = []; } $tmp = &$tmp[ $key ]; } $tmp = $value; } /** * Find a value in an array. * * @since 4.9.0 * * @param array $array The array to search in. * @param string $key The key to search for. * @param mixed $value The value to search for. * @param string|false $desired_key The key to return from the found item, or false to return the whole item. * @param mixed $default The default value to return if not found. * * @return mixed */ public static function find( $array, $key, $value, $desired_key = false, $default = '' ) { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded, Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound, Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound foreach ( $array as $item ) { if ( isset( $item[ $key ] ) && $item[ $key ] === $value ) { if ( $desired_key !== false ) { if ( isset( $item[ $desired_key ] ) ) { return $item[ $desired_key ]; } break; } return $item; } } return $default; } /** * Walk through array recursively. * * @since 4.9.0 * * @param array $array Array to walk through. * @param callable $callback Callback function that will be executed for each scalar array item. * @param string $parent_key Parent key. Used for recursive calls. */ public static function walk_recursive( &$array, $callback, $parent_key = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound foreach ( $array as $key => &$value ) { if ( ! is_numeric( $key ) ) { $current_key = $parent_key ? $parent_key . '.' . $key : $key; } else { $current_key = $parent_key; } if ( is_array( $value ) ) { self::walk_recursive( $value, $callback, $current_key ); } else { call_user_func_array( $callback, [ &$value, $current_key ] ); } } } } Helpers.php 0000644 00000010321 15253205667 0006667 0 ustar 00 <?php namespace WPMailSMTP\Helpers; use WPMailSMTP\Options; use WPMailSMTP\WP; use WP_Error; /** * Class with all the misc helper functions that don't belong elsewhere. * * @since 3.0.0 */ class Helpers { /** * Check if the current active mailer has email send confirmation functionality. * * @since 3.0.0 * * @return bool */ public static function mailer_without_send_confirmation() { return ! in_array( Options::init()->get( 'mail', 'mailer' ), [ 'sendlayer', 'smtpcom', 'sendinblue', 'mailgun', 'postmark', 'sparkpost', 'elasticemail', 'smtp2go', 'mailjet', 'mailersend', 'mandrill', 'resend', ], true ); } /** * Include mbstring polyfill. * * @since 3.1.0 */ public static function include_mbstring_polyfill() { static $included = false; if ( $included === true ) { return; } require_once wp_mail_smtp()->plugin_path . '/vendor_prefixed/symfony/polyfill-mbstring/Mbstring.php'; require_once wp_mail_smtp()->plugin_path . '/vendor_prefixed/symfony/polyfill-mbstring/bootstrap.php'; $included = true; } /** * Test if the REST API is accessible. * * @since 3.3.0 * * @return true|\WP_Error */ public static function test_rest_availability() { $headers = [ 'Cache-Control' => 'no-cache', ]; /** This filter is documented in wp-includes/class-wp-http-streams.php */ $sslverify = apply_filters( 'https_local_ssl_verify', false ); $url = rest_url( 'wp-mail-smtp/v1' ); $response = wp_remote_get( $url, [ 'headers' => $headers, 'sslverify' => $sslverify, ] ); if ( is_wp_error( $response ) ) { return $response; } elseif ( wp_remote_retrieve_response_code( $response ) !== 200 ) { return new WP_Error( wp_remote_retrieve_response_code( $response ), wp_remote_retrieve_body( $response ) ); } return true; } /** * Get string size in bytes. * * @since 3.4.0 * * @param string $str String. * * @return int */ public static function strsize( $str ) { if ( ! function_exists( 'mb_strlen' ) ) { self::include_mbstring_polyfill(); } return mb_strlen( $str, '8bit' ); } /** * Format a variable for debug-style output as an inline <code> block. * * Bools and empty values are rendered via var_dump (which shows the type); * everything else via print_r. Line breaks are stripped so the output fits * on a single rendered line. * * @since 4.9.0 * * @param mixed $var Variable to format. * * @return string */ public static function pvar( $var = '' ) { ob_start(); echo '<code>'; if ( is_bool( $var ) || empty( $var ) ) { var_dump( $var ); } else { print_r( $var ); } echo '</code>'; $output = ob_get_clean(); return str_replace( [ "\r\n", "\r", "\n" ], '', $output ); } /** * Format error message. * * @since 3.4.0 * * @param string $message Error message. * @param string $code Error code. * @param string $description Error description. * * @return string */ public static function format_error_message( $message, $code = '', $description = '' ) { $error_text = ''; if ( ! empty( $code ) ) { $error_text .= $code . ': '; } if ( ! is_string( $message ) ) { $error_text .= wp_json_encode( $message ); } else { $error_text .= $message; } if ( ! empty( $description ) ) { $error_text .= WP::EOL . $description; } return $error_text; } /** * Get the default user agent. * * @since 3.9.0 * * @return string */ public static function get_default_user_agent() { $license_type = wp_mail_smtp()->get_license_type(); return 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) . '; WPMailSMTP/' . $license_type . '-' . WPMS_PLUGIN_VER; } /** * Import Plugin_Upgrader class from core. * * @since 3.11.0 */ public static function include_plugin_upgrader() { /** \WP_Upgrader class */ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; /** \Plugin_Upgrader class */ require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; } /** * Whether the current request is a WP CLI request. * * @since 4.0.0 */ public static function is_wp_cli() { return defined( 'WP_CLI' ) && WP_CLI; } } PluginImportDataRetriever.php 0000644 00000025520 15253205667 0012407 0 ustar 00 <?php namespace WPMailSMTP\Helpers; /** * Class for preparing import data from other SMTP plugins. * * @since 2.6.0 */ class PluginImportDataRetriever { /** * The slug of the SMTP plugin to prepare the data for. * * @since 2.6.0 * * @var string */ private $slug; /** * PluginImportDataRetriever constructor. * * @since 2.6.0 * * @param string $slug The SMTP plugin slug. */ public function __construct( $slug ) { $this->slug = $slug; } /** * Get the data for the current plugin slug. * * @since 2.6.0 * * @return false|array */ public function get() { $method_name = preg_replace( '/[\-]/', '_', sanitize_key( "get_$this->slug" ) ); if ( method_exists( $this, $method_name ) ) { return $this->$method_name(); } return false; } /** * Check if Easy WP SMTP plugin settings are present and extract them. * * @since 2.6.0 * * @return array */ private function get_easy_smtp() { $options = get_option( 'swpsmtp_options' ); if ( empty( $options ) ) { return []; } return [ 'mail' => [ 'mailer' => 'smtp', 'from_email' => isset( $options['from_email_field'] ) ? $options['from_email_field'] : '', 'from_name' => isset( $options['from_name_field'] ) ? $options['from_name_field'] : '', 'from_name_force' => isset( $options['force_from_name_replace'] ) ? $options['force_from_name_replace'] : false, ], 'smtp' => [ 'host' => isset( $options['smtp_settings']['host'] ) ? $options['smtp_settings']['host'] : '', 'encryption' => isset( $options['smtp_settings']['type_encryption'] ) ? $options['smtp_settings']['type_encryption'] : 'none', 'port' => isset( $options['smtp_settings']['port'] ) ? $options['smtp_settings']['port'] : 25, 'auth' => isset( $options['smtp_settings']['autentication'] ) ? $options['smtp_settings']['autentication'] : true, 'user' => isset( $options['smtp_settings']['username'] ) ? $options['smtp_settings']['username'] : '', 'pass' => '', 'autotls' => true, ], ]; } /** * Check if FluentSMTP plugin settings are present and extract them. * * @since 3.2.0 * * @return array */ private function get_fluent_smtp() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded $options = get_option( 'fluentmail-settings' ); if ( empty( $options ) ) { return []; } if ( empty( $options['misc']['default_connection'] ) || empty( $options['connections'][ $options['misc']['default_connection'] ]['provider_settings'] ) ) { return []; } $fluent_data = $options['connections'][ $options['misc']['default_connection'] ]['provider_settings']; $allowed_mailers = [ 'smtp' => 'smtp', 'ses' => 'amazonses', 'mailgun' => 'mailgun', 'sendgrid' => 'sendgrid', 'sendinblue' => 'sendinblue', 'sparkpost' => 'sparkpost', 'postmark' => 'postmark', 'outlook' => 'outlook', ]; if ( empty( $fluent_data['provider'] ) || ! in_array( $fluent_data['provider'], array_keys( $allowed_mailers ), true ) ) { return []; } $data = [ 'mail' => [ 'mailer' => $allowed_mailers[ $fluent_data['provider'] ], 'from_email' => isset( $fluent_data['sender_email'] ) ? $fluent_data['sender_email'] : '', 'from_name' => isset( $fluent_data['sender_name'] ) ? $fluent_data['sender_name'] : '', 'from_email_force' => isset( $fluent_data['force_from_email'] ) && $fluent_data['force_from_email'] === 'yes', 'from_name_force' => isset( $fluent_data['force_from_name'] ) && $fluent_data['force_from_name'] === 'yes', ], ]; switch ( $data['mail']['mailer'] ) { case 'smtp': $data['smtp'] = [ 'host' => isset( $fluent_data['host'] ) ? $fluent_data['host'] : '', 'encryption' => isset( $fluent_data['encryption'] ) && in_array( $fluent_data['encryption'], [ 'none', 'ssl', 'tls' ], true ) ? $fluent_data['encryption'] : 'none', 'port' => isset( $fluent_data['port'] ) ? $fluent_data['port'] : 25, 'auth' => isset( $fluent_data['auth'] ) && $fluent_data['auth'] === 'yes', 'user' => isset( $fluent_data['username'] ) ? $fluent_data['username'] : '', 'pass' => isset( $fluent_data['password'] ) ? $fluent_data['password'] : '', 'autotls' => isset( $fluent_data['auto_tls'] ) && $fluent_data['auto_tls'] === 'yes', ]; break; case 'amazonses': $data['amazonses'] = [ 'client_id' => isset( $fluent_data['access_key'] ) ? $fluent_data['access_key'] : '', 'client_secret' => isset( $fluent_data['secret_key'] ) ? $fluent_data['secret_key'] : '', 'region' => isset( $fluent_data['region'] ) ? $fluent_data['region'] : '', ]; break; case 'mailgun': $data['mailgun'] = [ 'api_key' => isset( $fluent_data['api_key'] ) ? $fluent_data['api_key'] : '', 'domain' => isset( $fluent_data['domain_name'] ) ? $fluent_data['domain_name'] : '', 'region' => isset( $fluent_data['region'] ) && in_array( $fluent_data['region'], [ 'us', 'eu' ], true ) ? strtoupper( $fluent_data['region'] ) : '', ]; break; case 'sendgrid': $data['sendgrid'] = [ 'api_key' => isset( $fluent_data['api_key'] ) ? $fluent_data['api_key'] : '', ]; break; case 'sendinblue': $data['sendinblue'] = [ 'api_key' => isset( $fluent_data['api_key'] ) ? $fluent_data['api_key'] : '', ]; break; case 'sparkpost': $data['sparkpost'] = [ 'api_key' => isset( $fluent_data['api_key'] ) ? $fluent_data['api_key'] : '', ]; break; case 'postmark': $data['postmark'] = [ 'api_key' => isset( $fluent_data['api_key'] ) ? $fluent_data['api_key'] : '', 'message_stream' => isset( $fluent_data['message_stream'] ) ? $fluent_data['message_stream'] : '', ]; break; case 'outlook': $data['outlook'] = [ 'client_id' => isset( $fluent_data['client_id'] ) ? $fluent_data['client_id'] : '', 'client_secret' => isset( $fluent_data['client_secret'] ) ? $fluent_data['client_secret'] : '', ]; break; } return $data; } /** * Check if Post SMTP Mailer plugin settings are present and extract them. * * @since 2.6.0 * * @return array */ private function get_post_smtp_mailer() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded $options = get_option( 'postman_options' ); if ( empty( $options ) ) { return []; } $allowed_mailers = [ 'smtp' => 'smtp', 'gmail_api' => 'gmail', 'sendgrid_api' => 'sendgrid', 'mailgun_api' => 'mailgun', ]; $data = [ 'mail' => [ 'mailer' => ( isset( $options['transport_type'] ) && in_array( $options['transport_type'], array_keys( $allowed_mailers ), true ) ) ? $allowed_mailers[ $options['transport_type'] ] : 'mail', 'from_email' => isset( $options['sender_email'] ) ? $options['sender_email'] : '', 'from_name' => isset( $options['sender_name'] ) ? $options['sender_name'] : '', ], 'smtp' => [ 'host' => isset( $options['hostname'] ) ? $options['hostname'] : '', 'encryption' => isset( $options['enc_type'] ) ? $options['enc_type'] : 'none', 'port' => isset( $options['port'] ) ? $options['port'] : 25, 'auth' => isset( $options['auth_type'] ) && $options['auth_type'] !== 'none', 'user' => isset( $options['basic_auth_username'] ) ? $options['basic_auth_username'] : '', 'pass' => ! empty( $options['basic_auth_password'] ) ? base64_decode( $options['basic_auth_password'] ) : '', // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode 'autotls' => true, ], 'gmail' => [ 'client_id' => isset( $options['oauth_client_id'] ) ? $options['oauth_client_id'] : '', 'client_secret' => isset( $options['oauth_client_secret'] ) ? $options['oauth_client_secret'] : '', ], 'sendgrid' => [ 'api_key' => ! empty( $options['sendgrid_api_key'] ) ? base64_decode( $options['sendgrid_api_key'] ) : '', // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode ], 'mailgun' => [ 'api_key' => ! empty( $options['mailgun_api_key'] ) ? base64_decode( $options['mailgun_api_key'] ) : '', // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode 'domain' => isset( $options['mailgun_domain_name'] ) ? $options['mailgun_domain_name'] : '', 'region' => ( isset( $options['mailgun_region'] ) && ! empty( $options['mailgun_region'] ) ) ? 'EU' : 'US', ], ]; if ( class_exists( '\PostmanOptions' ) ) { $pm_options = \PostmanOptions::getInstance(); $data['sendgrid']['api_key'] = $pm_options->getSendGridApiKey(); $data['mailgun']['api_key'] = $pm_options->getMailgunApiKey(); $data['smtp']['pass'] = $pm_options->getPassword(); } return $data; } /** * Check if SMTP Mailer plugin settings are present and extract them. * * @since 2.6.0 * * @return array */ private function get_smtp_mailer() { $options = get_option( 'smtp_mailer_options' ); if ( empty( $options ) ) { return []; } return [ 'mail' => [ 'mailer' => 'smtp', 'from_email' => isset( $options['from_email'] ) ? $options['from_email'] : '', 'from_name' => isset( $options['from_name'] ) ? $options['from_name'] : '', ], 'smtp' => [ 'host' => isset( $options['smtp_host'] ) ? $options['smtp_host'] : '', 'encryption' => isset( $options['type_of_encryption'] ) ? $options['type_of_encryption'] : 'none', 'port' => isset( $options['smtp_port'] ) ? $options['smtp_port'] : 25, 'auth' => isset( $options['smtp_auth'] ) && $options['smtp_auth'] === 'true', 'user' => isset( $options['smtp_username'] ) ? $options['smtp_username'] : '', 'pass' => ! empty( $options['smtp_password'] ) ? base64_decode( $options['smtp_password'] ) : '', // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode 'autotls' => true, ], ]; } /** * Check if WP SMTP plugin settings are present and extract them. * * @since 2.6.0 * * @return array */ private function get_wp_smtp() { $options = get_option( 'wp_smtp_options' ); if ( empty( $options ) ) { return []; } return [ 'mail' => [ 'mailer' => 'smtp', 'from_email' => isset( $options['from'] ) ? $options['from'] : '', 'from_name' => isset( $options['fromname'] ) ? $options['fromname'] : '', ], 'smtp' => [ 'host' => isset( $options['host'] ) ? $options['host'] : '', 'encryption' => ! empty( $options['smtpsecure'] ) ? $options['smtpsecure'] : 'none', 'port' => isset( $options['port'] ) ? $options['port'] : 25, 'auth' => isset( $options['smtpauth'] ) && $options['smtpauth'] === 'yes', 'user' => isset( $options['username'] ) ? $options['username'] : '', 'pass' => isset( $options['password'] ) ? $options['password'] : '', 'autotls' => true, ], ]; } } Crypto.php 0000644 00000012116 15253205667 0006551 0 ustar 00 <?php namespace WPMailSMTP\Helpers; /** * Class for encryption functionality. * * @since 2.5.0 * * @link https://www.php.net/manual/en/intro.sodium.php */ class Crypto { /** * Get a secret key for encrypt/decrypt. * * @since 2.5.0 * * @param bool $create Should the key be created, if it does not exist yet. * * @return string|bool */ public static function get_secret_key( $create = false ) { if ( defined( 'WPMS_CRYPTO_KEY' ) ) { return WPMS_CRYPTO_KEY; } $secret_key = apply_filters( 'wp_mail_smtp_helpers_crypto_get_secret_key', get_option( 'wp_mail_smtp_mail_key' ) ); // If we already have the secret, send it back. if ( false !== $secret_key ) { return base64_decode( $secret_key ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode } if ( $create ) { // We don't have a secret, so let's generate one. try { $secret_key = sodium_crypto_secretbox_keygen(); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_crypto_secretbox_keygenFound } catch ( \Exception $e ) { $secret_key = wp_generate_password( SODIUM_CRYPTO_SECRETBOX_KEYBYTES ); // phpcs:ignore PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_keybytesFound } add_option( 'wp_mail_smtp_mail_key', base64_encode( $secret_key ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode return $secret_key; } return false; } /** * Encrypt a message. * * @since 2.5.0 * * @param string $message Message to encrypt. * @param string $key Encryption key. * * @return string * @throws \Exception The exception object. */ public static function encrypt( $message, $key = '' ) { if ( apply_filters( 'wp_mail_smtp_helpers_crypto_stop', false ) ) { return $message; } // Create a nonce for this operation. It will be stored and recovered in the message itself. // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.random_bytesFound, PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_noncebytesFound $nonce = random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ); if ( empty( $key ) ) { $key = self::get_secret_key( true ); } // Encrypt message and combine with nonce. $cipher = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $nonce . sodium_crypto_secretbox( // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_crypto_secretboxFound $message, $nonce, $key ) ); try { sodium_memzero( $message ); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_memzeroFound sodium_memzero( $key ); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_memzeroFound } catch ( \Exception $e ) { return $cipher; } return $cipher; } /** * Decrypt a message. * Returns encrypted message on any failure and the decrypted message on success. * * @since 2.5.0 * * @param string $encrypted Encrypted message. * @param string $key Encryption key. * * @return string * @throws \Exception The exception object. */ public static function decrypt( $encrypted, $key = '' ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh if ( apply_filters( 'wp_mail_smtp_helpers_crypto_stop', false ) ) { return $encrypted; } // Unpack base64 message. $decoded = base64_decode( $encrypted ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode if ( false === $decoded ) { return $encrypted; } // Include polyfill if mbstring PHP extension is not enabled. if ( ! function_exists( 'mb_strlen' ) || ! function_exists( 'mb_substr' ) ) { Helpers::include_mbstring_polyfill(); } // phpcs:ignore PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_noncebytesFound, PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_macbytesFound if ( mb_strlen( $decoded, '8bit' ) < ( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES ) ) { return $encrypted; } // Pull nonce and ciphertext out of unpacked message. $nonce = mb_substr( $decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit' ); // phpcs:ignore PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_noncebytesFound $ciphertext = mb_substr( $decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit' ); // phpcs:ignore PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_noncebytesFound $key = empty( $key ) ? self::get_secret_key() : $key; if ( empty( $key ) ) { return $encrypted; } // Decrypt it. $message = sodium_crypto_secretbox_open( // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_crypto_secretbox_openFound $ciphertext, $nonce, $key ); // Check for decryption failures. if ( false === $message ) { return $encrypted; } try { sodium_memzero( $ciphertext ); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_memzeroFound sodium_memzero( $key ); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sodium_memzeroFound } catch ( \Exception $e ) { return $message; } return $message; } }
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings