From: anon Date: Wed, 20 Aug 2025 21:17:32 +0000 (+0200) Subject: dont waste my time X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;h=44b0e7d9a131f203e1d103af21d240f346b9a418;p=gorillanest.git dont waste my time --- diff --git a/gorillanest b/gorillanest deleted file mode 100755 index b361068..0000000 --- a/gorillanest +++ /dev/null @@ -1,115 +0,0 @@ -#!/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 Cwd; - -use Data::Dumper; -sub info { - syslog("info", join(' ', @_)); -} - -# significant dirs only -sub GN::directories { - my $root = $_[0]; - opendir my $dir, $root or die "Cannot open directory: $!"; - my @directories; - my %drop = ( - '.' => 0, - '..' => 0, - ); - foreach (readdir $dir) { - push(@directories, $_) if (-d join('/', $_[0], $_) && ($drop{$_} // 1)); - } - closedir $dir; - return \@directories; -} - -# probably should output all repos recursively, currently just outputs list of users -sub GN::index { # / - my ($root, $dataref) = @_; - my %data = %$dataref; - my @directories = map { my $i = $_; map { join('/', $i, $_) } @{GN::directories(join('/', $root, $i))} } @{GN::directories($root)}; - $data{directories} = \@directories; - if ($data{directories}) { $data{found} = 1; } - return \%data; -} - -sub GN::user { # /$username/ - my ($root, $dataref) = @_; - my %data = %$dataref; - my @directories = @{GN::directories(join('/', $root, $data{username}))}; - $data{directories} = \@directories; - if ($data{directories}) { $data{found} = 1; } - return \%data; -} - -sub GN::repository { # /$username/$repository - my ($root, $dataref) = @_; - my %data = %$dataref; - my $d = getcwd(); - chdir(join('/', $root, $data{username}, $data{repository})); - warn 'sneed ' . getcwd() . "\n"; - $data{log} = Dumper(split(/\n/, qx(git log --pretty=format:\'%H | %an | %ad | %s%x0a\'))); # It technically works # | tac | tr -s \'\n\' - chdir($d); - $data{found} = 1; - return \%data; -} - -openlog("gorillanest", "ndelay,pid", Sys::Syslog::LOG_DAEMON); -try { - my $public = 'git/public'; - my $dbfile = 'gorillanest.sqlite3'; - my %data = ( - found => 0, - ); - my $request = FCGI::Request(); - my $template = Template->new({INCLUDE_PATH => 'template'}); - my $head = 0; - my $a_template; - while($request->Accept() >= 0) { - my $cgi = CGI->new; - my %header = ( - -Content_Type => 'text/html', - -charset => 'UTF-8', - ); - my $method = $ENV{'REQUEST_METHOD'} || ''; - my $uri = $ENV{'REQUEST_URI'} || '/'; - if ($method eq 'HEAD') { - $head = 1; - } elsif ($method eq 'GET') { - ($data{username}, $data{repository}) = $uri =~ m{^/([a-zA-Z0-9_.]+)(?:/([a-zA-Z0-9_.]+))?}; - info("name:", $data{username} || '', "repo:", $data{repository} || ''); - if ($uri eq '/') { - %data = %{GN::index($public, \%data)}; - $a_template = "index.tt"; - } elsif ($data{repository}) { - %data = %{GN::repository($public, \%data)}; - $a_template = "repository.tt"; - } elsif ($data{username}) { - %data = %{GN::user($public, \%data)}; - $a_template = "index_user.tt"; - } - if (!$data{found}) { - $header{-status} = '404 Not Found'; - $a_template = "404.tt"; - } - print $cgi->header(%header); - if ($head) { $head = 0; continue; } - $template->process($a_template, \%data) or info("Template: " . $template->error()); - } else { - $header{-status} = '405 Method Not Allowed'; - print $cgi->header(%header); - } - } -} catch ($error) { - info("Crashed: $error"); -} diff --git a/gorillanest.pl.cgi b/gorillanest.pl.cgi new file mode 100644 index 0000000..565fd6f --- /dev/null +++ b/gorillanest.pl.cgi @@ -0,0 +1,105 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use CGI; +use Switch::Back; +use Template; +use URI::Escape; +use Cwd; + +use Data::Dumper; +sub info { + print STDERR join(' ', @_); +} + +our $template = Template->new({INCLUDE_PATH => 'template'}); + +# significant dirs only +sub GN::directories { + my $root = $_[0]; + opendir my $dir, $root or die "Cannot open directory '$root': $!"; + my @directories; + my %drop = ( + '.' => 0, + '..' => 0, + ); + foreach (readdir $dir) { + push(@directories, $_) if (-d join('/', $_[0], $_) && ($drop{$_} // 1)); + } + closedir $dir; + return \@directories; +} + +# probably should output all repos recursively, currently just outputs list of users +sub GN::index { # / + my ($root, $dataref) = @_; + my %data = %$dataref; + my @directories = map { my $i = $_; map { join('/', $i, $_) } @{GN::directories(join('/', $root, $i))} } @{GN::directories($root)}; + $data{directories} = \@directories; + if ($data{directories}) { $data{found} = 1; } + return \%data; +} + +sub GN::user { # /$username/ + my ($root, $dataref) = @_; + my %data = %$dataref; + my @directories = @{GN::directories(join('/', $root, $data{username}))}; + $data{directories} = \@directories; + if ($data{directories}) { $data{found} = 1; } + return \%data; +} + +sub GN::repository { # /$username/$repository + my ($root, $dataref) = @_; + my %data = %$dataref; + my $d = getcwd(); + chdir(join('/', $root, $data{username}, $data{repository})); + warn 'sneed ' . getcwd() . "\n"; + $data{log} = Dumper(split(/\n/, qx(git log --pretty=format:\'%H | %an | %ad | %s%x0a\'))); # It technically works # | tac | tr -s \'\n\' + chdir($d); + $data{found} = 1; + return \%data; +} + +sub serve_template { + my ($file, @rest) = @_; + my %vars = @rest ? @rest : (); + + $template->process($file, \%vars) + or info("Template: " . $template->error()); +} + +my %routes = ( + '/' => sub { serve_template("index.tt", @_) }, + '/~([a-zA-Z0-9_.]+)' => sub { serve_template("index_user.tt", @_) }, + '/~([a-zA-Z0-9_.]+)/([a-zA-Z0-9_.]+)' => sub { serve_template("repository.tt", @_) }, +); + +my $public = 'git/public'; +my $dbfile = 'gorillanest.sqlite3'; +my %data = ( + found => 0, +); + +sub master { + my $cgi = CGI->new; + my %header = ( + -Content_Type => 'text/html', + -charset => 'UTF-8', + ); + my $method = $ENV{'REQUEST_METHOD'} || ''; + my $uri = $ENV{'REQUEST_URI'} || '/'; + + for my $pattern (keys %routes) { + if ($uri =~ m{^$pattern$}) { + my $handler = $routes{$pattern}; + $handler->($uri, $1, $2, $3); + } + } + + serve_template("404.tt"); # XXX missing code +} + +master() if !caller; 1; diff --git a/gorillanest.pl.fcgi b/gorillanest.pl.fcgi new file mode 100755 index 0000000..f4c0687 --- /dev/null +++ b/gorillanest.pl.fcgi @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Syntax::Keyword::Try; +use FCGI; + +require "gorillanest.pl.cgi"; + +our $request = FCGI::Request(); + +try { + while($request->Accept() >= 0) { + master(); + } +} catch ($error) { + info("Crashed: $error"); +} diff --git a/lighttpd-cgi.conf b/lighttpd-cgi.conf new file mode 100644 index 0000000..07b55d7 --- /dev/null +++ b/lighttpd-cgi.conf @@ -0,0 +1,21 @@ +server.modules = ( + "mod_cgi", + "mod_rewrite", + "mod_setenv" +) + +server.document-root = var.CWD +server.port = 5050 + +url.rewrite-once = ( + "/" => "/gorillanest.pl.cgi" +) + +setenv.add-environment = ( + "PERL5LIB" => env.PERL5LIB +) + + +cgi.assign = ( + ".pl.cgi" => "/usr/bin/perl" +) diff --git a/lighttpd-fcgi.conf b/lighttpd-fcgi.conf new file mode 100644 index 0000000..a9cbb25 --- /dev/null +++ b/lighttpd-fcgi.conf @@ -0,0 +1,25 @@ +server.modules = ( + "mod_fastcgi", + "mod_rewrite", + "mod_setenv" +) + +server.document-root = var.CWD +server.port = 5050 + +url.rewrite-once = ( + "/" => "/gorillanest" +) + +setenv.add-environment = ( + "PERL5LIB" => env.PERL5LIB +) + +fastcgi.server = ( + "/gorillanest" => (( + "bin-path" => "gorillanest.pl.fcgi", + "socket" => "gorillanest.sock", + )) +) + +fastcgi.debug = 1 diff --git a/lighttpd.conf b/lighttpd.conf deleted file mode 100644 index 3f21f8f..0000000 --- a/lighttpd.conf +++ /dev/null @@ -1,25 +0,0 @@ -server.modules = ( - "mod_fastcgi", - "mod_rewrite", - "mod_setenv" -) - -server.document-root = var.CWD -server.port = 5050 - -url.rewrite-once = ( - "/" => "/gorillanest" -) - -setenv.add-environment = ( - "PERL5LIB" => env.PERL5LIB -) - -fastcgi.server = ( - "/gorillanest" => (( - "bin-path" => "gorillanest", - "socket" => "gorillanest.sock", - )) -) - -fastcgi.debug = 1