Danja Vasiliev 10 лет назад
Родитель
Сommit
724ac3d5ce

+ 1 - 0
openwrt/common/etc/dropbear/authorized_keys

@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLq3vU+Z4i0RNJOUwfHwKzJt6BRGyv5ILfrqxUiF5Wye6GtZ92QjFFBq30MKy25pFBfJVVsyRX5jaFRB9vb0fjhtLUQB4+zbF8tGuUWP0d9f218+AoAoaoUd59exmNbNrV4u9jvNDmPwuUdGhAhFipH3pD9Ll7p0QPMXBoDbJ4LhdZWEeE0CbO+Gqihiyq9In6IDI79O6odd69gNny7RvEyWmyFkjmShninqKz6Ly1VjiJ/8BUyKcM+8GCK3ZZkGR0b5CZSfi7k8cTvM4JVR6cTWZVCy9sFOzC7q8Hqx87+u1ktlJsC0pLttYwfXj2B7IQgVYPKJREFr7G0q4rdkN7 danja@beacon

+ 21 - 5
openwrt/common/opt/lib/cgi/admin2.cgi

@@ -290,6 +290,19 @@ rebootNow() {
   showMesg 'Rebooting..' 'this might take up to 60 seconds'
 }
 
+upTime() {
+  local _T="$(uptime)"
+  _ERR=$?
+  if [[ $_ERR -gt 0 ]]; then
+    headerPrint 406
+    exit 1
+  else
+    headerPrint 200
+    printf '%b' "$_T\n"
+    exit 0
+  fi
+}
+
 doUci() {
   local _CMD=''
   local _ARG=''
@@ -345,7 +358,7 @@ doUci() {
       runSuid /sbin/wifi || echo 'wifi: error'
     fi
     if [[ "$_ARG" == 'network' ]]; then
-      runSuid /etc/init.d/dnsmasq restart && runSuid /etc/init.d/network restart || echo 'network: error'
+      runSuid /etc/init.d/dnsmasq reload && runSuid /etc/init.d/network reload || echo 'network: error'
     fi
   fi
 }
@@ -405,6 +418,7 @@ if [[ "${REQUEST_METHOD^^}" == "POST" ]]; then
                  *updatefw) updateFw;;
                 *rebootnow) rebootNow;;
                       *wan) wanSet;;
+                   *uptime) upTime;;
                          *) logThis 'bad action'; headerPrint 405; 
                             echo 'no such thing'; exit 1;;
   esac
@@ -424,7 +438,9 @@ wannetmask=$(doUci get wannetmask)
 wanssid=$(doUci get wanssid)
 wankey=$(doUci get wankey)
 
-ipaddr="$(ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
+wanifname='eth0'
+
+ipaddr="$(runSuid ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
 %>
 
 <body>
@@ -433,7 +449,7 @@ ipaddr="$(ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
 
 <section class='inert'>
   <span style='display:block;'><% printf "System version: %s | Device: %s | OpenWRT: %s" "$sgver" "$devmod" "$openwrt" %></span>
-  <span style='display:block;'><% uptime %></span>
+  <span style='display:block;' id='uptime'><% uptime %></span>
 </section>
 
 <section>
@@ -445,7 +461,7 @@ ipaddr="$(ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
   <option value='eth0' id='eth' <% ( [[ $wanifname =~ ('eth') ]] && _echo 'selected' ) %> >Wired (WAN port)</option>
   <option value='wlan1' id='wlan' <% ( [[ $wanifname =~ ('wlan') ]] && _echo 'selected' ) %> >Wireless (Wi-Fi)</option>
   </select>
-  <fieldset id='wanwifi' class='hide'>
+  <fieldset id='wanwifi' <% ( [[ $wanifname =~ ('wlan') ]] && _echo "class='show'" || _echo "class='hide'" ) %>>
   <input type='text' name='wanssid' value='<% _echo $wanssid %>'>
   <input type='password' name='wankey' value='<% _echo $wankey %>'>
   </fieldset>
@@ -457,7 +473,7 @@ ipaddr="$(ifconfig $wanifname | sed -n '/dr:/{;s/.*dr://;s/ .*//;p;}')"
   <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' class='hide' >
+  <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>

+ 12 - 14
openwrt/common/opt/lib/resources/admin/admin.css

@@ -1,3 +1,13 @@
+@font-face {
+  font-family: TitilliumWeb;
+  src: url('/resources/fonts/Titillium_Web/TitilliumWeb-Regular.ttf') format('truetype');
+}
+@font-face { 
+  font-family: TitilliumWeb; 
+  font-weight: bold;
+  src: url('/resources/fonts/Titillium_Web/TitilliumWeb-Bold.ttf') format('truetype'); 
+}
+
 html {
   /* width: 1000px; */
   max-width: 1000px;
@@ -12,18 +22,14 @@ body {
 }
 
 input, select {
-  font-family: sans-serif;
-  font-size: 100%; 
+  font-family: TitilliumWeb;
+  font-size: 100%;
   color: #2c2c2c;
   display: block;
-  font-family: sans-serif;
-  font-size: 100%; 
   width: 200px;
   padding: 5px;
   margin: 5px 5px 0 0;
   border: 1px solid #666;
-  -moz-box-sizing: border-box;
-  -webkit-box-sizing: border-box;
   box-sizing: border-box; 
   background: #fcfcfc;
 }
@@ -194,12 +200,4 @@ span.help:active::after
   display: inline-block;
 }
 
-@font-face {
-  font-family: TitilliumWeb;
-  src: url('/resources/fonts/Titillium_Web/TitilliumWeb-Regular.ttf') format('truetype');
-}
-@font-face { 
-  font-family: TitilliumWeb; 
-  font-weight: bold;
-  src: url('/resources/fonts/Titillium_Web/TitilliumWeb-Bold.ttf') format('truetype'); }
 

+ 63 - 35
openwrt/common/opt/lib/resources/admin/admin.js

@@ -1,48 +1,76 @@
 (function() {
 
-/*
- * seems like there is not need to use getElementById
- * and instead access elements directly by their id
- */
+var uploadbtn = document.getElementById('uploadbtn');
+var uploadfile = document.getElementById('uploadfile');
 
-//  var uploadbtn = document.getElementById('uploadbtn');
-//  var uploadfile = document.getElementById('uploadfile')
-  uploadbtn.addEventListener('change', function () {
-    uploadfile.value = this.value.replace(/^.*\\/, "");
-    var len = uploadfile.value.length - 7;
-    uploadfile.setAttribute('size', len);
-    var len = uploadfile.offsetWidth;
-    uploadbtn.style.width = len + "px";
-  });
+uploadbtn.addEventListener('change', function () {
+  uploadfile.value = this.value.replace(/^.*\\/, "");
+  var len = uploadfile.value.length - 7;
+  uploadfile.setAttribute('size', len);
+  var len = uploadfile.offsetWidth;
+  uploadbtn.style.width = len + "px";
+});
 
-  var selects = wan.getElementsByTagName('select');
-  for (i = 0; i < selects.length; i++) { 
-    wanChange(selects[i]);
-  }
+/* onload check wanconf form selects and set accordingly */
+/*  var wanconf = document.getElementById('wanconf');
+var selects = wanconf.getElementsByTagName('select');
+for (i = 0; i < selects.length; i++) { 
+  wanChange(selects[i]);
+}
+*/
 
-  wanconf.addEventListener('change', function() { wanChange(event.target) });
+wanconf.addEventListener('change', function(event) { wanChange(event.target) });
 
-  function wanChange(e) {
-  //  var wanwifi = document.getElementById('wanwifi');
-  //  var wanaddr = document.getElementById('wanaddr');
-    switch (e[e.selectedIndex].id) {
-      case 'wlan':
-        wanwifi.setAttribute('class','show');
-        break;
-      case 'dhcp':
-        wanaddr.setAttribute('class','hide');
-        break;
-      case 'eth':
-        wanwifi.setAttribute('class','hide');
-        break
-      case 'stat':
-        wanaddr.setAttribute('class','show');
-        break;
-    }
+function wanChange(e) {
+  var wanwifi = document.getElementById('wanwifi');
+  var wanaddr = document.getElementById('wanaddr');
+
+  switch (e[e.selectedIndex].id) {
+    case 'wlan':
+      wanwifi.setAttribute('class','show');
+      break;
+    case 'dhcp':
+      wanaddr.setAttribute('class','hide');
+      break;
+    case 'eth':
+      wanwifi.setAttribute('class','hide');
+      break
+    case 'stat':
+      wanaddr.setAttribute('class','show');
+      break;
   }
+}
+
+/* update uptime output */
+(function uptimeUpdate(){
+  setTimeout(function(){
+    ajaxReq('POST', '/admin/uptime', 'null', function(xmlDoc) {
+      //console.log(xmlDoc['response'])
+      document.getElementById('uptime').innerHTML = xmlDoc['response'];
+    });
+    uptimeUpdate();
+  }, 5000);
+})();
+
 
 })();
 
+function ajaxReq(url, method, data, callback) {
+  var xmlDoc = new XMLHttpRequest();
+
+  xmlDoc.open(url, method, true);
+  if (method == 'POST') {
+    xmlDoc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+  }
+
+  xmlDoc.onreadystatechange = function() {
+    if (xmlDoc.readyState === 4 && xmlDoc.status === 200) {
+      callback(xmlDoc);
+    }
+  }
+  xmlDoc.send(data);
+}
+
 /*
 function formChange() {
   if (document.activeElement.tagName.toLowerCase() !=  'select') {