From 6eb8b90eefd803ffe540875a4666e7e68193ab44 Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Tue, 6 May 2025 11:45:12 -0600 Subject: [PATCH] condensing 449 commits --- .gitignore | 1 - ixtab | 40 +--------- perl/.gitignore | 1 + perl/Triple.pm | 149 +++++++++++++++++++++++++++++++++++ run/.gitignore | 2 + scripts/daemon | 13 +++ scripts/live | 19 +++++ static/favicon.png | Bin 0 -> 1759 bytes static/favicon.png.copyright | 4 + static/style.css | 27 +++++++ tt/404 | 3 +- tt/footer | 8 ++ tt/header | 13 +++ tt/img | 15 +++- tt/index | 21 ++++- 15 files changed, 274 insertions(+), 42 deletions(-) delete mode 100644 .gitignore create mode 100644 perl/.gitignore create mode 100644 perl/Triple.pm create mode 100644 run/.gitignore create mode 100755 scripts/daemon create mode 100755 scripts/live create mode 100644 static/favicon.png create mode 100644 static/favicon.png.copyright create mode 100644 static/style.css create mode 100644 tt/footer create mode 100644 tt/header 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 0000000000000000000000000000000000000000..a9e900b731f5bd891fb8c6d94d861f7bffd8c19f GIT binary patch literal 1759 zcmZ{lc~p~E7Qi3KCIU_?tK$--rLu)22*e;12uLCc2_XSOf&{XWl8r2o0AYzNhE-6i z1W*>SYym-pve~hM9%)Oh6dCC$Q&BpK)1ZZE6)K&Np3^yJ{+M&#z4yF(fA_t2-n;Ky z9XUGE)_Sis0KgWH3#UN#9Z3FSwFA<3S2-d8OmYNRELp&218}59Qxk-{9kOpKIkx;D zb>F{WOJ`d!kJ`)74?XN#!a5uhm57n`UHYT%xx=fp>9=lGPj#Ixzus%ttA)KbS%Rb8 zM{&B}qpZDCkE4xu$8xI2vI_3^puSqc1HHJRo=W+0Ieuy}z6b_8gWllsT;#RqOIBZx zMi%sCAulcG8^1<&IC@!_g)f=;5*k#eRlHe$^y;3-1bUqAYuyLLQP?Zjd57wMpf4~T zRlLbBc|Yo0CsRAi>)o3I&n-I^ockjVcj=VzyqT^rM=c|p~o;s~!$ zt(CcwN-nN+HelQxQG=J)UsaFh>6q3d9;~McA+~!t^Sie!KO4JI7MtPY-e?x)Q?-V) zTQ`~-N}l8%42*tZW)-|6KKpKRy6N@HR{}7J>sHPS7VzFc{eUIY2wX`e!s%Z7EAIB? zf7^7?#2#?IX>Rdwd~snDtpNky(l#v6XfwBy=O>J7#+$~)t)N-sswJURcHzYL$q~?N zz}Pqn5rAwr01Ao#*nnIG&j3&&09auGfVl{OleBR(<~RVR0b~L-0+|2q3D7hjx+E$+ zCsCngsnx{H5STvY!Q(-5?}G1_O84%!C+lufr#DNRKbcuN4R>N!Ud#|Fj!YO#pi?I z0|-2v8gkGF@8%Wb?Gd~WLGUbX`$`*?oaXkLAns=QWO+ax=km821eXQqZ}i#ZLw*{#EQx>})>cd|uW zRGX2J!$`=W;ndJbk5jN?(ug6s$@F4Ql1{+U=jKneHeIVJ&tfE~7$kWdQIQa>OeD(^ z$XSUbbrQMfY}J(ElWQNJS2381cyczKC8LqJIJ}5N=r~g}+Nv+ij%hnn%nZi!Ba?>C zom0lg3ZqjQK_o`diE@dwSyz-JCuxKXF`1UdR3>9NU$kC+daLhYe`{A+sp^zU9GfAf z@zqS4n#EuSqH0umeT_Yd!K~}e9lzZlemgt*eCksTM^h{+Nee!j=v9i?byWQxkrZjri7!uRD^rCCTp&_=CPsinp`v}7EBi9es`s= zoWm=@`q2H{r|T+a+b;fd^y<}Yu{0bL@9Rl{dkFEk&f?sa$^KtwMsDgWpr=t0u`TJW zYDR3jzn7kXY^M4_MU|f!6$BZKf)X8T;!H2B&pF{{DVY9c>zDab+h6Uo44doKSolhp z=koH4CtDk}n;YYA+f7@qZGQM05q9-080Vj9VP|3W z!w*lFh6a9oy!?b;YGw6u*TUZy9tEN?$K)BNZ^Ax5+zRg%8xLGMwdfz6y7aD1EhYG7 z-j+$>shQAQhgwn|Kd?a!yi*hN4YEJu)lS_vE%HeP%L)| zy61b6K53h3?(Ck(yM4!{!C$iQ?!pj_#60+H_YSOU+sJoAs~6L*TFh)7UiB_a`5tN>UUH$}naz_J92G*~2_NRBVGbAq7v zw;>J`!m$4!01AQf^F}}eMMd~x{ElG|2u}n8(lf&k4F8iLl5hk(_5V-!Y~`cvcJbHk z9iR?@VN0ZHnSh_B0AyvVP{4+TOGGIG@lXwt0bz&##5i0zTPBby1QIdWJ}4|zDG(~W z1!9<-5*bF|hwg!Bhd*giide}@VJnm}uIvw-aOvzc1lau-kZ`y{u${_a;jvHz;3J~L Jd&5}T{{X;@-BJJm literal 0 HcmV?d00001 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 %] +
-- 2.47.3