This commit is contained in:
Chad C. Starz 2025-08-17 09:34:05 +00:00
commit bb90c030df
No known key found for this signature in database
GPG Key ID: 9489B46C65132B52
3 changed files with 77 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.db
git/*
!git/.gitkeep

0
git/.gitkeep Normal file
View File

74
gorillanest Executable file
View File

@ -0,0 +1,74 @@
#!/usr/bin/env perl
use strict;
use warnings;
use CGI;
use FCGI;
use Switch::Back;
use Syntax::Keyword::Try;
use Sys::Syslog;
use Template;
use URI::Escape;
use DBI;
sub info {
syslog("info", join(' ', @_));
}
sub GN::index { # /
}
sub GN::user { # /$username/
}
sub GN::repository { # /$username/(.*?(\.git)?)
}
sub GN::cache { # cache{'/some/path'}
}
openlog("gorillanest", "ndelay,pid", Sys::Syslog::LOG_DAEMON);
try {
my $gitroot = 'git';
my $dbfile = 'gorillanest.db';
#
my $request = FCGI::Request();
my $template = Template->new({INCLUDE_PATH => 'template'});
my $db = DBI->connect("dbi:SQLite:dbname=$dbfile","","", {
RaiseError => 1,
AutoCommit => 1,
sqlite_see_if_its_a_number => 1,
}) or die $DBI::errstr;
$db->do("CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL CHECK(length(name) <= 32), pass TEXT NOT NULL CHECK(length(pass) <= 128 AND length(pass) >= 32))");
$db->disconnect;
#
my $head = 0;
while($request->Accept() >= 0) {
my $cgi = CGI->new;
my %header = (
-Content_Type => 'text/plain',
-charset => 'UTF-8',
);
my $method = $ENV{'REQUEST_METHOD'} || '';
my $uri = $ENV{'REQUEST_URI'} // '/';
if ($method eq 'HEAD') {
$head = 1;
} elsif ($method eq 'GET') {
print $cgi->header(%header);
if ($head) { $head = 0; continue; }
if ($uri eq '/') {
GN::index($gitroot);
} # elsif ($uri ~= m__)
} else {
$header{-status} = '405 Method Not Allowed';
print $cgi->header(%header);
}
}
} catch ($error) {
info("Crashed: $error");
}