Browse Source

admin updates

Danja Vasiliev 10 years ago
parent
commit
119a3e06d4

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

@@ -10,18 +10,10 @@ config 'global' 'automount'
   option  'from_fstab'  '1' 
   option  'anon_mount'  '0' 
 
-## btrfs is not picked up here
+## btrfs is not picked up here, see /opt/lib/scripts/sg-data-mount.sh
 config 'mount'
-  option 'label'        'sg'
+  option 'label'        'sg-data'
   option 'target'       '/www'
   option 'enabled'      '1' 
   option 'enabled_fsck' '0' 
-  option 'options'      'rw,noatime,nodiratime'
-
-## compatibility
-#config 'mount'
-#  option 'label'       'SUPERGLUE'
-#  option 'target'       '/mnt/sg'
-#  option 'enabled'      '1' 
-#  option 'enabled_fsck' '0' 
-#  option 'options'      'rw,noatime,nodiratime'
+  option 'options'      'rw,noatime,nodiratime,sync'

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

@@ -1 +1,5 @@
+## logrotation
 1 6 * * *	  /sbin/logrotate /www/log/*.log; /etc/init.d/lighttpd reload
+
+## dyndns
+*/5 * * * *   /opt/lib/scripts/dyndns-update.sh

+ 1 - 40
openwrt/common/etc/hotplug.d/block/99-sg-dirs

@@ -1,40 +1 @@
-#!/bin/ash
-
-set -o xtrace
-
-## USB drive should be already mounted here
-_WWW="/www"
-
-n=0
-while ! mountpoint -q $_WWW; do [ $n -gt 30 ] && exit 1;
-  sleep 1
-  let n++
-done
-unset n
-
-## if /www is mounted, then..
-_HTDOCS="$_WWW/htdocs"
-
-## make ./htdocs if there is none
-[ -e $_HTDOCS ] || mkdir $_HTDOCS
-## 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 /opt/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
-  )
-
-## check for tmp directory
-[ -e $_WWW/tmp ] || (
-  mkdir $_WWW/tmp
-  chown httpd $_WWW/tmp
-  )
+/opt/lib/scripts/sg-data-dirs.sh

+ 12 - 12
openwrt/common/etc/lighttpd/lighttpd.conf

@@ -47,11 +47,11 @@ url.access-deny = ( "~", ".inc", ".htaccess", ".htpasswd", "htpasswd", "/tmp/" )
 auth.backend = "htdigest"
 auth.backend.htdigest.userfile = "/opt/lib/htpasswd"
 auth.require = (
-  "/admin"  => (
-    "method"  =>  "digest",
-    "realm"   =>  "superglue",
-    "require" =>  "valid-user"
-  ),
+#  "/admin"  => (
+#    "method"  =>  "digest",
+#    "realm"   =>  "superglue",
+#    "require" =>  "valid-user"
+#  ),
   "/log"  => (
     "method"  =>  "digest",
     "realm"   =>  "superglue",
@@ -92,13 +92,13 @@ $HTTP["request-method"] == "POST" {
     "/admin"    =>  "/opt/lib/cgi/admin2.cgi",
     ""          =>  "/opt/lib/cgi/post.cgi"
   )
-  auth.require = (
-    "" => (
-      "method"  =>  "digest",
-      "realm"   =>  "superglue",
-      "require" =>  "valid-user"
-    )
-  )
+#  auth.require = (
+#    "" => (
+#      "method"  =>  "digest",
+#      "realm"   =>  "superglue",
+#      "require" =>  "valid-user"
+#    )
+#  )
 }
 
 ## can use this? per 

+ 4 - 1
openwrt/common/etc/sysctl.conf

@@ -1,6 +1,9 @@
 vm.swappiness = 10
 
-kernel.panic=3
+# reboot on OOM killer
+vm.panic_on_oom=1
+kernel.panic=5
+
 net.ipv4.conf.default.arp_ignore=1
 net.ipv4.conf.all.arp_ignore=1
 net.ipv4.ip_forward=1

+ 100 - 26
openwrt/common/opt/lib/cgi/admin2.cgi

@@ -13,17 +13,18 @@
 ## returns: 200 (+ output of operation) on success
 ##          406 (+ error message in debug mode) on error
 
-_WWW='/www'
-_PWDFILE="/opt/lib/htpasswd"
-_TMP="${_WWW}/tmp"
-_LOG="${_WWW}/log/admin.log"
-_DEBUG=1
+readonly _WWW='/www'
+readonly _PWDFILE="/opt/lib/htpasswd"
+readonly _TMP="${_WWW}/tmp"
+readonly _LOG="${_WWW}/log/admin.log"
+readonly _DEBUG=1
+readonly _IFS=$IFS
 
 err() {
   _ERR="$?"
   [[ "$_ERR" -gt 0 ]] || return 0
-  log "$1"
-  head "${2:='400'}"
+  logThis "$1"
+  headerPrint "${2:='400'}"
   exit "$_ERR"
 } 
 
@@ -87,7 +88,7 @@ setQueryVars() {
 runSuid() {
   local _SID=$(/usr/bin/ps -p $$ -o sid=)  ## pass session id to the child
   local _CMD=$@
-  sudo ./suid.sh $_CMD $_SID 2>/dev/null
+  /usr/bin/sudo ./suid.sh $_CMD $_SID 2>/dev/null
 }
 
 getQueryFile() {
@@ -295,6 +296,14 @@ updateFw() {
   showMesg 'Firmware update is completed, rebooting..' 'this might take up to 60 seconds'
 }
 
+usbInit() {
+  _OUT="$(runSuid /opt/lib/scripts/usb-part.sh)"
+  _ERR=$?
+  [[ $_ERR -gt 0 ]] && showMesg "usb init failed, $_OUT"
+  showMesg 'USB storage initialization is completed'
+#  logThis 'usb init..'
+}
+
 rebootNow() {
   logThis "reboot: now!"
   runSuid reboot
@@ -321,6 +330,41 @@ iwScan() {
   exit 0
 }
 
+findUsbstor() {
+  local _P='/sys/block/'
+  local _D _DEV
+  for _D in ${_P}sd*; do
+    _DEV=$(readlink -f ${_D}/device)
+    if [[ ${_DEV/usb} != $_DEV ]]; then
+      _USBDEV="/dev/${_D/$_P}"
+    fi
+  done
+  [[ $_USBDEV ]] || return 1
+}
+
+storageInfo() {
+  if mountpoint -q $_WWW; then
+    IFS=$'\n' _STOR=( $(df -h $_WWW) ) IFS=$_IFS
+    _STOR=( ${_STOR[1]} )
+  else
+    return 1
+  fi
+}
+
+swapInfo() {
+  IFS=$'\n' _SWAP=( $(runSuid swapon -s) ) IFS=$_IFS
+  if [[ ${_SWAP[1]} ]]; then
+    IFS=$'\t' _SWAP=( ${_SWAP[1]} ) IFS=$_IFS
+    ## for the lack of floats add trailing 0
+    ## divide by 1023 and split last digit by a period
+    _SWAP[1]="$((${_SWAP[1]}0/1023))"
+    _SWAP[1]="${_SWAP[1]%?}.${_SWAP[1]/??}M"
+  else
+    unset _SWAP
+    return 1
+  fi
+}
+
 doUci() {
   local _CMD=''
   local _ARG=''
@@ -381,7 +425,6 @@ doUci() {
   fi
 }
 
-. /opt/lib/scripts/jshn-helper.sh
 
 ## call with argument to inject additional lines
 ## ie: htmlhead "<meta http-equiv='refresh' content='2;URL=http://${HTTP_REFERER}'>"
@@ -417,6 +460,7 @@ if [[ "${REQUEST_METHOD^^}" == "POST" ]]; then
                *ssidchange) ssidChange;;
                   *lanaddr) lanAddr;;
                  *updatefw) updateFw;;
+                  *usbinit) usbInit;;
                 *rebootnow) rebootNow;;
                       *wan) wanSet;;
                    *uptime) upTime;;
@@ -427,31 +471,28 @@ if [[ "${REQUEST_METHOD^^}" == "POST" ]]; then
 fi
 
 headerPrint '200'
-## html head
 htmlHead
 
-sgver=$(cat /etc/superglue_version)
-devmod=$(cat /etc/superglue_model)
-openwrt=$(cat /etc/openwrt_version)
+read sgver < /etc/superglue_version
+read devmod < /etc/superglue_model
+read openwrt < /etc/openwrt_version
+
+. /opt/lib/scripts/jshn-helper.sh
 
 IFS=","
 wan=( $(ifaceStat wan) )
 IFS=$OFS
 
-#wanifname=$(doUci get wanifname || echo 'wlan0') ## TODO fix this
 wanifname=${wan[3]}
 wanproto=$(doUci get wanproto)
-#wanipaddr=$(doUci get wanipaddr) 
 wanipaddr=${wan[0]}
-#wannetmask=$(doUci get wannetmask)
 wangw=${wan[2]}
 wandns=${wan[5]}
 wanuptime=${wan[4]}
 wanssid=$(doUci get wanssid)
 wankey=$(doUci get wankey)
 
-
-logThis $wanifname
+#logThis $stor
 %>
 
 <body>
@@ -464,7 +505,7 @@ logThis $wanifname
 </section>
 
 <section>
-  <h2>Internet connection: <% _echo "IP:$wanipaddr, Gateway:$wangw, DNS:$wandns, up for $wanuptime seconds" %></h3>
+  <h2>Internet connection:</h2>
   <form method='post' action='/admin/wan' name='wan' id='wanconf'>
   <div style='display:inline-flex'>
   <div style='display:inline-block;'>
@@ -481,7 +522,7 @@ logThis $wanifname
     _echo "<option id=$wanssid selected>$wanssid</option>"
   fi %>
   </select>
-  <input type='password' name='wankey' value='<% _echo $wankey %>'>
+  <input type='password' name='wankey' placeholder='passphrase' value='<% _echo $wankey %>'>
 
   </fieldset>
 
@@ -493,9 +534,10 @@ logThis $wanifname
   <option value='dhcp' name='dhcp' id='dhcp' <% ([[ $wanproto == 'dhcp' ]] && _echo 'selected') %>>Automatic (DHCP)</option>
   <option value='stat' name='dhcp' id='stat' <% ([[ $wanproto == 'static' ]] && _echo 'selected') %>>Manual (Static IP)</option>
   </select>
-  <fieldset id='wanaddr' <% ( [[ $wanproto =~ ('static') ]] && _echo "class='show'" || _echo "class='hide'" ) %>>
-  <input type='text' name='wanipaddr' id='wanipaddr' value='<% _echo $wanipaddr %>'>
-  <input type='text' name='wangw' id='wannetmask' value='<% _echo $wannetmask %>'>
+  <fieldset id='wanaddr' >
+  <input type='text' name='wanipaddr' id='wanipaddr' value='<% _echo $wanipaddr %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='ip address'>
+  <input type='text' name='wangw' id='wangw' value='<% _echo $wangw %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='gateway/router'>
+  <input type='text' name='wandns' id='wandns' value='<% _echo $wandns %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='dns server'>
   </fieldset>
   </div>
   </div>
@@ -505,6 +547,14 @@ logThis $wanifname
   <span class='help'>help</span>
 </section>
 
+<section>
+  <h2>Domain name:</h2>
+  <input type='text' name='dnsname' id='dnsname' value='<% _echo $dnsname %>' placeholder='domain name'>
+  <input type='text' name='dnstoken' id='dnstoken' value='<% _echo $dnstoken %>' placeholder='dns token'>
+ 
+ <span class='help'>help</span>
+</section>
+
 <section>
 <h2>Local wireless network:</h2>
 <form method='post' action='/admin/ssidchange'>
@@ -515,7 +565,7 @@ logThis $wanifname
   </div>
   <div style='display:inline-block;'>
     <input type='text' name='lanipaddr' value='<% doUci get lanipaddr %>'>
-    <input type='hidden' name='iface' value='lan' class='inline'>
+    <input type='hidden' name='iface' value='lan'>
   </div>
   </div>
     <input type='submit' value='Apply'>  
@@ -523,6 +573,30 @@ logThis $wanifname
   <span class='help'>help</span>
 </section>
 
+<section>
+<h2>Storage:</h2>
+<% if findUsbstor; then %>
+
+  <% if storageInfo; then %>
+    <div>File storage: <% _echo "${_STOR[2]} used, ${_STOR[3]} available" %></div>
+    <div>Swap: <% swapInfo && _echo "${_SWAP[1]}" || _echo '<b>n/a</b>' %></div>
+  <% else %>
+    <div>USB storage device must be initialized</div>
+    <form method='post' action='/admin/usbinit'>
+    <input type='hidden' name='dev' value='<% _echo $_USBDEV %>'>
+    <input type='submit' value='Initialize'>
+    </form>
+  <% fi %>
+
+<% else %>
+
+  <div><h3>USB storage device not found!</h3>Please check and try again</div>
+
+<% fi %>
+
+<span class='help'>help</span>
+</section>
+
 <section>
 <h2>Change password:</h2>
 <form method='post' action='/admin/pwdchange'>
@@ -531,8 +605,8 @@ logThis $wanifname
     <input type='text' name='usr' value='admin' readonly>
   </div>
   <div style='display:inline-block;'>
-    <input type='password' name='pwd' value=''>
-    <input type='password' name='pwdd' value=''>
+    <input type='password' name='pwd' placeholder='password' value=''>
+    <input type='password' name='pwdd' placeholder='password again' value=''>
   </div>
   </div>
     <input type='submit' value='Apply'>

+ 6 - 0
openwrt/common/opt/lib/resources/admin/admin.css

@@ -200,4 +200,10 @@ span.help:active::after
   display: inline-block;
 }
 
+/* .grey {
+  background-color: #ddd;
+} */
 
+input:read-only { 
+    background-color: #ddd;
+}

+ 8 - 28
openwrt/common/opt/lib/resources/admin/admin.js

@@ -32,20 +32,25 @@ function wanChange(e) {
       iwScan();
       break;
     case 'dhcp':
-      wanaddr.setAttribute('class','hide');
+    //  wanaddr.setAttribute('class','hide');
+      for (var i = 0; i < wanaddr.children.length; i++) {
+        wanaddr.children[i].setAttribute('readonly', true);
+      }
       break;
     case 'eth':
       wanwifi.setAttribute('class','hide');
       break
     case 'stat':
-      wanaddr.setAttribute('class','show');
+    //  wanaddr.setAttribute('class','show');
+      for (var i = 0; i < wanaddr.children.length; i++) {
+        wanaddr.children[i].removeAttribute('readonly');
+}
       break;
   }
 }
 
 var wanssid = document.getElementById('wanssid');
 wanssid.addEventListener('focus', function(event) { 
-  console.log('scan now');
   iwScan();
   event.stopPropagation();
 });
@@ -77,7 +82,6 @@ function iwScan() {
   ajaxReq('POST', '/admin/iwscan', 'null', function(xmlDoc) {
     var res = JSON.parse(xmlDoc['response']);
     var stas = res['results'].sort(comp);
-    sss = stas;
     var wanssid = document.getElementById('wanssid');
     for (var i = 0; i < Object.keys(stas).length; i++) { 
 //      console.log(stas[i]['ssid']);
@@ -116,27 +120,3 @@ function ajaxReq(url, method, data, callback) {
   xmlDoc.send(data);
 }
 
-/*
-function formChange() {
-  if (document.activeElement.tagName.toLowerCase() !=  'select') {
-    console.log('not select');
-    return false;
-  }
-  aElem = document.activeElement;
-  aParent = aElem.parentElement;
-  sOpt = aElem[aElem.selectedIndex];
-  console.log(aElem.id + sOpt.id);
-  if (aElem.id + sOpt.id == 'wanprotostat') {
-    document.getElementById('wanaddr').setAttribute('class','show');
-  }
-  if (aElem.id + sOpt.id == 'wanprotodhcp') {
-    document.getElementById('wanaddr').setAttribute('class','hide');
-  }
-  if (aElem.id + sOpt.id == 'wanifnamewlan') {
-    document.getElementById('wanwifi').setAttribute('class','show');
-  }
-  if (aElem.id + sOpt.id == 'wanifnameeth') {
-    document.getElementById('wanwifi').setAttribute('class','hide');
-  }
-};
-*/

+ 5 - 0
openwrt/common/opt/lib/scripts/iw-scan.sh

@@ -1,5 +1,10 @@
 #!/bin/bash
 
+## SuperGlue project | http://superglue.it | 2014 | GPLv3
+## http://git.superglue.it/superglue/serverfiles
+##
+## iw-scan.sh - scan for wireless networks 
+
 iwScan() {
   set -o noglob
   local AP

+ 10 - 0
openwrt/sgproxy.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+_SRV='usr.superglue.it'
+
+while read x
+  do echo "$x"
+  done < <(ssh -N -T -R "$_SRV":0:localhost:80 sgproxy@"$_SRV" -p443  -o ExitOnForwardFailure=yes 2>&1)
+
+  #ssh -N -T -R usr.superglue.it:0:localhost:80 sgproxy@usr.superglue.it -p443  -o ExitOnForwardFailure=yes #-y -y
+