]> git.xolatile.top Git - emil-3chen.org.git/commitdiff
condensing 449 commits
authorEmil Williams <emilemilemil@cock.li>
Tue, 6 May 2025 17:45:12 +0000 (11:45 -0600)
committerEmil Williams <emilemilemil@cock.li>
Tue, 6 May 2025 17:45:12 +0000 (11:45 -0600)
15 files changed:
.gitignore [deleted file]
ixtab
perl/.gitignore [new file with mode: 0644]
perl/Triple.pm [new file with mode: 0644]
run/.gitignore [new file with mode: 0644]
scripts/daemon [new file with mode: 0755]
scripts/live [new file with mode: 0755]
static/favicon.png [new file with mode: 0644]
static/favicon.png.copyright [new file with mode: 0644]
static/style.css [new file with mode: 0644]
tt/404
tt/footer [new file with mode: 0644]
tt/header [new file with mode: 0644]
tt/img
tt/index

diff --git a/.gitignore b/.gitignore
deleted file mode 100644 (file)
index db2fc0d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-secrets
diff --git a/ixtab b/ixtab
index 09bbff6cf5a0322671a199270859d1717896139f..1818ed0bea851451a94bf9d44863c33e7dfc92b4 100755 (executable)
--- 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 (file)
index 0000000..a189ecd
--- /dev/null
@@ -0,0 +1 @@
+Secrets.pm
diff --git a/perl/Triple.pm b/perl/Triple.pm
new file mode 100644 (file)
index 0000000..f77c097
--- /dev/null
@@ -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 (file)
index 0000000..5aed8eb
--- /dev/null
@@ -0,0 +1,2 @@
+socket
+pid
diff --git a/scripts/daemon b/scripts/daemon
new file mode 100755 (executable)
index 0000000..6cde54f
--- /dev/null
@@ -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 (executable)
index 0000000..d839f14
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..f2dc9b4
--- /dev/null
@@ -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 (file)
index 0000000..27d8fc3
--- /dev/null
@@ -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 7fbea0fb68b25ec068b2ee0b0c14cf7137c31a09..0e264932d50bcabd150b195a2089d7ed169590ba 100644 (file)
--- a/tt/404
+++ b/tt/404
@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <html>
+[% INCLUDE header %]
 <body>
-<h1>Nothing Lost, Nothing Gained</h1>
+<div id="title">Nothing Lost, Nothing Gained</div>
 </body>
 </html>
diff --git a/tt/footer b/tt/footer
new file mode 100644 (file)
index 0000000..c0e8118
--- /dev/null
+++ b/tt/footer
@@ -0,0 +1,8 @@
+<div id="foot">
+  <a href="https://test.3chen.org/">testsite</a>
+  | <a href="https://3chen.org/">mainsite</a>
+  <br />
+  <div id="version">
+    &lt;Triple [% version %]&gt;
+  </div>
+</div>
diff --git a/tt/header b/tt/header
new file mode 100644 (file)
index 0000000..e1ad41b
--- /dev/null
+++ b/tt/header
@@ -0,0 +1,13 @@
+<head>
+<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon.png">
+<link rel="stylesheet" type="text/css" href="/static/style.css">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta name="viewport" content="width=device-width, initial-scale=0.5">
+<meta property="og:title" content="[% sitename %]">
+<meta property="og:type" content="website">
+<meta property="og:url" content="https://[% sitename %][% uri %]">
+<meta property="og:image" content="/logo.png">
+<meta property="og:site_name" content="[% sitename %]">
+<meta name="description" content="[% description %]">
+<title>[% uri %] @ [% sitename %]</title>
+</head>
diff --git a/tt/img b/tt/img
index e733a1ae1d67f03dd7f3af18d54565722bf5effc..3155781ecc537743d5f535fe2ac9e8319fbd0e4e 100644 (file)
--- a/tt/img
+++ b/tt/img
@@ -1,6 +1,19 @@
 <!DOCTYPE html>
 <html>
+[% INCLUDE header %]
 <body>
-<h1>Image Board</h1>
+<div id="board">
+  <div id="title">[% uri %] - [% description %]</div>
+  [% FOREACH thread IN threads %]
+  <div id="thread">
+    [% FOREACH reply IN thread %]
+    <div id="post">
+      [% reply %]
+    </div>
+    [% END %]
+  </div>
+  [% END %]
+[% INCLUDE footer %]
+</div>
 </body>
 </html>
index 002aa3905437e0087fe8daeb8f2457bc1299d15d..296271e12759df84e3e3b3865d2bfc47ab1d6ea2 100644 (file)
--- a/tt/index
+++ b/tt/index
@@ -1,7 +1,24 @@
 <!DOCTYPE html>
 <html>
+[% INCLUDE header %]
 <body>
-<h1>Glorious Day</h1>
-<a href="/img">Imgb.</a>
+<div id="index">
+<div id="title">[% sitename %]</div>
+<div id="boards">
+  <table>
+    <tr>
+      <th>Board</th>
+      <th>Desc.</th>
+    </tr>
+    [% FOREACH board IN boards %]
+    <tr>
+      <td><a href="[% board %]">[% titles.${board} %]</a></td>
+      <td>[% descriptions.${board} %]</td>
+    </tr>
+    [% END %]
+  </table>
+</div>
+[% INCLUDE footer %]
+</div>
 </body>
 </html>