From 3358ef733678ffd42a057a1cce900620d0a04dfe Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 31 Aug 2025 12:28:54 -0600 Subject: Really single anti-bot thingy --- org/cgi-bin/guest-book.cgi | 76 +++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 24 deletions(-) (limited to 'org/cgi-bin') diff --git a/org/cgi-bin/guest-book.cgi b/org/cgi-bin/guest-book.cgi index dfbe38f..9fb71bc 100755 --- a/org/cgi-bin/guest-book.cgi +++ b/org/cgi-bin/guest-book.cgi @@ -8,6 +8,7 @@ (use-modules (json)) (define guest-book-json-file "guest-book.json") +(define test-number-max 100) (define (decode-hex hex) (string (integer->char @@ -57,6 +58,17 @@ (close-output-port output) sanitized)) +(define (number-to-entity number) + (letrec ((process-digits + (lambda (digits) + (if (eq? digits '()) + "" + (string-append "&#" + (number->string (char->integer (car digits))) + ";" + (process-digits (cdr digits))))))) + (process-digits (string->list (number->string number))))) + (define (write-guest-to-json name url message) (let ((guest-book '()) (guest `(("name" . ,name) @@ -113,11 +125,18 @@ (if form (let ((name (sanitize-input (cdr (list-ref form 0)))) (url (sanitize-input (cdr (list-ref form 1)))) - (message (sanitize-input (cdr (list-ref form 2))))) + (message (sanitize-input (cdr (list-ref form 2)))) + (answer (string->number (sanitize-input (cdr (list-ref form + 3))))) + (first (string->number (sanitize-input (cdr (list-ref form 4))))) + (second (string->number (sanitize-input (cdr (list-ref form + 5)))))) (cond ((string= name "") ;; No name given (display "

name is required

")) ((string= message "") ;; No message given (display "

please write a silly something (:

")) + ((not (= (+ first second) answer)) + (display "

You suck at math lol

")) (else (write-guest-to-json name url message))))))) @@ -134,7 +153,10 @@ ;; Display pretty much everything (define (display-guest-book) - (display "Content-Type: text/html\n\n\ + (set! *random-state* (seed->random-state (time-second (current-time)))) + (let ((first-test-number (number-to-entity (random test-number-max))) + (second-test-number (number-to-entity (random test-number-max)))) + (format #t "Content-Type: text/html\n\n\ \n\ \n\ @@ -160,35 +182,41 @@
\n\ \n\ +

\n\ + Answer ~a plus ~a\n\ + \n\ + \n\ + \n\
\n\ \n\ You can't delete/edit it afterwards\n\ \n\

\n\ Be nice! Dont be a fucking ass.\n\ -

\n") - (handle-fields) - (display " \n
\n") - - ;; Try to read the guest book json - (with-exception-handler - (lambda (error) - (display "
\n\ +

\n" first-test-number second-test-number first-test-number + second-test-number) + (handle-fields) + (display "
\n
\n") + + ;; Try to read the guest book json + (with-exception-handler + (lambda (error) + (display "
\n\

No guest(s) have been added ): But you can be the first!

\n\ -
\n")) - (lambda () - (call-with-input-file guest-book-json-file - (lambda (fp) - (letrec ((guest-book (json->scm fp)) - (guest-loop - (lambda (index) - (display-guest (vector-ref guest-book index)) - (if (> index 0) - (guest-loop (- index 1)))))) - (guest-loop (- (vector-length guest-book) 1)))))) - #:unwind? #t) - - (display "\n\n")) + \n")) + (lambda () + (call-with-input-file guest-book-json-file + (lambda (fp) + (letrec ((guest-book (json->scm fp)) + (guest-loop + (lambda (index) + (display-guest (vector-ref guest-book index)) + (if (> index 0) + (guest-loop (- index 1)))))) + (guest-loop (- (vector-length guest-book) 1)))))) + #:unwind? #t) + + (display "\n\n"))) (define (main args) (display-guest-book)) -- cgit v1.2.3