#!/usr/bin/perl # Copyright René Wagner 2020 # licenced under BSD 3-Clause licence # https://src.clttr.info/rwa/gmnifaq package gmnifaq; use strict; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(config footer write_response %CONF %RC); # automatically exported subs # enable UTF-8 mode for everything use utf8; binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; our %CONF = (); # define return codes our %RC = ( 'INPUT', 10, 'SENSITIVE_INPUT', 11, 'SUCCESS', 20, 'TEMPORARY_REDIRECT', 30, 'PERMANENT_REDIRECT', 31, 'TEMPORARY_FAILURE', 40, 'SERVER_UNAVAILABLE', 41, 'CGI_ERROR', 42, 'PROXY_ERROR', 43, 'SLOW_DOWN', 44, 'PERMANENT_FAILURE', 50, 'NOT_FOUND', 51, 'GONE', 52, 'PROXY_REQUEST_REFUSE', 53, 'BAD_REQUEST', 59, 'CLIENT_CERT_REQUIRED', 60, 'CERT_NOT_AUTHORISED', 61, 'CERT_NOT_VALID', 62 ); sub config { $CONF{'name'} = 'gmnifaq'; $CONF{'intro'} = 'Welcome to gmnifaq!'; if ( -f './gmnifaq.conf' ) { do './gmnifaq.conf'; } if ( !-f 'data/data.sqlite' ) { write_response('PERMANENT_FAILURE', 'Permanent failure', undef) }; $CONF{'dsn'} = "DBI:SQLite:dbname=data/data.sqlite"; } sub footer { return ('', '=> ./index.pl [home]', '=> https://src.clttr.info/rwa/gmnifaq powered by gmnifaq'); } sub write_response { my ($returncode, $meta, @content) = @_; defined($RC{$returncode}) or die "Unknown response code!"; printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta); foreach (@content) { print("$_\r\n"); } exit; } 1;