forked from jsa2/AADAppAudit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
69 lines (45 loc) · 1.72 KB
/
main.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
const { decode } = require("jsonwebtoken");
const getToken = require("./src/getToken");
const fs = require('fs');
const { exec } = require("child_process");
const { preCheck } = require("./precheck");
const { admins } = require("./admins");
const { mainV2 } = require("./mainV2");
const { argv } = require("yargs");
const wexc = require('util').promisify(exec)
run().catch((error) => {
return error
})
async function run() {
let accountName = argv?.sa || (process?.argv[2])
if (accountName?.match('--')) {accountName=undefined}
if (accountName) {
await preCheck(accountName)
} else {
console.log('running only CSV output')
}
var token = await getToken()
var tEnc = decode(token)
fs.writeFileSync('kql/tid.txt', tEnc.tid)
await mainV2({
access_token: token,
resource: "https://graph.microsoft.com"
})
await admins()
try {
await wexc('node nodeparse2.js')
//await wexc('node dynamicSend.js')
console.log('creating query')
if (accountName) {
await wexc(`node schemaForExternalData.js --sa=${accountName}`)
console.log('open kql/runtime.kql')
} else {
await wexc(`node toCSV.js --delimitter="${argv?.delimitter || ','}"`)
console.log('to review the results in csv open the output.csv, remember, that in order to show line breaks, for example in excel you need to select the "wrap text"')
}
} catch (error) {
console.log('failed', error)
fs.unlinkSync('sessionToken.json')
}
fs.unlinkSync('sessionToken.json')
}