From 85a16d2e0d0eb9da1e6118dc06bc079caef8e561 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Sat, 29 Mar 2025 21:59:47 +0300 Subject: [PATCH] Initial commit with work so far. --- bin/6625c400-0ccf-11f0-8230-eb390952483c | 1 + main.fasl | Bin 0 -> 10039 bytes main.lisp | 88 +++++++++++++++++++++++ main.lisp~ | 71 ++++++++++++++++++ paste.html | 47 ++++++++++++ paste.html~ | 47 ++++++++++++ root.html | 52 ++++++++++++++ root.html~ | 44 ++++++++++++ 8 files changed, 350 insertions(+) create mode 100644 bin/6625c400-0ccf-11f0-8230-eb390952483c create mode 100644 main.fasl create mode 100644 main.lisp create mode 100644 main.lisp~ create mode 100644 paste.html create mode 100644 paste.html~ create mode 100644 root.html create mode 100644 root.html~ diff --git a/bin/6625c400-0ccf-11f0-8230-eb390952483c b/bin/6625c400-0ccf-11f0-8230-eb390952483c new file mode 100644 index 0000000..2699a20 --- /dev/null +++ b/bin/6625c400-0ccf-11f0-8230-eb390952483c @@ -0,0 +1 @@ +hello world!!!! \ No newline at end of file diff --git a/main.fasl b/main.fasl new file mode 100644 index 0000000000000000000000000000000000000000..a56ea7dd865b5b9cb27d56b68d274ebbd77da8ff GIT binary patch literal 10039 zcmeHNdvqJsnV&nlcdVB!DY2ad$FZ!~dDzHGAciy$nz3eViAW<^8YQ8dmWo)|CbktU zDZqiWb`%3p2PtA|qHgf)cl3Q0KN{q7yf zmK}$1cIj^aU=q*$bl>-W_xs)NF|(^ZnN+Xmiq0NS>WVd8PPaR?rnhrl+C1CYEJg!n zr*loRdtGN&qRn|_Z?fCz@^mD-6P}Lvweha_!d{P*NUcpL*LlLd$@boOcXww`yC=|@ zTIX38Po)#ktvlTTdDnTmlrd<2 zsf2k%;5cs8;tSjtEK-1?PYL{uuT=>-^IBxZ+v0`J+^R1kixQ<`ir*WOIv^xiRE@{NPU)tQ) zXRmF)7!6bidxQZy*&}Q+8~?yL`DrN*BE)Snj=_H3Gqw)r0s&< zL>w3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l=XW5#~HrZuw zHtWl@S8Yal2V8-}b|?2keGxQt7R`|k`_A!SDX@Haoy|k5Ej<96n7iu!8OXx>5LR9o zd(xI}AFF%)m)6bSq4{Yr&d+E2u#fG-ejY3dZuB#%ddF^#tK^n&tz4F?MHitKel!1? z!HWmT6T~P4gtvr;iwNIC7GQ$#Lwv~taMwU`ub%u;Pj1zdteyaz(<;My@`|23uP1-f olLz(W0X_Mxp4_b`+w|l|dXm+X>sgm7dtc1n_3V8PT6U2CZyyF%u>b%7 literal 0 HcmV?d00001 diff --git a/main.lisp b/main.lisp new file mode 100644 index 0000000..3180043 --- /dev/null +++ b/main.lisp @@ -0,0 +1,88 @@ + +(ql:quickload "hunchentoot") +(ql:quickload "easy-routes") +(ql:quickload "djula") +(ql:quickload "frugal-uuid") + +(setf *default-pathname-defaults* (uiop:getcwd)) + +;;;; if you're gonna run a public instance, change to the url other people +;;;; will use to connect! +(defvar *server-external-address* "http://localhost:8080/") +(defvar *server* nil) + +;; we probably don't actually need a template for the root, +;; it's more or less static anyhow. +;; i guess retrieving a paste is the only place that actually needs +;; the dynamic templating thingy + +(defparameter *root-template* + (uiop:read-file-string "root.html")) + +(defparameter *paste-template* + (uiop:read-file-string "paste.html")) + +;; google code +;; holy hell, actual business logic + +(defun get-paste-contents (id) + "read file lmao. also do some checks. we don't want LFI" + (let ((path (probe-file (concatenate 'string "bin/" id)))) + (if (and path + (not (search "." id)) + (not (search "/" id))) + (uiop:read-file-string path) + nil))) + + + +(defun render-root () + (djula:render-template* + (djula:compile-string *root-template*) + nil)) +(defun render-paste (id) + (djula:render-template* + (djula:compile-string *paste-template*) + nil + :contents (or (get-paste-contents id) "err: paste not found") + :link-home *server-external-address* + :link-bin (concatenate 'string *server-external-address* "bin/" id) + :link-raw (concatenate 'string *server-external-address* "raw/" id))) + +(defun new-paste-file () + (let ((id (fuuid:to-string (fuuid:make-v1)))) + (if (get-paste-contents id) + (new-paste-file) + id))) + +(defun create-new-paste (contents) + "Returns the url to the new paste" + (let ((path (new-paste-file))) + (with-open-file (s (concatenate 'string "bin/" path) :direction :output) + (princ contents s)) + path)) + + +(easy-routes:defroute root ("/" :method :get) () + (render-root)) + +(easy-routes:defroute paste ("/bin/:n") () + (render-paste n)) + +(easy-routes:defroute raw ("/raw/:n") () + (get-paste-contents n)) + +;; todo: handle new pastes TODO: doesn't work, fix. +(easy-routes:defroute new ("/new" :method :post) (content) + (let ((path (create-new-paste content))) + (format t "created new bin ~a~%" path) + (hunchentoot:redirect (concatenate 'string "/bin/" path)))) + + +(defun start-server (&key (port 8080)) + (format t "Starting server on port ~a~%" port) + (force-output) + (setf *server* (make-instance 'easy-routes:easy-routes-acceptor :port port)) + (hunchentoot:start *server*)) +(defun stop-server () + (hunchentoot:stop *server*)) diff --git a/main.lisp~ b/main.lisp~ new file mode 100644 index 0000000..e8bfe1b --- /dev/null +++ b/main.lisp~ @@ -0,0 +1,71 @@ + +(ql:quickload "hunchentoot") +(ql:quickload "easy-routes") +(ql:quickload "djula") + +(setf *default-pathname-defaults* (uiop:getcwd)) + +;;;; if you're gonna run a public instance, change to the url other people +;;;; will use to connect! +(defvar *server-external-address* "http://localhost:8080/") +(defvar *server* nil) + +;; we probably don't actually need a template for the root, +;; it's more or less static anyhow. +;; i guess retrieving a paste is the only place that actually needs +;; the dynamic templating thingy + +(defparameter *root-template* + (uiop:read-file-string "root.html")) + +(defparameter *paste-template* + (uiop:read-file-string "paste.html")) + +;; google code +;; holy hell, actual business logic + +(defun get-paste-contents (id) + "read file lmao. also do some checks. we don't want LFI" + (let ((path (probe-file (concatenate 'string "bin/" id)))) + (if (and path + (not (search "." id)) + (not (search "/" id))) + (uiop:read-file-string path) + "err: bin not found"))) + + + +(defun render-root () + (djula:render-template* + (djula:compile-string *root-template*) + nil)) +(defun render-paste (id) + (djula:render-template* + (djula:compile-string *paste-template*) + nil + :contents (get-paste-contents id) + :link-home *server-external-address* + :link-bin (concatenate 'string *server-external-address* "bin/" id) + :link-raw (concatenate 'string *server-external-address* "raw/" id))) + +(easy-routes:defroute root ("/" :method :get) () + (render-root)) + +(easy-routes:defroute paste ("/bin/:n") () + (render-paste n)) + +(easy-routes:defroute raw ("/raw/:n") () + (get-paste-contents n)) + +;; todo: handle new pastes TODO: doesn't work, fix. +(easy-routes:defroute new ("/" :method :post) (content) + (format t "got somethin: ~a ~%" content)) + + +(defun start-server (&key (port 8080)) + (format t "Starting server on port ~a~%" port) + (force-output) + (setf *server* (make-instance 'easy-routes:easy-routes-acceptor :port port)) + (hunchentoot:start *server*)) +(defun stop-server () + (hunchentoot:stop *server*)) diff --git a/paste.html b/paste.html new file mode 100644 index 0000000..7554f65 --- /dev/null +++ b/paste.html @@ -0,0 +1,47 @@ + + + bin + + + + +
+ home + bin + raw +
+
+
+
{{ contents }}
+
+ + + diff --git a/paste.html~ b/paste.html~ new file mode 100644 index 0000000..7554f65 --- /dev/null +++ b/paste.html~ @@ -0,0 +1,47 @@ + + + bin + + + + +
+ home + bin + raw +
+
+
+
{{ contents }}
+
+ + + diff --git a/root.html b/root.html new file mode 100644 index 0000000..a14cee8 --- /dev/null +++ b/root.html @@ -0,0 +1,52 @@ + + + lispy pasty thingy + + + + + +
+

Lispy paste

+ +
+

New Paste:


+
+ +
+
+ + diff --git a/root.html~ b/root.html~ new file mode 100644 index 0000000..1e90460 --- /dev/null +++ b/root.html~ @@ -0,0 +1,44 @@ + + + lispy pasty thingy + + + + + +
+

Lispy paste

+ +
+ + +