This commit is contained in:
TLINDEN
2012-02-10 20:30:38 +01:00
parent 23c301be2a
commit 773584e400
14 changed files with 1550 additions and 545 deletions

View File

@@ -1,3 +1,23 @@
1.2.7:
ADDED: new config option: ReadOnly
ADDED: new database backend: NOTEDB::text, which uses the Storable
module.
CHANGED: the data import will now written to db once.
CHANGED: added global database locking support, which is usually
useful in multiuser environments.
ADDED: new database backend: NOTEDB::general, which uses the
Config::General module.
CLEANUP: almost everywhere
CHANGED: noterc config format changed! especially the config for
backend drivers has changed a lot.
CHANGED: the configuration variables are now stored in a hash, this
saved some global variables, the driver variables are stored
in an extra hash, which contains one key per driver, this
hash gets supplied to the driver backend module 1:1.
CHANGED: the libpath variable has been removed, it didnt't work either.
use now .. instead, so that a local installation for a non
root user is still possible.
================================================================================
1.2.6: 1.2.6:
FIXED: the binary driver (NOTEDB::binary) encounters now if a note FIXED: the binary driver (NOTEDB::binary) encounters now if a note
entry is bigger then MaxNoteByte. It prints the overlapping entry is bigger then MaxNoteByte. It prints the overlapping

View File

@@ -2,7 +2,7 @@
# this is a generic module, used by note database # this is a generic module, used by note database
# backend modules. # backend modules.
# #
# Copyright (c) 2000-2003 Thomas Linden <tom@daemon.de> # Copyright (c) 2000-2004 Thomas Linden <tom@daemon.de>
package NOTEDB; package NOTEDB;
@@ -241,4 +241,59 @@ sub check_exact {
sub lock {
my ($this) = @_;
if (-e $this->{LOCKFILE}) {
open LOCK, "<$this->{LOCKFILE}" or die "could not open $this->{LOCKFILE}: $!\n";
my $data = <LOCK>;
close LOCK;
chomp $data;
print "-- waiting for lock by $data --\n";
print "-- remove the lockfile if you are sure: \"$this->{LOCKFILE}\" --\n";
}
my $timeout = 60;
eval {
local $SIG{ALRM} = sub { die "timeout" };
local $SIG{INT} = sub { die "interrupted" };
alarm $timeout - 2;
while (1) {
if (! -e $this->{LOCKFILE}) {
open LOCK, ">$this->{LOCKFILE}" or die "could not open $this->{LOCKFILE}: $!\n";
flock LOCK, LOCK_EX;
my $now = scalar localtime();
print LOCK "$ENV{USER} since $now (PID: $$)\n";
flock LOCK, LOCK_UN;
close LOCK;
alarm 0;
return 0;
}
printf " %0d\r", $timeout;
$timeout--;
sleep 1;
}
};
if($@) {
if ($@ =~ /^inter/) {
print " interrupted\n";
}
else {
print " timeout\n";
}
return 1;
}
return 0;
}
sub unlock {
my ($this) = @_;
unlink $this->{LOCKFILE};
}
1; 1;

View File

@@ -3,38 +3,44 @@
# Perl module for note # Perl module for note
# binary database backend. see docu: perldoc NOTEDB::binary # binary database backend. see docu: perldoc NOTEDB::binary
# #
package NOTEDB; package NOTEDB::binary;
$NOTEDB::binary::VERSION = "1.10";
use strict; use strict;
use Data::Dumper; #use Data::Dumper;
use IO::Seekable; use IO::Seekable;
use File::Spec; use File::Spec;
use NOTEDB;
use Fcntl qw(LOCK_EX LOCK_UN); use Fcntl qw(LOCK_EX LOCK_UN);
use NOTEDB;
use Exporter ();
use vars qw(@ISA @EXPORT);
@ISA = qw(NOTEDB Exporter);
sub new
{
my($this, $dbdriver, $dbname, $MAX_NOTE, $MAX_TIME) = @_; sub new {
my($this, %param) = @_;
my $class = ref($this) || $this; my $class = ref($this) || $this;
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
if(! -e $dbname) { $self->{NOTEDB} = $param{dbname} || File::Spec->catfile($ENV{HOME}, ".notedb");
open(TT,">$dbname") or die "Could not create $dbname: $!\n"; my $MAX_NOTE = $param{max_note} || 4096;
my $MAX_TIME = $param{max_time} || 64;
if(! -e $self->{NOTEDB}) {
open(TT,">$self->{NOTEDB}") or die "Could not create $self->{NOTEDB}: $!\n";
close (TT); close (TT);
} }
elsif(! -w $dbname) { elsif(! -w $self->{NOTEDB}) {
print "$dbname is not writable!\n"; print "$self->{NOTEDB} is not writable!\n";
exit(1); exit(1);
} }
$self->{version} = "(NOTEDB::binary, 1.8)";
$self->{NOTEDB} = $dbname;
my $TYPEDEF = "i a$MAX_NOTE a$MAX_TIME"; my $TYPEDEF = "i a$MAX_NOTE a$MAX_TIME";
my $SIZEOF = length pack($TYPEDEF, () ); my $SIZEOF = length pack($TYPEDEF, () );
@@ -42,6 +48,7 @@ sub new
$self->{sizeof} = $SIZEOF; $self->{sizeof} = $SIZEOF;
$self->{typedef} = $TYPEDEF; $self->{typedef} = $TYPEDEF;
$self->{maxnote} = $MAX_NOTE; $self->{maxnote} = $MAX_NOTE;
$self->{LOCKFILE} = $self->{NOTEDB} . "~LOCK";
return $self; return $self;
} }
@@ -54,7 +61,7 @@ sub DESTROY
sub version { sub version {
my $this = shift; my $this = shift;
return $this->{version}; return $NOTEDB::binary::VERSION;
} }
@@ -116,6 +123,13 @@ sub get_all
return %res; return %res;
} }
sub import_data {
my ($this, $data) = @_;
foreach my $num (keys %{$data}) {
my $pos = $this->get_nextnum();
$this->set_edit($pos, $data->{$num}->{note}, $data->{$num}->{date});
}
}
sub get_nextnum sub get_nextnum
{ {
@@ -365,6 +379,31 @@ sub warn_if_too_big {
} }
} }
sub _retrieve {
my ($this) = @_;
my $file = $this->{dbname};
if (-s $file) {
if ($this->changed() || $this->{unread}) {
my $fh = new FileHandle "<$this->{dbname}" or die "could not open $this->{dbname}\n";
flock $fh, LOCK_EX;
my %data = ParseConfig(-ConfigFile => $fh) or die "could not read to database: $!\n";
flock $fh, LOCK_UN;
$fh->close();
$this->{unread} = 0;
$this->{data} = \%data;
return %data;
}
else {
return %{$this->{data}};
}
}
else {
return ();
}
}
1; # keep this! 1; # keep this!

View File

@@ -4,32 +4,42 @@
# DBM database backend. see docu: perldoc NOTEDB::dbm # DBM database backend. see docu: perldoc NOTEDB::dbm
# #
package NOTEDB; package NOTEDB::dbm;
$NOTEDB::dbm::VERSION = "1.40";
use DB_File; use DB_File;
use Data::Dumper;
use NOTEDB; use NOTEDB;
use strict; use strict;
use Exporter ();
use vars qw(@ISA @EXPORT %note %date);
@ISA = qw(NOTEDB Exporter);
# Globals:
my (%note, %date);
sub new sub new
{ {
my($this, $dbdriver, $dbm_dir) = @_; my($this, %param) = @_;
my $class = ref($this) || $this; my $class = ref($this) || $this;
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
my $notefile = "note.dbm"; my $notefile = "note.dbm";
my $timefile = "date.dbm"; my $timefile = "date.dbm";
$self->{version} = "(NOTEDB::dbm, 1.2)"; my $dbm_dir = $param{directory} || File::Spec->catfile($ENV{HOME}, ".note_dbm");
tie %note, "DB_File", "$dbm_dir/$notefile" || die $!; if (! -d $dbm_dir) {
tie %date, "DB_File", "$dbm_dir/$timefile" || die $!; # try to make it
mkdir $dbm_dir || die "Could not create $dbm_dir: $!\n";
}
tie %note, "DB_File", "$dbm_dir/$notefile" || die "Could not tie $dbm_dir/$notefile: $!\n";
tie %date, "DB_File", "$dbm_dir/$timefile" || die "Could not tie $dbm_dir/$timefile: $!\n";
$self->{LOCKFILE} = $param{dbname} . "~LOCK";
return $self; return $self;
} }
@@ -66,6 +76,14 @@ sub get_all
return %res; return %res;
} }
sub import_data {
my ($this, $data) = @_;
foreach my $num (keys %{$data}) {
my $pos = $this->get_nextnum();
$note{$pos} = $this->ude($note{$num}->{note});
$date{$pos} = $this->ude($date{$num}->{date});
}
}
sub get_nextnum sub get_nextnum
{ {

402
NOTEDB/general.pm Normal file
View File

@@ -0,0 +1,402 @@
# Perl module for note
# general database backend. see docu: perldoc NOTEDB::general
# using Config::General as backend.
package NOTEDB::general;
$NOTEDB::general::VERSION = "1.00";
use strict;
#use Data::Dumper;
use File::Spec;
use Config::General;
use MIME::Base64;
use FileHandle;
use NOTEDB;
use Fcntl qw(LOCK_EX LOCK_UN);
use Exporter ();
use vars qw(@ISA @EXPORT);
@ISA = qw(NOTEDB Exporter);
sub new {
my($this, %param) = @_;
my $class = ref($this) || $this;
my $self = {};
bless($self,$class);
$self->{dbname} = $param{dbname} || File::Spec->catfile($ENV{HOME}, ".notedb");
if(! -e $param{dbname}) {
open(TT,">$param{dbname}") or die "Could not create $param{dbname}: $!\n";
close (TT);
}
elsif(! -w $param{dbname}) {
print "$param{dbname} is not writable!\n";
exit(1);
}
$self->{mtime} = $self->get_stat();
$self->{unread} = 1;
$self->{data} = {};
$self->{LOCKFILE} = $param{dbname} . "~LOCK";
return $self;
}
sub DESTROY {
# clean the desk!
}
sub version {
my $this = shift;
return $NOTEDB::general::VERSION;
}
sub get_stat {
my ($this) = @_;
my $mtime = (stat($this->{dbname}))[9];
return $mtime;
}
sub changed {
my ($this) = @_;
my $current = $this->get_stat();
if ($current > $this->{mtime}) {
$this->{mtime} = $current;
return $current;
}
else {
return 0;
}
}
sub set_del_all {
my $this = shift;
unlink $this->{dbname};
open(TT,">$this->{dbname}") or die "Could not create $this->{dbname}: $!\n";
close (TT);
}
sub get_single {
my($this, $num) = @_;
my($address, $note, $date, $buffer, $n, $t, $buffer, );
my %data = $this->get_all();
return ($data{$num}->{note}, $data{$num}->{date});
}
sub get_all {
my $this = shift;
my($num, $note, $date, %res);
if ($this->unchanged) {
return %{$this->{cache}};
}
my %data = $this->_retrieve();
foreach my $num (keys %data) {
$res{$num}->{note} = $this->ude($data{$num}->{note});
$res{$num}->{date} = $this->ude($data{$num}->{date});
}
$this->cache(%res);
return %res;
}
sub import_data {
my ($this, $data) = @_;
my %res = $this->_retrieve();
my $pos = (scalar keys %res) + 1;
foreach my $num (keys %{$data}) {
$res{$pos}->{note} = $this->uen($data->{$num}->{note});
$res{$pos}->{date} = $this->uen($data->{$num}->{date});
$pos++;
}
$this->_store(\%res);
}
sub get_nextnum {
my $this = shift;
my($num, $te, $me, $buffer);
if ($this->unchanged) {
$num = 1;
foreach (keys %{$this->{cache}}) {
$num++;
}
return $num;
}
my %data = $this->get_all();
my $size = scalar keys %data;
$num = $size + 1;
return $num;
}
sub get_search {
my($this, $searchstring) = @_;
my($buffer, $num, $note, $date, %res, $t, $n, $match);
my $regex = $this->generate_search($searchstring);
eval $regex;
if ($@) {
print "invalid expression: \"$searchstring\"!\n";
return;
}
$match = 0;
if ($this->unchanged) {
foreach my $num (keys %{$this->{cache}}) {
$_ = $this->{cache}{$num}->{note};
eval $regex;
if ($match) {
$res{$num}->{note} = $this->{cache}{$num}->{note};
$res{$num}->{date} = $this->{cache}{$num}->{date}
}
$match = 0;
}
return %res;
}
my %data = $this->get_all();
foreach my $num(sort keys %data) {
$_ = $data{$num}->{note};
eval $regex;
if($match)
{
$res{$num}->{note} = $data{$num}->{note};
$res{$num}->{date} = $data{$num}->{data};
}
$match = 0;
}
return %res;
}
sub set_edit {
my($this, $num, $note, $date) = @_;
my %data = $this->_retrieve();
$data{$num} = {
note => $this->uen($note),
date => $this->uen($date)
};
$this->_store(\%data);
$this->changed;
}
sub set_new {
my($this, $num, $note, $date) = @_;
$this->set_edit($num, $note, $date);
}
sub set_del {
my($this, $num) = @_;
my(%data, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
$setnum = 1;
%data = $this->_retrieve();
return "ERROR" if (! exists $data{$num});
delete $data{$num};
$this->_store(\%data);
$this->changed;
return;
}
sub set_recountnums {
my($this) = @_;
my(%orig, %data, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
$setnum = 1;
%orig = $this->_retrieve();
foreach $N (sort {$a <=> $b} keys %orig) {
$data{$setnum} = {
note => $orig{$N}->{note},
date => $orig{$N}->{date}
};
$setnum++;
}
$this->_store(\%data);
$this->changed;
return;
}
sub uen {
my ($this, $raw) = @_;
my($crypted);
if($NOTEDB::crypt_supported == 1) {
eval {
$crypted = $this->{cipher}->encrypt($raw);
};
}
else {
$crypted = $raw;
}
my $coded = encode_base64($crypted);
return $coded;
}
sub ude {
my ($this, $crypted) = @_;
my($raw);
if($NOTEDB::crypt_supported == 1) {
eval {
$raw = $this->{cipher}->decrypt(decode_base64($crypted));
};
}
else {
$raw = decode_base64($crypted)
}
return $raw;
}
sub _store {
my ($this, $data) = @_;
open NOTE, ">$this->{dbname}" or die "could not open $this->{dbname}: $!\n";
flock NOTE, LOCK_EX;
my $content = SaveConfigString($data) or die "could not serialize data: $!\n";
print NOTE $content;
flock NOTE, LOCK_UN;
close NOTE;
# finally re-read the db, so that we always have the latest data
$this->_retrieve();
}
sub _retrieve {
my ($this) = @_;
my $file = $this->{dbname};
if (-s $file) {
if ($this->changed() || $this->{unread}) {
my $fh = new FileHandle "<$this->{dbname}" or die "could not open $this->{dbname}\n";
flock $fh, LOCK_EX;
my %data = ParseConfig(-ConfigFile => $fh) or die "could not read to database: $!\n";
flock $fh, LOCK_UN;
$fh->close();
$this->{unread} = 0;
$this->{data} = \%data;
return %data;
}
else {
return %{$this->{data}};
}
}
else {
return ();
}
}
1; # keep this!
__END__
=head1 NAME
NOTEDB::general - module lib for accessing a notedb from perl
=head1 SYNOPSIS
# include the module
use NOTEDB;
# create a new NOTEDB object
$db = new NOTEDB("text", "/home/tom/.notedb", 4096, 24);
# decide to use encryption
# $key is the cipher to use for encryption
# $method must be either Crypt::IDEA or Crypt::DES
# you need Crypt::CBC, Crypt::IDEA and Crypt::DES to have installed.
$db->use_crypt($key,$method);
# do not use encryption
# this is the default
$db->no_crypt;
# get a single note
($note, $date) = $db->get_single(1);
# search for a certain note
%matching_notes = $db->get_search("somewhat");
# format of returned hash:
#$matching_notes{$numberofnote}->{'note' => 'something', 'date' => '23.12.2000 10:33:02'}
# get all existing notes
%all_notes = $db->get_all();
# format of returnes hash like the one from get_search above
# get the next noteid available
$next_num = $db->get_nextnum();
# modify a certain note
$db->set_edit(1, "any text", "23.12.2000 10:33:02");
# create a new note
$db->set_new(5, "any new text", "23.12.2000 10:33:02");
# delete a certain note
$db->set_del(5);
# turn on encryption. CryptMethod must be IDEA, DES or BLOWFISH
$db->use_crypt("passphrase", "CryptMethod");
# turn off encryption. This is the default.
$db->no_crypt();
=head1 DESCRIPTION
You can use this module for accessing a note database. This backend uses
a text file for storage and Config::General for accessing the file.
Currently, NOTEDB module is only used by note itself. But feel free to use it
within your own project! Perhaps someone want to implement a webinterface to
note...
=head1 USAGE
please see the section SYNOPSIS, it says it all.
=head1 AUTHOR
Thomas Linden <tom@daemon.de>.
=cut

View File

@@ -1,31 +1,41 @@
#!/usr/bin/perl #
# $Id: mysql.pm,v 1.3 2000/08/11 00:05:58 zarahg Exp $
# Perl module for note # Perl module for note
# mysql database backend. see docu: perldoc NOTEDB::mysql # mysql database backend. see docu: perldoc NOTEDB::mysql
# #
package NOTEDB; package NOTEDB::mysql;
$NOTEDB::mysql::VERSION = "1.50";
use DBI; use DBI;
use strict; use strict;
use Data::Dumper; #use Data::Dumper;
use NOTEDB; use NOTEDB;
use Exporter ();
use vars qw(@ISA @EXPORT);
@ISA = qw(NOTEDB Exporter);
sub new
{
# no prototype, because of the bin-version, which takes only a filename!
my($this, $dbdriver, $dbname, $dbhost, $dbuser, $dbpasswd,
$table, $fnum, $fnote, $fdate, $dbport) = @_; sub new {
my($this, %param) = @_;
my $class = ref($this) || $this; my $class = ref($this) || $this;
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
my $dbname = $param{dbname} || "note";
my $dbhost = $param{dbhost} || "localhost";
my $dbuser = $param{dbuser} || "";
my $dbpasswd = $param{dbpasswd} || "";
my $dbport = $param{dbport} || "";
my $fnum = "number";
my $fnote = "note";
my $fdate = "date";
my $database; my $database;
if ($dbport) { if ($dbport) {
$database = "DBI:$dbdriver:$dbname;host=$dbhost:$dbport"; $database = "DBI:$dbdriver:$dbname;host=$dbhost:$dbport";
@@ -34,8 +44,7 @@ sub new
$database = "DBI:$dbdriver:$dbname;host=$dbhost"; $database = "DBI:$dbdriver:$dbname;host=$dbhost";
} }
$self->{version} = "(NOTEDB::mysql, 1.5)"; $self->{table} = "table";
$self->{table} = $table;
$self->{sql_getsingle} = "SELECT $fnote,$fdate FROM $self->{table} WHERE $fnum = ?"; $self->{sql_getsingle} = "SELECT $fnote,$fdate FROM $self->{table} WHERE $fnum = ?";
$self->{sql_all} = "SELECT $fnum,$fnote,$fdate FROM $self->{table}"; $self->{sql_all} = "SELECT $fnum,$fnote,$fdate FROM $self->{table}";
@@ -278,6 +287,14 @@ sub set_recountnums {
$this->changed; $this->changed;
} }
sub import_data {
my ($this, $data) = @_;
foreach my $num (keys %{$data}) {
my $pos = $this->get_nextnum();
$this->set_edit($pos, $data->{$num}->{note}, $data->{$num}->{date});
}
}
sub uen sub uen
{ {
my $this = shift; my $this = shift;

355
NOTEDB/text.pm Normal file
View File

@@ -0,0 +1,355 @@
# Perl module for note
# text database backend. see docu: perldoc NOTEDB::text
# using Storable as backend.
package NOTEDB::text;
use strict;
#use Data::Dumper;
use File::Spec;
use Storable qw(lock_nstore lock_retrieve);
use MIME::Base64;
use NOTEDB;
use Fcntl qw(LOCK_EX LOCK_UN);
use Exporter ();
use vars qw(@ISA @EXPORT);
@ISA = qw(NOTEDB Exporter);
sub new {
my($this, %param) = @_;
my $class = ref($this) || $this;
my $self = {};
bless($self,$class);
$self->{NOTEDB} = $param{dbname} || File::Spec->catfile($ENV{HOME}, ".notedb");
if(! -e $param{dbname}) {
open(TT,">$param{dbname}") or die "Could not create $param{dbname}: $!\n";
close (TT);
}
elsif(! -w $param{dbname}) {
print "$param{dbname} is not writable!\n";
exit(1);
}
$self->{LOCKFILE} = $param{dbname} . "~LOCK";
return $self;
}
sub DESTROY
{
# clean the desk!
}
sub version {
my $this = shift;
return $this->{version};
}
sub set_del_all {
my $this = shift;
unlink $this->{NOTEDB};
open(TT,">$this->{NOTEDB}") or die "Could not create $this->{NOTEDB}: $!\n";
close (TT);
}
sub get_single {
my($this, $num) = @_;
my($address, $note, $date, $buffer, $n, $t, $buffer, );
my %data = $this->get_all();
return ($data{$num}->{note}, $data{$num}->{date});
}
sub get_all {
my $this = shift;
my($num, $note, $date, %res);
if ($this->unchanged) {
return %{$this->{cache}};
}
my %data = $this->_retrieve();
foreach my $num (keys %data) {
$res{$num}->{note} = $this->ude($data{$num}->{note});
$res{$num}->{date} = $this->ude($data{$num}->{date});
}
$this->cache(%res);
return %res;
}
sub import_data {
my ($this, $data) = @_;
my %res = $this->_retrieve();
my $pos = (scalar keys %res) + 1;
foreach my $num (keys %{$data}) {
$res{$pos}->{note} = $this->uen($data->{$num}->{note});
$res{$pos}->{date} = $this->uen($data->{$num}->{date});
$pos++;
}
$this->_store(\%res);
}
sub get_nextnum {
my $this = shift;
my($num, $te, $me, $buffer);
if ($this->unchanged) {
$num = 1;
foreach (keys %{$this->{cache}}) {
$num++;
}
return $num;
}
my %data = $this->get_all();
my $size = scalar keys %data;
$num = $size + 1;
return $num;
}
sub get_search {
my($this, $searchstring) = @_;
my($buffer, $num, $note, $date, %res, $t, $n, $match);
my $regex = $this->generate_search($searchstring);
eval $regex;
if ($@) {
print "invalid expression: \"$searchstring\"!\n";
return;
}
$match = 0;
if ($this->unchanged) {
foreach my $num (keys %{$this->{cache}}) {
$_ = $this->{cache}{$num}->{note};
eval $regex;
if ($match) {
$res{$num}->{note} = $this->{cache}{$num}->{note};
$res{$num}->{date} = $this->{cache}{$num}->{date}
}
$match = 0;
}
return %res;
}
my %data = $this->get_all();
foreach my $num(sort keys %data) {
$_ = $data{$num}->{note};
eval $regex;
if($match)
{
$res{$num}->{note} = $data{$num}->{note};
$res{$num}->{date} = $data{$num}->{data};
}
$match = 0;
}
return %res;
}
sub set_edit {
my($this, $num, $note, $date) = @_;
my %data = $this->_retrieve();
$data{$num} = {
note => $this->uen($note),
date => $this->uen($date)
};
$this->_store(\%data);
$this->changed;
}
sub set_new {
my($this, $num, $note, $date) = @_;
$this->set_edit($num, $note, $date);
}
sub set_del {
my($this, $num) = @_;
my(%data, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
$setnum = 1;
%data = $this->_retrieve();
return "ERROR" if (! exists $data{$num});
delete $data{$num};
$this->_store(\%data);
$this->changed;
return;
}
sub set_recountnums {
my($this) = @_;
my(%orig, %data, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
$setnum = 1;
%orig = $this->_retrieve();
foreach $N (sort {$a <=> $b} keys %orig) {
$data{$setnum} = {
note => $orig{$N}->{note},
date => $orig{$N}->{date}
};
$setnum++;
}
$this->_store(\%data);
$this->changed;
return;
}
sub uen {
my ($this, $raw) = @_;
my($crypted);
if($NOTEDB::crypt_supported == 1) {
eval {
$crypted = $this->{cipher}->encrypt($raw);
};
}
else {
$crypted = $raw;
}
my $coded = encode_base64($crypted);
return $coded;
}
sub ude {
my ($this, $crypted) = @_;
my($raw);
if($NOTEDB::crypt_supported == 1) {
eval {
$raw = $this->{cipher}->decrypt(decode_base64($crypted));
};
}
else {
$raw = decode_base64($crypted)
}
return $raw;
}
sub _store {
my ($this, $data) = @_;
lock_nstore($data, $this->{NOTEDB});
}
sub _retrieve {
my $this = shift;
if (-s $this->{NOTEDB}) {
my $data = lock_retrieve($this->{NOTEDB});
return %{$data};
}
else {
return ();
}
}
1; # keep this!
__END__
=head1 NAME
NOTEDB::text - module lib for accessing a notedb from perl
=head1 SYNOPSIS
# include the module
use NOTEDB;
# create a new NOTEDB object
$db = new NOTEDB("text", "/home/tom/.notedb", 4096, 24);
# decide to use encryption
# $key is the cipher to use for encryption
# $method must be either Crypt::IDEA or Crypt::DES
# you need Crypt::CBC, Crypt::IDEA and Crypt::DES to have installed.
$db->use_crypt($key,$method);
# do not use encryption
# this is the default
$db->no_crypt;
# get a single note
($note, $date) = $db->get_single(1);
# search for a certain note
%matching_notes = $db->get_search("somewhat");
# format of returned hash:
#$matching_notes{$numberofnote}->{'note' => 'something', 'date' => '23.12.2000 10:33:02'}
# get all existing notes
%all_notes = $db->get_all();
# format of returnes hash like the one from get_search above
# get the next noteid available
$next_num = $db->get_nextnum();
# modify a certain note
$db->set_edit(1, "any text", "23.12.2000 10:33:02");
# create a new note
$db->set_new(5, "any new text", "23.12.2000 10:33:02");
# delete a certain note
$db->set_del(5);
# turn on encryption. CryptMethod must be IDEA, DES or BLOWFISH
$db->use_crypt("passphrase", "CryptMethod");
# turn off encryption. This is the default.
$db->no_crypt();
=head1 DESCRIPTION
You can use this module for accessing a note database. This backend uses
a text file for storage and Storable for accessing the file.
Currently, NOTEDB module is only used by note itself. But feel free to use it
within your own project! Perhaps someone want to implement a webinterface to
note...
=head1 USAGE
please see the section SYNOPSIS, it says it all.
=head1 AUTHOR
Thomas Linden <tom@daemon.de>.
=cut

33
README
View File

@@ -1,4 +1,4 @@
note 1.2.6 by Thomas Linden, 30/06/2004 note 1.3.0 by Thomas Linden, 11/01/2005
======================================= =======================================
Introduction Introduction
@@ -21,16 +21,25 @@ which you can use with note:
for data storage and requires the module DB_FILE, for data storage and requires the module DB_FILE,
which is part of the perl standard distribution. which is part of the perl standard distribution.
See below for more details about the DBM module. See below for more details about the DBM module.
o NOTEDB::general - uses the module Config::General
for storage, which makes the data file portable,
since it is a plain ascii file (binary content
will be base64 encoded).
o NOTEDB::text - uses the Storable module for data
storage (a serializer). Storable is included with
perl, and since it's written in C, it's very fast.
But the resulting data files are not that portable
as the once of NOTEDB::general are.
Where to get? Where to get?
============= =============
By now at By now you can download it at http://www.daemon.de/NOTE.
http://www.daemon.de/note/ If you are using debian, you can apt-get it. If you are
using gentoo, you can emerge it.
You may also try your nearest tucows mirror. You may also try your nearest tucows or freshmeat mirror.
@@ -38,7 +47,8 @@ You may also try your nearest tucows mirror.
Features Features
======== ========
o Three different database backends, mysql(DBI), dbm, binary(bin file). o Several different database backends, mysql(DBI), dbm,
binary(bin file), general and text (text files).
o Commandline interface using the standard perl module o Commandline interface using the standard perl module
Getopt::Long, which allows you to use short or long Getopt::Long, which allows you to use short or long
command-line options. command-line options.
@@ -96,6 +106,8 @@ You need the following things:
o Getopt::Long (part of perl std ditribution) o Getopt::Long (part of perl std ditribution)
o Term::ReadLine and optionally Term::ReadLine::Gnu if o Term::ReadLine and optionally Term::ReadLine::Gnu if
you want to use the auto-completion and history functionality. you want to use the auto-completion and history functionality.
o Config::General if you want to use the NOTEDB::general
backend.
Installation Installation
@@ -119,14 +131,11 @@ After that, you are ready to install. Become root and issue:
# make install # make install
The installation process installs all modules for every available The installation process installs all modules for every available
data backend (binary, dbm and mysql). The default note configuration data backends. The default note configuration does not require
does not require additional perl modules. additional perl modules.
If you want to use the mysql backend refer to the installation If you want to use the mysql backend refer to the installation
instructions for the mysql database installation in mysql/README. instructions for the mysql database installation in mysql/README.
The DBM backend(NOTEDB::dbm) requires the existence of a directory,
which you must specify in your config using the option "DbName".
If you want to use encryption support, you will need at least If you want to use encryption support, you will need at least
Crypt:CBC and Crypt::Blowfish (or Crypt::DES or whatever). Crypt:CBC and Crypt::Blowfish (or Crypt::DES or whatever).
@@ -205,4 +214,4 @@ and I'll add you.
Last changed Last changed
============ ============
30/06/2004 11/01/2005

View File

@@ -1 +1 @@
1.2.6 1.2.7

541
bin/note
View File

@@ -23,12 +23,19 @@
# http://www.daemon.de/note/ # http://www.daemon.de/note/
# #
BEGIN {
# works on unix or cygwin only!
my $path = $0;
$path =~ s#/[^/]*$##;
unshift @INC, "$path/..";
}
use strict; use strict;
no strict 'refs'; no strict 'refs';
#use Data::Dumper;
use Getopt::Long; use Getopt::Long;
use FileHandle; use FileHandle;
use File::Spec; use File::Spec;
#use Data::Dumper;
# #
@@ -66,22 +73,11 @@ my (
# #
# set from commandline (or interactive) # set from commandline (or interactive)
# #
$number, $searchstring, $dump_file, $ImportType, $NewType, $Raw, $number, $searchstring, $dump_file, $ImportType, $NewType, $Raw, $TOPIC,
# #
# options from config file .noterc # configuration options
# %conf, %driver,
$maxlen, $timelen, $TOPIC, $NOTEDB, $MAX_TIME, $PreferredEditor,
$ALWAYS_INT, $KEEP_TIMESTAMP, $COLOR, $ALWAYS_EDIT, $HOME, $FormatText,
$BORDER_COLOR, $NOTE_COLOR, $NUM_COLOR, $TOPIC_COLOR, $MAX_NOTE,
$USE_CRYPT, $CRYPT_METHOD, $TopicSep, $DEFAULT_LIST, $TIME_COLOR, $SHORT_CD,
$USE_CACHE, $AUTO_CLEAR,
#
# db specifics from .noterc
#
$db, $dbname, $dbhost, $dbport, $dbuser, $dbpasswd, $encrypt_passwd, $clearstring,
$table, $fnum, $fnote, $fdate, $date, $dbdriver, $libpath,
# #
# processed colors # processed colors
@@ -97,9 +93,9 @@ my (
# #
# internals # internals
# #
$TYPE, $mode, $NoteKey, $TempDir, %Color, @LastTopic, $TYPE, $mode, $NoteKey, %Color, @LastTopic, $timelen, $maxlen,
$version, $CurTopic, $CurDepth, $WantTopic,$time_format, $version, $CurTopic, $CurDepth, $WantTopic, $db,
$sizeof, %TP, $TreeType, $ListType, $SetTitle, $sizeof, %TP, $TreeType, $ListType, $SetTitle, $clearstring,
@ArgTopics, $key, $typedef, @NumBlock, $has_nothing, @completion_topics, @completion_notes, @ArgTopics, $key, $typedef, @NumBlock, $has_nothing, @completion_topics, @completion_notes,
); );
@@ -108,40 +104,31 @@ my (
# DEFAULTS, allows one to use note without a config # DEFAULTS, allows one to use note without a config
# don't change them, instead use the config file! # don't change them, instead use the config file!
# #
$maxlen = 50;
my $keepmaxlen = "auto"; $conf{dbdriver} = "binary";
$timelen = 22; $conf{color} = 1;
$date = &getdate; $conf{border_color} = "bold";
$conf{num_color} = "blue";
$conf{note_color} = "green";
$conf{time_color} = "blue";
$conf{topic_color} = "bold";
$conf{topicsep} = '/';
$conf{use_crypt} = 0;
$conf{tempdirectory} = File::Spec->tmpdir();
$conf{always_int} = 1;
$conf{always_edit} = 1;
$conf{auto_clear} = 1;
$CONF = File::Spec->catfile($ENV{HOME}, ".noterc");
$USER = getlogin || getpwuid($<); $USER = getlogin || getpwuid($<);
chomp $USER; chomp $USER;
$HOME = $ENV{'HOME'};
$CONF = File::Spec->catfile($HOME, ".noterc");
$dbdriver = "binary";
$NOTEDB = File::Spec->catfile($HOME, ".notedb");
$MAX_NOTE = 4096;
$MAX_TIME = 84;
$COLOR = "YES";
$BORDER_COLOR = "bold";
$NUM_COLOR = "blue";
$NOTE_COLOR = "green";
$TIME_COLOR = "blue";
$TOPIC_COLOR = "bold";
$TOPIC = 1; $TOPIC = 1;
$TopicSep = '/'; $version = "1.3.0";
$version = "1.2.6"; $CurDepth = 1; # the current depth inside the topic "directory" structure...
if ($TOPIC) { $maxlen = "auto";
$CurDepth = 1; # the current depth inside the topic "directory" structure... $timelen = 22;
}
$USE_CRYPT = "NO";
$TempDir = File::Spec->tmpdir();
# mysql stuff
$table = "note";
$fnote = "note";
$fdate = "date";
$fnum = "number";
$ALWAYS_INT = "YES";
$ALWAYS_EDIT = "YES";
$AUTO_CLEAR = "YES";
# colors available # colors available
# \033[1m%30s\033[0m # \033[1m%30s\033[0m
@@ -227,11 +214,11 @@ else {
elsif (defined $opt_l || defined $opt_L) { elsif (defined $opt_l || defined $opt_L) {
$mode = "list"; $mode = "list";
if (defined $opt_l) { if (defined $opt_l) {
@ArgTopics = split /$TopicSep/, $opt_l; @ArgTopics = split /$conf{topicsep}/, $opt_l;
} }
else { else {
$ListType = "LONG"; $ListType = "LONG";
@ArgTopics = split /$TopicSep/, $opt_L; @ArgTopics = split /$conf{topicsep}/, $opt_L;
} }
$CurDepth += $#ArgTopics + 1 if($opt_l || $opt_L); $CurDepth += $#ArgTopics + 1 if($opt_l || $opt_L);
$CurTopic = $ArgTopics[$#ArgTopics]; # use the last element everytime... $CurTopic = $ArgTopics[$#ArgTopics]; # use the last element everytime...
@@ -357,70 +344,48 @@ if ($mode eq "encrypt_passwd") {
} }
# Always interactive? # Always interactive?
if ($ALWAYS_INT eq "YES" && $mode ne "dump" && $mode ne "import") { if ($conf{always_int} && $mode ne "dump" && $mode ne "import") {
$mode = "interactive"; $mode = "interactive";
} }
# OK ... Long-Listing shall be default ... You wanted it!!! # OK ... Long-Listing shall be default ... You wanted it!!!
if ($DEFAULT_LIST eq "LONG") { if ($conf{default_list} eq "LONG") {
# takes only precedence in commandline mode # takes only precedence in commandline mode
$ListType="LONG"; $ListType="LONG";
} }
# *if* loading of the config was successful, try to load the
# configured database backend. Currently supported:
# mysql, dbm and binary.
if ($libpath) {
unshift @INC, $libpath;
}
if ($dbdriver eq "binary") {
eval {
require NOTEDB::binary;
$db = new NOTEDB($dbdriver, $NOTEDB, $MAX_NOTE, $MAX_TIME, $dbdriver);
};
}
elsif ($dbdriver eq "mysql") {
# do the new() later because of the encrypted password!
eval {
require NOTEDB::mysql;
};
die "mysql backend unsupported: $@\n" if($@);
}
else {
eval {
require "NOTEDB::$dbdriver";
$db = new NOTEDB($dbdriver, $dbname, $dbhost, $dbuser, $dbpasswd, $table, $fnum, $fnote, $fdate);
};
}
if ($@) {
die "$dbdriver backend unsupported: $@\n";
}
# calculate some constants... # calculate some constants...
$BORDERC = "<$BORDER_COLOR>"; $BORDERC = "<$conf{border_color}>";
$_BORDERC = "</$BORDER_COLOR>"; $_BORDERC = "</$conf{border_color}>";
$NUMC = "<$NUM_COLOR>"; $NUMC = "<$conf{num_color}>";
$_NUMC = "</$NUM_COLOR>"; $_NUMC = "</$conf{num_color}>";
$NOTEC = "<$NOTE_COLOR>"; $NOTEC = "<$conf{note_color}>";
$_NOTEC = "</$NOTE_COLOR>"; $_NOTEC = "</$conf{note_color}>";
$TIMEC = "<$TIME_COLOR>"; $TIMEC = "<$conf{time_color}>";
$_TIMEC = "</$TIME_COLOR>"; $_TIMEC = "</$conf{time_color}>";
$TOPICC = "<$TOPIC_COLOR>"; $TOPICC = "<$conf{topic_color}>";
$_TOPICC = "</$TOPIC_COLOR>"; $_TOPICC = "</$conf{topic_color}>";
$NoteKey = $conf{topicsep} . "notes" . $conf{topicsep};
$NoteKey = $TopicSep . "notes" . $TopicSep;
# default permissions on new files (tmp) # default permissions on new files (tmp)
umask 077; umask 077;
# check if the user wants to use encryption:
if ($USE_CRYPT eq "YES" && $NOTEDB::crypt_supported == 1) { # load the parent module
if ($CRYPT_METHOD eq "") { &load_driver(1);
$CRYPT_METHOD = "Crypt::IDEA";
# check wether the user wants to use encryption:
if ($conf{use_crypt} && $NOTEDB::crypt_supported == 1) {
if ($conf{crypt_method} eq "") {
$conf{crypt_method} = "Crypt::IDEA";
} }
if (!exists $ENV{'NOTE_PASSWD'}) { if (!exists $ENV{'NOTE_PASSWD'}) {
print "password: "; print "password: ";
@@ -442,18 +407,21 @@ if ($USE_CRYPT eq "YES" && $NOTEDB::crypt_supported == 1) {
$key = $ENV{'NOTE_PASSWD'}; $key = $ENV{'NOTE_PASSWD'};
} }
chomp $key; chomp $key;
if ($dbdriver eq "mysql") { if ($conf{dbdriver} eq "mysql") {
eval { eval {
require Crypt::CBC; require Crypt::CBC;
my $cipher = new Crypt::CBC($key, $CRYPT_METHOD); my $cipher = new Crypt::CBC($key, $conf{crypt_method});
# decrypt the dbpasswd, if it's encrypted! # decrypt the dbpasswd, if it's encrypted!
my $dbpasswd = $cipher->decrypt(unpack("u",$dbpasswd)) if($encrypt_passwd); $driver{mysql}->{dbpasswd} =
$db = new NOTEDB($dbdriver, $dbname, $dbhost, $dbuser, $cipher->decrypt(unpack("u", $driver{mysql}->{dbpasswd})) if($driver{mysql}->{encrypt_passwd});
$dbpasswd, $table, $fnum, $fnote, $fdate, $dbport); &load_driver();
}; };
die "Could not connect do db: $@!\n" if($@); die "Could not connect do db: $@!\n" if($@);
} }
$db->use_crypt($key,$CRYPT_METHOD); else {
&load_driver();
}
$db->use_crypt($key,$conf{crypt_method});
undef $key; undef $key;
# verify correctness of passwd # verify correctness of passwd
my ($cnote, $cdate) = $db->get_single(1); my ($cnote, $cdate) = $db->get_single(1);
@@ -465,16 +433,14 @@ if ($USE_CRYPT eq "YES" && $NOTEDB::crypt_supported == 1) {
} #else empty database! } #else empty database!
} }
else { else {
if ($dbdriver eq "mysql") { &load_driver();
$db = new NOTEDB($dbdriver, $dbname, $dbhost, $dbuser,
$dbpasswd, $table, $fnum, $fnote, $fdate, $dbport);
}
$db->no_crypt; $db->no_crypt;
# does: NOTEDB::crypt_supported = 0; # does: NOTEDB::crypt_supported = 0;
my ($cnote, $cdate) = $db->get_single(1); my ($cnote, $cdate) = $db->get_single(1);
if ($cdate ne "") { if ($cdate ne "") {
if ($cdate !~ /^\d+\.\d+?/) { if ($cdate !~ /^\d+\.\d+?/) {
print "$NOTEDB seems to be encrypted!\n"; print "notedb seems to be encrypted!\n";
exit(1); exit(1);
} }
} }
@@ -482,13 +448,13 @@ else {
# do we use the db cache? # do we use the db cache?
if ($USE_CACHE) { if ($conf{use_cache}) {
$db->use_cache(); $db->use_cache();
} }
# add the backend version to the note version: # add the backend version to the note version:
$version .= " " . $db->version(); $version .= ", " . $conf{dbdriver} . " " . $db->version();
# main loop: ############### # main loop: ###############
@@ -529,7 +495,7 @@ sub encrypt_passwd {
chomp $key; chomp $key;
eval { eval {
require Crypt::CBC; require Crypt::CBC;
my $cipher = new Crypt::CBC($key, $CRYPT_METHOD); my $cipher = new Crypt::CBC($key, $conf{crypt_method});
$crypt_string = pack("u", $cipher->encrypt($clearstring)); $crypt_string = pack("u", $cipher->encrypt($clearstring));
}; };
if ($@) { if ($@) {
@@ -574,7 +540,7 @@ sub search {
print "No searchstring specified!\n"; print "No searchstring specified!\n";
} }
else { else {
print "searching the database $dbname for \"$searchstring\"...\n\n"; print "searching the database $conf{dbname} for \"$searchstring\"...\n\n";
%res = $db->get_search($searchstring); %res = $db->get_search($searchstring);
my $nummatches = scalar keys %res; my $nummatches = scalar keys %res;
@@ -618,8 +584,8 @@ sub list {
if ($TOPIC) { if ($TOPIC) {
# this allows us to have multiple topics (subtopics!) # this allows us to have multiple topics (subtopics!)
my ($firstline,$dummy) = split /\n/, $n, 2; my ($firstline,$dummy) = split /\n/, $n, 2;
if ($firstline =~ /^($TopicSep)/) { if ($firstline =~ /^($conf{topicsep})/) {
@topic = split(/$TopicSep/,$firstline); @topic = split(/$conf{topicsep}/,$firstline);
} }
else { else {
@topic = (); @topic = ();
@@ -637,7 +603,7 @@ sub list {
} }
elsif ($topic[$CurDepth-1] eq $CurTopic || ($topic[$CurDepth] eq "" && $CurDepth ==1)) { elsif ($topic[$CurDepth-1] eq $CurTopic || ($topic[$CurDepth] eq "" && $CurDepth ==1)) {
# cut the topic off the note-text # cut the topic off the note-text
if ($n =~ /^($TopicSep)/) { if ($n =~ /^($conf{topicsep})/) {
$CurItem[$i]->{'note'} = $dummy; $CurItem[$i]->{'note'} = $dummy;
} }
else { else {
@@ -663,19 +629,19 @@ sub list {
# only if there were notes under current topic # only if there were notes under current topic
undef $PATH; undef $PATH;
foreach (@RealTopic) { foreach (@RealTopic) {
$PATH .= $_ . $TopicSep; $PATH .= $_ . $conf{topicsep};
last if($_ eq $CurTopic); last if($_ eq $CurTopic);
} }
} }
else { else {
# it is an empty topic, no notes here # it is an empty topic, no notes here
$PATH = join $TopicSep, @LastTopic; $PATH = join $conf{topicsep}, @LastTopic;
$PATH .= $TopicSep . $CurTopic . $TopicSep; $PATH .= $conf{topicsep} . $CurTopic . $conf{topicsep};
$PATH =~ s/^\Q$TopicSep$TopicSep\E/$TopicSep/; $PATH =~ s/^\Q$conf{topicsep}$conf{topicsep}\E/$conf{topicsep}/;
} }
} }
else { else {
$PATH = $TopicSep; $PATH = $conf{topicsep};
} }
@completion_topics = (); @completion_topics = ();
@@ -683,7 +649,7 @@ sub list {
# we are at top level, print a list of topics... # we are at top level, print a list of topics...
foreach $top (sort(keys %TP)) { foreach $top (sort(keys %TP)) {
push @completion_topics, $top; push @completion_topics, $top;
output("-", " => ". $top . "$TopicSep ($TP{$top} notes)", output("-", " => ". $top . "$conf{topicsep} ($TP{$top} notes)",
" Sub Topic "); " Sub Topic ");
} }
#print Dumper(@CurItem); #print Dumper(@CurItem);
@@ -701,9 +667,16 @@ sub list {
############################### NEW ################################## ############################### NEW ##################################
sub new { sub new {
my($TEMP,$editor, $date, $note, $WARN, $c, $line, $num, @topic); my($TEMP,$editor, $date, $note, $WARN, $c, $line, $num, @topic);
if ($conf{readonly}) {
print "readonly\n";
return;
}
$date = &getdate; $date = &getdate;
if ($ALWAYS_EDIT eq "YES") { return if $db->lock();
if ($conf{always_edit}) {
$TEMP = &gettemp; $TEMP = &gettemp;
# security!
unlink $TEMP;
# let the user edit it... # let the user edit it...
$editor = &find_editor; $editor = &find_editor;
if ($editor) { if ($editor) {
@@ -715,6 +688,7 @@ sub new {
} }
else { else {
print "Could not find an editor to use!\n"; print "Could not find an editor to use!\n";
$db->unlock();
exit(0); exit(0);
} }
# read it in ($note) # read it in ($note)
@@ -723,6 +697,7 @@ sub new {
if ($WARN) { if ($WARN) {
print "...edit process interupted! No note has been saved.\n"; print "...edit process interupted! No note has been saved.\n";
undef $WARN; undef $WARN;
$db->unlock();
return; return;
} }
$c = 0; $c = 0;
@@ -759,12 +734,13 @@ sub new {
# look if the note was empty, so don't store it! # look if the note was empty, so don't store it!
if ($note =~ /^\s*$/) { if ($note =~ /^\s*$/) {
print "...your note was empty and will not be saved.\n"; print "...your note was empty and will not be saved.\n";
$db->unlock();
return; return;
} }
# since we have not a number, look for the next one available: # since we have not a number, look for the next one available:
$number = $db->get_nextnum(); $number = $db->get_nextnum();
if ($TOPIC && $CurTopic ne "") { if ($TOPIC && $CurTopic ne "") {
@topic = split(/$TopicSep/,$note); @topic = split(/$conf{topicsep}/,$note);
if ($topic[1] eq "") { if ($topic[1] eq "") {
$note = $PATH . "\n$note"; $note = $PATH . "\n$note";
} }
@@ -772,14 +748,22 @@ sub new {
$db->set_new($number,$note,$date); $db->set_new($number,$note,$date);
# everything ok until here! # everything ok until here!
print "note stored. it has been assigned the number $number.\n\n"; print "note stored. it has been assigned the number $number.\n\n";
$db->unlock();
} }
############################### DELETE ################################## ############################### DELETE ##################################
sub del { sub del {
my($i,@count, $setnum, $pos, $ERR); my($i,@count, $setnum, $pos, $ERR);
if ($conf{readonly}) {
print "readonly\n";
return;
}
# delete a note # delete a note
&num_bereich; # get @NumBlock from $number &num_bereich; # get @NumBlock from $number
return if $db->lock();
foreach $_ (@NumBlock) { foreach $_ (@NumBlock) {
$ERR = $db->set_del($_); $ERR = $db->set_del($_);
if ($ERR) { if ($ERR) {
@@ -792,19 +776,35 @@ sub del {
# recount the notenumbers: # recount the notenumbers:
$db->set_recountnums(); $db->set_recountnums();
$db->unlock();
@NumBlock = (); @NumBlock = ();
} }
############################### EDIT ################################## ############################### EDIT ##################################
sub edit { sub edit {
my($keeptime, $date, $editor, $TEMP, $note, $t, $num, $match, $backup); my($keeptime, $date, $editor, $TEMP, $note, $t, $num, $match, $backup);
if ($conf{readonly}) {
print "readonly\n";
return;
}
# edit a note # edit a note
$date = &getdate; $date = &getdate;
return if $db->lock();
($note, $keeptime) = $db->get_single($number); ($note, $keeptime) = $db->get_single($number);
if ($keeptime eq "") { if ($keeptime eq "") {
print "no note with that number found!\n\n"; print "no note with that number found ($number)!\n\n";
exit(0) if($mode ne "interactive"); if($mode ne "interactive") {
$db->unlock();
exit(0);
} }
else {
$db->unlock();
return;
}
}
$TEMP = &gettemp; $TEMP = &gettemp;
open NOTE,">$TEMP" or die "Could not open $TEMP\n"; open NOTE,">$TEMP" or die "Could not open $TEMP\n";
select NOTE; select NOTE;
@@ -837,7 +837,7 @@ sub edit {
unlink $TEMP || die $!; unlink $TEMP || die $!;
if ($note ne $backup) { if ($note ne $backup) {
if ($KEEP_TIMESTAMP eq "YES") { if ($conf{keep_timestamp}) {
$t = $keeptime; $t = $keeptime;
} }
else { else {
@@ -851,6 +851,7 @@ sub edit {
else { else {
print "note number $number has not changed, no save done.\n"; print "note number $number has not changed, no save done.\n";
} }
$db->unlock();
} }
@@ -878,7 +879,7 @@ sub dump {
} }
sub import { sub import {
my($num, $start, $complete, $dummi, $note, $date, $time, $number, $stdin, $DUMP); my($num, $start, $complete, $dummi, $note, $date, $time, $number, $stdin, $DUMP, %data);
# open $dump_file and import it into the notedb # open $dump_file and import it into the notedb
$stdin = 1 if($dump_file eq "-"); $stdin = 1 if($dump_file eq "-");
if ($stdin) { if ($stdin) {
@@ -888,26 +889,27 @@ sub import {
open (DUMPFILE, "<$dump_file") or die "could not open $dump_file\n"; open (DUMPFILE, "<$dump_file") or die "could not open $dump_file\n";
$DUMP = *DUMPFILE; $DUMP = *DUMPFILE;
} }
$db->set_del_all() if($ImportType ne "");
$complete=0; $complete = $start = 0;
$start = 0; $number = 1;
while (<$DUMP>) { while (<$DUMP>) {
chomp $_; chomp $_;
if ($_ =~ /^Number:\s\d+/) { if ($_ =~ /^Number:\s\d+/) {
if ($start == 0) { if ($start == 0) {
# we have no previous record # we have no previous record
($dummi,$number) = split(/\s/,$_);
$start = 1; $start = 1;
} }
else { else {
# we got a complete record, save it! # we got a complete record, save it!
$number = $db->get_nextnum(); $data{$number} = {
$db->set_new($number,$note, $date); date => $date,
print "note number $number from $dump_file inserted into notedb.\n" if(!$stdin); note => $note
};
print "fetched note number $number from $dump_file from $date.\n" if(!$stdin);
$complete = 0; $complete = 0;
$note = ""; $note = "";
$date = ""; $date = "";
($dummi,$number) = split(/\s/,$_); $number++;
} }
} }
elsif ($_ =~ /^Timestamp:\s\d+/ && $complete == 0) { elsif ($_ =~ /^Timestamp:\s\d+/ && $complete == 0) {
@@ -919,17 +921,23 @@ sub import {
$note .= $_ . "\n"; $note .= $_ . "\n";
} }
} }
if ($note ne "" && $date ne "") { if ($note ne "" && $date ne "") {
# the last record, if existent # the last record, if existent
$number = $db->get_nextnum(); $data{$number} = {
$db->set_new($number,$note, $date); data => $date,
print "note number $number from $dump_file inserted into notedb.\n" if(!$stdin); note => $note
} };
print "fetched note number $number from $dump_file from $date.\n" if(!$stdin);
} }
$db->set_del_all() if($ImportType ne "");
$db->import_data(\%data);
}
sub determine_width { sub determine_width {
# determine terminal wide, if possible # determine terminal wide, if possible
if ($keepmaxlen eq "auto") { if ($maxlen eq "auto") {
eval { eval {
my $wide = `stty -a`; my $wide = `stty -a`;
if ($wide =~ /columns (\d+?);/) { if ($wide =~ /columns (\d+?);/) {
@@ -949,7 +957,7 @@ sub determine_width {
sub clear { sub clear {
# first, try to determine the terminal height # first, try to determine the terminal height
return if(!$AUTO_CLEAR); return if(!$conf{auto_clear});
my $hoch; my $hoch;
eval { eval {
my $height = `stty -a`; my $height = `stty -a`;
@@ -989,7 +997,7 @@ sub interactive {
# per default let's list all the stuff: # per default let's list all the stuff:
# Initially do a list command! # Initially do a list command!
&determine_width; &determine_width;
$ListType = ($DEFAULT_LIST eq "LONG") ? "LONG" : ""; $ListType = ($conf{default_list} eq "LONG") ? "LONG" : "";
&list; &list;
my ($term, $prompt, $attribs); my ($term, $prompt, $attribs);
@@ -1001,7 +1009,7 @@ sub interactive {
} }
for (;;) { for (;;) {
$ListType = ($DEFAULT_LIST eq "LONG") ? "LONG" : ""; $ListType = ($conf{default_list} eq "LONG") ? "LONG" : "";
undef $SetTitle; undef $SetTitle;
if ($CurDepth > 2) { if ($CurDepth > 2) {
print C $menu . $TOPICC . "../" . $CurTopic . $_TOPICC . ">"; print C $menu . $TOPICC . "../" . $CurTopic . $_TOPICC . ">";
@@ -1140,13 +1148,13 @@ sub interactive {
# unknown # unknown
my $unchar = $char; my $unchar = $char;
$unchar =~ s/^cd //; # you may use cd <topic> now! $unchar =~ s/^cd //; # you may use cd <topic> now!
if ($unchar =~ /^\d+?$/ && $SHORT_CD) { if ($unchar =~ /^\d+?$/ && $conf{short_cd}) {
# just a number! # just a number!
my @topic; my @topic;
my ($cnote, $cdate) = $db->get_single($unchar); my ($cnote, $cdate) = $db->get_single($unchar);
my ($firstline,$dummy) = split /\n/, $cnote, 2; my ($firstline,$dummy) = split /\n/, $cnote, 2;
if ($firstline =~ /^($TopicSep)/) { if ($firstline =~ /^($conf{topicsep})/) {
@topic = split(/$TopicSep/,$firstline); @topic = split(/$conf{topicsep}/,$firstline);
} }
else { else {
@topic = (); @topic = ();
@@ -1160,7 +1168,7 @@ sub interactive {
} }
&list; &list;
} }
elsif ($unchar eq $TopicSep) { elsif ($unchar eq $conf{topicsep}) {
# cd / # cd /
$CurDepth = 1; $CurDepth = 1;
$CurTopic = ""; $CurTopic = "";
@@ -1215,7 +1223,7 @@ Read the note(1) manpage for more details.
} }
sub find_editor { sub find_editor {
return $PreferredEditor || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vi"; return $conf{preferrededitor} || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vi";
} }
#/ #/
@@ -1223,7 +1231,7 @@ sub find_editor {
sub format { sub format {
# make text bold/underlined/inverse using current $NOTEC # make text bold/underlined/inverse using current $NOTEC
my($note) = @_; my($note) = @_;
if ($FormatText) { if ($conf{formattext}) {
# prepare colors to be used for replacement # prepare colors to be used for replacement
my $BN = uc($NOTEC); my $BN = uc($NOTEC);
my $_BN = uc($_NOTEC); my $_BN = uc($_NOTEC);
@@ -1236,7 +1244,7 @@ sub format {
$IN =~ s/<(.*)>/<$1I>/; $IN =~ s/<(.*)>/<$1I>/;
$_IN =~ s/<(.*)>/<$1I>/; $_IN =~ s/<(.*)>/<$1I>/;
if ($FormatText eq "simple") { if ($conf{formattext} eq "simple") {
$note =~ s/\*([^\*]*)\*/$BN$1$_BN/g; $note =~ s/\*([^\*]*)\*/$BN$1$_BN/g;
$note =~ s/_([^_]*)_/$UN$1$_UN/g; $note =~ s/_([^_]*)_/$UN$1$_UN/g;
$note =~ s/{([^}]*)}/$IN$1$_IN/g; $note =~ s/{([^}]*)}/$IN$1$_IN/g;
@@ -1299,7 +1307,7 @@ sub output {
$title = ""; $title = "";
$CUTSPACE = " " x $txtlen; $CUTSPACE = " " x $txtlen;
if ($TYPE eq "search") { if ($TYPE eq "search") {
$note =~ s/^\Q$TopicSep\E.+?\Q$TopicSep\E\n//; $note =~ s/^\Q$conf{topicsep}\E.+?\Q$conf{topicsep}\E\n//;
} }
$note =~ s/\n/$CUTSPACE/g; $note =~ s/\n/$CUTSPACE/g;
$len = length($note); $len = length($note);
@@ -1328,8 +1336,8 @@ sub output {
if ($Raw) { if ($Raw) {
print "$num "; print "$num ";
print "$time " if($ListType eq "LONG"); print "$time " if($ListType eq "LONG");
if ($title =~ /^ => (.*)$TopicSep (.*)$/) { if ($title =~ /^ => (.*)$conf{topicsep} (.*)$/) {
$title = "$1$TopicSep $2"; # seems to be a topic! $title = "$1$conf{topicsep} $2"; # seems to be a topic!
} }
print "$title\n"; print "$title\n";
} }
@@ -1363,7 +1371,7 @@ sub C {
$S = $_[0]; $S = $_[0];
foreach $Col (%Color) { foreach $Col (%Color) {
if ($S =~ /<$Col>/g) { if ($S =~ /<$Col>/g) {
if ($COLOR ne "NO") { if ($conf{color}) {
$NC = "\033[" . $Color{$Col} . "m"; $NC = "\033[" . $Color{$Col} . "m";
$S =~ s/<$Col>/$NC/g; $S =~ s/<$Col>/$NC/g;
$S =~ s/<\/$Col>/$default/g; $S =~ s/<\/$Col>/$default/g;
@@ -1426,8 +1434,8 @@ sub getdate {
$min =~ s/^(\d)$/0$1/; $min =~ s/^(\d)$/0$1/;
$sec =~ s/^(\d)$/0$1/; $sec =~ s/^(\d)$/0$1/;
$mday =~ s/^(\d)$/0$1/; $mday =~ s/^(\d)$/0$1/;
if ($time_format) { if ($conf{time_format}) {
my $back = $time_format; my $back = $conf{time_format};
$back =~ s/YYYY/$year/; $back =~ s/YYYY/$year/;
$back =~ s/YY/substr($year, 1, 2)/e; $back =~ s/YY/substr($year, 1, 2)/e;
$back =~ s/MM/$mon/; $back =~ s/MM/$mon/;
@@ -1448,7 +1456,7 @@ sub gettemp {
for (0..10) { for (0..10) {
$random .= $range[rand(int($#range)+1)]; $random .= $range[rand(int($#range)+1)];
} }
my $tempfile = $TempDir . "/" . $USER . "." . $random; my $tempfile = File::Spec->catfile($conf{tempdirectory}, $USER . $random);
if (-e $tempfile) { if (-e $tempfile) {
# avoid race conditions! # avoid race conditions!
unlink $tempfile; unlink $tempfile;
@@ -1512,19 +1520,19 @@ sub display_tree {
$t = $res{$num}->{'date'}; $t = $res{$num}->{'date'};
# this allows us to have multiple topics (subtopics!) # this allows us to have multiple topics (subtopics!)
my ($firstline,$text,$untext) = split /\n/, $n, 3; my ($firstline,$text,$untext) = split /\n/, $n, 3;
if ($firstline =~ /^($TopicSep)/) { if ($firstline =~ /^($conf{topicsep})/) {
$firstline =~ s/($TopicSep)*$//; #remove TopicSepatator $firstline =~ s/($conf{topicsep})*$//; #remove TopicSepatator
@nodes = split(/$TopicSep/,$firstline); @nodes = split(/$conf{topicsep}/,$firstline);
} }
else { else {
@nodes = (); #("$TopicSep"); @nodes = (); #("$conf{topicsep}");
$text = $firstline; $text = $firstline;
} }
&tree($num, $text, \%TREE, @nodes); &tree($num, $text, \%TREE, @nodes);
} }
#return if ($num == 0); #return if ($num == 0);
# now that we have build our tree (in %TREE) go on t display it: # now that we have build our tree (in %TREE) go on t display it:
print C $BORDERC . "\n[" . $TopicSep . $BORDERC . "]\n"; print C $BORDERC . "\n[" . $conf{topicsep} . $BORDERC . "]\n";
&print_tree(\%{$TREE{''}},"") if(%TREE); &print_tree(\%{$TREE{''}},"") if(%TREE);
print C $BORDERC . $_BORDERC . "\n"; print C $BORDERC . $_BORDERC . "\n";
} }
@@ -1578,58 +1586,31 @@ sub getconfig {
chomp; chomp;
next if(/^\s*$/ || /^\s*#/); next if(/^\s*$/ || /^\s*#/);
my ($option,$value) = split /\s\s*=?\s*/, $_, 2; my ($option,$value) = split /\s\s*=?\s*/, $_, 2;
$value =~ s/\s*$//; $value =~ s/\s*$//;
$home = $value if (/^Home/); $value =~ s/\s*#.*$//;
$libpath = $value if (/^LibPath/); if ($value =~ /^(~\/)(.*)$/) {
$dbdriver = $value if (/^DbDriver/); $value = File::Spec->catfile($ENV{HOME}, $2);
$dbhost = $value if (/^DbHost/);
$dbport = $value if (/^DbPort/);
$dbuser = $value if (/^DbUser/);
$dbpasswd = $value if (/^DbPasswd/);
$encrypt_passwd = $value if (/^encrypt_passwd/);
$dbname = $value if (/^DbName/);
$table = $value if (/^DbTable/);
$fnum = $value if (/^FieldNumber/);
$fnote = $value if (/^FieldNote/);
$fdate = $value if (/^FieldDate/);
$SHORT_CD = $value if (/^ShortCd/);
$NOTEDB = $value if (/^NoteDb/);
$MAX_NOTE = $value if (/^MaxNoteByte/);
$MAX_TIME = $value if (/^MaxTimeByte/);
$CRYPT_METHOD = $value if (/^CryptMethod/);
$USE_CRYPT = "YES" if (/^UseEncryption/ && $value == 1);
$USE_CRYPT = undef if (/^UseEncryption/ && $value == 0);
$ALWAYS_INT = "YES" if (/^AlwaysInteractive/ && $value == 1);
$ALWAYS_INT = undef if (/^AlwaysInteractive/ && $value == 0);
$DEFAULT_LIST = "LONG" if (/^DefaultLong/ && $value == 1);
$DEFAULT_LIST = undef if (/^DefaultLong/ && $value == 0);
$ALWAYS_EDIT = "YES" if (/^AlwaysEditor/ && $value == 1);
$ALWAYS_EDIT = undef if (/^AlwaysEditor/ && $value == 0);
$KEEP_TIMESTAMP = "YES" if (/^KeepTimeStamp/ && $value == 1);
$KEEP_TIMESTAMP = undef if (/^KeepTimeStamp/ && $value == 0);
$AUTO_CLEAR = "YES" if (/^AutoClear/ && $value == 1);
$COLOR = "YES" if (/^UseColors/ && $value == 1);
$COLOR = "NO" if (/^UseColors/ && $value == 0);
$TopicSep = $value if (/^TopicSeparator/);
$maxlen = $keepmaxlen = $value if (/^MaxLen/);
$BORDER_COLOR = $value if (/^BorderColor/);
$NUM_COLOR = $value if (/^NumberColor/);
$NOTE_COLOR = $value if (/^NoteColor/);
$TIME_COLOR = $value if (/^TimeColor/);
$TOPIC_COLOR = $value if (/^TopicColor/);
$PreferredEditor = $value if (/^PreferredEditor/);
$FormatText = $value if (/^FormatText/);
$TempDir = $value if (/^TempDirectory/);
$USE_CACHE = $value if (/^Cache/);
$time_format = $value if (/^TimeFormat/);
$AUTO_CLEAR = $value if (/^AutoClear/);
} }
if ($NOTEDB =~ /^(~\/)(.*)$/) { if ($value =~ /^(yes|on|1)$/i) {
$NOTEDB = File::Spec->catfile($HOME, $2); $value = 1;
}
elsif ($value =~ /^(no|off|0)$/i) {
$value = 0;
} }
$libpath = (File::Spec->splitpath($libpath))[1]; $option = lc($option);
if ($option =~ /^(.+)::(.*)$/) {
# driver option
$driver{$1}->{$2} = $value;
}
else {
# other option
$conf{$option} = $value;
}
}
close CONFIG; close CONFIG;
} }
@@ -1660,125 +1641,27 @@ sub complete {
} }
} }
sub load_driver {
my ($parent) = @_;
if ($parent) {
my $pkg = "NOTEDB";
if ($@) {
die "Could not load the NOTEDB module: $@\n";
}
}
else {
# load the backend driver
my $pkg = "NOTEDB::$conf{dbdriver}";
eval "use $pkg;";
if ($@) {
die "$conf{dbdriver} backend unsupported: $@\n";
}
else {
$db = $pkg->new(%{$driver{$conf{dbdriver}}});
}
}
}
__END__ __END__
#
# $Log: note,v $
# Revision 1.11 2000/12/09 21:56:08 zarahg
# cvs update to 1.1.2, but incomplete, more to come
#
# Revision 1.10 2000/08/19 13:38:33 zarahg
# .
#
# Revision 1.9 2000/08/14 14:14:20 zarahg
# changed bug in cd .. after cd <number>, $PATH was empty.
#
# Revision 1.8 2000/08/14 11:21:34 zarahg
# hmmm... the default size for time was too small :-(
#
# Revision 1.7 2000/08/14 10:59:26 zarahg
# moved %Color hash from ::C() to ::main, displaying is now faster.
#
# Revision 1.6 2000/08/14 10:27:26 zarahg
# use now better color defaults and added 2 new color values, bold an white_black
#
# Revision 1.5 2000/08/11 00:05:58 zarahg
# 1.1.0 beta2 ready for testing
#
# Revision 1.4 2000/08/10 09:21:56 zarahg
# ready for 1.1.0 shipping, lots of changes/additions, see Changelog
#
# Revision 1.3 2000/07/21 06:41:25 zarahg
# 638: precedence bug fixed
#
# Revision 1.2 2000/07/09 22:10:03 zarahg
# tempfile management more secure now. new option TempDirectory. thx to Donald.
#
# Revision 1.30 2000/07/09 21:59:48 scip
# secure temp files
#
# Revision 1.29 2000/06/25 20:13:23 scip
# *** empty log message ***
#
# Revision 1.28 2000/06/25 19:51:51 scip
# changed pattern matching of seraching(\@ ... \E)
# added --config option
#
# Revision 1.27 2000/05/16 23:51:35 thomas
# fixed many option-parsing related bugd!
#
# Revision 1.26 2000/05/13 01:05:17 thomas
# changed config format and fixed some bugs
# as well as some other additions...
#
# Revision 1.25 2000/05/11 23:42:43 thomas
# --tree changed to --topic
#
# Revision 1.24 2000/05/10 22:59:44 thomas
# updated usage to reflect --raw and build it into output
# and display subs.
#
# Revision 1.23 2000/05/10 22:19:04 thomas
# changed to Getopt::Long, added --raw
#
# Revision 1.22 2000/05/01 18:51:40 thomas
# added "-" to sub dump
#
# Revision 1.21 2000/05/01 00:17:27 thomas
# *** empty log message ***
#
# Revision 1.20 2000/04/30 23:31:38 thomas
# added -o and coloured sub help.
#
# Revision 1.19 2000/04/30 16:07:23 thomas
# *** empty log message ***
#
# Revision 1.18 2000/04/30 14:58:21 thomas
# updated the usage and help subs
#
# Revision 1.17 2000/04/30 14:44:38 thomas
# added colors to the tree functions
#
# Revision 1.16 2000/04/30 14:28:38 thomas
# added the t command, which displays a topic-tree.
# and enhanced the list command in interactive mode
#
# Revision 1.15 2000/03/19 23:41:04 thomas
# changed set_del, now no extra TEMP file is required!
# instead I get it from $this->get_all() !
# Revision 1.14 2000/03/19 22:51:49 thomas
# Bug in NOTEDB::binary fixed, recount of nubers was
# incorrect.
#
# Revision 1.13 2000/03/19 11:53:32 thomas
# edit bug fixed (ude => uen)
#
# Revision 1.12 2000/03/19 03:06:51 thomas
# backend support completed.
# mysql and binary backends now excluded in separate files
#
# Revision 1.11 2000/03/18 00:16:47 thomas
# added NOTEDB::mysql and changed note to work with that.
# thus, from now on there is only one script to maintain and
# it is possible to provide more bacjends as well as making
# additional scripts upon them, i.e. cgi script...
#
# Revision 1.8 2000/03/13 22:48:43 thomas
# small width bug fixed
#
# Revision 1.7 2000/03/08 23:11:19 tom
# added cd
#
# Revision 1.6 2000/03/08 22:50:41 tom
# Added the $KEEP_TIMESTAMP option and fixed a bug regarding topic names
# and invalid resolution of them in case it started with "1 name".
#
# Revision 1.5 2000/02/25 20:59:30 tom
# corrected small timestamp problem in &edit and &new
#
# Revision 1.4 2000/02/25 13:24:11 tom
# fixed a small bug, that caused to use the last line for a note title instead the 2nd.
#
# Revision 1.3 2000/02/25 11:28:53 tom
# all changes from bin version applied to sql version

172
bin/rc Normal file
View File

@@ -0,0 +1,172 @@
# 1.2.7 -*- sh -*-
# This is a sample config for the note script
# There are useful defaults set in note itself.
#
# Copy it to your $HOME as .noterc
#
# note is Copyright (c) 1999-2000 Thomas Linden.
# You can contact me per email: <tom@daemon.de>
#
# comments start with #, empty lines will be ignored.
# 1 turns an option on, 0 turns it off.
# An option consists of an atribute-value pair separated
# by minimum one space (more spaces and/or tabs are allowed)
# Your home directory, better do not change it!
# can be an environment variable or a path
Home $ENV{'HOME'}
# specify the path, where the NOTEDB lib directory
# resides. This will only used if it is not
# installed inside the perl-lib directory structure!
LibPath ..
# you need to decide which database backend you want
# to use. Please refer to the corresponding documentation
# for closer information about the certain backend!
# Currently supported types: "binary", "dbm" or "mysql".
# You must also edit/uncomment one section below for the
# backend you want to use!
DbDriver general
# backend specific settings for binary(default) backend
NoteDb /home/tlin/dev/note-1.2.7/bin/notedb.txt
# Define the maximum bytes fields can have in a
MaxNoteByte 32768
MaxTimeByte 64
# You can use encryption with note, that means notes and
# timestamps will be stored encrypted. This is supported
# by every db-backend.
# Set to 1 to turn it on. The Default is 0 (off)
UseEncryption 1
# Specify the encryption protocol. The appropriate perl
# module needs to be installed. Possible velues are
# IDEA, DES or Blowfish, the default is IDEA.
CryptMethod Blowfish
# You can run note always in interactive mode by simply
# typing "note". Set this option to 1 to turn it on.
# The default is 0 (off).
AlwaysInteractive 0
# In interactive mode, note issues a list command if you
# simply hit enter. By turning this on, it will issue a
# longlist command instead if you hit just enter.
# The default is 0 (off)
DefaultLong 0
# You can use an external editor everytime from note instead
# of STDIN for creating new notes. Set to 1 to turn it on.
# The default is 0 (off).
AlwaysEditor 1
# uncomment and edit it, if you want to use another
# editor than the default $EDITOR or as fallback vi.
#PreferredEditor emacs
# If you dont prefer that note updates the timestamp of a
# note after editing, turn this on. It will
# keep the original timestamp if this option is set.
# The default is 0(off), to turn it on set to 1.
KeepTimeStamp 0
# You can specify your own topic separator here.
# the default topic separator is a normal slash: "/"
# see README for details about topics!
TopicSeparator /
# The maximum width for displaying a note, in CHARS.
# Depends on your screen-size. You can set it to
# "auto", if you wish that note sould determine the
# available size, but it experimental, be aware!
MaxLen auto
# note can use colors for output, set this option to
# 1, if you don't want it, or if your terminal does
# not support it, set to 0. The default is 1 (on).
UseColors 1
# Color-definitions of the various items. Will only
# take effect, if "UseColors" is turned on!
BorderColor BLACK
NumberColor RED
NoteColor blue
TimeColor green
TopicColor BLACK
# The following colors are available:
# black, red, green, yellow, blue, magenta, cyan and white.
# for bold color write it uppercase (BLACK will be bold black)
# for underlined color append an underscore (blue_ will be underlined blue)
# for inverted color append an "I" (greenI will be inverted green)
# Additional to colors, you can also do a little bit of formatting your
# notes (bold, underlined, italic), see README!
# You need to set this Option to 1, if you decide to make use of this
# capabily
FormatText 1
# You might specify your own directory for temporary files.
# note needs to create some temp files during editing of notes.
# You could protect this directory using the command: chmod 700 directory.
# The default is /tmp
TempDirectory /home/tlin/tmp
# You can jump to a topic by typing "cd 13" in interactive mode.
# You need to set thi soption to 1 if you want to use this feature.
ShortCd 1
# note can use a cached copy of the note database for list/tree/search
# this is currently only supported by the binary and the mysql backends
# set it to 1 to turn it on, the default is 0 (off)
Cache 0
# you can define your very own time format for time stamps
# YY - the last 2 digits of a year
# YYYY - year
# MM - month
# DD - day
# hh - hours
# mm - minutes
# ss - seconds
# This is the default: (18.10.2000 21:32:08)
TimeFormat DD.MM.YYYY hh:mm:ss
AutoClear = 0
# That's all about it for now.
# If you still have any questiosn, please feel free to contact
# me by email: Thomas Linden <tom@daemon.de>

View File

@@ -1,164 +1,176 @@
# note 1.2.6 -*- sh -*- # note 1.3.0 -*- sh -*-
# #
# This is a sample config for the note script # This is a sample config for the note script
# There are useful defaults set in note itself. # There are useful defaults set in note itself.
# #
# Copy it to your $HOME as .noterc # Copy it to your $HOME as .noterc
# #
# note is Copyright (c) 1999-2004 Thomas Linden. # note is Copyright (c) 1999-2004 Thomas Linden.
# You can contact me per email: <tom@daemon.de> # You can contact me per email: <tom@daemon.de>
# #
# comments start with #, empty lines will be ignored. # Comments start with #, empty lines will be ignored.
# 1 turns an option on, 0 turns it off. #
# An option consists of an atribute-value pair separated # To turn on an option, set it to: 1, on or yes
# by minimum one space (more spaces and/or tabs are allowed) # To turn off an option, set it to: 0, off or no
#
# An option consists of an atribute-value pair separated
# specify the path, where the NOTEDB lib directory # by minimum one space (more spaces and/or tabs are allowed)
# resides. This will only used if it is not # and an optional equal sign in between.
# installed inside the perl-lib directory structure! #
#LibPath /usr/local/lib # Variable names are case in-sensitive.
#
# Refer to the manpage to learn more about the config
# you need to decide which database backend you want
# to use. Please refer to the corresponding documentation
# for closer information about the certain backend!
# Currently supported types: "binary", "dbm" or "mysql".
# You must also edit/uncomment one section below for the
# backend you want to use!
DbDriver binary
#
# backend specific settings for sql backend
#
#DbHost localhost
#DbPort
#DbUser you
#DbPasswd
#DbName mynotes
#DbTable note
#FieldNumber number
#FieldNote note
#FieldDate date
# uncomment for using an encrypted password, generate it
# with note "--encrypt"
#encrypt_passwd 1
#### specific end ###
# #
# backend specific settings for binary(default) backend # you need to decide which database backend you want
# # to use. Please refer to the corresponding documentation
# where to store the database (filename) # for closer information about the certain backend!
NoteDb ~/.notedb # Currently supported types: "binary", "dbm", "mysql",
# # "general" or "text".
# Define the maximum bytes fields can have in a # You must also edit/uncomment one section below for the
# note-entry. Do not change MaxTimeByte to less than 64! # backend you want to use!
MaxNoteByte 4096 dbdriver = binary
MaxTimeByte 64
#### specific end ###
# backend specific settings for DBM backend
#
# Directory where to store the dbm files
#DbName /home/you/.notedbm
#### specific end ###
# You can use encryption with note, that means notes and #
# timestamps will be stored encrypted. This is supported # BINARY backend (the default)
# by every db-backend. binary::dbname = ~/.notedb # filename
# Set to 1 to turn it on. The Default is 0 (off) binary::MaxNoteByte = 4096 # max bytes per note entry
UseEncryption 0 binary::MaxTimeByte = 64 # max bytes for the date
# Specify the encryption protocol. The appropriate perl #
# module needs to be installed. Possible velues are # MYSQL backend
# IDEA, DES or Blowfish, the default is IDEA. mysql::dbhost = localhost # hostname
CryptMethod IDEA mysql::dbport = 3306 # tcp port
mysql::dbuser = you # db login
mysql::dbpasswd = # db password
mysql::dbname = # database name (default: note)
mysql::encrypt_passwd = 0 # mysql::dbpasswd is
# encrypted (note --encrypt)
#
# DBM backend
dbm::directory = ~/.notedbm # directory
# You can run note always in interactive mode by simply #
# typing "note". Set this option to 1 to turn it on. # GENERAL backend
# The default is 1 (on). general::dbname = ~/.notedb # filename
AlwaysInteractive 1
#
# TEXT backend
text::dbname = ~/.notedb # filename
# In interactive mode, note issues a list command if you #
# simply hit enter. By turning this on, it will issue a # You can use encryption with note, that means notes and
# longlist command instead if you hit just enter. # timestamps will be stored encrypted. This is supported
# The default is 0 (off) # by every db-backend.
DefaultLong 0 UseEncryption = NO
# You can use an external editor everytime from note instead #
# of STDIN for creating new notes. Set to 1 to turn it on. # Specify the encryption protocol. The appropriate perl
# The default is 0 (off). # module needs to be installed. Possible velues are
AlwaysEditor 0 # IDEA, DES or Blowfish, the default is IDEA.
CryptMethod = IDEA
# uncomment and edit it, if you want to use another #
# editor than the default $EDITOR or as fallback vi. # You can run note always in interactive mode by simply
#PreferredEditor emacs # typing "note". The default is: YES.
AlwaysInteractive = YES
# If you dont prefer that note updates the timestamp of a #
# note after editing, turn this on. It will # In interactive mode, note issues a list command if you
# keep the original timestamp if this option is set. # simply hit enter. By turning this on, it will issue a
# The default is 0(off), to turn it on set to 1. # longlist command instead if you hit just enter.
KeepTimeStamp 0 # The default is: NO
DefaultLong = NO
# You can specify your own topic separator here. #
# the default topic separator is a normal slash: "/" # You can use an external editor everytime from note instead
# see README for details about topics! # of STDIN for creating new notes. The default is: NO
TopicSeparator / AlwaysEditor = NO
# The maximum width for displaying a note, in CHARS. #
# Depends on your screen-size. You can set it to # By default, note looks in the environment for a variable
# "auto", if you wish that note should determine the # $EDITOR or, if this is not the case, for $VISUAL and as
# available size. # fallback it uses 'vi'.
MaxLen auto # You can override this by setting this variable here.
PreferredEditor =
# Set this to 0 if you dont want note to automatically #
# clear the screen after displaying something and after # If you don't prefer that note updates the timestamp of a
# exit (feature introduced in 1.2.1). # note after editing, turn this on. It will
AutoClear 1 # keep the original timestamp if this option is set.
# The default is: NO
KeepTimeStamp = NO
# note can use colors for output, set this option to #
# 1, if you don't want it, or if your terminal does # You can specify your own topic separator here.
# not support it, set to 0. The default is 1 (on). # The default topic separator is a normal slash: "/"
UseColors 1 TopicSeparator = /
# Color-definitions of the various items. Will only #
# take effect, if "UseColors" is turned on! # The maximum width for displaying a note, in CHARS.
# # Depends on your screen-size. You can set it to
# The following colors are available: # "auto", if you wish that note should determine the
# black, red, green, yellow, blue, magenta, cyan and white. # available size automatically.
# for bold color write it uppercase (BLACK will be bold black) MaxLen = auto
# for underlined color append an underscore (blue_ will be underlined blue)
# for inverted color append an "I" (greenI will be inverted green)
#
# Turn this off if you dont want note to automatically
# clear the screen after displaying something and after
# exit. The default is: YES
AutoClear = YES
#
# note can use colors for output, turn this of, if
# you don't like it, or if your terminal does
# not support it. The default is: YES
UseColors = YES
#
# Color-definitions of the various items. Will only
# take effect, if "UseColors" is turned on!
#
# The following colors are available:
# black, red, green, yellow, blue, magenta, cyan and white.
#
# For bold color write it uppercase (BLACK will be bold black).
# For underlined color append an underscore (blue_ will be underlined blue).
# For inverted color append an "I" (greenI will be inverted green).
BorderColor BLACK BorderColor BLACK
NumberColor blue NumberColor blue
NoteColor green NoteColor green
@@ -167,51 +179,64 @@ TopicColor BLACK
# Additional to colors, you can also do a little bit of formatting your #
# notes (bold, underlined, italic), see README! # Additional to colors, you can also do a little bit of formatting your
# You need to set this Option to 1, if you decide to make use of this # notes (bold, underlined, italic) text. The default is: YES.
# capabily. You can also set it to 'simple' to achieve a simplified syntax. FormatText = YES
FormatText 1
# You might specify your own directory for temporary files. #
# note needs to create some temp files during editing of notes. # You might specify your own directory for temporary files.
# You could protect this directory using the command: chmod 700 directory. # note needs to create some temp files during editing of notes.
# The default is /tmp # You could protect this directory using the command: chmod 700 directory.
TempDirectory /home/you/tmp # The default is: /tmp
TempDirectory = ~/tmp
# You can jump to a topic by typing "cd 13" in interactive mode. #
# You need to set thi soption to 1 if you want to use this feature. # You can jump to a topic by typing "cd 13" in interactive mode.
ShortCd 0 # The deault is: NO
ShortCd = NO
# note can use a cached copy of the note database for list/tree/search #
# this is currently only supported by the binary and the mysql backends # note can use a cached copy of the note database for list/tree/search
# set it to 1 to turn it on, the default is 0 (off) # this is currently only supported by the binary and the mysql backends,
Cache 0 # the general and text backends have an internal cache.
# The default is: NO
Cache = NO
# you can define your very own time format for time stamps #
# YY - the last 2 digits of a year # You can define your very own time format for time stamps
# YYYY - year # YY - the last 2 digits of a year
# MM - month # YYYY - year
# DD - day # MM - month
# hh - hours # DD - day
# mm - minutes # hh - hours
# ss - seconds # mm - minutes
# This is the default: (18.10.2000 21:32:08) # ss - seconds
TimeFormat DD.MM.YYYY hh:mm:ss # This is the default: (18.10.2000 21:32:08)
TimeFormat = DD.MM.YYYY hh:mm:ss
#
# You can make note readonly which is useful for database copies
# The default is: NO
ReadOnly = NO
#
#
# That's all about it for now. # That's all about it for now.
# If you still have any questiosn, please feel free to contact # If you still have any questiosn, please feel free to contact
# me by email: Thomas Linden <tom@daemon.de> # me by email: Thomas Linden <tom@daemon.de>
#
#

View File

@@ -2,7 +2,7 @@
# installs note # installs note
# This is the installer for the mysql version only! # This is the installer for the mysql version only!
echo "Welcome to note `cat VERSION` installation." echo "Welcome to note `cat ../VERSION` installation."
echo "the install script will ask you a view questions," echo "the install script will ask you a view questions,"
echo "make sure to answer them correctly!" echo "make sure to answer them correctly!"
echo echo

View File

@@ -1,3 +1,5 @@
# -*-perl-*-
=head1 NAME =head1 NAME
note - a perl script for maintaining notes. note - a perl script for maintaining notes.
@@ -16,6 +18,7 @@ the commandline. Note can use different database-backends for
notes-storage. It ships with a DBI-based mysql-module(which notes-storage. It ships with a DBI-based mysql-module(which
can also be used for other by DBI supported DBMS), another can also be used for other by DBI supported DBMS), another
module, which uses a binary file for storage and a DBM module. module, which uses a binary file for storage and a DBM module.
There are also two modules available which uses a text file.
Note supports since version 1.0.0 encryption(IDEA or DES)! Note supports since version 1.0.0 encryption(IDEA or DES)!
@@ -495,9 +498,16 @@ The default config file is B<~/.noterc>. You may specify another
one with the commandline flag I<--config>. one with the commandline flag I<--config>.
Comments start with #, empty lines will be ignored. Comments start with #, empty lines will be ignored.
1 turns an option on, 0 turns it off.
To turn on an option, set it to: B<1>, B<on> or B<yes>.
To turn off an option, set it to: B<0>, B<off> or B<no>.
An option consists of an atribute-value pair separated An option consists of an atribute-value pair separated
by minimum one space (more spaces and/or tabs are allowed). by minimum one space (more spaces and/or tabs are allowed)
and an optional equal sign in between.
Variable names are case in-sensitive.
For a detailed explanation of each possible parameter take a look For a detailed explanation of each possible parameter take a look
at the supplied sample configuration file in B<config/noterc>. at the supplied sample configuration file in B<config/noterc>.
@@ -513,6 +523,6 @@ Thomas Linden <tom@daemon.de>
=head1 VERSION =head1 VERSION
1.2.6 (30/06/2004) 1.3.0 (11/01/2005)
=cut =cut