spanary=new Array();
inArrix=0;
pn=new pattern();
cmsg="";
colorsDict = {"aliceblue":"#f0f8ff","antiquewhite":"#faebd7","aqua":"#00ffff","aquamarine":"#7fffd4","azure":"#f0ffff",
"beige":"#f5f5dc","bisque":"#ffe4c4","black":"#000000","blanchedalmond":"#ffebcd","blue":"#0000ff","blueviolet":"#8a2be2","brown":"#a52a2a","burlywood":"#deb887",
"cadetblue":"#5f9ea0","chartreuse":"#7fff00","chocolate":"#d2691e","coral":"#ff7f50","cornflowerblue":"#6495ed","cornsilk":"#fff8dc","crimson":"#dc143c","cyan":"#00ffff",
"darkblue":"#00008b","darkcyan":"#008b8b","darkgoldenrod":"#b8860b","darkgray":"#a9a9a9","darkgreen":"#006400","darkkhaki":"#bdb76b","darkmagenta":"#8b008b","darkolivegreen":"#556b2f",
"darkorange":"#ff8c00","darkorchid":"#9932cc","darkred":"#8b0000","darksalmon":"#e9967a","darkseagreen":"#8fbc8f","darkslateblue":"#483d8b","darkslategray":"#2f4f4f","darkturquoise":"#00ced1",
"darkviolet":"#9400d3","deeppink":"#ff1493","deepskyblue":"#00bfff","dimgray":"#696969","dodgerblue":"#1e90ff",
"firebrick":"#b22222","floralwhite":"#fffaf0","forestgreen":"#228b22","fuchsia":"#ff00ff",
"gainsboro":"#dcdcdc","ghostwhite":"#f8f8ff","gold":"#ffd700","goldenrod":"#daa520","gray":"#808080","green":"#008000","greenyellow":"#adff2f",
"honeydew":"#f0fff0","hotpink":"#ff69b4",
"indianred ":"#cd5c5c","indigo":"#4b0082","ivory":"#fffff0","khaki":"#f0e68c",
"lavender":"#e6e6fa","lavenderblush":"#fff0f5","lawngreen":"#7cfc00","lemonchiffon":"#fffacd","lightblue":"#add8e6","lightcoral":"#f08080","lightcyan":"#e0ffff","lightgoldenrodyellow":"#fafad2",
"lightgrey":"#d3d3d3","lightgreen":"#90ee90","lightpink":"#ffb6c1","lightsalmon":"#ffa07a","lightseagreen":"#20b2aa","lightskyblue":"#87cefa","lightslategray":"#778899","lightsteelblue":"#b0c4de",
"lightyellow":"#ffffe0","lime":"#00ff00","limegreen":"#32cd32","linen":"#faf0e6",
"magenta":"#ff00ff","maroon":"#800000","mediumaquamarine":"#66cdaa","mediumblue":"#0000cd","mediumorchid":"#ba55d3","mediumpurple":"#9370d8","mediumseagreen":"#3cb371","mediumslateblue":"#7b68ee",
"mediumspringgreen":"#00fa9a","mediumturquoise":"#48d1cc","mediumvioletred":"#c71585","midnightblue":"#191970","mintcream":"#f5fffa","mistyrose":"#ffe4e1","moccasin":"#ffe4b5",
"navajowhite":"#ffdead","navy":"#000080",
"oldlace":"#fdf5e6","olive":"#808000","olivedrab":"#6b8e23","orange":"#ffa500","orangered":"#ff4500","orchid":"#da70d6",
"palegoldenrod":"#eee8aa","palegreen":"#98fb98","paleturquoise":"#afeeee","palevioletred":"#d87093","papayawhip":"#ffefd5","peachpuff":"#ffdab9","peru":"#cd853f","pink":"#ffc0cb","plum":"#dda0dd","powderblue":"#b0e0e6","purple":"#800080",
"red":"#ff0000","rosybrown":"#bc8f8f","royalblue":"#4169e1",
"saddlebrown":"#8b4513","salmon":"#fa8072","sandybrown":"#f4a460","seagreen":"#2e8b57","seashell":"#fff5ee","sienna":"#a0522d","silver":"#c0c0c0","skyblue":"#87ceeb","slateblue":"#6a5acd","slategray":"#708090","snow":"#fffafa","springgreen":"#00ff7f","steelblue":"#4682b4",
"tan":"#d2b48c","teal":"#008080","thistle":"#d8bfd8","tomato":"#ff6347","turquoise":"#40e0d0",
"violet":"#ee82ee",
"wheat":"#f5deb3","white":"#ffffff","whitesmoke":"#f5f5f5",
"yellow":"#ffff00","yellowgreen":"#9acd32"};
function locateObj(fm,fobj,offset)
{
for(var j=0;j<fm.length;j++)
{
if(fm.elements[j]==fobj)break;
}
return (arguments.length<3)?j:eval("fm.elements[j"+offset+"]");
}
function chkundo()
{
f=document.forms[0]
f.reset();
for(i=0;i<f.length;i++) showmsg(f.elements[i],true)
}
function pattern()
{
ips="(25[0-5]|2[0-4][0-9]|[1]?[0-9][0-9]?)"
ips_0="(25[0-5]|2[0-4][0-9]|[1][0-9][0-9]|[1-9][0-9]|[1-9])"
ipss=ips+"\\."+ips+"\\."+ips+"\\."+ips
n0_32="(3[0-2]|2[0-9]|1[0-9]|[0-9])"
ipssn=ipss+"\/"+n0_32
ipssnm="^"+ipssn+"$|"+ipssn+"(\\;"+ipssn+")+"
hexs="([0-9a-fA-F]+)"
hex2="([0-9a-fA-F]{2})"
ports="([0-9]{1,5})"
numbers="([0-9]+)"
numbers2="^(0|[1-9][0-9]*)$"
hours="(2[0-3]|1[0-9]|[0-9]|0[0-9])"
minutes="([1-5][0-9]|[0-9]|0[0-9])"
smasks="(1+0+|1{8}|0{8})"
ccsmasks="(1{8})"
strs="([^\r|^\n]+)"
strsns="([^\x20]+)"
strfilename="([^\\\\/:\*?\"<>|]*)"
emails="([a-zA-Z0-9_\\-\\.]+\\@[a-zA-Z0-9_\\-\\.]+\\.[a-zA-Z]{2,5})"
emails2="^"+emails+"$|"+emails+"(\\;"+emails+")+|"+emails+"(\\,"+emails+")+"
inte="([1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9])"
namepass="([a-zA-Z0-9_\\ -]*)"
namepass2="([a-zA-Z0-9_\\-\\.]*)"
nonword="([A-Za-z0-9]+)"
strsnmp="([a-zA-Z0-9_]*)"
strsnmp1="([0-9.]*)"
hexcolor="(^#([0-9a-fA-F]{3}){1,2}$)";
this.ip1=ips
this.ip=ipss
this.iprange=ipss+"-"+ipss
this.ipms="^"+ipss+"$|"+ipss+"(\\;"+ipss+")+"
this.subnetmask=smasks+"\\."+smasks+"\\."+smasks+"\\."+smasks
this.ccsubnetmask=ccsmasks+"\\."+ccsmasks+"\\."+ccsmasks+"\\."+smasks
this.port=ports
this.portrange=ports+"-"+ports
this.hex=hexs
this.mac=hex2+"-"+hex2+"-"+hex2+"-"+hex2+"-"+hex2+"-"+hex2
this.bmac=hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2
this.macs="^"+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+"$|"
+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+"(\\;"+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+":"+hex2+")+"
this.number=numbers
this.number2=numbers2
this.time=hours+":"+minutes
this.hour=hours
this.minute=minutes
this.ctime=hours+":"+minutes+":"+minutes
this.str=strs
this.strn=strsns
this.strname=strfilename
this.email=emails
this.emailm=emails2
this.ipnms=ipssnm
this.n0_32=n0_32
this.ipnms1=ipssn
this.inte=inte
this.name=namepass
this.name2=namepass2
this.nonwords=nonword
this.strsnmps=strsnmp
this.strsnmps1=strsnmp1
this.hexcolor=hexcolor;
}
function showmsg(cobj,Result,msg)
{
sobjia=inArr(spanary,cobj)
if(!Result){if(!sobjia)spanary[spanary.length]=cobj}
else if(sobjia)spanary.splice(inArrix,1)
cobj.style.color=(Result)?"":"#FF0000"
cobj.style.backgroundColor=(Result)?"":"#FFFF99"
}
function chkForm()
{
if(spanary.length!=0)
{
alert(GetElmCont("valChk_0","Please check the settings again!"));
try {spanary[0].focus();}
catch( err ){}
return false;
}
else return true
}
function clear_valchk_for_undo(){
if(spanary.length!=0){
for(s=0;s<spanary.length;s++){
spanary[s].style.color=""
spanary[s].style.backgroundColor=""
}
spanary.length=0 //set to no error!!
}
}
function clear_valchk(obj){
if(spanary.length!=0){
for(s=0;s<spanary.length;s++){
if(obj==spanary[s]){ //如果物件出現在spanary之中，就清除記錄
spanary[s].style.color="";
spanary[s].style.backgroundColor="";
spanary.splice(s,1);
}
}
}
}
function cvr(chkval,rs,re)
{
renumber=new RegExp("^"+pn.number+"$")
chkvalo=chkval
chkval=parseInt(chkval)
if(arguments.length<3)
{
if(rs.indexOf("-")!=-1){
v=rs.split("-");
rs=v[0];
re=v[1];
}
else {
re=rs;
rs=0;
}
}
return (renumber.test(chkvalo)&&rs<=chkval&&chkval<=re)
}
function clen(chklen,rs,re)
{
restr=new RegExp("^"+pn.str+"$")
chkleno=chklen
chklen=chklen.length
if(arguments.length<3)
{
if(String(rs).indexOf("-")!=-1){
v=rs.split("-");
rs=v[0];
re=v[1];
}
else {
re=rs;
}
}
return (restr.test(chkleno)&&rs<=chklen&&chklen<=re)
}
function inArr(arr,itm)
{
inArrix=0
for(aa=0;aa<arr.length;aa++)
{
if(arr[aa]==itm){inArrix=aa;return true;}
}
return false;
}
function add0(k1)
{
k1l=k1.length
for(kk=0;kk<(8-k1l);kk++){k1='0'+k1}
return k1
}
function turnbinary(v)
{  //ip address 轉為 binary, for subnet mask checking.
ipa=v.split(".")
ipa2=""
for(i=0;i<4;i++)
{
k=parseInt(ipa[i]).toString(2)
if(k.length<8)k=add0(k)
ipa2+=k+((i<3)?".":"")
}
return ipa2
}
/* check IP - chkI(this,'a')
1. 'a' => 合法 IP及 0.0.0.0
1. 'b' => 合法 IP，不可以是 0.0.0.0
1. 'c' => 合法 IP，且為 mask 型式
1. 'd' => 合法 IP，必須和 LAN IP 同一 subnet
1. 'r' => 合法 IP range
*/
function chkI(obj,type,separator)
{
objval=obj.value
reip=new RegExp("^"+pn.ip+"$")
resm=new RegExp("^"+pn.subnetmask+"$")
resmcc=new RegExp("^"+pn.ccsubnetmask+"$")
reipr=new RegExp("^"+pn.iprange+"$")
ipc=reip.test(objval)
if(type=='a') //合法 IP，包含 0.0.0.0
{
cmsg=GetElmCont("valChk_1","IP address is invalid.")
chkResult=ipc
}
if(type=='b') //合法 IP，不包含 0.0.0.0
{
cmsg=GetElmCont("valChk_1","IP address is invalid.")
chkResult=ipc&&(objval!="0.0.0.0")
}
if(type=='c') //一般 subnet mask
{
cmsg=GetElmCont("valChk_2","Subnet mask is invalid.")
chkResult=reip.test(objval)?(resm.test(turnbinary(objval))):false
}
if(type=='d') //合法 IP，必須和 LAN IP 同一 subnet
{
lanip="192.168.20.1"
cmsg="The subnet of IP address should be equal to LAN IP address("+lanip+")."
lips=lanip.lastIndexOf(".")
ipls=new RegExp("^"+lanip.substring(0,lips+1)+pn.ip1+"$")
chkResult=ipc&&ipls.test(objval)
}
if(type=='e') //subnet mask for class C
{
cmsg=GetElmCont("valChk_2","Subnet mask is invalid.")
chkResult=reip.test(objval)?(resmcc.test(turnbinary(objval))):false
}
if(type=='f') // FQDN
{
cmsg=GetElmCont("valChk_1","FQDN is invalid.");
var fqdnRegExp = new RegExp("^([a-z0-9]+\\.)?([a-z0-9][a-z0-9-]*\\.)+[a-z]{2,6}$");
chkResult = fqdnRegExp.test(objval);
}
if(type=='m') // multiple IP, separated by "separator"
{
cmsg=GetElmCont("valChk_1","IP address is invalid.");
if(typeof(separator)=='undefined') separator = ','; // set default separator to ','
var ip_list = objval.split(separator);
chkResult = true;
for(var ip_idx = 0; ip_idx < ip_list.length; ++ip_idx) { // check each IP
if(!reip.test(ip_list[ip_idx])) {
chkResult = false; // any one of IP is invalid
break;
}
}
}
if(type=='r') // normal IP range, including single IP address. e.g. 192.168.123.1-192.168.123.254
{
cmsg=GetElmCont("valChk_3","IP address range is invalid.");
chkResult=reip.test(objval)||reipr.test(objval);
}
if(type=='u') // url: allow IP addresses to also be a valid URL
{
cmsg=GetElmCont("valChk_1","URL is invalid.");
var urlReg = /^(http(s?):\/\/)?(((www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,6})+)|(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b))(:([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/;
chkResult = urlReg.test(objval);
}
if(type=='l') { // valid IP address, including 0.0.0.0. Don't accept empty value.
cmsg=GetElmCont("valChk_4","LAN IP address is invalid.");
chkResult=ipc&&(objval!="");
}
else { // accept empty value if type is other than 'l'
chkResult=chkResult||(objval=="");
}
showmsg(obj,chkResult,cmsg);
return chkResult;
}
/* check Number - chkN(this,'a')
1. 'i' => 最後一位 ip，1~255，0 也接受，代表沒有設定
1. 'p' => tcp/udp 的 port 1~65535， 0 也接受，代表沒有設定
1. 'q' => tcp/udp 的 port 1~65535，"" 也接受，代表沒有設定
1. 'r' => tcp/udp 的 port range，接受單一 port 或單一 port range
1. 'n' => tcp/udp 的 port range，接受單一 port 或多個 port(以 ","" 隔開)及 port range 混合輸入 (eg.Special AP 的 incoming port)
1. 'j' => static/Dynamic MTU (?)
1. 'm' => PPPoE MTU (?)
1. 'l' => PPTP MTU (?)
1. 'l' => L2TP MTU (?)
1. 't' => wan type idle timeout
1. 'x' => admin idle timeout
1. 'd' => ¤@¯ë¦Xªk¼Æ¦r¡A¥i¥H¥]§t 0¡A¦p MTU, idle time (¬í)
1. 'u' => User defined
*/
function chkN(obj,type,range,itemname)
{
objval=obj.value
report =new RegExp("^"+pn.port+"$")
reportr=new RegExp("^"+pn.portrange+"$")
renumber=new RegExp("^"+pn.number+"$")
renumber2=new RegExp("^"+pn.number2+"$")
inte = new RegExp("^"+pn.inte+"$");
if(arguments.length<3)
{
range=""
itemname=""
objl=locateObj(obj.form,obj)
/*
以下可以得出value是否要判斷range
ex.<input type="text" id="vrrp_si>要有range防呆,
則html裡要有顯示range提示的<span>給user看, 順便也當成設range的值
<span>命名原則為<text id>+<_range>,一般是緊接在<text>的後面
所以若看到<span id=vrrp_si_range>, 就代表<input type="text" id="vrrp_si>要range防呆
......toshi
*/
tagary=document.getElementsByTagName("span");
for(t=0;t<tagary.length;t++){
tid=tagary[t].id          //get <span id>
if(tid==obj.id+"_range"){ //ex. <span id=vrrp_si_range>(1-255)</span>
tids=GetElmCont(tid)   //get (1-255)
range=tids.substring(1,tids.length-1) //range=1-255
}
}
/*
這是舊的寫法...toshi
if((obj.id.length>0)&&(obj.id.indexOf("format : ")!=-1))
{
otls=splits(obj.id,"format : ")
itemname=otls[0]
range=(otls.length>1)?otls[1]:""
}
*/
if(itemname=="")itemname="Value"
}
if(type=='i') //最後一位 ip，1~255，0 也接受，代表沒有設定
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(report.test(objval)&&cvr(objval,0,255))
}
if(type=='k') //最後一位 ip，1~255，不接受 0
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||report.test(objval)&&cvr(objval,1,255))
}
if(type=='i_1') //最後一位 ip，1~254
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||report.test(objval)&&cvr(objval,1,254))
}
if(type=='i_2') //iprange，0~255
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||report.test(objval)&&cvr(objval,0,255))
}
if(type=='i_3')
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||report.test(objval)&&cvr(objval,range))
}
if(type=='o') //Number 0~65536， 0 也接受，代表沒有設定
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||renumber.test(objval)&&cvr(objval,0,65536))
}
if(type=='o_1') //Number 0~65535， 0 也接受，代表沒有設定
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||renumber.test(objval)&&cvr(objval,0,65535))
}
if(type=='p') //tcp/udp 的 port 1~65535， 0 也接受，代表沒有設定
{
cmsg=GetElmCont("valChk_6","Port is invalid.")
chkResult=(report.test(objval)&&cvr(objval,1,65535))
}
if(type=='q') //tcp/udp 的 port 1~65535， "" 也接受，代表沒有設定
{
cmsg=GetElmCont("valChk_6","Port is invalid.")
chkResult=((objval=="")||cvr(objval,1,65535))
}
if(type=='f_1') //range 10~10000
{
cmsg=GetElmCont("aipslist_18","Packets/second value is 10~10000!")
chkResult=((objval=="")||cvr(objval,10,10000))
}
if(type=='r') //tcp/udp 的 port range，接受單一 port 或單一 port range
{
reportr.exec(objval)
cmsg=GetElmCont("valChk_8","Port range is invalid.")+" (Format eg. 1-65535)"
portrary=splits(objval,"-")
chkResult=((objval.indexOf("-")!=-1)?(cvr(portrary[0],"1-65535")&&cvr(portrary[1],"1-65535")&&(parseInt(portrary[0])<parseInt(portrary[1]))):(report.test(objval)&&cvr(objval,1,65535)))
}
if(type=='n') // tcp/udp 的 port range，接受單一 port 或多個 port(以 "," 隔開)及 port range 混合輸入 (eg.Special AP 的 incoming port)
{
cmsg=GetElmCont("valChk_6","Port is invalid.")+" (Format eg. 1-65535,777)"
portrsary=splits(objval,",")
cflag=0
for(p=0;p<portrsary.length;p++)
{
portrary=splits(portrsary[p],"-")
chkResult=((portrsary[p].indexOf("-")!=-1)?(cvr(portrary[0],"1-65535")&&cvr(portrary[1],"1-65535")&&(parseInt(portrary[0])<parseInt(portrary[1]))):(report.test(portrsary[p])&&cvr(portrsary[p],1,65535)))
if(!chkResult)cflag++
}
chkResult=(cflag==0)
}
if(type=='a') //一般合法數字
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval))
}
if(type=='a2') //一般合法數字,只能輸入0和非0開頭的數字
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber2.test(objval))
}
if(type=='b') //一般合法數字，0 也接受,沒填也接受
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((renumber.test(objval))||(objval==""))
}
/*
1. 'j' => static/Dynamic MTU  (range?)
1. 'k' => PPPoE MTU (range?)
1. 'l' => PPTP MTU  (range?)
1. 'm' => L2TP MTU  (range?)
1. 't' => wan type idle timeout  (range?)
1. 'x' => admin idle timeout (range?)
*/
if(type=='j') //static/Dynamic MTU  (range?)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval)&&cvr(objval,512,1500)||(objval=="0"))
}
if(type=='m') //PPPoE MTU (range?)
{
cmsg=GetElmCont("valChk_9","MTU is invalid!")+" (576<=MTU<=1492 or 0(Auto))"
chkResult=(renumber.test(objval)&&(cvr(objval,512,1492)||(objval=="0")))
}
if(type=='l') //PPTP MTU (range?)
{
cmsg=GetElmCont("valChk_9","MTU is invalid!")+" (576<=MTU<=1460 or 0(Auto))"
chkResult=(renumber.test(objval)&&(cvr(objval,512,1460)||(objval=="0")))
}
if(type=='g') //3G MTU (range 0-1500)
{
cmsg=GetElmCont("valChk_9","MTU is invalid!")+" (0<=MTU<=1500 or 0(Auto))"
chkResult=(renumber.test(objval)&&(cvr(objval,0,1500)||(objval=="0")))
}
if(type=='h') //TLS Renegotiation Time (range 0-86400)
{
cmsg=GetElmCont("valChk_9","TLS Renegotiation Time is invalid!")+" (0-86400)"
chkResult=(renumber.test(objval)&&(cvr(objval,0,86400)||(objval=="0")))
}
if(type=='v') //Connection Retry (range -1~86400)
{
cmsg=GetElmCont("valChk_9","Connection Retry is invalid!")+" (-1~86400)"
nnn=("-1"==objval)
chkResult=(nnn||(renumber.test(objval)&&(cvr(objval,0,86400)||(objval=="0"))))
}
/*
if(type=='m') //L2TP MTU (range?)
{
cmsg="MTU is invalid! (576<=MTU<=1460)"
chkResult=(renumber.test(objval)&&cvr(objval,576,1460)&&(objval!="0"))
}
*/
if(type=='t') //wan type idle timeout  (range?)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval)&&cvr(objval,30,300)&&(objval!="0"))
}
if(type=='x') //admin idle timeout (range?)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval)&&cvr(objval,30,300)&&(objval!="0"))
}
if(type=='c') //一般合法數字，不能包含 0(?)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval)&&cvr(objval,range)&&(objval!="0"))
}
if(type=='d') //一般合法數字，可以包含 0，如 MTU, idle time (秒)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval)&&cvr(objval,range))
}
if(type=='y') //wan type idle timeout  (range? : Min)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval)&&cvr(objval,1,65521)||(objval=="0"))
}
if(type=='e') //一般合法數字，可以包含 0，無範圍檢查
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=(renumber.test(objval))
}
if(type=='u') //User defined
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||renumber.test(objval)&&cvr(objval,range))
}
if(type=='u2') //User defined ,只能輸入0和非0打頭的數字
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=((objval=="")||renumber2.test(objval)&&cvr(objval,range))
}
if(type=='f') //other function check
{//execute function (range)
func=range
}
if(type=='inr') //for Interval 0~xxxxx range x~xxxxx 但是不能0開頭 by kent
{
cmsg="Value is invalid."
chkResult=((objval=="")||inte.test(objval)&&cvr(objval,range))
}
if(type=='in') //for Interval 0~xxxxx 但是不能0開頭 by kent
{
cmsg="Value is invalid."
chkResult=((objval=="")||inte.test(objval))
}
if(range!=""&&range.indexOf("(")==-1)range="("+range
if(range!=""&&range.indexOf(")")==-1)range+=")"
if(itemname!="") cmsg=itemname+" is invalid. "+range
showmsg(obj,chkResult,cmsg)
return chkResult
}
/* check Time - chkT(this,'a')
1. 'h' => 一般合法小時，(0-23)
1. 'm' => 一般合法分鐘/秒，(0-59)
1. 's' => 一般合法時:分，(12:34)
1. 'c' => 一般合法小時:分鐘:秒，(1:23:45)
*/
function chkT(obj,type)
{
objval=obj.value
rehour = new RegExp("^"+pn.hour+"$")
reminute = new RegExp("^"+pn.minute+"$")
retime = new RegExp("^"+pn.time+"$")
rectime = new RegExp("^"+pn.ctime+"$")
if(type=='h') //合法小時，(0-23)
{
cmsg=GetElmCont("valChk_10","Hour is invalid.")
chkResult=rehour.test(objval)
}
if(type=='m') //合法分鐘/秒，(0-59)
{
cmsg=GetElmCont("valChk_11","Time is invalid.")
chkResult=reminute.test(objval)
}
if(type=='s') //合法時:分，(12:34)
{
cmsg=GetElmCont("valChk_11","Time is invalid.")
chkResult=retime.test(objval)
}
if(type=='c') //合法小時:分鐘:秒，(1:23:45)
{
cmsg=GetElmCont("valChk_11","Time is invalid.")
chkResult=rectime.test(objval)
}
showmsg(obj,chkResult,cmsg)
return chkResult
}
/* check Hex - chkH(this,'a')
1. 'm' => 合法 MAC
1. 'w' => 合法 Hex (WEP key)
1. 'p' => 合法 Hex (Preshared Key)
*/
function chkH(obj,type)
{
objval=obj.value
rehex = new RegExp("^"+pn.hex+"$")
remac = new RegExp("^"+pn.mac+"$")
if(type=='m') //一般合法 MAC
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=remac.test(objval)
}
if(type=='w') //合法 Hex (WEP key)
{
cmsg=GetElmCont("valChk_13","WEP key is invalid.")
chkResult=rehex.test(objval)
}
if(type=='p') //一般合法 Port range
{
cmsg=GetElmCont("valChk_14","Preshared Key is invalid.")
chkResult=rehex.test(objval)
}
chkResult=chkResult||(objval=="")
showmsg(obj,chkResult,cmsg)
return chkResult
}
function chkB(obj,type)
{
objval=obj.value
rebmac = new RegExp("^"+pn.bmac+"$")
remac = new RegExp("^"+pn.mac+"$")
if(type=='a') //一般合法 MAC
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=rebmac.test(objval)
}
if(type=='b') //一般合法 MAC , ":"
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=remac.test(objval)
}
if(type=='c') //一般合法 MAC,不包含00:00:00:00:00:00
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=rebmac.test(objval)&&(objval!="00:00:00:00:00:00")
}
if(type == 'd') //可接受":"跟"-"
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=rebmac.test(objval)||remac.test(objval)&&(objval!="00:00:00:00:00:00")
}
chkResult=chkResult||(objval=="")
showmsg(obj,chkResult,cmsg)
return chkResult
}
/* check String - chkS(this,'a')
1. 'a' => 字串，不能包含空白
1. 'b' => 字串，可以包含空白
1. 'e' => email 字串
1. 'm' => 多個 email 字串 , ';' 隔開
1. 'r' => tcp/udp 的 port range，接受單一 port 或單一 port range
1. 'n' => tcp/udp 的 port range，接受單一 port 或多個 port(以 "," 隔開)及 port range 混合輸入 (eg .Special AP 的 incoming port)
1. 't' => SMS
1. 'sw' => special word
*/
function chkS(obj,type,seat)
{
objval=obj.value
restr = new RegExp("^"+pn.str+"$");
restrn = new RegExp("^"+pn.strn+"$");
restrname = new RegExp("^"+pn.strname+"$");
reemail = new RegExp("^"+pn.email+"$");
reemails =new RegExp("^"+pn.emailm+"$");
report =new RegExp("^"+pn.port+"$");
reportr=new RegExp("^"+pn.portrange+"$");
rehex = new RegExp("^"+pn.hex+"$");
reip=new RegExp("^"+pn.ip+"$");
reipr=new RegExp("^"+pn.iprange+"$");
reipms=new RegExp("^"+pn.ipms+"$");
reipssnm=new RegExp("^"+pn.ipnms+"$");
reipssnm1=new RegExp("^"+pn.ipnms1+"$");
reipssnm2=new RegExp("^"+pn.ipnms2+"$");
rebmac = new RegExp("^"+pn.bmac+"$");
remacs = new RegExp("^"+pn.macs+"$");
rename = new RegExp("^"+pn.name+"$");
renonwords = new RegExp("^"+pn.nonwords+"$");
restrsnmps = new RegExp("^"+pn.strsnmps+"$");
restrsnmps1 = new RegExp("^"+pn.strsnmps1+"$");
renumber = new RegExp("^"+pn.number+"$");
recolor = new RegExp(pn.hexcolor);
ipc=reip.test(objval)
var chkResult;
if(type=='a') //字串，不能包含空白
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=restrn.test(objval)
}
if(type=='b') //字串，可以包含空白
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=restr.test(objval)
}
if(type=='c') //Strings, can't duplicate with other fields
{
itemnames=new Array(
"Blind Call Transfer"
,"Attended Call Transfer"
,"Anonymous Call Enable"
,"Anonymous Call Disable"
,"Anonymous Call Per Call Basis"
,"DND Enable"
,"DND Disable"
,"Call Forwarding"
,"Call Return"
)
chkResult=true
for(items=0;items<9;items++)
{
cmsg=GetElmCont("none_5","This value and "+itemnames[items]+" are the same!")
ckobj=document.getElementById("it"+items)
if(ckobj==obj) continue;
if(ckobj.value==obj.value)
{
chkResult=false;
break;
}
}
}
if(type=='color') // accept Hex color or color names  e.g. #fff, #00ff00, red
{
cmsg = "Color is invalid.";
var colorNameArr = Object.keys(colorsDict);
chkResult = recolor.test(objval); // check for Hex color
if(!chkResult) { // check for color names
for(var i=0; i<colorNameArr.length; ++i) {
if(colorNameArr[i]==objval.toLowerCase()) {
chkResult = true;
break;
}
}
}
}
if(type=='d') //ssid, can not be empty
{
cmsg=GetElmCont("wpa_52","SSID can not be empty!")
chkResult=(objval!="")
}
if(type=='e') //一般合法 email 字串
{
cmsg=GetElmCont("valChk_15","Email is invalid.")
chkResult=reemail.test(objval)
}
if(type=='f') //Find a non-word character
{
cmsg="Value is invalid."
chkResult=(renonwords.test(objval))
}
if(type=='f_1') //只能數字,字母,跟"_"
{
cmsg="Value is invalid."
chkResult=(restrsnmps.test(objval))
}
if(type=='f_2') //只能數字
{
cmsg="Value is invalid."
chkResult=(renumber.test(objval)&&cvr(objval,"1-2080768")&&(objval!="0"))
}
if(type=='f_3') //只能數字跟"."
{
cmsg="Value is invalid."
chkResult=(restrsnmps1.test(objval))
}
if(type=='f_4') //合法 IP，不包含 0.0.0.0
{
cmsg=GetElmCont("valChk_1","IP address is invalid.")
chkResult=ipc&&(objval!="0.0.0.0")
}
if(type=='j') //type存成字串的數字,不可超過42949672965
{
renumber=new RegExp("^"+pn.number+"$");
cmsg="Value is invalid.";
toint = parseInt(objval,10);
chkResult = ((renumber.test(objval))&&(toint <= 42949672965)) ;
/*alert("del chkS(j)="+((renumber.test(objval))&&(toint <= 42949672965))
+","+(renumber.test(objval))
+","+(toint <= 42949672965)
)
*/
}
if(type=='t') //SMS
{
cc=0;
cmsg=GetElmCont("valChk_20","The length of Text message is too long.")
var num_str = "";
for(p=0;p<objval.length;p++)
{
strc = objval.charCodeAt(p);
if (!(strc>=32&&strc<=126)){cc=70;break;}
else cc=160;
}
if(objval.length > cc)
{
var num = parseInt(objval.length/cc);
cc = cc*(num+1);
num_str = " ("+(num+1)+")";
}
SetElmCont("inputtextnum",objval.length+"/"+cc+num_str)
chkResult=(objval.length<=cc)
}
if(type=='i') //一般 IP range(單一合法 IP 也成立)
{
cmsg=GetElmCont("valChk_3","IP address range is invalid.")
chkResult=reip.test(objval)||reipr.test(objval)
}
if(type=='i1') //多個 ip , ';' 隔開
{
cmsg=GetElmCont("valChk_3","IP address range is invalid.")
chkResult=reipms.test(objval)
}
if(type=='s') //多個 subnet , ';' 隔開
{
cmsg=GetElmCont("valChk_2","Subnet is invalid.")
chkResult=reipssnm.test(objval)
}
if(type=='v') //IP/Subnet
{
cmsg=GetElmCont("valChk_2","Setting is invalid. (Format eg. IP/netmask.)")
chkResult=reipssnm1.test(objval)
}
if(type=='m') //多個 email 字串 , ';' 隔開
{
cmsg=GetElmCont("valChk_15","Email is invalid. (Format eg. Email-A;Email-B;Email-C... Or Email-A,Email-B,Email-C...)")
chkResult=reemails.test(objval)
}
if(type=='r') //tcp/udp 的 port range，接受單一 port 或單一 port range
{
reportr.exec(objval)
cmsg=GetElmCont("valChk_6","Port is invalid.")+" (Format eg. 1-65535)"
portrary=splits(objval,"-")
chkResult=((objval.indexOf("-")!=-1)?(cvr(portrary[0],"1-65535")&&cvr(portrary[1],"1-65535")&&(parseInt(portrary[0])<parseInt(portrary[1]))):(report.test(objval)&&cvr(objval,1,65535)))
}
if(type=='n') // tcp/udp 的 port range，接受單一 port 或多個 port(以 "," 隔開)及 port range 混合輸入 (eg.Special AP 的 incoming port)
{
cmsg=GetElmCont("valChk_6","Port is invalid.")+" (Format eg. 1-65535,777)"
portrsary=splits(objval,",")
cflag=0
for(p=0;p<portrsary.length;p++)
{
portrary=splits(portrsary[p],"-")
chkResult=((portrsary[p].indexOf("-")!=-1)?(cvr(portrary[0],"1-65535")&&cvr(portrary[1],"1-65535")&&(parseInt(portrary[0])<parseInt(portrary[1]))):(report.test(portrsary[p])&&cvr(portrsary[p],1,65535)))
if(!chkResult)cflag++
}
chkResult=(cflag==0)
}
if(type=='n1') //多個 port(以 ";" 隔開)
{
cmsg=GetElmCont("valChk_6","Port is invalid.")+" (Format eg. 1-65535,777)"
portrsary=splits(objval,";")
cflag=0
for(p=0;p<portrsary.length;p++)
{
portrary=splits(portrsary[p],"-")
chkResult=(report.test(portrsary[p])&&cvr(portrsary[p],1,65535))
if(!chkResult)cflag++
}
chkResult=(cflag==0)
}
if(type=='w') //合法 Hex (WEP key)
{//seat for hex、ascll選項不在key text的前一個....liwei
if(seat) ktype=obj.form.elements[locateObj(obj.form,obj)-seat].value
else ktype=obj.form.elements[locateObj(obj.form,obj)-1].value
cmsg=GetElmCont("valChk_13","WEP key is invalid.")+"  \n "+((ktype==0)?GetElmCont("valChk_16","Please input 10 or 26 hexadecimal digits in WEP Key field!!"):GetElmCont("valChk_17","Please input 5 or 13 ASCII characters in WEP Key field!!"))
wkeylen=obj.value.length
chkResult=(objval!="")
&&(((ktype=="0")&&(clen(objval,10)||clen(objval,26))&&rehex.test(objval))
||((ktype=="1")&&(clen(objval, 5)||clen(objval,13))&&restr.test(objval)))
}
if(type=='p') //合法 Hex (Preshared Key)
{
cmsg="Preshared Key is invalid."
pkeylen=obj.value.length
if((pkeylen>64)||(pkeylen<8))
{
cmsg="Please input 64 hexadecimal digits or 8~63 ASCII character in Preshared Key field!!"
chkResult=false; //fix 未顯示錯誤訊息......liwei
}
else if(pkeylen==64)
{
cmsg="Please input 64 hexadecimal digits in Preshared Key field!!"
chkResult=rehex.test(objval)
}
else  //ASCII
{
chkResult=(objval!="")
}
}
if(type=='x') //vnp Preshared Key 最少1個 最多 32
{
cmsg="Preshared Key is invalid."
pkeylen=obj.value.length
if(pkeylen < 1)
{
cmsg = "Preshared Key 1~32";
chkResult = false;
}
else
{
chkResult = (objval!="");
}
}
if(type=='x1') //可用於user在輸入時直接判斷長度是否為符合條件
{
cmsg=GetElmCont("valChk_5","Value is invalid.The value length is"+seat)
if(seat.search("-")==-1) chkResult=!(objval.length < seat);
else
{
var arr = seat.split("-");
chkResult=!(objval.length < arr[0] || objval.length > arr[1]);
}
}
if(type=='g') //一般合法 MAC
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=rebmac.test(objval)
}
if(type=='g1') //多個 MAC 字串 , ';' 隔開
{
cmsg=GetElmCont("valChk_12","MAC address is invalid.")
chkResult=remacs.test(objval)
}
if(type=='h') //0001~FFFF for IPv6 Address Range
{
cmsg="IPv6 Address Range is invalid."
chkResult=(rehex.test(objval))&&(objval!="0")&&(objval!="00")&&(objval!="000")&&(objval!="0000")
}
if(type=='sw') //排除特殊字元
{
cmsg="Only A~Z a~z 0~9 - and _."
chkResult=(rename.test(objval));
}
if(type=='sw1') //排除特殊字元 + 不能Only number
{
cmsg="Only A~Z a~z 0~9 - and _"
renumber=new RegExp("^"+pn.number+"$");
toint = parseInt(objval,10);
/*alert("del !renumber="+(!renumber.test(objval))
+","+(rename.test(objval))
+","+((rename.test(objval))&&(!renumber.test(objval)))
)*/
chkResult=((rename.test(objval))&&(!renumber.test(objval)));
}
if(type=='sw2') //排除特殊字元 + 不能空白
{
cmsg="Only A~Z a~z 0~9 - and _."
chkResult=((rename.test(objval)) && (restrn.test(objval)));
}
if(type=='sw3') //排除特殊字元(\ / : * ? " < > |) + 不能空白
{
cmsg="Beside '\','/',':','*','?','\','<','>','|'"
chkResult=restrname.test(objval);
}
if(type=='q') // 合法 Hex (0~9 a-f A-F)
{
cmsg=GetElmCont("valChk_5","Value is invalid.")
chkResult=rehex.test(objval)
}
if((type!='w')&&(type!='p')&&(type!='h'))
chkResult=chkResult||(objval=="")
showmsg(obj,chkResult,cmsg)
return chkResult
}
function splits(strs,splitby)
{
if(strs.indexOf(splitby)==-1)
ary=new Array(strs)
else ary=strs.split(splitby)
return ary
}
/*----------  20160707 encrypt password  start  ----------*/
/*-------------- encrypt 1 --------------
loginpage : add "aes.js" , "jsbn.js" , "jsbn2.js" , "rsa.js" (according to DIR-510L)
-------------- encrypt 2 --------------
change wifi , change login password : use NetComm key
-> change password to encrypt password ->pwd_trans()
after save -> check source htm / url ,can't find any correct password(Decryption)
after save -> this field have value: show ***** ,no value: show null
*/
/* ===== NetComm key rule =====
if value=4 -> ASCII=52  -> must three length=052 ->05 + 2(in ASCII is 50) ->0550
if value=z -> ASCII=122 -> three length          ->12 + 2(in ASCII is 50) ->1250
*/
function pwd_trans(key_id,type){
var strc=""
pwd=document.getElementById(key_id).value
if(type=='sima'){
if(pwd==""){//if SIM PIN Code input nothing,set space to encrypt
pwd = " ";
}
}
for(p=0;p<pwd.length;p++)
{
str_code = pwd.charCodeAt(p).toString(10);
if(str_code.length == 2)str_code="0"+str_code
strc+=str_code.substring(0,1)+str_code.substring(1,2)+str_code.charCodeAt(2).toString(10)
}
return strc;
}
function pwd_show(p){
pwdshow=""
for(i=0;i<document.getElementById(p).value.length;i++){
pwdshow+="*"
}
document.getElementById(p).value=pwdshow;
}
/*----------  20160707 encrypt password  end  ----------*/