forked from imperva/site-protection-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getAccountSub.js
85 lines (74 loc) · 2.5 KB
/
getAccountSub.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
var request = require('request-promise');
var querystring = require('querystring');
var async = require('async');
var settings = require('./settings.js');
function getAccountSubInfoList(commonPostData, accountList, accountSubInfoOutput, informCaller)
{
totalNumAccounts = accountList.length;
if(settings.printDebugInfo)
console.time("Get account info - total time");
async.forEachLimit(accountList, settings.numConcurrentConnections, function(account, cb){
getAccountSubInfo(commonPostData, account.accountId, accountSubInfoOutput, cb);
}, function(err){
if (err){
//deal with the error
console.log("error in checking sites")
informCaller();
}
if(settings.printDebugInfo)
console.timeEnd("Get account info - total time")
informCaller();
});
}
function getAccountSubInfo(commonPostData, accountId, accountSubInfoOutput, informCaller)
{
var postData = {};
postData.api_id = commonPostData.api_id;
postData.api_key = commonPostData.api_key;
postData.account_id = accountId;
// form data
postData = querystring.stringify(postData);
var options = {
method: 'POST',
port: 443,
uri: 'https://my.incapsula.com/api/prov/v1/accounts/subscription',
host: 'my.incapsula.com',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: postData,
path: '/api/prov/v1/accounts/subscription',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
},
}
request(options)
.then(function (response) {
var isWebVolDDosPurchased = false;
var jResponse = JSON.parse(response);
if (jResponse.res != 0)
{
console.log("Error retreiving information - " + jResult.res_message);
return;
}
// Get Volumetric DDoS purchase status
for (var i = 0; i < jResponse.planStatus.additionalServices.planSectionRows.length; i++)
{
if (jResponse.planStatus.additionalServices.planSectionRows[i].name == "DDoS Protection")
{
if (jResponse.planStatus.additionalServices.planSectionRows[i].purchased != "None")
isWebVolDDosPurchased = true;
}
}
accountSubInfoOutput.push({"accountId": jResponse.planStatus.accountId, "accountName": jResponse.planStatus.accountName, "isWebVolDDosPurchased": isWebVolDDosPurchased});
informCaller();
})
.catch(function (err) {
// Deal with the error
console.log("error in getting account subscription info " + err);
informCaller();
})
}
module.exports.getAccountSubInfo = getAccountSubInfo;
module.exports.getAccountSubInfoList = getAccountSubInfoList;