From 3ec4225c360b4bc72ac85207c68bc66c563b7e19 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Wed, 5 May 2021 14:35:36 -0600 Subject: [PATCH] Initial commit for shombler --- README.md | 29 +++++++++++++++++ shomble.pl | 32 +++++++++++++++++++ shomble/empty_posts.db | Bin 0 -> 12288 bytes shomble/get.pl | 70 +++++++++++++++++++++++++++++++++++++++++ shomble/posts.db | Bin 0 -> 12288 bytes 5 files changed, 131 insertions(+) create mode 100644 README.md create mode 100755 shomble.pl create mode 100644 shomble/empty_posts.db create mode 100755 shomble/get.pl create mode 100644 shomble/posts.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..083e9d1 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +### SHoMBler (Self Hosted MicroBlogger) + +## What is Shombler? + +Shombler is a light weight, hyper minimalistic, cli based microbloging platform. + +## Why? + +Why not? Its geared to those who both want to control their own data, avoid censorship, and spend a lot of time in a command line environment. Why load up a browser, and use some privately controled platform that sells your data, when you can just enter a simple command, and not be controled by some big tech nightmare. + +## Whatabout the social aspect? + +What about it? The web should never have been socialized in this developers oppinion. There is and will never be a commenting functionality built into Shombler. If you really feel like you must type at eachother and have your little flame wars, just link to the other persons post in your post, or fork this or something if you really must. + +## Ok well, hows it work? + +Shombler is composed of 3 parts: Input, Storage, Presentation + +* Input: fairly self explainitory, a script that takes your input and stores it in... +* Storage: a sqlite database designed to basically just hold entries and their dates (no character limit like some platforms btw, go hog wild... within reason. +* Presentation: A backend script, designed to be accessable by a webserver, that provides a read only API spitting out entries according to the request given to it. This will be given as JSON, which should make it very portable, it should easily be dropable into any old(or new) website ether using the included code snipet, or you can roll your own, the documentation should be very easy to understand and writing your own access should be very stright forward as long as you know some sort of front end language. + +## Sounds complicated... Got a tutorial? + +I mean, not really but I can write one eventually. + +## Great! Lets get started, wait.. your git project is empty, wtf??? + +Sorry, prewriting this readme, not that anyone will see this, as I will have removed it by the time anyone is aware of the projects exsistance. But you know, for the git history, in case someone is weird and decides to read it. diff --git a/shomble.pl b/shomble.pl new file mode 100755 index 0000000..6e24370 --- /dev/null +++ b/shomble.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl -w +use strict; +use warnings; +use DBI; + +my $username = ""; # Username to include in posts +my $dblocation = "./shomble/posts.db"; #needs to point to the relative or absolute + # system path of the posts.db file. +my $post = ""; + +my $db = DBI->connect("DBI:SQLite:dbname=$dblocation", "", "", { RaiseError => 1}) or die $DBI::errstr; + +TRYAGAIN: +print "Ok, what would you like to submit?\n>"; +$post = ; +chomp $post; + +print "Confirming this is your post:\n".$post."\n Is this correct? (you must type y or yes to submit)\n>"; + +if ( =~ /y(es)?/i ) { + #this needs to be called right before the post is submitted to the database. + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); + my $timeStamp = $mday."/".$mon."/".($year + 1900)." ".$hour.":".$min.":".$sec; + + my $statmentHandle = $db->prepare('INSERT INTO posts VALUES( ?1, ?2, ?3)') or die $DBI::errstr; + $statmentHandle->execute( $timeStamp, $username, $post ) or die $DBI::errstr; + print "Post submitted, thank you for using Shombler!"; +} else { + goto TRYAGAIN; +} + +$db->disconnect(); diff --git a/shomble/empty_posts.db b/shomble/empty_posts.db new file mode 100644 index 0000000000000000000000000000000000000000..ef53dbdd9080d5d8ec719fc8d87641d76e2464c9 GIT binary patch literal 12288 zcmeI#K}*9h6u|MMii$A0TM<0G;|fERodu`%Hc;1kloGXKacgHAWjp$f{33oIk2Zmw zcXs?AD{EXg}l_w+*lc@zS3GaW=l-|(nV(!=f8acOF7;g^5I_I{1Q0*~0R#|0009ILKww)14&BA* c|F`vdxfcQmAbnew; + +sub get_info { + my $clientIP = ($ENV{"REMOTE_ADDR"} or "0.0.0.0"); + my $proto = ($ENV{"REQUEST_SCHEME"} or "http"); + my $query = (split(/\?/,($ENV{"QUERY_STRING"} or "")))[0]; + my $referrer = ($ENV{"HTTP_REFERER"} or ""); + return ($proto,$clientIP,$query,$referrer); +} + +sub http_status { + my ($status,$content,$target) = @_; + my $header = ""; + $header .= "status: ".$status."\r\n"; + $header .= "Location: ".$target."\r\n" if $target; + $header .= "Content-Type: ".$content."\r\n" if $content; + $header .= "\r\n"; + return $header; +} + +sub soft_die { + print http_status(500,"text/json"); + print '{"error":"'.shift.'"}'; + exit; +} + +sub clean_input { + my $input = shift; + unless ($input) { return ""; } + if ($input =~ m!%2F!) { print "Location: /hax\r\n\r\n"; exit; } + $input =~ s!%(..)!chr hex $1!ge; + $input =~ s!\+! !g; + return $input; +} + +my $db = DBI->connect("DBI:SQLite:dbname=$dbpath", "", "", { RaiseError => 1, sqlite_open_flags => SQLITE_OPEN_READONLY }) or soft_die($DBI::errstr); +my $sth; + +my @request = get_info(); +my @get_params = split("&",clean_input($request[2])); +my $directive = shift(@get_params); +if ( "rand" eq $directive ) { + # select a random post + $sth = $db->prepare('SELECT * FROM posts ORDER BY RANDOM() LIMIT 1'); +} elsif ( "last" eq $directive ) { + # select the last post only + $sth = $db->prepare('SELECT * FROM posts ORDER BY DATE DESC LIMIT 1'); +} elsif ( "range" eq $directive ) { + # select range starting with lastest as 1 + my $low = $get_params[0]; + my $high = $get_params[1]; + $sth = $db->prepare('SELECT * FROM posts ORDER BY DATE DESC LIMIT '.$low.', '.$high); +} else { + # select the last 10 posts + $sth = $db->prepare('SELECT * FROM posts ORDER BY DATE DESC LIMIT 10'); +} +$sth->execute or soft_die($sth->errstr); + +print http_status(200,"text/json"); +print $json->encode( $sth->fetchall_arrayref({})); diff --git a/shomble/posts.db b/shomble/posts.db new file mode 100644 index 0000000000000000000000000000000000000000..ef53dbdd9080d5d8ec719fc8d87641d76e2464c9 GIT binary patch literal 12288 zcmeI#K}*9h6u|MMii$A0TM<0G;|fERodu`%Hc;1kloGXKacgHAWjp$f{33oIk2Zmw zcXs?AD{EXg}l_w+*lc@zS3GaW=l-|(nV(!=f8acOF7;g^5I_I{1Q0*~0R#|0009ILKww)14&BA* c|F`vdxfcQmAb