From: Emil Williams Date: Tue, 6 May 2025 17:45:12 +0000 (-0600) Subject: condensing 449 commits X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;h=6eb8b90eefd803ffe540875a4666e7e68193ab44;p=emil-3chen.org.git condensing 449 commits --- diff --git a/.gitignore b/.gitignore deleted file mode 100644 index db2fc0d..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -secrets diff --git a/ixtab b/ixtab index 09bbff6..1818ed0 100755 --- a/ixtab +++ b/ixtab @@ -1,40 +1,6 @@ #!/usr/bin/env perl -use strict; -use warnings; -use CGI; -use DBI; -use Template; -require "secrets"; # server data - shit that doesn't need to uploaded. +BEGIN {push @INC, './perl'} +use Triple; -my $cgi = CGI->new; - -my $tt = Template->new({ - INCLUDE_PATH => '.', - INTERPOLATE => 1, - }) or die Template->error(); - -# $dbfile from secrets -my $dbh = DBI->connect("dbi:SQLite:uri=file:$dbfile?mode=rwc"); - -my $path = $cgi->param('path') // ''; - -my %site = ( - ixtab => 'index', - img => 'img', - ); - -my $vars = ( - sneed => 'feed', - chuck => 'fuck', - ); - -my $page = $site{"$path"} // '404'; - -print $cgi->header( - -Content_Type => 'text/html', - -charset => 'UTF-8', - ); - -# I should probably put all of below into a buffer and run a pruning regexp on it -$tt->process('tt/' . $page, $vars) or die $tt->error(); +Triple::main(); diff --git a/perl/.gitignore b/perl/.gitignore new file mode 100644 index 0000000..a189ecd --- /dev/null +++ b/perl/.gitignore @@ -0,0 +1 @@ +Secrets.pm diff --git a/perl/Triple.pm b/perl/Triple.pm new file mode 100644 index 0000000..f77c097 --- /dev/null +++ b/perl/Triple.pm @@ -0,0 +1,149 @@ +package Triple; + +use strict; +use warnings; + +use Sys::Syslog; +use Data::Dumper; + +use CGI; +use FCGI; +use Template; + +use feature 'state'; + +# Internal +use Secrets; + +our $debug = 0; + +our @boards = ( + '/img/', + '/doc/', + ); + +our %titles = ( + '/' => 'Root', + '/img/' => 'Imgb.', + '/doc/' => '2nd.', + ); + +our %descriptions = ( + '/' => 'Forum Index', + '/img/' => 'Test Board', + '/doc/' => 'Secondary Board', + ); + +our %sitemap_static = ( + '/' => 'index', + '/404/' => '404', + ); +our %sitemap; + +sub sitemapgen { + %sitemap = %sitemap_static; + foreach (@boards) { + syslog("info", "+ $_"); + $sitemap{"$_"} = 'img'; + } +} + +sub sitename { + use Cwd; + my $sitename = getcwd(); # pwd + $sitename =~ s/.*\///; # /a/b/c/sitename/ => sitename + return $sitename; +} + +sub debug { + my $sitename = $_[0]; + $debug = 1 if $sitename =~ /^test\./; + openlog($sitename, "ndelay,pid", Sys::Syslog::LOG_DAEMON); +} + +sub handlers { + my $include = $_[0]; + my $request = FCGI::Request(); + my $template; + $template = Template->new({INCLUDE_PATH => $include}) or syslog("info", $template->error()); + return ($request, $template); +} + +sub version { + open my $fh, '<', $_[0] or die "Can't open file: $!"; + my $line = uc(substr(<$fh>, 0, 12)); + close $fh; + return $line; +} + +sub init { + my $sitename = sitename(); + debug($sitename); + my ($request, $template) = handlers('tt'); + sitemapgen(); + return $sitename, $request, $template; +} + +sub main() { + my ($sitename, $request, $template) = Triple::init(); + + my $version = Triple::version("version"); + syslog("info", "loading $version"); + + my %static; + { + my $vars = { + boards => \@Triple::boards, + titles => \%Triple::titles, + descriptions => \%Triple::descriptions, + sitename => $sitename, + version => $version, + }; + foreach (my ($path, $page) = each %sitemap_static) { + syslog("info", "staticify $path"); + $vars->{uri} = $path; + my $description = $Triple::descriptions{$path} // 'No Description Retard'; + $vars->{description} = $description; + my $pregen; + $template->process($page, $vars, \$pregen) or syslog("info", $template->error()); + $static{$path} = $pregen; + } + } + + + while($request->Accept() >= 0) { + my $cgi = CGI->new; + + # my $method = $ENV{'REQUEST_METHOD'} || '?'; + my $ip = $ENV{'REMOTE_ADDR'} || '?'; + $ip = 'hidden' if not $Triple::debug; + + my $path = $ENV{'REQUEST_URI'} // '/'; + my $page = $Triple::sitemap{$path} // '404'; + my $stale = $static{$path} || ''; + + print $cgi->header( + -Content_Type => 'text/html', + -charset => 'UTF-8', + ); + if (not $stale) { + syslog("info", "serving live"); + my $description = $Triple::descriptions{$path} // 'No Description Retard'; + my $vars = { + uri => $path, + description => $description, + sitename => $sitename, + version => $version, + ip => $ip, + }; + $template->process($page, $vars) or syslog("info", $template->error()); + } else { + syslog("info", "serving stale"); + print $stale; + } + # my $description = $Triple::descriptions{$path} // 'No Description Retard'; + # syslog("info", "$ip $method $path template $page described as '$description'") if $Triple::debug; + } +} + +1; diff --git a/run/.gitignore b/run/.gitignore new file mode 100644 index 0000000..5aed8eb --- /dev/null +++ b/run/.gitignore @@ -0,0 +1,2 @@ +socket +pid diff --git a/scripts/daemon b/scripts/daemon new file mode 100755 index 0000000..6cde54f --- /dev/null +++ b/scripts/daemon @@ -0,0 +1,13 @@ +#!/bin/sh +cd "$(dirname "$(readlink -f "$0")")" +cd ../ +u=www +if [ -e ./run/pid ]; then + pids=$(cat ./run/pid) + if [ ! -z $pids ]; then + echo stopping $pids + kill $pids + fi + rm ./run/pid ./run/socket +fi +spawn-fcgi -P ./run/pid -s ./run/socket -u $u -U $u -- ./ixtab diff --git a/scripts/live b/scripts/live new file mode 100755 index 0000000..d839f14 --- /dev/null +++ b/scripts/live @@ -0,0 +1,19 @@ +#!/bin/sh +# for "live" testing +cd "$(dirname "$(readlink -f "$0")")" + +file=../ixtab + +mtime() { + stat -f "%m" "$1" +} + +./daemon +while [ 1 ]; do +past=$(mtime $file) +sleep 3 +if [[ $(mtime $file) != $past ]]; then +echo altered. +./daemon || $file +fi +done diff --git a/static/favicon.png b/static/favicon.png new file mode 100644 index 0000000..a9e900b Binary files /dev/null and b/static/favicon.png differ diff --git a/static/favicon.png.copyright b/static/favicon.png.copyright new file mode 100644 index 0000000..f2dc9b4 --- /dev/null +++ b/static/favicon.png.copyright @@ -0,0 +1,4 @@ +by: kyuukei_usagi +source: https://cdn.donmai.us/original/c8/0a/__chen_touhou_drawn_by_kyuukei_usagi__c80aeddd3e2e178beab3f751c5b04491.png +modified: 1 +license: Unknown diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..27d8fc3 --- /dev/null +++ b/static/style.css @@ -0,0 +1,27 @@ +#title { + text-align: center; + font-size: 2.5em; + padding-bottom: 0.5em; + margin-bottom: 0.5em; + border-bottom-style: solid; + border-width: 1px; +} + +#foot { + text-align: center; + padding-top: 0.25em; + margin-top: 1em; + border-top-style: solid; + border-width: 1px; +} + +#index { + width: 70em; + padding: 1em 0.5em 0em 0.5em; + margin: 1em auto; +} + +#board { + padding: 1em 0.5em 0em 0.5em; + margin: 1em auto; +} diff --git a/tt/404 b/tt/404 index 7fbea0f..0e26493 100644 --- a/tt/404 +++ b/tt/404 @@ -1,6 +1,7 @@ +[% INCLUDE header %] -

Nothing Lost, Nothing Gained

+
Nothing Lost, Nothing Gained
diff --git a/tt/footer b/tt/footer new file mode 100644 index 0000000..c0e8118 --- /dev/null +++ b/tt/footer @@ -0,0 +1,8 @@ + diff --git a/tt/header b/tt/header new file mode 100644 index 0000000..e1ad41b --- /dev/null +++ b/tt/header @@ -0,0 +1,13 @@ + + + + + + + + + + + +[% uri %] @ [% sitename %] + diff --git a/tt/img b/tt/img index e733a1a..3155781 100644 --- a/tt/img +++ b/tt/img @@ -1,6 +1,19 @@ +[% INCLUDE header %] -

Image Board

+
+
[% uri %] - [% description %]
+ [% FOREACH thread IN threads %] +
+ [% FOREACH reply IN thread %] +
+ [% reply %] +
+ [% END %] +
+ [% END %] +[% INCLUDE footer %] +
diff --git a/tt/index b/tt/index index 002aa39..296271e 100644 --- a/tt/index +++ b/tt/index @@ -1,7 +1,24 @@ +[% INCLUDE header %] -

Glorious Day

-Imgb. +
+
[% sitename %]
+
+ + + + + + [% FOREACH board IN boards %] + + + + + [% END %] +
BoardDesc.
[% titles.${board} %][% descriptions.${board} %]
+
+[% INCLUDE footer %] +