summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2018-07-27 21:05:41 +0000
committerIan C <ianc@noddybox.co.uk>2018-07-27 21:05:41 +0000
commit374b4419d2ff88bfbb5cfdf2ab97bd9ed885fdaf (patch)
tree92ae4d4ebbc41e436c8f71300bcca368567b439f
parentba923b884a2678b5100e6defd07c9b7adb48bf30 (diff)
Added new passphrase box. Also tried to fix scrolling back to the top on
refresh.
-rw-r--r--INSTRUCTIONS4
-rw-r--r--www/index.html13
-rw-r--r--www/scripts/main.js102
3 files changed, 112 insertions, 7 deletions
diff --git a/INSTRUCTIONS b/INSTRUCTIONS
index d362853..fa0bc98 100644
--- a/INSTRUCTIONS
+++ b/INSTRUCTIONS
@@ -24,3 +24,7 @@ Alternatively all passwords (including the pass phrase) can be seen by ticking
the Show Passwords checkbox.
The Up/Down links move the entry up/down as appropriate in the list.
+
+The New Passphrase box and button allows you to enter a new passphrase for the
+passwords. Take heed of the warning -- if you have not entered a valid
+passphrase it will destroy the passwords in the database.
diff --git a/www/index.html b/www/index.html
index 3c585a0..ce53bb4 100644
--- a/www/index.html
+++ b/www/index.html
@@ -17,12 +17,10 @@
<tr>
<td class="headertext">Passphrase:</td>
<td class="headerinput">
-<input type="password" id="PassPhrase" class="fill">
+<input type="password" id="PassPhrase" maxlength="512" class="fill">
</td>
<td class="headerbutton">
-<div>
<input type="button" value="Load" onclick="DoLoad()" class="fill">
-</div>
</td>
</tr>
<tr>
@@ -46,6 +44,15 @@
</td>
<td class="headerbutton"></td>
</tr>
+<tr>
+<td class="headertext">New Passphrase:</td>
+<td class="headerinput">
+<input type="password" id="NewPassPhrase" maxlength="512" class="fill">
+</td>
+<td class="headerbutton">
+<input id="ChangePassphrase" type="button" value="Change" onclick="DoChangePassphrase()" class="fill" disabled>
+</td>
+</tr>
</table>
<hr>
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();