From a0d459807d87f76593dc4a1a68b4a909b403be19 Mon Sep 17 00:00:00 2001 From: Jefferson Julio Date: Tue, 1 Jun 2021 19:19:28 -0300 Subject: Handling POST multi/form-data uploads --- .gitignore | 3 ++ config.sh | 9 +++++ index.sh | 80 +++++++++++++++++++++++++++++++------------ pages/contato.sh | 38 +++++++++++++++++++++ static/styles.css | 83 ++++++++++++++++++++++++++++++++++++++++----- utils/handle-post-upload.sh | 34 +++++++++++++++++++ 6 files changed, 218 insertions(+), 29 deletions(-) create mode 100755 utils/handle-post-upload.sh diff --git a/.gitignore b/.gitignore index 1661d60..6c0d635 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /pages/articles/* /artigos/* /articles/* +/attachment +/pages/contato +/static/tmp diff --git a/config.sh b/config.sh index cfc02c1..ebc5027 100755 --- a/config.sh +++ b/config.sh @@ -11,3 +11,12 @@ ARTICLES_PATH=artigos/ # Exemple # ARTICLES_EXTS="txt|html|md" ARTICLES_EXTS="txt|html|md" + +# Pages, excluding the index "/"" +PAGES=( + "/contato" +) + +ALLOWED_POST_FOLDERS=( + "/contato/comments" +) diff --git a/index.sh b/index.sh index cd60cc0..4cac655 100755 --- a/index.sh +++ b/index.sh @@ -9,6 +9,7 @@ source ./config.sh RESPONSE_CONTENT_TYPE="text/html" STATUS=200 +EXTRA_HEADERS= HEADER_TITLE='cd programadores/;cd Jefferson\ Julio/;source jefferson.sh' HEADER_TITLE_MOBILE="$HEADER_TITLE" @@ -64,28 +65,64 @@ HTML router () { REQUEST_URI=$(urldecode "$REQUEST_URI") - case "$REQUEST_URI" in - /) - BODY=$(source ./pages/home.sh) - ;; - /contato) - HEADER_TITLE="source pages/contato.sh" + if [ "$REQUEST_METHOD" = "GET" ]; then + case "$REQUEST_URI" in + /) + BODY=$(source ./pages/home.sh) + ;; + /contato) + HEADER_TITLE="source pages/contato.sh" + HEADER_TITLE_MOBILE="$HEADER_TITLE" + BODY=$(source ./pages/contato.sh) + ;; + /$ARTICLES_PATH*) + ARTICLE_FILE=.$REQUEST_URI + HEADER_TITLE="ARTICLE_FILE=$(sanitize-filename "$ARTICLE_FILE");source pages/article.sh" + HEADER_TITLE_MOBILE="ARTICLE_FILE=$(sanitize-filename "$ARTICLE_FILE");source pages/article.sh" + BODY=$(source ./pages/article.sh) + ;; + *) + STATUS=404 + HEADER_TITLE="REQUEST_FILE=.$(sanitize-filename "$REQUEST_URI");source page.sh" + HEADER_TITLE_MOBILE="$HEADER_TITLE" + BODY="

404: .$REQUEST_URI: Arquivo ou diretório inexistente

" + ;; + esac + elif [ "$REQUEST_METHOD" = "POST" ]; then + source $SCRIPT_DIR/lib/cgibashopts/cgibashopts + + POST_DESTINATION="$FORM_destination" + + if [[ ! " ${ALLOWED_POST_FOLDERS[@]} " =~ " ${POST_DESTINATION} " ]]; then + STATUS=401 + HEADER_TITLE="POST_DESTINATION=$POST_DESTINATION;source jefferson.sh" HEADER_TITLE_MOBILE="$HEADER_TITLE" - BODY=$(source ./pages/contato.sh) - ;; - /$ARTICLES_PATH*) - ARTICLE_FILE=.$REQUEST_URI - HEADER_TITLE="ARTICLE_FILE=$(sanitize-filename "$ARTICLE_FILE");source pages/article.sh" - HEADER_TITLE_MOBILE="ARTICLE_FILE=$(sanitize-filename "$ARTICLE_FILE");source pages/article.sh" - BODY=$(source ./pages/article.sh) - ;; - *) - STATUS=404 - HEADER_TITLE="REQUEST_FILE=.$(sanitize-filename "$REQUEST_URI");source page.sh" - HEADER_TITLE_MOBILE="$HEADER_TITLE" - BODY="

404: .$REQUEST_URI: Arquivo ou diretório inexistente

" - ;; - esac + BODY="$(cat < + 401: .$POST_DESTINATION: Destino inválido, sem 1337 o suficiente. +

+ERR + )" + return 1 + fi + + POST_PATH="/pages$POST_DESTINATION" + POST_DESTINATION="${SCRIPT_DIR}/pages$POST_DESTINATION" + + mkdir -p "$POST_DESTINATION" + + case "$REQUEST_URI" in + /post) + source $SCRIPT_DIR/utils/handle-post-upload.sh + ;; + *) + STATUS=404 + HEADER_TITLE="REQUEST_FILE=.$(sanitize-filename "$REQUEST_URI");source page.sh" + HEADER_TITLE_MOBILE="$HEADER_TITLE" + BODY="

404: .$REQUEST_URI: Arquivo ou diretório inexistente

" + ;; + esac + fi } router @@ -102,6 +139,7 @@ esac cat < + +
+

Ou...

+ +

+ ...mande uma mensagem por aqui mesmo! Prencha o formulário abaixo que sua + mensagem será publicada. Ela por padrão será postada na área de mensagens abaixo, + marque a opção "privado" se não quiser que ela seja visível publicamente, + neste caso apenas a administração do site, eu, poderá ver. +

+ +
+ + + + +
+ + + +
+ + + + Campos marcados com asterisco (*) são obrigatórios +
+ + + +
+ + + + +
+
PAGE diff --git a/static/styles.css b/static/styles.css index ce4aeb6..77e1caa 100644 --- a/static/styles.css +++ b/static/styles.css @@ -149,16 +149,25 @@ template { /* jefferson.sh */ -@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap'); +/* @import url('https://fonts.googleapis.com/css2?family=VT323&display=swap'); */ + +@font-face { + font-family: 'White Rabbit'; + src: url(/static/whitrabt.ttf) +} html { --primary-bg: #2b2b2b; + --primary-bg-shadow: #2b2b2b; /* --primary-fg: #65d84a; */ --primary-fg: #0eff5d; + --primary-fg-shadow: #12e055; background-color: var(--primary-bg); color: var(--primary-fg); - font-family: 'VT323', monospace; + /* font-family: 'White Rabbit', monospace; */ + font-family: monospace; font-size: 18px; + text-shadow: 0 0 4px var(--primary-fg-shadow); position: relative; overflow: auto; /* scroll-behavior: smooth; */ @@ -171,7 +180,22 @@ html { } } -html:before { +html::before { + content: ' '; + display: block; + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: -1; + background-color: var(--primary-bg); + background-image: radial-gradient( + rgba(0, 150, 0, 0.5), var(--primary-bg) 120% + ); +} + +html::after { content: ' '; display: block; position: absolute; @@ -179,12 +203,19 @@ html:before { left: 0; bottom: 0; right: 0; - background: linear-gradient( - to bottom, - rgba(18, 16, 16, 0) 50%, - rgba(0, 0, 0, 0.25) 50% + /* background: linear-gradient( */ + /* to bottom, */ + /* rgba(18, 16, 16, 0) 50%, */ + /* rgba(0, 0, 0, 0.25) 50% */ + /* ); */ + /* background-size: 100% 3px; */ + background: repeating-linear-gradient( + 0deg, + rgba(0, 0, 0, 0.3) 1px, + rgba(0, 0, 0, 0.0) 4px, + transparent, + transparent 4px ); - background-size: 100% 3px; z-index: 99; pointer-events: none; } @@ -362,11 +393,13 @@ header > h2 { *::selection { background: var(--primary-fg); color: var(--primary-bg); + text-shadow: none; } *::-moz-selection { background: var(--primary-fg); color: var(--primary-bg); + text-shadow: none; } pre { @@ -376,6 +409,11 @@ pre { padding: 4px; } +[role=code]::first-line { + font-size: smaller; + border-bottom: 1px solid; +} + code { counter-increment: line; } @@ -386,3 +424,32 @@ code:before { margin-left: 4px; -webkit-user-select: none; } + +form { + display: flex; + flex-direction: column; +} + +input, textarea { + background-color: transparent; + border: 1px solid; + border-bottom-width: 2px; + color: var(--primary-fg); + margin: 4px 0px; +} + +form > input, +form > textarea { + width: 100%; +} + +form > textarea { + min-height: 100px; + max-width: 100%; + min-width: 100%; +} + +input[type=file]::-webkit-file-upload-button { + background-color: var(--primary-fg); + color: var(--primary-bg); +} diff --git a/utils/handle-post-upload.sh b/utils/handle-post-upload.sh new file mode 100755 index 0000000..1aff46c --- /dev/null +++ b/utils/handle-post-upload.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +export -p > $SCRIPT_DIR/static/tmp/1.headers +cat > $SCRIPT_DIR/static/tmp/1.body + +POST_NAME="$(ls "$POST_DESTINATION" | wc -l)" +POST_NAME="$(( POST_NAME + 1 ))" +NEW_POST_DESTINATION=""$POST_DESTINATION/$POST_NAME"" + +mkdir -p "$NEW_POST_DESTINATION" + +POST_FILES= + +if [ -d "$CGIBASHOPTS_DIR" ]; then + FILE_POST_PATH="/attachment$POST_PATH/$POST_NAME" + FILE_POST_DESTINATION="${SCRIPT_DIR}/attachment$POST_PATH/$POST_NAME" + + mkdir -p "$FILE_POST_DESTINATION" + + for file in "$CGIBASHOPTS_DIR/"*; do + cp "$file" "$FILE_POST_DESTINATION" + POST_FILES="${POST_FILES}$FILE_POST_PATH/$(basename "$file");" + done +fi + +cat << NEW_POST > "$NEW_POST_DESTINATION/post" +$FORM_is_private +$FORM_name +$FORM_email +$POST_FILES +$FORM_message +NEW_POST + +BODY="OK" -- cgit v1.2.3