admin-cli.js 1.88 KB
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);