Browse Source

no connectivity, yet

Danja Vasiliev 10 years ago
parent
commit
edfd6818da

+ 3 - 3
openwrt/common/etc/config/fstab

@@ -12,8 +12,8 @@ config 'global' 'automount'
 
 ## btrfs is not picked up here
 config 'mount'
-  option 'label'        'Sg_storage'
-  option 'target'       '/www/htdocs'
+  option 'label'        'sg'
+  option 'target'       '/mnt/sg'
   option 'enabled'      '1' 
   option 'enabled_fsck' '0' 
   option 'options'      'rw,noatime,nodiratime'
@@ -21,7 +21,7 @@ config 'mount'
 ## compatibility
 config 'mount'
   option 'label'        'sg-user'
-  option 'target'       '/www/htdocs'
+  option 'target'       '/mnt/sg'
   option 'enabled'      '1' 
   option 'enabled_fsck' '0' 
   option 'options'      'rw,noatime,nodiratime'

+ 4 - 4
openwrt/common/etc/crontabs/root

@@ -1,5 +1,5 @@
-1 6 * * *	  /sbin/logrotate /www/htdocs/logs/access.log \
-                            /www/htdocs/logs/error.log \
-                            /www/htdocs/logs/post.log \
-                            /www/htdocs/logs/admin.log; \
+1 6 * * *	  /sbin/logrotate /www/log/access.log \
+                            /www/log/error.log \
+                            /www/log/post.log \
+                            /www/log/admin.log; \
                             /etc/init.d/lighttpd restart

BIN
openwrt/common/www/lib/cgi/.post.sh.swp → openwrt/common/etc/lighttpd/.lighttpd.conf.swp


+ 26 - 0
openwrt/common/etc/lighttpd/compress.conf

@@ -0,0 +1,26 @@
+server.modules += (
+ "mod_compress"
+ )
+
+compress.cache-dir = "/www/tmp/compress"
+compress.max-filesize = "1024"
+compress.filetype = (
+    "application/atom+xml",
+    "application/javascript",
+    "application/json",
+    "application/rss+xml",
+    "application/vnd.ms-fontobject",
+    "application/x-font-ttf",
+    "application/x-web-app-manifest+json",
+    "application/xhtml+xml",
+    "application/xml",
+    "application/font-sfnt",
+    "font/opentype",
+    "image/svg+xml",
+    "image/x-icon",
+    "text/css",
+    "text/html",
+    "text/plain",
+    "text/x-component",
+    "text/xml",
+)

+ 55 - 88
openwrt/common/etc/lighttpd/lighttpd.conf

@@ -1,73 +1,39 @@
 server.modules = (
  "mod_access",
  "mod_cgi",
- "mod_compress",
  "mod_accesslog",
  "mod_rewrite",
  "mod_alias",
  "mod_auth",
  "mod_setenv",
- "mod_dirlisting",
-# "mod_status",
-# "mod_alias",
-# "mod_redirect",
+ "mod_status",
 # "mod_debug"
 )
 
-server.document-root = "/www/htdocs"
-server.upload-dirs = ( "/www/htdocs/tmp" )
-server.errorlog = "/www/htdocs/logs/error.log"
-accesslog.filename = "/www/htdocs/logs/access.log"
-server.pid-file = "/var/run/lighttpd.pid"
-server.username = "httpd"
-server.groupname = "nogroup"
-server.port = 80
+server.document-root =  "/www/htdocs"
+server.upload-dirs =  ( "/www/tmp" )
+server.errorlog =       "/www/log/error.log"
+accesslog.filename =    "/www/log/access.log"
+server.pid-file =       "/var/run/lighttpd.pid"
+server.username =       "httpd"
+server.groupname =      "nogroup"
+server.port =           80
 
-dir-listing.activate = "enable"
-dir-listing.hide-dotfiles = "enable"
-
-## defines var.superglueVersion from /etc/superglue_version
-include_shell "/etc/lighttpd/vars.sh"
-
-setenv.add-response-header = ( "X-Superglue-Version" => var.superglueVersion )
+#dir-listing.activate =   "enable"
+#dir-listing.hide-dotfiles = "enable"
 
 #debug.log-request-handling = "enable"
 #debug.log-request-header = "enable"
-#debug.log-file-not-found	= "enable"
+#debug.log-file-not-found = "enable"
 #debug.log-request-header-on-error = "enable"
 #debug.log-response-header = "enable"
 #debug.log-condition-handling	= "enable"
-
-auth.backend = "htdigest"
-auth.backend.htdigest.userfile = "/www/lib/admin/htpasswd"
 #auth.debug = 2
 
 #setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
-compress.cache-dir = "/www/htdocs/tmp/compress"
-compress.max-filesize = "1024" 
-compress.filetype = (
-    "application/atom+xml",
-    "application/javascript",
-    "application/json",
-    "application/rss+xml",
-    "application/vnd.ms-fontobject",
-    "application/x-font-ttf",
-    "application/x-web-app-manifest+json",
-    "application/xhtml+xml",
-    "application/xml",
-    "application/font-sfnt",
-    "font/opentype",
-    "image/svg+xml",
-    "image/x-icon",
-    "text/css",
-    "text/html",
-    "text/plain",
-    "text/x-component",
-    "text/xml",
-)
 
 index-file.names = (
-    "index.html", 
+    "index.html",
     "default.html"
 )
 
@@ -78,62 +44,63 @@ cgi.assign = (
 
 url.access-deny = ( "~", ".inc", ".htaccess", ".htpasswd", "htpasswd", "/tmp/" )
 
+auth.backend = "htdigest"
+auth.backend.htdigest.userfile = "/www/lib/htpasswd"
+auth.require = (
+  "/admin"  => (
+    "method"  =>  "digest",
+    "realm"   =>  "superglue",
+    "require" =>  "valid-user"
+  ),
+  "/log"  => (
+    "method"  =>  "digest",
+    "realm"   =>  "superglue",
+    "require" =>  "valid-user"
+  ),
+  "/server-status" => (
+    "method"  =>  "digest",
+    "realm"   =>  "superglue",
+    "require" =>  "valid-user"
+  )
+)
+
 $HTTP["request-method"] == "GET" {
   url.rewrite = (
     "^/resources/(.*)$" =>  "resources/$1",
     "^/devTools/(.*)$"  =>  "devTools/$1",
     "^/templates/(.*)$" =>  "templates/$1",
-    "^/admin/(.*)$"     =>  "admin/admin.sh"
   ),
   alias.url = (
     "/resources"  =>  "/www/lib/resources",
     "/devTools"   =>  "/www/lib/devTools",
     "/templates"  =>  "/www/lib/templates",
-    "/admin"      =>  "/www/lib/admin"
+    "/admin"      =>  "/www/lib/cgi/admin.cgi"
   )
-  ## override content and mime type for dotless files to text/html  
-  $HTTP["url"] !~ "(\.)" {                                                                 
-    setenv.add-response-header += (                                                         
-      "X-Superglue-Dotless" => "text/html Content-Type was forced",                        
-      "Content-Type" => "text/html"                                                        
-    )                                                                                      
+  ## override content and mime type for dotless files to text/html
+  $HTTP["url"] !~ "(\.)" {
+    setenv.add-response-header += (
+      "X-Superglue-Dotless" => "text/html Content-Type was forced",
+      "Content-Type" => "text/html"
+    )
   }
 }
 
 $HTTP["request-method"] == "POST" {
-#  url.rewrite = ( "^(/(?!admin).*)" => "post.cgi",
-  url.rewrite = (
-    "^(/(?!admin).*)" =>  "post.sh",
-    "^(/(admin).*)"   =>  "admin.sh" 
+  alias.url = (
+    "/admin"    =>  "/www/lib/cgi/admin.cgi",
+    ""          =>  "/www/lib/cgi/post.cgi"
   )
-#  $HTTP["url"] =~ "^/post.cgi" {
-  $HTTP["url"] =~ "^/post.sh" {
-    server.document-root = "/www/lib/cgi"
-  },
-  $HTTP["url"] =~ "^/admin.sh" {
-    server.document-root = "/www/lib/admin"
-  }
-}
-
-auth.require = ( 
-#  "/post.cgi" => ( "method" => "digest", 
-#                  "realm" => "superglue", 
-#                  "require" => "valid-user" ),
-  "/post.sh" => (
-    "method"  =>  "digest", 
-    "realm"   =>  "superglue", 
-    "require" =>  "valid-user"
-  ),
-  "/admin"  => (
-    "method"  =>  "digest", 
-    "realm"   =>  "superglue", 
-    "require" =>  "valid-user"
-  ),
-  "/logs"  => (
-    "method"  =>  "digest", 
-    "realm"   =>  "superglue", 
-    "require" =>  "valid-user"
+  auth.require = (
+    "" => (
+      "method"  =>  "digest",
+      "realm"   =>  "superglue",
+      "require" =>  "valid-user"
+    )
   )
-)
+}
 
-include "/etc/lighttpd/mime.conf"
+## reads optional conf files
+include_shell "/etc/lighttpd/opts.sh vhosts.conf mime.conf" # compress.conf
+## defines var.superglueVersion from /etc/superglue_version
+include_shell "/etc/lighttpd/vars.sh"
+setenv.add-response-header = ( "X-Superglue-Version" => var.superglueVersion )

+ 2 - 2
openwrt/common/etc/lighttpd/mime.conf

@@ -65,7 +65,7 @@ mimetype.assign             = (
   ".tgz"          =>      "application/x-tgz",
   ".torrent"      =>      "application/x-bittorrent",
   ".ttc"          =>      "application/x-font-ttf",
-  ".ttf"          =>  	  "application/font-sfnt",
+  ".ttf"          =>      "application/x-font-ttf",
   ".txt"          =>      "text/plain",
   ".vcf"          =>      "text/x-vcard",
   ".vtt"          =>      "text/vtt",
@@ -84,4 +84,4 @@ mimetype.assign             = (
   ".xwd"          =>      "image/x-xwindowdump",
   ".zip"          =>      "application/zip",
   ""              =>      "application/octet-stream"
-)
+)

+ 8 - 0
openwrt/common/etc/lighttpd/opts.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+_CONFDIR='/etc/lighttpd'
+
+for i in $*; do
+  printf '%b' 'include ' "\"$_CONFDIR/$i\""
+done
+

+ 2 - 2
openwrt/common/etc/lighttpd/vars.sh

@@ -1,3 +1,3 @@
-#!/bin/bash
+#!/bin/sh
 
-echo 'var.superglueVersion="'$(cat /etc/superglue_version)'"'
+printf '%b' 'var.superglueVersion=' "\"$(cat /etc/superglue_version)\"\n"

+ 23 - 0
openwrt/common/etc/lighttpd/vhosts.conf

@@ -0,0 +1,23 @@
+## primitive virtual host support
+
+$HTTP["host"] =~ "demo\.superglue\.it$" {
+  server.document-root = "/www/htdocs-demo" 
+  server.upload-dirs = ( "/www/tmp" )
+  server.errorlog = "/www/log/demo-error.log"
+  accesslog.filename = "/www/log/demo-access.log"
+
+  $HTTP["request-method"] == "GET" {
+    alias.url = (
+      "/resources"  =>  "/www/lib/resources",
+      ""            => "/www/lib/cgi/demo.cgi"
+    )
+  }
+
+  $HTTP["request-method"] == "POST" {
+    alias.url = (
+      ""          =>  "/www/lib/cgi/post.cgi"
+    )
+    ## disable authentication
+    auth.require = ""
+  }
+}

+ 33 - 39
openwrt/common/etc/rc.local

@@ -3,48 +3,42 @@
 ## tweaks
 sysctl -w vm.swappiness=10
 
-## checks specific to Superglue
+## some checks specific to Superglue
 
 ## where Superglue storage is mounted 
-_SG=/www/htdocs
+_SG=/mnt/sg
+## htdocs to bind to
+_HTDOCS=/www/htdocs
 
 ## mount if needed
-#mountpoint -q $_SG || block mount $_SG
-#mountpoint -q $_SG || mount -L sg-user -o rw,noatime,nodiratime $_SG
-
-## this seems to be the only way to mount btrfs on boot, ups                                ## (sleep 15; mount /dev/sda3 -o rw,noatime,nodiratime $_SG 
-
-## if /www/htdocs is mounted
-mountpoint -q $_SG && (
-
-  ## if not writable chown with httpd
-  [ $(stat $_SG -c %U) != 'httpd' ] && chown -R httpd $_SG
-  [ $(stat $_SG -c %a) -lt '755' ] && chmod -R u+rwX $_SG
-
-  ## check if index.html is present
-  [ -e $_SG/index.html ] || (
-      cp /www/lib/resources/index.html $_SG/default.html
-      chown httpd $_SG/default.html
-    )
-
-  ## check for log directory
-  [ -e $_SG/logs ] || (
-      mkdir $_SG/logs
-      chown httpd $_SG/logs
-      /etc/init.d/lighttpd reload
-    )
-
-  ## check for tmp directory
-  [ -e $_SG/tmp ] || (
-      mkdir $_SG/tmp
-      chown httpd $_SG/tmp
-    )
-
-  ## check for favicon
-  [ -e $_SG/favicon.ico ] || (
-      cp /www/lib/resources/img/favicon.ico $_SG/favicon.ico
-      chown httpd $_SG/favicon.ico
-    )
-)
+while ! mountpoint -q $_HTDOCS; do [ $n -gt 30 ] && break;
+  mount --bind $_SG/htdocs $_HTDOCS;
+  let n++
+done
+unset n
+mountpoint -q $_HTDOCS || ( echo 'failed to mount HTDOCS..'; exit 1; )
+
+## if /www/htdocs is mounted, then..
+  
+## if not writable chown with httpd
+[ $(stat $_HTDOCS -c %U) != 'httpd' ] && chown -R httpd $_HTDOCS
+[ $(stat $_HTDOCS -c %a) -lt '755' ] && chmod -R u+rwX $_HTDOCS
+
+## check if index.html is present
+[ -e $_HTDOCS/index.html ] || (
+  cp /www/lib/resources/demo.html $_HTDOCS/default.html
+  chown httpd $_HTDOCS/default.html
+  )
+
+## check for log directory
+[ -e /www/log ] || ( mkdir /www/log
+  chown httpd /www/log
+  /etc/init.d/lighttpd reload
+  )
+
+## check for tmp directory
+[ -e /www/tmp ] || ( mkdir /www/tmp
+  chown httpd /www/tmp
+  )
 
 exit 0

+ 1 - 1
openwrt/common/etc/sudoers.d/sg-suid

@@ -1 +1 @@
-httpd ALL=NOPASSWD: /www/lib/admin/suid.sh
+httpd ALL=NOPASSWD: /www/lib/cgi/suid.sh

BIN
openwrt/common/www/lib/cgi/.post.cgi.swp


+ 4 - 4
openwrt/common/www/lib/admin/admin.sh → openwrt/common/www/lib/cgi/admin.cgi

@@ -1,9 +1,9 @@
 #!/bin/bash
 
-_PWDFILE='/www/lib/htpasswd'
-
-_TMP='/www/htdocs/tmp'
-_LOG="/www/htdocs/logs/admin.log"
+_WWW='/www'
+_PWDFILE="${_WWW}/lib/htpasswd"
+_TMP="${_WWW}/tmp"
+_LOG="${_WWW}/log/admin.log"
 
 _DEBUG=1
 

+ 49 - 0
openwrt/common/www/lib/cgi/demo.cgi

@@ -0,0 +1,49 @@
+#!/bin/bash
+
+_WWW="/www"
+_SRC="${_WWW}/htdocs/demo.superglue.it/default-demo.html"
+_HTDOCS="${_WWW}/htdocs-demo"
+
+if ( [[ $REQUEST_URI != '/' ]] &&
+[[ -e $_HTDOCS/$REQUEST_URI ]] ); then
+  printf '%b' 'HTTP/1.1 200 OK\nAccess-Control-Allow-Origin: *\n\n'
+  cat $_HTDOCS/$REQUEST_URI
+  exit 0
+fi
+
+## http response
+headerPrint() {
+  case ${1} in
+    200) printf '%b' 'HTTP/1.1 200 OK\nAccess-Control-Allow-Origin: *\n';;
+    405) printf '%b' 'HTTP/1.1 405 Method Not Allowed\n';;
+    406) printf '%b' 'HTTP/1.1 406 Not Acceptable\n';;
+  esac
+  return 0
+}
+
+setCookie() {
+  printf '%b' 'Set-Cookie: ' "$1\n"
+}
+
+#_HASH=$(cat /dev/urandom | tr -dc 0-9 | head -c10)
+## is this slow?
+_HASH=($_HTDOCS/*)	## get all files
+_HASH=${#_HASH[@]}	## count files
+
+_PAGE="tryout-page-$_HASH"
+
+## set cookie of we have none
+if [[ -z $_PAGE ]]; then
+  setCookie $_HASH
+fi
+
+## see if we have a file matching the cookie
+if [[ -e $_HTDOCS/$_PAGE ]]; then
+  printf '%b' "HTTP/1.1 301 Moved Permanently\nLocation: http://demo.superglue.it/$_PAGE\n\n"
+  exit 0                                                                                 
+fi  
+
+## if neither URL or COOKIE is given then make a new demo page and direct user to it
+cat $_SRC/default-demo.html > $_HTDOCS/$_PAGE
+printf '%b' "HTTP/1.1 301 Moved Permanently\nLocation: http://demo.superglue.it/$_PAGE\n\n"
+exit 0

+ 7 - 2
openwrt/common/www/lib/cgi/post.sh → openwrt/common/www/lib/cgi/post.cgi

@@ -20,8 +20,13 @@ set -o noglob
 ## some path variables
 _WWW='/www'
 _HTDOCS="${_WWW}/htdocs"
-_TMP="${_HTDOCS}/tmp"
-_LOG="${_HTDOCS}/logs/post.log"
+_TMP="${_WWW}/tmp"
+_LOG="${_WWW}/log/post.log"
+
+## multihost
+#if [[ $HTTP_HOST == 'demo.superglue.it' ]]; then
+#  _HTDOCS="${_WWW}/htdocs-demo"
+#fi
 
 ## _DEBUG=0 no logging at all
 ## _DEBUG=1 writes to $_LOG file

+ 0 - 0
openwrt/common/www/lib/admin/suid.sh → openwrt/common/www/lib/cgi/suid.sh


+ 19 - 0
openwrt/common/www/lib/resources/demo.html

@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+		<meta name="generator" content="SuperGlue" data-superglue-version="1.0" data-superglue-settings="">
+		<title>Superglue demo page</title>
+		<style type="text/css" data-superglue="default-css">
+			body { margin: 0px; padding: 0px; }
+			#sg-page { position: relative; top: 0px; }
+			#sg-page.sg-page-centered { margin: 0px auto; }
+			.sg-element { position: absolute; overflow: hidden; }
+		</style>
+		<link rel="stylesheet" href="/resources/css/SuperGlue.css" data-superglue="text-css">
+	</head>
+	<body style="">
+		<div id="sg-page" data-superglue-grid="off/0px">
+		</div>
+	</body>
+</html>

+ 28 - 0
openwrt/common/www/lib/resources/failsafe.html

@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+		<meta name="generator" content="Superglue" data-superglue-version="1.0" data-superglue-settings="">
+		<title>Superglue failsafe</title>
+		<style type="text/css" data-superglue="default-css">
+			body { margin: 0px; padding: 0px; }
+			#sg-page { position: relative; top: 0px; }
+			#sg-page.sg-page-centered { margin: 0px auto; }
+			.sg-element { position: absolute; overflow: hidden; }
+		</style>
+		<link rel="stylesheet" href="/resources/css/SuperGlue.css" data-superglue="text-css">
+	</head>
+	<body style="background-color: rgb(153, 151, 161); background-repeat: repeat;">
+		<div id="sg-page" class="sg-page-centered" style="width: 1156px;" data-superglue-grid="off/7px">
+			<div class="sg-element" data-superglue-type="ImageElement" style="left: 193px; top: 93px; width: 105px; height: 225px;">
+	<div style="width: 100%; height: 100%; background-image: url(/resources/img/superglueLogo.png); background-repeat: repeat-y;"></div>
+			</div>
+			<div class="sg-element" data-superglue-type="TextElement" style="left: 313px; top: 193px; width: 270px; height: 55px;">
+<p style="font-size: 40px; font-family: Sans;"><span style="font-family: Montserrat;"><b><span style="font-size: 40px;">SUPERGLUE</span></b></span></p>
+			</div>
+			<div class="sg-element" data-superglue-type="TextElement" style="left: 315px; top: 266px; width: 456px; height: 80px;">
+<span style="font-size: 14px; font-family: Montserrat;"><b></b></span><span style="font-size: 14px; font-family: Montserrat;"><b><span style="color: rgb(214, 44, 44); font-size: 14px;">NO STORAGE IS AVAILABLE !!</span></b></span><div><font color="#d62c2c" face="Montserrat"><span style="font-size: 14px;"><b><br></b></span></font><div><b style="font-family: Montserrat; color: rgb(214, 44, 44);"><span style="font-size: 14px;">PLEASE MAKE SURE YOUR USB DRIVE IS CONNECTED</span></b><br></div></div>
+			</div>
+		</div>
+	</body>
+</html>

+ 0 - 0
openwrt/common/www/htdocs/log → openwrt/common/www/log


+ 0 - 0
openwrt/common/www/htdocs/tmp → openwrt/common/www/tmp


+ 1 - 1
openwrt/sg_0.1.revision

@@ -1 +1 @@
-7
+8