-
Notifications
You must be signed in to change notification settings - Fork 24
/
ClientSettingsManager.ojo
440 lines (380 loc) · 18 KB
/
ClientSettingsManager.ojo
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
<?xml version="1.0"?>
<!-- vim: set syntax=xml: -->
<BES>
<Wizard>
<Title>Custom - Client Settings Manager</Title>
<UIHooks LaunchType="Document" RequiresAuthoring="false" Menu="Dashboards"></UIHooks>
<DefaultPage>ClientSettingsManager</DefaultPage>
<Page Name="ClientSettingsManager" DocType="HTML5" >
<Title>Client Settings Manager</Title>
<Head><![CDATA[
<meta http-equiv="X-UA-Compatible" content="IE=11">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha256-rByPlHULObEjJ6XQxW/flG2r+22R5dKiAoef+aXWfik=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.13/css/jquery.dataTables.min.css" integrity="sha256-+Z1rYa3ys5OdZNUck5G7lBvb8A13OrYwvf+d8PfEaHQ=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha256-KM512VNnjElC30ehFwehXjx1YCHPiQkOPmqnrWtpccM=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.13/js/jquery.dataTables.min.js" integrity="sha256-yWA356lDhruy1J8jGncaMWKAPYDbK47OKb0uT/aELLc=" crossorigin="anonymous"></script>
<script>window.onerror = function(event, source, lineno, colno, error){ if( -1 != source.toString().indexOf("/wizards.js") && 0 == lineno && 0 == colno) { return true; } };</script>
]]></Head>
<HTML><![CDATA[
<script language="javascript">InsertUtilityDiv();</script>
<h2>Client Settings Manager</h2>
<p> The goal of this dashboard is to add buttons to quickly create tasks or actions to set these settings </p>
<div class="ui-widget">
<label><strong>Enter a Client Setting:</strong></label>
<select id="firstchoice">
<?Relevance ( html tag ("option", attr lists of ("value", multiplicity of it as string) of it, it as string as html as string ) ) of unique values of names of client settings of bes computers ?>
</select>
</div>
<br />
<table id="resultsTable" class="compact display" width="100%">
<thead><tr><th># of each</th><th>Values</th><th>Change</th></tr></thead>
<tbody id="results">
</tbody>
</table>
<br />
<br />
<br />
<hr />
<p><strong>NOTE: This is an early work in progress.</strong></p>
<p><strong>Known Issue: throws an error if value is invalid JSON. TODO: Need to escape some chars? ("\)</strong></p>
<p><strong>Known Issue: TakeAction currently only works for master operators. Work in Progress.</strong></p>
<p><strong>TODO: add option to delete the selected setting</strong></p>
<p><strong>TODO: add option to set a custom value not in the listed options</strong></p>
<p><strong>TODO: add results to table for tasks/fixlets that set custom settings that don't exist on computers already</strong></p>
<div id="chart" style="position: absolute; z-index: 3; top: -38px; right: 0px;">
<svg style="width: 270px; height: 270px;"></svg>
</div>
<style>
body {
overflow-y: scroll;
}
h2 {
padding: 0px;
margin: 0px 0px 1px 0px;
border: 0;
text-align: center;
}
.dataTables_wrapper {
width: 90%;
margin:1px auto;
}
/* https://datatables.net/forums/discussion/32210/can-i-move-the-search-box-to-the-left */
div.dataTables_filter {
float: left !important;
}
div.dataTables_filter input {
margin-top: 20px;
margin-bottom: 10px;
width: 250px;
}
.custom-combobox {
position: relative;
display: inline-block;
z-index: 5;
}
.custom-combobox-toggle {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
}
.custom-combobox-input {
width: 500px;
margin: 0;
padding: 5px 10px;
}
</style>
<script>
/***********************************************/
// the following is taken from bigfixme-api.0.0.1.js
var bigfix = bigfix?bigfix:{};
bigfix.relevance = {};
bigfix.relevance.evaluate = function(relevance, callbackObj) {
if(callbackObj !== undefined && callbackObj !== null) {
var results;
if(callbackObj.failure !== undefined && callbackObj.failure !== null) {
callbackObj.failure = bigfix.relevance.errorWrapper(relevance, callbackObj.failure);
} else {
callbackObj.failure = bigfix.relevance.errorWrapper(relevance, bigfix.relevance.defaultErrorHandler);
}
try {
results = Relevance(relevance, callbackObj);
} catch (e2) {
return undefined;
}
return results;
} else {
var results;
try {
results = EvaluateRelevance(relevance);
} catch (e2) {
return undefined;
}
return results;
}
};
bigfix.relevance.errorWrapper = function(relevance, customErrorHandler) {
if(customErrorHandler !== undefined && customErrorHandler != null) {
return function(errorMessage){
customErrorHandler(relevance, new Error(errorMessage));
};
}
return function(errorMessage){
bigfix.relevance.defaultErrorHandler(relevance, new Error(errorMessage));
};
};
bigfix.relevance.defaultErrorHandler = function(relevance, error){
// rethrow error
throw error;
};
/***********************************************/
function fnGetDataTablesDataAjax(data, callback, settings) {
callback(
JSON.parse(bigfix.relevance.evaluate(' ("{ %22data%22: [ " & it & " ] }") of concatenations ", " of ( (it as string) of jsons of ("["&it&"]") of concatenations ", " of ("%22" & it & "%22") of (tuple string items of it) ) of (it as string) of (multiplicity of it, it as html as string, (if ( it is contained by set of following texts of lasts "%22 whose(%22" of preceding texts of lasts "%22 = value of it) of client" of unique values of relevances of custom bes fixlets whose("Configuration: Client Settings" = category of it AND relevance of it starts with "not exists settings %22' + sSelection + '" AND relevance of it ends with "%22 = value of it) of client") ) then "<button>TakeAction</button>" else "<button>CreateTask</button>") ) of unique values of values of client settings whose("' + sSelection + '" = name of it) of bes computers '))
);
}
// https://github.com/jgstew/tools/blob/master/JS/createActionClientSettings.js
function fnCreateClientSettingsXML(name, value, dateRelease, userName) {
// http://www.codereadability.com/javascript-default-parameters-with-or-operator/
if (dateRelease === undefined) {
dateRelease = new Date();
}
if (userName === undefined) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
try {
// https://developer.bigfix.com/relevance/reference/bes-user.html#current-console-user-bes-user
// https://developer.bigfix.com/relevance/reference/string.html#bes-current-wruser-string
testGetUserName = bigfix.relevance.evaluate(' if (in web reports context AND exists properties "bes current wruser") then (bes current wruser) else (name of current console user | "") ');
if (testGetUserName !== "jgstew") {
userName=testGetUserName;
}
} catch (e) {
if (e instanceof ReferenceError && e.message == "bigfix is not defined"){
// pass
} else {
throw(e);
}
}
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
// following return statement compiled by http://babeljs.io/
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<BES xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BES.xsd\">\n\t<Task>\n\t\t<Title>Set \"" + name + "\" to \"" + value + "\" - Universal</Title>\n\t\t<Description><![CDATA[<P>This task will set a client setting</P><P>This task was automatically generated using the Dashboard: \"Custom - Client Settings Manager\"</P><P> </P>]]]]><![CDATA[></Description>\n\t\t<Relevance>not exists settings \"" + name + "\" whose(\"" + value + "\" = value of it) of client</Relevance>\n\t\t<Category>Configuration: Client Settings</Category>\n\t\t<DownloadSize>0</DownloadSize>\n\t\t<Source>Custom Dashboard - Client Settings Manager</Source>\n\t\t<SourceID>jgstew" + (userName ? "; " + userName : "") + "</SourceID>\n\t\t<SourceReleaseDate>" + dateRelease.toISOString().slice(0, 10) + "</SourceReleaseDate>\n\t\t<SourceSeverity></SourceSeverity>\n\t\t<CVENames></CVENames>\n\t\t<SANSID></SANSID>\n\t\t<Domain>BESC</Domain>\n\t\t<DefaultAction ID=\"Action1\">\n\t\t\t<Description>\n\t\t\t\t<PreLink>Click </PreLink>\n\t\t\t\t<Link>here</Link>\n\t\t\t\t<PostLink> to set the Client Setting</PostLink>\n\t\t\t</Description>\n\t\t\t<ActionScript MIMEType=\"application/x-Fixlet-Windows-Shell\">\nsetting \"" + name + "\"=\"" + value + "\" on \"{ parameter \"action issue date\" of action}\" for client\n\t\t\t</ActionScript>\n\t\t\t<SuccessCriteria Option=\"OriginalRelevance\"></SuccessCriteria>\n\t\t</DefaultAction>\n\t</Task>\n</BES>";
}
// https://bigfix.me/relevance/details/3019196
// http://jqueryui.com/autocomplete/#combobox
// TODO - this could probably be a lot better than just taken from a demo
$( function() {
$.widget( "custom.combobox", {
_create: function() {
this.wrapper = $( "<span>" )
.addClass( "custom-combobox" )
.insertAfter( this.element );
this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
},
_createAutocomplete: function() {
var selected = this.element.children( ":selected" ),
value = selected.val() ? selected.text() : "";
this.input = $( "<input>" )
.appendTo( this.wrapper )
.val( value )
.attr( "title", "" )
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy( this, "_source" )
})
.tooltip({
classes: {
"ui-tooltip": "ui-state-highlight"
}
});
this._on( this.input, {
autocompleteselect: function( event, ui ) {
ui.item.option.selected = true;
this._trigger( "select", event, {
item: ui.item.option
});
},
autocompletechange: "_removeIfInvalid"
});
},
_createShowAllButton: function() {
var input = this.input,
wasOpen = false;
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.on( "mousedown", function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.on( "click", function() {
input.trigger( "focus" );
// Close if already visible
if ( wasOpen ) {
return;
}
// Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
},
_source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( this.element.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text,
value: text,
option: this
};
}) );
},
_removeIfInvalid: function( event, ui ) {
// Selected an item, nothing to do
if ( ui.item ) {
return;
}
// Search for a match (case-insensitive)
var value = this.input.val(),
valueLowerCase = value.toLowerCase(),
valid = false;
this.element.children( "option" ).each(function() {
if ( $( this ).text().toLowerCase() === valueLowerCase ) {
this.selected = valid = true;
return false;
}
});
// Found a match, nothing to do
if ( valid ) {
return;
}
// Remove invalid value
this.input
.val( "" )
.attr( "title", value + " didn't match any item" )
.tooltip( "open" );
this.element.val( "" );
this._delay(function() {
this.input.tooltip( "close" ).attr( "title", "" );
}, 2500 );
this.input.autocomplete( "instance" ).term = "";
},
_destroy: function() {
this.wrapper.remove();
this.element.show();
}
});
$("#combobox").combobox();
$("#toggle").on( "click", function() {
$("#combobox").toggle();
});
} );
// This is a global variable to contain the combobox selection / new selection.
var sSelection = "";
var sUserActionSite = "";
$(document).ready(function(){
// set up the combobox UI elements
$("#firstchoice").combobox();
// set the global variable to the current selection.
sSelection = $(".custom-combobox-input")[0].value;
// https://datatables.net/forums/discussion/1440/how-to-reset-clear-sorting
// https://datatables.net/plug-ins/api/fnSortNeutral
// https://cdn.datatables.net/plug-ins/1.10.13/api/fnSortNeutral.js
// - Author: https://datatables.net/forums/profile/1/allan
jQuery.fn.dataTableExt.oApi.fnSortNeutral = function (oSettings)
{
/* Remove any current sorting */
oSettings.aaSorting = [];
/* Sort display arrays so we get them in numerical order */
oSettings.aiDisplay.sort( function (x,y) {
return x - y;
});
oSettings.aiDisplayMaster.sort( function (x,y) {
return x - y;
});
/* Redraw */
oSettings.oApi._fnReDraw(oSettings);
};
// load initial datatable with settings
// https://legacy.datatables.net/ref#bDestroy
oDataTable = $("#resultsTable").dataTable( {
"scrollY": "70vh",
"scrollCollapse": true,
"paging": false,
"bDestroy": true,
"order": [[ 0, 'desc' ]],
"language": {
"zeroRecords": "No content, make a choice above.",
"info": "Showing _TOTAL_ values",
"infoEmpty": "No values to show",
"search": "Search values:"
},
"ajax": fnGetDataTablesDataAjax,
"columnDefs": [
{"width": "6em", "targets": 0},
{"targets": 1, "searchable": true},
// the following is used to set an empty value when no value is returned (null)
{"targets": 1, "defaultContent": ""},
{"targets": 2, "defaultContent": ""},
{"targets": 2, "className": "dt-body-center"},
{"targets": 2, "width": "4em"}
],
"dom": '<"toolbar">frtip'
});
// https://api.jqueryui.com/autocomplete/
$(".custom-combobox-input").on("autocompleteselect", function( event, ui ) {
// set `sSelection` to the value that has been selected in combobox
sSelection = ui.item.value;
// update table & chart based upon new combobox selection
// https://datatables.net/reference/api/ajax.reload()
$(".dataTable").DataTable().ajax.reload();
});
// https://datatables.net/forums/discussion/1440/how-to-reset-clear-sorting
// - Author: https://datatables.net/forums/profile/6627/manifestinteractive
$(".sorting, .sorting_asc, .sorting_desc").dblclick(function(){
oDataTable.fnSortNeutral();
return false;
});
// http://api.jquery.com/on/
// https://datatables.net/examples/ajax/null_data_source.html
$("#resultsTable tbody").on( "click", "button", function() {
var dataRow = $(".dataTable").DataTable().row( $(this).parents("tr") ).data();
// TODO: create task if button contains "Create", Take action if button contains "Take"
//alert( $(this).html() ); // get name of button
if( $(this).html() === "CreateTask" ) {
// https://bigfix.me/relevance/details/3019354
// ImportXML(xml, openDocuments, siteName, computerIDs)
ImportXML(fnCreateClientSettingsXML(sSelection, dataRow[1]), false, "<?Relevance ( tuple string item 0 of concatenations ", " of names of (bes custom sites whose(name of it as lowercase contains "client" AND name of it as lowercase contains "setting" AND exists writer whose(it = current console user) of it)) ) | "" ?>" );
// reload table to show that the new task exists
$(".dataTable").DataTable().ajax.reload();
} else {
// https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Tivoli%20Endpoint%20Manager/page/IEM%20Console%20JavaScript%20_%20Relevance
// TakeFixletAction(id, siteID, contentID, parameters, callback);
TakeFixletAction( bigfix.relevance.evaluate(' minimum of ids of custom bes fixlets whose("Configuration: Client Settings" = category of it AND relevance of it = "not exists settings %22' + sSelection + '%22 whose(%22' + dataRow[1] + '%22 = value of it) of client") '), sUserActionSite, "Action1" );
}
});
if(sUserActionSite === "") {
sUserActionSite = bigfix.relevance.evaluate(' id of action site of current console user ');
}
});
</script>
]]></HTML>
</Page>
</Wizard>
</BES>