#!/usr/local/bin/haserl --shell=/bin/bash <% VERSION=0.1 BASE="/~bie/tears" HOST="low.radionova.no" path=$(pdecode <<<"${PATH_INFO#/}") error() { echo -e "Content-Type: text/plain; charset=utf-8\n" echo "$1" exit 1 } irc() { teatime -c '#radionova' "$1" } byline() { echo # noe som fungerer både på lunix og bsd her } info() { stat -c '%n: %U %G %a %Y' $1 } link() { [ "$BASE/$2" = $REQUEST_URI ] && echo "$1" || echo "$1" } qlink() { text="$1" && url="$BASE/$2" && shift 2 IFS=\& && echo -n "$text" } redirect() { echo "Content-Type: text/html" echo -e "Location: https://$HOST$1\n" echo "٩(͡๏̯͡๏)۶>" } kalender() { [ "$action" = index.html -o "$action" = ditt -o "$action" = gruppe ] || return echo "

for mye? reis i tid…" IFS=- read y m d <<<"$GET_dato" if [ -z "$y" ]; then for directory in $(cut -d / -f 2 | sort | uniq); do year=$(basename $directory) echo "$year" done elif [ -z "$m" ]; then echo "$y
" for directory in $(cut -d / -f 3 | sort | uniq); do month=$(basename $directory) echo "$month" done elif [ -z "$d" ]; then echo "$y/$m
" for directory in $(cut -d / -f 4 | sort | uniq); do day=$(basename $directory) echo "$day" done else echo "$y/$m/$d" fi } meny() { echo -e "Content-Type: text/html; charset=utf-8\n" echo "" echo "tears" echo "" echo "" echo "

" link "
$(figlet -f threepoint tears)
" "" echo "

hei, $(whoami) ♥
" link 'skriv en artikkel' 'skriv' echo "

du har tilgang til…
" link 'dine artikler' 'ditt' && echo "
" for group in $available; do link "$group" "gruppe/$group" done kalender echo "

kos deg! ٩(͡๏̯͡๏)۶" echo "

" } liste() { n=$((${GET_n:-0} + 7)) $finder -printf '%h\t%TT\t%f\n' | sort -r | head -$n | tail -7 | while read do d=$(cut -f 1 <<<"$REPLY") f=$(cut -f 3 <<<"$REPLY") kort $d/$f done echo "

" qlink "eldre artikler…" "$action/$path" "dato=$GET_dato" "n=$n" } tags() { find -L tags -samefile "$1" -execdir dirname {} + | while read file; do echo -n "${file##*/} " done # tag "$1" "$POST_tags" } tag() { echo "

" for tag in $2; do echo "-- sjekke om tag $tag er ok --" echo "
" echo ln -s "$1" "tags/$tag/$(tr / - <<<$1)" echo "
" done } skjema() { [ ! -f "$1" ] && echo "

finner ikke $1:

$(xxd <<<$1)
" && exit [ ! -w "$1" ] && echo "

du har ikke skrivetilgang" && exit echo "

" lupin -f <$1 echo "

" echo "" tag "$1" "ok test haha" echo "

" echo "

" echo "

$(info $1)" } vis() { [ ! -f "$1" ] && echo "

finner ikke $1:

$(xxd <<<$1)
" && exit [ ! -r "$1" ] && echo "

du har ikke lesetilgang" && exit lupin -h <$1 } lagre() { path=$(date +%Y/%m/%d -d $POST_publisert) slug=$(sed -e 's|[ /]|-|g' -e 's|[?:]||g' <<<$POST_title) [ -z "$slug" ] && error "Ugyldig overskrift" [ -f "artikler/$path/$slug.txt" ] && error "Artikkelen finnes allerede" mkdir -m 777 -p "artikler/$path" [ -z "$POST_privat" ] && umask 0002 lupin -l -e >"artikler/$path/$slug.txt" chgrp $POST_gruppe "artikler/$path/$slug.txt" irc "$(whoami) skriver ny artikkel: $POST_title" redirect "$BASE/rediger/artikler/$path/$slug.txt" } oppdater() { [ ! -f "$1" ] && error "finner ikke $1" [ ! -w "$1" ] && error "ikke skrivetilgang til $1" [ -z "$POST_title" ] && error "ingen overskrift" lupin -l -e >$1 irc "$(whoami) redigerte $POST_title" redirect "$BASE/rediger/$path" } kort() { IFS=/. read -r type y m d hhmm slug ext <<< "$1" ( read -r tittel echo "

$tittel

" "

$(byline $1), $y/$m/$d" [ -r "$1" ] && echo "·" && link "vis" $(pencode / <<<"vis/$1") [ -w "$1" ] && echo "·" && link "rediger" $(pencode / <<<"rediger/$1") [ -z "$2" ] && head -1 | marxup - || marxup - ) < $1 } forbered() { echo "

" echo "

" echo "" echo "

" echo "" echo "

" echo "" echo "for" echo "" echo "(privat artikkel?)" echo "

" echo "

" } [ -f tears.rc ] && . tears.rc umask 0022 groups=$(groups | tr " " "\n" | sort) available=$(comm -12 - <(ls redaksjoner | sort) <<<"$groups") action=$(basename $SCRIPT_FILENAME) kilde="artikler/$(sed 's|-|/|g' <<<$GET_dato)" finder="find $kilde -type f" [ "$action" = gruppe ] && finder="$finder -group $path" [ "$action" = ditt ] && finder="$finder -user $REMOTE_USER" [ "$REQUEST_METHOD" = GET ] && $finder | meny case $action in index.html|ditt|gruppe) liste;; skriv) forbered;; rediger) skjema $path;; vis) vis $path;; lagre) lagre;; oppdater) oppdater $path;; teatime) irc "$(whoami) <3 teatime"; echo "


";; spökvåningen) echo "

spök";; todo) echo "

$(cat TODO)
";; esac %>