You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

#!/usr/bin/perl
# Copyright René Wagner 2020
# licenced under BSD 3-Clause licence
# https://git.sr.ht/~rwa/gmni-perl-cgi
use strict;
# 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
);
# enable UTF-8 mode for everything
use utf8;
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {
write_response('CGI_ERROR', 'CGI execution error', undef);
}
write_response('SUCCESS', 'text/gemini', create_response());
exit;
sub create_response
{
my @body;
push @body, '# gmni Perl CGI demo';
push @body, '';
push @body, 'Welcome to the gmni Perl CGI Demo! 🖒 ';
push @body, '';
push @body, 'server stats:';
push @body, '```';
push @body, `uptime`;
push @body, `free -th`;
push @body, '```';
push @body, ('', '=> index.pl [home]');
return @body;
}
sub write_response
{
my ($returncode, $mime, @content) = @_;
if (!defined($RC{$returncode})) { die "Unknown response code!"; }
print("$RC{$returncode} $mime\r\n");
foreach (@content)
{
print("$_\r\n");
}
exit;
}