/
template.go
126 lines (115 loc) · 3.78 KB
/
template.go
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
package main
import (
"html/template"
)
type TemplateData struct {
Store Store
CsrfTemplate template.HTML
Errors []error
}
var templates = template.Must(template.New("form.html").Parse(
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RTMP Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="{{.Store.Prefix}}/public/mini-dark.css">
<link rel="stylesheet" type="text/css" href="{{.Store.Prefix}}/public/main.css">
</head>
<body>
<div class="container">
<h1><a href="/">rtmp-auth</a></h1>
<h2>Streams</h2>
<div class="row">
{{range .Errors}}
<div class="card error">
<div class="section">
<h3>Error</h3>
<p>{{.Error}}</p>
</div>
</div>
{{end}}
</div>
<table>
<thead>
<th>Name</th>
<th data-label="Auth">Auth</th>
<th>Expires</th>
<th data-label="Notes">Notes</th>
<th></th>
</thead>
<tbody>
{{range .Store.State.Streams}}
<tr>
<td data-label="Name">
{{.Application}}/{{.Name}}
{{if .Active}}
<mark class="tag">live</mark>
{{end}}
</td>
<td data-label="Auth">
<input class="authKey" size="5" value="{{.AuthKey}}" readonly/><button class="secondary copyToClipboard inputAddon">Copy</button>
</td>
<td data-label="Expire" data-expire="{{.AuthExpire}}">
{{if eq .AuthExpire -1}}
never
{{else}}
{{.AuthExpire}}
{{end}}
</td>
<td data-label="Notes">{{.Notes}}</td>
<td style="text-align:right;">
<form class="inline" action="{{$.Store.Prefix}}/remove" method="POST">
{{ $.CsrfTemplate }}
<input type="hidden" name="id" value="{{.Id}}">
<button class="secondary">Remove</button>
</form>
</td>
</tr>
{{end}}
</tbody>
</table>
<h2>Add Stream</h2>
<form class="addForm" action="{{$.Store.Prefix}}/add" method="POST" novalidate>
<div class="row">
<div class="col-sm-12 col-md-6">
<label for="application">Application</label>
<select type="text" id="application" name="application">
{{range .Store.Applications}}
<option value="{{.}}">{{.}}</option>
{{end}}
</select>
</div>
<div class="col-sm-12 col-md-6">
<label for="stream">Stream</label>
<input type="text" size="5" id="stream" name="name" placeholder="enter name">
</div>
<div class="col-sm-12 col-md-6">
<label for="authKey">Auth Key</label>
<input type="text" size="3" id="authKey" name="auth_key" placeholder="no auth"><button class="secondary generateKey inputAddon">Generate key</button>
</div>
<div class="col-sm-12 col-md-6">
<label for="authExpire">Auth Expire
<span class="tooltip" aria-label="ISO8601 Duration (e.g. P2DT10H) or empty for no expiry">
<span class="icon-help"></span>
</span>
</label>
<input type="text" size="5" id="authExpire" name="auth_expire" placeholder="never">
</div>
<div class="col-sm-12">
<label for="notes">Notes</label>
<input type="text" size="5" id="notes" name="notes" placeholder="optional notes">
</div>
</div>
<div class="row">
{{ .CsrfTemplate }}
<div class="col-sm-12 col-md-12">
<button class="primary">Submit</button>
</div>
</div>
</form>
</div>
<script src="{{.Store.Prefix}}/public/main.js"></script>
</body>
</html>`))