-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrenderer.js
97 lines (82 loc) · 2.55 KB
/
renderer.js
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
// Require Dependencies
const $ = require('jquery');
const powershell = require('node-powershell');
const dt = require('datatables.net')();
const dtbs = require('datatables.net-bs4')(window, $);
// Get Global Variables
let remote = require('electron').remote;
// Helper to wrap a string in quotes
String.prototype.wrap = function () {
return `'${this}'`;
}
$('#changeUser').click(() => {
let ps = new powershell({
executionPolicy: 'Bypass',
noProfile: true
})
let scriptPath = require("path").resolve(__dirname, './Convert-CredToJson.ps1')
ps.addCommand(scriptPath, [])
ps.invoke()
.then(output => {
console.log(output)
// Set the global Variable
remote.getGlobal('sharedObj').cred = JSON.parse(output)
// Read the global variable
console.log(remote.getGlobal('sharedObj').cred)
})
.catch(err => {
console.dir(err);
ps.dispose();
})
})
$("#getDisk").click(() => {
// Get the form input
let computer = $('#computerName').val() || 'localhost'
// Clear the Error Messages
$('.alert-danger .message').html("")
$('.alert-danger').hide()
// Create the PS Instance
let ps = new powershell({
executionPolicy: 'Bypass',
noProfile: true
})
let commands = [{ ComputerName: computer.wrap() }]
let cred = remote.getGlobal('sharedObj').cred
// If global cred exists, seralize and push it to commands
if (cred)
commands.push({ JsonUser: JSON.stringify(cred).wrap() })
// Load the gun
let scriptPath = require("path").resolve(__dirname, './Get-Drives.ps1')
ps.addCommand(scriptPath, commands)
// Pull the Trigger
ps.invoke()
.then(output => {
console.log(output)
let data = JSON.parse(output)
console.log(data)
// Catch Custom Errors
if (data.Error) {
$('.alert-danger .message').html(data.Error.Message)
$('.alert-danger').show()
return
}
// generate DataTables columns dynamically
let columns = [];
Object.keys(data[0]).forEach( key => columns.push({ title: key, data: key }) )
console.log(columns)
$('#output').DataTable({
data: data,
columns: columns,
paging: false,
searching: false,
info: false,
destroy: true // or retrieve
});
})
.catch(err => {
console.error(err)
$('.alert-danger .message').html(err)
$('.alert-danger').show()
ps.dispose()
})
})