diff options
author | bie <bie@blekksprut.net> | 2017-06-02 08:24:12 +0000 |
---|---|---|
committer | bie <bie@blekksprut.net> | 2017-06-02 08:24:12 +0000 |
commit | 3a7cdeb20edf7c57cfec9ec7f68e0277240a3fb7 (patch) | |
tree | 1ef690da43ef5f6161e65f6916a5f6fe203e5d03 /tears.cgi | |
parent | 61d54a847fe5dd79c945820bba5d42b8e357b4d3 (diff) | |
download | tears-3a7cdeb20edf7c57cfec9ec7f68e0277240a3fb7.tar.xz |
pusse pusse
Diffstat (limited to 'tears.cgi')
-rwxr-xr-x | tears.cgi | 112 |
1 files changed, 76 insertions, 36 deletions
@@ -4,9 +4,9 @@ VERSION=0.4 BASE="/tears" -HOST="zanthia.radionova.no" +HOST="happiest.place" -path=$(pdecode <<<"${PATH_INFO#/}") +path=$(/opt/bin/pdecode <<<"${PATH_INFO#/}") error() { echo -e "Content-Type: text/plain; charset=utf-8\n" @@ -15,7 +15,8 @@ error() { } irc() { - /opt/bin/birk -c radionova "$1" + echo >/dev/null + #/opt/bin/birk -c radionova "$1" } byline() { @@ -23,7 +24,7 @@ byline() { } info() { - stat -c '%n: %U %G %a %Y' $1 + stat -c '%n: %U %G %A %Y' $1 } link() { @@ -31,7 +32,9 @@ link() { local clean="/${raw%/}" local rawt="$BASE/$2" local cleant="/${rawt%/}" - [ $cleant = $clean ] && echo "$1" || echo "<a href='$BASE/$2'>$1</a>" + local target="" + [ -n "$3" ] && target=" target='$3'" + [ $cleant = $clean ] && echo "$1" || echo "<a$target href='$BASE/$2'>$1</a>" } qlink() { @@ -40,9 +43,11 @@ qlink() { } redirect() { - echo -e "Content-Type: text/html; charset=utf-8" - echo -e "Location: https://$HOST$1\n" + echo -ne "Location: https://$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() { @@ -63,33 +68,33 @@ kalender() { if [ -z "$y" ]; then for directory in $(cut -d / -f $((n + 2)) | sort | uniq); do year=$(basename $directory) - qlink "$year" "$action/$path" "dato=$year" "stikkord=$GET_stikkord" + qlink "$year" "$action/$args" "dato=$year" "stikkord=$GET_stikkord" done elif [ -z "$m" ]; then echo "<b>" - qlink "$y" "$action/$path" "stikkord=$GET_stikkord" + qlink "$y" "$action/$args" "stikkord=$GET_stikkord" echo "</b><br>" for directory in $(cut -d / -f $((n + 3)) | sort | uniq); do month=$(basename $directory) - qlink "$month" "$action/$path" "dato=$y-$month" "stikkord=$GET_stikkord" + qlink "$month" "$action/$args" "dato=$y-$month" "stikkord=$GET_stikkord" done elif [ -z "$d" ]; then echo "<b>" - qlink "$y" "$action/$path" "stikkord=$GET_stikkord" + qlink "$y" "$action/$args" "stikkord=$GET_stikkord" echo "/" - qlink "$m" "$action/$path" "dato=$y" "stikkord=$GET_stikkord" + qlink "$m" "$action/$args" "dato=$y" "stikkord=$GET_stikkord" echo "</b><br>" for directory in $(cut -d / -f $((n + 4)) | sort | uniq); do day=$(basename $directory) - qlink "$day" "$action/$path" "dato=$y-$m-$day" "stikkord=$GET_stikkord" + qlink "$day" "$action/$args" "dato=$y-$m-$day" "stikkord=$GET_stikkord" done else echo "<b>" - qlink "$y" "$action/$path" "stikkord=$GET_stikkord" + qlink "$y" "$action/$args" "stikkord=$GET_stikkord" echo "/" - qlink "$m" "$action/$path" "dato=$y" "stikkord=$GET_stikkord" + qlink "$m" "$action/$args" "dato=$y" "stikkord=$GET_stikkord" echo "/" - qlink "$d" "$action/$path" "dato=$y-$m" "stikkord=$GET_stikkord" + qlink "$d" "$action/$args" "dato=$y-$m" "stikkord=$GET_stikkord" echo "</b><br>" fi } @@ -121,12 +126,17 @@ liste() { n=$((${GET_n:-0} + 7)) $finder -printf '%h\t%TT\t%f\n' | sort -r | head -$n | tail -7 | while read do + ok=1 d=$(cut -f 1 <<<"$REPLY") f=$(cut -f 3 <<<"$REPLY") kort $d/$f done - echo "<hr><p>" - qlink "eldre artikler…" "$action/$path" "dato=$GET_dato" "n=$n" + if [ -z "$ok" ]; then + echo "<p><b>Ingen artikler</b>" + else + echo "<hr><p>" + qlink "eldre artikler…" "$action/$args" "dato=$GET_dato" "n=$n" + fi } stikkord() { @@ -143,7 +153,8 @@ stikk() { find -L stikkord -samefile "$1" -delete for ord in $2; do local path="stikkord/$ord/${1#artikler/}" - mkdir -p "$(dirname $path)" + umask 000 + mkdir -p -m 777 "$(dirname $path)" ln -s "../../../../../$1" "$path" done } @@ -155,7 +166,11 @@ skjema() { lupin -f <$1 echo "<p><label>Stikkord:</label>" echo "<input type='text' name='stikkord' value='$(stikkord $1)'>" - echo "<p><input type='submit' value='Lagre'>" + echo "<p>" + echo "<input type='submit' value='Lagre'>" + echo "<input name=delete type='submit' value='Slett'>" + echo "<input name=publish type='submit' value='Publiser'>" + [ -r "$1" ] && link "Vis" $(/opt/bin/pencode / <<<"vis/$1") preview echo "</form>" echo "<p><b>$(info $1)</b>" } @@ -167,13 +182,18 @@ vis() { } lagre() { - path=$(date +%Y/%m/%d -d $POST_publisert) + 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" - mkdir -m 777 -p "artikler/$path" - [ -z "$POST_privat" ] && umask 0002 + umask 0000 + mkdir -p "artikler/$path" lupin -l -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" @@ -182,34 +202,48 @@ lagre() { 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 -l -e >$1 irc "$(whoami) redigerte $POST_title" - redirect "$BASE/rediger/$path" + [ -n "$POST_publish" ] && chmod o+r "$1" + pushd /home/bie/maker >/dev/null; sudo -uwww ./maker; popd >/dev/null + redirect "$BASE/rediger/$1" } kort() { IFS=/. read -r type y m d hhmm slug ext <<< "$1" lupin -t -h <$1 echo "<p class='x'>$(byline $1), $y/$m/$d" - [ -r "$1" ] && echo "·" && link "vis" $(pencode / <<<"vis/$1") - [ -w "$1" ] && echo "·" && link "rediger" $(pencode / <<<"rediger/$1") + [ -r "$1" ] && echo "·" && link "vis" $(/opt/bin/pencode / <<<"vis/$1") + [ -w "$1" ] && echo "·" && link "rediger" $(/opt/bin/pencode / <<<"rediger/$1") lupin -s -h <$1 } +velkommen() { + echo "<blockquote><p>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.<p>Time to die.</blockquote>" +} + forbered() { - echo "<form method=post action='$BASE/lagre/$path'>" + echo "<h2>skriv en artikkel…</h2>" + echo "<form method=post action='$BASE/lagre'>" echo "<p><label>Overskrift:</label>" echo "<input type=text name=title size=24>" echo "<p><label>Dato:</label>" echo "<input type=date name=publisert value=$(date +%Y-%m-%d) size=10>" echo "<p><label>*</label>" echo "<select name='type'>" - for type in lupin/*; do + for type in lupin/*.lua; do id=$(basename $type .lua) - echo "<option value='$id'>$(sed 's|.|\U&|' <<<$id)</option>" + echo "<option value='$id'>$id</option>" done echo "</select>" echo "for" @@ -229,7 +263,12 @@ umask 0022 groups=$(groups | tr " " "\n" | sort) available=$(comm -12 - <(ls redaksjoner | sort) <<<"$groups") -action=$(basename $SCRIPT_FILENAME) +#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 @@ -237,18 +276,19 @@ mappe="artikler" [ -n "$GET_stikkord" ] && mappe="stikkord/$GET_stikkord" kilde="$mappe/$(sed 's|-|/|g' <<<$GET_dato)" finder="find -L $kilde -type f" -[ "$action" = gruppe ] && finder="$finder -group $path" +[ "$action" = gruppe ] && finder="$finder -group $args" [ "$action" = ditt ] && finder="$finder -user $REMOTE_USER" [ "$REQUEST_METHOD" = GET ] && $finder | meny case $action in + "") velkommen;; index.html|ditt|gruppe) liste;; skriv) forbered;; - rediger) skjema $path;; - vis) vis $path;; + rediger) skjema $args;; + vis) vis $args;; lagre) lagre;; - oppdater) oppdater $path;; - teatime) irc "$(whoami) <3 teatime"; echo "<p><img src='http://kyber.io/orz/src/1352063360909860.jpg'><br>";; - spökvåningen) echo "<p><img src='http://kyber.io/orz/src/1360086359591352.jpg'>";; + oppdater) oppdater $args;; + teatime) irc "$(whoami) <3 teatime"; echo "<p><img class='teatime' src='https://kyber.io/orz/src/1352063360909860.jpg'><br>";; + spökvåningen) echo "<p><img src='https://kyber.io/orz/src/1360086359591352.jpg'>";; todo) echo "<pre>$(cat TODO)</pre>";; esac %> |