// Copyright © 2001,2002 Ubicom Inc. . All rights reserved. // Author: Russell Smith. // NOTES: // * don't use array.push(), it is not supported in Explorer v5.0. // use array.concat() instead. // base 64 encoding is used, except for the following changes: // * the symbols . and _ are used instead of + and / // * the binary byte string is assumed to be a multiple of 3 bytes, so that // the base-64 string is a multiple of 4 characters. if it is not, it is // padded with 0's. no '=' symbols are used to mark the end of the encoded // string. // convert an array of 8-bit bytes into a base-64 encoded string //====================Begin section added by Jerry Hu========== // check if a mac address is valid, all zeros are invalid function check_integer(value) { for(var i=0;i> 18) & 0x3f); b += b64.charAt((x >> 12) & 0x3f); b += b64.charAt((x >> 6) & 0x3f); b += b64.charAt(x & 0x3f); } return b; } function charToSixBits (c) { if (c=='.') return 0; if (c >= 'A' && c <= 'Z') return c.charCodeAt(0) + 1 - "A".charCodeAt(0); if (c >= 'a' && c <= 'z') return c.charCodeAt(0) + 27 - "a".charCodeAt(0); if (c >= '0' && c <= '9') return c.charCodeAt(0) + 53 - "0".charCodeAt(0); return 63; } // read base-64 encoded binary data from the string `buf', and return // the resulting array of 8-bit numbers. invalid characters in the string will // be interpreted as 'A'. function convertFromBase64 (buf) { while (buf.length & 3) buf += 'A'; // make 'buf' a multiple of 4 var dst = new Array; for (var i = 0; i < buf.length; i += 4) { var cc = (charToSixBits (buf.charAt(i)) << 18) | (charToSixBits (buf.charAt(i+1)) << 12) | (charToSixBits (buf.charAt(i+2)) << 6) | (charToSixBits (buf.charAt(i+3))); dst = dst.concat ((cc >> 16) & 0xff); dst = dst.concat ((cc >> 8) & 0xff); dst = dst.concat ((cc) & 0xff); } return dst; } // convert a string to a byte array function stringToByteArray (s,len) { var a = new Array; var l = s.length; if (l > len) l = len; for (var i=0; i < l; i++) { a = a.concat (s.charCodeAt (i)); } for (var i=l; i < len; i++) { a = a.concat (0); } a = a.concat (0); return a; } // convert a byte array to a string. function byteArrayToString (b) { var s = ""; for (var i=0; i < b.length; i++) { if (b[i]) s += String.fromCharCode (b[i]); else break; } return s; } // convert a hex string of 'len' bytes into a byte array of 'len2' bytes. // ignore leading and trailing whitespace. if there are any conversion errors // or the string is the wrong length then return 0, else return the // byte array. if the string is empty or all whitespace, return an array of // all zeros. function convertHexString (s,len,len2) { if (s.match (/^\s*$/)) { var a = new Array; for (var i=0; i 255) return 0; a = a.concat (q); } return a; } else return 0; } function byteArrayToHexString (a) { var s = ""; for (var i=0; i < a.length; i++) { var s2 = a[i].toString(16); if (s2.length < 2) s2 = '0' + s2; s += s2; } return s.toUpperCase(); } // same as byteArrayToHexString() but an all-zero array will be converted // into a blank string. function byteArrayToHexString2 (a) { for (var i=0; i < a.length; i++) { if (a[i] != 0) return byteArrayToHexString (a); } return ""; } function byteArrayToIPAddress (a) { var s = ""; for (var i=0; i < 4; i++) { s += a[i].toString(10); if (i < 3) s += "."; } return s; } function byteArrayToMACAddress (a) { var s = ""; for (var i=0; i < 6; i++) { var s2 = a[i].toString(16); if (s2.length < 2) s2 = '0' + s2; s += s2; if (i < 5) s += ":"; } return s.toUpperCase(); } function ShowHelp(URL) { window.open(URL,"","toolbar=no,location=no,scrollbars=yes,width=680,height=480"); } function ShowHelp1(URL) { location.href = "help.shtml#"+URL; } /* * This function convert format like 01:02:03:04:05:06 to an array A * where A[1]=1, A[2]=2,... * Notes : MAC Address 00:00:00:00:00:00 is legal in this function */ function convertMACAddress (s) { var got = s.match (/^\s*([0-9a-fA-F]+)\s*[:]\s*([0-9a-fA-F]+)\s*[:]\s*([0-9a-fA-F]+)\s*[:]\s*([0-9a-fA-F]+)\s*[:]\s*([0-9a-fA-F]+)\s*[:]\s*([0-9a-fA-F]+)\s*$/); if (!got) { got = s.match(/^([0-9a-fA-F]{2})\s*([0-9a-fA-F]{2})\s*([0-9a-fA-F]{2})\s*([0-9a-fA-F]{2})\s*([0-9a-fA-F]{2})\s*([0-9a-fA-F]{2})\s*$/); if(!got){ return 0; } } //alert(got); var a = new Array; for (var i=1; i <= 6; i++) { var q = parseInt(got[i],16); if (q < 0 || q > 255) return 0; //if(i == 1 && (q > 223 || q == 127)) return 0; a = a.concat (q); } return a; }