Compare commits
10 Commits
a2fb4d6a55
...
47468f2805
Author | SHA1 | Date |
---|---|---|
Barrington | 47468f2805 | |
Barrington | 7858d62067 | |
Barrington | c0ae0e7784 | |
Barrington | e7e7fcab47 | |
Barrington | f15f072800 | |
Barrington | a3304051ae | |
Barrington | 85352ea4d5 | |
Barrington | 5ab693760e | |
qorg11 | 0597c1b153 | |
qorg11 | 0c31132bf8 |
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
20
README.org
20
README.org
|
@ -1,14 +1,16 @@
|
|||
* the_pit --- A simple blog software that uses plaintext files
|
||||
|
||||
** HISTORY
|
||||
For a lof of time, the person who wants a blog has been struggling
|
||||
with the question on how the fuck to make a blog, "ssg? wordpress?"
|
||||
And the_pit is the Final Solution to the Blog Question (in my opinion
|
||||
at least)
|
||||
** INSTALLATION
|
||||
One day I wrote this because I think most CMS are garbage and I had to
|
||||
create a good one myself.
|
||||
|
||||
INSTALLATION
|
||||
*** DEPENDENCES
|
||||
- fcgi
|
||||
- nginx
|
||||
- Text::Markdown
|
||||
- CGI
|
||||
- DBD::Pg (optional, if you want comments)
|
||||
*** NGINX INSTALLATION
|
||||
It has been tested in nginx so this configuration is guaranteed to
|
||||
work under nginx.
|
||||
|
@ -24,11 +26,15 @@ work under nginx.
|
|||
- Written in perl instead of python.
|
||||
- RSS
|
||||
- Depends on =CGI= only
|
||||
|
||||
** HOW TO USE
|
||||
After installing the_pit, you only drop files which have to have the
|
||||
following naming scheme: =yyyymmdd.whatever.txt= "whatever" can be
|
||||
whatever or can be nothing. Drop the files in the blogroot and the_pit
|
||||
will do the rest.
|
||||
|
||||
You may edit the footer.html and header.html according to your needs.
|
||||
|
||||
You may edit the =footer.html= and =header.html= according to your
|
||||
needs. And you can put whatever info you want in =notes.html=. These
|
||||
files are hardcoded in the perl script.
|
||||
** LICENSE
|
||||
Public domain.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
package Util;
|
||||
use v5.32;
|
||||
use experimental 'signatures';
|
||||
use Exporter;
|
||||
use POSIX;
|
||||
our @EXPORT_OK = qw(get_date file_to_arr get_title);
|
||||
our @EXPORT = qw(get_date file_to_arr get_title);
|
||||
|
||||
sub get_date($filename) {
|
||||
my @stat_thing = stat($filename);
|
||||
my $date = $stat_thing[9];
|
||||
return strftime ("%a %b %e %H:%M:%S %Y", localtime($date)) . "\n";
|
||||
}
|
||||
|
||||
sub file_to_arr($file) {
|
||||
open my $fh, "<$file";
|
||||
my @file;
|
||||
while (<$fh>) {
|
||||
push @file, $_;
|
||||
}
|
||||
return @file;
|
||||
close $fh;
|
||||
}
|
||||
|
||||
sub get_title($file) {
|
||||
my @file = file_to_arr($file);
|
||||
my $line = $file[0];
|
||||
# Remove trailing whitespaces
|
||||
$line =~ s/^\s*(.*?)\s*$/$1/;
|
||||
return $line;
|
||||
}
|
||||
|
||||
1;
|
68
blog.cgi
68
blog.cgi
|
@ -1,68 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use CGI;
|
||||
my $q = new CGI;
|
||||
|
||||
# =====================CONFIG======================
|
||||
|
||||
my $ROOT = "/trashyard/";
|
||||
|
||||
# =====================END CONFIG==================
|
||||
|
||||
my $url = $ENV{REQUEST_URI};
|
||||
|
||||
sub read_file($);
|
||||
|
||||
print $q->header("application/xhtml+xml");
|
||||
my @entries = reverse glob("*.txt"); # Get all entries
|
||||
|
||||
$url =~ s/index\.cgi//;
|
||||
$url =~ s/blog\.cgi//;
|
||||
|
||||
read_file("header.html");
|
||||
read_file("notes.html") if $url eq $ROOT;
|
||||
|
||||
if ($url eq $ROOT) {
|
||||
print "<ul>\n";
|
||||
foreach my $link (@entries) {
|
||||
$link =~ s/\.txt//;
|
||||
print "<li><a href=\"".$url . $link ."\">".get_title($link . ".txt") . "</a></li>\n";
|
||||
}
|
||||
print "</ul>\n";
|
||||
} else {
|
||||
my $file = $url;
|
||||
$file =~ s/$ROOT//;
|
||||
if(!-e $file . ".txt") {
|
||||
print $q->h1("This is a 404...");
|
||||
print "<a href=\"./\">Go back to the index?</a>";
|
||||
} else {
|
||||
print "<pre>";
|
||||
read_file($file . ".txt");
|
||||
print "</pre>";
|
||||
}
|
||||
}
|
||||
read_file("footer.html");
|
||||
|
||||
sub read_file($) {
|
||||
my $file = shift;
|
||||
open(my $fh, "<$file");
|
||||
print while <$fh>;
|
||||
close $fh;
|
||||
}
|
||||
sub file_to_arr($) {
|
||||
my $file = shift;
|
||||
open $fh, "<$file";
|
||||
my @file;
|
||||
while (<$fh>) {
|
||||
push @file, $_;
|
||||
}
|
||||
return @file;
|
||||
}
|
||||
|
||||
sub get_title($) {
|
||||
my $file = shift;
|
||||
my @file = file_to_arr($file);
|
||||
my $line = $file[0];
|
||||
$line =~ s/^\s*(.*?)\s*$/$1/;
|
||||
return $line;
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
56
header.html
56
header.html
|
@ -1,30 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd" xml:lang="en">
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>qorg11 - La grifa es una cosa que te pone ciego</title>
|
||||
<link rel="stylesheet" href="../css/styles.css"/>
|
||||
<meta name="author" content="xalloc xzal" />
|
||||
<link rel="alternate" type="application/rss+xml" href="rss.cgi" title="RSS feed" />
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Suragu.net --- [[TITLE]]</title>
|
||||
<meta name="author" content="Raoul Vaughn" />
|
||||
<meta name="generator" content="Org Mode" />
|
||||
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="sidebar">
|
||||
<div class="cat_image">
|
||||
<a href="/">
|
||||
<img src="/img/cat.gif" alt="cat">
|
||||
</a>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a href="/about.html">About</a>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a href="/tech_posts">Tech posts</a>
|
||||
</div>
|
||||
|
||||
<div class="button">
|
||||
<a href="/media.html">Media log</a>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a href="/blog">blog</a>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Header -->
|
||||
<div class="header">
|
||||
<a href="/">
|
||||
<img class="lain" alt="lain" src="../img/favicon.gif" width="100" height="100"/>
|
||||
</a>
|
||||
<div class="menu">
|
||||
<a href="/info.en.xhtml">Information</a>
|
||||
<a href="/guestbook/guestbook.cgi">shoutbox</a>
|
||||
<a href="https://git.qorg11.net">git</a>
|
||||
<a href="/webring.xhtml">Webring</a>
|
||||
<a href="/trashyard/index.cgi">Trashyard</a>
|
||||
<a href="https://kill-9.xyz">kill-9 (blog)</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="outline-2">
|
||||
|
||||
<!-- Quick Intro -->
|
||||
<div class="container" id="foobar">
|
||||
<!-- CONTENT GOES HERE -->
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
#!/bin/perl
|
||||
use v5.32;
|
||||
use experimental 'signatures';
|
||||
use POSIX qw(strftime);
|
||||
use Date::Parse;
|
||||
use Text::MultiMarkdown 'markdown';
|
||||
use lib ".";
|
||||
use Util;
|
||||
|
||||
my $q = new CGI;
|
||||
|
||||
# =====================CONFIG======================
|
||||
|
||||
my $ROOT = "/blog/";
|
||||
|
||||
# =====================END CONFIG==================
|
||||
|
||||
my $url = $ENV{REQUEST_URI};
|
||||
|
||||
# Remove if you're not using OpenBSD.
|
||||
|
||||
use CGI;
|
||||
|
||||
print $q->header(
|
||||
-type => 'text/html',
|
||||
-charset => 'utf-8',
|
||||
);
|
||||
|
||||
my @entries = reverse glob("*.txt"); # Get all entries
|
||||
|
||||
$url =~ s/index\.cgi//;
|
||||
$url =~ s/blog\.cgi//;
|
||||
if ($url eq "/blog") {
|
||||
$url .= "/";
|
||||
}
|
||||
read_file("header.html","Index",0) if $url eq $ROOT;
|
||||
read_file("notes.html","",0) if $url eq "/blog/";
|
||||
|
||||
my $date;
|
||||
if ($url eq $ROOT || $url eq "/blog") {
|
||||
print "<ul>\n";
|
||||
foreach my $link (@entries) {
|
||||
$link =~ s/\.txt//;
|
||||
$date = $link;
|
||||
$date =~ s/\.es.*//;
|
||||
$date = str2time($date);
|
||||
my $date_string = strftime("%B %d %Y",localtime($date));
|
||||
print "<li>$date_string: <a href=\"".$url . $link ."\">".Util::get_title($link . ".txt") . "</a></li>\n";
|
||||
}
|
||||
print "</ul>\n";
|
||||
} else {
|
||||
my $file = $url;
|
||||
$file =~ s/\/blog\///;
|
||||
if (!-e $file . ".txt") {
|
||||
read_file("header.html","404",0);
|
||||
print "<h2>That's a 404</h2>";
|
||||
print "<a href=\"./blog/index.cgi\">Go back to the index?</a>";
|
||||
} else {
|
||||
read_file("header.html",Util::get_title($file . ".txt"), 0);
|
||||
read_file($file . ".txt","", 1);
|
||||
get_comments($file);
|
||||
}
|
||||
}
|
||||
read_file("footer.html","",0);
|
||||
|
||||
sub get_comments($post) {
|
||||
print <<EOF;
|
||||
<hr/>
|
||||
<h2>Publicar comentario</h2>
|
||||
<form action="post_comment.cgi" method="post">
|
||||
<p><label>Nombre: <input name="nickname" /></label></p>
|
||||
<p><label>Comentario: <input name="comment" /></label></p>
|
||||
<p><label>2+2: <input name="captcha" /></label></p>
|
||||
<input type="hidden" name="post" value="$post" />
|
||||
<p><button type="submit">Submitir</button></p>
|
||||
</form>
|
||||
|
||||
EOF
|
||||
|
||||
use DBD::Pg;
|
||||
my $username = "XXXXXXXX";
|
||||
my $password = "XXXXXXXX";
|
||||
my $dbh = DBI->connect("dbi:Pg:dbname=comments;host=;port=5432",
|
||||
$username,
|
||||
$password,
|
||||
{AutoCommit => 1, RaiseError => 1, PrintError => 1}
|
||||
);
|
||||
my $sth = $dbh->prepare("select * from comments where post = \'$post\'");
|
||||
$sth->execute();
|
||||
my $results = $sth->fetchrow_hashref;
|
||||
|
||||
my $EntriesMin = $results->{comment_id};
|
||||
|
||||
$sth = $dbh->prepare("select * from comments where post = \'$post\' order by comment_id desc;");
|
||||
$sth->execute();
|
||||
$results = $sth->fetchrow_hashref;
|
||||
my $EntriesMax = $results->{comment_id};
|
||||
print "<h2>Comentarios</h2>";
|
||||
$sth = $dbh->prepare("select * from comments where post = \'$post\'");
|
||||
my $res = $sth->execute();
|
||||
while(my $data = $sth->fetchrow_hashref){
|
||||
#my $data = $sth->fetchrow_hashref;
|
||||
break if $data == undef;
|
||||
my $nickname = $data->{nickname};
|
||||
my $comment = $data->{comment};
|
||||
my $id = $data->{comment_id};
|
||||
|
||||
printf "<p>%s [%d]: %s</p>", $nickname, $id, $comment;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
sub read_file($file, $title, $markdown) {
|
||||
my $printable;
|
||||
my @contents;
|
||||
open(my $fh, "<$file");
|
||||
while (<$fh>) {
|
||||
$printable = $_;
|
||||
$printable =~ s/\[\[TITLE\]\]/$title/;
|
||||
push @contents, $printable;
|
||||
}
|
||||
if($markdown) {
|
||||
print markdown(join('', @contents));
|
||||
} else {
|
||||
print @contents;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use CGI;
|
||||
use POSIX qw(strftime);
|
||||
use Text::MultiMarkdown 'markdown';
|
||||
use OpenBSD::Unveil;
|
||||
use OpenBSD::Pledge;
|
||||
use strict;
|
||||
|
||||
my $q = new CGI;
|
||||
|
||||
use lib ".";
|
||||
use Util;
|
||||
use experimental 'signatures';
|
||||
use feature 'say';
|
||||
|
||||
print "Content-Type: application/rss+xml\n\n";
|
||||
|
||||
# Header
|
||||
|
||||
print <<HERE;
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0" xmlns:atom=\"http://www.w3.org/2005/Atom\">
|
||||
<channel>
|
||||
<atom:link href="https://suragu.net/blog/rss.cgi" rel="self" type="application/rss+xml" />
|
||||
<title>SURAGU</title>
|
||||
<link>https://suragu/blog</link>
|
||||
<description>Allah I thank, my mind went blank</description>
|
||||
HERE
|
||||
|
||||
unveil( ".", "r" );
|
||||
pledge("rpath");
|
||||
|
||||
# Prototypes
|
||||
|
||||
# Only show the latest 4 posts
|
||||
my $limit = 4;
|
||||
my $i = 0;
|
||||
foreach my $filename ( reverse glob("*.txt") ) {
|
||||
$filename =~ s/\.txt//;
|
||||
say "<item>";
|
||||
say "<title>";
|
||||
say Util::get_title($filename . ".txt");
|
||||
say "</title>";
|
||||
say "<pubDate>";
|
||||
say Util::get_date($filename . ".txt");
|
||||
say "</pubDate>";
|
||||
say "<link>\nhttp://$ENV{HTTP_HOST}/blog/$filename\n</link>";
|
||||
say "<guid>\nhttp://$ENV{HTTP_HOST}/blog/$filename\n</guid>";
|
||||
say "<description>\n<![CDATA[";
|
||||
print_file($filename . ".txt");
|
||||
say "]]>\n</description>";
|
||||
say "</item>";
|
||||
last if $limit == ++$i;
|
||||
}
|
||||
|
||||
print <<EOF;
|
||||
</channel>
|
||||
</rss>
|
||||
EOF
|
||||
|
||||
sub print_file ($file) {
|
||||
open my $fh, "<$file";
|
||||
my @file;
|
||||
while (<$fh>) {
|
||||
#$_ .= "<br>";
|
||||
push @file, $_;
|
||||
}
|
||||
close $fh;
|
||||
print markdown( join( '', @file ) );
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue