diff --git a/server/functions.php b/server/functions.php index 9a43ab6..df844d4 100755 --- a/server/functions.php +++ b/server/functions.php @@ -171,28 +171,28 @@ function load_database($user) return $db; } -function add_entry($user, $mkey, $url, $login, $password) +function add_entry($user, $login, $password) { $db = load_database($user); - if ($db == null) return false; - - $password = encrypt($mkey, trim($password), true); - $login = encrypt($mkey, "@@" . trim($url) . ";" . trim($login), false); - - if ($password == null || $login == null) + if ($db == null) + { + echo "Unknown user"; return false; + } $count = $db->querySingle("SELECT COUNT(*) FROM gpass WHERE login='" . $login . "'"); if ($count != 0) { - echo "
Entry already exists
"; + echo "Entry already exists"; return false; } $result = $db->query("INSERT INTO gpass ('login', 'password') VALUES ('" . $login . "', '" . $password . "')"); + echo "OK"; + return true; } @@ -200,10 +200,16 @@ function delete_entry($user, $login) { $db = load_database($user); - if ($db == null) return false; + if ($db == null) + { + echo "Unknown user"; + return false; + } $db->query("DELETE FROM gpass WHERE login='" . $login . "'"); + echo "OK"; + return true; } @@ -223,6 +229,8 @@ function list_entries($user) $result = $db->query("SELECT * FROM gpass"); + echo "entries\n"; + while (($row = $result->fetchArray())) { echo $row['login'] . ";" . $row['password'] . "\n"; diff --git a/server/index.php b/server/index.php index a599d11..66e566b 100644 --- a/server/index.php +++ b/server/index.php @@ -25,8 +25,16 @@ session_start(); $VIEW_CIPHERED_PASSWORDS=true; $ADMIN_MODE=true; -if (isset($_GET['get_passwords']) && isset($_GET['user'])) - return list_entries($_GET['user']); +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['delete_entry']) && isset($_POST['user']) && + isset($_POST['login'])) + return delete_entry($_POST['user'], $_POST['login']); ?> @@ -96,16 +104,13 @@ else if ($user != "") { echo "Add a new password
\n"; - echo '
' . "\n"; - echo ''; - echo 'URL '; + echo 'URL '; echo 'login '; - echo 'password '; - echo 'master key '; + echo 'password '; + echo 'master key '; echo ''; - echo ""; - echo '
' . "\n"; + echo ""; } ?> diff --git a/server/ressources/gpass.js b/server/ressources/gpass.js index eea0fe8..a16bf94 100755 --- a/server/ressources/gpass.js +++ b/server/ressources/gpass.js @@ -31,6 +31,20 @@ parseUri.options = { } }; +if (!String.prototype.trim) { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ""); + }; +} + +// Array Remove - By John Resig (MIT Licensed) +// http://stackoverflow.com/questions/500606/javascript-array-delete-elements +Array.prototype.remove = function(from, to) { + var rest = this.slice((to || from) + 1 || this.length); + this.length = from < 0 ? this.length + from : from; + return this.push.apply(this, rest); +}; + function generate_password() { // symbols 32 - 47 / 58 - 64 / 91 - 96 / 123 - 126 @@ -119,6 +133,10 @@ function PasswordEntry (ciphered_login="", ciphered_password="") { this.masterkey = masterkey; aes.finish(); + // Remove salt + this.clear_password = this.clear_password.replace(/\0*$/, ""); + this.clear_password = this.clear_password.substr(0, this.clear_password.length-3); + return true; } @@ -135,16 +153,19 @@ function list_all_entries(user) req = new XMLHttpRequest(); req.addEventListener("load", function(evt) { entries = this.responseText.split("\n"); - for(i=0; i