💾 Archived View for gmn.clttr.info › sources › gmnifaq.git › tree › index.pl.txt captured on 2024-05-10 at 10:58:49.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

#!/usr/bin/perl
# Copyright René Wagner 2020
# licenced under BSD 3-Clause licence
# https://src.clttr.info/rwa/gmnifaq

use strict;
use DBI;
use lib 'lib/';
use gmnifaq;

# enable UTF-8 mode for everything	
use utf8;
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';

config();

if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {
	write_response('CGI_ERROR', 'CGI execution error', undef);
}

if ($ENV{'QUERY_STRING'} ne '' || $ENV{'PATH_INFO'} ne '') {
	write_response('NOT_FOUND', 'File not found', undef);
}

my @body = ();
push @body, header();
push @body, body();
push @body, footer();

write_response('SUCCESS', 'text/gemini', @body);

exit;

sub body
{
	return ('## Meta', '', '=> ./search.pl search', '=> ./tags.pl browse tags', '=> ./faqs.pl view all', '');
}

sub header
{
	my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr;

	my $tagcount = $dbh->selectrow_array("SELECT count(id) from tags");
	my $faqcount = $dbh->selectrow_array("SELECT count(id) from questions");
	$dbh->disconnect();

	return ('# '. $CONF{'name'}, '', $CONF{'intro'}, '', sprintf('We are currently serving %d FAQs categorized with %d tags!', $faqcount, $tagcount), '');
}