diff --git a/admin/class-baskerville-admin.php b/admin/class-baskerville-admin.php index a5d3db7..b53a93f 100644 --- a/admin/class-baskerville-admin.php +++ b/admin/class-baskerville-admin.php @@ -285,6 +285,15 @@ public function add_admin_menu() { array($this, 'admin_page_turnstile') ); + add_submenu_page( + 'baskerville-settings', + esc_html__('Pay-Per-Crawl', 'baskerville-ai-security'), + esc_html__('Pay-Per-Crawl', 'baskerville-ai-security'), + 'manage_options', + 'baskerville-pay-per-crawl', + array($this, 'admin_page_pay_per_crawl') + ); + add_submenu_page( 'baskerville-settings', esc_html__('Analytics', 'baskerville-ai-security'), @@ -335,6 +344,11 @@ public function admin_page_turnstile() { $this->admin_page(); } + public function admin_page_pay_per_crawl() { + $_GET['tab'] = 'pay-per-crawl'; + $this->admin_page(); + } + public function admin_page_analytics() { $_GET['tab'] = 'analytics'; $this->admin_page(); @@ -769,6 +783,120 @@ public function sanitize_settings($input) { $sanitized['turnstile_borderline_max'] = isset($existing['turnstile_borderline_max']) ? $existing['turnstile_borderline_max'] : 70; } + // Pay-per-crawl settings + $is_pay_tab = isset($input['pay_per_crawl_tab']); + $sanitized['pay_enabled'] = isset($input['pay_enabled']) + ? (bool) $input['pay_enabled'] + : ($is_pay_tab ? false : (isset($existing['pay_enabled']) ? $existing['pay_enabled'] : false)); + + if (isset($input['pay_mode'])) { + $mode = sanitize_text_field($input['pay_mode']); + $sanitized['pay_mode'] = in_array($mode, ['off', 'test', 'observe', 'enforce'], true) ? $mode : 'off'; + } elseif (isset($existing['pay_mode'])) { + $sanitized['pay_mode'] = $existing['pay_mode']; + } + + if (isset($input['pay_ai_threshold'])) { + $sanitized['pay_ai_threshold'] = max(0, min(100, (int) $input['pay_ai_threshold'])); + } elseif (isset($existing['pay_ai_threshold'])) { + $sanitized['pay_ai_threshold'] = $existing['pay_ai_threshold']; + } + + if (isset($input['pay_protected_paths'])) { + $sanitized['pay_protected_paths'] = sanitize_textarea_field($input['pay_protected_paths']); + } elseif (isset($existing['pay_protected_paths'])) { + $sanitized['pay_protected_paths'] = $existing['pay_protected_paths']; + } + + if (isset($input['pay_wallet_address'])) { + $wallet = sanitize_text_field($input['pay_wallet_address']); + // Basic 0x address validation + if ($wallet && !preg_match('/^0x[0-9a-fA-F]{40}$/', $wallet)) { + $wallet = ''; + } + $sanitized['pay_wallet_address'] = $wallet; + } elseif (isset($existing['pay_wallet_address'])) { + $sanitized['pay_wallet_address'] = $existing['pay_wallet_address']; + } + + if (isset($input['pay_price'])) { + $price = sanitize_text_field($input['pay_price']); + if (!is_numeric($price) || (float) $price < 0) { + $price = '0.10'; + } + $sanitized['pay_price'] = $price; + } elseif (isset($existing['pay_price'])) { + $sanitized['pay_price'] = $existing['pay_price']; + } + + if (isset($input['pay_currency'])) { + $sanitized['pay_currency'] = sanitize_text_field($input['pay_currency']); + } elseif (isset($existing['pay_currency'])) { + $sanitized['pay_currency'] = $existing['pay_currency']; + } + + if (isset($input['pay_network'])) { + $sanitized['pay_network'] = sanitize_text_field($input['pay_network']); + } elseif (isset($existing['pay_network'])) { + $sanitized['pay_network'] = $existing['pay_network']; + } + + if (isset($input['pay_asset_type'])) { + $type = sanitize_text_field($input['pay_asset_type']); + $sanitized['pay_asset_type'] = in_array($type, ['native', 'erc20'], true) ? $type : 'erc20'; + } elseif (isset($existing['pay_asset_type'])) { + $sanitized['pay_asset_type'] = $existing['pay_asset_type']; + } + + if (isset($input['pay_token_contract'])) { + $sanitized['pay_token_contract'] = sanitize_text_field($input['pay_token_contract']); + } elseif (isset($existing['pay_token_contract'])) { + $sanitized['pay_token_contract'] = $existing['pay_token_contract']; + } + + if (isset($input['pay_token_decimals'])) { + $sanitized['pay_token_decimals'] = max(0, min(18, (int) $input['pay_token_decimals'])); + } elseif (isset($existing['pay_token_decimals'])) { + $sanitized['pay_token_decimals'] = $existing['pay_token_decimals']; + } + + if (isset($input['pay_verifier_type'])) { + $vtype = sanitize_text_field($input['pay_verifier_type']); + $sanitized['pay_verifier_type'] = in_array($vtype, ['stub', 'polling'], true) ? $vtype : 'stub'; + } elseif (isset($existing['pay_verifier_type'])) { + $sanitized['pay_verifier_type'] = $existing['pay_verifier_type']; + } + + if (isset($input['pay_provider'])) { + $sanitized['pay_provider'] = sanitize_text_field($input['pay_provider']); + } elseif (isset($existing['pay_provider'])) { + $sanitized['pay_provider'] = $existing['pay_provider']; + } + + if (isset($input['pay_api_key'])) { + $sanitized['pay_api_key'] = sanitize_text_field($input['pay_api_key']); + } elseif (isset($existing['pay_api_key'])) { + $sanitized['pay_api_key'] = $existing['pay_api_key']; + } + + if (isset($input['pay_min_confirmations'])) { + $sanitized['pay_min_confirmations'] = max(1, min(100, (int) $input['pay_min_confirmations'])); + } elseif (isset($existing['pay_min_confirmations'])) { + $sanitized['pay_min_confirmations'] = $existing['pay_min_confirmations']; + } + + if (isset($input['pay_challenge_ttl'])) { + $sanitized['pay_challenge_ttl'] = max(300, min(86400, (int) $input['pay_challenge_ttl'])); + } elseif (isset($existing['pay_challenge_ttl'])) { + $sanitized['pay_challenge_ttl'] = $existing['pay_challenge_ttl']; + } + + if (isset($input['pay_grant_ttl'])) { + $sanitized['pay_grant_ttl'] = max(60, min(86400, (int) $input['pay_grant_ttl'])); + } elseif (isset($existing['pay_grant_ttl'])) { + $sanitized['pay_grant_ttl'] = $existing['pay_grant_ttl']; + } + // Flush rewrite rules when settings are saved (for honeypot route) flush_rewrite_rules(); @@ -3133,6 +3261,7 @@ public function admin_page() { $burst_protection_enabled = isset($options['burst_protection_enabled']) ? $options['burst_protection_enabled'] : true; $api_rate_limit_enabled = isset($options['api_rate_limit_enabled']) ? $options['api_rate_limit_enabled'] : true; $turnstile_enabled = isset($options['turnstile_enabled']) ? $options['turnstile_enabled'] : false; + $pay_enabled = !empty($options['pay_enabled']); ?>
You successfully paid to access this page via the Baskerville x402 paywall.
+