summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/BEGEMOT-MIB.txt59
-rw-r--r--doc/FOKUS-MIB.txt57
-rw-r--r--doc/Makefile.am15
-rw-r--r--doc/REGEX-MIB.txt94
-rw-r--r--doc/bsnmp-regex.8145
-rw-r--r--doc/bsnmp-regex.conf14
-rw-r--r--doc/bsnmp-regex.conf.5123
-rwxr-xr-xdoc/man2html.pl230
-rw-r--r--doc/sockin.187
9 files changed, 824 insertions, 0 deletions
diff --git a/doc/BEGEMOT-MIB.txt b/doc/BEGEMOT-MIB.txt
new file mode 100644
index 0000000..9d99eab
--- /dev/null
+++ b/doc/BEGEMOT-MIB.txt
@@ -0,0 +1,59 @@
+--
+-- Copyright (c) 2001-2003
+-- Fraunhofer Institute for Open Communication Systems (FhG Fokus).
+-- All rights reserved.
+--
+-- Author: Harti Brandt <harti@freebsd.org>
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+-- 1. Redistributions of source code must retain the above copyright
+-- notice, this list of conditions and the following disclaimer.
+-- 2. Redistributions in binary form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+-- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+-- SUCH DAMAGE.
+--
+-- $Begemot: bsnmp/snmpd/BEGEMOT-MIB.txt,v 1.5 2004/08/06 08:47:07 brandt Exp $
+--
+-- Begemot private definitions and root.
+--
+BEGEMOT-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY
+ FROM SNMPv2-SMI
+ fokus
+ FROM FOKUS-MIB;
+
+begemot MODULE-IDENTITY
+ LAST-UPDATED "200201300000Z"
+ ORGANIZATION "Fraunhofer FOKUS, CATS"
+ CONTACT-INFO
+ " Hartmut Brandt
+
+ Postal: Fraunhofer Institute for Open Communication Systems
+ Kaiserin-Augusta-Allee 31
+ 10589 Berlin
+ Germany
+
+ Fax: +49 30 3463 7352
+
+ E-mail: harti@freebsd.org"
+ DESCRIPTION
+ "The root of the Begemot subtree of the fokus tree."
+ ::= { fokus 1 }
+
+END
diff --git a/doc/FOKUS-MIB.txt b/doc/FOKUS-MIB.txt
new file mode 100644
index 0000000..d4671e8
--- /dev/null
+++ b/doc/FOKUS-MIB.txt
@@ -0,0 +1,57 @@
+--
+-- Copyright (c) 2001-2003
+-- Fraunhofer Institute for Open Communication Systems (FhG Fokus).
+-- All rights reserved.
+--
+-- Author: Harti Brandt <harti@freebsd.org>
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+-- 1. Redistributions of source code must retain the above copyright
+-- notice, this list of conditions and the following disclaimer.
+-- 2. Redistributions in binary form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+-- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+-- SUCH DAMAGE.
+--
+-- $Begemot: bsnmp/snmpd/FOKUS-MIB.txt,v 1.5 2004/08/06 08:47:08 brandt Exp $
+--
+-- Begemot private definitions and fokus root.
+--
+FOKUS-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY, enterprises
+ FROM SNMPv2-SMI;
+
+fokus MODULE-IDENTITY
+ LAST-UPDATED "200202050000Z"
+ ORGANIZATION "Fraunhofer FOKUS, CATS"
+ CONTACT-INFO
+ " Hartmut Brandt
+
+ Postal: Fraunhofer Institute for Open Communication Systems
+ Kaiserin-Augusta-Allee 31
+ 10589 Berlin
+ Germany
+
+ Fax: +49 30 3463 7352
+
+ E-mail: harti@freebsd.org"
+ DESCRIPTION
+ "The root of the Fokus enterprises tree."
+ ::= { enterprises 12325 }
+
+END
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..62dc4ff
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,15 @@
+
+man_MANS = bsnmp-regex.8 bsnmp-regex.conf.5 sockin.1
+
+# Simple way to make docs
+html:
+ perl man2html.pl bsnmp-regex.8 > bsnmp-regex.8.html
+ perl man2html.pl bsnmp-regex.conf.5 > bsnmp-regex.conf.5.html
+ perl man2html.pl sockin.1 > sockin.1.html
+
+EXTRA_DIST = $(man_MANS) \
+ man2html.pl \
+ BEGEMOT-MIB.txt \
+ FOKUS-MIB.txt \
+ REGEX-MIB.txt \
+ bsnmp-regex.conf
diff --git a/doc/REGEX-MIB.txt b/doc/REGEX-MIB.txt
new file mode 100644
index 0000000..3b89fdc
--- /dev/null
+++ b/doc/REGEX-MIB.txt
@@ -0,0 +1,94 @@
+--
+-- Copyright (c) 2006
+-- Nate Nielsen <nielsen@memberwebs.com>
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+-- 1. Redistributions of source code must retain the above copyright
+-- notice, this list of conditions and the following disclaimer.
+-- 2. Redistributions in binary form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+-- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+-- SUCH DAMAGE.
+--
+REGEX-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY, OBJECT-TYPE, Counter64, Integer32, TimeTicks, Unsigned32
+ FROM SNMPv2-SMI
+ begemot
+ FROM BEGEMOT-MIB;
+
+regexData MODULE-IDENTITY
+ LAST-UPDATED "200603290000Z"
+ ORGANIZATION "Nate Nielsen"
+ CONTACT-INFO "nielsen@memberwesb.com"
+ DESCRIPTION "The MIB for the bsnmp-regex."
+
+ ::= { begemot 203 }
+
+-- --------------------------------------------------------------------------
+
+regexCount OBJECT-TYPE
+ SYNTAX Integer32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION "Number of regexEntry objects."
+ ::= { regexData 0 }
+
+regexEntry OBJECT IDENTIFIER
+ ::= { regexData 1 }
+
+--
+-- entry information
+--
+
+regexIndex OBJECT-TYPE
+ SYNTAX Integer32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION "Index of this regexEntry object."
+ :: { regexEntry 1 }
+
+regexDescr OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION "Description of the regexEntry object."
+ :: { regexEntry 2 }
+
+regexLast OBJECT-TYPE
+ SYNTAX TimeTicks
+ UNITS "1/100th of a Second"
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION "Last time this the regexEntry counters were updated."
+ ::= { regexEntry 3 }
+
+regexInteger OBJECT-TYPE
+ SYNTAX Integer32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION "Integer value of this regexEntry object."
+ :: { regexEntry 4 }
+
+regexString OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION "String value of this regexEntry object."
+ :: { regexEntry 5 }
+
+END
diff --git a/doc/bsnmp-regex.8 b/doc/bsnmp-regex.8
new file mode 100644
index 0000000..7acf116
--- /dev/null
+++ b/doc/bsnmp-regex.8
@@ -0,0 +1,145 @@
+.\"
+.\" Copyright (c) 2006, Nate Nielsen
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" * Redistributions of source code must retain the above
+.\" copyright notice, this list of conditions and the
+.\" following disclaimer.
+.\" * Redistributions in binary form must reproduce the
+.\" above copyright notice, this list of conditions and
+.\" the following disclaimer in the documentation and/or
+.\" other materials provided with the distribution.
+.\" * The names of contributors to this software may not be
+.\" used to endorse or promote products derived from this
+.\" software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+.\" COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+.\" OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+.\" THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+.\" DAMAGE.
+.\"
+.\"
+.\" CONTRIBUTORS
+.\" Nate Nielsen <nielsen@memberwebs.com>
+.\"
+.Dd April, 2006
+.Dt bsnmp-regex 8
+.Os bsnmp-regex
+.Sh NAME
+.Nm bsnmp-regex
+.Nd an SNMP module which produces counters from logs or other text
+.Sh DESCRIPTION
+.Nm
+is a module for
+.Xr bsnmpd 1
+which allows you to make SNMP counters from log files or other text. For example
+you could count the number of occurances of a certain string in a text file. You
+can also match specific numbers or text to build SNMP values.
+.Pp
+.Nm
+has a configuration file which contains regular expressions for the text you'd
+like to match. See
+.Xr bsnmp-regex.conf 5
+for details on this file.
+.Pp
+.Nm
+opens a UNIX domain socket which text is piped into. The text is matched line
+by line against the regular expressions in the configuration file and the
+appropriate counter or value is updated. The
+.Xr sockin 1
+utility is useful for piping text into this socket.
+.Sh MIBS
+The counters will be available as a table under the following MIB:
+.Bd -literal -offset indent
+ .1.3.6.1.4.1.12325.1.203
+.Ed
+.Pp
+Or if the appropriate MIB.txt files have been installed:
+.Bd -literal -offset indent
+ enterprises.fokus.begemot.regexData
+.Ed
+.Pp
+The following SNMP MIBs are available for use (where X is the counter index):
+.Bl -tag -width Fl
+.It Ar regexData.regexCount.0
+The number of counters available.
+.It Ar regexData.regexEntry.regexIndex.X
+The index of the counter.
+.It Ar regexData.regexEntry.regexDescr.X
+The description of the counter.
+.It Ar regexData.regexEntry.regexLast.X
+How long ago the counter was last updated.
+.It Ar regexData.regexEntry.regexInteger.X
+The current counter value as a integer.
+.It Ar regexData.regexEntry.regexString.X
+The current counter value as a string.
+.El
+.Sh OPTIONS
+To activate the
+.Nm
+module you must load the module in
+.Pa /etc/snmpd.config
+and configure the location for the UNIX socket and
+.Xr bsnmp-regex.conf 5
+file. See the examples section below.
+.Bl -tag -width Fl
+.It Ar regexConfig
+The location of the
+.Xr bsnmp-regex.conf 5
+file. This option must be specified.
+.It Ar regexSocket
+The location of the UNIX socket on which this module will listen for logs
+or text to match.
+.El
+.Sh EXAMPLES
+For a simple
+.Nm
+configuration add the following to
+.Pa /etc/snmpd.config:
+.Bd -literal -offset indent
+begemotSnmpdModulePath."regex" = "/usr/local/lib/snmp_regex.so"
+%regex
+regexConfig = "/usr/local/etc/bsnmp-regex.conf"
+regexSocket = "/var/run/bsnmp-regex.sock"
+.Ed
+.Pp
+For details on what
+.Pa /usr/local/etc/bsnmp-regex.conf
+should contain, see the
+.Xr bsnmp-regex.conf 5
+man page.
+.Pp
+To pipe logs or text to match into the socket use the
+.Xr sockin 1
+utility, run something like this:
+.Bd -literal -offset indent
+# sockin /var/run/bsnmp-regex.sock tail -f /var/log/maillog
+.Ed
+.Pp
+To have
+.Xr syslogd 8
+send all logs for matching add a line like this to the
+.Pa /etc/syslog.conf
+file:
+.Bd -literal -offset indent
+*.* | sockin /var/run/bsnmp-regex.sock
+.Ed
+.Sh SEE ALSO
+.Xr bsnmp-regex.conf 5 ,
+.Xr bsnmpd 1 ,
+.Xr sockin 1 ,
+.Xr syslog.conf 5
+.Sh AUTHOR
+.An Nate Nielsen Aq nielsen@memberwebs.com
diff --git a/doc/bsnmp-regex.conf b/doc/bsnmp-regex.conf
new file mode 100644
index 0000000..22acac8
--- /dev/null
+++ b/doc/bsnmp-regex.conf
@@ -0,0 +1,14 @@
+# Sample bsnmp-regex file
+
+expire = 5
+
+# Complete list of all lines
+all: /.*/
+
+# Relayed messages
+relayed: /relay.* status=sent/
+
+expires = 3600
+
+# Last user who login in last hour
+lastuser: /sshd.* Accepted.* for ([^ ]+) from/\\1/
diff --git a/doc/bsnmp-regex.conf.5 b/doc/bsnmp-regex.conf.5
new file mode 100644
index 0000000..d2e9b84
--- /dev/null
+++ b/doc/bsnmp-regex.conf.5
@@ -0,0 +1,123 @@
+.\"
+.\" Copyright (c) 2006, Nate Nielsen
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" * Redistributions of source code must retain the above
+.\" copyright notice, this list of conditions and the
+.\" following disclaimer.
+.\" * Redistributions in binary form must reproduce the
+.\" above copyright notice, this list of conditions and
+.\" the following disclaimer in the documentation and/or
+.\" other materials provided with the distribution.
+.\" * The names of contributors to this software may not be
+.\" used to endorse or promote products derived from this
+.\" software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+.\" COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+.\" OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+.\" THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+.\" DAMAGE.
+.\"
+.\"
+.\" CONTRIBUTORS
+.\" Nate Nielsen <nielsen@memberwebs.com>
+.\"
+.Dd April, 2006
+.Dt bsnmp-regex.conf 5
+.Os bsnmp-regex
+.Sh NAME
+.Nm bsnmp-regex.conf
+.Nd the configuration file for the
+.Xr bsnmp-regex 8
+module.
+.Sh DESCRIPTION
+The
+.Xr bsnmp-regex
+SNMP module parses logs or other textual output and exposes the matched values
+as SNMP counters. The
+.Nm
+config file contains definitions for the counters you want, and what text to
+match to those counters.
+.Pp
+Blank lines and lines starting with a '#' sign are ignored.
+.Sh COUNTERS
+.Pp
+Two different kinds of counters are possible.
+.Ar Stat
+counters increment their value each time a match is made.
+.Ar Value
+counters contain the last matched value.
+.Pp
+A counter line constists of a name, a colon and a delimited regular expression:
+.Bd -literal -offset indent
+name: /match.*/
+.Ed
+.Pp
+The name is used as the
+.Ar regexDescr
+SNMP value.
+.Pp
+A
+.Ar stat
+counter looks like the example above, and simply increments the
+.Ar regexInteger
+SNMP value each time a match is made.
+.Pp
+A value counter has a second part to it's regular expression, similar to
+a 'sed replace':
+.Bd -literal -offset indent
+name: /([0-9]+) degrees/\\1/
+.Ed
+.Pp
+The backslash-numeral refers to the regular expression group. \\0 refers to
+the entire matched text. The resulting value is available in the
+.Ar regexString
+SNMP value. If the result is parseable as an integer, it is also available
+in the
+.Ar regexInteger
+SNMP value.
+.Sh OPTIONS
+The file can contain options which change the behavior of the counters
+below that point. An option line consists of a name, an equals
+sign, and the value:
+.Bd -literal -offset indent
+option = value
+.Ed
+.Pp
+An option applies to all match lines below that point in the file.
+.Bl -tag -width Fl
+.It Ar expires
+This option is the amount of time (in seconds) after which to expire a counter
+if no new values have come in. This is mostly useful for
+.Ar stat
+counters.
+.El
+.Sh EXAMPLES
+Given a maillog output, this would make a counter for the number of messages
+relayed:
+.Bd -literal -offset indent
+relayed: /relay.* status=sent/
+.Ed
+This would set the counter to the user the last user that logged into the
+system over the past hour:
+.Bd -literal -offset indent
+expires = 3600
+lastuser: /sshd.* Accepted.* for ([^ ]+) from/\\1/
+.Ed
+.Sh SEE ALSO
+.Xr bsnmp-regex 8
+.Xr re_format 7
+.Sh AUTHOR
+.An Nate Nielsen Aq nielsen@memberwebs.com
diff --git a/doc/man2html.pl b/doc/man2html.pl
new file mode 100755
index 0000000..21e3ab5
--- /dev/null
+++ b/doc/man2html.pl
@@ -0,0 +1,230 @@
+#!/usr/bin/perl
+
+# TODO: We need to make this more resilient
+# currently expects args without enforcing
+
+$FIL = $NAM = $SEC = @ARGV[0];
+
+$NAM =~ s/^([^.]+)\..+$/$1/;
+$SEC =~ s/^.+\.([^.]+)$/$1/;
+
+$command = "groff";
+@args = split(" ", "-Tascii -mdoc $FIL");
+
+$enable_include_links = 0;
+
+man($NAM, $SEC);
+
+sub man {
+ local($name, $section) = @_;
+ local($_, $title, $head, *MAN);
+ local($html_name, $html_section, $prefix);
+ local(@manargs);
+ local($query) = $name;
+
+ # $section =~ s/^([0-9ln]).*$/$1/;
+ $section =~ tr/A-Z/a-z/;
+
+ $prefix = "Man ";
+ if ($alttitle) {
+ $prefix = "";
+ $title = &encode_title($alttitle);
+ $head = &encode_data($alttitle);
+ } elsif ($section) {
+ $title = &encode_title("${name}($section)");
+ $head = &encode_data("${name}($section)");
+ } else {
+ $title = &encode_title("${name}");
+ $head = &encode_data("${name}");
+ }
+
+ print &html_header("$title");
+ print "<H1>Man Page: ${title}</H1>";
+ print "<PRE>\n";
+
+ $html_name = &encode_data($name);
+ $html_section = &encode_data($section);
+
+ #print Dumper($sectionpath);
+ #print "yy $section yy $manpath\n";
+ if ($name =~ /^\s*$/) {
+ print "Empty input, no man page given.\n";
+ return;
+ }
+
+ if (index($name, '*') != -1) {
+ print "Invalid character input '*': $name\n";
+ return;
+ }
+
+ if ($section !~ /^[0-9ln]\w*$/ && $section ne '') {
+ print "Sorry, section `$section' is not valid\n";
+ return;
+ }
+
+ if (!$section) {
+ if ($sectionpath->{$manpath}) {
+ $section = "-S " . $sectionpath->{$manpath}{'path'};
+ } else {
+ $section = '';
+ }
+ } else {
+ if ($sectionpath->{$manpath}{$section}) {
+ $section = "-S " . $sectionpath->{$manpath}{$section};
+ } else {
+ $section = "-S $section";
+ }
+ }
+
+ # print "X $command{'man'} @manargs -- x $name x\n";
+ &proc(*MAN, $command, @args) ||
+ &mydie ("$0: open of $command{'man'} command failed: $!\n");
+ if (eof(MAN)) {
+ # print "X $command{'man'} @manargs -- x $name x\n";
+ print "Sorry, no data found for `$html_name" .
+ ($html_section ? "($html_section)": '') . "'.\n";
+ return;
+ }
+
+ local($space) = 1;
+ local(@sect);
+ local($i, $j);
+ while(<MAN>) {
+ # remove tailing white space
+ if (/^\s+$/) {
+ next if $space;
+ $space = 1;
+ } else {
+ $space = 0;
+ }
+
+ $_ = &encode_data($_);
+ if($enable_include_links &&
+ m,(<B>)?\#include(</B>)?\s+(<B>)?\&lt\;(.*\.h)\&gt\;(</B>)?,) {
+ $match = $4; ($regexp = $match) =~ s/\./\\\./;
+ s,$regexp,\<A HREF=\"$BASE/usr/include/$match\"\>$match\</A\>,;
+ }
+ /^\s/ && # skip headers
+ s,((<[IB]>)?[\w\_\.\-]+\s*(</[IB]>)?\s*\(([1-9ln][a-zA-Z]*)\)),&mlnk($1),oige;
+
+ # detect E-Mail Addreses in manpages
+ if (/\@/) {
+ s/([a-z0-9_\-\.]+\@[a-z0-9\-\.]+\.[a-z]+)/<A HREF="mailto:$1">$1<\/A>/gi;
+ }
+
+ # detect URLs in manpages
+ if (m%tp://%) {
+ s,((ftp|http)://[^\s<>\)]+),<A HREF="$1">$1</A>,gi;
+ }
+
+ if (/^<B>\S+/ && m%^<B>([^<]+)%) {
+ $i = $1; $j = &encode_url($i);
+ s%^<B>([^<]+)</B>%<B>$i</B>%;
+ push(@sect, $1);
+ }
+ print;
+ }
+ close(MAN);
+
+ print "<H6>Copyright, N. Nielsen&nbsp;&nbsp;&nbsp;[ <a href='./'>back</a> | <a href='../../'>home</a> ]</h6>";
+ print "</BODY>\n";
+ print "</HTML>\n";
+
+ # Sleep 0.35 seconds to avoid DoS attacs
+ select undef, undef, undef, 0.35;
+}
+
+# encode unknown data for use in <TITLE>...</TITILE>
+sub encode_title {
+ # like encode_url but less strict (I couldn't find docs on this)
+ local($_) = @_;
+ s/([\000-\031\%\&\<\>\177-\377])/sprintf('%%%02x',ord($1))/eg;
+ $_;
+}
+
+# encode unknown data for use in a URL <A HREF="...">
+sub encode_url {
+ local($_) = @_;
+ # rfc1738 says that ";"|"/"|"?"|":"|"@"|"&"|"=" may be reserved.
+ # And % is the escape character so we escape it along with
+ # single-quote('), double-quote("), grave accent(`), less than(<),
+ # greater than(>), and non-US-ASCII characters (binary data),
+ # and white space. Whew.
+ s/([\000-\032\;\/\?\:\@\&\=\%\'\"\`\<\>\177-\377 ])/sprintf('%%%02x',ord($1))/eg;
+ s/%20/+/g;
+ $_;
+}
+# encode unknown data for use inside markup attributes <MARKUP ATTR="...">
+sub encode_attribute {
+ # rfc1738 says to use entity references here
+ local($_) = @_;
+ s/([\000-\031\"\'\`\%\&\<\>\177-\377])/sprintf('\&#%03d;',ord($1))/eg;
+ $_;
+}
+# encode unknown text data for using as HTML,
+# treats ^H as overstrike ala nroff.
+sub encode_data {
+ local($_) = @_;
+ local($str);
+
+ # Escape &, < and >
+ s,\010[><&],,g;
+ s/\&/\&amp\;/g;
+ s/\</\&lt\;/g;
+ s/\>/\&gt\;/g;
+
+ s,((_\010.)+),($str = $1) =~ s/.\010//g; "<I>$str</I>";,ge;
+ s,(.\010)+,$1,g;
+
+ if (!s,((.\010.)+\s+(.\010.)+),($str = $1) =~ s/.\010//g; "<B>$str</B>";,ge) {
+ s,((.\010.)+),($str = $1) =~ s/.\010//g; "<B>$str</B>";,ge;
+ }
+
+ s,.\010,,g;
+
+ $_;
+}
+
+sub html_header {
+ return qq{<HTML>
+<HEAD>
+<TITLE>$_[0]</TITLE>
+<link rev="made" href="mailto:wosch\@FreeBSD.ORG">
+<META name="robots" content="nofollow">
+<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
+<link rel="stylesheet" type="text/css" href="/nielsen/style.css">
+</HEAD>
+<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n\n};
+}
+
+sub mlnk {
+ local($matched) = @_;
+ return qq{<U>$matched</U>};
+}
+
+sub proc {
+ local(*FH, $prog, @args) = @_;
+ local($pid) = open(FH, "-|");
+ return undef unless defined($pid);
+ if ($pid == 0) {
+ exec $prog, @args;
+ &mydie("exec $prog failed\n");
+ }
+ 1;
+}
+
+# CGI script must die with error status 0
+sub mydie {
+ local($message) = @_;
+ print &html_header("Error");
+ print $message;
+
+print qq{
+<p>
+<A HREF="$BASE">Index Page and Help</A>
+</BODY>
+</HTML>
+};
+
+ exit(0);
+}
diff --git a/doc/sockin.1 b/doc/sockin.1
new file mode 100644
index 0000000..b791648
--- /dev/null
+++ b/doc/sockin.1
@@ -0,0 +1,87 @@
+.\"
+.\" Copyright (c) 2006, Nate Nielsen
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" * Redistributions of source code must retain the above
+.\" copyright notice, this list of conditions and the
+.\" following disclaimer.
+.\" * Redistributions in binary form must reproduce the
+.\" above copyright notice, this list of conditions and
+.\" the following disclaimer in the documentation and/or
+.\" other materials provided with the distribution.
+.\" * The names of contributors to this software may not be
+.\" used to endorse or promote products derived from this
+.\" software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+.\" COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+.\" OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+.\" THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+.\" DAMAGE.
+.\"
+.\"
+.\" CONTRIBUTORS
+.\" Nate Nielsen <nielsen@memberwebs.com>
+.\"
+.Dd April, 2006
+.Dt sockin 1
+.Os bsnmp-regex
+.Sh NAME
+.Nm sockin
+.Nd a utility for piping textual program output into a UNIX domain socket.
+.Sh SYNOPSIS
+.Nm
+.Op Fl t Ar timeout
+.Ar socket
+.Nm
+.Op Fl d
+.Op Fl t Ar timeout
+.Ar socket
+.Ar command
+.Ar arg ...
+.Sh DESCRIPTION
+When executed without a
+.Ar command
+argument
+.Nm
+accepts text on stdin and writes it to
+.Ar socket
+which must be a UNIX domain socket.
+.Pp
+In the second form,
+.Ar command
+specifies a command to execute for which it's input and output will be
+redirected to
+.Ar socket
+.Pp
+.Sh OPTIONS
+.Nm
+accepts the following options.
+.Bl -tag -width Fl
+.It Fl d
+When executing a
+.Ar command
+this option makes the command become a daemon after redirecting it's output
+to the
+.Ar socket
+.It Fl t Ar timeout
+The
+.Ar timeout
+in seconds to wait for the socket to be ready before giving up. The default
+is to give up immediately on failure.
+.El
+.Sh SEE ALSO
+.Xr bsnmp-regex 8
+.Sh AUTHOR
+.An Nate Nielsen Aq nielsen@memberwebs.com