From 7006b8bcaf3cb143f431715ae5aa8651d630bf87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 29 Sep 2021 23:51:07 +0200 Subject: [PATCH] video updating, custom login form --- index.cgi | 42 ++++++++++++++++++++++ page_channel.sh | 44 ++++++++++++++++++++--- page_video.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ rawnet.css | 69 +++++++++++++++++++++--------------- 4 files changed, 215 insertions(+), 34 deletions(-) create mode 100644 page_video.sh diff --git a/index.cgi b/index.cgi index f540aed..9beb6a9 100755 --- a/index.cgi +++ b/index.cgi @@ -1,5 +1,6 @@ #!/bin/sh +USER_REGISTRATION=false USER_REQUIREEMAIL=false . "${_EXEC:-${0%/*}}"/cgilite/cgilite.sh @@ -15,6 +16,47 @@ else markdown() { busybox awk -f "$_EXEC/cgilite/markdown.awk"; } fi +checked(){ + local check="$1"; shift 1; + for comp in "$@"; do + if [ "$check" = "$comp" ] || [ "$check" -eq "$comp" ]; then + printf 'checked="checked"' + break; + fi 2>/dev/null + done +} +selected(){ + local check="$1"; shift 1; + for comp in "$@"; do + if [ "$check" = "$comp" ] || [ "$check" -eq "$comp" ]; then + printf 'selected="selected"' + break; + fi 2>/dev/null + done +} + +w_user_login(){ + if [ ! "$USER_ID" ]; then + cat <<-EOF + [form #user_login .login method=POST + [label Login] + [input name=uname placeholder="Username or Email" autocomplete=off] + [input type=password name=pw placeholder="Passphrase"] + [submit "action" "user_login" Login] + $([ "$USER_REGISTRATION" = true ] && printf '[a href="%s/register/" Register]' "$_BASE") + ] + EOF + elif [ "$USER_ID" ]; then + cat <<-EOF + [form #user_login .logout method=POST + [p Logged in as [span . $(HTML ${USER_NAME})]] + $([ "$USER_REGISTRATION" != true ] && printf '[a href="%s/invite/" Invite Friend]' "$_BASE") + [submit "action" "user_logout" Logout] + ] + EOF + fi +} + yield_page(){ title="${1:-RAW:NET}" page="$2" printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \ diff --git a/page_channel.sh b/page_channel.sh index 159c865..57de476 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -101,20 +101,46 @@ update_channel(){ ;; newvideo) video="$(POST video |checkid)" - # database video create - REDIRECT "${_BASE}/channel/${channel}/${video}/" + + [ "$channel" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ + && mkdir -p -- "${_DATA}/${channel}/" + + if [ ! "$video" ]; then + REDIRECT "${_BASE}/channel/${channel}/#ERROR_INVALID_ID" + elif [ ! "$channel" ]; then + REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" + elif [ ! "$USER_ID" ]; then + REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" + elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then + REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" + elif LOCK "$vid_db"; then + if grep -q '^${video} ' "$vid_db"; then + RELEASE "$vid_db" + REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_EXISTS" + else + # ID NAME DESC RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE + printf '%s \\ \\ \\ \\ \\ \\ private %s \\ \\\n' \ + "$video" "$(STRING "$USER_ID")" \ + >>"$vid_db" + RELEASE "$vid_db" + REDIRECT "${_BASE}/channel/${channel}/${video}/edit" + fi + else + REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK" + fi ;; esac w_video(){ local CID="$1" thumb - local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE + local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE if read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE; then thumb="${_BASE}/${CID}/thumb_${ID}.jpg" + [ "$NAME" = \\ ] && NAME="(Unnamed Video)" cat <<-EOF [div .video - [h3 . $(UNSTRING "$NAME" |HTML)] - [img href="${thumb}" alt="$(UNSTRING "$DESCRIPTION" |HTML)"] + [h3 [a href="${ID}/" . $(UNSTRING "$NAME" |HTML)]] + [img href="${thumb}" alt="$(UNSTRING "$DESCR_CACHE")"] ] EOF else @@ -176,7 +202,15 @@ elif [ "$channel" ]; then ] [h1 .name $(HTML "$CHANNEL_NAME")] [div .description . ${CHANNEL_DESCR_CACHE}] + [h1 .videos Videos] [div .videos + $( [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ + && printf ' + [form .video .newvideo method=POST + [hidden "video" "%s"] + [submit "action" "newvideo" New Video] + ]' "$(timeid)" + ) $( [ -f "$vid_db" -a -r "$vid_db" ] \ && while w_video "$ID"; do :; done <"$vid_db" ) diff --git a/page_video.sh b/page_video.sh new file mode 100644 index 0000000..eca7be7 --- /dev/null +++ b/page_video.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +if [ "$video" -a -f "$vid_db" -a -r "$vid_db" ]; then + read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \ + VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \ + VIDEO_DESCR_CACHE VIDEO_FUTUREUSE <<-EOF + $(grep "^${video} " "${vid_db}") + EOF + if [ "$VIDEO_ID" ]; then + VIDEO_NAME="$(UNSTRING "$VIDEO_NAME")" + VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")" + VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")" + else + video='' + fi +fi + +# Video +# ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS (void|private|hidden|public) UPLOADER HITS DESCR_CACHE FUTUREUSE + +update_video(){ + local id="${1}" name="${2}" description="${3}" resx="${4}" resy="${5}" \ + length="${6}" cover="${7}" status="${8}" uploader="${9}" \ + hits="${10}" descr_cache="${11}" futureuse="${12}" + local ID INFO + + if LOCK "$vid_db"; then + while read -r ID INFO; do + if [ "$id" = "$ID" ]; then + # ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE + printf '%s %s %s %i %i %i %s %s %s %i %s %s\n' \ + "$id" "$(STRING "$name")" "$(STRING "$description")" "$resx" "$resy" "$length" \ + "$(STRING "$cover")" "${status:-void}" "${uploader:-\\}" "$hits" \ + "$(printf %s "$description" |markdown |STRING)" "${futureuse:-\\}" + else + printf '%s %s\n' "$ID" "$INFO" + fi + done <"$vid_db" >"${vid_db}.$$" + mv -- "${vid_db}.$$" "${vid_db}" + RELEASE "$vid_db" + else + return 1 + fi +} + + +[ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in + update_video) + if [ ! "$USER_ID" ]; then + REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN" + elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then + REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED" + elif update_video "$video" "$(POST name)" "$(POST description)" 0 0 0 \ + "" "void" "$USER_ID" 0 ""; then + REDIRECT "${_BASE}/channel/${channel}/${video}/#UPDATE_SUCCESS" + else + REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK" + fi + ;; + update_video_cancel) + REDIRECT "${_BASE}/channel/${channel}/${video}/#CANCELED" + ;; +esac + +if [ "$channel" -a "$video" -a "$action" = edit ]; then + yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF + [form .video .edit method=POST + [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name"] + [fieldset .status $([ $VIDEO_STATUS = void ] && printf "disabled=disabled") + [radio "status" "void" #status_private $(checked $VIDEO_STATUS private void)] + [label for=status_private tooltip="Video is only visible to channel authors" Private] + [radio "status" "void" #status_hidden $(checked $VIDEO_STATUS hidden)] + [label for=status_hidden tooltip="Video will not be listed but can be viewed by anyone knowing the URL" Hidden] + [radio "status" "void" #status_public $(checked $VIDEO_STATUS public)] + [label for=status_public tooltip="Video will be listed publicly" Public] + ] + [textarea name="description" placeholder="Description" . $(HTML "$VIDEO_DESCRIPTION")] + [submit "action" "update_video" . Update] + [submit "action" "update_video_cancel" . Cancel] + ] + EOF +elif [ "$channel" -a "$video" ]; then + yield_page "$VIDEO_NAME" "video edit" <<-EOF + [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")] + $( [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ + && printf ' - [a href="edit" edit]' + ) + ] + [h1 .name $(HTML "$VIDEO_NAME")] + [div .description . ${VIDEO_DESCR_CACHE}] + EOF +else + . "$_EXEC/page_404.sh" +fi diff --git a/rawnet.css b/rawnet.css index 472db1e..c397b2d 100644 --- a/rawnet.css +++ b/rawnet.css @@ -1,4 +1,5 @@ body { + background-position: right; background-size: 4pt 4pt; background-image: /* #6AF #6FF */ linear-gradient( 0deg, transparent 25%, rgba(128,128,128,.5) 25% 50%, transparent 50% 75%, rgba(192,192,192,.5) 75%), @@ -6,31 +7,33 @@ body { } header { - background-size: inherit; - background-position: right; - background-image: /* #6AF #6FF */ - linear-gradient( 0deg, rgba(0,0,0,.75) 0% 100%), - linear-gradient( 0deg, transparent 25%, rgba(128,128,128,.5) 25% 50%, transparent 50% 75%, rgba(192,192,192,.5) 75%), - linear-gradient(90deg, transparent 25%, rgba(128,128,128,.5) 25% 50%, transparent 50% 75%, rgba(192,192,192,.5) 75%), - linear-gradient( 0deg, #FFF 0% 100%); - padding: .25em; - box-shadow: #000 .25em .25em .25em; + background: inherit; + padding: .25em 12em; text-align: center; - padding-right: .25em 12em; + box-shadow: #000 .25em .25em .25em; z-index: 1; } +header > * { background: inherit; } +header:before, +header > *:before { + content: ''; position: absolute; + top: 0; right: 0; bottom: 0; left: 0; + background-color: rgba(0,0,0,.75); +} + +header a { color: #8CE; } + header #user_login { - background-size: inherit; - background-image: inherit; - box-shadow: inherit; position: absolute; - right: 0; top: 30.5pt; max-height: 0; + right: 0; top: 31pt; max-height: 0; + width: 12em; padding: 0 .5em; - transition: max-height linear .125s; text-align: center; - width: 12em; + box-shadow: inherit; + transition: max-height linear .125s; } + #user_login > * { position: relative; top: -2.5em; @@ -43,34 +46,35 @@ header #user_login:hover { } header #user_login > p { color: #EEE; - font-size: .875em; line-height: 1.125em; + font-size: .875em; + line-height: 1.125em; } header #user_login > p span { display: block; font-size: initial; line-height: 1.375em; } -header #user_login.login:before { - display: block; - content: "Login"; - position: relative; +header #user_login label { + top: -1.5em; font-size: 1.25em; text-decoration: underline; - top: -1.5em; padding-bottom: 1em; color: #EEE; text-align: right; } -header #user_login input, -header #user_login button { +header #user_login > * { display: none; } -header #user_login:hover input, -header #user_login:hover button { +header #user_login > :first-child, +header #user_login:hover > * { display: block; margin-left: auto; margin-right: auto; } +header #user_login:hover > a[href$="/register/"] { + text-align: right; + margin-top: .75em; +} main { background-color: rgba(255,255,255,.75); @@ -92,13 +96,16 @@ body.channel main h1.name { text-align: center; } body.channel main .description, -body.channel main form.edit.channel { +body.channel main form.edit, +body.video main form.edit { max-width: 40em; margin: auto; } -body.channel main form.edit.channel input[name=name], -body.channel main form.edit.channel textarea[name=description] { +body.video main form.edit input[name=name], +body.video main form.edit textarea[name=description], +body.channel main form.edit input[name=name], +body.channel main form.edit textarea[name=description] { display: block; width: 100%; margin-bottom: .5em; @@ -117,3 +124,7 @@ body.channels main .channel > .description { width: 140pt; background-color: #FFF; } + +body.channel .videos .video { + display: inline-block; +} -- 2.39.2