Initial commit

This commit is contained in:
2026-07-29 22:52:47 +05:00
commit cb5a058984
13 changed files with 2064 additions and 0 deletions
+96
View File
@@ -0,0 +1,96 @@
<?php
/**
* AJAX-обработчики: health-check прокси.
*
* @package AI_Proxy_Manager
*/
defined( 'ABSPATH' ) || exit;
/**
* Класс AJAX-обработчиков плагина.
*
* @since 1.0.0
*/
class AIPMSP_Ajax {
/**
* Конструктор: регистрирует AJAX-экшены.
*
* @since 1.0.0
*/
public function __construct() {
add_action( 'wp_ajax_aipmsp_check_proxy', array( $this, 'check_proxy' ) );
}
/**
* Проверяет один прокси по запросу из админки.
*
* @since 1.0.0
*
* @return void
*/
public function check_proxy() {
// Проверка nonce и прав.
check_ajax_referer( 'aipmsp_ajax_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error(
array( 'message' => __( 'Недостаточно прав.', 'ai-proxy-manager' ) ),
403
);
}
$ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
$port = isset( $_POST['port'] ) ? absint( wp_unslash( $_POST['port'] ) ) : 0;
$type = isset( $_POST['type'] ) ? AIPMSP_Proxy::sanitize_type( wp_unslash( $_POST['type'] ) ) : 'http';
$valid_host = filter_var( $ip, FILTER_VALIDATE_IP ) || AIPMSP_Proxy::is_valid_host( $ip );
if ( ! $valid_host || $port < 1 || $port > 65535 ) {
wp_send_json_error(
array( 'message' => __( 'Некорректный адрес или порт прокси.', 'ai-proxy-manager' ) )
);
}
// Находим прокси в сохранённых настройках, чтобы взять зашифрованный пароль/логин.
$settings = AIPMSP_Proxy::get_settings();
$proxy = null;
foreach ( $settings['proxies'] as $candidate ) {
if ( $candidate['ip'] === $ip && (int) $candidate['port'] === $port ) {
$proxy = $candidate;
break;
}
}
if ( null === $proxy ) {
// Прокси ещё не сохранён — проверяем без авторизации.
$proxy = array(
'ip' => $ip,
'port' => $port,
'type' => $type,
'user' => '',
'pass' => '',
);
}
$result = AIPMSP_Proxy::health_check( $proxy );
if ( $result['success'] ) {
wp_send_json_success(
array(
'message' => $result['message'],
'time' => $result['time'],
)
);
}
wp_send_json_error(
array(
'message' => $result['message'],
'time' => $result['time'],
)
);
}
}