diff options
Diffstat (limited to 'www/scripts')
-rw-r--r-- | www/scripts/main.js | 102 |
1 files changed, 98 insertions, 4 deletions
diff --git a/www/scripts/main.js b/www/scripts/main.js index dc7e001..4323680 100644 --- a/www/scripts/main.js +++ b/www/scripts/main.js @@ -1,13 +1,35 @@ var globalDb = []; -var globalGroups = [] -var globalCurrentGroup = "" +var globalGroups = []; +var globalCurrentGroup = ""; + +var globalScrollY = 0; function Error(message) { alert(message); } +function SaveScroll() +{ + globalScrollY = window.pageYOffset; +} + +function RestoreScroll() +{ + if (globalScrollY > 0) + { + window.scroll(0, globalScrollY); + globalScrollY = 0; + } +} + +function SetEnable(id, enabled) +{ + var elem = document.getElementById(id); + elem.disabled = !enabled; +} + function Copy(id) { var elem = document.getElementById(id); @@ -59,7 +81,11 @@ function WebRequest(url, func, args) var req = new XMLHttpRequest(); - req.addEventListener("load", func); + if (func) + { + req.addEventListener("load", func); + } + req.open("GET", url); req.send(); } @@ -368,7 +394,17 @@ function LoadInitialData() function DoLoadAsync() { globalDb = JSON.parse(this.responseText); - LoadInitialData(); + + if (globalDb.error) + { + Error(globalDb.error); + globalDb = []; + } + else + { + LoadInitialData(); + SetEnable("ChangePassphrase", true); + } } function DoLoad() @@ -382,6 +418,52 @@ function DoLoad() WebRequest("get.php", DoLoadAsync, []); } +function DoChangePassphraseAsync() +{ + var response = JSON.parse(this.responseText); + + if (response.error) + { + Error(response.error); + } +} + +function DoChangePassphrase() +{ + if (IsEmpty("NewPassPhrase")) + { + Error("New passphrase empty"); + return; + } + + var msg = "WARNING: If you have not successfully loaded the passwords\n"; + msg += "then this option will destroy the saved passwords. Proceed?"; + + if (confirm(msg)) + { + var f; + + var newphrase = document.getElementById("NewPassPhrase").value; + + for(f = 0; f < globalDb.length; f++) + { + var password = Decrypt(globalDb[f].password); + + WebRequest("edit.php", DoChangePassphraseAsync, + [ + "id", globalDb[f].id, + "description", globalDb[f].description, + "group", globalDb[f].group, + "username", globalDb[f].username, + "password", AESEncrypt(password, newphrase) + ] + ); + } + + document.getElementById("NewPassPhrase").value = ""; + } +} + function DoSelectGroup() { var elem = document.getElementById("Group"); @@ -529,6 +611,8 @@ function DoCopyPassword() { var id = "Password" + this.dataset.pmId; + SaveScroll(); + if (!ShowPasswords()) { SetInputType(id, "text"); @@ -540,12 +624,15 @@ function DoCopyPassword() { SetInputType(id, "password"); } + + RestoreScroll(); } function DoShow() { if (!ShowPasswords()) { + SaveScroll(); SetInputType("Password" + this.dataset.pmId, "text"); } } @@ -555,6 +642,7 @@ function DoHide() if (!ShowPasswords()) { SetInputType("Password" + this.dataset.pmId, "password"); + setTimeout(RestoreScroll, 0); } } @@ -569,6 +657,7 @@ function DoReorderAsync() else { RefreshData(); + RestoreScroll(); } } @@ -577,6 +666,8 @@ function DoUp() var id = this.dataset.pmId; var prev = this.dataset.pmPrevId; + SaveScroll(); + WebRequest("reorder.php", DoReorderAsync, [ "from_id", id, @@ -590,6 +681,8 @@ function DoDown() var id = this.dataset.pmId; var next = this.dataset.pmNextId; + SaveScroll(); + WebRequest("reorder.php", DoReorderAsync, [ "from_id", id, @@ -612,6 +705,7 @@ function DoShowPasswords() } SetInputType("PassPhrase", type); + SetInputType("NewPassPhrase", type); SetInputType("Password-1", type); var rows = GetGroupRows(); |