-
Notifications
You must be signed in to change notification settings - Fork 19
/
addressing.js
145 lines (130 loc) · 4.55 KB
/
addressing.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Compute and Check the input data
function plugaddr_Compute(msg) {
var ipdeb = new Array();
var ipfin = new Array();
var subnet = new Array();
var netmask = new Array();
var i;
var val;
document.getElementById("plugaddr_range").innerHTML = "";
document.getElementById("plugaddr_ipdeb").value = "";
document.getElementById("plugaddr_ipfin").value = "";
for (var i = 0; i < 4; i++) {
val=document.getElementById("plugaddr_ipdeb"+i).value;
if (val=='' || isNaN(val) || parseInt(val)<0 || parseInt(val)>255) {
document.getElementById("plugaddr_range").innerHTML=msg+" ("+val+")";
return false;
}
ipdeb[i]=parseInt(val);
val=document.getElementById("plugaddr_ipfin"+i).value;
if (val=='' || isNaN(val) || parseInt(val)<0 || parseInt(val)>255) {
document.getElementById("plugaddr_range").innerHTML=msg+" ("+val+")";
return false;
}
ipfin[i]=parseInt(val);
}
if (ipdeb[0]>ipfin[0]) {
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[0]+">"+ipfin[0]+")";
return false;
}
if (ipdeb[0]==ipfin[0] && ipdeb[1]>ipfin[1]) {
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[1]+">"+ipfin[1]+")";
return false;
}
if (ipdeb[0]==ipfin[0] && ipdeb[1]==ipfin[1] && ipdeb[2]>ipfin[2]) {
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[2]+">"+ipfin[2]+")";
return false;
}
if (ipdeb[0]==ipfin[0] && ipdeb[1]==ipfin[1] && ipdeb[2]==ipfin[2] && ipdeb[3]>ipfin[3]) {
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[3]+">"+ipfin[3]+")";
return false;
}
document.getElementById("plugaddr_range").innerHTML=""+ipdeb[0]+"."+ipdeb[1]+"."+ipdeb[2]+"."+ipdeb[3]+" - "+ipfin[0]+"."+ipfin[1]+"."+ipfin[2]+"."+ipfin[3];
document.getElementById("plugaddr_ipdeb").value=""+ipdeb[0]+"."+ipdeb[1]+"."+ipdeb[2]+"."+ipdeb[3];
document.getElementById("plugaddr_ipfin").value=""+ipfin[0]+"."+ipfin[1]+"."+ipfin[2]+"."+ipfin[3];
return true;
}
// Check the input data (from onSubmit)
function plugaddr_Check(msg) {
if (plugaddr_Compute(msg)) {
return true;
}
alert(msg);
return false;
}
// Display initial values
function plugaddr_Init(msg) {
var ipdeb = new Array();
var ipfin = new Array();
var ipdebstr = document.getElementById("plugaddr_ipdeb").value;
var ipfinstr = document.getElementById("plugaddr_ipfin").value;
document.getElementById("plugaddr_range").innerHTML=""+ipdebstr+" - "+ipfinstr;
ipdeb=ipdebstr.split(".");
ipfin=ipfinstr.split(".");
for (i=0;i<4;i++) {
document.getElementById("plugaddr_ipdeb"+i).value=ipdeb[i];
document.getElementById("plugaddr_ipfin"+i).value=ipfin[i];
}
}
// Refresh the check message after onChange (from text input)
// function plugaddr_ChangeNumber(msg) {
//
// var lst=document.getElementById("plugaddr_subnet");
// if (lst!=null) {
// lst.selectedIndex=0;
// }
//
// plugaddr_Compute(msg);
// }
// Refresh the check message after onChange (from list)
// function plugaddr_ChangeList(id,msg) {
//
// var i;
// var lst=document.getElementById(id);
// if (lst.value == "0") {
// return;
// }
// var champ=lst.value.split("/");
// var subnet=champ[0].split(".");
// var netmask=champ[1].split(".", 4);
// var ipdeb = new Array();
// var ipfin = new Array();
//
// netmask[3] = parseInt(netmask[3]).toString();
// if (lst.selectedIndex>0) {
// for (var i=0;i<4;i++) {
// ipdeb[i]=subnet[i]&netmask[i];
// ipfin[i]=ipdeb[i]|(255-netmask[i]);
// if (i==3) {
// ipdeb[3]++;
// ipfin[3]--;
// }
// document.getElementById("plugaddr_ipdeb"+i).value=ipdeb[i];
// document.getElementById("plugaddr_ipfin"+i).value=ipfin[i];
// }
// plugaddr_Compute(msg);
// }
// }
function nameIsThere(params) {
var root_doc = params;
var nameElm = $('input[id*="name_reserveip"]');
var typeElm = $('select[name="type"]');
var divNameItemElm = $('div[id="nameItem"]');
$.ajax({
url: root_doc + '/front/addressing.php',
type: "GET",
dataType: "json",
data: {
action: 'isName',
name: (nameElm.length != 0) ? nameElm.val() : '0',
type: (typeElm.length != 0) ? typeElm.val() : '0',
},
success: function (json) {
if (json) {
divNameItemElm.show();
} else {
divNameItemElm.hide();
}
}
});
}