#!/usr/bin/haserl --shell=/bin/bash <% VERSION=0.4 path=$(/opt/bin/pdecode <<<"${PATH_INFO#/}") error() { echo -e "Content-Type: text/plain; charset=utf-8\n" echo "$1" exit 1 } irc() { echo >/dev/null #/opt/bin/birk -c radionova "$1" } byline() { echo "skrevet av $(ls -ld $1 | awk '{print $3}')" } info() { stat -c '%n: %U %G %A %Y' $1 } link() { local raw=${REQUEST_URI%\?*} local clean="/${raw%/}" local rawt="$BASE/$2" local cleant="/${rawt%/}" local target="" [ -n "$3" ] && target=" target='$3'" [ $cleant = $clean ] && echo "$1" || echo "$1" } qlink() { text="$1" && url="$BASE/$2" && shift 2 local IFS=\& && echo -ne "$text\n" } redirect() { echo -ne "Location: $SCHEME$HOST$1\r\n" echo -ne "Status: 302\r\n" echo -ne "Content-Type: text/html; charset=utf-8\r\n\r\n" echo "٩(͡๏̯͡๏)۶>" exit } stikkordsøk() { [ "$action" = index.html -o "$action" = ditt -o "$action" = gruppe ] || return echo "
" echo "

stikkordsøk" echo "
" echo "" 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" n=0 [ -n "$GET_stikkord" ] && n=1 if [ -z "$y" ]; then for directory in $(cut -d / -f $((n + 2)) | sort | uniq); do year=$(basename $directory) qlink "$year" "$action/$args" "dato=$year" "stikkord=$GET_stikkord" done elif [ -z "$m" ]; then echo "" qlink "$y" "$action/$args" "stikkord=$GET_stikkord" echo "
" for directory in $(cut -d / -f $((n + 3)) | sort | uniq); do month=$(basename $directory) qlink "$month" "$action/$args" "dato=$y-$month" "stikkord=$GET_stikkord" done elif [ -z "$d" ]; then echo "" qlink "$y" "$action/$args" "stikkord=$GET_stikkord" echo "/" qlink "$m" "$action/$args" "dato=$y" "stikkord=$GET_stikkord" echo "
" for directory in $(cut -d / -f $((n + 4)) | sort | uniq); do day=$(basename $directory) qlink "$day" "$action/$args" "dato=$y-$m-$day" "stikkord=$GET_stikkord" done else echo "" qlink "$y" "$action/$args" "stikkord=$GET_stikkord" echo "/" qlink "$m" "$action/$args" "dato=$y" "stikkord=$GET_stikkord" echo "/" qlink "$d" "$action/$args" "dato=$y-$m" "stikkord=$GET_stikkord" echo "
" fi } meny() { echo -e "Content-Type: text/html; charset=utf-8\n" echo "" echo "tears" echo "" echo "" 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 stikkordsøk echo "

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

" } liste() { n=$((${GET_n:-0} + 7)) finder="$finder -printf '%h\t%TT\t%f\n'" #$finder | sort -r | head -$n | tail -7 | while read path; do while read path; do d=$(cut -f 1 <<<"$path") f=$(cut -f 3 <<<"$path") ok=1 [ "$f" ] && kort $d/$f done <<< $(eval $finder | sort -r | head -$n | tail -7) if [ -z "$ok" ]; then echo "

Ingen artikler" else echo "


" qlink "eldre artikler…" "$action/$args" "dato=$GET_dato" "n=$n" fi } stikkord() { find -L stikkord -samefile "$1" | while read file; do local imp=${file#stikkord/} local ord=${imp%%/*} [ -z "$first" ] || echo -n " " echo -n "$ord" first=1 done } stikk() { find -L stikkord -samefile "$1" -delete for ord in $2; do local path="stikkord/$ord/${1#artikler/}" umask 000 mkdir -p -m 777 "$(dirname $path)" ln -s "../../../../../$1" "$path" done } skjema() { [ ! -f "$1" ] && echo "

finner ikke $1:

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

du har ikke skrivetilgang" && exit url=$(/opt/bin/pencode <<< $1) echo "

" lupin -f $1 echo "

" echo "" echo "

" echo "" echo "" echo "" [ -r "$1" ] && link "Vis" $(/opt/bin/pencode / <<<"vis/$1") preview echo "

" #echo "

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

finner ikke $1:

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

du har ikke lesetilgang" && exit echo "

" lupin $1 | /opt/bin/embed echo "
" } lagre() { path=$(tr '-' '/' <<< $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" umask 0000 mkdir -p "artikler/$path" lupin -p -e - >"artikler/$path/$slug.txt" if [ -z "$POST_privat" ]; then chmod 660 "artikler/$path/$slug.txt" else chmod 640 "artikler/$path/$slug.txt" fi 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" if [[ -n "$POST_delete" ]]; then rm "$1" redirect "$BASE" fi [ -z "$POST_title" ] && error "ingen overskrift" [ -z "$POST_stikkord" ] && error "ingen stikkord" stikk "$1" "$POST_stikkord" lupin -p -e - >$1 irc "$(whoami) redigerte $POST_title" [ -n "$POST_publish" ] && chmod o+r "$1" pushd /home/bie/maker >/dev/null; ./maker; popd >/dev/null redirect "$BASE/rediger/$1" } kort() { IFS=/. read -r type y m d hhmm slug ext <<< "$1" lupin -t $1 echo "

$(byline $1), $y/$m/$d" [ -r "$1" ] && echo "·" && link "vis" $(/opt/bin/pencode / <<<"vis/$1") [ -w "$1" ] && echo "·" && link "rediger" $(/opt/bin/pencode / <<<"rediger/$1") lupin -s $1 } velkommen() { echo "

I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhäuser Gate. All those moments will be lost in time, like tears in rain.

Time to die.

" } forbered() { echo "

skriv en artikkel…

" 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=${PATH_INFO#$BASE/} action=${PATH_INFO#/} if [[ "$action" =~ "/" ]]; then args=${action#*/} action=${action%%/*} fi if [[ "$action" == rediger && $path == stikkord/* ]]; then redirect "$BASE/rediger/artikler/${path#stikkord/*/}" fi mappe="artikler" [ -n "$GET_stikkord" ] && mappe="stikkord/$GET_stikkord" kilde="$mappe/$(sed 's|-|/|g' <<<$GET_dato)" finder="find -L $kilde -type f -not -name '*~'" [ "$action" = gruppe ] && finder="$finder -group $args" [ "$action" = ditt ] && finder="$finder -user $REMOTE_USER" [ "$REQUEST_METHOD" = GET ] && eval $finder | meny case $action in "") velkommen;; index.html|ditt|gruppe) liste;; skriv) forbered;; rediger) skjema $args;; vis) vis $args;; lagre) lagre;; oppdater) oppdater $args;; teatime) irc "$(whoami) <3 teatime"; echo "


";; spökvåningen) echo "

";; todo) echo "

$(cat TODO)
";; esac %>