admin-cli.js
1.88 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
58
59
60
61
62
63
64
var request = require('request');
var iniparser = require('iniparser');
var config = iniparser.parseSync(process.cwd() +'/config.ini');
var base_url = 'http://localhost:' + config.globals.admin_port
var apikey = config.globals.apikey;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
function doRequest(url) {
request(url, function(err, response, body) {
if (err) {
console.log('Error: ' + err);
return;
}
if (response.statusCode != 200) {
console.log('HTTP Response Status ' + response.statusCode + ' != 200');
}
console.log(body);
});
}
var argv = require('minimist')(process.argv.slice(2));
var url = base_url + '/info';
if (argv.addproduct) {
url = base_url + '/products/add/' + argv.addproduct + '/' + apikey;
} else if (argv.delproduct) {
url = base_url + '/products/del/' + argv.delproduct + '/' + apikey;
} else if (argv.pause) {
url = base_url + '/pause/' + apikey;
} else if (argv.resume) {
url = base_url + '/resume/' + apikey;
} else if (argv.configdump) {
url = base_url + '/config/index/' + apikey;
} else if (argv.configsave) {
url = base_url + '/config/save/' + apikey;
} else if (argv.configload) {
url = base_url + '/config/load/' + apikey;
} else if (argv.matrixdump) {
url = base_url + '/matrix/index/' + apikey;
} else if (argv.partnerprobe) {
url = config.h2h_out.partner;
console.log('Requesting to ' + url);
} else if (argv.help) {
console.log('Available commands: ')
console.log(' --info');
console.log(' --addproduct <PRODUCT>');
console.log(' --delproduct <PRODUCT>');
console.log(' --pause');
console.log(' --resume');
console.log(' --configdump');
console.log(' --configsave');
console.log(' --configload');
console.log(' --matrixdump');
console.log(' --partnerprobe');
return;
}
doRequest(url);