diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | config.sh | 9 | ||||
-rwxr-xr-x | index.sh | 80 | ||||
-rwxr-xr-x | pages/contato.sh | 38 | ||||
-rw-r--r-- | static/styles.css | 83 | ||||
-rwxr-xr-x | utils/handle-post-upload.sh | 34 |
6 files changed, 218 insertions, 29 deletions
@@ -1,3 +1,6 @@ /pages/articles/* /artigos/* /articles/* +/attachment +/pages/contato +/static/tmp @@ -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" +) @@ -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="<p class='err-404'>404: .$REQUEST_URI: Arquivo ou diretório inexistente</p>" + ;; + 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="<p class='err-404'>404: .$REQUEST_URI: Arquivo ou diretório inexistente</p>" - ;; - esac + BODY="$(cat <<ERR +<p class='err-401'> + 401: .$POST_DESTINATION: Destino inválido, sem 1337 o suficiente. +</p> +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="<p class='err-404'>404: .$REQUEST_URI: Arquivo ou diretório inexistente</p>" + ;; + esac + fi } router @@ -102,6 +139,7 @@ esac cat <<INDEX Content-Type: $RESPONSE_CONTENT_TYPE Status: $STATUS +$EXTRA_HEADERS $RESPONSE_BODY INDEX diff --git a/pages/contato.sh b/pages/contato.sh index b54a64e..c63228f 100755 --- a/pages/contato.sh +++ b/pages/contato.sh @@ -30,6 +30,44 @@ cat <<PAGE </a> </address> </section> + + <section> + <h1>Ou...</h1> + + <p> + ...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. + </p> + + <form method="POST" action="/post" enctype="multipart/form-data"> + <input type="hidden" name="destination" value="/contato/comments" /> + + <label for="name">Nome</label> + <input id="name" type="text" name="name" value="Anônimo" /> + <br/> + + <label for="email">Email</label> + <input id="email" type="email" name="email" /> + <br/> + + <label for="message">Mensagem *</label> + <textarea id="message" name="message" required></textarea> + <small>Campos marcados com asterisco (*) são obrigatórios</small> + <br /> + + <label for="private-message">Mensagem privada + <input id="private-message" name="is_private" type="checkbox" /> + </label> + + <br /> + <label for="file-attachment">Anexar arquivo</label> + <input id="file-attachment" type="file" name="attachment" /> + + <input type="submit" value="Enviar" /> + </form> + </section> </article> 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" |