[]], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOCK_EX); } function get_apix_data() { global $data_file; if (!file_exists($data_file)) { return ['apis' => []]; } $content = @file_get_contents($data_file); $json = json_decode($content, true); return is_array($json) ? $json : ['apis' => []]; } function save_apix_data($data) { global $data_file; return @file_put_contents($data_file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOCK_EX) !== false; } // Helper: Determine Current Base URL function get_current_base_url() { $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $script = $_SERVER['SCRIPT_NAME'] ?? '/APIX.php'; return $protocol . $host . $script; } // ========================================================================= // 1. PUBLIC PROXY ENDPOINT HANDLER (Runs when 'api' or 'endpoint' is passed) // ========================================================================= $requested_api = $_GET['api'] ?? $_GET['endpoint'] ?? $_POST['api'] ?? $_POST['endpoint'] ?? null; if (!empty($requested_api)) { $query = $_GET['q'] ?? $_GET['query'] ?? $_GET['num'] ?? $_POST['q'] ?? $_POST['query'] ?? ''; $data = get_apix_data(); $slug = strtolower(trim($requested_api)); if (!isset($data['apis'][$slug])) { header('Content-Type: application/json; charset=UTF-8'); http_response_code(404); echo json_encode(['status' => false, 'error' => 'API endpoint not found.'], JSON_PRETTY_PRINT); exit; } $api_info = $data['apis'][$slug]; if (empty($api_info['is_active'])) { header('Content-Type: application/json; charset=UTF-8'); http_response_code(403); echo json_encode(['status' => false, 'error' => 'API endpoint is currently disabled.'], JSON_PRETTY_PRINT); exit; } $target_template = trim($api_info['target_url']); if (empty($target_template)) { header('Content-Type: application/json; charset=UTF-8'); http_response_code(500); echo json_encode(['status' => false, 'error' => 'Target API URL is not configured.'], JSON_PRETTY_PRINT); exit; } // Build the target URL if (strpos($target_template, '{query}') !== false) { $final_url = str_replace('{query}', urlencode($query), $target_template); } elseif (strpos($target_template, '{value}') !== false) { $final_url = str_replace('{value}', urlencode($query), $target_template); } elseif (strpos($target_template, '{q}') !== false) { $final_url = str_replace('{q}', urlencode($query), $target_template); } else { // Append query parameter if template ends with = or ? if (substr($target_template, -1) === '=' || substr($target_template, -1) === '?') { $final_url = $target_template . urlencode($query); } else { $sep = (strpos($target_template, '?') !== false) ? '&' : '?'; $final_url = $target_template . $sep . 'q=' . urlencode($query); } } // Perform Server-Side cURL Request (Hides third-party IP/domain completely) $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $final_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 APIX/1.0'); // Forward custom headers if needed curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json, text/plain, */*' ]); $raw_response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $curl_error = curl_error($ch); curl_close($ch); if ($raw_response === false) { // Fallback attempt with stream context $opts = [ 'http' => [ 'method' => 'GET', 'timeout' => 20, 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)\r\nAccept: */*\r\n" ] ]; $context = stream_context_create($opts); $stream_resp = @file_get_contents($final_url, false, $context); if ($stream_resp !== false) { $raw_response = $stream_resp; } else { $last_err = error_get_last(); header('Content-Type: application/json; charset=UTF-8'); http_response_code(502); echo json_encode([ 'status' => false, 'error' => 'Gateway error: Target server connection refused/blocked.', 'curl_msg' => $curl_error, 'stream_msg' => $last_err['message'] ?? 'Connection failed', 'note' => 'Hosting server firewall may be blocking outgoing port 3000, or 56.124.98.201 is blocking hosting server IP (54.39.160.85).' ], JSON_PRETTY_PRINT); exit; } } // Apply "Hide Word" Filter / Masking $clean_response = $raw_response; $hide_words = $api_info['hide_words'] ?? []; $replace_with = $api_info['replace_with'] ?? ''; if (!empty($hide_words) && is_array($hide_words)) { foreach ($hide_words as $word) { $word = trim($word); if ($word !== '') { // Case-insensitive word/pattern replacement $clean_response = str_ireplace($word, $replace_with, $clean_response); } } } // Track hit counter $data['apis'][$slug]['hits'] = ($data['apis'][$slug]['hits'] ?? 0) + 1; save_apix_data($data); // Set Response Headers if ($content_type) { header('Content-Type: ' . $content_type); } else { header('Content-Type: application/json; charset=UTF-8'); } header('Access-Control-Allow-Origin: *'); header('X-Powered-By: APIX-Engine'); echo $clean_response; exit; } // ========================================================================= // 2. AUTHENTICATION & SESSION MANAGEMENT (PIN Verification) // ========================================================================= $auth_error = ''; // Handle PIN Login if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'login') { $entered_pin = trim($_POST['pin'] ?? ''); // Server-Side Hash Verification if (hash_equals(APIX_PIN_HASH, hash('sha256', $entered_pin))) { $_SESSION['apix_auth'] = true; $_SESSION['apix_login_time'] = time(); header('Location: ' . $_SERVER['PHP_SELF']); exit; } else { $auth_error = 'गलत PIN (Incorrect PIN). कृपया पुनः प्रयास करें।'; } } // Handle Logout if (isset($_GET['action']) && $_GET['action'] === 'logout') { unset($_SESSION['apix_auth']); session_destroy(); header('Location: ' . $_SERVER['PHP_SELF']); exit; } $is_authenticated = !empty($_SESSION['apix_auth']); // ========================================================================= // 3. ADMIN ACTIONS (Only accessible when authenticated) // ========================================================================= if ($is_authenticated && $_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; $data = get_apix_data(); // Add New API if ($action === 'add_api') { $name = trim($_POST['api_name'] ?? ''); $slug = strtolower(preg_replace('/[^a-zA-Z0-9_\-]/', '', trim($_POST['api_slug'] ?? ''))); $target_url = trim($_POST['target_url'] ?? ''); $hide_words_raw = trim($_POST['hide_words'] ?? ''); $replace_with = trim($_POST['replace_with'] ?? ''); if (empty($slug)) { $slug = 'api_' . substr(md5(time() . rand(100, 999)), 0, 6); } if (!empty($name) && !empty($target_url)) { $hide_words_array = []; if (!empty($hide_words_raw)) { $lines = preg_split('/[\r\n,]+/', $hide_words_raw); foreach ($lines as $l) { $l = trim($l); if ($l !== '') { $hide_words_array[] = $l; } } } $data['apis'][$slug] = [ 'id' => $slug, 'name' => $name, 'slug' => $slug, 'target_url' => $target_url, 'hide_words' => array_values(array_unique($hide_words_array)), 'replace_with' => $replace_with, 'is_active' => true, 'hits' => 0, 'created_at' => time() ]; save_apix_data($data); $_SESSION['apix_flash'] = ['type' => 'success', 'msg' => "API '{$name}' सफलतापूर्वक जोड़ दी गई!"]; } else { $_SESSION['apix_flash'] = ['type' => 'danger', 'msg' => 'API Name और Target URL दोनों अनिवार्य हैं।']; } header('Location: ' . $_SERVER['PHP_SELF']); exit; } // Edit Existing API if ($action === 'edit_api') { $slug = trim($_POST['api_slug'] ?? ''); if (isset($data['apis'][$slug])) { $name = trim($_POST['api_name'] ?? ''); $target_url = trim($_POST['target_url'] ?? ''); $hide_words_raw = trim($_POST['hide_words'] ?? ''); $replace_with = trim($_POST['replace_with'] ?? ''); if (!empty($name) && !empty($target_url)) { $hide_words_array = []; if (!empty($hide_words_raw)) { $lines = preg_split('/[\r\n,]+/', $hide_words_raw); foreach ($lines as $l) { $l = trim($l); if ($l !== '') { $hide_words_array[] = $l; } } } $data['apis'][$slug]['name'] = $name; $data['apis'][$slug]['target_url'] = $target_url; $data['apis'][$slug]['hide_words'] = array_values(array_unique($hide_words_array)); $data['apis'][$slug]['replace_with'] = $replace_with; save_apix_data($data); $_SESSION['apix_flash'] = ['type' => 'success', 'msg' => "API '{$name}' सफलतापूर्वक अपडेट हो गई!"]; } } header('Location: ' . $_SERVER['PHP_SELF']); exit; } // Delete API if ($action === 'delete_api') { $slug = trim($_POST['api_slug'] ?? ''); if (isset($data['apis'][$slug])) { $name = $data['apis'][$slug]['name']; unset($data['apis'][$slug]); save_apix_data($data); $_SESSION['apix_flash'] = ['type' => 'success', 'msg' => "API '{$name}' डिलीट कर दी गई।"]; } header('Location: ' . $_SERVER['PHP_SELF']); exit; } // Toggle Status if ($action === 'toggle_api') { $slug = trim($_POST['api_slug'] ?? ''); if (isset($data['apis'][$slug])) { $data['apis'][$slug]['is_active'] = empty($data['apis'][$slug]['is_active']); save_apix_data($data); $status_txt = $data['apis'][$slug]['is_active'] ? 'सक्रिय (Active)' : 'निष्क्रिय (Disabled)'; $_SESSION['apix_flash'] = ['type' => 'info', 'msg' => "API '{$data['apis'][$slug]['name']}' अब {$status_txt} है।"]; } header('Location: ' . $_SERVER['PHP_SELF']); exit; } // AJAX Endpoint to safely fetch raw target URL for edit modal (Session protected) if ($action === 'get_api_details') { header('Content-Type: application/json; charset=UTF-8'); $slug = trim($_POST['api_slug'] ?? ''); if (isset($data['apis'][$slug])) { echo json_encode(['status' => true, 'api' => $data['apis'][$slug]]); } else { echo json_encode(['status' => false, 'error' => 'Not found']); } exit; } } // Flash messages $flash = $_SESSION['apix_flash'] ?? null; unset($_SESSION['apix_flash']); $base_endpoint_url = get_current_base_url(); $data = get_apix_data(); $api_list = $data['apis'] ?? []; $total_apis = count($api_list); $active_apis = count(array_filter($api_list, function($item) { return !empty($item['is_active']); })); $total_hits = array_sum(array_column($api_list, 'hits')); ?> APIX Engine - Smart API Proxy & Masking Manager

APIX Engine

सुरक्षित API प्रॉक्सी & मास्किंग पोर्टल

कुल API एंडपॉइंट्स

सक्रिय (Active) APIs

कुल प्रॉक्सी रिक्वेस्ट्स

आपकी प्रबंधित APIs (Configured Endpoints)

कोई API अभी तक नहीं जोड़ी गई है

ऊपर दिए गए 'Add New API' बटन पर क्लिक करके किसी भी API को अपना बनायें।

$api): ?>
/ Active Disabled
Your Own URL:
{QUERY}
Target URL:
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Hiding Words:
➔ Replaced with: "" ➔ (Word Completely Removed)