Skip to content

Instantly share code, notes, and snippets.

@shadowbq
Last active February 14, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadowbq/5f631fa62936adcd144999b2d9b1d2c2 to your computer and use it in GitHub Desktop.
Save shadowbq/5f631fa62936adcd144999b2d9b1d2c2 to your computer and use it in GitHub Desktop.
Nsm javascript pseudo
{
"FirewallPolicyId": 120,
"Name": "TestFirewallPolicy",
"DomainId": 0,
"VisibleToChild": true,
"Description": "test the firewallpolicy",
"LastModifiedTime": "2012-12-12 12:32:44",
"IsEditable": true,
"PolicyType": "ADVANCED",
"PolicyVersion": 1,
"LastModifiedUser": "admin",
"MemberDetails": {
"MemberRuleList": [{
"Description": "Test Member Rule",
"Enabled": true,
"Response": "IGNORE",
"IsLogging": false,
"Direction": "OUTBOUND",
"SourceAddressObjectList": [{
"RuleObjectId": "AF",
"Name": "Afghanistan",
"RuleObjectType": "COUNTRY"
}],
"DestinationAddressObjectList": [{
"RuleObjectId": "101",
"Name": "hostDNSRule",
"RuleObjectType": "HOST_DNS_NAME"
}, {
"RuleObjectId": "102",
"Name": "hostIpv4",
"RuleObjectType": "HOST_IPV_4"
}, {
"RuleObjectId": "103",
"Name": "ipv4Addressrange",
"RuleObjectType": "IPV_4_ADDRESS_RANGE"
}, {
"RuleObjectId": "104",
"Name": "networkgroup",
"RuleObjectType": "NETWORK_GROUP"
}],
"SourceUserObjectList": [{
"RuleObjectId": "-1",
"Name": "ANY",
"RuleObjectType": "USER"
}],
"ServiceObjectList": [],
"ApplicationObjectList": [{
"RuleObjectId": "1308991488",
"Name": "100bao",
"RuleObjectType": "APPLICATION",
"ApplicationType": "DEFAULT"
}, {
"RuleObjectId": "106",
"Name": "applicaionOncutomPort",
"RuleObjectType": "APPLICATION_ON_CUSTOM_PORT",
"ApplicationType": "CUSTOM"
}, {
"RuleObjectId": "105",
"Name": "applicationgroup",
"RuleObjectType": "APPLICATION_GROUP",
"ApplicationType": "CUSTOM"
}],
"TimeObjectList": [{
RuleObjectId " : "
107 ","
Name " : "
finiteTimePeriod ", "
RuleObjectType " : "
FINITE_TIMING_PERIOD " }, { "
RuleObjectId " : "
108 ", "
Name " : "
recuringTimePeriod ", "
RuleObjectType " : "
RECURRING_TIME_PERIOD " }, { "
RuleObjectId " : "
109 ", "
Name " : "
recurringTimeperiodGroup ", "
RuleObjectType " : "
RECURRING_TIME_PERIOD_GROUP " } ] } ] }}
var session_credentials = '';
var insecure = params.insecure;
// handle '/' at the end of the url
var base_url = params.url.slice(0, params.url.length - params.url.match('/*$')[0].length) + '/sdkapi/';
var proxy = params.proxy;
function sendRequest(method, url_suffix, headers, body, params)
{
// add default headers
if (!("Accept" in headers))
{
headers["Accept"] = ['application/vnd.nsm.v1.0+json', 'application/vnd.nsm.v2.0+json'];
}
if (!("Content-Type" in headers))
{
headers['Content-Type'] = ['application/json'];
}
if (session_credentials !== '')
{
headers['NSM-SDK-API'] = [session_credentials];
}
var path = base_url + url_suffix;
if (params)
{
path += encodeToURLQuery(params);
}
var res = http(
path,
{
Method: method,
Headers: headers,
Body: body,
},
insecure,
proxy
);
if (res.StatusCode < 200 || res.StatusCode >= 300)
{
throw 'Request Failed.\nStatus code: ' + res.StatusCode + '.\nBody: ' + JSON.stringify(res) + '.';
}
return JSON.parse(res.Body);
}
function validateTimeArgs(time_period, start_time, end_time)
{
if (time_period === 'CUSTOM')
{
if ((start_time === undefined) || (end_time === undefined))
{
return false;
}
}
return true;
}
function login()
{
var cmd_url = "session";
var credentials = btoa(params.credentials.identifier + ':' + params.credentials.password);
var headers = {
'NSM-SDK-API': [credentials]
};
var res = sendRequest("GET", cmd_url, headers, '');
// store current credentials
session_credentials = btoa(res.session + ':' + res.userId);
return res;
}
function sensors_to_entry(title, sensors)
{
return createEntry(sensors,
{
contextPath: 'NSM.Sensors(val.ID && val.ID === obj.ID)',
title: title,
data: [
{
to: 'ID',
from: 'sensorId'
},
{
to: 'Name',
from: 'name'
},
{
to: 'Description',
from: 'Description'
},
{
to: 'DomainID',
from: 'DomainID'
},
{
to: 'IPSPolicyID',
from: 'IPSPolicyID'
},
{
to: 'IP Address',
from: 'sensorIPAddress'
}, ],
},
undefined, pascalToSpace);
}
function get_sensors(domain_id)
{
var cmd_url = 'sensors';
if (domain_id !== undefined)
{
cmd_url += '?domain=' + domain_id;
}
var res = sendRequest('GET', cmd_url,
{}, '');
return sensors_to_entry('Sensors', res.SensorDescriptor);
}
{
"RuleObjDef":
{
"domain": 0,
"visibleToChild": true,
"description": "try",
"ruleobjId": 0,
"name": "test_NTW",
"Network":
{
"networkList": ["172.0.0.0/8", "172.16.0.0/16", "192.168.12.0/24"]
},
"ruleobjType": "NETWORK",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment