Browse Source

update

master
René Wagner 9 months ago
parent
commit
73d08ce8c4
  1. 21
      README.md
  2. 12
      index.pl
  3. 73
      server.pl

21
README.md

@ -4,26 +4,9 @@ This project contains cgi scripts for gemini servers like [gmnisrv](https://git.
[gemini](gemini://gemini.circumlunar.space) ([view via HTTP proxy](https://portal.mozz.us/gemini/gemini.circumlunar.space/)) is a newly created lightweight internet protocol for documents. Read more about gemini on [Drew DeVault's Blog](https://drewdevault.com/2020/11/01/What-is-Gemini-anyway.html).
# projects
## orrg
A self-hostable online rss/atom feed reader which renders arbitrary feeds as gemini pages.
-> [visit the repo](https://git.sr.ht/~rwa/orrg)
## gmnifaq
A self-hostable faq engine for gemini
-> [visit the repo](https://git.sr.ht/~rwa/gmnifaq)
## willgemini.support
There are often discussions on the [gemini mailinglist](https://lists.orbitalfox.eu/archives/gemini/) about features that someone thinks gemini is missing.
This capsule answers every question on when gemini will support a specific feature.
-> [visit the repo](https://git.sr.ht/~rwa/willgemini.support)
# What's this?
This repo contains the simple Perl scripts which show the basic functionality of CGI with gemini.
## requirements
- Perl 5.28 (or newer)
- some Perl modules (see README of the specific project for details)
- gemini server with cgi support

12
index.pl

@ -1,11 +1,12 @@
#!/usr/bin/perl
# Copyright René Wagner 2020
# licenced under BSD 3-Clause licence
# https://git.sr.ht/~rwa/gmni-perl-cgi
# https://src.clttr.info/rwa/gemini-perl-cgi
use strict;
# define return codes
# only to enhance readabilty for the coder
our %RC = (
'INPUT', 10,
'SENSITIVE_INPUT', 11,
@ -32,6 +33,7 @@ use utf8;
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
# check if we run in a gemini cgi env
if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {
write_response('CGI_ERROR', 'CGI execution error', undef);
}
@ -43,6 +45,7 @@ exit;
sub create_response
{
my @body;
# create a array and add all lines to it
push @body, '# gmni Perl CGI demo';
push @body, '';
push @body, 'Welcome to the gmni Perl CGI Demo! 🖒 ';
@ -51,12 +54,14 @@ sub create_response
push @body, '## more demos on this capsule';
push @body, '=> gemini://gmndemo.clttr.info/faq/ gmnifaq demo';
push @body, '=> gemini://gmndemo.clttr.info/orrg/ orrg demo';
push @body, '=> gemini://gmndemo.clttr.info/server.pl server stats';
push @body, '';
push @body, '=> https://sr.ht/~rwa/gmni-perl-cgi The source of this demos can be found on sourcehut';
push @body, '=> https://src.clttr.info/rwa/gemini-perl-cgi The source of this demos can be found on src.clttr.info';
push @body, '';
push @body, '## CGI query info';
push @body, '```';
# write all known environment variables to stdout
my @keys = qw/GATEWAY_INTERFACE SERVER_PROTOCOL SERVER_SOFTWARE GEMINI_URL SCRIPT_NAME PATH_INFO QUERY_STRING SERVER_NAME SERVER_PORT REMOTE_HOST TLS_CIPHER TLS_VERSION/;
foreach (@keys)
{
@ -64,8 +69,6 @@ sub create_response
}
push @body, '```';
push @body, '';
push @body, 'this server is '. `uptime -p`;
return @body;
}
@ -76,6 +79,7 @@ sub write_response
if (!defined($RC{$returncode})) { die "Unknown response code!"; }
# send return message and page content to stdout
print("$RC{$returncode} $mime\r\n");
foreach (@content)
{

73
server.pl

@ -0,0 +1,73 @@
#!/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;
}
Loading…
Cancel
Save