diff options
author | Simone Bortolin <simonebortolin@users.noreply.github.com> | 2022-12-27 16:41:48 +0100 |
---|---|---|
committer | Simone Bortolin <simonebortolin@users.noreply.github.com> | 2022-12-27 16:41:48 +0100 |
commit | 367d77a31ee18c41bc8a47536ea187dad755e98b (patch) | |
tree | 387aa950bbad4c09ce8843b597e685d96ce9b5e1 | |
parent | add some thing (diff) | |
download | hack-gpon.github.io-eeprom.tar hack-gpon.github.io-eeprom.tar.gz hack-gpon.github.io-eeprom.tar.bz2 hack-gpon.github.io-eeprom.tar.lz hack-gpon.github.io-eeprom.tar.xz hack-gpon.github.io-eeprom.tar.zst hack-gpon.github.io-eeprom.zip |
-rw-r--r-- | _includes/js/custom.js | 196 | ||||
-rw-r--r-- | _ont/ont-huawei-ma5671a-rooted.md | 51 |
2 files changed, 186 insertions, 61 deletions
diff --git a/_includes/js/custom.js b/_includes/js/custom.js index 3e14a68..228f2ee 100644 --- a/_includes/js/custom.js +++ b/_includes/js/custom.js @@ -139,7 +139,13 @@ class uuencoding { outBytes[outIndex + 2] = b3 & 0xFF; } } -/* + +function getChunks(s, i) { + var a = []; + do{ a.push(s.substring(0, i)) } while( (s = s.substring(i)) != "" ); + return a; +} + class asciiHex { static asciiToHex(str, prefix = "0x", glue = " ") { var prefixi = glue !== "" ? prefix : ""; @@ -159,40 +165,41 @@ class gponSerial { #vendor; #progressive; constructor(vendor, progressive) { - if(vendor.length == 4) { - this.#vendor = vendor.toUpperCase(); - } else if(vendor.length == 8) { - this.#vendor = asciiHex.hexToAscii(vendor,'','').toUpperCase(); - } else { - throw "vendor length unvalid"; - } - if(progressive.length == 8) { - this.#progressive = progressive.toLowerCase(); + if(progressive !== undefined) { + if(vendor.length == 4) { + this.#vendor = vendor.toUpperCase(); + } else if(vendor.length == 8) { + this.#vendor = asciiHex.hexToAscii(vendor,'','').toUpperCase(); + } else { + throw "vendor length unvalid"; + } + if(progressive.length == 8) { + this.#progressive = progressive.toLowerCase(); + } else { + throw "progressive length unvalid"; + } } else { - throw "progressive length unvalid"; - } - } - constructor(serial) { - if(serial.length == 12) { - this.#vendor = serial.substring(0, 4).toUpperCase(); - this.#progressive = serial.substring(4).toLowerCase(); - } else if(serial.length == 16) { - this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); - this.#progressive = serial.substring(8).toLowerCase(); - } else { - throw "serial length unvalid"; + if(vendor.length == 12) { + this.#vendor = vendor.substring(0, 4).toUpperCase(); + this.#progressive = vendor.substring(4).toLowerCase(); + } else if(vendor.length == 16) { + this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); + this.#progressive = vendor.substring(8).toLowerCase(); + } else { + throw "serial length unvalid"; + } } } - get [vendorHex]() { - return ([...this.#vendor].map((elem, n) => Number(this.#vendor.charCodeAt(n)).toString(16)).join('')); + get vendorHex() { + return ([...this.#vendor].map((_, n) => Number(this.#vendor.charCodeAt(n)).toString(16)).join('')); } - get [vendor]() { + get vendor() { return this.#vendor; } - get [progressive]() { + get progressive() { return this.#progressive; } - get [serial]() { + get serial() { return `${this.#vendor}${this.#progressive}`; } } @@ -201,26 +208,26 @@ class gponPloam { #ploam; constructor(ploam) { if(ploam.length <= 10) { - this.#ploam = ([...gpon_password].map((elem, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); + this.#ploam = ([...gpon_password].map((_, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); this.#ploam += '0'.repeat(20-gpon_password.length); } else if(ploam.length === 20) { this.#ploam = ploam; } - else if(ploam.length === 22 && ploam.startsWith("0x")) { - this.#ploam = ploam.substring(2); + else { + throw "ploam length unvalid"; } } - get [ploam]() { + get ploam() { return asciiHex.hexToAscii(this.#ploam, '',''); } - get [ploamEncoding]() { + get ploamEncoding() { return JSON.stringify(ploam); } - get [ploamHex] () { + get ploamHex() { return this.#ploam; } -}*/ +} class eeprom1 { #hex; @@ -237,74 +244,159 @@ class eeprom1 { if(value.length != calcLength) { value += '0'.repeat(calcLength-value.length); } - this.#hex.splice(startIndex, calcLength, ...[...value]); + this.#hex.splice(startIndex*2, calcLength, ...[...value]); } - getHex() { + get hex() { return this.#hex.join(''); } - getSerial() { + get serial() { return this.getPart(233, 240); } - setSerial(value) { + set serial(value) { this.setPart(233, 240, value); } - getPloam() { + get ploam() { return this.getPart(191, 214); } - setPloam(value) { + set ploam(value) { this.setPart(191, 214, value); } - getLoid() { + get loid() { return this.getPart(191, 214); } - setLoid(value) { + set loid(value) { this.setPart(191, 214, value); } - getLpwd() { + get lpwd() { return this.getPart(215, 231); } - setLpwd(value) { + set lpwd(value) { this.setPart(215, 231, value); } - getLoidPloamSwitch() { + get loidPloamSwitch() { return this.getPart(232, 232); } - setLoidPloamSwitch(value) { + set loidPloamSwitch(value) { this.setPart(232, 232, value); } - getEquipmentID() { + get equipmentID() { return this.getPart(512, 531); } - setEquipmentID(value) { + set equipmentID(value) { this.setPart(512, 531, value); } - getVendorID() { + get vendorID() { return this.getPart(532, 535); } - setVendorID(value) { + set vendorID(value) { this.setPart(532, 535, value); } - getMacAddress() { + get macAddress() { return this.getPart(384, 389); } - setMacAddress(value) { + set macAddress(value) { this.setPart(384, 389, value); } } + +function populateForm(form, data, basename) { + for (const key in data) { + if (!data.hasOwnProperty(key)) { + continue; + } + + let name = key; + let value = data[key]; + + if ('undefined' === typeof value) + value = ''; + + if (null === value) + value = ''; + + // add basename + if (typeof(basename) !== "undefined") + name = basename + "-" + key; + + if (value.constructor === Array) { + if(typeof(basename) !== "undefined") + name += '[]'; + } else if(typeof value == "object") { + if(Object.keys(value).length === 1) { + if (typeof(basename) !== "undefined") + name += "-" + Object.keys(value)[0]; + value = value[Object.keys(value)[0]]; + } else { + if (typeof(basename) !== "undefined") + populateForm(form, value, name); + else + populateForm(form, value); + continue; + } + } + + // only proceed if element is set + let element = form.elements.namedItem(name); + if (! element) { + continue; + } + + let type = element.type || element[0].type; + + switch(type ) { + default: + element.value = value; + break; + + case 'radio': + case 'checkbox': { + let values = value.constructor === Array ? value : [value]; + for (let j = 0; j < element.length; j++) { + element[j].checked = (values.findIndex(it => it.toString() === element[j].value) > -1); + } + break; + } + case 'select-multiple': { + let values = value.constructor === Array ? value : [value]; + for (let j = 0; j < element.options.length; j++) { + element.options[j].selected = (values.findIndex(it => it.toString() === element.options[j].value) > -1); + } + break; + } + case 'select': + case 'select-one': + element.value = value.toString() || value; + break; + + case 'date': + let date = new Date(value); + date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); + element.value = date.toISOString().substring(0, 10); + break; + + case 'datetime-local': + let datetime = new Date(value); + datetime.setMinutes(datetime.getMinutes() - datetime.getTimezoneOffset()); + element.value = datetime.toISOString().substring(0, 16); + break; + } + + } +} diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 93bace5..222b4c4 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -20,20 +20,35 @@ layout: default <input type="text" class="form-control" placeholder="sfp_a2_info input" name="sfp-a2-info" id="sfp-a2-info" > <label for="sfp-a2-info">sfp_a2_info input</label> </div> + <div class="mb-3"> + <input type="submit" class="btn btn-primary" value="Show!" name="submit"> + </div> + <div class="form-floating mb-3"> + <input type="text" class="form-control" placeholder="GPON S/N" name="gpon-serial" id="gpon-serial" value=""> + <label for="gpon-serial">GPON S/N in format GPON12345678 or 47504F4E12345678, empty for not modify it</label> + </div> + <div class="form-floating mb-3"> + <input type="text" class="form-control" placeholder="GPON Ploam Password" name="gpon-ploam" id="gpon-ploam" value=""> + <label for="gpon-ploam">GPON Ploam in format 1234567890, 31323334353637383930, empty for not modify it</label> + </div> <div class="form-floating mb-3"> - <input type="text" class="form-control" placeholder="GPON S/N" name="gpon-sn" id="gpon-sn" value=""> - <label for="gpon-sn">GPON S/N in format GPON12345678 or 47504F4E12345678, empty for not modify it</label> + <input type="text" class="form-control" placeholder="GPON LoID User" name="gpon-loid" id="gpon-loid" value=""> + <label for="gpon-loid">GPON LoID User in hex format 0123456789ABCDEF, empty for not modify it</label> </div> <div class="form-floating mb-3"> - <input type="text" class="form-control" placeholder="GPON Ploam Password" name="gpon-password" id="gpon-password" value=""> - <label for="gpon-password">GPON S/N in format 1234567890, 31323334353637383930 or 0x31323334353637383930, empty for not modify it</label> + <input type="text" class="form-control" placeholder="GPON LoPW Password" name="gpon-lopw" id="gpon-lopw" value=""> + <label for="gpon-lopw">GPON LoPW Passwrd in hex format 0123456789ABCDEF, empty for not modify it</label> + </div> + <div class="form-floating mb-3"> + <input type="text" class="form-control" placeholder="GPON Ploam/LoID Switch" name="gpon-loid-ploam-switch" id="gpon-loid-ploam-switch" value=""> + <label for="gpon-loid-ploam-switch">GPON Ploam/LoID Switch</label> </div> <div class="form-floating mb-3"> <input type="text" class="form-control" placeholder="MAC address" name="mac-addr" id="mac-addr" value=""> <label for="mac-addr">MAC Address in format 48:57:02:da:be:ef, 48-57-02-da-be-ef or 485702dabeef, empty for not modify it</label> </div> <div class="mb-3"> - <input type="submit" class="btn btn-primary" value="Calculate!"> + <input type="submit" class="btn btn-primary" value="Calculate!" name="submit"> </div> <div class="form-floating mb-3"> <input readonly class="form-control" type="text" id="result" placeholder="sfp_a2_info result"> @@ -47,7 +62,26 @@ layout: default var fomrdata = new FormData(form); var sfp_a2_info = fomrdata.get('sfp-a2-info'); var sfp_a2_info_arr = sfp_a2_info.split('@'); - if(sfp_a2_info_arr.length > 10 && sfp_a2_info_arr[0] === 'begin-base64 644 sfp_a2_info ') { + var sfp_a2_info_0 = sfp_a2_info_arr.splice(0); + var sfp_a2_decode = sfp_a2_info_arr.map(it => base64ToHex(it)).join(''); + var eeprom = new eeprom1(sfp_a2_decode); + console.log(eeprom); + if(fomrdata.get('submit') == "Show!") { + fomrdata.set('gpon-serial', eeprom.serial); + fomrdata.set('gpon-ploam', eeprom.ploam); + fomrdata.set('gpon-loid', eeprom.loid); + fomrdata.set('gpon-lpwd', eeprom.lopw); + fomrdata.set('gpon-loid-ploam-switch', eeprom.loidPloamSwitch); + populateForm(form, fomrdata); + } else { + eeprom.serial = fomrdata.get('gpon-serial'); + eeprom.ploam = fomrdata.get('gpon-ploam'); + eeprom.loid = fomrdata.get('gpon-loid'); + eeprom.lopw = fomrdata.get('gpon-lopw'); + eeprom.loidPloamSwitch = fomrdata.get('gpon-loid-ploam-switch'); + document.getElementById('result').value = eeprom.hex; + } + /*if(sfp_a2_info_arr.length > 10 && sfp_a2_info_arr[0] === 'begin-base64 644 sfp_a2_info ') { var gpon_sn = fomrdata.get('gpon-sn'); if(gpon_sn.length == 12) { var vendor_id = gpon_sn.substring(0, 4); @@ -84,11 +118,10 @@ layout: default var hex = base64ToHex(sfp_a2_info_arr[9]); hex = hex.substring(0,48) + mac_addr + hex.substring(61); sfp_a2_info_arr[9] = hexToBase64(hex); - } - document.getElementById('result').value = sfp_a2_info_arr.join('@'); + } } else { document.getElementById('result').value = 'sfp_a2_info variable in wrong format!'; - } + }*/ }); function hexToBase64(hexStr) { return btoa([...hexStr].reduce((acc, _, i) => acc += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : '', '')); |