-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·57 lines (49 loc) · 1.38 KB
/
Copy pathindex.js
File metadata and controls
executable file
·57 lines (49 loc) · 1.38 KB
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
#!/usr/bin/env node
const fs = require("fs")
, os = require("os")
, unifi = require("node-unifiapi");
const actions = {
device: "./device",
setup: require("./setup"),
poe: "./poe_mode"
}
var called = process.argv.splice(0, process.execArgv.length + 2).slice(-1)[0];
var action = process.argv.splice(0, 1)[0];
var argv = require('minimist')(process.argv);
switch (typeof actions[action]) {
case 'undefined':
console.log(`Supported actions: ${Object.keys(actions).join(', ')}`);
return;
case 'string':
actions[action] = require(actions[action]);
break;
}
if (actions[action].login !== true) {
actions[action].func(called, argv);
return;
}
const confPaths = [ "config.json", `${os.homedir()}/.unificli.json`, "/etc/unificli/config.json" ]
var filen;
for(key in confPaths) {
if (fs.existsSync(confPaths[key])) {
filen = confPaths[key];
break;
}
}
if (filen === undefined) {
console.log("Could not find a configuration file");
return;
}
try {
var config = JSON.parse(fs.readFileSync(filen, "utf-8"));
actions.setup.validate(config);
}
catch (err) {
console.log(`Can't access or parse 'config.json'`);
return;
}
var r = unifi(config.options);
if(actions[action].deps !== undefined) {
Object.assign(actions[action].deps, { config: config, unifi: r });
}
actions[action].func(called, argv);