Repository navigation
Expand file tree
/
Copy pathapi_instructions.php
More file actions
290 lines (254 loc) · 16.7 KB
/
Copy pathapi_instructions.php
File metadata and controls
290 lines (254 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
require 'config.php';
require_auth();
header('X-Robots-Tag: noindex, nofollow');
$apiKey = defined('API_KEY') ? API_KEY : '';
$isDefaultKey = ($apiKey === 'change_me_to_a_random_string');
$apiUrl = BASE_URL . '/api.php';
$proxyUrl = BASE_URL . '/api_console_proxy.php';
$csrfToken = csrf_token();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex, nofollow">
<title>API Docs & Console | Tuxxin QR Track</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Recursive:wght@300..900&display=swap" rel="stylesheet">
<style>
:root { --bg: #121212; --card: #1e1e1e; --text: #e0e0e0; --accent: #ff6600; --border: #333; --code-bg: #151515; --danger: #ff4444; }
body { font-family: 'Recursive', sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; line-height: 1.6; }
.container { max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 30px; }
header { grid-column: 1 / -1; border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
h1 { color: var(--accent); margin: 0; }
h2 { border-left: 4px solid var(--accent); padding-left: 10px; margin-top: 30px; color: #fff; }
.doc-section { background: var(--card); padding: 25px; border-radius: 8px; border: 1px solid var(--border); }
.console-section { background: #181818; padding: 25px; border-radius: 8px; border: 1px solid var(--border); position: sticky; top: 20px; height: fit-content; }
.alert-danger { grid-column: 1 / -1; background: rgba(255,68,68,0.1); border: 1px solid var(--danger); padding: 20px; border-radius: 8px; text-align: center; margin-bottom: 20px; }
.alert-danger h3 { color: var(--danger); margin-top: 0; }
pre { background: var(--code-bg); padding: 15px; border-radius: 5px; overflow-x: auto; border: 1px solid #333; color: #a5d6a7; font-size: 0.9em; margin: 0; }
code { font-family: 'Courier New', monospace; color: #ff9e42; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 4px; font-size: 0.75em; font-weight: bold; background: #333; cursor: pointer; border: 1px solid transparent; transition: 0.2s; }
.badge:hover { border-color: var(--accent); color: white; }
label { display: block; margin: 12px 0 5px; color: #888; font-size: 0.85em; text-transform: uppercase; letter-spacing: 1px; }
input, select, textarea { width: 100%; padding: 10px; background: #222; border: 1px solid #444; color: white; border-radius: 4px; box-sizing: border-box; font-family: 'Courier New', monospace; }
button { background: var(--accent); color: white; border: none; padding: 12px; width: 100%; cursor: pointer; font-weight: bold; border-radius: 4px; margin-top: 20px; }
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 100; align-items: center; justify-content: center; }
.modal-content { background: var(--card); padding: 30px; border-radius: 10px; width: 90%; max-width: 600px; position: relative; border: 1px solid var(--border); }
.close-btn { position: absolute; top: 15px; right: 20px; color: #fff; cursor: pointer; font-size: 1.5em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.keygen-box { background: #222; border: 1px solid var(--accent); padding: 15px; border-radius: 5px; margin-bottom: 25px; text-align: center; }
.keygen-val { font-family: monospace; font-size: 1.1em; color: var(--accent); display: block; margin: 10px 0; word-break: break-all; }
.btn-copy { background: #444; color: white; border: none; padding: 5px 10px; border-radius: 3px; cursor: pointer; font-size: 0.8em; }
.back-btn { color: white; text-decoration: none; background: var(--accent); padding: 9px 18px; border-radius: 4px; font-weight: bold; display: inline-block; }
.back-btn:hover { opacity: 0.85; }
</style>
</head>
<body>
<div class="container">
<header>
<div>
<h1>API Documentation</h1>
<small style="color:#888;">Endpoint: <?= htmlspecialchars($apiUrl) ?></small>
</div>
<div><a href="<?= htmlspecialchars(BASE_URL) ?>" class="back-btn">← Back to Dashboard</a></div>
</header>
<?php if ($isDefaultKey): ?>
<div class="alert-danger">
<h3>⚠️ API IS DISABLED</h3>
<p>You are using the default insecure API Key. For security, the API endpoint has been deactivated.</p>
<p>Use the generator below to create a new key, update your <code>config.php</code>, and refresh this page.</p>
<div class="keygen-box" style="max-width:500px; margin:20px auto; background:#000;">
<strong style="color:white; font-size:0.9em;">GENERATE NEW SECURE KEY</strong>
<span id="newKeyDisplay" class="keygen-val">Click generate below...</span>
<button class="btn-copy" onclick="generateKey()">Generate & Copy</button>
</div>
</div>
<?php else: ?>
<div class="doc-section">
<h2>1. Authentication</h2>
<p>Pass your API key via the <code>X-Api-Key</code> HTTP header on every request. The key is set in <code>config.php</code>.</p>
<pre>X-Api-Key: <your-api-key></pre>
<p style="color:#888; font-size:0.85em;">🔒 The API key is <strong>never</strong> exposed in this page's HTML source. The Live Console sends requests through a server-side proxy.</p>
<h2>2. Endpoints & Payloads</h2>
<div style="display:flex; flex-wrap:wrap; gap:10px; margin-bottom:20px;">
<span class="badge" onclick="showPayload('url')">URL</span>
<span class="badge" onclick="showPayload('wifi')">WiFi</span>
<span class="badge" onclick="showPayload('vcard')">vCard</span>
<span class="badge" onclick="showPayload('sms')">SMS</span>
<span class="badge" onclick="showPayload('email')">Email</span>
<span class="badge" onclick="showPayload('phone')">Phone</span>
<span class="badge" onclick="showPayload('map')">Map</span>
<span class="badge" onclick="showPayload('social')">Social</span>
</div>
<h3>GET Endpoints</h3>
<p><strong>List All:</strong> <code>GET /api.php</code></p>
<p><strong>Get Single:</strong> <code>GET /api.php?uuid={uuid}</code></p>
<p><strong>Create:</strong> <code>POST /api.php</code> with JSON body</p>
<h2>3. PHP Example</h2>
<pre>
$ch = curl_init('<?= htmlspecialchars($apiUrl) ?>');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Api-Key: YOUR_API_KEY',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'title' => 'My Link',
'type' => 'url',
'target' => 'https://example.com'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);</pre>
<h2>4. Rate Limiting</h2>
<p>The API enforces a configurable rate limit (default: <?= (int)API_THROTTLE_LIMIT ?> requests per <?= (int)API_THROTTLE_WINDOW ?>s per IP).
Exceeding the limit returns <code>HTTP 429 Too Many Requests</code>. Adjust in <code>config.php</code>.</p>
<div style="margin-top:30px; border-top:1px solid var(--border); padding-top:20px;">
<a href="<?= htmlspecialchars(BASE_URL) ?>" class="back-btn">← Back to Dashboard</a>
</div>
</div>
<div class="console-section">
<h2 style="margin-top:0">Live Console</h2>
<p style="color:#888; font-size:0.8em; margin-top:-10px;">Requests are proxied server-side. Your API key is never sent to the browser.</p>
<form id="apiForm">
<input type="hidden" id="csrfToken" value="<?= htmlspecialchars($csrfToken) ?>">
<label>Action</label>
<select id="apiAction" onchange="toggleConsole()">
<option value="create">Create QR (POST)</option>
<option value="list">List All QRs (GET)</option>
<option value="get">Get Single QR (GET)</option>
</select>
<div id="createWrapper">
<label>Title</label><input type="text" id="qrTitle" placeholder="Reference Name">
<label>Type</label>
<select id="qrType" onchange="toggleTypeFields()">
<option value="url">Website URL</option>
<option value="wifi">WiFi Network</option>
<option value="vcard">vCard Contact</option>
<option value="sms">SMS Message</option>
<option value="email">Email</option>
<option value="phone">Phone Number</option>
<option value="map">Map Location</option>
<option value="social">Social Media</option>
</select>
<div id="f-url" class="field-group"><label>Target URL</label><input type="text" id="in-target" placeholder="https://..."></div>
<div id="f-phone" class="field-group" style="display:none"><label>Phone Number</label><input type="text" id="in-phone" placeholder="+1555..."></div>
<div id="f-wifi" class="field-group" style="display:none">
<label>SSID</label><input type="text" id="in-ssid">
<div class="grid-2">
<div><label>Password</label><input type="text" id="in-pass"></div>
<div><label>Encryption</label><select id="in-enc"><option>WPA</option><option>WEP</option><option>nopass</option></select></div>
</div>
</div>
<div id="f-vcard" class="field-group" style="display:none">
<div class="grid-2">
<div><label>First Name</label><input type="text" id="in-fname"></div>
<div><label>Last Name</label><input type="text" id="in-lname"></div>
</div>
<label>Phone</label><input type="text" id="in-vphone">
<label>Email</label><input type="text" id="in-vemail">
</div>
<div id="f-sms" class="field-group" style="display:none"><label>Phone</label><input type="text" id="in-sphone"><label>Message</label><textarea id="in-sbody"></textarea></div>
<div id="f-email" class="field-group" style="display:none"><label>Email To</label><input type="text" id="in-eaddr"><label>Subject</label><input type="text" id="in-esub"><label>Body</label><textarea id="in-ebody"></textarea></div>
</div>
<div id="getWrapper" style="display:none;">
<label>UUID</label>
<input type="text" id="qrUuid" placeholder="e.g. 5f3a2b...">
</div>
<button type="submit">Send Request</button>
</form>
<label style="margin-top:20px;">Response</label>
<pre id="responseArea" style="min-height:100px;">...</pre>
</div>
<?php endif; ?>
</div>
<div id="payloadModal" class="modal">
<div class="modal-content">
<span class="close-btn" onclick="document.getElementById('payloadModal').style.display='none'">×</span>
<h2 id="modalTitle" style="margin-top:0">JSON Payload</h2>
<pre id="modalCode"></pre>
</div>
</div>
<script>
function generateKey() {
const arr = new Uint8Array(32);
window.crypto.getRandomValues(arr);
const hex = Array.from(arr).map(b => b.toString(16).padStart(2,'0')).join('');
document.getElementById('newKeyDisplay').innerText = hex;
navigator.clipboard.writeText(hex).then(() => alert('New API Key copied to clipboard!'));
}
<?php if (!$isDefaultKey): ?>
const payloads = {
url: { title: "My Link", type: "url", target: "https://google.com" },
map: { title: "Office", type: "map", target: "123 Main St, New York, NY" },
social: { title: "My Facebook", type: "social", target: "https://facebook.com/..." },
phone: { title: "Call Support", type: "phone", phone: "+15550000000" },
wifi: { title: "Guest WiFi", type: "wifi", ssid: "MyNet", pass: "123456", enc: "WPA" },
vcard: { title: "John Doe", type: "vcard", fname: "John", lname: "Doe", phone: "+1555...", email: "john@doe.com", company: "Acme Inc" },
sms: { title: "Text Me", type: "sms", phone: "+1555...", body: "Hello!" },
email: { title: "Email Support",type: "email", email: "help@site.com", subject: "Help", body: "I need help with..." },
};
function showPayload(type) {
document.getElementById('modalTitle').innerText = type.toUpperCase() + ' Payload';
document.getElementById('modalCode').textContent = JSON.stringify(payloads[type], null, 4);
document.getElementById('payloadModal').style.display = 'flex';
}
function toggleConsole() {
const action = document.getElementById('apiAction').value;
document.getElementById('createWrapper').style.display = (action === 'create') ? 'block' : 'none';
document.getElementById('getWrapper').style.display = (action === 'get') ? 'block' : 'none';
}
function toggleTypeFields() {
document.querySelectorAll('.field-group').forEach(el => el.style.display = 'none');
const type = document.getElementById('qrType').value;
if (type === 'url' || type === 'map' || type === 'social') document.getElementById('f-url').style.display = 'block';
else if (type === 'phone') document.getElementById('f-phone').style.display = 'block';
else if (type === 'wifi') document.getElementById('f-wifi').style.display = 'block';
else if (type === 'vcard') document.getElementById('f-vcard').style.display = 'block';
else if (type === 'sms') document.getElementById('f-sms').style.display = 'block';
else if (type === 'email') document.getElementById('f-email').style.display = 'block';
}
document.getElementById('apiForm').addEventListener('submit', async function(e) {
e.preventDefault();
const action = document.getElementById('apiAction').value;
const resultArea = document.getElementById('responseArea');
const csrf = document.getElementById('csrfToken').value;
resultArea.textContent = 'Sending...';
const fd = new FormData();
fd.append('csrf_token', csrf);
if (action === 'list') {
fd.append('method', 'GET');
} else if (action === 'get') {
fd.append('method', 'GET');
fd.append('uuid', document.getElementById('qrUuid').value.trim());
} else {
// create
fd.append('method', 'POST');
const type = document.getElementById('qrType').value;
let payload = { title: document.getElementById('qrTitle').value, type };
if (type === 'url' || type === 'map' || type === 'social') payload.target = document.getElementById('in-target').value;
else if (type === 'phone') payload.phone = document.getElementById('in-phone').value;
else if (type === 'wifi') { payload.ssid = document.getElementById('in-ssid').value; payload.pass = document.getElementById('in-pass').value; payload.enc = document.getElementById('in-enc').value; }
else if (type === 'vcard') { payload.fname = document.getElementById('in-fname').value; payload.lname = document.getElementById('in-lname').value; payload.phone = document.getElementById('in-vphone').value; payload.email = document.getElementById('in-vemail').value; }
else if (type === 'sms') { payload.phone = document.getElementById('in-sphone').value; payload.body = document.getElementById('in-sbody').value; }
else if (type === 'email') { payload.email = document.getElementById('in-eaddr').value; payload.subject = document.getElementById('in-esub').value; payload.body = document.getElementById('in-ebody').value; }
fd.append('payload', JSON.stringify(payload));
}
try {
const res = await fetch('<?= htmlspecialchars($proxyUrl) ?>', { method: 'POST', body: fd });
const json = await res.json();
resultArea.textContent = JSON.stringify(json, null, 4);
} catch (err) {
resultArea.textContent = 'Error: ' + err.message;
}
});
<?php endif; ?>
window.addEventListener('click', function(e) {
if (e.target.classList.contains('modal')) e.target.style.display = 'none';
});
</script>
</body>
</html>