commit 0a4e6923a421893503926243a5ac7e8d10c0261e from: monaco via: GitHub date: Fri Jan 27 12:54:51 2023 UTC Create kpsm2.pl This uses Mojolicious module so you would need this library to run it it has full functionality and it runs on it's own web server :) commit - 25106484a2b09a0293ceb3c4c8f08f89e5a7bbbf commit + 0a4e6923a421893503926243a5ac7e8d10c0261e blob - /dev/null blob + 1c137d2a2ef670287e420405b55277eab7f963e1 (mode 644) --- /dev/null +++ kpsm2.pl @@ -0,0 +1,75 @@ +#!/usr/bin/env perl + +use Mojolicious::Lite; +use DBI; +use Digest::SHA qw(sha1_hex); + +my $dbh = DBI->connect("dbi:SQLite:dbname=pastes.db", "", "", { RaiseError => 1 }); + +my $table_exists = $dbh->selectrow_array("SELECT name FROM sqlite_master WHERE type='table' AND name='pastes'"); +if (!$table_exists) { + $dbh->do("CREATE TABLE pastes (id TEXT PRIMARY KEY, content TEXT)"); +} + +get '/' => sub { + my $c = shift; + $c->render(template => 'index'); +}; + +post '/create' => sub { + my $c = shift; + my $content = $c->param('content'); + my $id = sha1_hex(time . $content); + $dbh->do("INSERT INTO pastes (id, content) VALUES (?, ?)", undef, $id, $content); + $c->redirect_to("/view/$id"); +}; + +get '/view/:id' => sub { + my $c = shift; + my $id = $c->param('id'); + my $content = $dbh->selectrow_array("SELECT content FROM pastes WHERE id = ?", undef, $id); + $c->render(text => $content); +}; + +get '/search' => sub { + my $c = shift; + my $query = $c->param('q'); + my $results = $dbh->selectall_arrayref("SELECT id FROM pastes WHERE content LIKE ?", { Slice => {} }, "%$query%"); + $c->render(template => 'search', results => $results); +}; + +app->start; +__DATA__ + +@@ index.html.ep + + + + Pastebin + + + +

Create a new paste

+
+ + +
+

Search for a paste

+
+ + +
+ + + +@@ search.html.ep + + + + Pastebin + + + +

Search Results

+