]> git.plutz.net Git - rawnet/blobdiff - index.cgi
For progress frame use chunked encoding instead of long poll
[rawnet] / index.cgi
index a2059e290bf84e58a20e733167123b3fa932d09c..76e3592a236f63bafe9d9171eae4cbe2db5373ed 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
 #!/bin/sh
 
-. "${_EXEC:-${0%/*}}"/cgilite/cgilite.sh
-. "$_EXEC"/cgilite/session.sh
-. "$_EXEC"/cgilite/file.sh
-. "$_EXEC"/cgilite/storage.sh
-. "$_EXEC"/widgets.sh
+USER_REGISTRATION=false
+USER_REQUIREEMAIL=false
 
-PATH_INFO="$(PATH "/${PATH_INFO#${_BASE}}")"
+. "${_EXEC:-${0%/*}}"/cgilite/cgilite.sh
+. "$_EXEC"/cgilite/session.sh nocookie
+. "$_EXEC"/cgilite/users.sh
 
-# bookmarks_cookie="$(COOKIE bookmarks |grep -xE '[0-9a-zA-Z:=]{16}(/[0-9a-zA-Z:=]{16})?( [0-9a-zA-Z:=]{16}(/[0-9a-zA-Z:=]{16})?)*')"
-bookmarks=''
-for bm in $(COOKIE bookmarks); do
-  [ -f "${_DATA}/$(checkid "${bm%/*}")" ] && bookmarks="${bookmarks}${bookmarks:+ }${bm}"
-done
-if [ "$bookmarks" ]; then
-  SET_COOKIE +$((182 * 86400)) bookmarks="${bm}" Path="${_BASE}/"
+export MD_HTML="false"
+if [ "$(which awk)" ]; then
+  markdown() { awk -f "$_EXEC/cgilite/markdown.awk"; }
+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:-Webpoll}" page="$2"
+  title="${1:-RAW:NET}" page="$2"
   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
                   "Content-Security-Policy: script-src 'none'" \
                   ''
-  { printf '[html
-    [head
-      [meta name="viewport" content="width=device-width"]
-      [link rel="stylesheet" type="text/css" href="%s/common.css"]
-      [link rel="stylesheet" type="text/css" href="%s/widgets.css"]
-      [link rel="stylesheet" type="text/css" href="%s/webpoll.css"]
-      [title %s]
-    ] [body class="%s"
-  ' "$_BASE" "$_BASE" "$_BASE" "$(HTML "$title")" "$page"
+  { cat <<-EOF
+       [!DOCTYPE HTML]
+       [html [head
+         [meta name="viewport" content="width=device-width"]
+         [link rel="stylesheet" type="text/css" href="$_BASE/cgilite/common.css"]
+         [link rel="stylesheet" type="text/css" href="$_BASE/rawnet.css"]
+         [title . $(HTML "$title")]
+       ] [body class="$page"
+         [header
+           [form method=POST action="$_BASE/search/"
+             [input name=search placeholder="Search"]
+           ]
+           $(w_user_login)
+         ][main
+       EOF
   cat
-  printf '] ]'
+  printf ']]]'
   } |"$_EXEC/cgilite/html-sh.sed" -u
 }
 
-pagename() {
-  local id="$1"
-  local file="$_DATA/$id"
-  if [ -f "$file" ]; then
-    DBM "$file" get title || printf 'Unnamed Page'
-  else
-    return 1;
-  fi
-}
-
-   page_home() { . "$_EXEC"/home.sh; }
-page_newdate() { . "$_EXEC"/newdate.sh; }
-   page_poll() { . "$_EXEC"/poll.sh; }
-
 case ${PATH_INFO} in
   /favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
-  /common.css) FILE "$_EXEC/cgilite/common.css";;
-  /widgets.css|/webpoll.css) FILE "${_EXEC}/${PATH_INFO}";;
-  /) page_home;;
-  /[0-9a-zA-Z:=]???????????????/[0-9a-zA-Z:=]???????????????) page_newdate;;
-  /*/newoptions);;
-  /[0-9a-zA-Z:=]???????????????) page_poll;;
-  /*) page_home;;
+  *.css)
+    . "${_EXEC}/cgilite/file.sh"
+    FILE "${_EXEC}/${PATH_INFO}"
+    ;;
+  /login/)
+    if [ "$USER_ID" ]; then
+      REDIRECT "${_BASE}/"
+    else
+      yield_page 'RAW:NET Login' login <<-EOF
+       $(w_user_login)
+       EOF
+    fi
+    ;;
+  /register/)
+    if [ "$USER_ID" -a "$(GET user_register)" = confirm ]; then
+      printf 'Refresh: 2; url=%s\r\n' "/${_BASE#/}"
+      yield_page "RAW:NET Register confirm" "message register_confirm" <<-EOF
+       User registration successful!
+       EOF
+      exit 0
+    fi
+    yield_page 'RAW:NET Register User' register <<-EOF
+       $(w_user_register)
+       EOF
+    ;;
+  /recover/)
+    yield_page 'RAW:NET Recover Account' recover <<-EOF
+       $(w_user_recover)
+       EOF
+    ;;
+  /invite/)
+    if [ "$USER_ID" -a "$(GET user_register)" = confirm ]; then
+      printf 'Refresh: 2; url=%s\r\n' "/${_BASE#/}"
+      yield_page "RAW:NET Account activation" "message invite_confirm" <<-EOF
+       Account activation successful!
+       EOF
+      exit 0
+    fi
+    yield_page 'RAW:NET Invite User' invite <<-EOF
+       [nav [a href="../" Channels] - [span Invite]]
+       $(w_user_invite)
+       EOF
+    ;;
+  /video/*/*.mp4|/video/*/*.webm|/video/*/*.jpg)
+    . "${_EXEC}/cgilite/file.sh"
+    FILE "${_DATA}/${PATH_INFO#/video/}"
+    ;;
+  /channel/*/*/*)
+    action="${PATH_INFO##*/}"
+    video="${PATH_INFO%/*}" video="${video##*/}"
+    channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+    . "$_EXEC/page_video.sh"
+    ;;
+  /channel/*/*/)
+    action=""
+    video="${PATH_INFO%/}" video="${video##*/}"
+    channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+    . "$_EXEC/page_video.sh"
+    ;;
+  /channel/*/*)
+    action="${PATH_INFO##*/}"
+    video=""
+    channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+    . "$_EXEC/page_channel.sh"
+    ;;
+  /channel/*/)
+    action=""
+    video=""
+    channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+    . "$_EXEC/page_channel.sh"
+    ;;
+  /|/channel/)
+    . "${_EXEC}/page_channel.sh"
+    ;;
+  /playlist/*) . "${_EXEC}/page_playlist.sh";;
+  /search/*) . "${_EXEC}/page_search.sh";;
+  *) . "${_EXEC}/page_404.sh";;
 esac
 
 exit 0