add man pages + add -n option to nobotgate-access

This commit is contained in:
kento2 2026-09-09 03:26:53 +02:00
parent 107ec67105
commit 26aa9c3b7e
4 changed files with 57 additions and 4 deletions

13
doc/nobotgate-access.1 Normal file
View file

@ -0,0 +1,13 @@
.TH nobotgate-access 3
.SH NAME
nobotgate-access \- respond with http
.SH SYNOPSIS
nobotgate-access [-c] PROG ARGS
.SH DESCRIPTION
nobotgate-access is meant to run under a superserver such
as tcpserver(1) or inetd(8). It reads http request headers
from stdin(unless \-n is given), prints http response
OK headers and finally exec's into PROG where the first
argument is set to PROG and the remaining to ARGS.
.SH "SEE ALSO"
nobotgate(1), tcpserver(1), inetd(8)

24
doc/nobotgate.1 Normal file
View file

@ -0,0 +1,24 @@
.TH nobotgate 3
.SH NAME
nobotgate \- block bots using http header authentication
.SH SYNOPSIS
nobotgate TOKENFILE VALID INVALID
.SH DESCRIPTION
nobotgate-access is meant to run under a superserver such
as tcpserver(1) or inetd(8).
It reads http request headers from stdin and tries find a
HTTP Bearer token. If no token is found or the token is not
listed in TOKENFILE, it exec's into INVALID.
If a token is found and the token is listed in
TOKENFILE, it exec's into VALID.
.SH "TOKENFILE FORMAT"
The tokenfile is parsed line by line. Empty lines are
ignored.
The token begins at line start and ends at the first space
in the line(the space is not part of the token of course).
.SH "EXAMPLE"
An example tokenfile:
1234 this is bob's token
abc223-23cm ci/cd token
.SH "SEE ALSO"
nobotgate-access(1), tcpserver(1), inetd(8)

View file

@ -26,3 +26,8 @@ executable('nobotgate', files(
executable('nobotgate-access', files( executable('nobotgate-access', files(
'./nobotgate-access.c', './nobotgate-access.c',
), dependencies:deps, install:true) ), dependencies:deps, install:true)
install_man([
'./doc/nobotgate.1',
'./doc/nobotgate-access.1',
])

View file

@ -3,7 +3,9 @@
#include <libowfat/str.h> #include <libowfat/str.h>
#include <unistd.h> #include <unistd.h>
#define dieusage() die(100, argv0, " PROG ARGS"); #define dieusage() die(100, argv0, " [-n] PROG ARGS");
static int consume=1;
static void consume_headers(void) { static void consume_headers(void) {
char buf[2048]; char buf[2048];
@ -19,12 +21,21 @@ static void consume_headers(void) {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char *header; char *header;
(void)argc; int i;
errmsg_iam(*argv); errmsg_iam(*argv);
for (i=1;i<argc;i++) {
if (argv[i][0]!='-') break;
if (argv[i][1]=='-' && !argv[i][2]) break;
switch (argv[i][1]) {
case 'n': consume=0; break;
default: dieusage();
}
}
argc-=i;argv+=i;
if (argc<2) dieusage(); if (argc<2) dieusage();
if (consume)
consume_headers(); consume_headers();
header = "HTTP/1.0 200 OK\r\n" header = "HTTP/1.0 200 OK\r\n"
"Connection: close\r\n" "Connection: close\r\n"