Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
<?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;
}
}

View File

@@ -0,0 +1,41 @@
<?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';
}
}

View File

@@ -0,0 +1,170 @@
<?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',
],
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 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';
}
}

View File

@@ -0,0 +1,323 @@
<?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,
],
];
}
}

View File

@@ -0,0 +1,69 @@
<?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
}
}