| Total Complexity | 274 |
| Complexity/F | 2.77 |
| Lines of Code | 1690 |
| Function Count | 99 |
| Duplicated Lines | 21 |
| Ratio | 1.24 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like modern/main.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | "use strict"; |
||
| 2 | |||
| 3 | sodium.ready.then(function() { |
||
| 4 | |||
| 5 | const ae = new AllEars(function(ok) { |
||
| 6 | if (ok) { |
||
| 7 | if (localStorage.greeting) { |
||
| 8 | document.getElementById("greeting").textContent = localStorage.greeting; |
||
| 9 | document.getElementById("txt_pg").value = localStorage.greeting; |
||
| 10 | } else localStorage.greeting = document.getElementById("greeting").textContent; |
||
| 11 | |||
| 12 | document.getElementById("txt_skey").style.background = "#466"; |
||
| 13 | document.getElementById("txt_skey").maxLength = "64"; |
||
| 14 | } else { |
||
| 15 | console.log("Failed to load All-Ears"); |
||
|
|
|||
| 16 | } |
||
| 17 | }); |
||
| 18 | |||
| 19 | function TabState(cur, max, btnDele, btnUpdt) { |
||
| 20 | this.cur = cur; |
||
| 21 | this.max = max; |
||
| 22 | this.btnDele = btnDele; |
||
| 23 | this.btnUpdt = btnUpdt; |
||
| 24 | } |
||
| 25 | |||
| 26 | const tabs = [ |
||
| 27 | new TabState(0, 0, false, true), // Inbox |
||
| 28 | new TabState(0, 0, false, true), // Outbx |
||
| 29 | new TabState(0, 1, true, false), // Write |
||
| 30 | new TabState(0, 2, false, false), // Notes |
||
| 31 | new TabState(0, 2, false, true) // Tools |
||
| 32 | ]; |
||
| 33 | |||
| 34 | let showHeaders = false; |
||
| 35 | |||
| 36 | let tab = 0; |
||
| 37 | const TAB_INBOX = 0; |
||
| 38 | const TAB_DRBOX = 1; |
||
| 39 | const TAB_WRITE = 2; |
||
| 40 | const TAB_NOTES = 3; |
||
| 41 | const TAB_TOOLS = 4; |
||
| 42 | |||
| 43 | // Helper functions |
||
| 44 | function getCountryName(countryCode) { |
||
| 45 | switch (countryCode) { |
||
| 46 | case "??": return "Unknown"; |
||
| 47 | case "DZ": return "Algeria"; |
||
| 48 | case "AO": return "Angola"; |
||
| 49 | case "BJ": return "Benin"; |
||
| 50 | case "BW": return "Botswana"; |
||
| 51 | case "BF": return "Burkina Faso"; |
||
| 52 | case "BI": return "Burundi"; |
||
| 53 | case "CV": return "Cabo Verde"; |
||
| 54 | case "CM": return "Cameroon"; |
||
| 55 | case "CF": return "Central African Republic"; |
||
| 56 | case "TD": return "Chad"; |
||
| 57 | case "KM": return "Comoros"; |
||
| 58 | case "CD": return "Congo"; |
||
| 59 | case "DJ": return "Djibouti"; |
||
| 60 | case "EG": return "Egypt"; |
||
| 61 | case "GQ": return "Equatorial Guinea"; |
||
| 62 | case "ER": return "Eritrea"; |
||
| 63 | case "SZ": return "Eswatini"; |
||
| 64 | case "ET": return "Ethiopia"; |
||
| 65 | case "GA": return "Gabon"; |
||
| 66 | case "GM": return "Gambia"; |
||
| 67 | case "GH": return "Ghana"; |
||
| 68 | case "GW": return "Guinea-Bissau"; |
||
| 69 | case "GN": return "Guinea"; |
||
| 70 | case "CI": return "Ivory Coast"; |
||
| 71 | case "KE": return "Kenya"; |
||
| 72 | case "LS": return "Lesotho"; |
||
| 73 | case "LR": return "Liberia"; |
||
| 74 | case "LY": return "Libya"; |
||
| 75 | case "MG": return "Madagascar"; |
||
| 76 | case "MW": return "Malawi"; |
||
| 77 | case "ML": return "Mali"; |
||
| 78 | case "MR": return "Mauritania"; |
||
| 79 | case "MU": return "Mauritius"; |
||
| 80 | case "YT": return "Mayotte"; |
||
| 81 | case "MA": return "Morocco"; |
||
| 82 | case "MZ": return "Mozambique"; |
||
| 83 | case "NA": return "Namibia"; |
||
| 84 | case "NE": return "Niger"; |
||
| 85 | case "NG": return "Nigeria"; |
||
| 86 | case "CG": return "Republic of the Congo"; |
||
| 87 | case "RW": return "Rwanda"; |
||
| 88 | case "RE": return "Réunion"; |
||
| 89 | case "SH": return "Saint Helena"; |
||
| 90 | case "SN": return "Senegal"; |
||
| 91 | case "SC": return "Seychelles"; |
||
| 92 | case "SL": return "Sierra Leone"; |
||
| 93 | case "SO": return "Somalia"; |
||
| 94 | case "ZA": return "South Africa"; |
||
| 95 | case "SS": return "South Sudan"; |
||
| 96 | case "SD": return "Sudan"; |
||
| 97 | case "ST": return "São Tomé and Príncipe"; |
||
| 98 | case "TZ": return "Tanzania"; |
||
| 99 | case "TG": return "Togo"; |
||
| 100 | case "TN": return "Tunisia"; |
||
| 101 | case "UG": return "Uganda"; |
||
| 102 | case "EH": return "Western Sahara"; |
||
| 103 | case "ZM": return "Zambia"; |
||
| 104 | case "ZW": return "Zimbabwe"; |
||
| 105 | case "AQ": return "Antarctica"; |
||
| 106 | case "BV": return "Bouvet Island"; |
||
| 107 | case "TF": return "French Southern Territories"; |
||
| 108 | case "HM": return "Heard Island and McDonald Islands"; |
||
| 109 | case "GS": return "South Georgia and the South Sandwich Islands"; |
||
| 110 | case "AF": return "Afghanistan"; |
||
| 111 | case "AM": return "Armenia"; |
||
| 112 | case "AZ": return "Azerbaijan"; |
||
| 113 | case "BH": return "Bahrain"; |
||
| 114 | case "BD": return "Bangladesh"; |
||
| 115 | case "BT": return "Bhutan"; |
||
| 116 | case "IO": return "British Indian Ocean Territory"; |
||
| 117 | case "BN": return "Brunei"; |
||
| 118 | case "KH": return "Cambodia"; |
||
| 119 | case "CN": return "China"; |
||
| 120 | case "CC": return "Cocos [Keeling] Islands"; |
||
| 121 | case "GE": return "Georgia"; |
||
| 122 | case "JO": return "Hashemite Kingdom of Jordan"; |
||
| 123 | case "HK": return "Hong Kong"; |
||
| 124 | case "IN": return "India"; |
||
| 125 | case "ID": return "Indonesia"; |
||
| 126 | case "IR": return "Iran"; |
||
| 127 | case "IQ": return "Iraq"; |
||
| 128 | case "IL": return "Israel"; |
||
| 129 | case "JP": return "Japan"; |
||
| 130 | case "KZ": return "Kazakhstan"; |
||
| 131 | case "KW": return "Kuwait"; |
||
| 132 | case "KG": return "Kyrgyzstan"; |
||
| 133 | case "LA": return "Laos"; |
||
| 134 | case "LB": return "Lebanon"; |
||
| 135 | case "MO": return "Macao"; |
||
| 136 | case "MY": return "Malaysia"; |
||
| 137 | case "MV": return "Maldives"; |
||
| 138 | case "MN": return "Mongolia"; |
||
| 139 | case "MM": return "Myanmar"; |
||
| 140 | case "NP": return "Nepal"; |
||
| 141 | case "KP": return "North Korea"; |
||
| 142 | case "OM": return "Oman"; |
||
| 143 | case "PK": return "Pakistan"; |
||
| 144 | case "PS": return "Palestine"; |
||
| 145 | case "PH": return "Philippines"; |
||
| 146 | case "QA": return "Qatar"; |
||
| 147 | case "SA": return "Saudi Arabia"; |
||
| 148 | case "SG": return "Singapore"; |
||
| 149 | case "KR": return "South Korea"; |
||
| 150 | case "LK": return "Sri Lanka"; |
||
| 151 | case "SY": return "Syria"; |
||
| 152 | case "TW": return "Taiwan"; |
||
| 153 | case "TJ": return "Tajikistan"; |
||
| 154 | case "TH": return "Thailand"; |
||
| 155 | case "TR": return "Turkey"; |
||
| 156 | case "TM": return "Turkmenistan"; |
||
| 157 | case "AE": return "United Arab Emirates"; |
||
| 158 | case "UZ": return "Uzbekistan"; |
||
| 159 | case "VN": return "Vietnam"; |
||
| 160 | case "YE": return "Yemen"; |
||
| 161 | case "AL": return "Albania"; |
||
| 162 | case "AD": return "Andorra"; |
||
| 163 | case "AT": return "Austria"; |
||
| 164 | case "BY": return "Belarus"; |
||
| 165 | case "BE": return "Belgium"; |
||
| 166 | case "BA": return "Bosnia and Herzegovina"; |
||
| 167 | case "BG": return "Bulgaria"; |
||
| 168 | case "HR": return "Croatia"; |
||
| 169 | case "CY": return "Cyprus"; |
||
| 170 | case "CZ": return "Czechia"; |
||
| 171 | case "DK": return "Denmark"; |
||
| 172 | case "EE": return "Estonia"; |
||
| 173 | case "FO": return "Faroe Islands"; |
||
| 174 | case "FI": return "Finland"; |
||
| 175 | case "FR": return "France"; |
||
| 176 | case "DE": return "Germany"; |
||
| 177 | case "GI": return "Gibraltar"; |
||
| 178 | case "GR": return "Greece"; |
||
| 179 | case "GG": return "Guernsey"; |
||
| 180 | case "HU": return "Hungary"; |
||
| 181 | case "IS": return "Iceland"; |
||
| 182 | case "IE": return "Ireland"; |
||
| 183 | case "IM": return "Isle of Man"; |
||
| 184 | case "IT": return "Italy"; |
||
| 185 | case "JE": return "Jersey"; |
||
| 186 | case "XK": return "Kosovo"; |
||
| 187 | case "LV": return "Latvia"; |
||
| 188 | case "LI": return "Liechtenstein"; |
||
| 189 | case "LU": return "Luxembourg"; |
||
| 190 | case "MT": return "Malta"; |
||
| 191 | case "MC": return "Monaco"; |
||
| 192 | case "ME": return "Montenegro"; |
||
| 193 | case "NL": return "Netherlands"; |
||
| 194 | case "MK": return "North Macedonia"; |
||
| 195 | case "NO": return "Norway"; |
||
| 196 | case "PL": return "Poland"; |
||
| 197 | case "PT": return "Portugal"; |
||
| 198 | case "LT": return "Republic of Lithuania"; |
||
| 199 | case "MD": return "Republic of Moldova"; |
||
| 200 | case "RO": return "Romania"; |
||
| 201 | case "RU": return "Russia"; |
||
| 202 | case "SM": return "San Marino"; |
||
| 203 | case "RS": return "Serbia"; |
||
| 204 | case "SK": return "Slovakia"; |
||
| 205 | case "SI": return "Slovenia"; |
||
| 206 | case "ES": return "Spain"; |
||
| 207 | case "SJ": return "Svalbard and Jan Mayen"; |
||
| 208 | case "SE": return "Sweden"; |
||
| 209 | case "CH": return "Switzerland"; |
||
| 210 | case "UA": return "Ukraine"; |
||
| 211 | case "GB": return "United Kingdom"; |
||
| 212 | case "VA": return "Vatican City"; |
||
| 213 | case "AX": return "Åland"; |
||
| 214 | case "AI": return "Anguilla"; |
||
| 215 | case "AG": return "Antigua and Barbuda"; |
||
| 216 | case "AW": return "Aruba"; |
||
| 217 | case "BS": return "Bahamas"; |
||
| 218 | case "BB": return "Barbados"; |
||
| 219 | case "BZ": return "Belize"; |
||
| 220 | case "BM": return "Bermuda"; |
||
| 221 | case "BQ": return "Bonaire, Sint Eustatius, and Saba"; |
||
| 222 | case "VG": return "British Virgin Islands"; |
||
| 223 | case "CA": return "Canada"; |
||
| 224 | case "KY": return "Cayman Islands"; |
||
| 225 | case "CR": return "Costa Rica"; |
||
| 226 | case "CU": return "Cuba"; |
||
| 227 | case "CW": return "Curaçao"; |
||
| 228 | case "DM": return "Dominica"; |
||
| 229 | case "DO": return "Dominican Republic"; |
||
| 230 | case "SV": return "El Salvador"; |
||
| 231 | case "GL": return "Greenland"; |
||
| 232 | case "GD": return "Grenada"; |
||
| 233 | case "GP": return "Guadeloupe"; |
||
| 234 | case "GT": return "Guatemala"; |
||
| 235 | case "HT": return "Haiti"; |
||
| 236 | case "HN": return "Honduras"; |
||
| 237 | case "JM": return "Jamaica"; |
||
| 238 | case "MQ": return "Martinique"; |
||
| 239 | case "MX": return "Mexico"; |
||
| 240 | case "MS": return "Montserrat"; |
||
| 241 | case "NI": return "Nicaragua"; |
||
| 242 | case "PA": return "Panama"; |
||
| 243 | case "PR": return "Puerto Rico"; |
||
| 244 | case "BL": return "Saint Barthélemy"; |
||
| 245 | case "LC": return "Saint Lucia"; |
||
| 246 | case "MF": return "Saint Martin"; |
||
| 247 | case "PM": return "Saint Pierre and Miquelon"; |
||
| 248 | case "VC": return "Saint Vincent and the Grenadines"; |
||
| 249 | case "SX": return "Sint Maarten"; |
||
| 250 | case "KN": return "St Kitts and Nevis"; |
||
| 251 | case "TT": return "Trinidad and Tobago"; |
||
| 252 | case "TC": return "Turks and Caicos Islands"; |
||
| 253 | case "VI": return "U.S. Virgin Islands"; |
||
| 254 | case "US": return "United States"; |
||
| 255 | case "AS": return "American Samoa"; |
||
| 256 | case "AU": return "Australia"; |
||
| 257 | case "CX": return "Christmas Island"; |
||
| 258 | case "CK": return "Cook Islands"; |
||
| 259 | case "TL": return "Democratic Republic of Timor-Leste"; |
||
| 260 | case "FM": return "Federated States of Micronesia"; |
||
| 261 | case "FJ": return "Fiji"; |
||
| 262 | case "PF": return "French Polynesia"; |
||
| 263 | case "GU": return "Guam"; |
||
| 264 | case "KI": return "Kiribati"; |
||
| 265 | case "MH": return "Marshall Islands"; |
||
| 266 | case "NR": return "Nauru"; |
||
| 267 | case "NC": return "New Caledonia"; |
||
| 268 | case "NZ": return "New Zealand"; |
||
| 269 | case "NU": return "Niue"; |
||
| 270 | case "NF": return "Norfolk Island"; |
||
| 271 | case "MP": return "Northern Mariana Islands"; |
||
| 272 | case "PW": return "Palau"; |
||
| 273 | case "PG": return "Papua New Guinea"; |
||
| 274 | case "PN": return "Pitcairn Islands"; |
||
| 275 | case "WS": return "Samoa"; |
||
| 276 | case "SB": return "Solomon Islands"; |
||
| 277 | case "TK": return "Tokelau"; |
||
| 278 | case "TO": return "Tonga"; |
||
| 279 | case "TV": return "Tuvalu"; |
||
| 280 | case "UM": return "U.S. Minor Outlying Islands"; |
||
| 281 | case "VU": return "Vanuatu"; |
||
| 282 | case "WF": return "Wallis and Futuna"; |
||
| 283 | case "AR": return "Argentina"; |
||
| 284 | case "BO": return "Bolivia"; |
||
| 285 | case "BR": return "Brazil"; |
||
| 286 | case "CL": return "Chile"; |
||
| 287 | case "CO": return "Colombia"; |
||
| 288 | case "EC": return "Ecuador"; |
||
| 289 | case "FK": return "Falkland Islands"; |
||
| 290 | case "GF": return "French Guiana"; |
||
| 291 | case "GY": return "Guyana"; |
||
| 292 | case "PY": return "Paraguay"; |
||
| 293 | case "PE": return "Peru"; |
||
| 294 | case "SR": return "Suriname"; |
||
| 295 | case "UY": return "Uruguay"; |
||
| 296 | case "VE": return "Venezuela"; |
||
| 297 | } |
||
| 298 | |||
| 299 | return "Error"; |
||
| 300 | } |
||
| 301 | |||
| 302 | function getCountryFlag(countryCode) { |
||
| 303 | return (!countryCode || countryCode.length !== 2 || countryCode == "??") ? "❔" : sodium.to_string(new Uint8Array([ |
||
| 304 | 240, 159, 135, 166 + countryCode.codePointAt(0) - 65, |
||
| 305 | 240, 159, 135, 166 + countryCode.codePointAt(1) - 65 |
||
| 306 | ])); |
||
| 307 | } |
||
| 308 | |||
| 309 | function getClockIcon(d) { |
||
| 310 | const h24 = d.getUTCHours(); |
||
| 311 | let h12 = (h24 === 0 ? 12 : ((h24 > 12) ? h24 - 12 : h24)); |
||
| 312 | |||
| 313 | const m60 = (d.getUTCMinutes() * 60) + d.getUTCSeconds(); |
||
| 314 | let m30 = 0; |
||
| 315 | if (m60 <= 900) { // <= 15: round down to this hour |
||
| 316 | m30 = 0; |
||
| 317 | } else if (m60 > 900 && m60 < 2700) { // 15..45: round to half-past this hour |
||
| 318 | m30 = 12; |
||
| 319 | } else { // >= 45: round up to next hour |
||
| 320 | h12++; |
||
| 321 | m30 = 0; |
||
| 322 | } |
||
| 323 | |||
| 324 | return String.fromCodePoint((128335 + h12) + m30); |
||
| 325 | } |
||
| 326 | |||
| 327 | function clearDisplay() { |
||
| 328 | let el = document.querySelector("article > img"); |
||
| 329 | if (!el) el = document.querySelector("article > audio"); |
||
| 330 | if (!el) el = document.querySelector("article > video"); |
||
| 331 | if (!el) el = document.querySelector("article > embed"); |
||
| 332 | if (!el) el = document.querySelector("article > iframe"); |
||
| 333 | if (!el) return; |
||
| 334 | |||
| 335 | URL.revokeObjectURL(el.src); |
||
| 336 | el.remove(); |
||
| 337 | } |
||
| 338 | |||
| 339 | function downloadFile(num) { |
||
| 340 | const a = document.createElement("a"); |
||
| 341 | a.href = URL.createObjectURL(new Blob([ae.GetUplMsgBody(num).buffer])); |
||
| 342 | a.download = ae.GetUplMsgTitle(num); |
||
| 343 | a.click(); |
||
| 344 | |||
| 345 | URL.revokeObjectURL(a.href); |
||
| 346 | a.href = ""; |
||
| 347 | a.download = ""; |
||
| 348 | } |
||
| 349 | |||
| 350 | function displayFile(num) { |
||
| 351 | const fileType = ae.GetUplMsgType(num); |
||
| 352 | if (!fileType) {downloadFile(num); return;} |
||
| 353 | |||
| 354 | clearDisplay(); |
||
| 355 | document.querySelector("article").scroll(0, 0); |
||
| 356 | document.querySelector("article").setAttribute("data-msgid", ae.GetUplMsgIdHex(num)); |
||
| 357 | |||
| 358 | document.getElementById("btn_mdele").disabled = false; |
||
| 359 | document.getElementById("btn_msave").disabled = false; |
||
| 360 | document.getElementById("btn_reply").disabled = true; |
||
| 361 | |||
| 362 | document.getElementById("btn_msave").onclick = function() {downloadFile(num);}; |
||
| 363 | |||
| 364 | document.querySelector("article").children[0].hidden = true; |
||
| 365 | document.querySelector("article").children[1].textContent = ae.GetUplMsgTitle(num); |
||
| 366 | |||
| 367 | switch (fileType) { |
||
| 368 | case "text": { |
||
| 369 | document.querySelector("article").children[2].hidden = false; |
||
| 370 | document.querySelector("article").children[2].textContent = sodium.to_string(ae.GetUplMsgBody(num)); |
||
| 371 | break;} |
||
| 372 | |||
| 373 | case "image": { |
||
| 374 | document.querySelector("article").children[2].hidden = true; |
||
| 375 | const img = document.createElement("img"); |
||
| 376 | img.src = URL.createObjectURL(new Blob([ae.GetUplMsgBody(num).buffer])); |
||
| 377 | document.querySelector("article").appendChild(img); |
||
| 378 | |||
| 379 | img.onclick = function() { |
||
| 380 | if (!document.fullscreen) |
||
| 381 | img.requestFullscreen(); |
||
| 382 | else |
||
| 383 | document.exitFullscreen(); |
||
| 384 | }; |
||
| 385 | break;} |
||
| 386 | |||
| 387 | case "audio": |
||
| 388 | case "video": { |
||
| 389 | document.querySelector("article").children[2].hidden = true; |
||
| 390 | const el = document.createElement(fileType); |
||
| 391 | el.controls = "controls"; |
||
| 392 | el.src = URL.createObjectURL(new Blob([ae.GetUplMsgBody(num).buffer])); |
||
| 393 | document.querySelector("article").appendChild(el); |
||
| 394 | break;} |
||
| 395 | |||
| 396 | case "pdf": { |
||
| 397 | document.querySelector("article").children[2].hidden = true; |
||
| 398 | const el = document.createElement("embed"); |
||
| 399 | el.type = "application/pdf"; |
||
| 400 | el.src = URL.createObjectURL(new Blob([ae.GetUplMsgBody(num).buffer], {type: "application/pdf"})); |
||
| 401 | document.querySelector("article").appendChild(el); |
||
| 402 | break;} |
||
| 403 | |||
| 404 | case "html": { |
||
| 405 | document.querySelector("article").children[2].hidden = true; |
||
| 406 | const el = document.createElement("iframe"); |
||
| 407 | el.allow = ""; |
||
| 408 | el.sandbox = ""; |
||
| 409 | el.referrerPolicy = "no-referrer"; |
||
| 410 | el.csp = "base-uri 'none'; child-src 'none'; connect-src 'none'; default-src 'none'; font-src 'none'; form-action 'none'; frame-ancestors 'none'; frame-src 'none'; img-src 'none'; manifest-src 'none'; media-src 'none'; object-src 'none'; script-src 'none'; style-src 'none'; worker-src 'none';"; |
||
| 411 | el.srcdoc = sodium.to_string(ae.GetUplMsgBody(num).buffer); |
||
| 412 | document.querySelector("article").appendChild(el); |
||
| 413 | break;} |
||
| 414 | } |
||
| 415 | } |
||
| 416 | |||
| 417 | function displayMsg(isInt, num) { |
||
| 418 | clearDisplay(); |
||
| 419 | |||
| 420 | document.getElementById("btn_mdele").disabled = false; |
||
| 421 | document.getElementById("btn_msave").disabled = isInt; |
||
| 422 | |||
| 423 | document.querySelector("article").scroll(0, 0); |
||
| 424 | document.querySelector("article").setAttribute("data-msgid", isInt? ae.GetIntMsgIdHex(num) : ae.GetExtMsgIdHex(num)); |
||
| 425 | |||
| 426 | const ts = isInt? ae.GetIntMsgTime(num) : ae.GetExtMsgTime(num); |
||
| 427 | |||
| 428 | if (!isInt) { |
||
| 429 | document.getElementById("btn_msave").onclick = function() { |
||
| 430 | this.blur(); |
||
| 431 | |||
| 432 | const a = document.createElement("a"); |
||
| 433 | a.href = URL.createObjectURL(new Blob([ae.ExportExtMsg(num)])); |
||
| 434 | a.download = ae.GetExtMsgTitle(num); |
||
| 435 | a.click(); |
||
| 436 | |||
| 437 | URL.revokeObjectURL(a.href); |
||
| 438 | a.href = ""; |
||
| 439 | a.download = ""; |
||
| 440 | }; |
||
| 441 | } |
||
| 442 | |||
| 443 | if (!isInt || (ae.GetIntMsgFrom(num) !== "public" && ae.GetIntMsgFrom(num) !== "system")) { |
||
| 444 | document.getElementById("btn_reply").disabled = false; |
||
| 445 | |||
| 446 | document.getElementById("btn_reply").onclick = function() { |
||
| 447 | document.getElementById("write_recv").value = isInt? ae.GetIntMsgFrom(num) : ae.GetExtMsgReplyAddress(num); |
||
| 448 | document.getElementById("write_subj").value = isInt? ae.GetIntMsgTitle(num) : ae.GetExtMsgTitle(num); |
||
| 449 | if (!document.getElementById("write_subj").value.startsWith("Re:")) document.getElementById("write_subj").value = "Re: " + document.getElementById("write_subj").value; |
||
| 450 | document.querySelector("#write2_pkey > input").value = isInt? ae.GetIntMsgFromPk(num) : ""; |
||
| 451 | |||
| 452 | document.getElementById("write_recv").readOnly = !isInt; |
||
| 453 | document.getElementById("write_subj").readOnly = !isInt; |
||
| 454 | document.getElementById("write_subj").setAttribute("data-replyid", isInt? "" : ae.GetExtMsgHdrId(num)); |
||
| 455 | |||
| 456 | tabs[TAB_WRITE].cur = 0; |
||
| 457 | document.getElementById("btn_write").disabled = false; |
||
| 458 | document.getElementById("btn_write").click(); |
||
| 459 | document.getElementById("write_body").focus(); |
||
| 460 | |||
| 461 | for (const opt of document.getElementById("write_from").options) { |
||
| 462 | if (opt.value === (isInt ? ae.GetIntMsgTo(num) : ae.GetExtMsgEnvTo(num).split("@")[0].toLowerCase())) { |
||
| 463 | opt.selected = true; |
||
| 464 | } |
||
| 465 | } |
||
| 466 | }; |
||
| 467 | } else { |
||
| 468 | document.getElementById("btn_reply").disabled = true; |
||
| 469 | } |
||
| 470 | |||
| 471 | document.querySelector("article").children[0].hidden = false; |
||
| 472 | document.querySelector("article").children[2].hidden = false; |
||
| 473 | |||
| 474 | document.getElementById("readmsg_envto").textContent = isInt ? "" : ae.GetExtMsgEnvTo(num); |
||
| 475 | document.getElementById("readmsg_hdrto").textContent = isInt ? ae.GetIntMsgTo(num) : (ae.GetExtMsgHdrTo(num) + (ae.GetExtMsgDnTo(num) ? " (" + ae.GetExtMsgDnTo(num) + ")" : "")); |
||
| 476 | |||
| 477 | const tzOs = new Date().getTimezoneOffset(); |
||
| 478 | const msgDate = new Date((ts * 1000) + (tzOs * -60000)); |
||
| 479 | document.getElementById("readmsg_date").children[0].textContent = getClockIcon(msgDate); |
||
| 480 | document.getElementById("readmsg_date").children[1].dateTime = new Date(ts * 1000).toISOString(); |
||
| 481 | |||
| 482 | if (isInt) { |
||
| 483 | document.querySelector("article").children[1].textContent = ae.GetIntMsgTitle(num); |
||
| 484 | document.querySelector("article").children[2].textContent = ae.GetIntMsgBody(num); |
||
| 485 | |||
| 486 | document.getElementById("readmsg_date").children[1].textContent = msgDate.toISOString().slice(0, 19).replace("T", " "); |
||
| 487 | |||
| 488 | document.getElementById("readmsg_ip").style.visibility = "hidden"; |
||
| 489 | document.getElementById("readmsg_rdns").style.visibility = "hidden"; |
||
| 490 | document.getElementById("readmsg_dkim").style.visibility = "hidden"; |
||
| 491 | document.getElementById("readmsg_greet").style.visibility = "hidden"; |
||
| 492 | document.getElementById("readmsg_cert").style.visibility = "hidden"; |
||
| 493 | document.getElementById("readmsg_envfrom").style.visibility = "hidden"; |
||
| 494 | document.getElementById("readmsg_envto").style.visibility = "hidden"; |
||
| 495 | |||
| 496 | if (ae.GetIntMsgFrom(num) !== "system" && ae.GetIntMsgFrom(num) !== "public") { |
||
| 497 | document.getElementById("readmsg_tls").style.visibility = "visible"; |
||
| 498 | document.getElementById("readmsg_tls").children[0].textContent = ae.GetIntMsgFromPk(num); |
||
| 499 | } else document.getElementById("readmsg_tls").style.visibility = "hidden"; |
||
| 500 | |||
| 501 | let symbol = "<span title=\"Invalid level\">⚠</span>"; |
||
| 502 | if (ae.GetIntMsgFrom(num) === "system") {if (ae.GetIntMsgLevel(num) === 3) symbol = "<span title=\"System message\">🅢</span>";} // (S) |
||
| 503 | else if (ae.GetIntMsgFrom(num) === "public") {if (ae.GetIntMsgLevel(num) === 3) symbol = "<span title=\"Public announcement\">🅟</span>";} // (P) |
||
| 504 | else if (ae.GetIntMsgLevel(num) === 0) symbol = "<span title=\"Level 0 User\">🄌</span>"; // 0 |
||
| 505 | else if (ae.GetIntMsgLevel(num) === 1) symbol = "<span title=\"Level 1 User\">➊</span>"; // 1 |
||
| 506 | else if (ae.GetIntMsgLevel(num) === 2) symbol = "<span title=\"Level 2 User\">➋</span>"; // 2 |
||
| 507 | else if (ae.GetIntMsgLevel(num) === 3) symbol = "<span title=\"Administrator\">🅐</span>"; // A (Admin) |
||
| 508 | document.getElementById("readmsg_hdrfrom").innerHTML = symbol + " " + ae.GetIntMsgFrom(num); |
||
| 509 | |||
| 510 | clearMsgFlags(); |
||
| 511 | if (!ae.GetIntMsgFlagVPad(num)) addMsgFlag("PAD", "Invalid padding"); |
||
| 512 | if (!ae.GetIntMsgFlagVSig(num)) addMsgFlag("SIG", "Invalid signature"); |
||
| 513 | if ( ae.GetIntMsgFlagE2ee(num)) addMsgFlag("E2EE", "End-to-end encrypted"); |
||
| 514 | } else { |
||
| 515 | document.querySelector("article").children[2].innerHTML = ""; |
||
| 516 | |||
| 517 | const headers = document.createElement("p"); |
||
| 518 | headers.textContent = ae.GetExtMsgHeaders(num); |
||
| 519 | headers.className = "mono"; |
||
| 520 | headers.hidden = !showHeaders; |
||
| 521 | document.querySelector("article").children[2].appendChild(headers); |
||
| 522 | |||
| 523 | const body = document.createElement("p"); |
||
| 524 | body.innerHTML = ae.GetExtMsgBody(num); |
||
| 525 | document.querySelector("article").children[2].appendChild(body); |
||
| 526 | |||
| 527 | document.querySelector("article").children[1].textContent = ae.GetExtMsgTitle(num); |
||
| 528 | document.querySelector("article").children[1].style.cursor = headers.textContent? "pointer" : ""; |
||
| 529 | document.querySelector("article").children[1].onclick = function() { |
||
| 530 | if (!headers.textContent) return; |
||
| 531 | showHeaders = !showHeaders; |
||
| 532 | headers.hidden = !showHeaders; |
||
| 533 | }; |
||
| 534 | |||
| 535 | let hdrSecs = Math.abs(ae.GetExtMsgHdrTime(num)); |
||
| 536 | let hdrTime = ""; |
||
| 537 | if (hdrSecs >= 3600) { |
||
| 538 | const hdrHours = Math.floor(hdrSecs / 3600); |
||
| 539 | hdrTime += hdrHours.toString() + "h "; |
||
| 540 | hdrSecs -= hdrHours * 3600; |
||
| 541 | } |
||
| 542 | if (hdrSecs >= 60) { |
||
| 543 | const hdrMins = Math.floor(hdrSecs / 60); |
||
| 544 | hdrTime += hdrMins.toString() + "m "; |
||
| 545 | hdrSecs -= hdrMins * 60; |
||
| 546 | } |
||
| 547 | hdrTime += hdrSecs + "s"; |
||
| 548 | |||
| 549 | const hdrTz = (ae.GetExtMsgHdrTz(num) >= 0 ? "+" : "-") + Math.floor(Math.abs(ae.GetExtMsgHdrTz(num)) / 60).toString().padStart(2, "0") + (Math.abs(ae.GetExtMsgHdrTz(num)) % 60).toString().padStart(2, "0"); |
||
| 550 | document.getElementById("readmsg_date").children[1].textContent = msgDate.toISOString().slice(0, 19).replace("T", " ") + "; " + hdrTz + " " + ((ae.GetExtMsgHdrTime(num) >= 0) ? "+" : "-") + hdrTime; |
||
| 551 | |||
| 552 | document.getElementById("readmsg_ip").style.visibility = "visible"; |
||
| 553 | document.getElementById("readmsg_rdns").style.visibility = "visible"; |
||
| 554 | document.getElementById("readmsg_dkim").style.visibility = "visible"; |
||
| 555 | document.getElementById("readmsg_greet").style.visibility = "visible"; |
||
| 556 | document.getElementById("readmsg_tls").style.visibility = "visible"; |
||
| 557 | document.getElementById("readmsg_cert").style.visibility = "visible"; |
||
| 558 | document.getElementById("readmsg_envfrom").style.visibility = "visible"; |
||
| 559 | document.getElementById("readmsg_envto").style.visibility = "visible"; |
||
| 560 | |||
| 561 | const cc = ae.GetExtMsgCountry(num); |
||
| 562 | |||
| 563 | // DKIM |
||
| 564 | let dkim = ""; |
||
| 565 | if (ae.GetExtMsgDkim(num)) { |
||
| 566 | [ // Look for a matching domain in this order |
||
| 567 | ae.GetExtMsgHdrFrom(num).split("@")[1], |
||
| 568 | ae.GetExtMsgEnvFrom(num).split("@")[1], |
||
| 569 | ae.GetExtMsgRdns(num), |
||
| 570 | ae.GetExtMsgGreet(num), |
||
| 571 | ae.GetExtMsgTlsDomain(num) |
||
| 572 | ].forEach(function(dom) { |
||
| 573 | if (dkim) return; |
||
| 574 | for (let i = 0; i < ae.GetExtMsgDkim(num).domain.length; i++) { |
||
| 575 | if (ae.GetExtMsgDkim(num).domain[i] === dom) { |
||
| 576 | dkim = dom + " ✓"; |
||
| 577 | return; |
||
| 578 | } |
||
| 579 | } |
||
| 580 | }); |
||
| 581 | |||
| 582 | if (!dkim) dkim = ae.GetExtMsgDkim(num).domain[0]; // Default to first signature domain |
||
| 583 | } |
||
| 584 | |||
| 585 | if (ae.GetExtMsgFlagDkFl(num)) dkim += " (fail)"; |
||
| 586 | |||
| 587 | // Left side |
||
| 588 | document.getElementById("readmsg_country").textContent = getCountryFlag(cc); |
||
| 589 | document.getElementById("readmsg_country").title = getCountryName(cc); |
||
| 590 | document.getElementById("readmsg_ip").children[1].textContent = ae.GetExtMsgIp(num) + (ae.GetExtMsgFlagIpBl(num) ? " ❗" : ""); |
||
| 591 | document.getElementById("readmsg_tls").children[0].textContent = ae.GetExtMsgTLS(num); |
||
| 592 | |||
| 593 | // Right side |
||
| 594 | document.getElementById("readmsg_greet").children[0].textContent = ae.GetExtMsgGreet(num) + (ae.GetExtMsgFlagGrDm(num) ? " ✓" : ""); |
||
| 595 | document.getElementById("readmsg_rdns").children[0].textContent = ae.GetExtMsgRdns(num) + (ae.GetExtMsgGreet(num) === ae.GetExtMsgRdns(num) ? " ✓" : ""); |
||
| 596 | document.getElementById("readmsg_cert").children[0].textContent = ae.GetExtMsgTlsDomain(num) ? (ae.GetExtMsgTlsDomain(num) + " ✓") : ""; |
||
| 597 | document.getElementById("readmsg_dkim").children[0].textContent = dkim; |
||
| 598 | document.getElementById("readmsg_envfrom").textContent = ae.GetExtMsgEnvFrom(num); |
||
| 599 | document.getElementById("readmsg_hdrfrom").textContent = ae.GetExtMsgHdrFrom(num) + (ae.GetExtMsgDnFrom(num) ? " (" + ae.GetExtMsgDnFrom(num) + ")" : ""); |
||
| 600 | |||
| 601 | clearMsgFlags(); |
||
| 602 | if (!ae.GetExtMsgFlagVPad(num)) addMsgFlag("PAD", "Invalid padding"); |
||
| 603 | if (!ae.GetExtMsgFlagVSig(num)) addMsgFlag("SIG", "Invalid signature"); |
||
| 604 | if (!ae.GetExtMsgFlagPExt(num)) addMsgFlag("SMTP", "The sender did not use the Extended (ESMTP) protocol"); |
||
| 605 | if (!ae.GetExtMsgFlagQuit(num)) addMsgFlag("QUIT", "The sender did not issue the required QUIT command"); |
||
| 606 | if ( ae.GetExtMsgFlagRare(num)) addMsgFlag("RARE", "The sender issued unusual command(s)"); |
||
| 607 | if ( ae.GetExtMsgFlagFail(num)) addMsgFlag("FAIL", "The sender issued invalid command(s)"); |
||
| 608 | if ( ae.GetExtMsgFlagPErr(num)) addMsgFlag("PROT", "The sender violated the protocol"); |
||
| 609 | } |
||
| 610 | } |
||
| 611 | |||
| 612 | function getErrorMessage(err) { |
||
| 613 | switch (err) { |
||
| 614 | // 0x01-0x20 Client-side error codes |
||
| 615 | case 0x01: return "Invalid input"; |
||
| 616 | case 0x02: return "Only administrators can perform this action"; |
||
| 617 | case 0x03: return "Failed connecting to server"; |
||
| 618 | case 0x04: return "Invalid input to _FetchEncrypted"; |
||
| 619 | case 0x05: return "Failed decrypting response from server"; |
||
| 620 | case 0x06: return "Invalid response length"; |
||
| 621 | case 0x07: return "Server responded with invalid data"; |
||
| 622 | case 0x08: return "Addr32 encoding failed"; |
||
| 623 | |||
| 624 | case 0x10: return "Message too short"; |
||
| 625 | case 0x11: return "Name too long"; |
||
| 626 | case 0x12: return "File too large"; |
||
| 627 | |||
| 628 | case 0x17: return "Server failed decrypting the request"; // 400 |
||
| 629 | case 0x18: return "Account does not exist"; // 403 |
||
| 630 | case 0x19: return "Server failed checking account data"; // 500 |
||
| 631 | case 0x20: return "Invalid status code in response"; |
||
| 632 | |||
| 633 | // 0x21-0x2F Generic |
||
| 634 | case 0x21: return ["FORMAT", "Invalid format"]; |
||
| 635 | case 0x22: return ["ADMINONLY", "Only administrators can perform this action"]; |
||
| 636 | case 0x23: return ["MISC", "Unknown error"]; |
||
| 637 | case 0x24: return ["INTERNAL", "Internal server error"]; |
||
| 638 | case 0x25: return ["TODO", "Functionality missing - in development"]; |
||
| 639 | case 0x26: return ["FIXME", "Unexpected error encountered"]; |
||
| 640 | |||
| 641 | case 0x2A: return ["NOTEXIST", "Item does not exist"]; |
||
| 642 | |||
| 643 | // 0xDA-0xDF Address/Create|Delete|Update |
||
| 644 | case 0xDA: return ["ADDRESS_CREATE_INUSE", "Address already taken"]; |
||
| 645 | case 0xDB: return ["ADDRESS_CREATE_ATLIMIT", "Limit reached - unable to register additional addresses"]; |
||
| 646 | case 0xDC: return ["ADDRESS_DELETE_SOMEFOUND", "Delete successful, but some addresses were not found"]; |
||
| 647 | case 0xDD: return ["ADDRESS_DELETE_NONEFOUND", "No such address(es)"]; |
||
| 648 | case 0xDE: return ["ADDRESS_UPDATE_SOMEFOUND", "Partial success - some addresses not found"]; |
||
| 649 | case 0xDF: return ["ADDRESS_UPDATE_NONEFOUND", "No update performed - address(es) not found"]; |
||
| 650 | |||
| 651 | // 0xE0-0xEF Message/Create |
||
| 652 | case 0xE0: return ["MESSAGE_CREATE_EXT_MINLEVEL", "Account level too low"]; |
||
| 653 | case 0xE1: return ["MESSAGE_CREATE_EXT_FORMAT_FROM", "Malformed from-address"]; |
||
| 654 | case 0xE2: return ["MESSAGE_CREATE_EXT_FORMAT_TO", "Malformed to-address"]; |
||
| 655 | case 0xE3: return ["MESSAGE_CREATE_EXT_FORMAT_REPLYID", "Malformed reply-id"]; |
||
| 656 | case 0xE4: return ["MESSAGE_CREATE_EXT_FORMAT_SUBJECT", "Malformed subject"]; |
||
| 657 | case 0xE5: return ["MESSAGE_CREATE_EXT_INVALID_REPLYID", "Invalid reply-id"]; |
||
| 658 | case 0xE6: return ["MESSAGE_CREATE_EXT_INVALID_FROM", "Invalid from-address"]; |
||
| 659 | case 0xE7: return ["MESSAGE_CREATE_EXT_INVALID_TO", "Invalid to-address"]; |
||
| 660 | case 0xE8: return ["MESSAGE_CREATE_EXT_BODY_SIZE", "Body too long or short"]; |
||
| 661 | case 0xE9: return ["MESSAGE_CREATE_EXT_BODY_UTF8", "Body not UTF-8"]; |
||
| 662 | case 0xEA: return ["MESSAGE_CREATE_EXT_BODY_CONTROL", "Body contains control characters"]; |
||
| 663 | case 0xEB: return ["MESSAGE_CREATE_EXT_LINE_TOOLONG", "Body exceeds line-length limit"]; |
||
| 664 | case 0xEC: return ["MESSAGE_CREATE_EXT_BODY_FORMAT", "Malformed body"]; |
||
| 665 | case 0xED: return ["MESSAGE_CREATE_EXT_BODY_TOOSHORT", "Body too short"]; |
||
| 666 | case 0xEE: return ["MESSAGE_CREATE_EXT_TODOMAIN", "Invalid to-address domain"]; |
||
| 667 | // case 0xEF: return ["", ""]; |
||
| 668 | |||
| 669 | // 0xF0-0xF9 Message/Create sendMail() |
||
| 670 | case 0xF0: return ["MESSAGE_CREATE_SENDMAIL_GREET", "Failed greeting receiver server"]; |
||
| 671 | case 0xF1: return ["MESSAGE_CREATE_SENDMAIL_EHLO", "EHLO command failed"]; |
||
| 672 | case 0xF2: return ["MESSAGE_CREATE_SENDMAIL_STLS", "STARTTLS command failed"]; |
||
| 673 | case 0xF3: return ["MESSAGE_CREATE_SENDMAIL_SHAKE", "TLS handshake failed"]; |
||
| 674 | case 0xF4: return ["MESSAGE_CREATE_SENDMAIL_NOTLS", "TLS not available"]; |
||
| 675 | case 0xF5: return ["MESSAGE_CREATE_SENDMAIL_MAIL", "MAIL command failed"]; |
||
| 676 | case 0xF6: return ["MESSAGE_CREATE_SENDMAIL_RCPT", "RCPT command failed"]; |
||
| 677 | case 0xF7: return ["MESSAGE_CREATE_SENDMAIL_DATA", "DATA command failed"]; |
||
| 678 | case 0xF8: return ["MESSAGE_CREATE_SENDMAIL_BODY", "Sending body failed"]; |
||
| 679 | // case 0xF9: return ["", ""]; |
||
| 680 | |||
| 681 | // 0xFA-0xFF Message/Create Int |
||
| 682 | case 0xFA: return ["MESSAGE_CREATE_INT_TOOSHORT", "Message too short"]; |
||
| 683 | case 0xFB: return ["MESSAGE_CREATE_INT_TS_INVALID", "Invalid timestamp"]; |
||
| 684 | case 0xFC: return ["MESSAGE_CREATE_INT_SUBJECT_SIZE", "Subject too long or short"]; |
||
| 685 | case 0xFD: return ["MESSAGE_CREATE_INT_ADDR_NOTOWN", "Sender address not owned"]; |
||
| 686 | case 0xFE: return ["MESSAGE_CREATE_INT_TO_NOTACCEPT", "Receiver address does not accept messages"]; |
||
| 687 | case 0xFF: return ["MESSAGE_CREATE_INT_TO_SELF", "Sending to own account not allowed"]; |
||
| 688 | |||
| 689 | default: return ["???", "Unknown error"]; |
||
| 690 | } |
||
| 691 | } |
||
| 692 | |||
| 693 | // Interface |
||
| 694 | function clearMsgFlags() { |
||
| 695 | const parent = document.getElementById("readmsg_flags").children[0].innerHTML = ""; |
||
| 696 | } |
||
| 697 | |||
| 698 | function addMsgFlag(abbr, abbrTitle) { |
||
| 699 | const parent = document.getElementById("readmsg_flags").children[0]; |
||
| 700 | |||
| 701 | const el = document.createElement("abbr"); |
||
| 702 | el.title = abbrTitle; |
||
| 703 | el.textContent = abbr; |
||
| 704 | |||
| 705 | parent.appendChild(document.createTextNode(" ")); |
||
| 706 | parent.appendChild(el); |
||
| 707 | } |
||
| 708 | |||
| 709 | function errorDialog(err) { |
||
| 710 | if (typeof(err) !== "number" || err < 1) return; |
||
| 711 | |||
| 712 | let btnDisable = []; |
||
| 713 | const btn = document.querySelectorAll("nav > button"); |
||
| 714 | for (let i = 0; i < btn.length; i++) { |
||
| 715 | btnDisable.push(btn[i].disabled); |
||
| 716 | btn[i].disabled = true; |
||
| 717 | } |
||
| 718 | |||
| 719 | const errMsg = getErrorMessage(err); |
||
| 720 | |||
| 721 | const dlg = document.querySelector("dialog"); |
||
| 722 | dlg.children[0].style.height = getComputedStyle(document.querySelector("#main1 > div[class='mid']")).height; |
||
| 723 | dlg.querySelector("h1").textContent = "ERROR 0x" + err.toString(16).padStart(2, "0").toUpperCase(); |
||
| 724 | dlg.querySelector("p").textContent = (typeof(errMsg) === "string") ? errMsg : errMsg[1]; |
||
| 725 | dlg.show(); |
||
| 726 | |||
| 727 | document.querySelector("dialog > div").onclick = function() { |
||
| 728 | for (let i = 0; i < btn.length; i++) { |
||
| 729 | btn[i].disabled = btnDisable[i]; |
||
| 730 | dlg.close(); |
||
| 731 | } |
||
| 732 | }; |
||
| 733 | } |
||
| 734 | |||
| 735 | function addMsg(isInt, i) { |
||
| 736 | const row = document.getElementById("tbl_inbox").insertRow(-1); |
||
| 737 | row.setAttribute("data-msgid", isInt? ae.GetIntMsgIdHex(i) : ae.GetExtMsgIdHex(i)); |
||
| 738 | |||
| 739 | const ts = isInt? ae.GetIntMsgTime(i) : ae.GetExtMsgTime(i); |
||
| 740 | const el = document.createElement("time"); |
||
| 741 | el.dateTime = new Date(ts * 1000).toISOString(); |
||
| 742 | el.textContent = new Date((ts * 1000) + (new Date().getTimezoneOffset() * -60000)).toISOString().slice(0, 10); |
||
| 743 | |||
| 744 | const cellTime = row.insertCell(-1); |
||
| 745 | cellTime.appendChild(el); |
||
| 746 | |||
| 747 | const cellSubj = row.insertCell(-1); |
||
| 748 | cellSubj.textContent = isInt? ae.GetIntMsgTitle(i) : ae.GetExtMsgTitle(i); |
||
| 749 | |||
| 750 | if (isInt) { |
||
| 751 | const cellSnd = row.insertCell(-1); |
||
| 752 | cellSnd.textContent = ae.GetIntMsgFrom(i); |
||
| 753 | cellSnd.className = (ae.GetIntMsgFrom(i).length === 16) ? "mono" : ""; |
||
| 754 | } else { |
||
| 755 | const from1 = ae.GetExtMsgHdrFrom(i); |
||
| 756 | const from2 = from1.substring(from1.indexOf("@") + 1); |
||
| 757 | |||
| 758 | const cc = ae.GetExtMsgCountry(i); |
||
| 759 | const cellSnd1 = row.insertCell(-1); |
||
| 760 | cellSnd1.textContent = from1.substring(0, from1.indexOf("@")); |
||
| 761 | |||
| 762 | const flag = document.createElement("abbr"); |
||
| 763 | flag.textContent = getCountryFlag(cc); |
||
| 764 | flag.title = getCountryName(cc); |
||
| 765 | |||
| 766 | const fromText = document.createElement("span"); |
||
| 767 | fromText.textContent = " " + from2; |
||
| 768 | |||
| 769 | const cellSnd2 = row.insertCell(-1); |
||
| 770 | cellSnd2.appendChild(flag); |
||
| 771 | cellSnd2.appendChild(fromText); |
||
| 772 | } |
||
| 773 | |||
| 774 | row.onclick = function() { |
||
| 775 | displayMsg(isInt, i); |
||
| 776 | }; |
||
| 777 | } |
||
| 778 | |||
| 779 | function getRowsPerPage() { |
||
| 780 | const tbl = document.getElementById("tbl_inbox"); |
||
| 781 | tbl.innerHTML = ""; |
||
| 782 | const row = tbl.insertRow(-1); |
||
| 783 | const cell = row.insertCell(-1); |
||
| 784 | cell.textContent = "0"; |
||
| 785 | |||
| 786 | const rowsPerPage = Math.floor(getComputedStyle(document.getElementById("div_inbox")).height.replace("px", "") / getComputedStyle(document.querySelector("#tbl_inbox > tbody > tr:first-child")).height.replace("px", "")) - 1; // -1 allows space for 'load more' |
||
| 787 | tbl.innerHTML = ""; |
||
| 788 | return rowsPerPage; |
||
| 789 | } |
||
| 790 | |||
| 791 | function addMessages() { |
||
| 792 | const maxExt = ae.GetExtMsgCount(); |
||
| 793 | const maxInt = ae.GetIntMsgCount(); |
||
| 794 | |||
| 795 | if (maxExt + maxInt < 1) { |
||
| 796 | tabs[TAB_INBOX].max = 0; |
||
| 797 | return; |
||
| 798 | } |
||
| 799 | |||
| 800 | const rowsPerPage = getRowsPerPage(); |
||
| 801 | let skipMsgs = rowsPerPage * tabs[TAB_INBOX].cur; |
||
| 802 | |||
| 803 | tabs[TAB_INBOX].max = Math.floor((maxExt + maxInt - 1) / rowsPerPage); |
||
| 804 | |||
| 805 | let numExt = 0; |
||
| 806 | let numInt = 0; |
||
| 807 | let numAdd = 0; |
||
| 808 | |||
| 809 | while (numAdd < rowsPerPage) { |
||
| 810 | const tsInt = (numInt < maxInt) ? ae.GetIntMsgTime(numInt) : -1; |
||
| 811 | const tsExt = (numExt < maxExt) ? ae.GetExtMsgTime(numExt) : -1; |
||
| 812 | if (tsInt === -1 && tsExt === -1) break; |
||
| 813 | |||
| 814 | if (tsInt !== -1 && (tsExt === -1 || tsInt > tsExt)) { |
||
| 815 | if (skipMsgs > 0) skipMsgs--; else {addMsg(true, numInt); numAdd++;} |
||
| 816 | numInt++; |
||
| 817 | } else if (tsExt !== -1) { |
||
| 818 | if (skipMsgs > 0) skipMsgs--; else {addMsg(false, numExt); numAdd++;} |
||
| 819 | numExt++; |
||
| 820 | } |
||
| 821 | } |
||
| 822 | |||
| 823 | if (ae.GetReadyMsgBytes() < ae.GetTotalMsgBytes()) { |
||
| 824 | const inbox = document.getElementById("tbl_inbox"); |
||
| 825 | const row = inbox.insertRow(-1); |
||
| 826 | const cell = row.insertCell(-1); |
||
| 827 | cell.textContent = "Load more (" + Math.round((ae.GetTotalMsgBytes() - ae.GetReadyMsgBytes()) / 1024) + " KiB left)"; |
||
| 828 | |||
| 829 | row.onclick = function() { |
||
| 830 | this.onclick = ""; |
||
| 831 | |||
| 832 | ae.Message_Browse(false, false, function(errorBrowse) { |
||
| 833 | document.getElementById("tbl_inbox").style.opacity = 1; |
||
| 834 | |||
| 835 | if (errorBrowse === 0) { |
||
| 836 | addMessages(); |
||
| 837 | addUploads(); |
||
| 838 | addSent(); |
||
| 839 | if (tabs[tab].cur < tabs[tab].max) document.getElementById("btn_rght").disabled = false; |
||
| 840 | } // else TODO |
||
| 841 | }); |
||
| 842 | }; |
||
| 843 | } |
||
| 844 | } |
||
| 845 | |||
| 846 | function addUploads() { |
||
| 847 | const tbl = document.getElementById("tbd_uploads"); |
||
| 848 | tbl.innerHTML = ""; |
||
| 849 | |||
| 850 | for (let i = 0; i < ae.GetUplMsgCount(); i++) { |
||
| 851 | const row = tbl.insertRow(-1); |
||
| 852 | row.setAttribute("data-msgid", ae.GetUplMsgIdHex(i)); |
||
| 853 | |||
| 854 | let cell; |
||
| 855 | cell = row.insertCell(-1); cell.textContent = new Date(ae.GetUplMsgTime(i) * 1000).toISOString().slice(0, 10); |
||
| 856 | |||
| 857 | cell = row.insertCell(-1); cell.textContent = ae.GetUplMsgTitle(i); |
||
| 858 | cell.onclick = function() {displayFile(this.parentElement.rowIndex - 1);}; |
||
| 859 | |||
| 860 | cell = row.insertCell(-1); cell.textContent = (ae.GetUplMsgBytes(i) / 1024).toFixed(1); |
||
| 861 | |||
| 862 | cell = row.insertCell(-1); |
||
| 863 | if (ae.GetUplMsgIdHex(i)) { |
||
| 864 | const btn = document.createElement("button"); |
||
| 865 | btn.setAttribute("data-msgid", ae.GetUplMsgIdHex(i)); |
||
| 866 | btn.type = "button"; |
||
| 867 | btn.textContent = "X"; |
||
| 868 | |||
| 869 | btn.onclick = function() { |
||
| 870 | const tr = this.parentElement.parentElement; |
||
| 871 | ae.Message_Delete(this.getAttribute("data-msgid"), function(error) { |
||
| 872 | if (error === 0) tr.remove(); |
||
| 873 | else errorDialog(error); |
||
| 874 | }); |
||
| 875 | }; |
||
| 876 | |||
| 877 | cell.appendChild(btn); |
||
| 878 | } |
||
| 879 | } |
||
| 880 | } |
||
| 881 | |||
| 882 | function displayOutMsg(num) { |
||
| 883 | clearDisplay(); |
||
| 884 | document.querySelector("article").scroll(0, 0); |
||
| 885 | document.querySelector("article").setAttribute("data-msgid", ae.GetOutMsgIdHex(num)); |
||
| 886 | |||
| 887 | document.getElementById("btn_mdele").disabled = false; |
||
| 888 | document.getElementById("btn_msave").disabled = true; |
||
| 889 | document.getElementById("btn_reply").disabled = true; |
||
| 890 | |||
| 891 | document.querySelector("article").children[0].hidden = false; |
||
| 892 | document.querySelector("article").children[2].hidden = false; |
||
| 893 | |||
| 894 | document.querySelector("article").children[1].textContent = ae.GetOutMsgSubj(num); |
||
| 895 | document.querySelector("article").children[2].textContent = ae.GetOutMsgBody(num); |
||
| 896 | |||
| 897 | document.getElementById("readmsg_dkim").style.visibility = "hidden"; |
||
| 898 | document.getElementById("readmsg_hdrto").style.visibility = "visible"; |
||
| 899 | document.getElementById("readmsg_hdrfrom").style.visibility = "visible"; |
||
| 900 | document.getElementById("readmsg_envto").style.visibility = "visible"; |
||
| 901 | document.getElementById("readmsg_envfrom").style.visibility = "hidden"; |
||
| 902 | |||
| 903 | document.getElementById("readmsg_hdrfrom").textContent = ae.GetOutMsgFrom(num); |
||
| 904 | |||
| 905 | document.getElementById("readmsg_envto").textContent = ae.GetOutMsgMxDom(num); |
||
| 906 | document.getElementById("readmsg_hdrto").textContent = ae.GetOutMsgTo(num); |
||
| 907 | |||
| 908 | const ts = ae.GetOutMsgTime(num); |
||
| 909 | const tzOs = new Date().getTimezoneOffset(); |
||
| 910 | document.getElementById("readmsg_date").children[1].textContent = new Date((ts * 1000) + (tzOs * -60000)).toISOString().slice(0, 19).replace("T", " "); |
||
| 911 | |||
| 912 | const isInt = ae.GetOutMsgIsInt(num); |
||
| 913 | document.getElementById("readmsg_ip").style.visibility = isInt? "hidden" : "visible"; |
||
| 914 | document.getElementById("readmsg_rdns").style.visibility = /*isInt?*/ "hidden" /*: "visible"*/; // TODO |
||
| 915 | document.getElementById("readmsg_tls").style.visibility = /*isInt?*/ "hidden" /*: "visible"*/; // TODO |
||
| 916 | document.getElementById("readmsg_cert").style.visibility = /*isInt?*/ "hidden" /*: "visible"*/; // TODO |
||
| 917 | document.getElementById("readmsg_greet").style.visibility = isInt? "hidden" : "visible"; |
||
| 918 | |||
| 919 | if (!isInt) { |
||
| 920 | // const cc = ae.GetExtMsgCountry(num); |
||
| 921 | |||
| 922 | document.getElementById("readmsg_ip").children[1].textContent = ae.GetOutMsgIp(num); |
||
| 923 | // document.getElementById("readmsg_country").textContent = getCountryFlag(cc) + " " + getCountryName(cc); |
||
| 924 | // document.getElementById("readmsg_tls").children[0].textContent = ae.GetOutMsgTLS(num); |
||
| 925 | document.getElementById("readmsg_greet").children[0].textContent = ae.GetOutMsgGreet(num); |
||
| 926 | } |
||
| 927 | |||
| 928 | clearMsgFlags(); |
||
| 929 | if (!ae.GetOutMsgFlagVPad(num)) addMsgFlag("PAD", "Invalid padding"); |
||
| 930 | if (!ae.GetOutMsgFlagVSig(num)) addMsgFlag("SIG", "Invalid signature"); |
||
| 931 | if ( ae.GetOutMsgFlagE2ee(num)) addMsgFlag("E2EE", "End-to-end encrypted"); |
||
| 932 | } |
||
| 933 | |||
| 934 | function addSent() { |
||
| 935 | const tbl = document.getElementById("tbl_drbox"); |
||
| 936 | tbl.innerHTML = ""; |
||
| 937 | |||
| 938 | for (let i = 0; i < ae.GetOutMsgCount(); i++) { |
||
| 939 | const row = tbl.insertRow(-1); |
||
| 940 | row.setAttribute("data-msgid", ae.GetOutMsgIdHex(i)); |
||
| 941 | |||
| 942 | let cell; |
||
| 943 | cell = row.insertCell(-1); cell.textContent = new Date(ae.GetOutMsgTime(i) * 1000).toISOString().slice(0, 10); |
||
| 944 | cell = row.insertCell(-1); cell.textContent = ae.GetOutMsgSubj(i); |
||
| 945 | row.onclick = function() {displayOutMsg(i);}; |
||
| 946 | } |
||
| 947 | } |
||
| 948 | |||
| 949 | function updateAddressCounts() { |
||
| 950 | document.querySelector("#tbd_accs > tr > td:nth-child(3)").textContent = ae.GetAddressCountNormal(); |
||
| 951 | document.querySelector("#tbd_accs > tr > td:nth-child(4)").textContent = ae.GetAddressCountShield(); |
||
| 952 | |||
| 953 | document.getElementById("limit_normal").textContent = (ae.GetAddressCountNormal() + "/" + ae.GetLimitNormalA(ae.GetUserLevel())).padStart(ae.GetLimitNormalA(ae.GetUserLevel()) > 9 ? 5 : 1); |
||
| 954 | document.getElementById("limit_shield").textContent = (ae.GetAddressCountShield() + "/" + ae.GetLimitShieldA(ae.GetUserLevel())).padStart(ae.GetLimitShieldA(ae.GetUserLevel()) > 9 ? 5 : 1); |
||
| 955 | document.getElementById("limit_total").textContent = ((ae.GetAddressCountNormal() + ae.GetAddressCountShield()) + "/" + ae.GetAddrPerUser()).padStart(5); |
||
| 956 | |||
| 957 | const limitReached = (ae.GetAddressCountNormal() + ae.GetAddressCountShield() >= 31); |
||
| 958 | document.getElementById("btn_address_create_normal").disabled = (limitReached || ae.GetAddressCountNormal() >= ae.GetLimitNormalA(ae.GetUserLevel())); |
||
| 959 | document.getElementById("btn_address_create_shield").disabled = (limitReached || ae.GetAddressCountShield() >= ae.GetLimitShieldA(ae.GetUserLevel())); |
||
| 960 | } |
||
| 961 | |||
| 962 | function adjustLevel(pubkey, level, c) { |
||
| 963 | const fs = document.getElementById("tbl_accs"); |
||
| 964 | fs.disabled = true; |
||
| 965 | |||
| 966 | ae.Account_Update(pubkey, level, function(error) { |
||
| 967 | fs.disabled = false; |
||
| 968 | |||
| 969 | if (error === 0) { |
||
| 970 | c[4].textContent = level; |
||
| 971 | c[5].children[0].disabled = (level === 3); |
||
| 972 | c[6].children[0].disabled = (level === 0); |
||
| 973 | } else errorDialog(error); |
||
| 974 | }); |
||
| 975 | } |
||
| 976 | |||
| 977 | function addAccountToTable(i) { |
||
| 978 | const tblAccs = document.getElementById("tbd_accs"); |
||
| 979 | const row = tblAccs.insertRow(-1); |
||
| 980 | let cell; |
||
| 981 | cell = row.insertCell(-1); cell.textContent = ae.Admin_GetUserPkHex(i); |
||
| 982 | cell = row.insertCell(-1); cell.textContent = ae.Admin_GetUserSpace(i); |
||
| 983 | cell = row.insertCell(-1); cell.textContent = ae.Admin_GetUserNAddr(i); |
||
| 984 | cell = row.insertCell(-1); cell.textContent = ae.Admin_GetUserSAddr(i); |
||
| 985 | cell = row.insertCell(-1); cell.textContent = ae.Admin_GetUserLevel(i); |
||
| 986 | |||
| 987 | cell = row.insertCell(-1); |
||
| 988 | let btn = document.createElement("button"); |
||
| 989 | btn.type = "button"; |
||
| 990 | btn.textContent = "+"; |
||
| 991 | btn.disabled = (ae.Admin_GetUserLevel(i) === 3); |
||
| 992 | btn.onclick = function() {const c = this.parentElement.parentElement.cells; adjustLevel(c[0].textContent, parseInt(c[4].textContent, 10) + 1, c);}; |
||
| 993 | cell.appendChild(btn); |
||
| 994 | |||
| 995 | cell = row.insertCell(-1); |
||
| 996 | btn = document.createElement("button"); |
||
| 997 | btn.type = "button"; |
||
| 998 | btn.textContent = "−"; |
||
| 999 | btn.disabled = (ae.Admin_GetUserLevel(i) === 0); |
||
| 1000 | btn.onclick = function() {const c = this.parentElement.parentElement.cells; adjustLevel(c[0].textContent, parseInt(c[4].textContent, 10) - 1, c);}; |
||
| 1001 | cell.appendChild(btn); |
||
| 1002 | |||
| 1003 | cell = row.insertCell(-1); |
||
| 1004 | btn = document.createElement("button"); |
||
| 1005 | btn.type = "button"; |
||
| 1006 | btn.textContent = "X"; |
||
| 1007 | btn.onclick = function() { |
||
| 1008 | const tr = this.parentElement.parentElement; |
||
| 1009 | ae.Account_Delete(tr.cells[0].textContent, function(error) { |
||
| 1010 | if (error === 0) tr.remove(); else errorDialog(error); |
||
| 1011 | }); |
||
| 1012 | }; |
||
| 1013 | cell.appendChild(btn); |
||
| 1014 | } |
||
| 1015 | |||
| 1016 | function reloadAccount() { |
||
| 1017 | // Limits |
||
| 1018 | const tblLimits = document.getElementById("tbl_limits"); |
||
| 1019 | if (ae.IsUserAdmin()) { |
||
| 1020 | for (let i = 0; i < 4; i++) { |
||
| 1021 | tblLimits.rows[i].cells[1].children[0].disabled = false; |
||
| 1022 | tblLimits.rows[i].cells[2].children[0].disabled = false; |
||
| 1023 | tblLimits.rows[i].cells[3].children[0].disabled = false; |
||
| 1024 | |||
| 1025 | tblLimits.rows[i].cells[1].children[0].value = ae.GetLimitStorage(i) + 1; |
||
| 1026 | tblLimits.rows[i].cells[2].children[0].value = ae.GetLimitNormalA(i); |
||
| 1027 | tblLimits.rows[i].cells[3].children[0].value = ae.GetLimitShieldA(i); |
||
| 1028 | } |
||
| 1029 | } else { |
||
| 1030 | const lvl = ae.GetUserLevel(); |
||
| 1031 | tblLimits.rows[lvl].cells[1].children[0].value = ae.GetLimitStorage(lvl) + 1; |
||
| 1032 | tblLimits.rows[lvl].cells[2].children[0].value = ae.GetLimitNormalA(lvl); |
||
| 1033 | tblLimits.rows[lvl].cells[3].children[0].value = ae.GetLimitShieldA(lvl); |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | // Accounts |
||
| 1037 | const tblAccs = document.getElementById("tbd_accs"); |
||
| 1038 | |||
| 1039 | // All: Our account |
||
| 1040 | const row = tblAccs.insertRow(-1); |
||
| 1041 | let cell; |
||
| 1042 | cell = row.insertCell(-1); cell.textContent = ae.GetUserPkHex(); |
||
| 1043 | cell = row.insertCell(-1); cell.textContent = Math.round(ae.GetTotalMsgBytes() / 1048576); // MiB |
||
| 1044 | cell = row.insertCell(-1); cell.textContent = ae.GetAddressCountNormal(); |
||
| 1045 | cell = row.insertCell(-1); cell.textContent = ae.GetAddressCountShield(); |
||
| 1046 | cell = row.insertCell(-1); cell.textContent = ae.GetUserLevel(); |
||
| 1047 | |||
| 1048 | cell = row.insertCell(-1); |
||
| 1049 | let btn = document.createElement("button"); |
||
| 1050 | btn.type = "button"; |
||
| 1051 | btn.textContent = "+"; |
||
| 1052 | btn.disabled = true; |
||
| 1053 | cell.appendChild(btn); |
||
| 1054 | |||
| 1055 | cell = row.insertCell(-1); |
||
| 1056 | btn = document.createElement("button"); |
||
| 1057 | btn.type = "button"; |
||
| 1058 | btn.textContent = "−"; |
||
| 1059 | btn.disabled = true; |
||
| 1060 | btn.id = "btn_lowme"; |
||
| 1061 | btn.onclick = function() { |
||
| 1062 | const newLevel = parseInt(row.cells[4].textContent, 10) - 1; |
||
| 1063 | ae.Account_Update(ae.GetUserPkHex(), newLevel, function(error) { |
||
| 1064 | if (error === 0) { |
||
| 1065 | row.cells[4].textContent = newLevel; |
||
| 1066 | if (newLevel === 0) { |
||
| 1067 | document.getElementById("btn_lowme").disabled = true; |
||
| 1068 | document.getElementById("chk_lowme").disabled = true; |
||
| 1069 | } |
||
| 1070 | } else errorDialog(error); |
||
| 1071 | }); |
||
| 1072 | }; |
||
| 1073 | cell.appendChild(btn); |
||
| 1074 | |||
| 1075 | cell = row.insertCell(-1); |
||
| 1076 | btn = document.createElement("button"); |
||
| 1077 | btn.type = "button"; |
||
| 1078 | btn.textContent = "X"; |
||
| 1079 | btn.disabled = true; |
||
| 1080 | btn.id = "btn_delme"; |
||
| 1081 | btn.onclick = function() { |
||
| 1082 | ae.Account_Delete(ae.GetUserPkHex(), function(error) { |
||
| 1083 | if (error === 0) { |
||
| 1084 | row.remove(); |
||
| 1085 | document.getElementById("chk_delme").disabled = true; |
||
| 1086 | } else errorDialog(error); |
||
| 1087 | }); |
||
| 1088 | }; |
||
| 1089 | cell.appendChild(btn); |
||
| 1090 | |||
| 1091 | document.getElementById("txt_reg").disabled = !ae.IsUserAdmin(); |
||
| 1092 | document.getElementById("btn_reg").disabled = !ae.IsUserAdmin(); |
||
| 1093 | document.getElementById("chk_lowme").disabled = (ae.GetUserLevel() === 0); |
||
| 1094 | |||
| 1095 | // Contacts |
||
| 1096 | for (let i = 0; i < ae.GetContactCount(); i++) { |
||
| 1097 | addContact( |
||
| 1098 | ae.GetContactMail(i), |
||
| 1099 | ae.GetContactName(i), |
||
| 1100 | ae.GetContactNote(i) |
||
| 1101 | ); |
||
| 1102 | } |
||
| 1103 | |||
| 1104 | refreshContactList(); |
||
| 1105 | |||
| 1106 | // Addresses |
||
| 1107 | for (let i = 0; i < ae.GetAddressCount(); i++) { |
||
| 1108 | addAddress(i); |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | updateAddressCounts(); |
||
| 1112 | addMessages(); |
||
| 1113 | addUploads(); |
||
| 1114 | addSent(); |
||
| 1115 | |||
| 1116 | document.getElementById("btn_rght").disabled = (tabs[tab].cur === tabs[tab].max); |
||
| 1117 | } |
||
| 1118 | |||
| 1119 | function deleteAddress(addr) { |
||
| 1120 | let btns = document.querySelectorAll("#tbl_addrs button"); |
||
| 1121 | for (let i = 0; i < btns.length; i++) btns[i].disabled = true; |
||
| 1122 | |||
| 1123 | let addressToDelete = -1; |
||
| 1124 | |||
| 1125 | for (let i = 0; i < ae.GetAddressCount(); i++) { |
||
| 1126 | if (addr === ae.GetAddress(i)) { |
||
| 1127 | addressToDelete = i; |
||
| 1128 | break; |
||
| 1129 | } |
||
| 1130 | } |
||
| 1131 | |||
| 1132 | if (addressToDelete === -1) return; |
||
| 1133 | |||
| 1134 | ae.Address_Delete(addressToDelete, function(error1) { |
||
| 1135 | if (error1 === 0) { |
||
| 1136 | document.getElementById("tbl_addrs").deleteRow(addressToDelete); |
||
| 1137 | document.getElementById("write_from").remove(addressToDelete); |
||
| 1138 | updateAddressCounts(); |
||
| 1139 | |||
| 1140 | const limitReached = (ae.GetAddressCountNormal() + ae.GetAddressCountShield() >= 31); |
||
| 1141 | document.getElementById("btn_address_create_normal").disabled = (limitReached || ae.GetAddressCountNormal() > ae.GetLimitNormalA(ae.GetUserLevel())); |
||
| 1142 | document.getElementById("btn_address_create_shield").disabled = (limitReached || ae.GetAddressCountShield() > ae.GetLimitShieldA(ae.GetUserLevel())); |
||
| 1143 | |||
| 1144 | ae.Private_Update(function(error2) { |
||
| 1145 | btns = document.querySelectorAll("#tbl_addrs button"); |
||
| 1146 | for (let i = 0; i < btns.length; i++) btns[i].disabled = false; |
||
| 1147 | if (error2) errorDialog(error2); |
||
| 1148 | }); |
||
| 1149 | } else { |
||
| 1150 | btns = document.querySelectorAll("#tbl_addrs button"); |
||
| 1151 | for (let i = 0; i < btns.length; i++) btns[i].disabled = false; |
||
| 1152 | errorDialog(error1); |
||
| 1153 | } |
||
| 1154 | }); |
||
| 1155 | } |
||
| 1156 | |||
| 1157 | View Code Duplication | function shieldMix(addr) { |
|
| 1158 | let newAddr = ""; |
||
| 1159 | |||
| 1160 | for (let i = 0; i < 16; i++) { |
||
| 1161 | switch (addr.charAt(i)) { |
||
| 1162 | case '1': |
||
| 1163 | newAddr += "1iIlL".charAt(Math.floor(Math.random() * 5)); |
||
| 1164 | break; |
||
| 1165 | case '0': |
||
| 1166 | newAddr += "0oO".charAt(Math.floor(Math.random() * 3)); |
||
| 1167 | break; |
||
| 1168 | case 'w': |
||
| 1169 | newAddr += "VvWw".charAt(Math.floor(Math.random() * 4)); |
||
| 1170 | break; |
||
| 1171 | default: |
||
| 1172 | newAddr += (Math.random() > 0.5) ? addr.charAt(i) : addr.charAt(i).toUpperCase(); |
||
| 1173 | } |
||
| 1174 | } |
||
| 1175 | |||
| 1176 | return newAddr; |
||
| 1177 | } |
||
| 1178 | |||
| 1179 | function addAddress(num) { |
||
| 1180 | const addrTable = document.getElementById("tbl_addrs"); |
||
| 1181 | const row = addrTable.insertRow(-1); |
||
| 1182 | const cellAddr = row.insertCell(-1); |
||
| 1183 | const cellChk1 = row.insertCell(-1); |
||
| 1184 | const cellChk2 = row.insertCell(-1); |
||
| 1185 | const cellBtnD = row.insertCell(-1); |
||
| 1186 | |||
| 1187 | cellAddr.textContent = ae.GetAddress(num); |
||
| 1188 | cellAddr.onclick = function() { |
||
| 1189 | if (cellAddr.textContent.length === 16) |
||
| 1190 | navigator.clipboard.writeText(shieldMix(cellAddr.textContent) + "@" + ae.GetDomainEml()); |
||
| 1191 | else |
||
| 1192 | navigator.clipboard.writeText(cellAddr.textContent + "@" + ae.GetDomainEml()); |
||
| 1193 | }; |
||
| 1194 | |||
| 1195 | cellChk1.innerHTML = ae.GetAddressAccExt(num) ? "<input type=\"checkbox\" checked=\"checked\">" : "<input type=\"checkbox\">"; |
||
| 1196 | cellChk2.innerHTML = ae.GetAddressAccInt(num) ? "<input type=\"checkbox\" checked=\"checked\">" : "<input type=\"checkbox\">"; |
||
| 1197 | |||
| 1198 | cellBtnD.innerHTML = "<button type=\"button\">X</button>"; |
||
| 1199 | cellBtnD.onclick = function() {deleteAddress(cellAddr.textContent);}; |
||
| 1200 | |||
| 1201 | const opt = document.createElement("option"); |
||
| 1202 | opt.value = cellAddr.textContent; |
||
| 1203 | opt.textContent = cellAddr.textContent + "@" + ae.GetDomainEml(); |
||
| 1204 | document.getElementById("write_from").appendChild(opt); |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | document.getElementById("btn_dele").onclick = function() { |
||
| 1208 | this.blur(); |
||
| 1209 | |||
| 1210 | if (tab === TAB_WRITE) { |
||
| 1211 | tabs[tab].cur = 0; |
||
| 1212 | updateTab(); |
||
| 1213 | |||
| 1214 | document.querySelector("#write2_pkey > input").value = ""; |
||
| 1215 | |||
| 1216 | document.getElementById("write_recv").value = ""; |
||
| 1217 | document.getElementById("write_subj").value = ""; |
||
| 1218 | document.getElementById("write_body").value = ""; |
||
| 1219 | |||
| 1220 | document.getElementById("write_recv").readOnly = false; |
||
| 1221 | document.getElementById("write_subj").readOnly = false; |
||
| 1222 | document.getElementById("write_subj").setAttribute("data-replyid", ""); |
||
| 1223 | |||
| 1224 | document.getElementById("write_recv").focus(); |
||
| 1225 | } |
||
| 1226 | }; |
||
| 1227 | |||
| 1228 | document.getElementById("btn_updt").onclick = function() { |
||
| 1229 | const btn = this; |
||
| 1230 | btn.disabled = true; |
||
| 1231 | btn.blur(); |
||
| 1232 | |||
| 1233 | if (tab === TAB_INBOX) { |
||
| 1234 | document.getElementById("tbl_inbox").style.opacity = 0.5; |
||
| 1235 | |||
| 1236 | ae.Message_Browse(true, false, function(error) { |
||
| 1237 | if (error === 0) { |
||
| 1238 | addMessages(); |
||
| 1239 | addUploads(); |
||
| 1240 | } else { |
||
| 1241 | errorDialog(error); |
||
| 1242 | } |
||
| 1243 | |||
| 1244 | document.getElementById("tbl_inbox").style.opacity = 1; |
||
| 1245 | btn.disabled = false; |
||
| 1246 | }); |
||
| 1247 | } |
||
| 1248 | }; |
||
| 1249 | |||
| 1250 | document.getElementById("btn_mdele").onclick = function() { |
||
| 1251 | const btn = this; |
||
| 1252 | btn.blur(); |
||
| 1253 | btn.disabled = true; |
||
| 1254 | |||
| 1255 | const delId = document.querySelector("article").getAttribute("data-msgid"); |
||
| 1256 | if (!delId) return; |
||
| 1257 | |||
| 1258 | ae.Message_Delete(delId, function(error) { |
||
| 1259 | if (error === 0) { |
||
| 1260 | ["tbl_inbox", "tbl_drbox", "tbd_uploads"].forEach(function(tbl_name) { |
||
| 1261 | const tbl = document.getElementById(tbl_name); |
||
| 1262 | for (let i = 0; i < tbl.rows.length; i++) {if (tbl.rows[i].getAttribute("data-msgid") === delId) tbl.deleteRow(i);} |
||
| 1263 | }); |
||
| 1264 | |||
| 1265 | addMessages(); |
||
| 1266 | addUploads(); |
||
| 1267 | addSent(); |
||
| 1268 | } else btn.disabled = false; // TODO display error |
||
| 1269 | }); |
||
| 1270 | }; |
||
| 1271 | |||
| 1272 | function refreshContactList() { |
||
| 1273 | const lst = document.getElementById("contact_emails"); |
||
| 1274 | lst.innerHTML = ""; |
||
| 1275 | |||
| 1276 | for (let i = 0; i < ae.GetContactCount(); i++) { |
||
| 1277 | const el = document.createElement("option"); |
||
| 1278 | el.value = ae.GetContactMail(i); |
||
| 1279 | lst.appendChild(el); |
||
| 1280 | } |
||
| 1281 | |||
| 1282 | if (ae.IsUserAdmin()) { |
||
| 1283 | const el = document.createElement("option"); |
||
| 1284 | el.value = "public"; |
||
| 1285 | lst.appendChild(el); |
||
| 1286 | } |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | function addContact(mail, name, note) { |
||
| 1290 | const tbl = document.getElementById("tbl_ctact"); |
||
| 1291 | const row = tbl.insertRow(-1); |
||
| 1292 | const cellMail = row.insertCell(-1); |
||
| 1293 | const cellName = row.insertCell(-1); |
||
| 1294 | const cellNote = row.insertCell(-1); |
||
| 1295 | const cellBtnD = row.insertCell(-1); |
||
| 1296 | |||
| 1297 | cellMail.autocapitalize = "off"; |
||
| 1298 | cellMail.spellcheck = false; |
||
| 1299 | cellMail.inputMode = "email"; |
||
| 1300 | |||
| 1301 | cellName.autocapitalize = "words"; |
||
| 1302 | cellName.spellcheck = false; |
||
| 1303 | |||
| 1304 | cellNote.autocapitalize = "off"; |
||
| 1305 | cellNote.spellcheck = false; |
||
| 1306 | |||
| 1307 | cellMail.textContent = mail; |
||
| 1308 | cellName.textContent = name; |
||
| 1309 | cellNote.textContent = note; |
||
| 1310 | cellBtnD.innerHTML = "<button type=\"button\">X</button>"; |
||
| 1311 | |||
| 1312 | cellMail.contentEditable = true; |
||
| 1313 | cellName.contentEditable = true; |
||
| 1314 | cellNote.contentEditable = true; |
||
| 1315 | |||
| 1316 | cellBtnD.onclick = function() {row.remove();}; |
||
| 1317 | } |
||
| 1318 | |||
| 1319 | document.getElementById("btn_newcontact").onclick = function() { |
||
| 1320 | addContact("", "", ""); |
||
| 1321 | }; |
||
| 1322 | |||
| 1323 | document.getElementById("btn_savecontacts").onclick = function() { |
||
| 1324 | while (ae.GetContactCount() > 0) { |
||
| 1325 | ae.DeleteContact(0); |
||
| 1326 | } |
||
| 1327 | |||
| 1328 | for (const row of document.getElementById("tbl_ctact").rows) { |
||
| 1329 | ae.AddContact(row.cells[0].textContent, row.cells[1].textContent, row.cells[2].textContent); |
||
| 1330 | } |
||
| 1331 | |||
| 1332 | refreshContactList(); |
||
| 1333 | |||
| 1334 | const btn = this; |
||
| 1335 | btn.disabled = true; |
||
| 1336 | |||
| 1337 | ae.Private_Update(function(error) { |
||
| 1338 | btn.disabled = false; |
||
| 1339 | if (error) errorDialog(error); |
||
| 1340 | }); |
||
| 1341 | }; |
||
| 1342 | |||
| 1343 | function writeVerify() { |
||
| 1344 | if ( |
||
| 1345 | !document.getElementById("write_recv").reportValidity() |
||
| 1346 | || !document.getElementById("write_subj").reportValidity() |
||
| 1347 | || !document.getElementById("write_body").reportValidity() |
||
| 1348 | ) {tabs[TAB_WRITE].cur = 0; return;} |
||
| 1349 | |||
| 1350 | document.getElementById("div_write_1").hidden = true; |
||
| 1351 | document.getElementById("div_write_2").hidden = false; |
||
| 1352 | |||
| 1353 | document.getElementById("write2_recv").textContent = document.getElementById("write_recv").value; |
||
| 1354 | document.getElementById("write2_subj").textContent = document.getElementById("write_subj").value; |
||
| 1355 | document.getElementById("write2_rply").textContent = document.getElementById("write_subj").getAttribute("data-replyid"); |
||
| 1356 | document.getElementById("write2_body").textContent = document.getElementById("write_body").value; |
||
| 1357 | |||
| 1358 | if (document.getElementById("write_recv").value.indexOf("@") >= 0) { |
||
| 1359 | document.getElementById("write2_from").textContent = document.getElementById("write_from").value + "@" + ae.GetDomainEml(); |
||
| 1360 | document.getElementById("write2_pkey").hidden = true; |
||
| 1361 | } else { |
||
| 1362 | document.getElementById("write2_from").textContent = document.getElementById("write_from").value; |
||
| 1363 | document.getElementById("write2_pkey").hidden = (document.getElementById("write_recv").value === "public"); |
||
| 1364 | } |
||
| 1365 | |||
| 1366 | document.querySelector("#write2_send > button").disabled = false; |
||
| 1367 | document.getElementById("write2_btntxt").textContent = (document.getElementById("write_recv").value === "public") ? "Make" : "Send to"; |
||
| 1368 | } |
||
| 1369 | |||
| 1370 | function updateTab() { |
||
| 1371 | switch (tab) { |
||
| 1372 | case TAB_INBOX: |
||
| 1373 | addMessages(); |
||
| 1374 | break; |
||
| 1375 | |||
| 1376 | case TAB_DRBOX: |
||
| 1377 | addSent(); |
||
| 1378 | break; |
||
| 1379 | |||
| 1380 | case TAB_WRITE: |
||
| 1381 | if (tabs[tab].cur === 0) { |
||
| 1382 | document.getElementById("div_write_1").hidden = false; |
||
| 1383 | document.getElementById("div_write_2").hidden = true; |
||
| 1384 | document.getElementById("write_body").focus(); |
||
| 1385 | } else { |
||
| 1386 | writeVerify(); |
||
| 1387 | } |
||
| 1388 | break; |
||
| 1389 | |||
| 1390 | case TAB_NOTES: |
||
| 1391 | for (let i = 0; i <= tabs[tab].max; i++) { |
||
| 1392 | document.getElementById("div_notes").children[i].hidden = (i !== tabs[tab].cur); |
||
| 1393 | } |
||
| 1394 | break; |
||
| 1395 | |||
| 1396 | case TAB_TOOLS: |
||
| 1397 | for (let i = 0; i <= tabs[tab].max; i++) { |
||
| 1398 | document.getElementById("div_tools").children[i].hidden = (i !== tabs[tab].cur); |
||
| 1399 | } |
||
| 1400 | break; |
||
| 1401 | } |
||
| 1402 | |||
| 1403 | document.getElementById("btn_left").disabled = (tabs[tab].cur === 0); |
||
| 1404 | document.getElementById("btn_rght").disabled = (tabs[tab].cur === tabs[tab].max); |
||
| 1405 | } |
||
| 1406 | |||
| 1407 | document.getElementById("btn_left").onclick = function() { |
||
| 1408 | tabs[tab].cur--; |
||
| 1409 | if (tabs[tab].cur === 0) this.disabled = true; |
||
| 1410 | if (tabs[tab].cur < tabs[tab].max) document.getElementById("btn_rght").disabled = false; |
||
| 1411 | updateTab(); |
||
| 1412 | this.blur(); |
||
| 1413 | }; |
||
| 1414 | |||
| 1415 | document.getElementById("btn_rght").onclick = function() { |
||
| 1416 | tabs[tab].cur++; |
||
| 1417 | if (tabs[tab].cur === tabs[tab].max) this.disabled = true; |
||
| 1418 | document.getElementById("btn_left").disabled = false; |
||
| 1419 | updateTab(); |
||
| 1420 | this.blur(); |
||
| 1421 | }; |
||
| 1422 | |||
| 1423 | const buttons = document.querySelectorAll("#main1 > .top > button"); |
||
| 1424 | for (let i = 0; i < buttons.length; i++) { |
||
| 1425 | buttons[i].onclick = function() { |
||
| 1426 | tab = i; |
||
| 1427 | |||
| 1428 | for (let j = 0; j < buttons.length; j++) { |
||
| 1429 | document.querySelectorAll("#main1 > .mid > div")[j].hidden = (tab !== j); |
||
| 1430 | buttons[j].disabled = (tab === j); |
||
| 1431 | } |
||
| 1432 | |||
| 1433 | document.getElementById("btn_left").disabled = (tabs[tab].cur === 0); |
||
| 1434 | document.getElementById("btn_rght").disabled = (tabs[tab].cur === tabs[tab].max); |
||
| 1435 | document.getElementById("btn_dele").disabled = !tabs[tab].btnDele; |
||
| 1436 | document.getElementById("btn_updt").disabled = !tabs[tab].btnUpdt; |
||
| 1437 | |||
| 1438 | updateTab(); |
||
| 1439 | }; |
||
| 1440 | } |
||
| 1441 | |||
| 1442 | function addressCreate(addr) { |
||
| 1443 | document.getElementById("btn_address_create_normal").disabled = true; |
||
| 1444 | document.getElementById("btn_address_create_shield").disabled = true; |
||
| 1445 | |||
| 1446 | ae.Address_Create(addr, function(error1) { |
||
| 1447 | if (error1 === 0) { |
||
| 1448 | ae.Private_Update(function(error2) { |
||
| 1449 | updateAddressCounts(); |
||
| 1450 | |||
| 1451 | if (error2 === 0) { |
||
| 1452 | addAddress(ae.GetAddressCount() - 1); |
||
| 1453 | if (addr !== "SHIELD") { |
||
| 1454 | document.getElementById("txt_address_create_normal").value = ""; |
||
| 1455 | document.getElementById("txt_address_create_normal").focus(); |
||
| 1456 | } |
||
| 1457 | } else errorDialog(error2); |
||
| 1458 | }); |
||
| 1459 | } else { |
||
| 1460 | errorDialog(error1); |
||
| 1461 | updateAddressCounts(); |
||
| 1462 | } |
||
| 1463 | }); |
||
| 1464 | } |
||
| 1465 | |||
| 1466 | document.getElementById("btn_address_create_normal").onclick = function() { |
||
| 1467 | if (ae.GetAddressCountNormal() >= ae.GetLimitNormalA(ae.GetUserLevel()) || ae.GetAddressCountNormal() + ae.GetAddressCountShield() >= 31) return; |
||
| 1468 | |||
| 1469 | const txtNewAddr = document.getElementById("txt_address_create_normal"); |
||
| 1470 | if (!txtNewAddr.reportValidity()) return; |
||
| 1471 | |||
| 1472 | addressCreate(txtNewAddr.value); |
||
| 1473 | }; |
||
| 1474 | |||
| 1475 | document.getElementById("btn_address_create_shield").onclick = function() { |
||
| 1476 | if (ae.GetAddressCountShield() >= ae.GetLimitShieldA(ae.GetUserLevel()) || ae.GetAddressCountNormal() + ae.GetAddressCountShield() >= 31) return; |
||
| 1477 | |||
| 1478 | addressCreate("SHIELD"); |
||
| 1479 | }; |
||
| 1480 | |||
| 1481 | document.getElementById("btn_address_update").onclick = function() { |
||
| 1482 | const btn = this; |
||
| 1483 | btn.disabled = true; |
||
| 1484 | |||
| 1485 | const rows = document.getElementById("tbl_addrs").rows; |
||
| 1486 | |||
| 1487 | for (let i = 0; i < rows.length; i++) { |
||
| 1488 | ae.SetAddressAccExt(i, rows[i].getElementsByTagName("input")[0].checked); |
||
| 1489 | ae.SetAddressAccInt(i, rows[i].getElementsByTagName("input")[1].checked); |
||
| 1490 | } |
||
| 1491 | |||
| 1492 | ae.Address_Update(function(error) { |
||
| 1493 | btn.disabled = false; |
||
| 1494 | if (error) errorDialog(error); |
||
| 1495 | }); |
||
| 1496 | }; |
||
| 1497 | |||
| 1498 | |||
| 1499 | document.getElementById("txt_reg").onkeyup = function(event) { |
||
| 1500 | if (event.key === "Enter") { |
||
| 1501 | event.preventDefault(); |
||
| 1502 | document.getElementById("btn_reg").click(); |
||
| 1503 | } |
||
| 1504 | }; |
||
| 1505 | |||
| 1506 | document.getElementById("btn_reg").onclick = function() { |
||
| 1507 | const btn = document.getElementById("btn_reg"); |
||
| 1508 | const txt = document.getElementById("txt_reg"); |
||
| 1509 | if (!txt.reportValidity()) return; |
||
| 1510 | btn.disabled = true; |
||
| 1511 | |||
| 1512 | ae.Account_Create(txt.value, function(error) { |
||
| 1513 | if (error === 0) { |
||
| 1514 | addAccountToTable(ae.Admin_GetUserCount() - 1); |
||
| 1515 | txt.value = ""; |
||
| 1516 | } else errorDialog(error); |
||
| 1517 | |||
| 1518 | btn.disabled = false; |
||
| 1519 | }); |
||
| 1520 | }; |
||
| 1521 | |||
| 1522 | document.getElementById("chk_delme").onclick = function() {document.getElementById("btn_delme").disabled = !this.checked;}; |
||
| 1523 | document.getElementById("chk_lowme").onclick = function() {document.getElementById("btn_lowme").disabled = !this.checked;}; |
||
| 1524 | |||
| 1525 | document.getElementById("btn_notepad_saveupl").onclick = function() { |
||
| 1526 | const np = document.getElementById("txt_notepad"); |
||
| 1527 | np.disabled = true; |
||
| 1528 | |||
| 1529 | let fname = prompt("Save as...", "Untitled"); |
||
| 1530 | if (!fname.endsWith(".txt")) fname += ".txt"; |
||
| 1531 | |||
| 1532 | ae.Message_Upload(fname, np.value, function(error) { |
||
| 1533 | if (error === 0) { |
||
| 1534 | np.value = ""; |
||
| 1535 | addUploads(); |
||
| 1536 | document.getElementById("tbd_accs").children[0].children[1].textContent = Math.round(ae.GetTotalMsgBytes() / 1024 / 1024); |
||
| 1537 | } else errorDialog(error); |
||
| 1538 | |||
| 1539 | np.disabled = false; |
||
| 1540 | }); |
||
| 1541 | }; |
||
| 1542 | |||
| 1543 | document.getElementById("btn_upload").onclick = function() { |
||
| 1544 | const btn = this; |
||
| 1545 | const fileSelector = document.createElement("input"); |
||
| 1546 | fileSelector.type = "file"; |
||
| 1547 | fileSelector.click(); |
||
| 1548 | |||
| 1549 | fileSelector.onchange = function() { |
||
| 1550 | btn.disabled = true; |
||
| 1551 | |||
| 1552 | const reader = new FileReader(); |
||
| 1553 | reader.onload = function() { |
||
| 1554 | ae.Message_Upload(fileSelector.files[0].name, new Uint8Array(reader.result), function(error) { |
||
| 1555 | if (error === 0) { |
||
| 1556 | addUploads(); |
||
| 1557 | document.getElementById("tbd_accs").children[0].children[1].textContent = Math.round(ae.GetTotalMsgBytes() / 1024 / 1024); |
||
| 1558 | } else errorDialog(error); |
||
| 1559 | |||
| 1560 | btn.disabled = false; |
||
| 1561 | }); |
||
| 1562 | }; |
||
| 1563 | |||
| 1564 | reader.readAsArrayBuffer(fileSelector.files[0]); |
||
| 1565 | }; |
||
| 1566 | }; |
||
| 1567 | |||
| 1568 | document.getElementById("btn_pg").onclick = function() { |
||
| 1569 | localStorage.greeting = document.getElementById("txt_pg").value; |
||
| 1570 | }; |
||
| 1571 | |||
| 1572 | document.querySelector("#write2_send > button").onclick = function() { |
||
| 1573 | const btn = this; |
||
| 1574 | btn.disabled = true; |
||
| 1575 | |||
| 1576 | // Public announcement |
||
| 1577 | if (document.getElementById("write2_recv").textContent === "public") { |
||
| 1578 | ae.Message_Public(document.getElementById("write_subj").value, document.getElementById("write_body").value, function(error) { |
||
| 1579 | if (error === 0) { |
||
| 1580 | document.getElementById("write2_btntxt").textContent = "Announced to"; |
||
| 1581 | document.getElementById("write_recv").value = ""; |
||
| 1582 | document.getElementById("write_subj").value = ""; |
||
| 1583 | document.getElementById("write_body").value = ""; |
||
| 1584 | } else { |
||
| 1585 | // TODO display error |
||
| 1586 | document.getElementById("write2_btntxt").textContent = "Retry making"; |
||
| 1587 | btn.disabled = false; |
||
| 1588 | } |
||
| 1589 | }); |
||
| 1590 | |||
| 1591 | return; |
||
| 1592 | } |
||
| 1593 | |||
| 1594 | // Email or internal message |
||
| 1595 | document.getElementById("write2_btntxt").textContent = "Sending to"; |
||
| 1596 | |||
| 1597 | ae.Message_Create( |
||
| 1598 | document.getElementById("write_subj").value, |
||
| 1599 | document.getElementById("write_body").value, |
||
| 1600 | document.getElementById("write_from").value, |
||
| 1601 | document.getElementById("write_recv").value, |
||
| 1602 | document.getElementById("write_subj").getAttribute("data-replyid"), |
||
| 1603 | (document.getElementById("write2_recv").textContent.indexOf("@") > 0) ? null : sodium.from_base64(document.querySelector("#write2_pkey > input").value, sodium.base64_variants.ORIGINAL_NO_PADDING), |
||
| 1604 | function(error) { |
||
| 1605 | if (error === 0) { |
||
| 1606 | document.getElementById("write2_btntxt").textContent = "Delivered to"; |
||
| 1607 | document.getElementById("write_recv").value = ""; |
||
| 1608 | document.getElementById("write_subj").value = ""; |
||
| 1609 | document.getElementById("write_body").value = ""; |
||
| 1610 | } else { |
||
| 1611 | errorDialog(error); |
||
| 1612 | |||
| 1613 | document.getElementById("write2_btntxt").textContent = "Retry sending to"; |
||
| 1614 | btn.disabled = false; |
||
| 1615 | } |
||
| 1616 | } |
||
| 1617 | ); |
||
| 1618 | }; |
||
| 1619 | |||
| 1620 | document.getElementById("txt_skey").onfocus = function() { |
||
| 1621 | document.getElementById("greeting").textContent = localStorage.greeting; |
||
| 1622 | }; |
||
| 1623 | |||
| 1624 | document.getElementById("txt_skey").onkeyup = function(event) { |
||
| 1625 | if (event.key === "Enter") { |
||
| 1626 | event.preventDefault(); |
||
| 1627 | document.getElementById("btn_enter").click(); |
||
| 1628 | } |
||
| 1629 | }; |
||
| 1630 | |||
| 1631 | document.getElementById("btn_enter").onclick = function() { |
||
| 1632 | const txtSkey = document.getElementById("txt_skey"); |
||
| 1633 | |||
| 1634 | if (txtSkey.value === "") { |
||
| 1635 | ae.Reset(); |
||
| 1636 | document.getElementById("greeting").textContent = "Data cleared"; |
||
| 1637 | return; |
||
| 1638 | } |
||
| 1639 | |||
| 1640 | if (!txtSkey.reportValidity()) return; |
||
| 1641 | |||
| 1642 | const btn = this; |
||
| 1643 | btn.disabled = true; |
||
| 1644 | |||
| 1645 | document.getElementById("txt_skey").disabled = true; |
||
| 1646 | document.getElementById("txt_skey").style.background = "#233"; |
||
| 1647 | |||
| 1648 | ae.SetKeys(txtSkey.value, function(successSetKeys) { |
||
| 1649 | if (successSetKeys) { |
||
| 1650 | document.body.style.cursor = "wait"; |
||
| 1651 | |||
| 1652 | ae.Message_Browse(false, true, function(statusBrowse) { |
||
| 1653 | document.body.style.cursor = "auto"; |
||
| 1654 | |||
| 1655 | if (statusBrowse === 0) { |
||
| 1656 | txtSkey.value = ""; |
||
| 1657 | document.getElementById("div_begin").hidden = true; |
||
| 1658 | document.getElementById("div_main").hidden = false; |
||
| 1659 | reloadAccount(); |
||
| 1660 | |||
| 1661 | if (ae.IsUserAdmin()) { |
||
| 1662 | ae.Account_Browse(function(statusAcc) { |
||
| 1663 | if (statusAcc === 0) { |
||
| 1664 | for (let i = 0; i < ae.Admin_GetUserCount(); i++) {addAccountToTable(i);} |
||
| 1665 | } else { |
||
| 1666 | errorDialog(statusAcc); |
||
| 1667 | } |
||
| 1668 | }); |
||
| 1669 | } |
||
| 1670 | } else { |
||
| 1671 | document.getElementById("txt_skey").disabled = false; |
||
| 1672 | document.getElementById("txt_skey").style.background = "#466"; |
||
| 1673 | btn.focus(); |
||
| 1674 | |||
| 1675 | document.getElementById("greeting").textContent = getErrorMessage(statusBrowse) + " (0x" + statusBrowse.toString(16).padStart(2, "0").toUpperCase() + ")"; |
||
| 1676 | btn.disabled = false; |
||
| 1677 | } |
||
| 1678 | }); |
||
| 1679 | } else { |
||
| 1680 | document.getElementById("txt_skey").disabled = false; |
||
| 1681 | document.getElementById("txt_skey").style.background = "#466"; |
||
| 1682 | txtSkey.focus(); |
||
| 1683 | |||
| 1684 | document.getElementById("greeting").textContent = "SetKeys failed"; |
||
| 1685 | btn.disabled = false; |
||
| 1686 | } |
||
| 1687 | }); |
||
| 1688 | }; |
||
| 1689 | |||
| 1690 | }); |
||
| 1691 |