FIXED: most config variables not related to drivers had

invalid sentence in note, so the new ones of the new config
                were ignored.
FIXED:          added version to NOTEDB::text.
FIXED:          fixed handling of NOTEDB::crypt_supported, now encryption
                works again.
ADDED:          NOTEDB::text now supports internal caching too.
CHANGED:        lock() sets the umask internally to 022, so that other
                users are able to read the lockfile.
This commit is contained in:
TLINDEN
2012-02-10 20:31:13 +01:00
parent 773584e400
commit b2b5cea5ec
10 changed files with 117 additions and 87 deletions

View File

@@ -1,4 +1,15 @@
1.2.7:
1.3.1:
FIXED: most config variables not related to drivers had
invalid sentence in note, so the new ones of the new config
were ignored.
FIXED: added version to NOTEDB::text.
FIXED: fixed handling of NOTEDB::crypt_supported, now encryption
works again.
ADDED: NOTEDB::text now supports internal caching too.
CHANGED: lock() sets the umask internally to 022, so that other
users are able to read the lockfile.
================================================================================
1.3.0:
ADDED: new config option: ReadOnly
ADDED: new database backend: NOTEDB::text, which uses the Storable
module.

View File

@@ -7,7 +7,10 @@
package NOTEDB;
$NOTEDB::VERSION = "1.3";
use Exporter ();
use vars qw(@ISA @EXPORT $crypt_supported);
$NOTEDB::VERSION = "1.31";
BEGIN {
# make sure, it works, otherwise encryption
@@ -35,7 +38,8 @@ sub use_crypt {
$cipher = new Crypt::CBC($key, $method);
};
if($@) {
$NOTEDB::crypt_supported == 0;
print "warning: Crypt::$method not supported by system!\n";
$NOTEDB::crypt_supported = 0;
}
else {
$this->{cipher} = $cipher;
@@ -261,6 +265,7 @@ sub lock {
alarm $timeout - 2;
while (1) {
if (! -e $this->{LOCKFILE}) {
umask 022;
open LOCK, ">$this->{LOCKFILE}" or die "could not open $this->{LOCKFILE}: $!\n";
flock LOCK, LOCK_EX;
@@ -282,6 +287,7 @@ sub lock {
print " interrupted\n";
}
else {
print $@;
print " timeout\n";
}
return 1;

View File

@@ -4,7 +4,7 @@
package NOTEDB::general;
$NOTEDB::general::VERSION = "1.00";
$NOTEDB::general::VERSION = "1.01";
use strict;
#use Data::Dumper;
@@ -258,6 +258,7 @@ sub uen {
eval {
$crypted = $this->{cipher}->encrypt($raw);
};
print $@;
}
else {
$crypted = $raw;
@@ -287,8 +288,13 @@ sub _store {
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;
if (%{$data}) {
my $content = SaveConfigString($data) or die "could not serialize data: $!\n";
print NOTE $content;
}
else {
print NOTE "";
}
flock NOTE, LOCK_UN;
close NOTE;

View File

@@ -4,6 +4,8 @@
package NOTEDB::text;
$NOTEDB::text::VERSION = "1.01";
use strict;
#use Data::Dumper;
use File::Spec;
@@ -40,6 +42,9 @@ sub new {
}
$self->{LOCKFILE} = $param{dbname} . "~LOCK";
$self->{mtime} = $self->get_stat();
$self->{unread} = 1;
$self->{data} = {};
return $self;
}
@@ -52,9 +57,14 @@ sub DESTROY
sub version {
my $this = shift;
return $this->{version};
return $NOTEDB::text::VERSION;
}
sub get_stat {
my ($this) = @_;
my $mtime = (stat($this->{dbname}))[9];
return $mtime;
}
sub set_del_all {
@@ -268,8 +278,12 @@ sub _store {
sub _retrieve {
my $this = shift;
if (-s $this->{NOTEDB}) {
my $data = lock_retrieve($this->{NOTEDB});
return %{$data};
if ($this->changed() || $this->{unread}) {
my $data = lock_retrieve($this->{NOTEDB});
$this->{unread} = 0;
$this->{data} = $data;
return %{$data};
}
}
else {
return ();

2
README
View File

@@ -1,4 +1,4 @@
note 1.3.0 by Thomas Linden, 11/01/2005
note 1.3.1 by Thomas Linden, 12/01/2005
=======================================
Introduction

6
TODO
View File

@@ -3,10 +3,4 @@
- ncurses support
- readline/editline support for interactive prompt
with: completion and history
- LOCKing support, so that multiple people can use
note simultaneously while not interfering with
each other

View File

@@ -1 +1 @@
1.2.7
1.3.1

133
bin/note
View File

@@ -105,31 +105,30 @@ my (
# don't change them, instead use the config file!
#
$conf{dbdriver} = "binary";
$conf{color} = 1;
$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{dbdriver} = "binary";
$conf{usecolors} = 1;
$conf{bordercolor} = "bold";
$conf{numbercolor} = "blue";
$conf{notecolor} = "green";
$conf{timecolor} = "blue";
$conf{topiccolor} = "bold";
$conf{topicseparator} = '/';
$conf{useencryption} = 0;
$conf{tempdirectory} = File::Spec->tmpdir();
$conf{alwaysinteractive} = 1;
$conf{alwayseditor} = 1;
$conf{autoclear} = 1;
$CONF = File::Spec->catfile($ENV{HOME}, ".noterc");
$USER = getlogin || getpwuid($<);
chomp $USER;
$TOPIC = 1;
$version = "1.3.0";
$version = "1.3.1";
$CurDepth = 1; # the current depth inside the topic "directory" structure...
$maxlen = "auto";
$timelen = 22;
# colors available
# \033[1m%30s\033[0m
%Color = ( 'black' => '0;30',
@@ -214,11 +213,11 @@ else {
elsif (defined $opt_l || defined $opt_L) {
$mode = "list";
if (defined $opt_l) {
@ArgTopics = split /$conf{topicsep}/, $opt_l;
@ArgTopics = split /$conf{topicseparator}/, $opt_l;
}
else {
$ListType = "LONG";
@ArgTopics = split /$conf{topicsep}/, $opt_L;
@ArgTopics = split /$conf{topicseparator}/, $opt_L;
}
$CurDepth += $#ArgTopics + 1 if($opt_l || $opt_L);
$CurTopic = $ArgTopics[$#ArgTopics]; # use the last element everytime...
@@ -344,12 +343,12 @@ if ($mode eq "encrypt_passwd") {
}
# Always interactive?
if ($conf{always_int} && $mode ne "dump" && $mode ne "import") {
if ($conf{alwaysinteractive} && $mode ne "dump" && $mode ne "import") {
$mode = "interactive";
}
# OK ... Long-Listing shall be default ... You wanted it!!!
if ($conf{default_list} eq "LONG") {
if ($conf{defaultlong}) {
# takes only precedence in commandline mode
$ListType="LONG";
}
@@ -358,18 +357,18 @@ if ($conf{default_list} eq "LONG") {
# calculate some constants...
$BORDERC = "<$conf{border_color}>";
$_BORDERC = "</$conf{border_color}>";
$NUMC = "<$conf{num_color}>";
$_NUMC = "</$conf{num_color}>";
$NOTEC = "<$conf{note_color}>";
$_NOTEC = "</$conf{note_color}>";
$TIMEC = "<$conf{time_color}>";
$_TIMEC = "</$conf{time_color}>";
$TOPICC = "<$conf{topic_color}>";
$_TOPICC = "</$conf{topic_color}>";
$BORDERC = "<$conf{bordercolor}>";
$_BORDERC = "</$conf{bordercolor}>";
$NUMC = "<$conf{numbercolor}>";
$_NUMC = "</$conf{numbercolor}>";
$NOTEC = "<$conf{notecolor}>";
$_NOTEC = "</$conf{notecolor}>";
$TIMEC = "<$conf{timecolor}>";
$_TIMEC = "</$conf{timecolor}>";
$TOPICC = "<$conf{topiccolor}>";
$_TOPICC = "</$conf{topiccolor}>";
$NoteKey = $conf{topicsep} . "notes" . $conf{topicsep};
$NoteKey = $conf{topicseparator} . "notes" . $conf{topicseparator};
@@ -381,11 +380,10 @@ umask 077;
# load the parent module
&load_driver(1);
# 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 ($conf{useencryption} && $NOTEDB::crypt_supported == 1) {
if ($conf{cryptmethod} eq "") {
$conf{cryptmethod} = "Crypt::IDEA";
}
if (!exists $ENV{'NOTE_PASSWD'}) {
print "password: ";
@@ -410,7 +408,7 @@ if ($conf{use_crypt} && $NOTEDB::crypt_supported == 1) {
if ($conf{dbdriver} eq "mysql") {
eval {
require Crypt::CBC;
my $cipher = new Crypt::CBC($key, $conf{crypt_method});
my $cipher = new Crypt::CBC($key, $conf{cryptmethod});
# decrypt the dbpasswd, if it's encrypted!
$driver{mysql}->{dbpasswd} =
$cipher->decrypt(unpack("u", $driver{mysql}->{dbpasswd})) if($driver{mysql}->{encrypt_passwd});
@@ -421,7 +419,7 @@ if ($conf{use_crypt} && $NOTEDB::crypt_supported == 1) {
else {
&load_driver();
}
$db->use_crypt($key,$conf{crypt_method});
$db->use_crypt($key,$conf{cryptmethod});
undef $key;
# verify correctness of passwd
my ($cnote, $cdate) = $db->get_single(1);
@@ -448,7 +446,7 @@ else {
# do we use the db cache?
if ($conf{use_cache}) {
if ($conf{cache}) {
$db->use_cache();
}
@@ -495,7 +493,7 @@ sub encrypt_passwd {
chomp $key;
eval {
require Crypt::CBC;
my $cipher = new Crypt::CBC($key, $conf{crypt_method});
my $cipher = new Crypt::CBC($key, $conf{cryptmethod});
$crypt_string = pack("u", $cipher->encrypt($clearstring));
};
if ($@) {
@@ -584,8 +582,8 @@ sub list {
if ($TOPIC) {
# this allows us to have multiple topics (subtopics!)
my ($firstline,$dummy) = split /\n/, $n, 2;
if ($firstline =~ /^($conf{topicsep})/) {
@topic = split(/$conf{topicsep}/,$firstline);
if ($firstline =~ /^($conf{topicseparator})/) {
@topic = split(/$conf{topicseparator}/,$firstline);
}
else {
@topic = ();
@@ -603,7 +601,7 @@ sub list {
}
elsif ($topic[$CurDepth-1] eq $CurTopic || ($topic[$CurDepth] eq "" && $CurDepth ==1)) {
# cut the topic off the note-text
if ($n =~ /^($conf{topicsep})/) {
if ($n =~ /^($conf{topicseparator})/) {
$CurItem[$i]->{'note'} = $dummy;
}
else {
@@ -629,19 +627,19 @@ sub list {
# only if there were notes under current topic
undef $PATH;
foreach (@RealTopic) {
$PATH .= $_ . $conf{topicsep};
$PATH .= $_ . $conf{topicseparator};
last if($_ eq $CurTopic);
}
}
else {
# it is an empty topic, no notes here
$PATH = join $conf{topicsep}, @LastTopic;
$PATH .= $conf{topicsep} . $CurTopic . $conf{topicsep};
$PATH =~ s/^\Q$conf{topicsep}$conf{topicsep}\E/$conf{topicsep}/;
$PATH = join $conf{topicseparator}, @LastTopic;
$PATH .= $conf{topicseparator} . $CurTopic . $conf{topicseparator};
$PATH =~ s/^\Q$conf{topicseparator}$conf{topicseparator}\E/$conf{topicseparator}/;
}
}
else {
$PATH = $conf{topicsep};
$PATH = $conf{topicseparator};
}
@completion_topics = ();
@@ -649,7 +647,7 @@ sub list {
# we are at top level, print a list of topics...
foreach $top (sort(keys %TP)) {
push @completion_topics, $top;
output("-", " => ". $top . "$conf{topicsep} ($TP{$top} notes)",
output("-", " => ". $top . "$conf{topicseparator} ($TP{$top} notes)",
" Sub Topic ");
}
#print Dumper(@CurItem);
@@ -673,7 +671,7 @@ sub new {
}
$date = &getdate;
return if $db->lock();
if ($conf{always_edit}) {
if ($conf{alwayseditor}) {
$TEMP = &gettemp;
# security!
unlink $TEMP;
@@ -740,7 +738,7 @@ sub new {
# since we have not a number, look for the next one available:
$number = $db->get_nextnum();
if ($TOPIC && $CurTopic ne "") {
@topic = split(/$conf{topicsep}/,$note);
@topic = split(/$conf{topicseparator}/,$note);
if ($topic[1] eq "") {
$note = $PATH . "\n$note";
}
@@ -837,7 +835,7 @@ sub edit {
unlink $TEMP || die $!;
if ($note ne $backup) {
if ($conf{keep_timestamp}) {
if ($conf{keeptimestamp}) {
$t = $keeptime;
}
else {
@@ -957,7 +955,7 @@ sub determine_width {
sub clear {
# first, try to determine the terminal height
return if(!$conf{auto_clear});
return if(!$conf{autoclear});
my $hoch;
eval {
my $height = `stty -a`;
@@ -997,7 +995,7 @@ sub interactive {
# per default let's list all the stuff:
# Initially do a list command!
&determine_width;
$ListType = ($conf{default_list} eq "LONG") ? "LONG" : "";
$ListType = ($conf{defaultlong}) ? "LONG" : "";
&list;
my ($term, $prompt, $attribs);
@@ -1009,7 +1007,7 @@ sub interactive {
}
for (;;) {
$ListType = ($conf{default_list} eq "LONG") ? "LONG" : "";
$ListType = ($conf{defaultlong}) ? "LONG" : "";
undef $SetTitle;
if ($CurDepth > 2) {
print C $menu . $TOPICC . "../" . $CurTopic . $_TOPICC . ">";
@@ -1153,8 +1151,8 @@ sub interactive {
my @topic;
my ($cnote, $cdate) = $db->get_single($unchar);
my ($firstline,$dummy) = split /\n/, $cnote, 2;
if ($firstline =~ /^($conf{topicsep})/) {
@topic = split(/$conf{topicsep}/,$firstline);
if ($firstline =~ /^($conf{topicseparator})/) {
@topic = split(/$conf{topicseparator}/,$firstline);
}
else {
@topic = ();
@@ -1168,7 +1166,7 @@ sub interactive {
}
&list;
}
elsif ($unchar eq $conf{topicsep}) {
elsif ($unchar eq $conf{topicseparator}) {
# cd /
$CurDepth = 1;
$CurTopic = "";
@@ -1307,7 +1305,7 @@ sub output {
$title = "";
$CUTSPACE = " " x $txtlen;
if ($TYPE eq "search") {
$note =~ s/^\Q$conf{topicsep}\E.+?\Q$conf{topicsep}\E\n//;
$note =~ s/^\Q$conf{topicseparator}\E.+?\Q$conf{topicseparator}\E\n//;
}
$note =~ s/\n/$CUTSPACE/g;
$len = length($note);
@@ -1336,8 +1334,8 @@ sub output {
if ($Raw) {
print "$num ";
print "$time " if($ListType eq "LONG");
if ($title =~ /^ => (.*)$conf{topicsep} (.*)$/) {
$title = "$1$conf{topicsep} $2"; # seems to be a topic!
if ($title =~ /^ => (.*)$conf{topicseparator} (.*)$/) {
$title = "$1$conf{topicseparator} $2"; # seems to be a topic!
}
print "$title\n";
}
@@ -1371,7 +1369,7 @@ sub C {
$S = $_[0];
foreach $Col (%Color) {
if ($S =~ /<$Col>/g) {
if ($conf{color}) {
if ($conf{usecolors}) {
$NC = "\033[" . $Color{$Col} . "m";
$S =~ s/<$Col>/$NC/g;
$S =~ s/<\/$Col>/$default/g;
@@ -1434,8 +1432,8 @@ sub getdate {
$min =~ s/^(\d)$/0$1/;
$sec =~ s/^(\d)$/0$1/;
$mday =~ s/^(\d)$/0$1/;
if ($conf{time_format}) {
my $back = $conf{time_format};
if ($conf{timeformat}) {
my $back = $conf{timeformat};
$back =~ s/YYYY/$year/;
$back =~ s/YY/substr($year, 1, 2)/e;
$back =~ s/MM/$mon/;
@@ -1520,19 +1518,19 @@ sub display_tree {
$t = $res{$num}->{'date'};
# this allows us to have multiple topics (subtopics!)
my ($firstline,$text,$untext) = split /\n/, $n, 3;
if ($firstline =~ /^($conf{topicsep})/) {
$firstline =~ s/($conf{topicsep})*$//; #remove TopicSepatator
@nodes = split(/$conf{topicsep}/,$firstline);
if ($firstline =~ /^($conf{topicseparator})/) {
$firstline =~ s/($conf{topicseparator})*$//; #remove Topicseparator
@nodes = split(/$conf{topicseparator}/,$firstline);
}
else {
@nodes = (); #("$conf{topicsep}");
@nodes = (); #("$conf{topicseparator}");
$text = $firstline;
}
&tree($num, $text, \%TREE, @nodes);
}
#return if ($num == 0);
# now that we have build our tree (in %TREE) go on t display it:
print C $BORDERC . "\n[" . $conf{topicsep} . $BORDERC . "]\n";
print C $BORDERC . "\n[" . $conf{topicseparator} . $BORDERC . "]\n";
&print_tree(\%{$TREE{''}},"") if(%TREE);
print C $BORDERC . $_BORDERC . "\n";
}
@@ -1646,6 +1644,7 @@ sub load_driver {
if ($parent) {
my $pkg = "NOTEDB";
eval "use $pkg;";
if ($@) {
die "Could not load the NOTEDB module: $@\n";
}

View File

@@ -1,4 +1,4 @@
# note 1.3.0 -*- sh -*-
# note 1.3.1 -*- sh -*-
#
# This is a sample config for the note script
# There are useful defaults set in note itself.

View File

@@ -475,7 +475,7 @@ to encryption, I suggest you to follow the directions in the
file UPGRADE!
You can choose from different encryption algorythms. The default
is IDEA, but DES or BLOWFISH is also possible. You need to have
is IDEA, but DES or BLOWFISH are also possible. You need to have
installed the following additional perl-modules on your system:
MD5
Crypt::IDEA
@@ -523,6 +523,6 @@ Thomas Linden <tom@daemon.de>
=head1 VERSION
1.3.0 (11/01/2005)
1.3.1 (12/01/2005)
=cut