# HG changeset patch # User heiko # Date 1124323729 0 # Node ID e05dded1b622f5b761f8186df1e335e52f77c7ad Public :) diff -r 000000000000 -r e05dded1b622 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,24 @@ +prefix = /usr/local +bindir = $(prefix)/bin +sysconfdir = /etc/logbuch + +bin_SCRIPTS = log + + +all: $(bin_SCRIPTS) + +install: all + install -d $(DESTDIR)/$(sysconfdir) + test -f $(DESTDIR)/$(sysconfdir)/config.pm \ + || install -m644 config.pm $(DESTDIR)/$(sysconfdir)/config.pm + install -d $(bindir) + install -m755 $(bin_SCRIPTS) $(DESTDIR)/$(bindir)/ + cd $(DESTDIR)/$(bindir) && ln -sf log logbuch + +clean: + -rm -f $(bin_SCRIPTS) + +%: %.pl + perl -c $< + cp -f $< $@ + chmod -w+x $@ diff -r 000000000000 -r e05dded1b622 config.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.pm Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,2 @@ +package config; +@mailto = qw(root@localhost); diff -r 000000000000 -r e05dded1b622 debian/README.Debian --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/README.Debian Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,6 @@ +logbuch for Debian +------------------ + + + + -- Heiko Schlittermann , Fri, 4 Apr 2003 10:03:49 +0200 diff -r 000000000000 -r e05dded1b622 debian/changelog --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/changelog Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,86 @@ +logbuch (0.15-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Wed, 01 Jun 2005 16:50:31 +0200 + +logbuch (0.14-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Wed, 01 Jun 2005 16:50:31 +0200 + +logbuch (0.13-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Wed, 01 Jun 2005 16:50:31 +0200 + +logbuch (0.12-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Wed, 14 Jan 2004 10:08:15 +0100 + +logbuch (0.10-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Wed, 16 Apr 2003 09:32:10 +0200 +logbuch (0.9-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Tue, 8 Apr 2003 15:43:11 +0200 + +logbuch (0.8-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Tue, 8 Apr 2003 12:41:27 +0200 +logbuch (0.7-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Tue, 8 Apr 2003 12:41:27 +0200 + +logbuch (0.6-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Tue, 8 Apr 2003 12:40:27 +0200 + +logbuch (0.5-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Tue, 8 Apr 2003 09:49:27 +0200 + +logbuch (0.4-2) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Tue, 8 Apr 2003 00:31:27 +0200 + +logbuch (0.3-2) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Fri, 4 Apr 2003 17:58:52 +0200 +logbuch (0.2-2) unstable; urgency=low + + * depends on dbi, dbd + + -- Heiko Schlittermann Fri, 4 Apr 2003 17:26:53 +0200 + +logbuch (0.2-1) unstable; urgency=low + + * new upstream + + -- Heiko Schlittermann Fri, 4 Apr 2003 11:39:43 +0200 +logbuch (0.1-1) unstable; urgency=low + + * Initial Release. + + -- Heiko Schlittermann Fri, 4 Apr 2003 10:03:49 +0200 + diff -r 000000000000 -r e05dded1b622 debian/conffiles --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/conffiles Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,1 @@ +/etc/logbuch/config.pm diff -r 000000000000 -r e05dded1b622 debian/conffiles.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/conffiles.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,7 @@ +# +# If you want to use this conffile, remove all comments and put files that +# you want dpkg to process here using their absolute pathnames. +# See the policy manual +# +# for example: +# /etc/logbuch/logbuch.conf diff -r 000000000000 -r e05dded1b622 debian/control --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/control Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,13 @@ +Source: logbuch +Section: unknown +Priority: optional +Maintainer: Heiko Schlittermann +Build-Depends: debhelper (>> 3.0.0) +Standards-Version: 3.5.2 + +Package: logbuch +Architecture: any +Depends: ${perl:Depends}, libdbi-perl, libdbd-mysql-perl, + libmailtools-perl +Description: Logbuch for server maintainance + A simple script for tracking server changes in a logfile diff -r 000000000000 -r e05dded1b622 debian/copyright --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/copyright Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,10 @@ +This package was debianized by Heiko Schlittermann on +Fri, 4 Apr 2003 10:03:49 +0200. + +It was downloaded from + +Upstream Author(s): + +Copyright: + + diff -r 000000000000 -r e05dded1b622 debian/cron.d.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/cron.d.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,4 @@ +# +# Regular cron jobs for the logbuch package +# +0 4 * * * root logbuch_maintenance diff -r 000000000000 -r e05dded1b622 debian/dirs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/dirs Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff -r 000000000000 -r e05dded1b622 debian/docs diff -r 000000000000 -r e05dded1b622 debian/ex.package.doc-base --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/ex.package.doc-base Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,22 @@ +Document: logbuch +Title: Debian logbuch Manual +Author: +Abstract: This manual describes what logbuch is + and how it can be used to + manage online manuals on Debian systems. +Section: unknown + +Format: debiandoc-sgml +Files: /usr/share/doc/logbuch/logbuch.sgml.gz + +Format: postscript +Files: /usr/share/doc/logbuch/logbuch.ps.gz + +Format: text +Files: /usr/share/doc/logbuch/logbuch.text.gz + +Format: HTML +Index: /usr/share/doc/logbuch/html/index.html +Files: /usr/share/doc/logbuch/html/*.html + + diff -r 000000000000 -r e05dded1b622 debian/init.d.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/init.d.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,70 @@ +#! /bin/sh +# +# skeleton example file to build /etc/init.d/ scripts. +# This file should be used to construct scripts for /etc/init.d. +# +# Written by Miquel van Smoorenburg . +# Modified for Debian GNU/Linux +# by Ian Murdock . +# +# Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl +# +# This file was automatically customized by dh-make on Fri, 4 Apr 2003 10:03:49 +0200 + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/sbin/logbuch +NAME=logbuch +DESC=logbuch + +test -f $DAEMON || exit 0 + +set -e + +case "$1" in + start) + echo -n "Starting $DESC: " + start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ + --exec $DAEMON + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \ + --exec $DAEMON + echo "$NAME." + ;; + #reload) + # + # If the daemon can reload its config files on the fly + # for example by sending it SIGHUP, do it here. + # + # If the daemon responds to changes in its config file + # directly anyway, make this a do-nothing entry. + # + # echo "Reloading $DESC configuration files." + # start-stop-daemon --stop --signal 1 --quiet --pidfile \ + # /var/run/$NAME.pid --exec $DAEMON + #;; + restart|force-reload) + # + # If the "reload" option is implemented, move the "force-reload" + # option to the "reload" entry above. If not, "force-reload" is + # just the same as "restart". + # + echo -n "Restarting $DESC: " + start-stop-daemon --stop --quiet --pidfile \ + /var/run/$NAME.pid --exec $DAEMON + sleep 1 + start-stop-daemon --start --quiet --pidfile \ + /var/run/$NAME.pid --exec $DAEMON + echo "$NAME." + ;; + *) + N=/etc/init.d/$NAME + # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 1 + ;; +esac + +exit 0 diff -r 000000000000 -r e05dded1b622 debian/manpage.1.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/manpage.1.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,60 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH LOGBUCH SECTION "April 4, 2003" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +logbuch \- program to do something +.SH SYNOPSIS +.B logbuch +.RI [ options ] " files" ... +.br +.B bar +.RI [ options ] " files" ... +.SH DESCRIPTION +This manual page documents briefly the +.B logbuch +and +.B bar +commands. +This manual page was written for the Debian distribution +because the original program does not have a manual page. +Instead, it has documentation in the GNU Info format; see below. +.PP +.\" TeX users may be more comfortable with the \fB\fP and +.\" \fI\fP escape sequences to invode bold face and italics, +.\" respectively. +\fBlogbuch\fP is a program that... +.SH OPTIONS +These programs follow the usual GNU command line syntax, with long +options starting with two dashes (`-'). +A summary of options is included below. +For a complete description, see the Info files. +.TP +.B \-h, \-\-help +Show summary of options. +.TP +.B \-v, \-\-version +Show version of program. +.SH SEE ALSO +.BR bar (1), +.BR baz (1). +.br +The programs are documented fully by +.IR "The Rise and Fall of a Fooish Bar" , +available via the Info system. +.SH AUTHOR +This manual page was written by Heiko Schlittermann , +for the Debian GNU/Linux system (but may be used by others). diff -r 000000000000 -r e05dded1b622 debian/manpage.sgml.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/manpage.sgml.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,152 @@ + manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + + FIRSTNAME"> + SURNAME"> + + April 4, 2003"> + + SECTION"> + heiko@schlittermann.de"> + + LOGBUCH"> + + + Debian"> + GNU"> +]> + + + +
+ &dhemail; +
+ + &dhfirstname; + &dhsurname; + + + 2001 + &dhusername; + + &dhdate; +
+ + &dhucpackage; + + &dhsection; + + + &dhpackage; + + program to do something + + + + &dhpackage; + + + + + + + + DESCRIPTION + + This manual page documents briefly the + &dhpackage; and bar + commands. + + This manual page was written for the &debian; distribution + because the original program does not have a manual page. + Instead, it has documentation in the &gnu; + Info format; see below. + + &dhpackage; is a program that... + + + + OPTIONS + + These programs follow the usual GNU command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. For a complete description, see the + Info files. + + + + + + + + Show summary of options. + + + + + + + + Show version of program. + + + + + + SEE ALSO + + bar (1), baz (1). + + The programs are documented fully by The Rise and + Fall of a Fooish Bar available via the + Info system. + + + AUTHOR + + This manual page was written by &dhusername; &dhemail; for + the &debian; system (but may be used by others). Permission is + granted to copy, distribute and/or modify this document under + the terms of the GNU Free Documentation + License, Version 1.1 or any later version published by the Free + Software Foundation; with no Invariant Sections, no Front-Cover + Texts and no Back-Cover Texts. + + +
+ + + + diff -r 000000000000 -r e05dded1b622 debian/menu.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/menu.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,2 @@ +?package(logbuch):needs=X11|text|vc|wm section=Apps/see-menu-manual\ + title="logbuch" command="/usr/bin/logbuch" diff -r 000000000000 -r e05dded1b622 debian/postinst.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/postinst.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,48 @@ +#! /bin/sh +# postinst script for logbuch +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package +# +# quoting from the policy: +# Any necessary prompting should almost always be confined to the +# post-installation script, and should be protected with a conditional +# so that unnecessary prompting doesn't happen if a package's +# installation fails and the `postinst' is called with `abort-upgrade', +# `abort-remove' or `abort-deconfigure'. + +case "$1" in + configure) + + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 + + diff -r 000000000000 -r e05dded1b622 debian/postrm.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/postrm.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,38 @@ +#! /bin/sh +# postrm script for logbuch +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' overwrit>r> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + + + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff -r 000000000000 -r e05dded1b622 debian/preinst.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/preinst.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,44 @@ +#! /bin/sh +# preinst script for logbuch +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) +# if [ "$1" = "upgrade" ] +# then +# start-stop-daemon --stop --quiet --oknodo \ +# --pidfile /var/run/logbuch.pid \ +# --exec /usr/sbin/logbuch 2>/dev/null || true +# fi + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 + + diff -r 000000000000 -r e05dded1b622 debian/prerm.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/prerm.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,39 @@ +#! /bin/sh +# prerm script for logbuch +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `upgrade' +# * `failed-upgrade' +# * `remove' `in-favour' +# * `deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + remove|upgrade|deconfigure) +# install-info --quiet --remove /usr/info/logbuch.info.gz + ;; + failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 + + diff -r 000000000000 -r e05dded1b622 debian/rules --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/rules Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,94 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 to 1999 by Joey Hess. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This is the debhelper compatibility version to use. +export DH_COMPAT=3 + + + +ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) + CFLAGS += -g +endif +ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) + INSTALL_PROGRAM += -s +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) prefix=/usr + #/usr/bin/docbook-to-man debian/logbuch.sgml > logbuch.1 + + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/logbuch. + $(MAKE) install DESTDIR=debian/logbuch prefix=/usr + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot +# dh_installdebconf + dh_installdocs +# dh_installexamples +# dh_installmenu +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_installinit +# dh_installcron +# dh_installman +# dh_installinfo +# dh_undocumented + dh_installchangelogs +# dh_link +# dh_strip +# dh_compress +# dh_fixperms +# dh_makeshlibs + dh_installdeb + dh_perl +# dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff -r 000000000000 -r e05dded1b622 debian/watch.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/watch.ex Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,5 @@ +# Example watch control file for uscan +# Rename this file to "watch" and then you can run the "uscan" command +# to check for upstream updates and more. +# Site Directory Pattern Version Script +sunsite.unc.edu /pub/Linux/Incoming logbuch-(.*)\.tar\.gz debian uupdate diff -r 000000000000 -r e05dded1b622 log.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/log.pl Thu Aug 18 00:08:49 2005 +0000 @@ -0,0 +1,198 @@ +#! /usr/bin/perl +# $Id$ +# $URL$ +my $USAGE = <<'#'; +$ME [options] + --[no]db insert into log database [$opt_db] + --[no]mail send mails to @config::mailto [$opt_mail] + --message=s message +# + +use strict; +use warnings; +use File::Basename; +use File::Temp qw(tempfile); +use File::stat; +use Getopt::Long; +use Mail::Mailer; +use DBI; + +use lib "/etc/logbuch"; +use config; + +# print @config::mailto, "\n"; + +#+-------+---------------+------+-----+---------+----------------+ +#| Field | Type | Null | Key | Default | Extra | +#+-------+---------------+------+-----+---------+----------------+ +#| id | int(11) | | MUL | NULL | auto_increment | +#| host | varchar(255) | YES | | NULL | | +#| date | datetime | YES | | NULL | | +#| user | varchar(255) | YES | | NULL | | +#| mailto| varchar(255) | YES | | NULL | | +#| text | text | YES | MUL | NULL | | +#| stamp | timestamp(14) | YES | | NULL | | +#+-------+---------------+------+-----+---------+----------------+ + +my $ME = basename $0; + +my $DSN = "DBI:mysql:logbuch:pu.schlittermann.de"; +my $USER = "logbuch"; +my $PW = "HIDDEN"; + +my $LOG = "$ENV{HOME}/LOG"; +my $EDITOR = $ENV{VISUAL} || $ENV{EDITOR} || "vim"; +my $MAGIC = "#--- all changes below are ignored ---#\n"; + +my $opt_db = 1; +my $opt_mail = 1; +my $opt_message = ""; + + + +my $Dbh; + +sub identity(); +sub hostname(); +sub mailto(); + +MAIN: { + + GetOptions("db!" => \$opt_db, + "mail!" => \$opt_mail, + "message=s" => \$opt_message) + or die eval "\"$USAGE\""; + + if ($opt_message =~ /^\.?\// and -f $opt_message) { + @ARGV = ($opt_message); + $opt_message = join "", <>; + } elsif ($opt_message eq "-") { + $opt_message = join "", ; + } + + if ($opt_message =~ /\n/) { + $opt_message =~ s/\n/\n /g; + } + + if ($opt_db) { + $Dbh = DBI->connect($DSN, $USER, $PW, {RaiseError => 1}) + or die $DBI::errstr; + END { $Dbh->disconnect() if $Dbh; } + } + + # Temporärfile öffnen + my ($fh, $file); + END { unlink $file if $file; } + ($fh, $file) = tempfile(DIR => "/tmp"); + + # Kopftext eintragen + print $fh + "Date: ", scalar(localtime()), "\n", + "User: ", identity(), "\n", + "MailTo: ", mailto(), "\n", + "\n", + " * $opt_message", + "\n", + "\n", $MAGIC, "\n"; + + if (!-e $LOG) { + open(X, $_ = ">>$LOG") or die "Can't open $_: $!\n"; + close X; + }; + + open(IN, $_ = $LOG) or die "Can't open $_: $!\n"; + print $fh ; + close IN; + + if (!$opt_message) { + my $stamp = stat($file)->mtime(); + system($EDITOR, "+5", $file); + + if ($stamp == stat($file)->mtime()) { + print STDERR "Nothing changed. Discarding the note.\n"; + unlink $file; + exit 0; + } + } + + # Jetzt wie versprochen den (eventuell geänderten Rest) aus der + # Temp-Datei wegschneiden + { + my ($date, $user, $head, $text, $mailto); + my $pos; + + seek $fh, 0, 0; + for($pos = tell $fh; defined($_ = <$fh>); $pos = tell $fh) { + + $head .= "$_" if not $text and /^\S+:/; + + /^Date:\s+(.*)/ and $date = $1, next; + /^User:\s+(.*)/ and $user = $1, next; + /^MailTo:\s(.*)/ and $mailto = $1, next; + last if $_ eq $MAGIC; + + $text .= $_ if /\S/ || $text; # somit werden die ersten Leerzeilen übersprungen + } + + $text =~ s/\s*$//s; # Leerzeichen am Ende weg + + truncate $fh, $pos; + seek $fh, 0, 2; + + if ($opt_db) { + my $sth = $Dbh->prepare(" + INSERT INTO log (host, date, user, mailto, text) + VALUES(?, now(), ?, ?, ?)"); + $sth->execute(hostname(), $user, $mailto, $text); + print STDERR "Database entry inserted\n"; + } + + if ($opt_mail and $mailto) { + my $mailer = new Mail::Mailer "sendmail" + or die "Can't create Mailer: $!\n"; + + my $subject = (split /\n/, $text)[0]; + $subject =~ s/^\s*\S\s//; + $subject = "Service [". hostname(). "]: $subject"; + + $mailer->open({ + "To" => $mailto, + "Subject" => $subject}); + print $mailer $head, "\n", $text; + close $mailer; + print STDERR "Mail sent (to $mailto).\n"; + } + } + + # Und jetzt das aus der alten Datei dort anhängen + open(IN, $_ = $LOG) or die "Can't open $_: $!\n"; + print $fh ; + close $fh; + close IN; + + rename $file, $LOG; + +} + +sub identity() +{ + my $user = `who am i`; + chomp $user; + $user .= " [" . ($ENV{REMOTE_USER} || "-") . "]"; + return $user; +} + +sub hostname() +{ + my $r = `hostname -f`; + chomp($r); + return $r; +} + +sub mailto() +{ + return join(", ", @config::mailto); +} + +# vim:sts=4 sw=4 aw ai sm: +