From 0f76ccb06ea72979ce20a6403e1bdc6c08ad3b28 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Wed, 23 Oct 2013 19:39:47 +0200 Subject: [PATCH] Add update + fix a lot of bugs --- server/index.php | 30 ++-- server/ressources/gpass.js | 355 +++++++++++++++++++++++++------------ 2 files changed, 263 insertions(+), 122 deletions(-) diff --git a/server/index.php b/server/index.php index 66e566b..260ccf5 100644 --- a/server/index.php +++ b/server/index.php @@ -24,17 +24,26 @@ session_start(); $VIEW_CIPHERED_PASSWORDS=true; $ADMIN_MODE=true; +$user = ""; -if (isset($_POST['get_passwords']) && isset($_POST['user'])) - return list_entries($_POST['user']); +if ($ADMIN_MODE && isset($_POST['create_user'])) +{ + if (create_user($_POST['user'])) + $user = $_POST['user']; +} +else +{ + if (isset($_POST['get_passwords']) && isset($_POST['user'])) + return list_entries($_POST['user']); -if (isset($_POST['add_entry']) && isset($_POST['user']) && - isset($_POST['login']) && isset($_POST['password'])) - return add_entry($_POST['user'], $_POST['login'], $_POST['password']); + if (isset($_POST['add_entry']) && isset($_POST['user']) && + isset($_POST['login']) && isset($_POST['password'])) + return add_entry($_POST['user'], $_POST['login'], $_POST['password']); -if (isset($_POST['delete_entry']) && isset($_POST['user']) && - isset($_POST['login'])) - return delete_entry($_POST['user'], $_POST['login']); + if (isset($_POST['delete_entry']) && isset($_POST['user']) && + isset($_POST['login'])) + return delete_entry($_POST['user'], $_POST['login']); +} ?> @@ -61,6 +70,7 @@ if (isset($_POST['delete_entry']) && isset($_POST['user']) &&
Master key '; echo "" . "\n"; - if ($_SERVER['HTTPS'] == "") + if (!isset($_SERVER['HTTPS'])) echo "
Current addon address is : http://" . $_SERVER['SERVER_NAME'] . "/" . $user . "
\n"; else echo "
Current addon address is : https://" . $_SERVER['SERVER_NAME'] . "/" . $user . "
\n"; @@ -108,7 +118,7 @@ if ($user != "") echo 'URL '; echo 'login '; echo 'password '; - echo 'master key '; + echo 'master key '; echo ''; echo ""; } diff --git a/server/ressources/gpass.js b/server/ressources/gpass.js index a16bf94..2823770 100755 --- a/server/ressources/gpass.js +++ b/server/ressources/gpass.js @@ -45,6 +45,12 @@ Array.prototype.remove = function(from, to) { return this.push.apply(this, rest); }; +Element.prototype.removeAllChilds = function() { + while (this.hasChildNodes()) + this.removeChild(this.childNodes[0]); +}; + + function generate_password() { // symbols 32 - 47 / 58 - 64 / 91 - 96 / 123 - 126 @@ -118,6 +124,7 @@ function PasswordEntry (ciphered_login="", ciphered_password="") { aes = new AES(); a_masterkey = aes.init(hex2a(masterkey)); login = aes.decryptLongString(hex2a(this.ciphered_login), a_masterkey); + login = login.replace(/\0*$/, ""); if (login.indexOf("@@") != 0) { aes.finish(); @@ -144,6 +151,11 @@ function PasswordEntry (ciphered_login="", ciphered_password="") { { return (this.unciphered == true && masterkey == this.masterkey && masterkey != "") } + + this.isCiphered = function(masterkey) + { + return !(this.isUnciphered(masterkey)); + } } function list_all_entries(user) @@ -168,36 +180,56 @@ function list_all_entries(user) req.send("get_passwords=1&user=" + user); } -function change_master_key() +function update_stats() { nb_ciphered_passwords = 0; nb_unciphered_passwords = 0; for(i=0; i