/
sources.hbs
155 lines (140 loc) · 5.72 KB
/
sources.hbs
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
{{> header title="Admin" }}
<body class="text-center">
{{> nav }}
<div class="container mt-3">
<div class="col-xl-10 offset-xl-1 text-left">
{{> flash }}
<div class="row mt-3 mb-3">
<a href="/admin" class="btn confirmed-blue-btn btn-sm">Back to Admin</a>
</div>
<div class="row mt-3">
<div class="container-fluid mt-1 p-3 rounded confirmed-bg text-center">
<span style="display: none;">{{certAccessSecret}}</span> <!-- intentionally have Admin use inspect element to view this -->
<form id="toggle-secret-form" action="/toggle-secret" method="POST">
<h5>
Certificate Access:
{{#if secretEnabled}}
ENABLED
{{else}}
DISABLED
{{/if}}
</h5>
<button id="toggleSecretButton" type="submit" class="btn confirmed-blue-btn btn-sm text-white mt-2">Click to Toggle</button>
</form>
</div>
</div>
<div class="row mt-3 mb-5 pb-4">
<div class="container-fluid mt-1 p-3 rounded confirmed-bg text-center">
<h1 class="h5"><strong>Sources</strong></h1>
<table class="mt-3 mb-3" style="width:100%">
{{#each sources}}
<tr>
<td width="10%">
<div class="confirmed-blue">
{{ this.id }}
</div>
</td>
<td width="15%">
<div class="">
{{ this.createDateString }}
</div>
</td>
<td width="20%">
{{#if this.isCurrent}}
<span class="badge badge-secondary">Current Source</span>
{{else}}
<button id="source{{this.id}}" onclick="setCurrentSource('{{this.id}}')" class="btn confirmed-gray-btn btn-sm">Set Current</button>
{{/if}}
</td>
<td width="25%">
<button id="unassigned{{this.id}}" onclick="getUnassigned('{{this.id}}')" class="btn confirmed-blue-btn btn-sm">Get # Unassigned Certificates</button>
</td>
<td width="30%">
<input type="text" id="num{{this.id}}" style="width: 30%;" placeholder="# IDs"/>
<button id="generate{{this.id}}" onclick="generateCertificates('{{this.id}}')" class="btn confirmed-blue-btn btn-sm">Generate Certificates</button>
</td>
</tr>
{{/each}}
</table>
<hr/>
<form id="new-source-form" action="/new-source" method="POST">
<h5>Create New Source</h5>
<input type="text" id="id" name="id" class="form-control mb-2 text-center" form="new-source-form" placeholder="Alphanumeric, 1-25 characters."/>
<button id="newSourceButton" type="submit" class="btn confirmed-blue-btn btn-sm text-white btn-block mt-2">Create New Source</button>
</form>
</div>
</div>
</div> <!-- column -->
</div> <!-- row -->
{{> footer}}
{{> bootstrapjs}}
<script>
function setCurrentSource(id) {
if (confirm("Are you sure you want to set \"" + id + "\" as the current source? You'll need to restart all Main AND Helper instances to pick up the change.")) {
document.getElementById("source" + id).disabled = true;
var http = new XMLHttpRequest();
var url = "set-current-source";
var params = "id=" + id
http.open("POST", url, true);
http.responseType = 'json';
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if (http.readyState == 4) {
if (http.status == 200) {
location.reload()
return;
}
alert("Error: " + JSON.stringify(http.response));
}
}
http.send(params);
}
}
function generateCertificates(id) {
if (confirm("Are you sure you want to generate certs for \"" + id + "\"?")) {
document.getElementById("generate" + id).disabled = true;
var http = new XMLHttpRequest();
var url = "generate-certificates";
var params = "id=" + id + "&num=" + document.getElementById("num" + id).value
http.open("POST", url, true);
http.responseType = 'json';
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if (http.readyState == 4) {
if (http.status == 200) {
document.getElementById("generate" + id).disabled = false;
document.getElementById("num" + id).value = null;
alert("Generation started.");
return;
}
alert("Error: " + JSON.stringify(http.response));
}
}
http.send(params);
}
}
function getUnassigned(id) {
document.getElementById("unassigned" + id).disabled = true;
var http = new XMLHttpRequest();
var url = "get-unassigned-certificates";
var params = "id=" + id;
http.open("POST", url, true);
http.responseType = 'json';
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if (http.readyState == 4) {
if (http.status == 200) {
document.getElementById("unassigned" + id).disabled = false;
document.getElementById("unassigned" + id).innerText = http.response.count + " Unassigned Certificates";
return;
}
else {
document.getElementById("unassigned" + id).disabled = false;
alert("Error: " + JSON.stringify(http.response));
}
}
}
http.send(params);
}
</script>
</body>