diff options
| author | nathansmith <nathansmith@posteo.com> | 2025-05-12 15:43:13 +0000 | 
|---|---|---|
| committer | nathansmith <nathansmith@posteo.com> | 2025-05-12 15:43:13 +0000 | 
| commit | 448f3a743d982518163abc15f0e1ddfedb30753d (patch) | |
| tree | 4ab1384c10de29c79ae0f89479e74f9ee436f5d2 /cgi-bin/guest_book_scm.cgi | |
| parent | 7dce1ba59c56c139050851a1bd533c2a0dcdc390 (diff) | |
| download | shittyweb-448f3a743d982518163abc15f0e1ddfedb30753d.tar.gz shittyweb-448f3a743d982518163abc15f0e1ddfedb30753d.tar.bz2 shittyweb-448f3a743d982518163abc15f0e1ddfedb30753d.zip  | |
Working on scheme guest book
Diffstat (limited to 'cgi-bin/guest_book_scm.cgi')
| -rwxr-xr-x | cgi-bin/guest_book_scm.cgi | 104 | 
1 files changed, 104 insertions, 0 deletions
diff --git a/cgi-bin/guest_book_scm.cgi b/cgi-bin/guest_book_scm.cgi new file mode 100755 index 0000000..3963b25 --- /dev/null +++ b/cgi-bin/guest_book_scm.cgi @@ -0,0 +1,104 @@ +#! /usr/bin/guile \ +-e main -s +!# + +(use-modules (ice-9 exceptions)) +(use-modules (json)) + +(define guest-book-json-file "cgi-bin/guest_book.json") + +;; Display a guest in the guest book +(define (display-guest guest) +  (let ((date (cdr (list-ref guest 0))) +        (message (cdr (list-ref guest 1))) +        (url (cdr (list-ref guest 2))) +        (name (cdr (list-ref guest 3)))) +    (format #t "    <table border=\"1\" width=\"60%\">\n\ +      <tr><td>\n\ +      <b>~a</b> <a href=\"~a\" target=\"_blank\">~a</a> --- signed ~a\n\ +      </td></tr>\n\ +      <tr><td>\n\ +      <p>~a</p>\n\ +    </table>\n\n" name url url date message))) + +;; Display pretty much everything +(define (display-guest-book) +  (display "Content-Type: text/html\n\n\ +<!DOCTYPE html>\n\ +<html>\n\ +<head>\n\ +  <title>Guest Book</title>\n\ +  <style>\n\ +body {\n\ +    color: black;\n\ +    background-image: url('../images/guest_book_background.png');\n\ +}\n\ +\n\ +table {\n\ +    color: black;\n\ +    background-color: #bebebe;\n\ +    margin-top: 10px;\n\ +    margin-bottom: 10px;\n\ +    margin-left: 10px;\n\ +    margin-right: 10px;\n\ +}\n\ +</style>\n\ +</head>\n\ +<body>\n\ +  <a href=\"../index.html\"><img src=\"../images/back_home.png\"\n\ +  alt=\"Back to home page\"/></a>\n\ +  <center>\n\ +    <table border=\"1\" width=\"60%\">\n\ +      <tr>\n\ +        <td>\n\ +          <h3>Sign my fucking guest book</h3>\n\ +          <form action = \"guest_book.cgi\" method = \"get\">\n\ +            <lable for = \"name\" maxlength=\"100\">Name</lable>\n\ +            <input type = \"text\" name = \"name\"/>\n\ +            <br/>\n\ +            <lable for = \"url\" maxlength=\"256\">Website (Optional)\n\ +            </lable>\n\ +            <input type = \"text\" name = \"url\"/>\n\ +            <br/><br/>\n\ +            <lable for = \"message\">Write a little silly something</lable>\n\ +            <br/>\n\ +            <textarea type = \"text\" name = \"message\" rows = \"4\"\n\ +            cols = \"40\" maxlength=\"512\"></textarea>\n\ +            <br/>\n\ +            <input type = \"submit\" value = \"Fucking submit\">\n\ +            <b>You can't delete/edit it afterwards</b>\n\ +          </form>\n\ +          <p>\n\ +            <b>Be nice! Dont be a fucking ass.</b>\n\ +          </p>\n\ +        </td>\n\ +      </tr>\n\ +    </table>\n\n") + +  ;; Try to read the guest book json +  (with-exception-handler +      (lambda (error) +        (display "    <table border=\"1\" width=\"60%\">\n\ +      <tr><td>\n\ +      <p>No guest have been added ): But you can be the first!</p>\n\ +      </td></tr>\n\ +    </table>\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 (- (vector-length guest-book) 1)) +                          (guest-loop (+ index 1)))))) +            (guest-loop 0))))) +    #:unwind? #t) + +  (display "  </center>\n\ +</body>\n\ +</html>\n")) + +(define (main args) +  (display-guest-book)) +  | 
