forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudflare.html
More file actions
693 lines (595 loc) · 24.3 KB
/
Copy pathcloudflare.html
File metadata and controls
693 lines (595 loc) · 24.3 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Validate a Cloudflare Stream API token and generate an encrypted cftoken parameter for VDO.Ninja.">
<title>Cloudflare Token Helper | VDO.Ninja</title>
<link rel="icon" href="/media/favicon.ico" sizes="any">
<link rel="icon" type="image/png" sizes="32x32" href="/media/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/media/favicon-16x16.png">
<style>
:root {
--page-bg: #edf2f7;
--panel-bg: rgba(255, 255, 255, 0.92);
--panel-border: rgba(15, 23, 42, 0.08);
--text: #14213d;
--muted: #52607a;
--primary: #1d4ed8;
--primary-hover: #1e40af;
--success-bg: #e8f8ef;
--success-border: #8fd19e;
--success-text: #166534;
--warning-bg: #fff7db;
--warning-border: #f2c96d;
--warning-text: #8a5a00;
--error-bg: #feebee;
--error-border: #f3a7af;
--error-text: #b42318;
--info-bg: #e8f1ff;
--info-border: #9ebeff;
--info-text: #1e3a8a;
--shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, sans-serif;
color: var(--text);
background:
radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 35%),
linear-gradient(to right, rgba(148, 163, 184, 0.16) 1px, transparent 1px),
linear-gradient(to bottom, rgba(148, 163, 184, 0.16) 1px, transparent 1px),
var(--page-bg);
background-size: auto, 18px 18px, 18px 18px, auto;
}
a {
color: var(--primary);
}
a:hover {
color: var(--primary-hover);
}
.page {
display: grid;
grid-template-columns: minmax(320px, 520px) minmax(320px, 1fr);
gap: 28px;
min-height: 100vh;
padding: 28px;
align-items: start;
}
.panel {
background: var(--panel-bg);
border: 1px solid var(--panel-border);
border-radius: 18px;
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
.tool-panel {
padding: 28px;
position: sticky;
top: 24px;
}
.content-panel {
padding: 28px 30px;
}
h1,
h2,
h3 {
margin-top: 0;
}
h1 {
margin-bottom: 12px;
font-size: 2rem;
}
h2 {
margin-top: 28px;
margin-bottom: 12px;
font-size: 1.3rem;
}
h3 {
margin-top: 18px;
margin-bottom: 8px;
font-size: 1rem;
}
p,
li {
color: var(--muted);
line-height: 1.55;
}
.intro {
margin-bottom: 20px;
}
.form-card {
background: rgba(248, 250, 252, 0.9);
border: 1px solid rgba(15, 23, 42, 0.08);
border-radius: 14px;
padding: 18px;
}
label {
display: block;
margin-bottom: 6px;
font-weight: 600;
color: var(--text);
}
.field-note {
margin-top: -8px;
margin-bottom: 14px;
font-size: 0.9rem;
color: var(--muted);
}
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid rgba(15, 23, 42, 0.14);
border-radius: 10px;
font: inherit;
color: var(--text);
background: #fff;
}
input[type="number"] {
max-width: 140px;
}
textarea {
min-height: 132px;
resize: vertical;
}
.actions,
.response-actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-top: 16px;
}
button {
border: none;
border-radius: 999px;
padding: 11px 18px;
font: inherit;
font-weight: 700;
cursor: pointer;
transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:disabled {
cursor: wait;
opacity: 0.7;
}
.primary-button {
background: var(--primary);
color: #fff;
}
.primary-button:hover:not(:disabled) {
background: var(--primary-hover);
}
.secondary-button {
background: rgba(29, 78, 216, 0.1);
color: var(--primary);
}
.secondary-button:hover:not(:disabled) {
background: rgba(29, 78, 216, 0.16);
}
.ghost-button {
background: rgba(15, 23, 42, 0.08);
color: var(--text);
}
.status {
margin-top: 18px;
padding: 14px 16px;
border-radius: 12px;
border: 1px solid transparent;
}
.status.hidden,
.meta.hidden {
display: none;
}
.status strong {
display: block;
margin-bottom: 6px;
}
.status.success {
background: var(--success-bg);
border-color: var(--success-border);
color: var(--success-text);
}
.status.warning {
background: var(--warning-bg);
border-color: var(--warning-border);
color: var(--warning-text);
}
.status.error {
background: var(--error-bg);
border-color: var(--error-border);
color: var(--error-text);
}
.status.info {
background: var(--info-bg);
border-color: var(--info-border);
color: var(--info-text);
}
.meta {
margin-top: 14px;
padding: 14px 16px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.7);
border: 1px solid rgba(15, 23, 42, 0.08);
}
.meta ul {
margin: 0;
padding-left: 18px;
}
.meta li + li {
margin-top: 6px;
}
.output-label {
margin-top: 20px;
margin-bottom: 8px;
}
.hint {
margin-top: 14px;
font-size: 0.92rem;
}
.section-card {
background: rgba(248, 250, 252, 0.72);
border-radius: 14px;
padding: 18px 18px 8px;
border: 1px solid rgba(15, 23, 42, 0.06);
}
code {
font-family: Consolas, monospace;
font-size: 0.95em;
}
@media (max-width: 980px) {
.page {
grid-template-columns: 1fr;
}
.tool-panel {
position: static;
}
}
</style>
</head>
<body>
<div class="page">
<section class="panel tool-panel">
<h1>Cloudflare Token Helper</h1>
<p class="intro">
Validate a Cloudflare API token, confirm it can access Stream live inputs for the selected account,
and then generate an encrypted <code>&cftoken=</code> parameter for VDO.Ninja.
</p>
<div class="form-card">
<label for="userId">Cloudflare Account ID</label>
<input type="text" id="userId" name="userId" autocomplete="userId" spellcheck="false" required>
<p class="field-note">Example: <code>ee168fc4abe50941832645a0a4fd1adf</code></p>
<label for="accessToken">Cloudflare API Token</label>
<input type="password" id="accessToken" autocomplete="accessToken" name="accessToken" required>
<p class="field-note">Use a token with <code>Account -> Stream -> Edit</code>.</p>
<label for="expiration">Hours Until Expiration</label>
<input min="0" type="number" id="expiration" name="expiration" placeholder="Optional">
<p class="field-note">Optional wrapper expiry for the generated <code>cftoken</code>.</p>
<div class="actions">
<button type="button" id="validateButton" class="secondary-button">Validate Token</button>
<button type="button" id="submitButton" class="primary-button">Generate cftoken</button>
</div>
<p class="hint">
Validation checks token status first, then confirms the account can access Cloudflare Stream live inputs.
</p>
</div>
<div id="statusBanner" class="status hidden" role="status" aria-live="polite"></div>
<div id="validationMeta" class="meta hidden"></div>
<label for="response" class="output-label">Generated URL Parameter</label>
<textarea id="response" rows="5" readonly placeholder="Use this with your VDO.Ninja links in place of &meshcast"></textarea>
<div class="response-actions">
<button type="button" id="copyButton" class="ghost-button" disabled>Copy</button>
</div>
</section>
<section class="panel content-panel">
<div class="section-card">
<h2>Why This Exists</h2>
<p>
Cloudflare can create unique WHIP ingest endpoints for each participant, but doing that manually is tedious.
This helper encrypts your Cloudflare credentials into a short URL-safe parameter that VDO.Ninja can use to
create live inputs on demand.
</p>
<p>
The token helper does not replace your Cloudflare permissions. If the API token is inactive, expired,
scoped incorrectly, or pointed at the wrong account, validation will now tell you that before you send links out.
</p>
</div>
<div class="section-card">
<h2>What Validation Checks</h2>
<h3>1. Token status</h3>
<p>
Cloudflare can mark a token as valid but not usable yet if it has a future <code>not_before</code> time.
Validation reports that directly.
</p>
<h3>2. Stream account access</h3>
<p>
The helper also checks the selected account's live input list and reports the current live input count.
That catches the common failures: wrong account ID, missing Stream scope, or an unusable token.
</p>
<h3>3. Better troubleshooting</h3>
<p>
If publish fails later, <code>cloudflare.vdo.ninja</code> now returns the actual Cloudflare API error instead of a generic
JavaScript null-property failure.
</p>
</div>
<div class="section-card">
<h2>Setup Notes</h2>
<p>The Cloudflare account ID is shown in the dashboard on the relevant account overview pages.</p>
<p>
Create an API token from
<a href="https://dash.cloudflare.com/profile/api-tokens" target="_blank" rel="noopener noreferrer">Cloudflare API Tokens</a>
and grant <code>Account -> Stream -> Edit</code>.
</p>
<p>
If you want to inspect Stream live inputs directly, use the
<a href="https://dash.cloudflare.com" target="_blank" rel="noopener noreferrer">Cloudflare dashboard</a>
and open <code>Stream -> Live inputs</code>.
</p>
</div>
<div class="section-card">
<h2>Useful Cloudflare Stream Notes</h2>
<p>
The Stream live inputs API can list how many live inputs already exist, which is useful when cleaning up stale test inputs.
</p>
<p>
Cloudflare also added API support to disable and re-enable live inputs, so you can pause an input without deleting it.
</p>
<p>
References:
<a href="https://developers.cloudflare.com/stream/get-started/" target="_blank" rel="noopener noreferrer">Start a live stream</a>,
<a href="https://developers.cloudflare.com/api/resources/stream/subresources/live_inputs/" target="_blank" rel="noopener noreferrer">Live inputs API</a>,
<a href="https://developers.cloudflare.com/changelog/post/2026-02-24-disable-live-inputs/" target="_blank" rel="noopener noreferrer">Disable or enable live inputs</a>
</p>
</div>
</section>
</div>
<script>
let lastValidation = null;
function setStorage(name, value, hours) {
const now = new Date();
const item = {
value: value,
expiry: now.getTime() + ((hours || 9999) * 60 * 60 * 1000)
};
localStorage.setItem(name, JSON.stringify(item));
}
function getStorage(name) {
const itemStr = localStorage.getItem(name);
if (!itemStr) {
return "";
}
try {
const item = JSON.parse(itemStr);
if (Date.now() > item.expiry) {
localStorage.removeItem(name);
return "";
}
return item.value || "";
} catch (error) {
localStorage.removeItem(name);
return "";
}
}
function getFormData() {
return {
accessToken: (document.getElementById("accessToken").value || "").trim(),
userId: (document.getElementById("userId").value || "").trim(),
expiration: (document.getElementById("expiration").value || "").trim()
};
}
function saveFields(data) {
setStorage("accessToken", data.accessToken);
setStorage("userId", data.userId);
setStorage("expiration", data.expiration);
}
function setBusy(button, label, busy) {
if (!button.dataset.defaultLabel) {
button.dataset.defaultLabel = button.textContent;
}
button.disabled = busy;
button.textContent = busy ? label : button.dataset.defaultLabel;
}
function formatDate(value) {
if (!value) {
return null;
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return value;
}
return date.toLocaleString(undefined, {
dateStyle: "medium",
timeStyle: "short"
});
}
function setStatus(kind, title, lines) {
const banner = document.getElementById("statusBanner");
banner.className = `status ${kind}`;
let html = `<strong>${title}</strong>`;
if (lines && lines.length) {
html += lines.map((line) => `<div>${line}</div>`).join("");
}
banner.innerHTML = html;
}
function renderMeta(items) {
const meta = document.getElementById("validationMeta");
if (!items || !items.length) {
meta.className = "meta hidden";
meta.innerHTML = "";
return;
}
meta.className = "meta";
meta.innerHTML = `<ul>${items.map((item) => `<li>${item}</li>`).join("")}</ul>`;
}
function resetValidationState() {
lastValidation = null;
renderMeta([]);
}
function buildValidationMeta(validation) {
const items = [];
if (validation.token && validation.token.status) {
items.push(`Token status: ${validation.token.status}`);
}
if (validation.token && validation.token.notBefore) {
items.push(`Token not before: ${formatDate(validation.token.notBefore)}`);
}
if (validation.token && validation.token.expiresOn) {
items.push(`Token expires: ${formatDate(validation.token.expiresOn)}`);
}
if (validation.account && validation.account.id) {
items.push(`Account ID: ${validation.account.id}`);
}
if (validation.accountChecked) {
const total = validation.account && validation.account.liveInputsTotal;
items.push(`Existing live inputs in account: ${typeof total === "number" ? total : "unknown"}`);
}
if (validation.token && validation.token.scope) {
items.push(`Verification endpoint used: ${validation.token.scope}`);
}
return items;
}
function renderValidation(validation) {
const metaItems = buildValidationMeta(validation);
renderMeta(metaItems);
if (validation.ok && validation.canUseNow) {
const lines = [];
if (validation.accountChecked && validation.account && typeof validation.account.liveInputsTotal === "number") {
lines.push(`Cloudflare Stream access is working. Live inputs currently in the account: ${validation.account.liveInputsTotal}.`);
}
setStatus("success", "Token is active and Stream access check passed.", lines);
return;
}
if (validation.warnings && validation.warnings.length && (!validation.errors || !validation.errors.length)) {
setStatus("warning", "Token generated later may work, but it is not fully usable right now.", validation.warnings);
return;
}
const lines = [];
if (validation.errors) {
validation.errors.forEach((item) => lines.push(item));
}
if (validation.warnings) {
validation.warnings.forEach((item) => lines.push(item));
}
setStatus("error", "Validation failed.", lines.length ? lines : ["Cloudflare rejected the token or account settings."]);
}
async function postJson(url, payload) {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
const text = await response.text();
let json = null;
try {
json = JSON.parse(text);
} catch (error) {
json = null;
}
return {
ok: response.ok,
status: response.status,
text: text,
json: json
};
}
async function validateToken() {
const validateButton = document.getElementById("validateButton");
const data = getFormData();
if (!data.accessToken || !data.userId) {
setStatus("error", "Cloudflare API token and account ID are required.", []);
renderMeta([]);
return null;
}
saveFields(data);
setBusy(validateButton, "Validating...", true);
setStatus("info", "Checking Cloudflare token and Stream access...", []);
try {
const result = await postJson("https://cloudflare.vdo.ninja/validate/", data);
if (!result.json) {
throw new Error(result.text || `Validation failed with HTTP ${result.status}`);
}
lastValidation = result.json;
renderValidation(result.json);
return result.json;
} catch (error) {
resetValidationState();
setStatus("error", "Validation request failed.", [error.message || "Unknown error"]);
return null;
} finally {
setBusy(validateButton, "Validating...", false);
}
}
async function generateToken() {
const submitButton = document.getElementById("submitButton");
const responseField = document.getElementById("response");
const copyButton = document.getElementById("copyButton");
const data = getFormData();
if (!data.accessToken || !data.userId) {
setStatus("error", "Cloudflare API token and account ID are required.", []);
return;
}
saveFields(data);
setBusy(submitButton, "Generating...", true);
try {
if (!lastValidation) {
await validateToken();
}
const result = await postJson("https://cloudflare.vdo.ninja/encode/", data);
if (!result.ok) {
throw new Error(result.text || `Generation failed with HTTP ${result.status}`);
}
responseField.value = `&cftoken=${encodeURIComponent(result.text)}`;
copyButton.disabled = false;
if (lastValidation && lastValidation.ok && lastValidation.canUseNow) {
setStatus("success", "Encrypted cftoken generated.", ["Validation already passed for this token and account."]);
} else if (lastValidation && lastValidation.warnings && lastValidation.warnings.length) {
setStatus("warning", "Encrypted cftoken generated, but validation still shows a timing or availability warning.", lastValidation.warnings);
} else if (lastValidation && lastValidation.errors && lastValidation.errors.length) {
setStatus("warning", "Encrypted cftoken generated, but validation still shows an account or permission problem.", lastValidation.errors);
} else {
setStatus("info", "Encrypted cftoken generated.", ["Run validation before sharing the link if you want to confirm token timing and Stream access."]);
}
} catch (error) {
setStatus("error", "Could not generate cftoken.", [error.message || "Unknown error"]);
} finally {
setBusy(submitButton, "Generating...", false);
}
}
async function copyResponse() {
const responseField = document.getElementById("response");
if (!responseField.value) {
return;
}
try {
await navigator.clipboard.writeText(responseField.value);
setStatus("success", "Copied.", ["The generated cftoken parameter is now in your clipboard."]);
} catch (error) {
responseField.select();
document.execCommand("copy");
setStatus("success", "Copied.", ["The generated cftoken parameter is now in your clipboard."]);
}
}
document.getElementById("accessToken").value = getStorage("accessToken");
document.getElementById("userId").value = getStorage("userId");
document.getElementById("expiration").value = getStorage("expiration");
document.getElementById("validateButton").addEventListener("click", validateToken);
document.getElementById("submitButton").addEventListener("click", generateToken);
document.getElementById("copyButton").addEventListener("click", copyResponse);
["accessToken", "userId", "expiration"].forEach((id) => {
document.getElementById(id).addEventListener("input", () => {
resetValidationState();
});
});
</script>
</body>
</html>