-
Notifications
You must be signed in to change notification settings - Fork 3
/
iiNet.js
48 lines (44 loc) · 1.64 KB
/
iiNet.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
function iiNet_getConfig() {
var cfg = new Object();
cfg.url = "https://toolbox.iinet.net.au/cgi-bin/new/volume_usage_xml.cgi?username={USERNAME}&action=login&password={PASSWORD}";
cfg.requestType = "GET";
cfg.requestParams = null;
return cfg;
}
/*
* iiNet isp
*/
function iiNet_parseXML(text) {
var xml = (new DOMParser()).parseFromString(text, "text/xml");
var results = new Array();
if(!xml) {
return mkError("error: invalid xml");
}
var errorResults = xml.evaluate('/ii_feed/error', xml, null, XPathResult.ANY_TYPE,null).iterateNext();
if (errorResults){
var errorMessage = errorResults.childNodes[0].nodeValue;
return mkError(errorMessage);
}
var qResults = xml.evaluate('/ii_feed/volume_usage/quota_reset/days_remaining', xml, null, XPathResult.ANY_TYPE,null).iterateNext();
var daysLeft = 0;
if(qResults) {
daysLeft = qResults.childNodes[0].nodeValue;
} else {
return mkError("error: invalid XML. days_remaining not found");
}
var nodes = xml.evaluate('/ii_feed/volume_usage/expected_traffic_types/type', xml, null, XPathResult.ANY_TYPE, null);
qResults = nodes.iterateNext();
for(var i = 0; qResults; i++, qResults = nodes.iterateNext()) {
if(qResults.getElementsByTagName("quota_allocation").length > 0) {
results[i] = new Object();
results[i]['name'] = qResults.getAttribute('classification');
results[i]['limit'] = parseInt(qResults.getElementsByTagName("quota_allocation")[0].childNodes[0].nodeValue);
results[i]['usagemb'] = parseInt(qResults.getAttribute('used')/1000/1000); //iinet uses 1000mb per gb
results[i]['daysleft'] = daysLeft;
results[i]['custom'] = false;
} else {
i--;
}
}
return results;
}