Browse Source

function to edit entries added. action icons replace text links.

master
Rolf Brugger 14 years ago
parent
commit
24b22e2314
  1. BIN
      img/decrypt.png
  2. BIN
      img/del.png
  3. BIN
      img/edit.png
  4. BIN
      img/encrypt.png
  5. 223
      index.php
  6. 18
      makerelease.sh
  7. 2
      vault/simplevault.txt

BIN
img/decrypt.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

BIN
img/del.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

BIN
img/edit.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

BIN
img/encrypt.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

223
index.php

@ -14,7 +14,8 @@
# Author: Rolf Brugger
# Email: rolf.brugger@schweiz.org
# Date: September 2007
# Version: 0.1
# Version: 1.0 Sep 07: initial release
# 1.1 Oct 07: edit entires
#
################################################################
@ -43,11 +44,12 @@ foreach ($cats as $cat){print "<a href='?cat=$cat'>$cat</a> &nbsp; ";}
print "</p>";
// *** Actions
if(isset($_POST['entrysave'])){
if(isset($_POST['t1']) and strlen($_POST['t1'])>0){
// *** create new entry
if (!isset($_POST['cat']) or strlen($_POST['cat'])<1){ $_POST['cat']=$_POST['catdl']; $_REQUEST['cat']=$_POST['catdl']; } // take category from dropdown list?
if (!isset($_POST['cat']) or strlen($_POST['cat'])<1){ $_POST['cat']=$_POST['catdl']; $_REQUEST['cat']=$_POST['catdl']; } // take category from dropdown list? category in text field has precedence.
$encpart = svencrypt($_POST['pf'], $preamble, $_POST['newp1'], $_POST['newp2'], $_POST['newp3'], $_POST['newnote']);
$newentry = $_POST['cat']."\t".$_POST['t1']."\t".$_POST['t2']."\t".time()."\t\t\t\t\t\t".$encpart;
@ -74,26 +76,18 @@ if(isset($_POST['entrysave'])){
// ----------------------------------------------------------------------------------------
// *** Show one entry
if( isset($_GET['dec']) or isset($_GET['del'])
or isset($_POST['entrydecrypt']) or isset($_POST['entrysave'])
or isset($_POST['entrydelete'])
)
{
// decrypt and display the selected entry
if ($_GET['dec'] or isset($_POST['entrydecrypt']) ){
print "<h1>Decrypt Entry</h1>";
}
if ($_GET['del'] or isset($_POST['entrydelete']) ){
print "<h1>Delete Entry</h1>";
}
if ($_GET['dec'] or isset($_POST['entrydecrypt']) ){ $decrmode = "decrypt"; }
if ($_GET['del'] or isset($_POST['entrydelete'] ) ){ $decrmode = "delete"; }
if ($_GET['edt'] or isset($_POST['entryedit'] ) ){ $decrmode = "edit"; }
print "<table class='entry'>";
print "<tr><td>Category:</td><td>".$_REQUEST['cat']."</td></tr>";
print "<tr><td>Title:</td><td>".$_REQUEST['t1']."</td></tr>";
print "<tr><td>Subtitle:</td><td>".$_REQUEST['t2']."</td></tr>";
print "</table>";
if(isset($decrmode) or isset($_POST['entrysave']) ) {
// decrypt the specified entry
print "<h1>".ucfirst($decrmode)." Entry</h1>";
if (isset($_POST['entrydecrypt']) or isset($_POST['entrydelete'])){
show_entry_title($_REQUEST['cat'], $_REQUEST['t1'], $_REQUEST['t2']);
if (isset($_POST['entrydecrypt']) or isset($_POST['entrydelete']) or isset($_POST['entryedit'])){
// find and decrypt it
$pattern = $_POST['cat']."\t".$_POST['t1']."\t".$_POST['t2'];
$i = 0;
@ -105,29 +99,30 @@ if( isset($_GET['dec']) or isset($_GET['del'])
$recfields = explode ("\t", $vlt[$i], $nbfields);
$decfields = svdecrypt($_POST['pf'], $recfields[$nbfields-1]);
if ($decfields[0] == $preamble){
if (isset($_POST['entrydecrypt'])){
// show decrypted entry
print "<p>decrypted:<br/>";
print "<table class='encrbox'>";
print "<tr><td>Login:</td><td>".$decfields[1]."</td></tr>";
print "<tr><td>URL:</td><td>" .print_url($decfields[2])."</td></tr>";
print "<tr><td>Password:</td><td>".$decfields[3]."</td></tr>";
print "<tr><td>Note:</td><td><pre>".$decfields[$nbencfields-1]."</pre></td></tr>";
print "</table>";
print "</p>";
// decryption suceeded
if ($decrmode == "decrypt"){
// passphrase is ok, show decrypted entry
show_entry_body($decfields);
}
else{
// passphrase is ok, delete entry with index $1
array_splice ($vlt, $i, 1);
elseif ($decrmode == "delete"){
// passphrase is ok, delete entry with index $i
delete_entry($vlt, $i, $cats);
print "<p><span class='info'>Entry ".$_POST['t1']."/".$_POST['t2']." deleted!</span> &nbsp; <a href='".basename($_SERVER["PHP_SELF"])."'>Ok</a></p>";
file_put_contents("$vaultdir/$vaultfile", implode("\n", $vlt));
$cats = categories($vlt);
}
elseif ($decrmode == "edit"){
// passphrase is ok, delete entry with index $i
delete_entry($vlt, $i, $cats);
print "<p><span class='info'>Entry ".$_POST['t1']."/".$_POST['t2']." deleted! Save a new entry.</span></p>";
entry_form($_POST['cat'], $_POST['t1'], $_POST['t2'], $decfields);
}
else{
print "<p><span class='warning'>Error: wrong mode.</span></p>";
}
}
else{
// decryption failed
print "<p><span class='warning'>Wrong pass phrase!</span></p>";
decrypt_form($_POST['cat'], $_POST['t1'], $_POST['t2'], ($_POST['entrydelete']) ? "delete":"decrypt");
decrypt_form($_POST['cat'], $_POST['t1'], $_POST['t2'], $decrmode);
}
}
else{
@ -135,8 +130,10 @@ if( isset($_GET['dec']) or isset($_GET['del'])
}
}
else{
// show form for passphrase
decrypt_form($_REQUEST['cat'], $_REQUEST['t1'], $_REQUEST['t2'], (isset($_GET['del'])) ? "delete":"decrypt");
if (isset($decrmode)){
// show form for passphrase
decrypt_form($_REQUEST['cat'], $_REQUEST['t1'], $_REQUEST['t2'], $decrmode);
}
}
}
@ -145,51 +142,7 @@ if( isset($_GET['dec']) or isset($_GET['del'])
// *** Show form to create a new entry
elseif(isset($_GET['new'])){
print "<h1>Create a New Entry</h1>";
$myfname = basename($_SERVER["PHP_SELF"]);
print "<form action='$myfname' method='post'>";
print "<table class='entry'>";
print "<tr><td>Category:</td><td>";
print "<table class='raw'><tr><td>existing:</td><td><select name='catdl' size='1'><option></option>";
foreach ($cats as $cat){
print "<option".($_GET['cat']==$cat ? " selected":"").">$cat</option>";
}
print "</select></td></tr>";
print "<tr><td>or new:</td><td><input name='cat' type='text' value='' size='20' maxlength='200'/></td></tr></table>";
print "</td></tr>";
print "<tr><td>Title:</td><td>";
print "<input name='t1' type='text' value='' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>Subtitle:</td><td>";
print "<input name='t2' type='text' value='' size='20' maxlength='200'/>";
print "</td></tr>";
print "</table>";
print "<p>encrypted:<br/>";
print "<table class='encrbox'>";
print "<tr><td>Login:</td><td>";
print "<input name='newp1' type='text' value='' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>URL:</td><td>";
print "<input name='newp2' type='text' value='' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>Password:</td><td>";
print "<input name='newp3' type='text' value='' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>Note:</td><td>";
print "<textarea name='newnote' cols='40' rows='6'></textarea>";
print "</td></tr>";
print "</table>";
print "</p>";
print "<p>";
print "Passphrase: <input name='pf' type='password' value='' size='20' maxlength='200'/>";
print "</p>";
print "<p>";
print "<input type='submit' name='entrysave' value='create new' />";
print "</p>";
print "</form>";
entry_form($_GET['cat'], "", "", array());
}
@ -204,8 +157,14 @@ elseif(isset($_GET['cat'])){
$recfields = explode ("\t", $record, $nbfields);
if ($recfields[0] == $_GET['cat']){
print "<tr><td>".$recfields[0]."</td><td>".$recfields[1]."</td><td>".$recfields[2]."</td><td>".date("m.d.y G:i", $recfields[3])."</td>";
/*
print "<td><a href='?dec=1&cat=".$recfields[0]."&t1=".$recfields[1]."&t2=".$recfields[2]."'>decrypt</a></td>";
print "<td><a href='?edt=1&cat=".$recfields[0]."&t1=".$recfields[1]."&t2=".$recfields[2]."'>edit</a></td>";
print "<td><a href='?del=1&cat=".$recfields[0]."&t1=".$recfields[1]."&t2=".$recfields[2]."'>delete</a></td>";
*/
print "<td><a href='?dec=1&cat=".$recfields[0]."&t1=".$recfields[1]."&t2=".$recfields[2]."'><img src='img/decrypt.png' border='0' title='decrypt'></a></td>";
print "<td><a href='?edt=1&cat=".$recfields[0]."&t1=".$recfields[1]."&t2=".$recfields[2]."'><img src='img/edit.png' border='0' title='edit'></a></td>";
print "<td><a href='?del=1&cat=".$recfields[0]."&t1=".$recfields[1]."&t2=".$recfields[2]."'><img src='img/del.png' border='0' title='delete'></a></td>";
print "</tr>";
}
}
@ -275,6 +234,76 @@ function svdecrypt($pf, $data)
return explode ("\n", rtrim($p_t, "\0"), $nbencfields);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
function delete_entry(&$vlt, $i, &$cats)
// delete entry with index $i. The vault ($vlt) and category ($cats) arrays are updated. The vault array is saved to the file.
{
global $vaultdir, $vaultfile;
array_splice ($vlt, $i, 1);
file_put_contents("$vaultdir/$vaultfile", implode("\n", $vlt));
$cats = categories($vlt);
}
/* -------------------------------------------------------------------------- */
/* *** Forms *** */
/* -------------------------------------------------------------------------- */
function entry_form($defcat, $deft1, $deft2, $encfields)
// Prints form to create a new entry or edit an existing entry
// All function parameters are optional. They are used as default values in the form.
{
global $cats, $nbencfields;
$myfname = basename($_SERVER["PHP_SELF"]);
print "<form action='$myfname' method='post'>";
print "<table class='entry'>";
print "<tr><td>Category:</td><td>";
print "<table class='raw'><tr><td>existing:</td><td><select name='catdl' size='1'><option></option>";
foreach ($cats as $cat){
print "<option".($defcat==$cat ? " selected":"").">$cat</option>";
}
print "</select></td></tr>"; // text field category has precedence over dropdown list!
print "<tr><td>or new:</td><td><input name='cat' type='text' value='' size='20' maxlength='200'/></td></tr></table>";
print "</td></tr>";
print "<tr><td>Title:</td><td>";
print "<input name='t1' type='text' value='$deft1' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>Subtitle:</td><td>";
print "<input name='t2' type='text' value='$deft2' size='20' maxlength='200'/>";
print "</td></tr>";
print "</table>";
print "<p>encrypted:<br/>";
print "<table class='encrbox'>";
print "<tr><td>Login:</td><td>";
print "<input name='newp1' type='text' value='".$encfields[1]."' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>URL:</td><td>";
print "<input name='newp2' type='text' value='".$encfields[2]."' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>Password:</td><td>";
print "<input name='newp3' type='text' value='".$encfields[3]."' size='20' maxlength='200'/>";
print "</td></tr>";
print "<tr><td>Note:</td><td>";
print "<textarea name='newnote' cols='40' rows='6'>".$encfields[$nbencfields-1]."</textarea>";
print "</td></tr>";
print "</table>";
print "</p>";
print "<p>";
print "Passphrase: <input name='pf' type='password' value='' size='20' maxlength='200'/>";
print "</p>";
print "<p>";
print "<input type='submit' name='entrysave' value='save entry' />";
print "</p>";
print "</form>";
}
/* -------------------------------------------------------------------------- */
function decrypt_form($cat, $t1, $t2, $action)
@ -293,6 +322,34 @@ function decrypt_form($cat, $t1, $t2, $action)
print "</form>";
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
function show_entry_title($cat, $t1, $t2)
{
print "<table class='entry'>";
print "<tr><td>Category:</td><td>$cat</td></tr>";
print "<tr><td>Title:</td><td>$t1</td></tr>";
print "<tr><td>Subtitle:</td><td>$t2</td></tr>";
print "</table>";
}
/* -------------------------------------------------------------------------- */
function show_entry_body($decfields)
{
global $nbencfields;
print "<p>decrypted:<br/>";
print "<table class='encrbox'>";
print "<tr><td>Login:</td><td>".$decfields[1]."</td></tr>";
print "<tr><td>URL:</td><td>" .print_url($decfields[2])."</td></tr>";
print "<tr><td>Password:</td><td>".$decfields[3]."</td></tr>";
print "<tr><td>Note:</td><td><pre>".$decfields[$nbencfields-1]."</pre></td></tr>";
print "</table>";
print "</p>";
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
function categories ($vault)

18
makerelease.sh

@ -0,0 +1,18 @@
#!/bin/sh
if [ "$#" = "1" ]
then
echo "making package for simplevault version $1"
mkdir simplevault-$1
mkdir simplevault-$1/img
mkdir simplevault-$1/vault
mkdir simplevault-$1/doc
cp README index.php sv.css simplevault-$1
cp img/*.png simplevault-$1/img
cp doc/*.png doc/*.html doc/*.css simplevault-$1/doc
cp vault/simplevault.txt-demo simplevault-$1/vault/simplevault.txt
tar -cvzf simplevault-$1.tgz simplevault-$1
rm -rf simplevault-$1
else
echo "you have to pass one parameter: the version number like 1.0"
fi

2
vault/simplevault.txt

@ -1,4 +1,4 @@
BbVista Blackboard devnet 1190719875 %C57%BD%DDF%CF%A9%5BK%40%23%F8%ED%1Ct%1C%3F%F6%8C%82%E936%88%9F%B3%9D%A8c%92%FA%5D6%9D%26%9E%5BzY%DD%AE%E9%4098Z6%14%FD%1E%11XT%01SA%1A%86%DEx%0C2%BDh
BbVista Blackboard devnet 1192897168 %7Dz8%BE4%D4%1E%A4%E1%3AK%C40%91%FBOq%FF%C6%23%C2%F3%2A%CF%915m%0D%28%AA%10S%A2%D65%979%B8%28%0B%05m%25%E1dty8%B3%7F%9E%8Ax%BA%D2s%DD%03%87%24%89%C74U
BbVista calanda host 1190241235 %1C%5B%8A%84%27%8C%AD%FCR%B4%A5%E2%EF%85%60%60%BD%AD%12%B7%81%F3A%3C%BF%0B%5E%F5b%CB%7F%A4
BbVista calanda oracle 1190241401 G%CFH%EE%85%A2%FA%8A%80N%C1%D8M%12%A6Yk%CA%BEc%C8%BF%8E%DB%D1%D3%16%F8o%AD%95%11%10Al%17%8Ei%D4%8E%29%B8%97%D0%7E%F3%88o_h%0C%C8%AA%21%00V%C3%F2%22%5B%1A%2C%18%BF
BbVista falknis host 1190241453 %8A_%EA%F1%81b%E8%82%CE%17%0EN%1F%2C%D2%0B%BAz%DB%E4%14%2B3%D1%B4M6%C2%15M%88%F1f%B8%A2s1%3E4%91fsu%A3%0D%14%C8%85Y%B6%C9%8E%D6e%0E%AC5%DC%CE%94d%13%7E%9C