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
|
<form id="tableDataForm" method="post" action="?do=rebootcontrol" class="form-inline">
<input type="hidden" name="token" value="{{token}}">
<div class="row">
<div class="col-md-12">
<label>{{lang_location}}:
<select id="locationDropdown" name="locationId" class="form-control" onchange="selectLocation()">
{{#locations}}
<option value="{{locationid}}" {{#selected}}selected{{/selected}}>{{locationpad}} {{locationname}}</option>
{{/locations}}
</select>
</label>
<button type="button" id="settingsButton" class="btn btn-default pull-right" data-toggle="modal" data-target="#settingsModal"><span class="glyphicon glyphicon-cog"></span></button>
<button type="button" id="selectAllButton" class="btn btn-primary pull-right" onclick="selectAllRows()"><span class="glyphicon glyphicon-check"></span> {{lang_selectall}}</button>
<button type="button" id="unselectAllButton" class="btn btn-default pull-right" onclick="unselectAllRows()" style="display: none;"><span class="glyphicon glyphicon-unchecked"></span> {{lang_unselectall}}</button>
<button type="button" id="rebootButton" class="btn btn-warning pull-right" data-toggle="modal" data-target="#rebootModal" disabled><span class="glyphicon glyphicon-repeat"></span> {{lang_rebootButton}}</button>
<button type="button" id="shutdownButton" class="btn btn-danger pull-right" data-toggle="modal" data-target="#shutdownModal" disabled><span class="glyphicon glyphicon-off"></span> {{lang_shutdownButton}}</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-condensed table-hover" id="dataTable">
<thead>
<tr>
<th data-sort="string">{{lang_client}}</th>
<th data-sort="ipsort">{{lang_ip}}</th>
<th data-sort="string">{{lang_status}}</th>
<th data-sort="string">{{lang_session}}</th>
<th data-sort="string">{{lang_user}}</th>
<th data-sort="int" data-sort-default="desc">{{lang_selected}}</th>
</tr>
</thead>
<tbody>
{{#data}}
<tr>
<td>
{{hostname}}
{{^hostname}}{{clientip}}{{/hostname}}
</td>
<td>{{clientip}}</td>
<td class="statusColumn">
{{#status}}
<span class="text-success">{{lang_on}}</span>
{{/status}}
{{^status}}
<span class="text-danger">{{lang_off}}</span>
{{/status}}
</td>
<td>{{#status}}{{currentsession}}{{/status}}</td>
<td>{{#status}}{{currentuser}}{{/status}}</td>
<td data-sort-value="0" class="checkboxColumn">
<div class="checkbox">
<input id="m-{{machineuuid}}" type="checkbox" name="clients[]" value='{{machineuuid}}'>
<label for="m-{{machineuuid}}"></label>
</div>
</td>
</tr>
{{/data}}
</tbody>
</table>
</div>
</div>
<!-- Modals -->
<div id="settingsModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><b>{{lang_settings}}</b></h4>
</div>
<div class="modal-body">
<span id="pubKeyTitle">{{lang_pubKey}}</span>
<button class="btn btn-s btn-warning pull-right" onclick="generateNewKeypair()" type="button">{{lang_genNew}}</button>
<pre id="pubKey">{{pubKey}}</pre>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class ="modal fade" id="rebootModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">{{lang_rebootButton}}</h4>
</div>
<div class="modal-body">
{{lang_rebootCheck}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button>
<button type="submit" name="action" value="startReboot" class="btn btn-warning"><span class="glyphicon glyphicon-repeat"></span> {{lang_reboot}}</button>
</div>
</div>
</div>
</div>
<div class ="modal fade" id="shutdownModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel2">{{lang_shutdownButton}}</h4>
</div>
<div class="modal-body">
{{lang_shutdownCheck}}
{{lang_shutdownIn}} <input id="shutdownTimer" name="minutes" title="{{lang_shutdownIn}}" type="number" value="0" min="0" onkeypress="return isNumberKey(event)"> {{lang_minutes}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button>
<button type="submit" name="action" value="startShutdown" class="btn btn-danger"><span class="glyphicon glyphicon-off"></span> {{lang_shutdownButton}}</button>
</div>
</div>
</div>
</div>
</form>
<script type="application/javascript">
document.addEventListener("DOMContentLoaded", function() {
markCheckedRows();
$('input:checkbox').change(
function(){
//give each checkbox the function to mark the row (in green)
if ($(this).is(':checked')) {
markRows($(this).closest("tr"), true);
$(this).closest("td").data("sort-value", 1);
} else {
markRows($(this).closest("tr"), false);
$(this).closest("td").data("sort-value", 0);
}
//if all are checked, change the selectAll-Button to unselectAll. if one is not checked, change unselectAll to selectAll
var dataTable = $("#dataTable");
var unchecked = dataTable.find("input[type=checkbox]:not(:checked)").length;
if (unchecked == 0) {
$('#selectAllButton').hide();
$('#unselectAllButton').show();
} else if (unchecked == 1) {
$('#selectAllButton').show();
$('#unselectAllButton').hide();
}
//if no client is selected, disable the shutdown/reboot button, and enable them if a client is selected
var checked = dataTable.find("input[type=checkbox]:checked").length;
if (checked == 0) {
$('#rebootButton').prop('disabled', true);
$('#shutdownButton').prop('disabled', true);
} else {
$('#rebootButton').prop('disabled', false);
$('#shutdownButton').prop('disabled', false);
}
});
$('.checkboxColumn').click(function(e) {
if (e.target === this) {
$(this).find('input[type="checkbox"]').click();
}
});
});
// Change Location when selected in Dropdown Menu
function selectLocation() {
var dropdown = $("#locationDropdown");
var location = dropdown.val();
window.location.replace("?do=rebootcontrol&location="+location);
}
// Check all checkboxes, change selectAll button, make shutdown/reboot button enabled as clients will certainly be selected
function selectAllRows() {
var checked = $("tr input:checkbox:checked");
//change button
$('#selectAllButton').hide();
$('#unselectAllButton').show();
//check rows and mark them
$('input[type="checkbox"]', '#dataTable').prop('checked', true);
markRows($("tr:not(:first)"), true);
$(".checkboxColumn").data("sort-value", 1);
//enable shutdown/reboot button
$('#rebootButton').prop('disabled', false);
$('#shutdownButton').prop('disabled', false);
}
// Uncheck all checkboxes, change unselectAll Button, make shutdown/reboot button disabled as clients will certainly be not selected
function unselectAllRows() {
//change button
$('#selectAllButton').show();
$('#unselectAllButton').hide();
//uncheck rows and unmark them
$('input[type="checkbox"]', '#dataTable').prop('checked', false);
markRows($("tr"), false);
$(".checkboxColumn").data("sort-value", 0);
//disable shutdown/reboot button
$('#rebootButton').prop('disabled', true);
$('#shutdownButton').prop('disabled', true);
}
// mark all previous checked rows (used when loading site)
function markCheckedRows() {
var checked = $("tr input:checkbox:checked");
markRows(checked.closest("tr"), true);
var unchecked = $("#dataTable").find("input[type=checkbox]:not(:checked)").length;
if(unchecked == 0) {
$('#selectAllButton').hide();
$('#unselectAllButton').show();
}
}
// only allow numbers to get typed into the "shutdown in X Minutes" box.
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode > 31 && (charCode < 48 || charCode > 57));
}
function markRows($rows, marked) {
if (marked) {
$rows.addClass('active');
} else {
$rows.removeClass('active');
}
}
function generateNewKeypair() {
$.ajax({
url: '?do=rebootcontrol',
type: 'POST',
data: { action: "generateNewKeypair", token: TOKEN },
success: function(value) {
$('#pubKey').text(value);
}
});
}
</script>
|