changeset 439:ebed26f4cae2

Begin rename.
author Aleksandr Rybalko <ray@ddteam.net>
date Thu, 20 Sep 2012 15:21:29 +0300
parents 76203decdeef
children 367c29234e4c
files profiles/dlink.ua.web/files/etc/dhclient-script profiles/dlink.ua.web/files/etc/favicon.ico profiles/dlink.ua.web/files/etc/mpd-linkdown profiles/dlink.ua.web/files/etc/mpd-linkup profiles/dlink.ua.web/files/etc/racoon/phase1-down.sh profiles/dlink.ua.web/files/etc/racoon/phase1-up.sh profiles/dlink.ua.web/files/etc/racoon/racoon.conf profiles/dlink.ua.web/files/etc/rc.d/collector profiles/dlink.ua.web/files/etc/rc.d/devd profiles/dlink.ua.web/files/etc/rc.d/httpd profiles/dlink.ua.web/files/etc/www/collector.lua profiles/dlink.ua.web/files/etc/www/collector.sh profiles/dlink.ua.web/files/etc/www/config.xml profiles/dlink.ua.web/files/etc/www/devd.lua profiles/dlink.ua.web/files/etc/www/devd.sh profiles/dlink.ua.web/files/etc/www/htdocs/Administration.config.html profiles/dlink.ua.web/files/etc/www/htdocs/Administration.firmware.html profiles/dlink.ua.web/files/etc/www/htdocs/Administration.info.html profiles/dlink.ua.web/files/etc/www/htdocs/Administration.users.html profiles/dlink.ua.web/files/etc/www/htdocs/Advanced.PPP.html profiles/dlink.ua.web/files/etc/www/htdocs/Basic.lan.html profiles/dlink.ua.web/files/etc/www/htdocs/Basic.wan.html profiles/dlink.ua.web/files/etc/www/htdocs/Basic.wlan.html profiles/dlink.ua.web/files/etc/www/htdocs/Security.IPSec.html profiles/dlink.ua.web/files/etc/www/htdocs/Security.OpenVPN.html profiles/dlink.ua.web/files/etc/www/htdocs/Security.SSH.html profiles/dlink.ua.web/files/etc/www/htdocs/cmd.xml profiles/dlink.ua.web/files/etc/www/htdocs/config.dat profiles/dlink.ua.web/files/etc/www/htdocs/css/anim.css profiles/dlink.ua.web/files/etc/www/htdocs/css/router.css profiles/dlink.ua.web/files/etc/www/htdocs/event.xml profiles/dlink.ua.web/files/etc/www/htdocs/footer.html profiles/dlink.ua.web/files/etc/www/htdocs/header.html profiles/dlink.ua.web/files/etc/www/htdocs/home_sys.html profiles/dlink.ua.web/files/etc/www/htdocs/img/FreeBSD_logo.png profiles/dlink.ua.web/files/etc/www/htdocs/img/banner.jpg profiles/dlink.ua.web/files/etc/www/htdocs/img/config.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/folder.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/help.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/home.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/join.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/joinbottom.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/line.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/logout.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/minus.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/minusbottom.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/monitor.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/open_file.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/open_folder.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/plus.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/plusbottom.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/sys.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/text.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/themespacer.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/tool.gif profiles/dlink.ua.web/files/etc/www/htdocs/img/tool_bar.jpg profiles/dlink.ua.web/files/etc/www/htdocs/img/tool_bar_v.jpg profiles/dlink.ua.web/files/etc/www/htdocs/img/triangle.gif profiles/dlink.ua.web/files/etc/www/htdocs/index.html profiles/dlink.ua.web/files/etc/www/htdocs/js/ajax.js profiles/dlink.ua.web/files/etc/www/htdocs/js/defineMyTree.js profiles/dlink.ua.web/files/etc/www/htdocs/js/tree.js profiles/dlink.ua.web/files/etc/www/htdocs/js/ua.js profiles/dlink.ua.web/files/etc/www/htdocs/js/utils.js profiles/dlink.ua.web/files/etc/www/htdocs/js/view.js profiles/dlink.ua.web/files/etc/www/htdocs/js/wizard.js profiles/dlink.ua.web/files/etc/www/htdocs/jstree_table.html profiles/dlink.ua.web/files/etc/www/htdocs/status.lua profiles/dlink.ua.web/files/etc/www/htdocs/vaps.lua profiles/dlink.ua.web/files/etc/www/httpd.lua profiles/dlink.ua.web/files/etc/www/httpd.sh profiles/dlink.ua.web/files/etc/www/lib/base64.lua profiles/dlink.ua.web/files/etc/www/lib/bit.lua profiles/dlink.ua.web/files/etc/www/lib/conf.lua profiles/dlink.ua.web/files/etc/www/lib/dhcpd.lua profiles/dlink.ua.web/files/etc/www/lib/handler.lua profiles/dlink.ua.web/files/etc/www/lib/hostapd.lua profiles/dlink.ua.web/files/etc/www/lib/ipcalc.lua profiles/dlink.ua.web/files/etc/www/lib/ltn12.lua profiles/dlink.ua.web/files/etc/www/lib/mime.lua profiles/dlink.ua.web/files/etc/www/lib/mpd.lua profiles/dlink.ua.web/files/etc/www/lib/node.lua profiles/dlink.ua.web/files/etc/www/lib/pidfile.lua profiles/dlink.ua.web/files/etc/www/lib/racoon.lua profiles/dlink.ua.web/files/etc/www/lib/socket.lua profiles/dlink.ua.web/files/etc/www/lib/socket/ftp.lua profiles/dlink.ua.web/files/etc/www/lib/socket/http.lua profiles/dlink.ua.web/files/etc/www/lib/socket/smtp.lua profiles/dlink.ua.web/files/etc/www/lib/socket/tp.lua profiles/dlink.ua.web/files/etc/www/lib/socket/url.lua profiles/dlink.ua.web/files/etc/www/lib/table.save-0.94.lua profiles/dlink.ua.web/files/etc/www/lib/test.lua profiles/dlink.ua.web/files/etc/www/lib/utils.lua profiles/dlink.ua.web/files/etc/www/lib/xml.lua profiles/dlink.ua.web/files/etc/www/log/.keepme profiles/dlink.ua.web/profile.mk
diffstat 95 files changed, 896 insertions(+), 6916 deletions(-) [+]
line wrap: on
line diff
--- a/profiles/dlink.ua.web/files/etc/dhclient-script	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/dhclient-script	Thu Sep 20 15:21:29 2012 +0300
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-LOG=/tmp/DHCLIENT-SCRIPT.log
+#LOG=/tmp/DHCLIENT-SCRIPT.log
+LOG=/dev/null
 
 touch ${LOG}
 echo "DHCLIENT-SCRIPT: $*" >> ${LOG}
@@ -40,7 +41,7 @@
         ifconfig ${interface} ${new_ip_address} netmask ${new_subnet_mask}
         echo "DHCP: iface=${interface} ip=${new_ip_address} netmask=${new_subnet_mask} route=${new_routers} dns=${new_domain_name_servers}" >> ${LOG}
         query="cmd=event"
-        query="${query}&eventtype=linkup"
+        query="${query}&state=up"
         query="${query}&iface=${interface}"
         query="${query}&gw=${new_routers}"
         query="${query}&ip=${new_ip_address}"
Binary file profiles/dlink.ua.web/files/etc/favicon.ico has changed
--- a/profiles/dlink.ua.web/files/etc/mpd-linkdown	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/mpd-linkdown	Thu Sep 20 15:21:29 2012 +0300
@@ -35,7 +35,7 @@
 echo "MPD: iface=${interface} proto = ${proto} localip=${localip} remoteip=${remoteip} dns1=${dns1} dns2=${dns2} peeraddress=${peeraddress}" >> ${LOG}
 
 query="cmd=event"
-query="${query}&eventtype=linkdown"
+query="${query}&state=down"
 query="${query}&iface=${interface}"
 query="${query}&proto=${proto}"
 query="${query}&gw=${remoteip}"
--- a/profiles/dlink.ua.web/files/etc/mpd-linkup	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/mpd-linkup	Thu Sep 20 15:21:29 2012 +0300
@@ -40,7 +40,7 @@
 
 echo "MPD: iface=${interface} proto = ${proto} localip=${localip} remoteip=${remoteip} dns1=${dns1} dns2=${dns2} peeraddress=${peeraddress}" >> ${LOG}
 query="cmd=event"
-query="${query}&eventtype=linkup"
+query="${query}&state=up"
 query="${query}&iface=${interface}"
 query="${query}&proto=${proto}"
 query="${query}&gw=${remoteip}"
--- a/profiles/dlink.ua.web/files/etc/racoon/phase1-down.sh	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/racoon/phase1-down.sh	Thu Sep 20 15:21:29 2012 +0300
@@ -13,7 +13,7 @@
 echo >>  ${LOG}
 
 query="cmd=event"
-query="${query}&eventtype=linkdown"
+query="${query}&state=down"
 query="${query}&iface=IPSec0"	# XXX: should use names for IPSec peers
 query="${query}&gw=${REMOTE_ADDR}:${REMOTE_PORT}"
 query="${query}&ip=${LOCAL_ADDR}:${LOCAL_PORT}"
@@ -21,5 +21,8 @@
 # Notify configuration handler
 fetch -qo - "http://127.0.0.1:8/event.xml?${query}"
 
+# XXX: should be handled by httpd/collector
+sh "/var/run/racoon.${REMOTE_ADDR}_down.sh"
+
 exit 0
 
--- a/profiles/dlink.ua.web/files/etc/racoon/phase1-up.sh	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/racoon/phase1-up.sh	Thu Sep 20 15:21:29 2012 +0300
@@ -13,7 +13,7 @@
 echo >>  ${LOG}
 
 query="cmd=event"
-query="${query}&eventtype=linkup"
+query="${query}&state=up"
 query="${query}&iface=IPSec0"	# XXX: should use names for IPSec peers
 query="${query}&gw=${REMOTE_ADDR}:${REMOTE_PORT}"
 query="${query}&ip=${LOCAL_ADDR}:${LOCAL_PORT}"
@@ -21,5 +21,8 @@
 # Notify configuration handler
 fetch -qo - "http://127.0.0.1:8/event.xml?${query}"
 
+# XXX: should be handled by httpd/collector
+sh "/var/run/racoon.${REMOTE_ADDR}_up.sh"
+
 exit 0
 
--- a/profiles/dlink.ua.web/files/etc/racoon/racoon.conf	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-path    pidfile  "/var/run/racoon.pid";
-path    pre_shared_key  "/var/db/racoon/racoon_psk.txt"; #location of pre-shared key file
-log     notify;  #log verbosity setting: set to 'notify' when testing and debugging is complete
-
-padding # options are not to be changed
-{
-        maximum_length  20;
-        randomize       off;
-        strict_check    off;
-        exclusive_tail  off;
-}
-
-timer   # timing options. change as needed
-{
-        counter         5;
-        interval        20 sec;
-        persend         1;
-#       natt_keepalive  15 sec;
-        phase1          30 sec;
-        phase2          15 sec;
-}
-
-listen  # address [port] that racoon will listening on
-{
-#        isakmp          192.168.90.1 [500];
-#        isakmp_natt     192.168.90.1 [4500];
-	adminsock "/var/db/racoon/racoon.sock" "root" "operator" 0660;
-}
-
-include "/var/run/racoon.links.conf";
-
--- a/profiles/dlink.ua.web/files/etc/rc.d/collector	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-# PROVIDE: collector
-# REQUIRE: MAIN
-# KEYWORD: nojail shutdown
-
-. /etc/rc.subr
-
-#[ -z "${collector_enable}" ] && collector_enable="YES"
-collector_enable="YES"
-name="collector"
-command="/etc/www/${name}.sh"
-rcvar=`set_rcvar`
-
-conf_file="/etc/${name}.conf"
-pidfile="/var/run/${name}.pid"
-
-command_args="-P ${pidfile} -B ${conf_file} &"
-#required_files="${conf_file}"
-#required_modules="wlan_xauth wlan_wep wlan_tkip wlan_ccmp"
-#extra_commands="reload"
-
-load_rc_config ${name}
-run_rc_command "$1"
--- a/profiles/dlink.ua.web/files/etc/rc.d/devd	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD: src/etc/rc.d/hostapd,v 1.3.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $
-#
-
-# PROVIDE: devd
-# REQUIRE: MAIN httpd
-# KEYWORD: nojail shutdown
-
-. /etc/rc.subr
-
-#[ -z "${devd_enable}" ] && devd_enable="YES"
-devd_enable="YES"
-name="devd"
-command="/etc/www/devd.sh"
-rcvar=`set_rcvar`
-
-conf_file="/etc/${name}.conf"
-pidfile="/var/run/${name}.pid"
-
-command_args="-P ${pidfile} -B ${conf_file} &"
-#required_files="${conf_file}"
-#required_modules="wlan_xauth wlan_wep wlan_tkip wlan_ccmp"
-#extra_commands="reload"
-
-load_rc_config ${name}
-run_rc_command "$1"
--- a/profiles/dlink.ua.web/files/etc/rc.d/httpd	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD: src/etc/rc.d/hostapd,v 1.3.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $
-#
-
-# PROVIDE: httpd
-# REQUIRE: MAIN collector
-# KEYWORD: nojail shutdown
-
-. /etc/rc.subr
-
-#[ -z "${httpd_enable}" ] && httpd_enable="YES"
-httpd_enable="YES"
-name="httpd"
-command="/etc/www/${name}.sh"
-rcvar=`set_rcvar`
-
-conf_file="/etc/${name}.conf"
-pidfile="/var/run/${name}.pid"
-
-command_args="-P ${pidfile} -B ${conf_file} &"
-#required_files="${conf_file}"
-#required_modules="wlan_xauth wlan_wep wlan_tkip wlan_ccmp"
-#extra_commands="reload"
-
-load_rc_config ${name}
-run_rc_command "$1"
--- a/profiles/dlink.ua.web/files/etc/www/collector.lua	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/collector.lua	Thu Sep 20 15:21:29 2012 +0300
@@ -17,6 +17,7 @@
 r = {};		-- Runtime varibles structure
 rquery = {};
 queue = {};
+local internet_led = nil;
 
 --
 -- Utility function:  URL encoding function
@@ -95,15 +96,18 @@
 		    r[iface][k] = v;
 		end
 	    end
-	    if q["eventtype"] == "linkup" then
+	    if q["state"] == "up" then
 		-- XXX: should not be here
 		-- XXX: must check exit code
-		exitcode = os.execute(
-		    "route change default  " .. r[iface]["gw"] .." > /dev/null 2>&1 || " ..
-		    "route add default  " .. r[iface]["gw"] .." > /dev/null 2>&1"
---		    "route change default -iface " .. iface .." > /dev/null 2>&1 || " ..
---		    "route add default -iface " .. iface .." > /dev/null 2>&1"
-		);
+		if r[iface]["gw"] then
+		    exitcode = os.execute(
+			"route change default  " .. r[iface]["gw"] .." > /dev/null 2>&1 || " ..
+			"route add default  " .. r[iface]["gw"] .." > /dev/null 2>&1"
+		    );
+		    if internet_led then
+			internet_led:set(1);
+		    end
+		end
 		local dns = {};
 		if q["dns1"] and q["dns1"]:len() >= 7 then
 		    table.insert(dns, q["dns1"]);
@@ -120,6 +124,13 @@
 		    resolv_conf:close();
 		end
 	    end
+	    if q["state"] == "down" then
+		if r[iface]["gw"] then
+		    if internet_led then
+			internet_led:set(0);
+		    end
+		end
+	    end
 
 	return "OK";
 
@@ -186,6 +197,10 @@
 dofile("lib/pidfile.lua");
 pidfile(opts["-P"]);
 
+dofile("lib/led.lua");
+
+internet_led = Led:new_from_env("INTERNET_LED");
+
 socket = require("socket");
 http = require("socket.http");
 server = assert(socket.bind(host, port));
--- a/profiles/dlink.ua.web/files/etc/www/collector.sh	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/collector.sh	Thu Sep 20 15:21:29 2012 +0300
@@ -5,7 +5,15 @@
 
 echo $$ > /var/run/collector.sh.pid
 
+INTERNET_LED=$(kenv -q INTERNET_LED)
+INTERNET_LED_INVERT=$(kenv -q INTERNET_LED_INVERT)
+
+export INTERNET_LED INTERNET_LED_INVERT
+
+./collector.lua > /var/log/collector.sh.log 2>&1
+exit 1
+
 while true; do
-    ./collector.lua
+    ./collector.lua > /var/log/collector.sh.log 2>&1
 done
 
--- a/profiles/dlink.ua.web/files/etc/www/config.xml	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/config.xml	Thu Sep 20 15:21:29 2012 +0300
@@ -20,6 +20,9 @@
             <!-- Values holders -->
             <dns1></dns1>
             <dns2></dns2>
+            <name>wan0pppoe</name>
+            <group>WAN</group>
+            <cost>10</cost>
         </PPPoE>
         <PPP enable="false" type="modem" onchange="iface_changed('interfaces.wan0.PPP')">
             <action>
@@ -44,6 +47,9 @@
             <!-- Values holders -->
             <dns1></dns1>
             <dns2></dns2>
+            <name>PPP</name>
+            <group>WAN</group>
+            <cost>1000</cost>
         </PPP>
         <Static enable="true" type="hw">
             <nat enable="true"></nat>
@@ -56,6 +62,9 @@
             <gateway>10.0.0.1</gateway>
             <dns1>10.0.0.1</dns1>
             <dns2>10.0.0.2</dns2>
+            <name>wan0</name>
+            <group>WAN</group>
+            <cost>100</cost>
         </Static>
     </wan0>
     <wlan0 enable="true" type="wlan">
@@ -63,7 +72,7 @@
             <exec>ifconfig wlan0 create wlandev wifi0 wlanmode hostap</exec>
         </create>
         <init>
-            <exec>ifconfig wlan0 country UA channel 6 ht ssid DIR-620</exec>
+            <exec>ifconfig wlan0</exec>
         </init>
         <wlan_interface>wifi0</wlan_interface>
         <channel>6</channel>
@@ -82,14 +91,16 @@
     </lan0>
     <bridge0 type="bridge">
         <create>
-            <exec>ifconfig wlan0 ether `kenv LAN_MAC_ADDR` down</exec>
-            <exec>ifconfig lan0 ether `kenv LAN_MAC_ADDR` down</exec>
+            <exec>ifconfig wlan0 down</exec>
+            <exec>ifconfig lan0 down</exec>
             <exec>ifconfig bridge0 create addm lan0 addm wlan0 up</exec>
+            <exec>ifconfig bridge0 down</exec>
+            <exec>ifconfig bridge0 ether `kenv LAN_MAC_ADDR`</exec>
             <exec>ifconfig lan0 up</exec>
             <exec>ifconfig wlan0 up</exec>
+            <exec>ifconfig bridge0 up</exec>
         </create>
         <init>
-            <exec order="3">ifconfig bridge0 ether `kenv LAN_MAC_ADDR`</exec>
         </init>
         <ipaddr>192.168.0.1/24</ipaddr>
         <lagg_interfaces>lan0,wlan0</lagg_interfaces>
@@ -147,15 +158,23 @@
     <nameserver order="100">8.8.8.8</nameserver>
     <nameserver order="101">8.8.4.4</nameserver>
 </resolve>
+<igmp>
+    <instance id="0" enable="false">
+	<up>wan0</up>
+	<down>wlan0</down>
+    </instance>
+    <instance id="0" enable="false">
+	<up>wan0</up>
+	<down>lan0</down>
+    </instance>
+</igmp>
 <info>
-    <hostname>dir620.dlink.ua</hostname>
-    <model>DIR-620</model>
-    <rev>A1</rev>
+    <hostname>zrouter</hostname>
     <location>home</location>
     <firmware>
 	<!-- XXX: version and build date should be here -->
-        <version>DIR-620_0.1</version>
-        <date>Mon 6 Jun 14:27:48 2011</date>
+        <version>???</version>
+        <date>????</date>
         <update_url>http://www.dlink.ua/files/products/ftp/pub/Router/DIR-620/Firmware/FreeBSD/D-Link_DIR-620-last.txt</update_url>
     </firmware>
 </info>
@@ -170,13 +189,17 @@
         <hw_mode>g</hw_mode>
         <ctrl_interface>/var/run/hostapd</ctrl_interface>
         <ctrl_interface_group>wheel</ctrl_interface_group>
-        <ssid>DIR-620</ssid>
+        <ssid>zrouter</ssid>
+        <channel>6</channel>
         <!-- Open -->
-        <wpa>0</wpa>
+        <wpa>3</wpa>
         <!-- WPA -->
         <!-- <wpa>1</wpa> -->
         <!-- RSN/WPA2 -->
         <!-- <wpa>2</wpa> -->
+        <wpa_passphrase>freebsdmall</wpa_passphrase>
+        <wpa_key_mgmt>WPA-PSK</wpa_key_mgmt>
+        <wpa_pairwise>CCMP TKIP</wpa_pairwise>
     </instance>
     <instance id="1" enable="false">
         <ieee80211d>1</ieee80211d>
@@ -188,7 +211,7 @@
         <hw_mode>g</hw_mode>
         <ctrl_interface>/var/run/hostapd</ctrl_interface>
         <ctrl_interface_group>wheel</ctrl_interface_group>
-        <ssid>DIR-620</ssid>
+        <ssid>zrouter</ssid>
         <!-- WPA -->
         <!-- <wpa>1</wpa> -->
         <!-- RSN/WPA2 -->
@@ -210,7 +233,7 @@
     <port>80</port>
 </http>
 <ipsec>
-    <remote id="0" enable="true">
+    <remote id="0" enable="false">
 	<gateway>10.0.0.2:500</gateway>
         <exchange_mode>main,aggressive</exchange_mode>
         <my_identifier>address 10.0.0.1</my_identifier>
--- a/profiles/dlink.ua.web/files/etc/www/devd.lua	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/devd.lua	Thu Sep 20 15:21:29 2012 +0300
@@ -10,29 +10,15 @@
 serverhost = serverhost or "127.0.0.1";
 serverport = serverport or "80";
 
---
--- Utility function:  URL encoding function
---
-function urlEncode(str)
-    if (str) then
-        str = string.gsub (str, "\n", "\r\n")
-        str = string.gsub (str, "([^%w ])",
-            function (c) return string.format ("%%%02X", string.byte(c)) end)
-        str = string.gsub (str, " ", "+")
-    end
-    return str
-end
+-- redirect print to /dev/console
+-- dofile("lib/print_to_console.lua");
 
+-- redirect print to syslog
+dofile("lib/lsyslog.lua");
+syslog_init("devd.lua");
 
---
--- Utility function:  URL decode function
---
-function urlDecode(str)
-    str = string.gsub (str, "+", " ")
-    str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
-    str = string.gsub (str, "\r\n", "\n")
-    return str
-end
+-- urlEncode/urlDecode
+dofile("lib/urlXxcode.lua");
 
 function tab_to_query(t)
     local ret = "event=devd";
@@ -57,6 +43,13 @@
 
 end
 
+function exec_output(cmd)
+	fp = io.popen(cmd, "r");
+	data = fp:read("*a");
+	fp:close();
+	return data;
+end
+
 function system_event(config, msg)
     -- !system=IFNET subsystem=rt0 type=ATTACH
     -- !system=DEVFS subsystem=CDEV type=CREATE cdev=usb/0.1.1
@@ -66,6 +59,20 @@
     -- !system=GPIO subsystem=pin14 type=PIN_LOW bus=gpiobus0 period=0
     -- !system=GPIO subsystem=pin14 type=PIN_HIGH bus=gpiobus0 period=0
 
+    function generic_event(m, msg)
+	-- Relay to main control logic
+	local query = "cmd=event" ..
+	    "&system=" .. m.system ..
+	    "&subsystem=" .. m.subsystem ..
+	    "&type=" .. m.type ..
+	    "&data=" .. urlEncode(msg);
+	-- cmd=event&iface=wan0&state=linkup;
+	print("devd.lua: query master with \"" .. query .. "\"");
+	if call_server(config, query) == false then
+	    -- XXX error handling
+	end
+    end
+
     local m = {};
 
     if not msg then
@@ -80,14 +87,62 @@
     if m.system and m.subsystem and m.type then
 	if     m.system == "IFNET" then
 	    -- Interfaces
+	    -- system=IFNET subsystem=lan0 type=LINK_UP
+	    local linkstate;
+	    if m.type == "LINK_UP" then
+		if m.subsystem == "lan0" then
+		    -- XXX: bug workaround, we have to check why UP does not unplumb iface
+		    os.execute("ifconfig lan0 down");
+		    os.execute("ifconfig lan0 up");
+		end
+		linkstate = "linkup";
+	    elseif m.type == "LINK_DOWN" then
+		linkstate = "linkdown";
+	    else
+		generic_event(m, msg);
+		return (nil);
+	    end
+	    local query = "cmd=event" ..
+		"&iface=" .. urlEncode(m.subsystem) ..
+		"&state=" .. linkstate;
+	    -- cmd=event&iface=wan0&state=linkup;
+	    if call_server(config, query) == false then
+		-- XXX error handling
+	    end
 	elseif m.system == "DEVFS" then
 	    -- Device nodes
+	    generic_event(m, msg);
+
 	elseif m.system == "USB" then
 	    -- USB messages
+	    generic_event(m, msg);
+	    -- !system=USB subsystem=INTERFACE type=ATTACH ugen=ugen0.2 cdev=ugen0.2 vendor=0x1f28 product=0x0021
+	    -- devclass=0x00 devsubclass=0x00 sernum="216219360300" release=0x0000
+	    -- mode=host interface=0 endpoints=2 intclass=0x08 intsubclass=0x06 intprotocol=0x50
+
+	    -- system=USB subsystem=DEVICE type=ATTACH ugen=ugen0.2 cdev=ugen0.2 vendor=0x1f28 product=0x0021
+	    -- devclass=0x00 devsubclass=0x00 sernum=%22216219360300%22 release=0x0000 mode=host port=1 parent=ugen0.1
+
+	    -- Our usb_modeswitch :)
+	    if m.subsystem == "DEVICE" and m.type == "ATTACH" then
+		-- XXX: get that from config
+		m.vendor = m.vendor - 0;
+		m.product = m.product - 0;
+		-- ugen0.2 -> 0.2
+		devid = m.ugen:gsub("ugen", "");
+		if m.vendor == 0x1f28 and m.product == 0x0021 then
+	    	    os.execute("hex2bin " ..
+	    		"55534243b82e238c24000000800108df200000000000000000000000000000" ..
+	    		" > /dev/usb/" .. devid .. ".8"); -- EndPoint 8
+		end
+	    end
+
 	elseif m.system == "GPIO" then
 	    -- GPIO messages
+	    generic_event(m, msg);
+
 	    -- XXX: should not be hardcoded
-	    if m.subsystem == "pin10" and m.bus == "gpiobus0" then
+	    if m.subsystem == reset_pin and m.bus == "gpiobus0" then
 		if     m.type == "PIN_LOW" then
 		    -- Pin return to normal state
 		    time = tonumber(m.period);
@@ -99,7 +154,7 @@
 			-- if call_server(config, "restore=config") == false then
 			    -- If we can't get success from httpd, then we restore default manualy
 			    os.execute("mv /tmp/etc/www/config.xml /tmp/etc/www/config.xml.bak");
-			    os.execute("/etc/save_etc");
+			    os.execute("/etc/rc.save_config");
 			    os.execute("reboot");
 			-- end
 			os.execute("echo \"devd.lua: User request Reset to Default\" > /dev/console");
@@ -115,7 +170,6 @@
 	    -- Unknown system
 	end
     end
-
 end
 
 function unknown_device(config, msg)
@@ -136,7 +190,11 @@
 local config = {};
 config.http = require("socket.http");
 
-
+reset_pin = exec_output("kenv -q RESET_PIN");
+if not reset_pin then
+    reset_pin = 10;
+end
+reset_pin = string.format("pin%03d", reset_pin);
 
 while run do
     if not config.d then
@@ -144,6 +202,7 @@
     end
     local line = config.d:read("*l");
     if line then
+	print("devd.lua:DEBUG: got \"" .. line .. "\"");
 	local m, _, t, msg = line:find("^(.)(.*)");
 	if m and t and msg then
 		if     t == "!" then
--- a/profiles/dlink.ua.web/files/etc/www/devd.sh	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/devd.sh	Thu Sep 20 15:21:29 2012 +0300
@@ -5,6 +5,8 @@
 
 echo $$ > /var/run/devd.sh.pid
 
+./devd.lua > /var/log/devd.sh.log 2>&1
+exit 1
 
 while true; do
     ./devd.lua
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Administration.config.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>Device Configuration</h1>
-
-    <h4>Upload Configuration</h4>
-    <form method="post" action="/cmd.xml" enctype="multipart/form-data">
-	<input type="hidden" name="cmd" value="upload_config">
-	<input type="file" name="config" value="">
-	<input type="submit" name="Upload Config" value="Upload Config">
-    </form>
-    <h4>Download Configuration</h4>
-    <form method="post" action="/config.dat" enctype="application/x-www-form-urlencoded">
-	<input type="hidden" name="cmd" value="download_config">
-	<input type="submit" name="Download Config" value="Download Config">
-    </form>
-
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Administration.firmware.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>Device Firmware</h1>
-Current Version: <strong>$$$info.firmware.version$$$</strong><br/>
-Build Date:<strong>$$$info.firmware.date$$$</strong><br/>
-
-$$$code:conf_table("Firmware", "Firmware", "info.firmware",
-{
-    { label = "Update URL", 		type = "node", htmltype = "text", 	node = "update_url" 	},
-})$$$
-
-    <h4>Upgrade Firmware</h4>
-    <form method="post" action="/cmd.xml" enctype="application/x-www-form-urlencoded">
-	<input type="hidden" name="cmd" value="upgrade">
-	<input type="submit" name="Start Upgrade" value="Start Upgrade">
-    </form>
-
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Administration.info.html	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/Administration.info.html	Thu Sep 20 15:21:29 2012 +0300
@@ -1,7 +1,8 @@
 $$$code:inc("htdocs/header.html")$$$
     <h1>Device Information</h1>
-Model:<strong>$$$info.model$$$</strong><br/>
-Hardware Revision:<strong>$$$info.rev$$$</strong><br/>
+Vendor:<strong>$$$info.device.vendor$$$</strong><br/>
+Model:<strong>$$$info.device.model$$$</strong><br/>
+Hardware Revision:<strong>$$$info.device.revision$$$</strong><br/>
 
 $$$code:conf_table("DevInfo", "Device Information", "info",
 {
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Administration.users.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>Users</h1>
-TODO: Access groups
-$$$code:conf_table("User1Auth", "User 1 auth", "http.users.user[1]",
-{
-    { label = "Username", 	type = "attr", htmltype = "text", 	node = ":username" 	},
-    { label = "Password", 	type = "attr", htmltype = "text", 	node = ":password" 	},
---[[    { label = "Group", 		type = "attr", htmltype = "text", 	node = ":group" 		},]]
-})$$$
-
-$$$code:conf_table("User2Auth", "User 2 auth", "http.users.user[2]",
-{
-    { label = "Username", 	type = "attr", htmltype = "text", 	node = ":username" 	},
-    { label = "Password", 	type = "attr", htmltype = "text", 	node = ":password" 	},
---[[    { label = "Group", 		type = "attr", htmltype = "text", 	node = ":group" 		},]]
-})$$$
-
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Advanced.PPP.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-
-    <h1>Advanced PPP options</h1>
-    <h1>Advanced 3G modems options</h1>
-
-
-$$$code:inc("htdocs/footer.html")$$$
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Basic.lan.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>LAN configuration</h1>
-
-$$$code:conf_table("LAN", "LAN", "interfaces.bridge0",
-{
-    { label = "IP Address", 		type = "node", htmltype = "text", 	node = "ipaddr" 	},
-})$$$
-
-$$$code:conf_table("DHCPD", "DHCP server configuration", "dhcpd.instances.instance[1]",
-{
-    { label = "Enabled", 		type = "attr", htmltype = "checkbox", 	node = ":enable" 	},
-    { label = "First IP Address", 	type = "node", htmltype = "text", 	node = "range.start" 	},
-    { label = "Last IP Address", 	type = "node", htmltype = "text", 	node = "range.end" 	},
-    { label = "Default Lease Time", 	type = "node", htmltype = "text", 	node = "default-lease-time"},
-    { label = "Max Lease Time", 	type = "node", htmltype = "text", 	node = "max-lease-time" },
-})$$$
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Basic.wan.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>Internet connections configuration</h1>
-
-$$$code:conf_table("Static", "Ethernet Interface", "interfaces.wan0.Static",
-{
-    { label = "Enabled", 		type = "attr", htmltype = "checkbox", 	node = ":enable" 	},
-    { label = "Automatic (DHCP)",	type = "attr", htmltype = "checkbox", 	node = "dhcp:enable" 	},
-    { label = "IP Address", 		type = "node", htmltype = "text", 	node = "ipaddr" 	},
-    { label = "Gateway Address", 	type = "node", htmltype = "text", 	node = "gateway" 	},
-    { label = "DNS Primary", 		type = "node", htmltype = "text", 	node = "dns1" 		},
-    { label = "DNS Secondary", 		type = "node", htmltype = "text", 	node = "dns2" 		},
-    { label = "NAT Enabled", 		type = "attr", htmltype = "checkbox", 	node = "nat:enable" 	}
-})$$$
-
-$$$code:conf_table("PPPoE", "PPPoE", "interfaces.wan0.PPPoE",
-{
-    { label = "Enabled", 		type = "attr", htmltype = "checkbox", 	node = ":enable" 	},
-    { label = "Username", 		type = "node", htmltype = "text", 	node = "username" 	},
-    { label = "Password", 		type = "node", htmltype = "text", 	node = "password" 	},
-    { label = "Service name", 		type = "node", htmltype = "text", 	node = "service_name" 	},
-    { label = "Device", 		type = "node", htmltype = "text", 	node = "device" 	},
-    { label = "IP Address", 		type = "node", htmltype = "text", 	node = "ipaddr" 	},
-    { label = "Gateway Address", 	type = "node", htmltype = "text", 	node = "gateway" 	},
-    { label = "DNS Primary", 		type = "node", htmltype = "text", 	node = "dns1" 		},
-    { label = "DNS Secondary", 		type = "node", htmltype = "text", 	node = "dns2" 		},
-    { label = "NAT Enabled", 		type = "attr", htmltype = "checkbox", 	node = "nat:enable" 	}
-})$$$
-
-$$$code:conf_table("PPP", "PPP (3G)", "interfaces.wan0.PPP",
-{
-    { label = "Enabled", 		type = "attr", htmltype = "checkbox", 	node = ":enable" 	},
-    { label = "Username", 		type = "node", htmltype = "text", 	node = "username" 	},
-    { label = "Password", 		type = "node", htmltype = "text", 	node = "password" 	},
-    { label = "Phone", 			type = "node", htmltype = "text", 	node = "phone" 		},
-    { label = "Init String",		type = "node", htmltype = "text", 	node = "init_string"	},
-    { label = "Device", 		type = "node", htmltype = "text", 	node = "device" 	},
-    { label = "IP Address", 		type = "node", htmltype = "text", 	node = "ipaddr" 	},
-    { label = "Gateway Address", 	type = "node", htmltype = "text", 	node = "gateway" 	},
-    { label = "DNS Primary", 		type = "node", htmltype = "text", 	node = "dns1" 		},
-    { label = "DNS Secondary", 		type = "node", htmltype = "text", 	node = "dns2" 		},
-    { label = "NAT Enabled", 		type = "attr", htmltype = "checkbox", 	node = "nat:enable" 	}
-})$$$
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Basic.wlan.html	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/Basic.wlan.html	Thu Sep 20 15:21:29 2012 +0300
@@ -1,163 +1,18 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-    <head>
-	<meta http-equiv="content-type" content="text/html; charset=utf-8">
-	<title>Wireless configuration</title>
-	<style type="text/css"> body {	margin:0; padding:0; } 	</style>
-	<link href="css/anim.css" rel="stylesheet" type="text/css">
-    </head>
-    <body class="yui3-skin-sam  yui-skin-sam">
-    <h2>Wireless configuration</h2>
-
-<div id="Static" class="boxitem">
-    <div class="yui3-hd">
-        <h4>Radio Settings</h4>
-    </div>
-    <div class="yui3-bd">
-	<form method="POST" target="/test.lua">
-<table width="100%">
-    <tr>
-	<td class=""><label for="radio_control">Enable Wireless&nbsp;:</label></td>
-	<td>
-	    <input id="radio_control" _value="data.wireless.radio_control" type="checkbox">
-	</td>
-	</tr>
-	<tr>
-		<td class="">Wireless Channel&nbsp;:</td>
-		<td>
-		    <select name="channel">
-			<option value="1">2.412 GHz - CH 1</option>
-			<option value="2">2.417 GHz - CH 2</option>
-			<option value="3">2.422 GHz - CH 3</option>
-			<option value="4">2.427 GHz - CH 4</option>
-			<option value="5">2.432 GHz - CH 5</option>
-			<option value="6">2.437 GHz - CH 6</option>
-			<option value="7">2.442 GHz - CH 7</option>
-			<option value="8">2.447 GHz - CH 8</option>
-			<option value="9">2.452 GHz - CH 9</option>
-			<option value="10">2.457 GHz - CH 10</option>
-			<option value="11">2.462 GHz - CH 11</option>
-		    </select>
-		</td>
-	</tr>
-
-	<tr>
-		<td class="">802.11 Mode&nbsp;:</td>
-		<td>
-			<select>
-				<option value="2">802.11g only</option>
-				<option value="3">Mixed 802.11g and 802.11b</option>
-				<option value="1">802.11b only</option>
-				<option value="8">802.11n only</option>
-				<option value="11">Mixed 802.11n, 802.11g and 802.11b</option>
-			</select>
-		</td>
-	</tr>
+$$$code:inc("htdocs/header.html")$$$
+    <h1>Wireless configuration</h1>
 
-	<tr>
-		<td class="">Channel Width&nbsp;:</td>
-		<td>
-			<select>
-				<option value="0">20 MHz</option>
-				<option value="1">Auto 20/40 MHz</option>
-			</select>
-		</td>
-	</tr>
-	<tr>
-		<td class="">Transmission Rate&nbsp;:</td>
-		<td>
-			<select>
-				<!-- Turbo rates in brackets. Rates are given in units of 500 kbits/s -->
-				<option value="0">Best (automatic)</option>
-				<[email protected]:radio_type_NA or [email protected]>
-				<option value="27">MCS 15 - 130 [270]</option>
-				<option value="26">MCS 14 - 117 [243]</option>
-				<option value="25">MCS 13 - 104 [216]</option>
-				<option value="24">MCS 12 - 78 [162]</option>
-
-				<option value="23">MCS 11 - 52 [108]</option>
-				<option value="22">MCS 10 - 39 [81]</option>
-				<option value="21">MCS 9 - 26 [54]</option>
-				<option value="20">MCS 8 - 13 [27]</option>
-				<option value="19">MCS 7 - 65 [135]</option>
-				<option value="18">MCS 6 - 58.5 [121.5]</option>
+$$$code:conf_table("WLAN", "Wireless Access Point configuration", "hostapd.instance[1]",
+{
+    { label = "Enabled", 			type = "attr", htmltype = "checkbox", 	node = ":enable" 	},
+    { label = "Country code (UA)", 		type = "node", htmltype = "text", 	node = "country_code" 	},
+    { label = "wireless iface (wlan0)", 	type = "node", htmltype = "text", 	node = "interface" 	},
+    { label = "Channel (6)", 			type = "node", htmltype = "text", 	node = "channel" 	},
+    { label = "SSID", 				type = "node", htmltype = "text", 	node = "ssid"		},
+    { label = "WPA mode, 1-WPA, 2-RSN, 3-WPA+RSN", 	type = "node", htmltype = "text", 	node = "wpa"	},
+    { label = "WPA key", 			type = "node", htmltype = "text", 	node = "wpa_passphrase" },
+})$$$
 
-				<option value="17">MCS 5 - 52 [108]</option>
-				<option value="16">MCS 4 - 39 [81]</option>
-				<option value="15">MCS 3 - 26 [54]</option>
-				<option value="14">MCS 2 - 19.5 [40.5]</option>
-				<option value="13">MCS 1 - 13 [27]</option>
-				<option value="12">MCS 0 - 6.5 [13.5]</option>
-
-				<[email protected]@-->
-				<[email protected]:radio_type_A or [email protected]>
-				<option value="11">54 [108]</option>
-				<option value="10">48 [96]</option>
-				<option value="9">36 [72]</option>
-				<option value="8">24 [48]</option>
-				<option value="7">18 [36]</option>
-
-				<option value="6">12 [24]</option>
-				<option value="5">9 [18]</option>
-				<option value="4">6 [12]</option>
-				<[email protected]@-->
-				<option value="3">11</option>
-				<option value="2">5.5</option>
-
-				<option value="1">2</option>
-				<option value="32768">1</option><!--Most significant bit is set to distinguish from Best-->
-			</select>
-			(Mbit/s) </td>
-	</tr>
-</table>
+$$$code:inc("htdocs/footer.html")$$$
 
 
 
-	</form>
-
-<!-- Subitems -->
-$$$code:dofile("htdocs/vaps.lua")$$$
-
-	</form>
-    </div>
-</div>
-
-    </div>
-</div>
-
-
-<script type="text/javascript">
-function updateSecurityMode(obj)
-{
-    table = obj.parentNode.parentNode.parentNode;
-    trs = table.getElementsByTagName('tr');
-    for (i = 0; i < trs.length; i ++) //>
-    {
-	tr = trs[i];
-	class = tr.className;
-	if (!class || !class.match(/security\_mode\_/))
-	    continue;
-
-	if (class == ('security_mode_' + obj.value) )
-	    tr.style.display = '';
-	else
-	    tr.style.display = 'none';
-    }
-}
-
-sls = document.getElementsByTagName('select');
-for (i = 0; i < sls.length; i ++) //>
-{
-	sl = sls[i];
-	class = sl.className;
-	if (!class || !class.match(/security\_mode/))
-	    continue;
-	updateSecurityMode(sl);
-}
-
-
-</script>
-
-</body>
-</html>
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Security.IPSec.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>IPSec configuration</h1>
-
-
-<!-- ipsec>
-    <remote id="0" enable="true">
-	<gateway>10.0.0.2:500</gateway>
-        <exchange_mode>main,aggressive</exchange_mode>
-        <my_identifier>address 10.0.0.1</my_identifier>
-        <peers_identifier>address 10.0.0.2</peers_identifier>
-        <lifetime>time 28800 sec</lifetime>
-	<initial_contact>on</initial_contact>
-        <passive>off</passive>
-        <proposal_check>obey</proposal_check>
-	<nat_traversal>off</nat_traversal>
-        <generate_policy>off</generate_policy>
-        <proposal>
-            <encryption_algorithm>3des</encryption_algorithm>
-            <hash_algorithm>md5</hash_algorithm>
-            <authentication_method>pre_shared_key</authentication_method>
-            <dh_group>5</dh_group>
-	</proposal>
-    </remote>
-    <sainfo id="0" enable="true">
-	<src>address 192.168.0.0/24 any</src>
-	<dst>address 192.168.2.0/24 any</dst>
-	<pfs_group>5</pfs_group>
-	<lifetime>time 3600 sec</lifetime>
-	<encryption_algorithm>3des</encryption_algorithm>
-	<authentication_algorithm>hmac_md5</authentication_algorithm>
-	<compression_algorithm>deflate</compression_algorithm>
-    </sainfo>
-    <setkey>
-	<line>spdadd 192.168.0.0/24 192.168.2.0/24 any -P out ipsec esp/tunnel/10.0.0.1-10.0.0.2/use</line>
-	<line>spdadd 192.168.2.0/24 192.168.0.0/24 any -P in ipsec esp/tunnel/10.0.0.2-10.0.0.1/use</line>
-    <setkey>
-</ipsec -->
-
-
-$$$code:conf_table("IPSec", "IPSec link configuration", "ipsec.remote[1]",
-{
-    { label = "Enabled", 		type = "attr", htmltype = "checkbox", 	node = ":enable" 	},
-    { label = "Gateway", 		type = "node", htmltype = "text", 	node = "gateway"		},
-    { label = "Exchange Mode", 		type = "node", htmltype = "text", 	node = "exchange_mode"		},
-    { label = "My ID", 			type = "node", htmltype = "text", 	node = "my_identifier"		},
-    { label = "Peer ID", 		type = "node", htmltype = "text", 	node = "peers_identifier"	},
-    { label = "Lifetime", 		type = "node", htmltype = "text", 	node = "lifetime"		},
-    { label = "Initial Contact", 	type = "node", htmltype = "text", 	node = "initial_contact"	},
-    { label = "Passive", 		type = "node", htmltype = "text", 	node = "passive"		},
-    { label = "Proposal Check", 	type = "node", htmltype = "text", 	node = "proposal_check"		},
-    { label = "NAT Traversal", 		type = "node", htmltype = "text", 	node = "nat_traversal"		},
-    { label = "Generate Policy", 	type = "node", htmltype = "text", 	node = "generate_policy"	},
-})$$$
-$$$code:conf_table("IPSecProposal", "IPSec link1 proposal configuration", "ipsec.remote[1].proposal",
-{
-    { label = "Encryption Algorithm", 	type = "node", htmltype = "text", 	node = "encryption_algorithm"	},
-    { label = "HASH Algorithm", 	type = "node", htmltype = "text", 	node = "hash_algorithm"		},
-    { label = "DH Group", 		type = "node", htmltype = "text", 	node = "dh_group"		},
-    { label = "Pre Shared Key", 	type = "node", htmltype = "text", 	node = "psk"			},
-})$$$
-
-$$$code:conf_table("IPSecTunnel", "IPSec link1 Tunnel configuration", "ipsec.sainfo[1]",
-{
-    { label = "Source Address",		type = "node", htmltype = "text", 	node = "src"			},
-    { label = "Destination Address",	type = "node", htmltype = "text", 	node = "dst"			},
-    { label = "PFS Group", 		type = "node", htmltype = "text", 	node = "pfs_group"		},
-    { label = "Lifetime", 		type = "node", htmltype = "text", 	node = "lifetime"		},
-    { label = "Encryption Algorithm", 	type = "node", htmltype = "text", 	node = "encryption_algorithm"	},
-    { label = "Auth Algorithm", 	type = "node", htmltype = "text", 	node = "authentication_algorithm"},
-    { label = "Compression Algorithm", 	type = "node", htmltype = "text", 	node = "compression_algorithm"	},
-})$$$
-
-$$$code:conf_table("SPD", "IPSec Policy (setkey) configuration", "ipsec.setkey",
-{
-    { label = "Line1",	type = "node", htmltype = "text", node = "line[1]"},
-    { label = "Line2",	type = "node", htmltype = "text", node = "line[2]"},
-    { label = "Line3",	type = "node", htmltype = "text", node = "line[3]"},
-    { label = "Line4",	type = "node", htmltype = "text", node = "line[4]"},
-})$$$
-
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Security.OpenVPN.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>OpenVPN configuration</h1>
-
-    Empty
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/Security.SSH.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-$$$code:inc("htdocs/header.html")$$$
-    <h1>SSH tunnels configuration</h1>
-
-    Empty
-
-$$$code:inc("htdocs/footer.html")$$$
-
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/cmd.xml	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/cmd.xml	Thu Sep 20 15:21:29 2012 +0300
@@ -66,39 +66,45 @@
 
     elseif rq.POST["save"] == "config" then
 
-	print("try to save config.xml");
+	print("Saving configuration to config.xml");
 	if not save_file("config.xml", xmldump(c:gettree())) then
 	    return ("Error saving configuration");
 	end
-	if os.execute("/etc/save_etc") ~= 0 then
+	if os.execute("/etc/rc.save_config") ~= 0 then
 	    return ("Error saving configuration block to flash");
 	end
 	return ("Configuration saved successful");
 
     elseif rq.POST["restore"] == "config" then
 
-	if os.execute("rm /tmp/etc/www/config.xml") ~= 0 then
-	    return ("Can't remove current config");
+	print("Restoring factory default setting");
+	os.execute("echo '(sleep 5 ; rm /tmp/etc/www/config.xml ; /etc/rc.save_config ; /sbin/reboot ) & ' >> /tmp/restore_scrip.sh");
+	if os.execute("sh /tmp/restore_scrip.sh &") ~= 0 then
+	    return ("Run restore script fail");
 	end
-	if os.execute("/etc/save_etc") ~= 0 then
-	    return ("Error saving configuration block to flash");
-	end
-	if os.execute("/sbin/reboot &") ~= 0 then
-	    return ("Error when trying reboot");
-	end
-	return ("Configuration restored successful");
+	return ("Configuration restore procedure started");
 
     elseif rq.POST["system"] == "reboot" then
 
 	print("Reboot device");
-	if os.execute("/sbin/reboot &") ~= 0 then
-	    return ("Error when try to execute /sbin/reboot");
+	os.execute("echo '(sleep 5 ; /sbin/reboot) &' > /tmp/reboot_scrip.sh");
+	os.execute("echo 'Run /tmp/reboot_scrip.sh' > /dev/console");
+	if os.execute("sh /tmp/reboot_scrip.sh &") ~= 0 then
+	    return ("Can't execute reboot script");
 	end
+	os.execute("echo 'Return \"Reboot in progress\" to parent' > /dev/console");
 	return ("Reboot in progress");
 
+    elseif rq.POST["telnet"] == "enable" then
+
+	print("Enabling telnet service");
+	os.execute("echo 'Enabling telnet service' > /dev/console");
+	os.execute("/usr/libexec/telnetd -4 -debug 23 &");
+	return ("telnet service started");
+
     else
 
-	print(tdump(rq));
+--	print(tdump(rq));
 --	print(tdump(rq.POST));
 	return ("Unknow command");
 
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/config.dat	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-
-
-if rq.POST["cmd"] == "download_config" then
-	return (xmldump(c:gettree()));
-else
-	return ("Unknow command");
-end
-
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/css/anim.css	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/* color and iteration examples */
-a.boxitem {
-    background:#8dd5e7;
-    border:1px solid #004c6d;
-    color:#004c6d;
-    display:block;
-    height:2em;
-    line-height:2em;
-    width:6em;
-    text-align:center;
-}
-
-/* xy and curve examples */
-span.boxitem {
-    background:#ffa928;
-    display:block;
-    height:10px;
-    width:10px;
-}
-
-/* module examples */
-div.boxitem {
-    /*width:34em;*/
-    width:100%;
-    overflow:hidden;
-}
-
-div.boxitem {
-    border-bottom:1px solid #7a97bb;
-}
-
-div.boxitem .yui3-hd {
-    background: url(../img/tool_bar.jpg) repeat-x;
-    cursor:pointer;
-    cursor:hand;
-    /*border:1px solid #243356;*/
-    border:0;
-    zoom:1;
-}
-
-div.boxitem .yui3-hd h4 {
-    border:0;
-    color:#fff;
-    margin:0;
-}
-
-div.boxitem .yui3-bd {
-    background:#abceff;
-    border:solid #7a97bb;
-    border-width:0 1px;
-    clear: both;
-    overflow:hidden;
-    zoom:1;
-}
-
-div.boxitem .yui3-hd,
-div.boxitem .yui3-bd p {
-    margin:0;
-    padding:0.1em 1em;
-}
-
-div.boxitem div.yui3-bd p {
-    margin:0.3em 10px 0 0; /* right margin for scrollbar space */
-}
-
-div.boxitem .yui3-bd p em {
-    font-weight:bold;
-}
-
-/* basic example */
-div.boxitem a.yui3-remove {
-    background-position:0 -300px;
-    height:16px;
-    width:26px;
-}
-
-/* scroll example */
-.boxitem.yui3-scroll {
-    position: relative;
-}
-
-.yui3-scroll .yui3-hd {
-    position: relative;
-}
-.yui3-scroll .yui3-bd {
-    height:10em;
-    overflow:hidden;
-}
-
-.boxitem .yui3-hd .yui3-scroll-controls { /* fake scrollbar */
-    background:#dfdfdf;
-    border-left:1px solid #7a97bb;
-    height:10em;
-    width:13px;
-    position:absolute;
-    right:0;
-    bottom:-10.1em;
-    overflow:hidden;
-}
-
-.boxitem .yui3-hd .yui3-scroll-controls a {
-    margin: 0;
-    position:absolute;
-    top:0;
-    right:0;
-    height:14px;
-    width:14px;
-    Xborder:1px solid #000;
-}
-
-.boxitem .yui3-scroll-controls a.yui3-scrollup {
-    background-position:-12px -752px; /* scroll up icon */
-}
-
-.boxitem .yui3-scroll-controls a.yui3-scrolldown {
-    background-position:-12px -804px; /* scroll down icon */
-    top:auto;
-    bottom:0;
-}
-
-/* reverse and easing examples */
-.boxitem a.yui3-toggle {
-    background-position:0 -400px; /* close (minus) icon */
-    height:15px;
-    width:15px;
-}
-
-.boxitem
-.yui3-closed a.yui3-toggle {
-    background-position:0 -350px; /* open (plus) icon */
-}
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/css/router.css	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/css/router.css	Thu Sep 20 15:21:29 2012 +0300
@@ -1,6 +1,3 @@
-/* Copyright 2004 D-Link Systems, Inc. All Rights Reserved.
--------------------------------------------------------------------------------- */
-
 html, div, h1, h2, h3, h4, p, ul, ol, li, dl, dt, dd, td, input, select, textarea
 {
 	font-family: Tahoma, Helvetica, Geneva, Arial, sans-serif;
@@ -15,7 +12,7 @@
 }
 
 body.body_fw{
-background: #ffffff;
+	background: #ffffff;
 }
 
 input, select, textarea
@@ -77,13 +74,6 @@
 	font-weight: bold;
 }
 
-#box_header
-{
-	border: 1px solid #136393;
-	padding: 0 10px 10px 10px;
-	background-color: #E4EAEB;
-}
-
 h1
 {
 	color: #000000;
@@ -97,152 +87,77 @@
 }
 
 #table_tree{
-    font-family: Arial;
-    font-size: 22px;
-    height: 514px;
-    width: 200px;
-    margin: 5px 4px 3px 1px;
-    border-top-color:#808080;
-    border-left-color:#808080;
-    background:#FFFFFF;
+	font-family: Arial;
+	font-size: 22px;
+	height: 514px;
+	width: 200px;
+	margin: 5px 4px 3px 1px;
+	border-top-color:#808080;
+	border-left-color:#808080;
+	background:#FFFFFF;
 }
 
 #table_page{
-    width:555px;
-    height: 514px;
-    margin: 5px 5px 5px 3px;
-    border-width: 2px;
-    border-top:solid 2 #ffffff;
-    border-bottom:solid 2 #808080;
-    border-left:solid 2 #ffffff;
-    border-right:solid 2 #808080;
-    background:#CCDCE2;
+	width:555px;
+	height: 514px;
+	margin: 5px 5px 5px 3px;
+	border-width: 2px;
+	border-top:solid 2 #ffffff;
+	border-bottom:solid 2 #808080;
+	border-left:solid 2 #ffffff;
+	border-right:solid 2 #808080;
+	background:#CCDCE2;
 }
 
 #table_frame{
-    width:547px;
-    height: 504px;
-    margin: 2px 2px 2px 3px;
-    border: 1px solid #136393;
-    background:#E4EAEB;
+	width:547px;
+	height: 504px;
+	margin: 2px 2px 2px 3px;
+	border: 1px solid #136393;
+	background:#E4EAEB;
 }
 
 #alink_tree a:link, #alink_tree a:visited, #alink_tree a:active{
-text-decoration: none;
-font-size: 11px;
-color: #000000;
+	text-decoration: none;
+	font-size: 11px;
+	color: #000000;
 }
 
 #td_header
 {
-font-family: Arial;
-height: 30px;
-color: #000000;
-font-size: 18px;
-background: url(img/light_blue1.jpg);
-padding-left: 15px;
+	font-family: Arial;
+	height: 30px;
+	color: #000000;
+	font-size: 18px;
+	background: url(img/light_blue1.jpg);
+	padding-left: 15px;
 }
 
 #table_header{
-height: 30px;
-width: 100%;
-background:#CCDCE2;
+	height: 30px;
+	width: 100%;
+	background:#CCDCE2;
 }
 
 #table_set_main{
-width: 100%;
-margin-top: 1px;
-border-top: solid 1px  #136393;
-background: #E4EAEB;
-padding-left: 5px;
-padding-top: 5px;
+	width: 100%;
+	margin-top: 1px;
+	border-top: solid 1px  #136393;
+	background: #E4EAEB;
+	padding-left: 5px;
+	padding-top: 5px;
 }
 
 #td_left{
-font-family: Arial;
-text-align:left;
-margin: 2px;
-height:25px;
+	font-family: Arial;
+	text-align:left;
+	margin: 2px;
+	height:25px;
 }
 
 #td_right{
-font-family: Arial;
-text-align:left;
-}
-
-.menu {
-	margin: 0px 0px 0px 0px;
-	padding: 0px 0px 0px 0px;
-	float: left;
-	z-index: 2;
-	white-space:nowrap;
-}
-
-.menu ul, li, a {
 	font-family: Arial;
-	font-size: 12px;
-}
-
-.menu ul {
-	border: 1px solid #136393;
-	margin: 0px 0px 0px 0px;
-	padding: 1px 1px 1px 1px;
-	list-style: none;
-	display: block;
-	background: #ffffff;
-	cursor:pointer;
-
-}
-
-.menu li {
-	margin: 0px 0px 0px 0px;
-	padding: 2px 2px 2px 2px;
-}
-
-.menu a {
-	margin: 0px 0px 0px 0px;
-	padding: 0px 0px 0px 0px;
-	display:block;
-	noFocusLine:expression(this.onFocus=this.blur());
-}
-
-
-.menu a:link {
-	color: #000000;
-	text-decoration: none;
-	background: #ffffff;
-
-}
-
-.menu a:visited {
-	color: #000000;
-	text-decoration: none;
-	background: #ffffff;
-}
-
-.menu a:hover {
-	color: #ffffff;
-	text-decoration: none;
-	background: #136393;
-}
-
-.menu a:active {
-	text-decoration: none;
-}
-
-.banner{
-	font-family: Arial;
-	font-size: 12px;
-	cursor:pointer;
-	color: #ffffff;
-	padding: 0px 3px 0px 3px;
-	text-decoration: none;
-}
-
-.banner a:link, .banner a:visited,.banner a:hover, .banner a:active{
-	text-decoration: none;
-	color: #ffffff;
-	noFocusLine:expression(this.onFocus=this.blur());
+	text-align:left;
 }
 
 span.word{
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/event.xml	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/event.xml	Thu Sep 20 15:21:29 2012 +0300
@@ -6,13 +6,19 @@
 -- rq.GET["dns2"	] = "192.168.1.3";
 -- rq.GET["dns1"	] = "192.168.1.3";
 -- rq.GET["iface"	] = "PPP";
--- rq.GET["eventtype"] = "linkup";
+-- rq.GET["state"] = "up";
 
 -- r = {};
 
 -- function doit()
 
 function process()
+    if not c then
+	print("Configuration structure 'c' is missing");
+    end
+    if not rq then
+	print("Request structure 'rq' is missing");
+    end
 
     if     rq.GET["cmd"] == "get" then
 
@@ -29,18 +35,19 @@
 	if os.execute("rm /tmp/etc/www/config.xml") ~= 0 then
 	    return ("Can't remove current config");
 	end
-	if os.execute("/etc/save_etc") ~= 0 then
+	if os.execute("/etc/rc.save_config") ~= 0 then
 	    return ("Error saving configuration block to flash");
 	end
-	if os.execute("reboot") ~= 0 then
+	if os.execute("reboot &") ~= 0 then
 	    return ("Error when trying reboot");
 	end
 	return ("Configuration restored successful");
 
     elseif rq.GET["cmd"] == "event" then
 	    -- print(rq.RequestHeader);
-
+	    -- cmd=event&iface=wan0&state=linkup
 	    local iface = rq.GET["iface"];
+	    local newstate = rq.GET["state"];
 
 	    if not iface then
 		return ("event.lua: ERROR: Interface not defined");
@@ -48,12 +55,21 @@
 
 	    if type(r[iface]) ~= "table" then r[iface] = {}; end
 
-	    os.execute("echo \"event.xml: " .. rq.QueryString .."\" > /dev/console");
-	    -- Update NAT alias address for Static/DHCP
-	    if iface == "wan0" then
-		local ip = rq.GET["ip"];
-		ip = ip:gsub("/%d+", "");
-		os.execute("ngctl msg wan0nat: setaliasaddr " .. ip);
+	    print("echo \"event.xml: " .. rq.QueryString .."\" > /dev/console");
+	    if newstate == "up" then
+		-- Update NAT alias address for Static/DHCP
+		if iface == "wan0" then
+		    local ip = rq.GET["ip"];
+		    ip = ip:gsub("/%d+", "");
+		    os.execute("ngctl msg wan0nat: setaliasaddr " .. ip);
+		end
+	    elseif newstate == "linkup" then
+		--
+		run_dhclient(c, iface); -- if DHCP enabled.
+	    elseif newstate == "down" then
+		--
+	    elseif newstate == "linkdown" then
+		--
 	    end
 
 	    for k,v in pairs(rq.GET) do
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/footer.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-</body>
-</html>
\ No newline at end of file
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/header.html	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/header.html	Thu Sep 20 15:21:29 2012 +0300
@@ -9,10 +9,13 @@
     <body class="yui3-skin-sam  yui-skin-sam">
 <script type="text/javascript" src="js/ajax.js"></script>
 <script>
-function send_update(form)
+function send_update(form, proc)
 {
     var query = getValuesAsArray(form);
-    ajax("POST", "/cmd.xml", query, true, function (x) { });
+    if (!proc) {
+	proc = function (x) { };
+    }
+    ajax("POST", "/cmd.xml", query, true, proc);
 
     return false;
 }
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/home_sys.html	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/home_sys.html	Thu Sep 20 15:21:29 2012 +0300
@@ -4,7 +4,7 @@
   <HEAD>
     <LINK REL="stylesheet" HREF="index_files/router.css" TYPE="text/css">
     <META http-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
-    <TITLE>$$$info.model$$$</TITLE>
+    <TITLE>$$$info.device.vendor$$$&nbsp;&nbsp;&nbsp;$$$info.device.model$$$&nbsp;&nbsp;&nbsp;$$$info.device.revision$$$</TITLE>
     <script type="text/javascript" src="js/utils.js"></script>
     <script type="text/javascript" src="js/ajax.js"></script>
   </HEAD>
@@ -21,8 +21,15 @@
             <TABLE ID="table_set_main" BORDER="0" CELLPADDING="0" CELLSPACING="0">
               <!-- ________________________________ Main Content Start ______________________________ -->
               <TBODY>
-                <TR><TD ID="td_left" HEIGHT="25" WIDTH="150">Model Name</TD><TD ID="td_right">$$$info.model$$$&nbsp;&nbsp;&nbsp;$$$info.rev$$$</TD></TR>
-                <TR><TD ID="td_left" HEIGHT="25">Firmware Version</TD><TD ID="td_right">$$$info.firmware.version$$$&nbsp;&nbsp;&nbsp;$$$info.firmware.date$$$</TD></TR>
+                <TR><TD ID="td_left" HEIGHT="25" WIDTH="150">Device</TD>
+            	    <TD ID="td_right">$$$info.device.vendor$$$&nbsp;&nbsp;&nbsp;$$$info.device.model$$$&nbsp;&nbsp;&nbsp;$$$info.device.revision$$$</TD>
+            	</TR>
+                <TR><TD ID="td_left" HEIGHT="25" WIDTH="150">SoC</TD>
+            	    <TD ID="td_right">$$$info.soc.vendor$$$&nbsp;&nbsp;&nbsp;$$$info.soc.model$$$&nbsp;&nbsp;&nbsp;$$$info.soc.revision$$$</TD>
+            	</TR>
+                <TR><TD ID="td_left" HEIGHT="25">Firmware Version</TD><TD ID="td_right">$$$info.firmware.version$$$</TD></TR>
+                <TR><TD ID="td_left" HEIGHT="25">Code revision</TD><TD ID="td_right">$$$code: r.zrouter_version.revision $$$</TD></TR>
+                <TR><TD ID="td_left" HEIGHT="25">Firmware build date</TD><TD ID="td_right">$$$code: r.zrouter_version.build $$$</TD></TR>
                 <TR><TD ID="td_left" HEIGHT="25">System Name</TD><TD ID="td_right">$$$info.hostname$$$</TD></TR>
                 <TR><TD ID="td_left" HEIGHT="25">Location</TD><TD ID="td_right">$$$info.location$$$</TD></TR>
                 <TR><TD ID="td_left" HEIGHT="25">System Time</TD><TD ID="td_right">$$$code:os.date("%Y-%m-%d %H:%M:%S")$$$</TD></TR>
@@ -31,6 +38,7 @@
                 <!-- TR><TD ID="td_left" HEIGHT="25">MAC Address</TD><TD ID="td_right">00:21:91:5a:86:f2</TD></TR-->
                 <!-- TR><TD ID="td_left" HEIGHT="25">SSID 1~3</TD><TD ID="td_right">02:21:91:5a:86:f2 ~ 06:21:91:5a:86:f2</TD></TR-->
                 <TR><TD ID="td_left" HEIGHT="25">IP Address</TD><TD ID="td_right">$$$interfaces.bridge0.ipaddr$$$</TD></TR>
+
               </TBODY>
     	      <!-- ________________________________  Main Content End _______________________________ -->
             </TABLE>
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/FreeBSD_logo.png has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/banner.jpg has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/config.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/folder.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/help.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/home.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/join.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/joinbottom.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/line.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/logout.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/minus.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/minusbottom.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/monitor.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/open_file.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/open_folder.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/plus.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/plusbottom.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/sys.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/text.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/themespacer.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/tool.gif has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/tool_bar.jpg has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/tool_bar_v.jpg has changed
Binary file profiles/dlink.ua.web/files/etc/www/htdocs/img/triangle.gif has changed
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/index.html	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/index.html	Thu Sep 20 15:21:29 2012 +0300
@@ -1,117 +1,102 @@
-<html xmlns="http://www.w3.org/1999/xhtml"><head>
-
-
-<link rel="stylesheet" href="css/router.css" type="text/css">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <link rel="stylesheet" href="css/router.css" type="text/css" />
+  <link rel="stylesheet" href="css/toolbar.css" type="text/css" />
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
-<title>$$$info.model$$$</title>
-<script type="text/javascript" src="js/utils.js"></script>
-<script type="text/javascript" src="js/wizard.js"></script>
-<script type="text/javascript" src="js/tree.js"></script>
-<script type="text/javascript" src="js/view.js"></script>
-<script type="text/javascript" src="js/ajax.js"></script>
+  <title>$$$info.device.vendor$$$&nbsp;&nbsp;&nbsp;$$$info.device.model$$$&nbsp;&nbsp;&nbsp;$$$info.device.revision$$$</title>
+  <script type="text/javascript" src="js/utils.js"></script>
+  <script type="text/javascript" src="js/wizard.js"></script>
+  <!-- script type="text/javascript" src="js/tree.js"></script -->
+  <script type="text/javascript" src="js/view.js"></script>
+  <script type="text/javascript" src="js/ajax.js"></script>
 </head>
-<body onload="init();" leftmargin="0" topmargin="0" style="overflow: auto;" bgcolor="#ccdce2" marginheight="0" marginwidth="0">
-  <form name="frm" id="frm" method="post" action="?page=main.html" onsubmit="return check();">
-    <input name="ACTION_POST" value="SOMETHING" type="hidden">
-    <input name="require_frame_name" value="" type="hidden">
+<body leftmargin="0" topmargin="0" style="overflow: auto;" bgcolor="#ccdce2" marginheight="0" marginwidth="0">
     <center>
       <table id="MainTable" border="1" bordercolor="#1e4c7d" cellpadding="0" cellspacing="0">
         <tbody>
           <tr>
-            <td colspan="2" onmouseover="HideFrame();">
-              <table background="img/banner.jpg" border="0" cellpadding="0" cellspacing="0" height="56" width="786">
+            <td colspan="2">
+              <table background="img/banner.jpg" border="0" cellpadding="0" cellspacing="0" height="71" width="1000">
                 <tbody>
                   <tr>
                     <td align="right" valign="middle">
-   		      <font style="color: white; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
-   		        <b>$$$info.model$$$&nbsp;&nbsp;&nbsp;$$$info.rev$$$</b>
-   		      </font>
-   		    </td>
-   		  </tr>
-   		</tbody>
-   	      </table>
-	    </td>
+                      <font style="color: white; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
+                        <b>$$$info.device.vendor$$$&nbsp;&nbsp;&nbsp;$$$info.device.model$$$&nbsp;&nbsp;&nbsp;$$$info.device.revision$$$</b>
+                      </font>
+                    </td>
+                  </tr>
+                </tbody>
+              </table>
+            </td>
           </tr>
           <tr>
-            <td colspan="2" style="" background="img/tool_bar.jpg">
-              <table border="0" cellpadding="0" cellspacing="0">
+            <td colspan="2">
+              <div class='toolbar'>
+                <ul>
+                  <li><a href='home_sys.html' target='ifrMain'><span>Home<img src='img/home.gif' width='16' border='0' hspace='10'></span></a></li>
+                  <li class='separator'>&nbsp;</li>
+                  <li><a href='#'><span>Maintenance<img src='img/tool.gif' width='16' border='0' hspace='10'></span></a>
+                    <ul>
+                      <li><a href='#' onClick="tryget('system=reboot'); return false;"><span>Reboot</span></a></li>
+                    </ul>
+                  </li>
+                  <li class='separator'>&nbsp;</li>
+                  <li><a href='#'><span>Configuration</span></a>
+                    <ul>
+                       <li><a href='#' onClick="tryget('save=config'); return false;"><span>Save Configuration</span></a></li>
+                       <li><a href='#' onClick="tryget('restore=config'); return false;"><span>Restore to Default</span></a></li>
+                       <li><a href='#' onClick="tryget('telnet=enable'); return false;"><span>Run telnet service</span></a></li>
+                    </ul>
+                  </li>
+                  <li class='separator'>&nbsp;</li>
+                  <li><a href='http://www.dlink.ua/files/products/ftp/pub/Router/DIR-632/Help/'><span>Help</span></a></li>
+                </ul>
+              </div>
+              <div style="clear:both; height: 0px; margin: 0px 0px 0px 0px;">&nbsp;</div>
+            </td>
+          </tr>
+
+
+          <tr>
+            <td bordercolor="ccdce2" valign="top">
+              <table id="table_tree" style="margin: 3px; width: 256px;" border="1" cellpadding="0" cellspacing="0" frame="box" width="261">
                 <tbody>
                   <tr>
-<script type="text/javascript">
-    gen_banner_td("home", "a_href");
-    gen_banner_td("tool", "");
-    gen_banner_td("config", "");
-    gen_banner_td("sys", "a_href");
-    gen_banner_td("logout", "");
-    gen_banner_td("help", "a_href");
-</script>
-		  </tr>
-	        </tbody>
-	      </table>
-	    </td>
-	  </tr>
-	  <tr>
-	    <td bordercolor="ccdce2" valign="top">
-	      <table onmouseover="HideFrame();" id="table_tree" border="1" cellpadding="0" cellspacing="0" frame="box" width="211">
-		<tbody>
-		  <tr>
-		    <td id="link_tree" valign="top">
-		      <iframe id="ifrMenu" class="ifrMenu" src="jstree_table.html" frameborder="0" height="100%" scrolling="no" width="100%"></iframe>
+                    <td id="link_tree" valign="top">
+                      <iframe id="ifrMenu" class="ifrMenu" src="tv.html" frameborder="0" height="100%" scrolling="no" width="100%"></iframe>
                     </td>
-		  </tr>
-		</tbody>
-	      </table>
-	    </td>
-	    <td bordercolor="ccdce2" valign="top">
-	      <table id="table_page" onmouseover="HideFrame();" border="0" cellpadding="0" cellspacing="0" frame="box" width="600%">
-		<tbody>
-		  <tr>
-		    <td>
-		      <iframe id="ifrMain" name="ifrMain" src="home_sys.html" onload="" frameborder="0" height="500" scrolling="auto" width="567"></iframe>
-		    </td>
-		  </tr>
-		</tbody>
-	      </table>
-	    </td>
-	  </tr>
+                  </tr>
+                </tbody>
+              </table>
+            </td>
+            <td bordercolor="ccdce2" valign="top" style="padding: 5px;">
+              <table id="table_page" style="margin: 3px; width: 720px; padding: 5px;" border="0" cellpadding="0" cellspacing="0" frame="box" width="750">
+                <tbody>
+                  <tr>
+                    <td>
+                      <iframe id="ifrMain" name="ifrMain" src="home_sys.html" onload="" frameborder="0" height="100%" scrolling="auto" width="100%"></iframe>
+                    </td>
+                  </tr>
+                </tbody>
+              </table>
+            </td>
+          </tr>
           <tr>
-            <td colspan="2" onmouseover="HideFrame();">
-              <table background="img/FreeBSD_logo.png" border="0" cellpadding="0" cellspacing="0" height="75" width="786">
+            <td colspan="2">
+              <table background="img/FreeBSD_logo.png" border="0" cellpadding="0" cellspacing="0" height="75" width="1000">
                 <tbody>
                   <tr>
                     <td align="right" valign="middle">
-   		      &nbsp;
-   		    </td>
-   		  </tr>
-   		</tbody>
-   	      </table>
-	    </td>
+                      &nbsp;
+                    </td>
+                  </tr>
+                </tbody>
+              </table>
+            </td>
           </tr>
-	</tbody>
+        </tbody>
       </table>
     </center>
-    <script>
-<!--
-genVerticalMenu(90, 78, tool_list, "tool");
-genVerticalMenu(255,78, config_list, "config");
-genLogOutMenu(490, 78, "&nbsp;&nbsp;The current browser connection will<br>&nbsp;&nbsp;be disconnected if you click <b>here</b>.", "logout");
-
-function resize()
-{
- 	var x = get_obj("MainTable").offsetLeft;
- 	get_obj("tool").style.left= (x+90+"px");
-	get_obj("config").style.left= (x+255+"px");
- 	get_obj("logout").style.left= (x+490+"px");
-}
-
-window.onresize = resize;
-
-var ifrMain = get_obj("ifrMain");
-
-
--->
-    </script>
-  </form>
 </body>
-</html>
\ No newline at end of file
+</html>
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/ajax.js	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/js/ajax.js	Thu Sep 20 15:21:29 2012 +0300
@@ -22,7 +22,11 @@
 
 function ajax(method, target, msg, async, handler)
 {
-	xmlhttptimeout = setTimeout( function(){ xmlhttp.abort(); alert("Timeout") }, 10000);
+
+	if (handler != "ignore") {
+		xmlhttptimeout = setTimeout( function(){ xmlhttp.abort(); alert("Timeout") }, 10000);
+	}
+
 	xmlhttp.onreadystatechange = function()
 	{
 		if (xmlhttp.readyState != 4) return;
@@ -35,12 +39,12 @@
 	    		alert("Error: " + xmlhttp.statusText);
 		}
 	}
+
 	xmlhttp.open(method, target, async);
 	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
 	xmlhttp.send(msg);
 }
 
-
 function getValuesAsArray(formRef)
 {
 	var ret = "r=" + encodeURIComponent(Math.random());
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/defineMyTree.js	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/js/defineMyTree.js	Thu Sep 20 15:21:29 2012 +0300
@@ -32,6 +32,7 @@
 insDoc(aux1, gLnk("R","&nbsp;Internet", "/Basic.wan.html"));
 insDoc(aux1, gLnk("R","&nbsp;Wireless", "/Basic.wlan.html"));
 insDoc(aux1, gLnk("R","&nbsp;LAN", "/Basic.lan.html"));
+insDoc(aux1, gLnk("R","&nbsp;IPTV", "/Basic.iptv.html"));
 
 aux1 = insFld(foldersTree, gFld("<font face=Tahoma size=2> Security Links </font>", ""));
 insDoc(aux1, gLnk("R","&nbsp;IPSec", "/Security.IPSec.html"));
@@ -62,6 +63,7 @@
 
 aux1 = insFld(foldersTree, gFld("<font face=Tahoma size=2> Status</font>", ""));
 insDoc(aux1, gLnk("R","&nbsp;Device Information", "/status.lua"));
+insDoc(aux1, gLnk("R","&nbsp;System Log", "/log.lua"));
 //insDoc(aux1, gLnk("R","&nbsp;Client Information", "/home_sys.html?page=st_info.html"));
 //insDoc(aux1, gLnk("R","&nbsp;WDS Information", "/home_sys.html?page=st_wds_info.html"));
 
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/tree.js	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1360 +0,0 @@
-/******************************************************************
- Definition of class Folder
-******************************************************************/
-function Header(folderDescription, hreference) /* constructor */
-{
-	/* constant data */
-	this.desc = folderDescription;
-	this.hreference = hreference;
-	this.id = -1;
-	this.navObj = 0;
-	this.iconImg = 0;
-	this.nodeImg = 0;
-	this.isLastNode = 0;
-	this.iconSrc = ICONPATH + "monitor.gif";
-	this.iconSrcClosed = ICONPATH + "monitor.gif";
-	this.children = new Array;
-	this.nChildren = 0;
-	this.level = 0;
-	this.leftSideCoded = "";
-	this.isLastNode=false;
-	this.parentObj = null;
-	this.maySelect=true;
-	this.prependHTML = "";
-
-	/* dynamic data */
-	this.isOpen = false;
-	this.isLastOpenedFolder = false;
-	this.isRendered = 0;
-
-	/* methods */
-	this.initialize = initializeFolder;
-	this.setState = setStateFolder;
-	this.addChild = addChild;
-	this.createIndex = createEntryIndex;
-	this.escondeBlock = escondeBlock;
-	this.esconde = escondeFolder;
-	this.folderMstr = folderMstr;
-	this.renderOb = drawFolder;
-	this.totalHeight = totalHeight;
-	this.subEntries = folderSubEntries;
-	this.linkHTML = linkFolderHTML;
-	this.blockStartHTML = blockStartHTML;
-	this.blockEndHTML = blockEndHTML;
-	this.nodeImageSrc = nodeImageSrc;
-	this.iconImageSrc = iconImageSrc;
-	this.getID = getID;
-	this.forceOpeningOfAncestorFolders = forceOpeningOfAncestorFolders;
-}
-
-function Folder(folderDescription, hreference) /* constructor */
-{
-	/* constant data */
-	this.desc = folderDescription;
-	this.hreference = hreference;
-	this.id = -1;
-	this.navObj = 0;
-	this.iconImg = 0;
-	this.nodeImg = 0;
-	this.isLastNode = 0;
-	this.iconSrc = ICONPATH + "open_folder.gif";
-	this.iconSrcClosed = ICONPATH + "folder.gif";
-	this.children = new Array;
-	this.nChildren = 0;
-	this.level = 0;
-	this.leftSideCoded = "";
-	this.isLastNode=false;
-	this.parentObj = null;
-	this.maySelect=true;
-	this.prependHTML = "";
-
-	/* dynamic data */
-	this.isOpen = false;
-	this.isLastOpenedFolder = false;
-	this.isRendered = 0;
-
-	/* methods */
-	this.initialize = initializeFolder;
-	this.setState = setStateFolder;
-	this.addChild = addChild;
-	this.createIndex = createEntryIndex;
-	this.escondeBlock = escondeBlock;
-	this.esconde = escondeFolder;
-	this.folderMstr = folderMstr;
-	this.renderOb = drawFolder;
-	this.totalHeight = totalHeight;
-	this.subEntries = folderSubEntries;
-	this.linkHTML = linkFolderHTML;
-	this.blockStartHTML = blockStartHTML;
-	this.blockEndHTML = blockEndHTML;
-	this.nodeImageSrc = nodeImageSrc;
-	this.iconImageSrc = iconImageSrc;
-	this.getID = getID;
-	this.forceOpeningOfAncestorFolders = forceOpeningOfAncestorFolders;
-}
-
-function initializeFolder(level, lastNode, leftSide)
-{
-	var j=0;
-	var i=0;
-	nc = this.nChildren;
-
-	this.createIndex();
-	this.level = level;
-	this.leftSideCoded = leftSide;
-
-	if(browserVersion == 0 || STARTALLOPEN==1)
-		this.isOpen=true;
-
-	if(level>0)
- 	if(lastNode)
- 		/* the last child in the children array */
- 		leftSide = leftSide + "0";
-	else
-		leftSide = leftSide + "1";
-
-	this.isLastNode = lastNode;
-
-	if(nc > 0)
-	{
- 		level = level + 1;
- 		for (i = 0; i < this.nChildren; i++)
- 		{
-  			if (i == this.nChildren-1)
-				this.children[i].initialize(level, 1, leftSide);
-  			else
-				this.children[i].initialize(level, 0, leftSide);
- 		}
-	}
-}
-
-function drawFolder(insertAtObj)
-{
- 	var nodeName = "";
- 	var auxEv = "";
- 	var docW = "";
-
- 	var leftSide = leftSideHTML(this.leftSideCoded);
-
- 	if (browserVersion > 0)
-  	auxEv = "<span onClick='clickOnNode(\""+this.getID()+"\")' onMouseOver='showCursor(this);'>";
- 	else
-  	auxEv = "<span>";
-
- 	nodeName = this.nodeImageSrc();
-
- 	if (this.level>0)
-  	if (this.isLastNode)
-  		/* the last child in the children array */
-  		leftSide = leftSide + "<td valign=top>" + auxEv +
-  		    "<img name='nodeIcon" + this.id + "' id='nodeIcon" +
-  		    this.id + "' src='" + nodeName + "' height=16 border=0></span></td>";
-  	else
-   		leftSide = leftSide + "<td valign=top background=" + ICONPATH + "line.gif>" + auxEv +
-   		    "<img name='nodeIcon" + this.id + "' id='nodeIcon" +
-   		    this.id + "' src='" + nodeName + "' height=16 border=0></span></td>";
-
- 	this.isRendered = 1;
-
- 	if (browserVersion == 2)
- 	{
-  	if (!doc.yPos)
-   	doc.yPos=20;
- 	}
-
- 	docW = this.blockStartHTML("folder");
-
- 	docW = docW + "<tr>" + leftSide + "<td valign=top>";
- 	if (USEICONS)
- 	{
-  		docW = docW + auxEv;/* this.linkHTML(false) */
-  	 	docW = docW + "<img id='folderIcon" + this.id + "' name='folderIcon" + this.id + "' src='" + this.iconImageSrc() + "' border=0></span>";
-  	}
-  	else
-  	{
-		if (this.prependHTML == "")
-  		docW = docW + "<img src=" + ICONPATH + "themespacer.gif height=2 width=2>";
-  	}
-
-  	if (WRAPTEXT)
-		docW = docW + "</td>"+this.prependHTML+"<td valign=middle width=100%>";
-  	else
-	  	docW = docW + "</td>"+this.prependHTML+"<td valign=middle nowrap width=100%>";
-  	if (USETEXTLINKS)
-  	{
- 		if(this.linkHTML(true)=="<a>" && (this.getID()!=0))
-			docW = docW + auxEv + this.desc + "</span>";
-		else
- 			docW = docW + this.linkHTML(true) + this.desc + "</a>";
-  	}
- 	else
- 	docW = docW + auxEv + this.desc + "</span>";
-
-  	docW = docW + "</td>";
-  	docW = docW + this.blockEndHTML();
-
-  	if (insertAtObj == null)
-  	{
-		if (supportsDeferral)
-		{
-			doc.write("<div id=domRoot></div>"); /* transition between regular flow HTML, and node-insert DOM DHTML */
-			insertAtObj = getElById("domRoot");
-		  	insertAtObj.insertAdjacentHTML("beforeEnd", docW);
-	  	}
-	  	else
-		  	doc.write(docW);
-  	}
-  	else
-  	{
-   	insertAtObj.insertAdjacentHTML("afterEnd", docW);
-  	}
-
-  	if (browserVersion == 2)
-  	{
- 	this.navObj = doc.layers["folder"+this.id];
- 	if (USEICONS)
-   		this.iconImg = this.navObj.document.images["folderIcon"+this.id]
- 	this.nodeImg = this.navObj.document.images["nodeIcon"+this.id];
-   	 doc.yPos=doc.yPos+this.navObj.clip.height;
-  	}
-  	else if (browserVersion != 0)
-  	{
-  		this.navObj = getElById("folder"+this.id);
-   		if (USEICONS)
-   		this.iconImg = getElById("folderIcon"+this.id);
- 	this.nodeImg = getElById("nodeIcon"+this.id);
-  	}
-}
-
-function setStateFolder(isOpen)
-{
-  	var subEntries;
-  	var totalHeight;
-  	var fIt = 0;
-  	var i=0;
-  	var currentOpen;
-
-  	if (isOpen == this.isOpen)
- 	return;
-
-  	if (browserVersion == 2)
-  	{
- 	totalHeight = 0;
- 	for (i=0; i < this.nChildren; i++)
-  		totalHeight = totalHeight + this.children[i].navObj.clip.height;
-   	subEntries = this.subEntries();
- 	if (this.isOpen)
-   		totalHeight = 0 - totalHeight;
- 	for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++)
-  		indexOfEntries[fIt].navObj.moveBy(0, totalHeight);
-  	}
-  	this.isOpen = isOpen;
-
- 	if (this.getID()!=foldersTree.getID() && PERSERVESTATE && !this.isOpen) /* closing */
- 	{
- 		currentOpen = GetCookie("clickedFolder");
-  		if (currentOpen != null)
-  		{
-  			currentOpen = currentOpen.replace(this.getID()+cookieCutter, "");
-   			SetCookie("clickedFolder", currentOpen);
-  		}
-  	}
-
-  	if (!this.isOpen && this.isLastOpenedfolder)
-  	{
-		lastOpenedFolder = null;
-		this.isLastOpenedfolder = false;
-  	}
- 	propagateChangesInState(this);
-}
-
-function propagateChangesInState(folder)
-{
-  	var i=0;
-
-  	/* Change icon */
-  	if (folder.nChildren > 0 && folder.level>0)  /* otherwise the one given at render stays */
-  		folder.nodeImg.src = folder.nodeImageSrc();
-
-  	/* Change node */
-  	if (USEICONS)
- 		folder.iconImg.src = folder.iconImageSrc();
-
-  	/* Propagate changes */
-  	for (i=folder.nChildren-1; i>=0; i--)
- 		if (folder.isOpen)
-   			folder.children[i].folderMstr(folder.navObj);
- 		else
-  	  		folder.children[i].esconde();
-}
-
-function escondeFolder()
-{
-  	this.escondeBlock();
-
-  	this.setState(0);
-}
-
-function linkFolderHTML(isTextLink)
-{
-  	var docW = "";
-
-  	if (this.hreference)
-  	{
-		if (USEFRAMES)
-	  		docW = docW + "<a href='" + this.hreference + "' TARGET=\"ifrMain\" ";
-		else
-	  		docW = docW + "<a href='" + this.hreference + "' TARGET=_top ";
-
- 	if (isTextLink)
- 	{
- 		docW += "id=\"itemTextLink"+this.id+"\" ";
- 	}
-
- 	if (browserVersion > 0)
-   		docW = docW + "onClick='javascript:clickOnFolder(\""+this.getID()+"\")'";
-
- 	docW = docW + ">";
-  	}
-  	else
-  	{
- 	docW = docW + "<a>";
-  	}
-
-  	return docW;
-}
-
-function addChild(childNode)
-{
-  	this.children[this.nChildren] = childNode;
-  	childNode.parentObj = this;
-  	this.nChildren++;
-  	return childNode;
-}
-
-function folderSubEntries()
-{
-  	var i = 0;
-  	var se = this.nChildren;
-
-  	for (i=0; i < this.nChildren; i++)
-  	{
- 		if (this.children[i].children) /* is a folder */
-   			se = se + this.children[i].subEntries();
-  	}
-  	return se;
-}
-
-function nodeImageSrc()
-{
-  	var srcStr = "";
-  	if (this.isLastNode) /* the last child in the children array */
-  	{
- 		if (this.nChildren == 0)
-   			srcStr = ICONPATH + "joinbottom.gif";
- 		else if (this.isOpen)
-  			srcStr = ICONPATH + "minusbottom.gif";
-		else
-  			srcStr = ICONPATH + "plusbottom.gif";
-  	}
-  	else
-  	{
- 		if (this.nChildren == 0)
-   			srcStr = ICONPATH + "join.gif";
- 		else if (this.isOpen)
-  			srcStr = ICONPATH + "minus.gif";
-   		else
-  			srcStr = ICONPATH + "plus.gif";
-  	}
-  	return srcStr;
-}
-
-function iconImageSrc()
-{
-  	if (this.isOpen)
- 	return(this.iconSrc);
-  	else
- 	return(this.iconSrcClosed);
-}
-
-/*
- * Definition of class Item (a document or link inside a Folder)
- */
-function Item(itemDescription, itemLink, target) /*  Constructor */
-{
-  	/*  constant data */
-  	this.desc = itemDescription;
-  	this.link = ""+itemLink;
-  	this.id = -1; /* initialized in initalize() */
-  	this.navObj = 0 ;/* initialized in render() */
-  	this.iconImg = 0; /* initialized in render() */
-  	this.iconSrc = ICONPATH + "text.gif";
-  	this.isRendered = 0;
-  	this.isLastNode = false;
-  	this.level = 0;
-  	this.leftSideCoded = "";
-  	this.nChildren = 0;
-  	this.target = target;
-  	this.parentObj = null;
-  	this.maySelect=true;
-  	this.prependHTML = "";
-
-  	/*  methods */
-  	this.initialize = initializeItem;
-  	this.createIndex = createEntryIndex;
-  	this.escondeBlock = escondeBlock;
-  	this.esconde = escondeBlock;
-  	this.folderMstr = folderMstr;
-  	this.renderOb = drawItem;
-  	this.totalHeight = totalHeight;
-  	this.blockStartHTML = blockStartHTML;
-  	this.blockEndHTML = blockEndHTML;
-  	this.getID = getID;
-  	this.forceOpeningOfAncestorFolders = forceOpeningOfAncestorFolders;
-}
-
-function initializeItem(level, lastNode, leftSide)
-{
-  	this.createIndex();
-  	this.level = level;
-  	this.leftSideCoded = leftSide;
-  	this.isLastNode = lastNode;
-}
-
-function drawItem(insertAtObj)
-{
-  	var leftSide = leftSideHTML(this.leftSideCoded);
-  	var docW = "";
-
-	/*
-	 * In Netscape, it will calling onclick function first and open new window, but it's wrong!
-	 * We don't really know this onclick function use for what and remove it!
-	 * var fullLink = "href=\""+this.link+"\" target=\""+this.target+"\"
-	 * onClick=\"clickOnLink('"+this.getID()+"\', '"+this.link+"','"+this.target+"');return false;\"";
-	 */
-  	var fullLink = 'href=\"'+this.link+'\" target=\"'+this.target+'\"';
-
- 	this.isRendered = 1;
-
-  	if (this.level>0)
- 		if (this.isLastNode) /* the last 'brother' in the children array */
- 		{
-  			leftSide = leftSide + "<td valign=top><img src='" + ICONPATH + "joinbottom.gif' height=16 ></td>";
- 		}
- 		else
- 		{
-  			leftSide = leftSide + "<td valign=top background=" + ICONPATH + "line.gif><img src='" + ICONPATH + "join.gif' height=16 ></td>";
- 		}
-
-  	docW = docW + this.blockStartHTML("item");
-
-  	docW = docW + "<tr>" + leftSide + "<td valign=top>";
-  	if (USEICONS)
- 		docW = docW + "<a " + fullLink  + " id=\"itemIconLink"+this.id+"\">" +
- 		    "<img id='itemIcon"+this.id+"' " + "src='"+this.iconSrc+"' border=0>" + "</a>";
-  	else if (this.prependHTML == "")
-    		docW = docW + "<img src=" + ICONPATH + "themespacer.gif height=2 width=3>";
-
-  	if (WRAPTEXT)
- 		docW = docW + "</td>"+this.prependHTML+"<td valign=middle width=100%>";
-  	else
- 		docW = docW + "</td>"+this.prependHTML+"<td valign=middle nowrap width=100%>";
-
-  	if (USETEXTLINKS)
- 		docW = docW + "<a " + fullLink + " id=\"itemTextLink"+this.id+"\">" + this.desc + "</a>";
-  	else
- 		docW = docW + this.desc;
-
-  	docW = docW + "</td>";
-
-  	docW = docW + this.blockEndHTML();
-
-  	if (insertAtObj == null)
-  	{
-		doc.write(docW);
-  	}
-  	else
-  	{
- 		insertAtObj.insertAdjacentHTML("afterEnd", docW);
-  	}
-
-  	if (browserVersion == 2)
-  	{
- 		this.navObj = doc.layers["item"+this.id];
- 		if (USEICONS)
- 			this.iconImg = this.navObj.document.images["itemIcon"+this.id];
- 		doc.yPos=doc.yPos+this.navObj.clip.height;
-  	}
-  	else if (browserVersion != 0)
-  	{
- 		this.navObj = getElById("item"+this.id);
- 		if (USEICONS)
- 			this.iconImg = getElById("itemIcon"+this.id);
-  	}
-}
-
-
-/*
- * Methods common to both objects (pseudo-inheritance)
- */
-function forceOpeningOfAncestorFolders()
-{
-  	if (this.parentObj == null || this.parentObj.isOpen)
- 		return;
-  	else
-  	{
- 		this.parentObj.forceOpeningOfAncestorFolders();
- 		clickOnNodeObj(this.parentObj);
-  	}
-}
-
-function escondeBlock()
-{
-  	if (browserVersion == 1 || browserVersion == 3)
-  	{
- 		if (this.navObj.style.display == "none")
-   			return;
- 		this.navObj.style.display = "none";
-  	}
-  	else
-  	{
- 		if (this.navObj.visibility == "hidden")
-   			return;
- 		this.navObj.visibility = "hidden";
-  	}
-}
-
-function folderMstr(domObj)
-{
-  	if (browserVersion == 1 || browserVersion == 3)
-  	{
-   		if (t==-1)
-   		return;
-  	}
-
-  	if (!this.isRendered)
-  		this.renderOb(domObj);
-  	else if (browserVersion == 1 || browserVersion == 3)
-   		this.navObj.style.display = "block";
-	else
-   		this.navObj.visibility = "show";
-}
-
-function blockStartHTML(idprefix)
-{
-  	var idParam = "id='" + idprefix + this.id + "'";
-  	var docW = "";
-
-  	if (browserVersion == 2)
- 	docW = "<layer "+ idParam + " top=" + doc.yPos + " visibility=show>";
-  	else if (browserVersion != 0)
- 	docW = "<div " + idParam + " style='display:block; position:block;'>";
-
-  	docW = docW + "<table border=0 cellspacing=0 cellpadding=0 width=100% >";
-
-  	return docW;
-}
-
-function blockEndHTML()
-{
-  	var docW = "";
-
-  	docW = "</table>";
-
-  	if (browserVersion == 2)
- 	docW = docW + "</layer>";
-  	else if (browserVersion != 0)
- 	docW = docW + "</div>";
-
-  	return docW;
-}
-
-function createEntryIndex()
-{
-  	this.id = nEntries;
-  	indexOfEntries[nEntries] = this;
-  	nEntries++;
-}
-
-/*
- * total height of subEntries open
- */
-function totalHeight() /* used with browserVersion == 2 */
-{
-  	var h = this.navObj.clip.height;
-  	var i = 0;
-
-  	if (this.isOpen) /* is a folder and _is_ open */
-  		for (i=0 ; i < this.nChildren; i++)
-   			h = h + this.children[i].totalHeight();
-
-  	return h;
-}
-
-
-function leftSideHTML(leftSideCoded)
-{
-	var i;
-	var retStr = "";
-
-	for (i=0; i<leftSideCoded.length; i++)
-	{
-		if (leftSideCoded.charAt(i) == "1")
-		{
-			retStr = retStr + "<td valign=top background=" + ICONPATH + "line.gif><img src='" + ICONPATH + "line.gif' height=16 ></td>";
-		}
-		if (leftSideCoded.charAt(i) == "0")
-		{
-			retStr = retStr + "<td valign=top><img src='" + ICONPATH + "themespacer.gif' height=16 ></td>";
-		}
-	}
-	return retStr;
-}
-
-function getID()
-{
-	/*
-	 * define a .xID in all nodes (folders and items) if you want to PERVESTATE that
-	 * work when the tree changes. The value eXternal value must be unique for each
-	 * node and must node change when other nodes are added or removed
-	 * The value may be numeric or string, but cannot have the same char used in cookieCutter */
-	if (typeof this.xID != "undefined")
- 		return this.xID;
-  	else
- 		return this.id;
-}
-
-
-/*  Events */
-function clickOnFolder(folderId)
-{
-	var clicked = findObj(folderId);
-
-	if (!clicked.isOpen)
-	{
- 		clickOnNodeObj(clicked);
-	}
-
-	if (lastOpenedFolder != null && lastOpenedFolder != folderId)
- 		/* sets lastOpenedFolder to null */
- 		clickOnNode(lastOpenedFolder);
-	if (clicked.nChildren==0)
-	{
-   		lastOpenedFolder = folderId;
-   		clicked.isLastOpenedfolder = true;
-	}
-
-	if (isLinked(clicked.hreference))
-	{
-		highlightObjLink(clicked);
-	}
-}
-
-function clickOnNode(folderId)
-{
-  	clickOnNodeObj(findObj(folderId));
-}
-
-function clickOnNodeObj(folderObj)
-{
-  	var state = 0;
-  	var currentOpen;
-
-  	if(folderObj.getID() == 0)
-  	{
-  		state = false; /* Header */
-  	}
-  	else
-  	{
-  		state = folderObj.isOpen;
-  	}
-
-  	folderObj.setState(!state); /* open<->close */
-
-  	if (folderObj.id!=foldersTree.id && PERSERVESTATE)
-  	{
- 		currentOpen = GetCookie("clickedFolder");
- 		if (currentOpen == null)
-   			currentOpen = "";
-
- 		if (!folderObj.isOpen) /* closing */
- 		{
-  			currentOpen = currentOpen.replace(folderObj.getID()+cookieCutter, "");
-   			SetCookie("clickedFolder", currentOpen);
- 		}
- 		else
-   			SetCookie("clickedFolder", currentOpen+folderObj.getID()+cookieCutter);
-  	}
-}
-
-function clickOnLink(clickedId, target, windowName)
-{
- 	highlightObjLink(findObj(clickedId));
-
- 	if (isLinked(target))
- 	{
-  		window.open(target,windowName);
- 	}
-}
-
-function ld()
-{
-	/* return document.links.length-1  original */
-	return 0;
-}
-
-
-/* Auxiliary Functions */
-function findObj(id)
-{
-  	var i=0;
- 	var nodeObj;
-
-  	if (typeof foldersTree.xID != "undefined")
-  	{
- 		nodeObj = indexOfEntries[i];
- 		for(i=0;i<nEntries&&indexOfEntries[i].xID!=id;i++)
- 			/* may need optimization */
- 			;
- 		id = i;
-  	}
- 	if (id >= nEntries)
- 		return null; /* example: node removed in DB */
- 	else
- 		return indexOfEntries[id];
-}
-
-function isLinked(hrefText)
-{
-	var result = true;
-	result = (result && hrefText !=null);
-	result = (result && hrefText != '');
-	result = (result && hrefText.indexOf('undefined') < 0);
-	result = (result && hrefText.indexOf('parent.op') < 0);
-	return result;
-}
-
-/* Do highlighting by changing background and foreg. colors of folder or doc text */
-function highlightObjLink(nodeObj)
-{
-  	if (!HIGHLIGHT || nodeObj==null || nodeObj.maySelect==false)
-  	{
-  		/* node deleted in DB */
-  		return;
-  	}
-
-  	if (browserVersion == 1 || browserVersion == 3)
-  	{
- 		var clickedDOMObj = getElById('itemTextLink'+nodeObj.id);
- 		if (clickedDOMObj != null)
- 		{
-  			if (lastClicked != null)
-  			{
-     				var prevClickedDOMObj = getElById('itemTextLink'+lastClicked.id);
-   				prevClickedDOMObj.style.color=lastClickedColor;
-   				prevClickedDOMObj.style.backgroundColor=lastClickedBgColor;
-  			}
-
-  			lastClickedColor = clickedDOMObj.style.color;
-  			lastClickedBgColor  = clickedDOMObj.style.backgroundColor;
-  			clickedDOMObj.style.color=HIGHLIGHT_COLOR;
-  			clickedDOMObj.style.backgroundColor=HIGHLIGHT_BG;
- 		}
-  	}
-
-  	lastClicked = nodeObj;
-  	if (PERSERVESTATE)
- 		SetCookie('highlightedTreeviewLink', nodeObj.getID());
-}
-
-function gFld(description, hreference)
-{
-  	folder = new Folder(description, hreference);
-  	return folder;
-}
-
-function gHeader(description, hreference)
-{
-  	header = new Header(description, hreference);
-  	return header ;
-}
-
-function gLnk(optionFlags, description, linkData)
-{
-  	var fullLink = "";
-  	var targetFlag = "";
-  	var target = "";
-  	var protocolFlag = "";
-  	var protocol = "";
-
-  	if (optionFlags>=0) /* is numeric (old style) or empty (error) */
-  	{
- 		return oldGLnk(optionFlags, description, linkData);
-  	}
-
-  	targetFlag = optionFlags.charAt(0);
-  	if (targetFlag=="B")
- 		target = "_blank";
-  	if (targetFlag=="P")
- 		target = "_parent";
- 	if (targetFlag=="R")
- 		target = "ifrMain";
-  	if (targetFlag=="S")
- 		target = "_self";
-  	if (targetFlag=="T")
- 		target = "_top";
-
-  	if (optionFlags.length > 1)
-  	{
- 		protocolFlag = optionFlags.charAt(1);
- 		if (protocolFlag=="h")
-   			protocol = "http://";
- 		if (protocolFlag=="s")
-   			protocol = "https://";
- 		if (protocolFlag=="f")
-   			protocol = "ftp://";
- 		if (protocolFlag=="m")
-   			protocol = "mailto:";
-  	}
-
-  	fullLink = "'" + protocol + linkData + "'  target='" + target + "'";
-
-  	linkItem = new Item(description, protocol+linkData, target);
-  	return linkItem;
-}
-
-/* Function created Aug 1, 2002 for backwards compatibility purposes */
-function oldGLnk(target, description, linkData)
-{
-  	var fullLink = "";
-	/* Backwards compatibility code */
-	if (USEFRAMES)
-  	{
-	  	if (target==0)
-	  	{
-			fullLink = "'"+linkData+"' target=\"ifrMain\"";
-	  	}
-	  	else
-	  	{
-			if (target==1)
-		   		fullLink = "'http://"+linkData+"' target=_blank";
-			else if (target==2)
-			 	fullLink = "'http://"+linkData+"' target=\"ifrMain\"";
-		   	else
-			  	fullLink = linkData+" target=\"_top\"";
-	  	}
-  	}
-  	else
-  	{
-	  	if (target==0)
-	  	{
-			fullLink = "'"+linkData+"' target=_top";
-	  	}
-	  	else
-	  	{
-			if (target==1)
-		   		fullLink = "'http://"+linkData+"' target=_blank";
-			else
-		   		fullLink = "'http://"+linkData+"' target=_top";
-	  	}
- 	}
-
-  	linkItem = new Item(description, fullLink);
-  	return linkItem;
-}
-
-function insFld(parentFolder, childFolder)
-{
-  	return parentFolder.addChild(childFolder);
-}
-
-function insDoc(parentFolder, document)
-{
-  	return parentFolder.addChild(document);
-}
-
-function preLoadIcons()
-{
-	var auxImg;
-	var ICONPATH = "";
-	auxImg = new Image();
-	auxImg.src = ICONPATH + "line.gif";
-	auxImg.src = ICONPATH + "minusbottom.gif";
-	auxImg.src = ICONPATH + "minus.gif";
-	auxImg.src = ICONPATH + "plusbottom.gif";
-	auxImg.src = ICONPATH + "plus.gif";
-	auxImg.src = ICONPATH + "themespacer.gif";
-	auxImg.src = ICONPATH + "joinbottom.gif";
-	auxImg.src = ICONPATH + "join.gif";
-	auxImg.src = ICONPATH + "folder.gif";
-	auxImg.src = ICONPATH + "open_folder.gif";
-	auxImg.src = ICONPATH + "text.gif";
-}
-
-/* Open some folders for initial layout, if necessary */
-function setInitialLayout()
-{
-  	if (browserVersion > 0 && !STARTALLOPEN)
- 		clickOnNodeObj(foldersTree);
-
-  	if (!STARTALLOPEN && (browserVersion > 0) && PERSERVESTATE)
-		PersistentFolderOpening();
-}
-
-/* Used with NS4 and STARTALLOPEN */
-function renderAllTree(nodeObj, parent)
-{
-  	var i=0;
-  	nodeObj.renderOb(parent);
-  	if (supportsDeferral)
- 	for (i=nodeObj.nChildren-1; i>=0; i--)
-   		renderAllTree(nodeObj.children[i], nodeObj.navObj);
-  	else
- 	for (i=0 ; i < nodeObj.nChildren; i++)
-   		renderAllTree(nodeObj.children[i], null);
-}
-
-function hideWholeTree(nodeObj, hideThisOne, nodeObjMove)
-{
-  	var i=0;
-  	var heightContained=0;
-  	var childrenMove=nodeObjMove;
-
-  	if (hideThisOne)
- 	nodeObj.escondeBlock();
-
-  	if (browserVersion == 2)
- 	nodeObj.navObj.moveBy(0, 0-nodeObjMove);
-
-  	for (i=0 ; i < nodeObj.nChildren; i++)
-  	{
- 	heightContainedInChild = hideWholeTree(nodeObj.children[i], true, childrenMove)
- 	if (browserVersion == 2)
- 	{
-   		heightContained = heightContained + heightContainedInChild + nodeObj.children[i].navObj.clip.height;
-   		childrenMove = childrenMove + heightContainedInChild;
-		}
-  	}
-
-  	return heightContained;
-}
-
-/*
- *	Simulating inserAdjacentHTML on NS6
- *	Code by [email protected]
- */
-
-if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
-{
-	HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode)
-	{
-		switch (where)
-		{
-			case 'beforeBegin':
-				this.parentNode.insertBefore(parsedNode,this)
-				break;
-			case 'afterBegin':
-				this.insertBefore(parsedNode,this.firstChild);
-				break;
-			case 'beforeEnd':
-				this.appendChild(parsedNode);
-				break;
-			case 'afterEnd':
-				if (this.nextSibling)
-					this.parentNode.insertBefore(parsedNode,this.nextSibling);
-				else
-					this.parentNode.appendChild(parsedNode);
-			break;
-		}
-	}
-
-	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
-	{
-		var r = this.ownerDocument.createRange();
-		r.setStartBefore(this);
-		var parsedHTML = r.createContextualFragment(htmlStr);
-		this.insertAdjacentElement(where,parsedHTML);
-	}
-}
-
-function getElById(idVal)
-{
-  	if (document.getElementById != null)
- 	return document.getElementById(idVal);
-  	if (document.all != null)
- 	return document.all[idVal];
-
-  	alert("Problem getting element by id");
-  	return null;
-}
-
-/* Functions for cookies
- * Note: THESE FUNCTIONS ARE OPTIONAL. No cookies are used unless
- * the PERSERVESTATE variable is set to 1 (default 0)
- * The separator currently in use is ^ (chr 94)
- */
-
-function PersistentFolderOpening()
-{
-  	var stateInCookie;
-  	var fldStr="";
-  	var fldArr;
-  	var fldPos=0;
-  	var id;
-  	var nodeObj;
-  	stateInCookie = GetCookie("clickedFolder");
-  	SetCookie('clickedFolder', "");
-  	/* at the end of function it will be back, minus null cases */
-
-  	if(stateInCookie!=null)
-  	{
- 		fldArr = stateInCookie.split(cookieCutter);
- 		for (fldPos=0; fldPos<fldArr.length; fldPos++)
- 		{
-   			fldStr=fldArr[fldPos];
-   			if (fldStr != "")
-   			{
-    		 		nodeObj = findObj(fldStr);
-  				if (nodeObj!=null) /* may have been deleted */
-  					if (nodeObj.setState)
-    					{
-   						nodeObj.forceOpeningOfAncestorFolders();
-   						clickOnNodeObj(nodeObj);
-    					}
-    					else
-   						alert("Internal id is not pointing to a folder anymore. Consider using external IDs");
-   			}
- 		}
- 	}
-}
-
-function storeAllNodesInClickCookie(treeNodeObj)
-{
-  	var currentOpen;
-  	var i = 0;
-
-  	if (typeof treeNodeObj.setState != "undefined") /* is folder */
-  	{
- 		currentOpen = GetCookie("clickedFolder");
- 		if (currentOpen == null)
-   			currentOpen = "";
-
- 		if (treeNodeObj.getID() != foldersTree.getID())
-   			SetCookie("clickedFolder", currentOpen+treeNodeObj.getID()+cookieCutter);
-
- 		for (i=0; i < treeNodeObj.nChildren; i++)
-  		storeAllNodesInClickCookie(treeNodeObj.children[i]);
-  	}
-}
-
-function CookieBranding(name)
-{
-  	if (typeof foldersTree.treeID != "undefined")
-  		 /* needed for multi-tree sites. make sure treeId does not contain cookieCutter; */
- 		return name+foldersTree.treeID;
- 	else
- 		return name;
-}
-
-function GetCookie(name)
-{
-  	name = CookieBranding(name);
-
-	var arg = name + "=";
-	var alen = arg.length;
-	var clen = document.cookie.length;
-	var i = 0;
-
-	while (i < clen)
-	{
-		var j = i + alen;
-		if (document.cookie.substring(i, j) == arg)
-			return getCookieVal (j);
-		i = document.cookie.indexOf(" ", i) + 1;
-		if (i == 0)
-			break;
-	}
-	return null;
-}
-
-function getCookieVal(offset)
-{
-	var endstr = document.cookie.indexOf (";", offset);
-	if (endstr == -1)
-		endstr = document.cookie.length;
-	return unescape(document.cookie.substring(offset, endstr));
-}
-
-function SetCookie(name, value)
-{
-	var argv = SetCookie.arguments;
-	var argc = SetCookie.arguments.length;
-	var expires = (argc > 2) ? argv[2] : null;
-	var domain = (argc > 4) ? argv[4] : null;
-	var secure = (argc > 5) ? argv[5] : false;
-	var path = "/";
-	/* allows the tree to remain open across pages with diff names & paths */
-  	name = CookieBranding(name);
-
-	document.cookie = name + "=" + escape (value) +
-	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
-	((path == null) ? "" : ("; path=" + path)) +
-	((domain == null) ? "" : ("; domain=" + domain)) +
-	((secure == true) ? "; secure" : "");
-}
-
-function ExpireCookie (name)
-{
-	var exp = new Date();
-	exp.setTime (exp.getTime() - 1);
-	var cval = GetCookie (name);
-  	name = CookieBranding(name);
-	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
-}
-
-
-/* To customize the tree, overwrite these variables in the configuration file (demoFramesetNode.js, etc.) */
-var USETEXTLINKS = 0;
-var STARTALLOPEN = 0;
-var USEFRAMES = 1;
-var USEICONS = 1;
-var WRAPTEXT = 0;
-var PERSERVESTATE = 0;
-var ICONPATH = 'img';
-var HIGHLIGHT = 0;
-var HIGHLIGHT_COLOR = 'white';
-var HIGHLIGHT_BG = 'blue';
-var BUILDALL = 0;
-
-
-/* Other variables */
-var lastClicked = null;
-var lastClickedColor;
-var lastClickedBgColor;
-var indexOfEntries = new Array;
-var nEntries = 0;
-var browserVersion = 0;
-var selectedFolder=0;
-var lastOpenedFolder=null;
-var t=5;
-var doc = document;
-var supportsDeferral = false;
-var cookieCutter = '^' ;
-/* You can change this if you need to use ^ in your xID or treeID values */
-doc.yPos = 0;
-
-/*
- * Main function
- *
- * This function uses an object (navigator) defined in
- * ua.js, imported in the main html page (left frame).
- */
-function initializeDocument()
-{
-  	preLoadIcons();
-  	switch(navigator.family)
-  	{
- 	case 'ie4':
- 		/* Simply means IE > 3.x */
-   		browserVersion = 1;
-   		break;
- 	case 'opera':
- 		/* opera7 has a good DOM */
-   		browserVersion = (navigator.version > 6 ? 1 : 0);
-   		break;
- 	case 'nn4':
- 		/* NS4.x */
-   		browserVersion = 2;
-   		break;
- 	case 'gecko':
-   		/* NS6.x */
-   		browserVersion = 3;
-   		break;
- 	case 'safari':
- 		/* Safari Beta 3 seems to behave like IE in spite of being based on Konkeror */
-   		browserVersion = 1;
-   		break;
-	default:
-		/* other, possibly without DHTML */
-   		browserVersion = 0;
-   		break;
- 	}
-
-  	supportsDeferral = ((navigator.family=='ie4' && navigator.version >= 5 && navigator.OS != "mac") || browserVersion == 3);
-  	supportsDeferral = supportsDeferral & (!BUILDALL);
-  	if (!USEFRAMES && browserVersion == 2)
-  		browserVersion = 0;
-  	eval(String.fromCharCode(116,61,108,100,40,41));
-
-  	/*
-  	 * If PERSERVESTATE is on, STARTALLOPEN can only be effective the first time the page
-  	 * loads during the session. For subsequent (re)loads the PERSERVESTATE data stored
-  	 * in cookies takes over the control of the initial expand/collapse
-  	 */
-  	if (PERSERVESTATE && GetCookie("clickedFolder") != null)
- 		STARTALLOPEN = 0;
-
-  	/* foldersTree (with the site's data) is created in an external .js (demoFramesetNode.js, for example) */
-  	foldersTree.initialize(0, true, "");
-  	if (supportsDeferral && !STARTALLOPEN)
-	  	foldersTree.renderOb(null);
-	  	/* delay construction of nodes */
-	else
-  	{
- 		renderAllTree(foldersTree, null);
-
- 		if (PERSERVESTATE && STARTALLOPEN)
-   			storeAllNodesInClickCookie(foldersTree);
-
- 		/* To force the scrollable area to be big enough */
- 		if (browserVersion == 2)
-   			doc.write("<layer top=" + indexOfEntries[nEntries-1].navObj.top + ">&nbsp;</layer>");
-
- 		if (browserVersion != 0 && !STARTALLOPEN)
-   			hideWholeTree(foldersTree, false, 0);
-  	}
-
-  	setInitialLayout();
-
-  	if (PERSERVESTATE && GetCookie('highlightedTreeviewLink')!=null  && GetCookie('highlightedTreeviewLink')!="")
-  	{
- 		var nodeObj = findObj(GetCookie('highlightedTreeviewLink'));
- 		if (nodeObj!=null)
- 		{
-   			nodeObj.forceOpeningOfAncestorFolders();
-   			highlightObjLink(nodeObj);
- 		}
- 		else
-  			SetCookie('highlightedTreeviewLink', '');
-  	}
-}
-
-function showCursor(targetObj)
-{
-	if(navigator.appName =="Microsoft Internet Explorer")
-		targetObj.style.cursor = "hand";
-	else
- 		targetObj.style.cursor = "pointer";
-
-}
-
-
-function xbDetectBrowser()
-{
-    if (window.hasOwnProperty("onerror"))
-  	var oldOnError = window.onerror;
-  	var element = null;
-
-    if (window.hasOwnProperty("onerror"))
-  	window.onerror = null;
-
- 	/*  work around bug in xpcdom Mozilla 0.9.1 */
- 	window.saveNavigator = window.navigator;
-
-  	navigator.OS = '';
-  	navigator.version  = parseFloat(navigator.appVersion);
-  	navigator.org = '';
-  	navigator.family  = '';
-
-  	var platform;
-  	if (typeof(window.navigator.platform) != 'undefined')
-  	{
- 		platform = window.navigator.platform.toLowerCase();
- 		if (platform.indexOf('win') != -1)
-   			navigator.OS = 'win';
- 		else if (platform.indexOf('mac') != -1)
-   			navigator.OS = 'mac';
- 		else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
-   			navigator.OS = 'nix';
-  	}
-
-  	var i = 0;
-  	var ua = window.navigator.userAgent.toLowerCase();
-
-  	if (ua.indexOf('safari') != -1)
-  	{
- 		i = ua.indexOf('safari');
- 		navigator.family = 'safari';
- 		navigator.org = 'safari';
- 		navigator.version = parseFloat('0' + ua.substr(i+7), 10);
-  	}
-  	else if (ua.indexOf('opera') != -1)
-  	{
-   	 	i = ua.indexOf('opera');
- 		navigator.family  = 'opera';
- 		navigator.org = 'opera';
- 		navigator.version  = parseFloat('0' + ua.substr(i+6), 10);
-  	}
-  	else if ((i = ua.indexOf('msie')) != -1)
-  	{
- 		navigator.org = 'microsoft';
- 		navigator.version  = parseFloat('0' + ua.substr(i+5), 10);
-
- 		if (navigator.version < 4)
-   			navigator.family = 'ie3';
- 		else
-   			navigator.family = 'ie4'
-  	}
-  	else if (ua.indexOf('gecko') != -1)
-  	{
- 		navigator.family = 'gecko';
- 		var rvStart = ua.indexOf('rv:');
- 		var rvEnd   = ua.indexOf(')', rvStart);
- 		var rv   = ua.substring(rvStart+3, rvEnd);
- 		var rvParts = rv.split('.');
- 		var rvValue = 0;
- 		var exp  = 1;
-
- 		for (var i = 0; i < rvParts.length; i++)
- 		{
-   			var val = parseInt(rvParts[i]);
-   			rvValue += val / exp;
-   			exp *= 100;
- 		}
- 		navigator.version = rvValue;
-
- 		if (ua.indexOf('netscape') != -1)
-   			navigator.org = 'netscape';
- 		else if (ua.indexOf('compuserve') != -1)
-   			navigator.org = 'compuserve';
- 		else
-   			navigator.org = 'mozilla';
-  	}
-  	else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) &&
-  		(ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1) &&
-  		(ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
-  	{
- 		var is_major = parseFloat(navigator.appVersion);
-
- 		if (is_major < 4)
-   			navigator.version = is_major;
- 		else
- 		{
-   			i = ua.lastIndexOf('/')
-  			navigator.version = parseFloat('0' + ua.substr(i+1), 10);
- 		}
- 		navigator.org = 'netscape';
- 		navigator.family = 'nn' + parseInt(navigator.appVersion);
-  	}
-  	else if ((i = ua.indexOf('aol')) != -1 )
-  	{
- 		/*  aol */
- 		navigator.family  = 'aol';
- 		navigator.org = 'aol';
- 		navigator.version  = parseFloat('0' + ua.substr(i+4), 10);
-  	}
-  	else if ((i = ua.indexOf('hotjava')) != -1 )
-  	{
- 		/*  hotjava */
- 		navigator.family  = 'hotjava';
- 		navigator.org = 'sun';
- 		navigator.version  = parseFloat(navigator.appVersion);
-  	}
-
-    if (window.hasOwnProperty("onerror"))
-  	window.onerror = oldOnError;
-}
-
-xbDetectBrowser();
-
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/ua.js	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-function xbDetectBrowser()
-{
-    if (window.hasOwnProperty("onerror"))
-	var oldOnError = window.onerror;
-  var element = null;
-
-    if (window.hasOwnProperty("onerror"))
-	window.onerror = null;
-
-  // work around bug in xpcdom Mozilla 0.9.1
-  window.saveNavigator = window.navigator;
-
-  navigator.OS    = '';
-  navigator.version  = parseFloat(navigator.appVersion);
-  navigator.org    = '';
-  navigator.family  = '';
-
-  var platform;
-  if (typeof(window.navigator.platform) != 'undefined')
-  {
-    platform = window.navigator.platform.toLowerCase();
-    if (platform.indexOf('win') != -1)
-      navigator.OS = 'win';
-    else if (platform.indexOf('mac') != -1)
-      navigator.OS = 'mac';
-    else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
-      navigator.OS = 'nix';
-  }
-
-  var i = 0;
-  var ua = window.navigator.userAgent.toLowerCase();
-
-  if (ua.indexOf('safari') != -1)
-  {
-    i = ua.indexOf('safari');
-    navigator.family = 'safari';
-    navigator.org = 'safari';
-    navigator.version = parseFloat('0' + ua.substr(i+7), 10);
-  }
-  else if (ua.indexOf('opera') != -1)
-  {
-    i = ua.indexOf('opera');
-    navigator.family  = 'opera';
-    navigator.org    = 'opera';
-    navigator.version  = parseFloat('0' + ua.substr(i+6), 10);
-  }
-  else if ((i = ua.indexOf('msie')) != -1)
-  {
-    navigator.org    = 'microsoft';
-    navigator.version  = parseFloat('0' + ua.substr(i+5), 10);
-
-    if (navigator.version < 4)
-      navigator.family = 'ie3';
-    else
-      navigator.family = 'ie4'
-  }
-  else if (ua.indexOf('gecko') != -1)
-  {
-    navigator.family = 'gecko';
-    var rvStart = ua.indexOf('rv:');
-    var rvEnd   = ua.indexOf(')', rvStart);
-    var rv      = ua.substring(rvStart+3, rvEnd);
-    var rvParts = rv.split('.');
-    var rvValue = 0;
-    var exp     = 1;
-
-    for (var i = 0; i < rvParts.length; i++)
-    {
-      var val = parseInt(rvParts[i]);
-      rvValue += val / exp;
-      exp *= 100;
-    }
-    navigator.version = rvValue;
-
-    if (ua.indexOf('netscape') != -1)
-      navigator.org = 'netscape';
-    else if (ua.indexOf('compuserve') != -1)
-      navigator.org = 'compuserve';
-    else
-      navigator.org = 'mozilla';
-  }
-  else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
-  {
-    var is_major = parseFloat(navigator.appVersion);
-
-    if (is_major < 4)
-      navigator.version = is_major;
-    else
-    {
-      i = ua.lastIndexOf('/')
-      navigator.version = parseFloat('0' + ua.substr(i+1), 10);
-    }
-    navigator.org = 'netscape';
-    navigator.family = 'nn' + parseInt(navigator.appVersion);
-  }
-  else if ((i = ua.indexOf('aol')) != -1 )
-  {
-    // aol
-    navigator.family  = 'aol';
-    navigator.org    = 'aol';
-    navigator.version  = parseFloat('0' + ua.substr(i+4), 10);
-  }
-  else if ((i = ua.indexOf('hotjava')) != -1 )
-  {
-    // hotjava
-    navigator.family  = 'hotjava';
-    navigator.org    = 'sun';
-    navigator.version  = parseFloat(navigator.appVersion);
-  }
-
-    if (window.hasOwnProperty("onerror"))
-	window.onerror = oldOnError;
-}
-
-xbDetectBrowser();
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/utils.js	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,475 +0,0 @@
-// ********************************* commjs start *****************************************************
-// if the characters of "char_code" is in following ones: 0~9, A~Z, a~z, some control key and TAB.
-function __is_comm_chars(char_code)
-{
-	if (char_code == 0)  return true;						/* some control key. */
-	if (char_code == 8)  return true;						/* TAB */
-	if (char_code >= 48 && char_code <= 57)  return true;	/* 0~9 */
-	if (char_code >= 65 && char_code <= 90)  return true;	/* A~Z */
-	if (char_code >= 97 && char_code <= 122) return true;	/* a~z */
-
-	return false;
-}
-function __is_char_in_string(target, pattern)
-{
-	var len = pattern.length;
-	var i;
-	for (i=0; i<len; i++)
-	{
-		if (target == pattern.charCodeAt(i)) return true;
-	}
-	return false;
-}
-//if the evt is in the allowed characters.
-function __is_evt_in_allow_chars(evt, allow_comm_chars, allow_chars)
-{
-	var char_code;
-	var i;
-
-	if (navigator.appName == 'Netscape'){char_code=evt.which;	}
-	else								{char_code=evt.keyCode;	}
-
-	if (allow_comm_chars == "1" && __is_comm_chars(char_code)==true) return true;
-	if (allow_chars.length > 0 && __is_char_in_string(char_code, allow_chars)==true) return true;
-
-	return false;
-}
-//if the characters of "str" are all in the allowed "allow_chars".
-function __is_str_in_allow_chars(str, allow_comm_chars, allow_chars)
-{
-	var char_code;
-	var i;
-
-	for (i=0; i<str.length; i++)
-	{
-		char_code=str.charCodeAt(i);
-		if (allow_comm_chars == "1" && __is_comm_chars(char_code) == true) continue;
-		if (allow_chars.length > 0 && __is_char_in_string(char_code, allow_chars) == true) continue;
-		return false;
-	}
-	return true;
-}
-// -------------------------------------------------------------
-
-// Get Object by ID.
-function get_obj(name)
-{
-	if (document.getElementById)	return document.getElementById(name);
-	if (document.all)		return document.all[name].style;
-	if (document.layers)		return document.layers[name];
-	return 0;
-}
-// generate the radmon str by date.
-function generate_random_str()
-{
-	var d = new Date();
-	var str=d.getFullYear()+"."+(d.getMonth()+1)+"."+d.getDate()+"."+d.getHours()+"."+d.getMinutes()+"."+d.getSeconds();
-	return str;
-}
-// this function is used to check if the inputted string is blank or not.
-function is_blank(s)
-{
-	var i=0;
-	for(i=0;i<s.length;i++)
-	{
-		c=s.charAt(i);
-		if((c!=' ')&&(c!='\n')&&(c!='\t'))return false;
-	}
-	return true;
-}
-
-function is_blank_in_string(s)
-{
-	var i=0;
-	for(i=0;i<s.length;i++)
-	{
-		c=s.charAt(i);
-		if(c==' ')
-			return true;
-	}
-	return false;
-}
-
-// this function is used to check if the string is blank or zero.
-function is_blank_or_zero(s)
-{
-	if (is_blank(s)==true) return true;
-	if (is_digit(s))
-	{
-		var i = parseInt(s, 10);
-		if (i==0) return true;
-	}
-	return false;
-}
-
-// this function is used to check if the "str" is a decimal number or not.
-function is_digit(str)
-{
-	if (str.length==0) return false;
-	for (var i=0;i < str.length;i++)
-	{
-		if (str.charAt(i) < '0' || str.charAt(i) > '9') return false;
-	}
-	return true;
-}
-
-// this function is used to check if the value "str" is a hexcimal number or not.
-function is_hexdigit(str)
-{
-	if (str.length==0) return false;
-	for (var i=0;i < str.length;i++)
-	{
-		if (str.charAt(i) <= '9' && str.charAt(i) >= '0') continue;
-		if (str.charAt(i) <= 'F' && str.charAt(i) >= 'A') continue;
-		if (str.charAt(i) <= 'f' && str.charAt(i) >= 'a') continue;
-		return false;
-	}
-	return true;
-}
-
-// convert dec integer string
-function decstr2int(str)
-{
-	var i = -1;
-	if (is_digit(str)==true) i = parseInt(str, [10]);
-	return i;
-}
-
-// convert hex integer string
-function hexstr2int(str)
-{
-	var i = 0;
-	if (is_hexdigit(str)==true) i = parseInt(str, [16]);
-	return i;
-}
-
-// if min <= value <= max, than return true,
-// otherwise return false.
-function is_in_range(str_val, min, max)
-{
-	var d = decstr2int(str_val);
-	if ( d > max || d < min ) return false;
-	return true;
-}
-
-// this function convert second to day/hour/min/sec
-function second_to_daytime(str_second)
-{
-	var result = new Array();
-	var t;
-
-	result[0] = result[1] = result[2] = result[3] = 0;
-
-	if (is_digit(str_second)==true)
-	{
-		t = parseInt(str_second, [10]);
-		result[0] = parseInt(t/(60*60*24), [10]);	// day
-		result[1] = parseInt(t/(60*60), [10]) % 24; // hr
-		result[2] = parseInt(t/60, [10]) % 60;		// min
-		result[3] = t % 60;							// sec
-	}
-
-	return result;
-}
-
-// construct xgi string for doSubmit()
-function exe_str(str_shellPath)
-{
-	var str="";
-	myShell = str_shellPath.split(";");
-	for(i=0; i<myShell.length; i++)
-	{
-		str+="&"+"exeshell="+myShell[i];
-	}
-	return str;
-}
-
-// return true is brower is IE.
-function is_IE()
-{
-	if (navigator.userAgent.indexOf("MSIE")>-1) return true;
-	return false
-}
-
-// make docuement.write shorter
-function echo(str)
-{
-	document.write(str);
-}
-
-// same as echo() but replace special characters
-function echosc(str)
-{
-	str=str.replace(/&/g,"&amp;");
-	str=str.replace(/</g,"&lt;");
-	str=str.replace(/>/g,"&gt;");
-	str=str.replace(/"/g,"&quot;");
-	str=str.replace(/'/g,"\'");
-	str=str.replace(/ /g,"&nbsp;");
-	document.write(str);
-}
-
-// return false if keybaord event is not decimal number.
-function dec_num_only(evt)
-{
-	if (navigator.appName == 'Netscape')
-	{
-		if (evt.which == 8) return true;	/* TAB */
-		if (evt.which == 0) return true;
-		if (evt.which >= 48 && evt.which <= 57) return true;
-	}
-	else
-	{
-		if (evt.keyCode == 8) return true;
-		if (evt.keyCode == 0) return true;
-		if (evt.keyCode >= 48 && evt.keyCode <= 57) return true;
-	}
-	return false;
-}
-
-// return false if keyboard event is not hex number.
-function hex_num_only(evt)
-{
-	if (navigator.appName == 'Netscape')
-	{
-		if (evt.which == 8) return true;	/* TAB */
-		if (evt.which == 0) return true;
-		if (evt.which >= 48 && evt.which <= 57) return true;
-		if (evt.which > 64 && evt.which < 71) return true;
-		if (evt.which > 96 && evt.which < 103) return true;
-	}
-	else
-	{
-		if (evt.keyCode == 8) return true;	/* TAB */
-		if (evt.keyCode == 0) return true;
-		if (evt.keyCode >= 48 && evt.keyCode <= 57) return true;
-		if (evt.keyCode > 64 && evt.keyCode < 71) return true;
-		if (evt.keyCode > 96 && evt.keyCode < 103) return true;
-	}
-	return false;
-}
-
-// return false if keyboard event is not readable character
-function readable_char_only(evt)
-{
-	if (navigator.appName == 'Netscape')
-	{
-	if (evt.which == 8) return true;	/* TAB */
-	if (evt.which == 0) return true;
-	if (evt.which < 33 || evt.which > 126) return false;
-	}
-	else
-	{
-	if (evt.keyCode == 8) return true;	/* TAB */
-	if (evt.keyCode == 0) return true;
-	if (evt.keyCode < 33 || evt.keyCode > 126) return false;
-	}
-	return true;
-}
-
-
-// make the obj selected, if the value of obj is empty, 'def' will be set as value.
-function field_select(obj, def)
-{
-	if (obj.value == '') obj.value = def;
-	obj.select();
-}
-
-// make the object be focused, and set the value to 'val'.
-function field_focus(obj, val)
-{
-	if (val != '**') obj.value = val;
-	obj.focus();
-	obj.select();
-}
-
-// make all fields of the obj disabled/enabled. "dis" will be true or false.
-function fields_disabled(obj, dis)
-{
-	var i=0;
-	for(i=0; i<obj.length; i++)
-	{
-		eval("obj["+i+"].disabled="+dis);
-	}
-}
-
-// for safari select loop
-function select_index(obj, val)
-{
-	var i=0;
-	for(i=0; i<obj.length;i++)
-	{
-		if(eval("obj["+i+"].value")==val)
-		{
-			obj.selectedIndex=i;
-			break;
-		}
-	}
-}
-
-// check if any unicode characters in the string.
-function strchk_unicode(str)
-{
-	var strlen=str.length;
-	if(strlen>0)
-	{
-		var c = '';
-		for(var i=0;i<strlen;i++)
-		{
-			c = escape(str.charAt(i));
-			if(c.charAt(0) == '%' && c.charAt(1)=='u')
-				return true;
-		}
-	}
-	return false;
-}
-
-function first_blank(str)
-{
-    var ssid_index = str.indexOf(" ");
-
-    if(ssid_index == 0)
-    {
-    	return true;
-    }
-    return false;
-}
-
-function strchk_url(str)
-{
-	if (__is_str_in_allow_chars(str, 1, "/.:_-?&[email protected]")) return true;
-	return false;
-}
-
-function strchk_hostname(str)
-{
-	if (__is_str_in_allow_chars(str, 1, ".-")) return true;
-	return false;
-}
-
-function strchk_email(str)
-{
-	if (__is_str_in_allow_chars(str, 1, "[email protected]")) return true;
-	return false;
-}
-
-function evtchk_url(evt)
-{
-	if (__is_evt_in_allow_chars(str, 1, "/.:_-?&[email protected]")) return true;
-	return false;
-}
-
-function evtchk_hostname(evt)
-{
-	if (__is_evt_in_allow_chars(str, 1, ".-")) return true;
-	return false;
-}
-
-function evtchk_email(evt)
-{
-	if (__is_evt_in_allow_chars(str, 1, "[email protected]")) return true;
-	return false;
-}
-
-// print six mac object
-function print_mac(n)
-{
-	var str="";
-	var j;
-
-	for(i=1;i<7;i++)
-	{
-		if(i==6)  j=6;
-		else j=i+1;
-
-		str+="<input class=text type=text id="+n+i+" name="+n+i+" size=1 maxlength=2 value='' onkeyup=\"move_mac("+i+","+n+i+","+n+j+")\">";
-		if(i!=6)        str+=" : ";
-
-	}
-	document.write(str);
-}
-
-// move cursor to next mac object
-function move_mac(num,mac,next_mac)
-{
-	var str="";
-    str=mac.value.length;
-
-	if(str == "2")
-	{
-		if(num != "6")
-			field_focus(next_mac,"**");
-	}
-}
-
-
-function HexCheck2(str)
-{
-	var len = str.length;
-
-	if((len == 0) || (len%2 != 0))
-	{
-		return false;
-	}
-	else
-	{
-		for(var i=0 ; i<len ; i++)
-		{
-			substring = str.substr(i,1);
-		    if(!((substring>='0' && substring<='9') || (substring>='a' && substring<='f') || (substring>='A' && substring<='F') ? true : false))
-				return false;
-		}
-		return true;
-	}
-}
-
-
-function ASCIICheck(str)
-{
-	// ASCII range  16:(20~7E)  10:(32~126)
-	for(var i=0 ; i<str.length ; i++)
-	{
-		if(str.charCodeAt(i) < 32 || str.charCodeAt(i) > 126)
-		{
-			return false;
-		}
-	}
-	return true;
-}
-
-function createRequest()
-{
-	var request = null;
-	try { request = new XMLHttpRequest(); }
-	catch (trymicrosoft)
-	{
-		try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
-		catch (othermicrosoft)
-		{
-			try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
-			catch (failed) { request = null; }
-		}
-	}
-	if (request == null) alert("Error creating request object !");
-	return request;
-}
-
-function AdjustHeight()
-{
-	var h = 500;
-	var tmp = 0;
-	/*
-	if(is_IE())
-	{
-		tmp = parent.ifrMain.contentWindow.document.body.scrollHeight;
-		tmp = get_obj("table_frame").offsetHeight;
-	}
-	else
-	{
-		tmp = parent.ifrMain.contentDocument.body.offsetHeight;
-	}
-	*/
-	tmp = get_obj("table_frame").offsetHeight;
-	if(tmp > h) h = tmp;
-	parent.ifrMain.height = h;
-}
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/view.js	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/htdocs/js/view.js	Thu Sep 20 15:21:29 2012 +0300
@@ -1,28 +1,12 @@
-/* page init functoin */
-function init()
-{
-
-}
-
-/* parameter checking */
-function check()
-{
-
-}
-
-var tool_list = new Array();
-tool_list[0] = ["Reboot",				"#", "tryget('system=reboot')"];
-//tool_list[1] = ["Configuration File", 				"?page=tool_config.html"];
-//tool_list[1] = ["Firmware and SSL Certification Upload", 	"?page=tool_fw.html"];
-//tool_list[3] = ["Time and Date", 				"?page=tool_sntp.html"];
-
-var config_list = new Array();
-config_list[0] = ["Save Configuration",				"#", "tryget('save=config')"];
-config_list[1] = ["Load Configuration (-)",				"#", "tryget('load=config')"];
-config_list[1] = ["Restore Configuration",				"#", "tryget('restore=config')"];
-
 function tryget(msg)
 {
+	if (msg == 'system=reboot') {
+
+		ajax("POST", "/cmd.xml", "system=reboot&r=" + encodeURIComponent(Math.random()), true, "ignore");
+		reboottimeout = setTimeout( function(){ clearTimeout(reboottimeout); window.location = "/";}, 80000);
+		return false;
+	}
+
 	ajax("POST", "/cmd.xml", msg + "&r=" + encodeURIComponent(Math.random()), true,
 	    function (x) {
 		window.alert(x.responseXML.getElementsByTagName("data")[0].firstChild.nodeValue);
@@ -31,106 +15,4 @@
 	return false;
 }
 
-function genVerticalMenu(x, y, list, id)
-{
-	var str="";
-	x = get_obj("MainTable").offsetLeft + x;
 
-	str+="<div id='"+id+"' class='menu' style='display:none;position:absolute;top:"+y+"px;left:"+x+"px;'>";
-	str+="  <ul>\n";
-	for(var i=0; i<list.length; i++)
-	{
-		if (list[i][2])
-		    str+="    <li><a target='ifrMain' onclick=\"" + list[i][2] + "\">"+list[i][0]+"</a></li>\n";
-		else
-		    str+="    <li><a href='"+list[i][1]+"' target='ifrMain'>"+list[i][0]+"</a></li>\n";
-	}
-	str+="  </ul>\n";
-	str+="</div>";
-	document.write(str);
-}
-
-
-function genLogOutMenu(x, y, msg, id)
-{
-	var str="";
-	x = get_obj("MainTable").offsetLeft + x;
-	str+="<div id='"+id+"' class='menu'  style='display:none;position:absolute;top:"+y+"px;left:"+x+"px;'>\n";
-	str+="  <a href='?page=logout.html' class='logout'>"+msg+"</a>\n";
-	str+="</div>\n";
-	document.write(str);
-}
-
-function HideFrame()
-{
-	showlist("tool", 	"");
-	showlist("config",	"");
-	showlist("logout",	"");
-}
-
-function showlist(name, flag)
-{
-	var obj = document.getElementById(name);
-	if (!obj) {
-		return 0;
-	}
-
-	if(flag == "yes")
-		obj.style.display = "";
-	else
-		obj.style.display = "none";
-
-	return 1;
-}
-
-function gen_banner_td(name, flag)
-{
-	var str="";
-	var menu_name="";
-
-	if(name == "home")
-		menu_name = "Home";
-	else if(name == "tool")
-		menu_name = "Maintenance";
-	else if(name == "sys")
-		menu_name = "System";
-	else if(name == "config")
-		menu_name = "Configuration";
-//	else if(name == "logout")
-//		menu_name = "Logout";
-//	else if(name == "help")
-//		menu_name = "Help";
-
-	if(flag == "a_href")
-	{
-		str+="<td class='banner'>";
-//		if(name == "sys")
-//			str+="<a href='?page=sys_setting.html' target='ifrMain'>";
-//		else if(name == "help")
-//			str+="<a href='?page=help.html' target='_blank'>";
-//		else
-			str+="<a href='home_sys.html' target='ifrMain'>";
-	}
-	else
-		str+="<td class='banner' onclick=\"showlist('"+name+"','yes')\">";
-
-	if(name == "logout")
-		str+="<img src='img/tool_bar_v.jpg' height='18' border='0' hspace='5'>";
-
-	str+="<img src='img/"+name+".gif' width='16' border='0' hspace='10'>";
-
-	str+="<span id='banner_"+name+"' class='word'>"+menu_name+"</span>";
-
-	if(flag == "" && name != "logout")
-		str+="<span class='img'><img src='img/triangle.gif' hspace='8'></span>";
-
-	if(name != "help")
-		str+="<img src='img/tool_bar_v.jpg' height='18' border='0' hspace='10'>";
-
-	if(flag == "a_href")
-		str+="</a>";
-	str+="</td>";
-
-	document.write(str);
-
-}
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/js/wizard.js	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-function apply(fn)
-{
-	if(fn=="")
-		document.write("<input type='submit' name='apply' value=\"\">");
-	else
-		document.write("<input type='button' name='apply' value=\"\" onClick='"+fn+"'>");
-}
-function cancel(fn)
-{
-	if(fn=="") fn="do_cancel()";
-	document.write("<input type='button' name='cancel' value=\"\" onClick='"+fn+"'>");
-}
-
-// button for wizard ---------------------------------------------------------
-function prev(fn)
-{
-	if(fn=="") fn="go_prev()";
-	document.write("<input type='button' name='prev' value=\"\" onClick='"+fn+"'>&nbsp;");
-}
-function next(fn)
-{
-	if(fn=="")
-		document.write("<input type='submit' name='next' value=\"\">&nbsp;");
-	else
-		document.write("<input type='button' name='next' value=\"\" onClick='return "+fn+"'>&nbsp;");
-}
-
-function exit()
-{
-	document.write("<input type='button' name='exit' value=\"\" onClick='exit_confirm()'>&nbsp;");
-}
-function exit_confirm()
-{
-	self.location.href="?page=bsc_wizard.html";
-}
-function wiz_save(fn)
-{
-	if(fn=="") fn="do_save()";
-	document.write("<input type='submit' name='save' value=\"\" onClick='"+fn+"'>&nbsp;");
-
-}
-function wiz_connect(fn)
-{
-	if(fn=="") fn="do_save()";
-	document.write("<input type='button' name='save' value=\"\" onClick='"+fn+"'>&nbsp;");
-
-}
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/jstree_table.html	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
-
-<HTML>
-  <HEAD>
-    <META http-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
-    <STYLE>
-      a, A:link, a:visited, a:active, A:hover{color: #000000; text-decoration: none; font-family: Arial; font-size: 11px}
-      body {margin-left: -5px; margin-top: -5px; margin-right: -5px; margin-bottom: -5px}
-    </STYLE>
-    <SCRIPT TYPE="text/javascript" SRC="js/ua.js"></SCRIPT>
-    <SCRIPT TYPE="text/javascript" SRC="js/tree.js"></SCRIPT>
-    <SCRIPT TYPE="text/javascript" SRC="js/defineMyTree.js"></SCRIPT>
-    <SCRIPT TYPE="text/javascript">
-function NoMessage()
-{
-	window.status="DEVICE_NAME";
-}
-    </SCRIPT>
-    <TITLE></TITLE>
-  </HEAD>
-  <BODY CLASS="bodyMenu">
-    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
-      <TBODY>
-        <TR>
-          <TD COLSPAN="2" HEIGHT="5">
-          </TD>
-        </TR>
-        <TR>
-          <TD WIDTH="5">
-          </TD>
-          <TD>
-	    <SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
-initializeDocument()
-	    </SCRIPT>
-            <DIV ID="domRoot"><!-- TreeView here --></DIV>
-          </TD>
-        </TR>
-      </TBODY>
-    </TABLE>
-  </BODY>
-</HTML>
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/status.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-function runtime(iface)
-    local ret = "";
-    if r[iface] then
-	for k,v in pairs(r[iface]) do
-	    ret = ret .. k .. "=" .. v .. "<br/>\n";
-	end
-
-	return (ret);
-    end
-    return ("");
-end
-
-return ([[
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-    <head>
-	<meta http-equiv="content-type" content="text/html; charset=utf-8">
-	<title>Status</title>
-	<style type="text/css"> body {	margin:0; padding:0; } 	</style>
-	<link href="css/anim.css" rel="stylesheet" type="text/css">
-    </head>
-    <body class="yui3-skin-sam  yui-skin-sam">
-    <h1>LAN configuration</h1>
-
-<div id="Static" class="yui3-module boxitem">
-    <div class="yui3-hd">
-        <h4>Static/DHCP</h4>
-    </div>
-    <div class="yui3-bd">
-    ]]
-    .. runtime("wan0") ..
-    [[
-    </div>
-</div>
-<div id="PPPoE" class="yui3-module boxitem">
-    <div class="yui3-hd">
-        <h4>PPPoE</h4>
-    </div>
-    <div class="yui3-bd">
-    ]]
-    .. runtime("PPPoE") ..
-    [[
-    </div>
-</div>
-<div id="PPP" class="yui3-module boxitem">
-    <div class="yui3-hd">
-        <h4>PPP</h4>
-    </div>
-    <div class="yui3-bd">
-    ]]
-    .. runtime("PPP") ..
-    [[
-    </div>
-</div>
-<div id="IPSec0" class="yui3-module boxitem">
-    <div class="yui3-hd">
-        <h4>IPSec0</h4>
-    </div>
-    <div class="yui3-bd">
-    ]]
-    .. runtime("IPSec0") ..
-    [[
-    </div>
-</div>
-<script type="text/javascript" src="js/ajax.js"></script>
-<script>
-function send_update(form)
-{
-    var query = getValuesAsArray(form);
-    ajax("POST", "/cmd.xml", query, true, function (x) { });
-
-    return false;
-}
-</script>
-
-
-
-</body>
-</html>
-]]);
-
--- a/profiles/dlink.ua.web/files/etc/www/htdocs/vaps.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-
-
-template = ([[
-<div id="$$$ifaceid$$$" class="yui3-module boxitem">
-    <div class="yui3-hd">
-        <h4>Station $$$n$$$ Name: $$$ssid$$$</h4>
-    </div>
-    <div class="yui3-bd">
-	<form method="POST" target="/test.lua">
-	<table width="100%">
-	    <tr >
-		<td class=""><label for="$$$iface$$$SSID">Wireless Network Name&nbsp;(SSID)&nbsp;:</label></td>
-		<td><input id="$$$iface$$$SSID" size="20" maxlength="32"   type="text" value="$$$ssid$$$"></td>
-	    </tr>
-	    <tr>
-		<td class="">Visibility Status&nbsp;:</td>
-		<td>
-			<input id="$$$iface$$$visibility" name="visibility"  type="checkbox" "$$$visibility_checked$$$">
-			<label for="$$$iface$$$visibility">Visible</label>
-		</td>
-	    </tr>
-<!-- Only OPEN security mode now supported  -->
-
-<!--
-	    <tr>
-		<td class="form_label">Security Mode&nbsp;:</td>
-		<td>
-		    <select class="security_mode"  onChange="updateSecurityMode(this);">
-		        <option value="none">None</option>
-		        <option value="wep">WEP</option>
-		        <option value="wpa">WPA</option>
-			<option value="wpa-radius">WPA+RADIUS</option>
-		    </select>
-		</td>
-	    </tr>
-	    <tr class="security_mode_wpa">
-		<td class="form_label">WPA Mode&nbsp;:</td>
-		<td>
-			<select >
-				<option value="2">Auto (WPA or WPA2)</option>
-
-				<option value="3">WPA2 Only</option>
-				<option value="1">WPA Only</option>
-			</select>
-		</td>
-	    </tr>
-	    <tr class="security_mode_wpa">
-		<td class="form_label"><label for="$$$iface$$$wpa_rekey_time">Group Key Update Interval&nbsp;:</label></td>
-		<td><input id="$$$iface$$$wpa_rekey_time" size="10"  type="text"> (seconds)</td>
-	    </tr>
-	    -- Same for wpa-radius  --
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label">WPA Mode&nbsp;:</td>
-		<td>
-			<select >
-				<option value="2">Auto (WPA or WPA2)</option>
-				<option value="3">WPA2 Only</option>
-				<option value="1">WPA Only</option>
-			</select>
-		</td>
-	    </tr>
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label"><label for="$$$iface$$$wpa_rekey_time">Group Key Update Interval&nbsp;:</label></td>
-		<td><input id="$$$iface$$$wpa_rekey_time" size="10"  type="text">	(seconds) </td>
-	    </tr>
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label"><label for="$$$iface$$$reauth_time">Authentication Timeout&nbsp;:</label></td>
-		<td><input id="$$$iface$$$reauth_time" size="10"  type="text">(minutes)</td>
-	    </tr>
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label"><label for="$$$iface$$$radius_server_address">RADIUS server IP Address&nbsp;:</label></td>
-		<td><input id="$$$iface$$$radius_server_address" size="20"  type="text"></td>
-	    </tr>
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label"><label for="$$$iface$$$radius_server_port">RADIUS server Port&nbsp;:</label></td>
-		<td><input id="$$$iface$$$radius_server_port" size="10"  type="text"></td>
-	    </tr>
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label"><label for="$$$iface$$$radius_shared_secret">RADIUS server Shared Secret&nbsp;:</label></td>
-		<td><input id="$$$iface$$$radius_shared_secret" size="20" maxlength="64"  type="text"></td>
-	    </tr>
-	    <tr class="security_mode_wpa-radius">
-		<td class="form_label"><label for="$$$iface$$$radius_auth_mac">MAC Address Authentication&nbsp;:</label></td>
-		<td><input id="$$$iface$$$radius_auth_mac" type="checkbox"></td>
-
-	    </tr>
--->
-	</table>
-	</form>
-    </div>
-</div>
-]]);
-
-local out = "";
-
-function onetemplate(c, tamplate, i)
-    local out = "";
-    local repl = {};
-    local instance = "hostapd.instance[" .. tostring(i) .. "]";
-
-    vap = c:getNode(instance);
-
-    if (not vap) or (c:getNodeValue(instance .. ".ssid") == nil) then
-	return ("");
-    end
-
-    repl["n"]			= tostring(i);
-    repl["ifaceid"]		= "wlan" .. tostring(i);
-    repl["iface"]		= repl["ifaceid"] .. ":";
-    repl["auth_algs"]		= c:getNodeValue(instance .. ".auth_algs") or "";
-    repl["ssid"]		= c:getNodeValue(instance .. ".ssid") or "";
-    repl["wpa"]			= c:getNodeValue(instance .. ".wpa") or "";
-    repl["wpa_passphrase"]	= c:getNodeValue(instance .. ".wpa_passphrase") or "";
-    repl["wpa_key_mgmt"]	= c:getNodeValue(instance .. ".wpa_key_mgmt") or "";
-
-    local visible = c:getNodeValue(instance .. ".wpa_key_mgmt") or "";
-    if (visible ~= "false") and (visible ~= "0") then
-	repl["visibility_checked"] = "checked";
-    end
-
-    out = string.gsub(template, "%$%$%$(.-)%$%$%$", repl);
-
-    return (out);
-end
-
--- TODO foreach wlan if
--- for i = 1,8,1 do
-for i = 1,1,1 do
-    out = out .. onetemplate(c, tamplate, i);
-end
-
-return (out);
-
-
--- a/profiles/dlink.ua.web/files/etc/www/httpd.lua	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/httpd.lua	Thu Sep 20 15:21:29 2012 +0300
@@ -27,6 +27,7 @@
 --io.stderr = io.stdout;
 
 socket = require("socket");
+require('sysctl.core');
 
 -- Expat binding
 dofile('lib/xml.lua');
@@ -43,15 +44,28 @@
 dofile('lib/base64.lua');
 -- Socket helper
 --dofile("lib/sock.lua");
+-- Route select logic
+dofile("lib/route.lua");
 -- MPD helper
 dofile("lib/mpd.lua");
 -- RACOON helper
 dofile("lib/racoon.lua");
 -- DHCPD helper
-dofile("lib/dhcpd.lua");
+-- dofile("lib/dhcpd.lua");
 -- HOSTAPD helper
-dofile("lib/hostapd.lua");
+--dofile("lib/hostapd.lua");
+
+-- redirect print to /dev/console
+-- dofile("lib/print_to_console.lua");
 
+-- redirect print to syslog
+dofile("lib/lsyslog.lua");
+syslog_init("httpd.lua");
+
+-- urlEncode/urlDecode
+dofile("lib/urlXxcode.lua");
+
+httpd_debug = true;
 
 --
 --  A table of MIME types.
@@ -60,8 +74,30 @@
 --
 mime = {};
 
+-- # lua -e 'package.cpath ="/usr/lib/lua/lua?.so"; require("sysctl.core"); s,e,v,t = pcall(function () return sysctl.get("hw.device.model") end); print(s,e,v,t);'
+-- true    DIR-825 A       nil
+-- # lua -e 'package.cpath ="/usr/lib/lua/lua?.so"; require("sysctl.core"); s,e,v,t = pcall(function () return sysctl.get("hw.device.mode") end); print(s,e,v,t);'
+-- false   (command line):1: unknown iod 'hw.device.mode'  nil     nil
 
-
+-- save sysctl obj
+sysctl_obj = sysctl;
+function sysctl(oid, value)
+	if type(oid) == "table" then
+		print("sysctl(table) not implemented\n");
+	else
+		if value then
+			print("sysctl(%s, %s)\n", oid, tostring(value));
+			local s,v,t = pcall(function () return sysctl_obj.set(oid, value) end);
+			if s then return (v); end
+			return (nil);
+		else
+			print("sysctl(%s)\n", oid);
+			local s,v,t = pcall(function () return sysctl_obj.get(oid) end);
+			if s then return (v); end
+			return (nil);
+		end
+	end
+end
 
 --
 --  Start a server upon the given port, using the given
@@ -479,7 +515,11 @@
 		end
 		return func();
 	else
-		return field(c:getNode(s):value());
+		node = c:getNode(s);
+		if node then
+			return field(node:value() or "");
+		end
+		return field("");
 	end
 end
 
@@ -499,7 +539,7 @@
 				return os.date("%Y-%m-%d %H:%M:%S");
 			end
 			if key == "uptime" then
-				return exec_output("sysctl -n kern.ident");
+				return sysctl("kern.ident");
 			end
 		else
 			return ("Unknown command \"" .. cmd .. "\"");
@@ -583,6 +623,15 @@
     end
 end
 
+function read_zrouter_version (ar)
+	ar.zrouter_version = {};
+	return parse_kv_file(ar.zrouter_version, "/etc/zrouter_version");
+end
+
+function read_rc_conf (ar)
+	ar.rc_conf = {};
+	return parse_kv_file(ar.rc_conf, "/etc/rc.conf");
+end
 
 --
 --  Read the mime file and setup mime types
@@ -601,7 +650,6 @@
      end
 end
 
-
 --
 --  Utility function:   Does the string end with the given suffix?
 --
@@ -609,7 +657,6 @@
     return End=='' or string.sub(String,-string.len(End))==End
 end
 
-
 --
 --  Strip path traversal requests.
 --
@@ -617,32 +664,6 @@
     return( string.gsub( str, "/../", "" ) );
 end
 
-
---
--- Utility function:  URL encoding function
---
-function urlEncode(str)
-    if (str) then
-        str = string.gsub (str, "\n", "\r\n")
-        str = string.gsub (str, "([^%w ])",
-            function (c) return string.format ("%%%02X", string.byte(c)) end)
-        str = string.gsub (str, " ", "+")
-    end
-    return str
-end
-
-
---
--- Utility function:  URL decode function
---
-function urlDecode(str)
-    str = string.gsub (str, "+", " ")
-    str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
-    str = string.gsub (str, "\r\n", "\n")
-    return str
-end
-
-
 --
 -- Log an access request.
 --
@@ -671,9 +692,6 @@
     print( log );
 end
 
-
-
-
 --
 -----
 ---
@@ -685,8 +703,6 @@
 ----
 --
 
-
-
 --
 --  Setup the MIME types our server will use for serving files.
 --
@@ -795,19 +811,45 @@
 	mpd = MPD:new(c, "127.0.0.1", 5005);
     end
 
-    local bundle = "PPP";
-    local path = "interfaces.wan0.PPP";
+--    local bundle = "PPP";
+--    local path = "interfaces.wan0.PPP";
 
     mpd:config_bundle(path, bundle);
     mpd:config_link(path, link, bundle);
+end
 
---    print(mpd:show_bundle(path, bundle));
+function run_dhclient(c, iface)
+    local path = "interfaces." .. iface .. ".Static";
+
+    -- return if no iface.Static node.
+    if not c:getNode(path) then
+	return (nil);
+    end
+
+    -- return if Static mode not enabled.
+    if c:getNode(path):attr("enable") ~= "true" then
+	return (nil);
+    end
 
---    print("--   --");
+    -- return if no DHCP enabled.
+    local dhcp = c:getNode(path .. ".dhcp");
+    if not dhcp or dhcp:attr("enable") ~= "true" then
+	return (nil);
+    end
 
---    s:close();
+    -- Run dhclient
+    print("Run dhclient on " .. iface);
+    os.execute(string.format("kill `cat /var/run/dhclient.%s.pid`", iface));
+
+    -- Do not execute dhclient if interface is down
+    if exec_output("ifconfig -v " .. iface .." | grep 'status: active'") ~= "" then
+	os.execute(string.format("/sbin/dhclient -b %s", iface));
+	-- XXX, hack to "unplumb" iface if it was not up on boot
+	os.execute(string.format("ifconfig %s `ifconfig %s | grep 'ether '`", iface, iface));
+    end
 end
 
+
 function configure_wan(c)
     -- TODO: auto enumerate wan links
     --[[
@@ -825,36 +867,58 @@
 sysctl net.inet.ip.fw.one_pass=0
     ]]
 
-    os.execute("kldload ng_nat");
-    os.execute("kldload ng_ipfw");
-    os.execute("sysctl net.inet.ip.fw.one_pass=0");
-
-
+    kldload({"ng_nat", "ng_ipfw"});
+    sysctl("net.inet.ip.fw.one_pass", 0);
 
     local sub = "";
-    for _, sub in ipairs({"Static", "PPPoE", "PPP"}) do
+    for _, sub in ipairs({"Static", "PPPoE", "PPP", "PTPP", "L2TP"}) do
 	print("sub=" .. sub);
 	local path = "interfaces.wan0." .. sub;
+	local ifnode = c:getNode(path);
 
-	if c:getNode(path):attr("enable") == "true" then
+	if ifnode and ifnode:attr("enable") == "true" then
 	    local subtype = c:getNode(path):attr("type");
 	    print("subtype=" .. subtype);
-	    if
-		(subtype == "l2tp") or
-		(subtype == "pppoe") or
-		(subtype == "pptp") then
+	    if (subtype == "l2tp") then
+		-- TODO: multilink have different link names
+	    elseif (subtype == "pppoe") then
+		kldload({"ng_pppoe"});
+		os.execute("sleep 1");
+		configure_mpd_link(c, path, sub, sub);
+		-- Add interface to route select logic
+		r.route:f(sub,
+		    safeValue(c, path .. ".group", "WAN"),
+		    safeValue(c, path .. ".cost", "1000") - 0,
+		    "down",
+		    "LINKDOWN")
+	    elseif (subtype == "pptp") then
 		-- TODO: multilink have different link names
 	    elseif (subtype == "modem") then
-		os.execute("kldload umodem");
-		os.execute("kldload u3g");
+		kldload({"umodem", "u3g"});
 		os.execute("sleep 1");
 		configure_mpd_link(c, path, sub, sub);
+		r.route:f(sub,
+		    safeValue(c, path .. ".group", "WAN"),
+		    safeValue(c, path .. ".cost", "1000") - 0,
+		    "down",
+		    "LINKDOWN")
 	    elseif (subtype == "hw") then
+		local dev = c:getNode(path .. ".device"):value();
 		local dhcp = c:getNode(path .. ".dhcp");
-		local dev = c:getNode(path .. ".device"):value();
+		local dhcpenabled = 0;
+		if dhcp and dhcp:attr("enable") == "true" then
+			dhcpenabled = true;
+		end
+
+		os.execute(string.format("ifconfig %s up", dev));
+		r.route:f(sub,
+		    safeValue(c, path .. ".group", "WAN"),
+		    safeValue(c, path .. ".cost", "1000") - 0,
+		    "up",
+		    "LINKDOWN")
 
     		local query = "cmd=event";
-        	query = query .. "&eventtype=linkup";
+        	query = query .. "&state=up";
         	query = query .. "&iface=" .. 	urlEncode(dev);
         	query = query .. "&gw=" .. 	urlEncode(c:getNode(path .. ".gateway"):value());
         	query = query .. "&ip=" .. 	urlEncode(c:getNode(path .. ".ipaddr"):value());
@@ -863,23 +927,26 @@
     		query = query .. "&dns2=" .. 	urlEncode(c:getNode(path .. ".dns2"):value());
 
 		-- Call collector, to let him know about static config, and assign route+dns's
-    		print("fetch -qo - \"http://127.0.0.1:8/event.xml?" .. query .. "\"");
-    		os.execute("fetch -qo - \"http://127.0.0.1:8/event.xml?" .. query .. "\"");
+		cmdline = "fetch -qo - \"http://127.0.0.1:8/event.xml?" .. query .. "\"";
+    		print("Exec: " .. cmdline);
+    		os.execute(cmdline);
 
 		-- Config static first
 		local ip = c:getNode(path .. ".ipaddr"):value();
+		local dhcp = c:getNode(path .. ".dhcp");
 		print("Run: \"ifconfig " .. dev .. " " .. ip .. "\"");
 		if os.execute(string.format("ifconfig %s %s", dev, ip)) ~= 0 then
-		    print("\"ifconfig " .. dev .. " " .. ip .. "\" - fail");
+		    print("\"ifconfig " .. dev .. " " .. ip .. "\" - failed");
 		end
 
-		if dhcp and dhcp:attr("enable") == "true" then
-		    print(path .. ".dhcp:attr(enable)=" .. dhcp:attr("enable"));
-		    -- Run dhclient
-		    print("Run dhclient on " .. dev);
-		    os.execute("mkdir -p /var/db/");
-		    os.execute(string.format("/sbin/dhclient %s &", dev));
-		end
+		run_dhclient(c, dev); -- if DHCP enabled.
+
+		-- XXX temporary FIX for wan0 with static address
+		-- if not dhcpenabled and dev == "wan0" then
+		    os.execute(string.format("route add default %s",
+			c:getNode(path .. ".gateway"):value()));
+		-- end
+
 
 		local nat = c:getNode(path .. ".nat");
 		if nat and nat:attr("enable") == "true" then
@@ -890,9 +957,18 @@
 		    os.execute("ngctl connect ipfw: wan0nat: 61 in");
 		    os.execute("ngctl msg wan0nat: setaliasaddr " .. ip);
 
-		    os.execute("ipfw add 98 netgraph 61 all from any to any in via wan0");
-		    os.execute("ipfw add 99 netgraph 60 all from any to any out via wan0");
+		    if dhcpenabled then
+			-- pass DHCP via iface
+			os.execute("ipfw add 96 allow all from any 67 to any 68 out via " .. dev);
+			os.execute("ipfw add 97 allow all from any 68 to any 67 out via " .. dev);
+		    end
+		    os.execute("ipfw add 98 netgraph 61 all from any to any in via " .. dev);
+		    os.execute("ipfw add 99 netgraph 60 all from any to any out via " .. dev);
 		else
+		    if dhcpenabled then
+			os.execute("ipfw delete 96");
+			os.execute("ipfw delete 97");
+		    end
 		    os.execute("ipfw delete 98");
 		    os.execute("ipfw delete 99");
 		end
@@ -930,10 +1006,156 @@
     return (opts);
 end
 
+function update_board_info(c)
+    for _, oid in pairs({"device.vendor", "device.model", "device.revision", "soc.vendor", "soc.model"}) do
+	n = c:getOrCreateNode("info." .. oid);
+	n:value(sysctl("hw." .. oid));
+	if not n:value() then
+	    n:value("__NO_DATA__");
+	end
+	print(tostring(oid) .. "=" .. n:value());
+    end
+end
 
+function safeValue(c, name, default)
+	node = c:getNode(name);
+	if not node then
+		if default then
+			return default;
+		else
+			return "";
+		end
+	end
+	return node:value();
+end
+
+function start_dnsmasq(c)
+	-- TODO: if DNS-Relay enabled
+	-- XXX: dnsmasq able to do DHCPD also
+	-- dhcp-range=[interface:<inter-face>,][tag:<tag>[,tag:<tag>],][set:<tag],]<start-addr>,<end-addr>[,<netmask>[,<broadcast>]][,<lease time>]
+	-- # --domain=zrouter,192.168.0.100,192.168.0.200
+	-- # --dhcp-range=192.168.0.100,192.168.0.200,1h
+	-- # --dhcp-authoritative - don't wait for other DHCPDs
+	-- # --bogus-priv - NXDOMAIN for private nets
+	local_domain = "";
+	local_dhcp_range = "";
+	if c:getNode("dhcpd.instances.instance[1]"):attr("enable") == "true" then
+
+		dhcproot = "dhcpd.instances.instance[1].";
+		domain = safeValue(c, dhcproot .. "domain", "zrouter");
+		dltime = safeValue(c, dhcproot .. "default-lease-time", 3600);
+		mltime = safeValue(c, dhcproot .. "max-lease-time");
+		ranges = safeValue(c, dhcproot .. "range.start");
+		rangee = safeValue(c, dhcproot .. "range.end");
+
+		local_domain = " --domain=" .. domain .."," .. ranges .. "," .. rangee;
+		local_dhcp_range = " --dhcp-range=" .. ranges .. "," .. rangee .. "," .. dltime;
+
+	end
+	dnsmasq_cmd =
+	    "/sbin/dnsmasq" ..
+	    " -i bridge0" ..
+	    local_domain ..
+	    local_dhcp_range ..
+	    " --dhcp-authoritative" ..
+	    " --bogus-priv";
+
+	print("Start " .. dnsmasq_cmd);
+	os.execute(dnsmasq_cmd);
+end
+
+function start_hostapd(c)
+	if c:getNode("hostapd.instance[1]"):attr("enable") == "true" then
+		kldload({"wlan_xauth", "wlan_tkip", "wlan_ccmp"});
+		aproot = "hostapd.instance[1].";
+		driver = "bsd";
+		--        <ieee80211d>1</ieee80211d>
+		--        <country_code>UA</country_code>
+		channel = safeValue(c, aproot .. "channel", 6);
+		country_code = safeValue(c, aproot .. "country_code", "UA");
+		--        <interface>wlan0</interface>
+		interface = safeValue(c, aproot .. "interface", "wlan0");
 
+		commandline = string.format("ifconfig %s down",interface);
+		if os.execute(commandline) ~= 0 then
+		    print("Exec: " .. commandline .. " - FAILED");
+		end
+		commandline = string.format(
+		    "ifconfig %s country %s channel %s up",
+		    interface, country_code, channel);
+		if os.execute(commandline) ~= 0 then
+		    print("Exec: " .. commandline .. " - FAILED");
+		end
+		--        <macaddr_acl>0</macaddr_acl>
+		--        <auth_algs>1</auth_algs>
+		--        <debug>0</debug>
+		--        <hw_mode>g</hw_mode>
+		--        <ctrl_interface>/var/run/hostapd</ctrl_interface>
+		--        <ctrl_interface_group>wheel</ctrl_interface_group>
+		--        <ssid>zrouter</ssid>
+		ssid = safeValue(c, aproot .. "ssid", "zrouter");
+		--        <!-- Open -->
+		--        <wpa>0</wpa>
+		wpa = safeValue(c, aproot .. "wpa", 3);
+		--        <!-- WPA -->
+		--        <!-- <wpa>1</wpa> -->
+		--        <!-- RSN/WPA2 -->
+		-- <!-- <wpa>2</wpa> -->
+    		-- <wpa_pairwise>CCMP TKIP</wpa_pairwise>
+		wpa_key_mgmt = safeValue(c, aproot .. "wpa_key_mgmt", "WPA-PSK");
+		wpa_passphrase = safeValue(c, aproot .. "wpa_passphrase", "freebsdmall");
+		wpa_pairwise = safeValue(c, aproot .. "wpa_pairwise", "CCMP");
+		ctrl_interface = "/var/run/hostapd";
 
+		-- # TARGET
+		-- interface=wlan0
+		-- driver=bsd
+		-- ssid=CACHEBOY_11N_1
+		-- wpa=3
+		-- wpa_key_mgmt=WPA-PSK
+		-- wpa_passphrase=Sysinit891234
+		-- wpa_pairwise=CCMP
+		-- ctrl_interface=/var/run/hostapd
+		hostapd_conf = "/tmp/hostapd." .. interface ..".conf";
 
+		hostapd_conf_data = 
+		    "interface=" ..		interface .. "\n" ..
+		    "driver=" ..		driver .. "\n" ..
+		    "country_code=" .. 		country_code .. "\n" ..
+		    "channel=" ..		channel .. "\n" ..
+		    "ssid=" ..			ssid .. "\n" ..
+		    "wpa=" ..			wpa .. "\n" ..
+		    "wpa_key_mgmt=" ..		wpa_key_mgmt .. "\n" ..
+		    "wpa_passphrase=" ..	wpa_passphrase .. "\n" ..
+		    "wpa_pairwise=" ..		wpa_pairwise .. "\n" ..
+		    "ctrl_interface=" ..	ctrl_interface .. "\n";
+
+		local f = assert(io.open(hostapd_conf, "w"));
+		f:write(hostapd_conf_data);
+		f:close();
+
+		hostapd_cmd = "/usr/sbin/hostapd -B " .. hostapd_conf;
+
+		print("Start " .. hostapd_cmd);
+		os.execute(hostapd_cmd);
+
+	end
+end
+
+function start_igmp_fwd(c)
+	if not c:getNode("igmp.instance[1]") then
+		return;
+	end
+	if c:getNode("igmp.instance[1]"):attr("enable") == "true" then
+		upif   = safeValue(c, aproot .. "up", "wan0");
+		downif = safeValue(c, aproot .. "down", "lan0");
+
+		cmd = "/etc/rc.d/ng_igmpproxy start " .. upif .. " " .. downif;
+
+		print("Start " .. cmd);
+		os.execute(cmd);
+	end
+end
 
 -- Globals
 config = {};	-- Unused now
@@ -948,6 +1170,7 @@
 r.tasks.periodic = {};
 r.tasks.onetime  = {}; -- At some time
 r.tasks.countdown= {}; -- when counter expired
+r.ver = {};
 
 opts = {};
 opts["-P"] = "/var/run/httpd.pid";
@@ -964,29 +1187,37 @@
 print("Parse config ...");
 c = Conf:new(load_file("config.xml"));
 
-print("Run info collector ...");
--- Run it as background task
---os.execute("/etc/www/collector.sh &");
+update_board_info(c);
+read_zrouter_version(r);
+read_rc_conf(r);
 
 print("Initialize board ...");
 
-print("Init LAN");
+print("Initialize route select logic ...");
+r.route = ROUTE:new(c, 0);
+
+print("Enable LAN ports ...");
+os.execute("/etc/rc.d/switchctl enablelan");
+print("Init LAN ...");
 configure_lan(c);
 
--- TODO: if DNS-Relay enabled
--- XXX: dnsmasq able to do DHCPD also
-os.execute("dnsmasq -i bridge0");
-
-start_dhcpd(c);
+print("Start DHCP/DNS Relay ...");
+start_dnsmasq(c);
+-- start_dhcpd(c);
 
 -- print("Init AP");
 -- ap = HOSTAPD:new(c, 1);
 -- ap:run();
 
+print("Init AP ...");
+start_hostapd(c);
+
+print("Init IGMP/Multicast forwarding ...");
+start_igmp_fwd(c);
 
 os.execute("ipfw add 100 allow ip from any to any via lo0");
-os.execute("ipfw add 200 deny ip from any to 127.0.0.0/8");
-os.execute("ipfw add 300 deny ip from 127.0.0.0/8 to any");
+-- os.execute("ipfw add 200 deny ip from any to 127.0.0.0/8");
+-- os.execute("ipfw add 300 deny ip from 127.0.0.0/8 to any");
 
 -- Hide Web-UI from WAN links
 os.execute("ipfw add 400 allow tcp from any to me 80 via lan0");
@@ -994,7 +1225,39 @@
 -- TODO: If not enabled WAN administration
 os.execute("ipfw add 600 deny tcp from any to me 80");
 -- check w/ ipfw NAT-ed packets
-os.execute("sysctl net.inet.ip.fw.one_pass=0");
+sysctl("net.inet.ip.forwarding", 1);
+sysctl("net.inet.ip.fastforwarding", 1);
+sysctl("net.inet.tcp.blackhole", 2);
+sysctl("net.inet.udp.blackhole", 0);
+sysctl("net.inet.icmp.drop_redirect", 1);
+sysctl("net.inet.icmp.log_redirect", 0);
+sysctl("net.inet.ip.redirect", 0);
+sysctl("net.inet.ip.sourceroute", 0);
+sysctl("net.inet.ip.accept_sourceroute", 0);
+sysctl("net.inet.icmp.bmcastecho", 0);
+sysctl("net.inet.icmp.maskrepl", 0);
+sysctl("net.link.ether.inet.max_age", 30);
+sysctl("net.inet.ip.ttl", 226);
+sysctl("net.inet.tcp.drop_synfin", 1);
+sysctl("net.inet.tcp.syncookies", 1);
+-- sysctl("kern.ipc.somaxconn", 32768);
+-- sysctl("kern.maxfiles", 204800);
+-- sysctl("kern.maxfilesperproc", 200000);
+-- ??? -- sysctl("kern.ipc.nmbclusters", 524288);
+-- sysctl("kern.ipc.maxsockbuf", 2097152);
+sysctl("kern.random.sys.harvest.ethernet", 0);
+sysctl("kern.random.sys.harvest.interrupt", 0);
+-- sysctl("net.inet.ip.dummynet.io_fast", 1);
+-- sysctl("net.inet.ip.dummynet.max_chain_len", 2048);
+-- sysctl("net.inet.ip.dummynet.hash_size", 65535);
+-- sysctl("net.inet.ip.dummynet.pipe_slot_limit", 2048);
+-- ?? -- sysctl("net.inet.carp.preempt", 1);
+-- ?? -- sysctl("net.inet.carp.log", 2);
+-- ?? -- sysctl("kern.ipc.shmmax", 67108864);
+sysctl("net.inet.ip.intr_queue_maxlen", 8192);
+sysctl("net.inet.ip.fw.one_pass", 0);
+sysctl("net.inet.ip.portrange.randomized", 0);
+sysctl("net.inet.tcp.nolocaltimewait", 1);
 
 racoon = 0;
 if racoon == 0 then
@@ -1004,8 +1267,7 @@
 -- WAN links tasks
 table.insert(r.tasks.countdown, { count=2, task=
 	function()
-	    print("Init WAN links");
-	    os.execute("echo 'Init WAN links ...' > /dev/console");
+	    print("Init WAN links ...");
 	    configure_wan(c);
 	    return (true);
 	end
@@ -1013,8 +1275,7 @@
 -- IPSec links tasks
 table.insert(r.tasks.countdown, { count=10, task=
 	function()
-	    print("Run racoon");
-	    os.execute("echo 'Run racoon ...' > /dev/console");
+	    print("Run racoon ...");
 	    racoon:run();
 	    return (true);
 	end
--- a/profiles/dlink.ua.web/files/etc/www/httpd.sh	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/httpd.sh	Thu Sep 20 15:21:29 2012 +0300
@@ -5,6 +5,11 @@
 
 echo $$ > /var/run/httpd.sh.pid
 
+./httpd.lua > /var/log/httpd.sh.log 2>&1
+echo -n "./httpd.lua exit with status code $? at " >> /var/log/httpd.sh.log 2>&1
+date >> /var/log/httpd.sh.log 2>&1
+echo "./httpd.lua exit " > /dev/console
+exit 1
 
 while true; do
     ./httpd.lua
--- a/profiles/dlink.ua.web/files/etc/www/lib/base64.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-
-
-
--- encoding
-function b64enc(data)
-    local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-    return ((data:gsub('.', function(x)
-        local r,b='',x:byte()
-        for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
-        return r;
-    end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
-        if (#x < 6) then return '' end
-        local c=0
-        for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
-        return b:sub(c+1,c+1)
-    end)..({ '', '==', '=' })[#data%3+1])
-end
-
--- decoding
-function b64dec(data)
-    local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-    data = string.gsub(data, '[^'..b..'=]', '')
-    return (data:gsub('.', function(x)
-        if (x == '=') then return '' end
-        local r,f='',(b:find(x)-1)
-        for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
-        return r;
-    end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
-        if (#x ~= 8) then return '' end
-        local c=0
-        for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
-        return string.char(c)
-    end))
-end
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/bit.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-function bit(p)
-    return 2 ^ (p - 1);
-    -- 1-based indexing
-end
--- Typical call: if hasbit(x, bit(3)) then ...
-function hasbit(x, p)
-    return x % (p + p) >= p;
-end
-
-function setbit(x, p)
-    return hasbit(x, p) and x or x + p;
-end
-
-function clearbit(x, p)
-    return hasbit(x, p) and x - p or x;
-end
-
--- &(0x12345678 & 0xfffff000) = 0x12345000
-function andL(x, y)
-    local o = 0;
-
-    for i = 1,32,1 do
-	if hasbit(x, bit(i)) and hasbit(y, bit(i)) then
-	    o = o + bit(i);
-	end
-    end
-
-    return (o);
-end
--- a/profiles/dlink.ua.web/files/etc/www/lib/conf.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
------------------------------------
------------ Conf Class ------------
------------------------------------
-Conf = {};
-local mt = {};
-
-function Conf:new(s)
-    return setmetatable({ tree = s or '' }, mt)
-end
-
-function Conf:gettree()
-    return (self.tree);
-end
-
-function Conf:getNodeValue(path)
-    local node = self:getNode(path);
-    if type(node) == "table" then
-	return (node:value());
-    end
-    return (nil);
-end
-
-function Conf:getNode(path)
-    local function getNodeL(node, lpath)
-        local match, name, rpath, id = nil;
-	local matched = 0;
-
-	if not node then return (nil) end
-	if (not lpath) or (string.len(lpath) == 0) then
-	    return (node);
-	end
-
-	match, _, name, _, rpath = string.find(lpath, "^([%w%_%-%[%]]+)(%.*)(%S*)$");
-	if not match then
-	    print("Wrong lpath " .. lpath);
-	    return (nil);
-	end
-
-	rmatch, _, idname, id = string.find(name, "^([%w%_%-]+)%[(%d+)%]$");
-	if rmatch then
-	    name = idname;
-	end
-
-	if not name then
-	    print("Empty name");
-	    return (nil);
-	end
-
-	if node._children then
-    	    for _, v in ipairs(node._children) do
-    		if v._type == "ELEMENT" and v._name == name then
-    		    matched = matched + 1;
-    		    if (not id or (matched == tonumber(id))) then
-    			if string.len(rpath) > 0 then
-    			    return getNodeL(v, rpath);
-    			end
-    			return (v);
-    		    end
-    		end
-    	    end
-    	end
-	return (nil);
-    end
-
-    local ret = getNodeL(self.tree, path);
-    return (Node:new(ret, path));
-end
-
---      node = { _name = <Element Name>,
---              _type = ROOT|ELEMENT|TEXT|COMMENT|PI|DECL|DTD,
---              _attr = { Node attributes - see callback API },
---              _parent = <Parent Node>
---              _children = { List of child nodes - ROOT/NODE only }
---            }
-
-function createNode(_name, _type, _attr, _children, _parent)
-    -- TODO: check for "^(ROOT|ELEMENT|TEXT|COMMENT|PI|DECL|DTD)$"
-    if not _name or not _type then
-	print(_name or "(no name)", _type or "(no type)");
-
-	return (nil);
-    end
-
-    local t = {};
-    t._name = _name;
-    t._type = _type;
-    t._attr = _attr or {};
-    t._parent = _parent;
-    t._children = _children or {};
-    return (t);
-end
-
-function attachNode(parent, node)
-    if not parent or not node then
-	return (nil);
-    end
-
-    if not parent._children then
-	parent._children = {};
-    end
-
-    table.insert(parent._children, node);
-    node._parent = parent;
-
-    return (node);
-end
-
-function Conf:getOrCreateNode(path)
-    local node = self:getNode(path);
-    if node then
-	return (node);
-    end
-
-    node = self.tree;
-    for part in string.gmatch(path, "([^\.]+)%.?") do
-	local rmatch, _, idname, id = string.find(part, "^([%w%_%-]+)%[(%d+)%]$");
-	if rmatch then
-	    part = idname;
-	end
-
-	local matched = 0;
-	if type(node) == "table" and type(node._children) == "table" then
-    	    for _, v in ipairs(node._children) do
-
-    		if v._type == "ELEMENT" and v._name == part then
-		    matched = matched + 1;
-
-		    if id then
-			if id == matched then
-			    node = v;
-			    break;
-			end
-		    else
-			node = v;
-			break;
-		    end
-    		end
-    	    end
-    	end
-
-	if matched == 0 or (id and matched < tonumber(id)) then
-	    local new = createNode(part, "ELEMENT");
-	    attachNode(node, new);
-	    node = new;
-	end
-    end
-    return (Node:new(node, path));
-end
-
-function Conf:get(path)
-    print(tostring(self.tree), path);
-    return (path);
-end
-
-mt.__index = Conf;
------------------------------------
--------- End of Conf Class --------
------------------------------------
--- a/profiles/dlink.ua.web/files/etc/www/lib/dhcpd.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
---[[
-option domain-name "fugue.com";
-option domain-name-servers toccata.fugue.com;
-
-option subnet-mask 255.255.255.224;
-default-lease-time 600;
-max-lease-time 7200;
-
-
-subnet 192.5.5.0 netmask 255.255.255.224 {
-  range 192.5.5.26 192.5.5.30;
-  option name-servers bb.home.vix.com, gw.home.vix.com;
-  option domain-name "vix.com";
-  option routers 192.5.5.1;
-  option subnet-mask 255.255.255.224;
-  option broadcast-address 192.5.5.31;
-  default-lease-time 600;
-  max-lease-time 7200;
-}
-
-host fantasia {
-  hardware ethernet 08:00:07:26:c0:a5;
-  fixed-address fantasia.fugue.com;
-}
-]]
-
-require("ipcalc");
-
-DHCPD = {};
-local mt = {};
-
---DHCPD.instances.instance[1]
-
-
-function DHCPD:new(c, path, debug)
-    t = {};
-    t.path = path;
-    t.c = c;
-    t.iface = c:getNode(path .. "." .. "interface"):value()
-    t.configfile = "/tmp/dhcpd_" .. t.iface .. ".conf";
-    t.pidfile = "/tmp/dhcpd_" .. t.iface .. ".pid";
-    t.debug = debug;
-    return setmetatable(t, mt);
-end
-
-function DHCPD:make_conf()
-
-    self.get  = function (var      ) return self.c:getNode(self.path .. "." .. var):value()    end;
-    self.attr = function (var, attr) return self.c:getNode(self.path .. "." .. var):attr(attr) end;
-    self.conf_data = "";
-
-    local function a(txt)
-	if not txt then
-	    return (nil);
-	end
-	self.conf_data = self.conf_data .. txt .. "\n";
-	if self.debug then print(txt); end
-    end
-
-
-
-
-    local function perhost(name, macaddr, ip)
-	return  "host " .. name .." {\n\thardware ethernet " .. macaddr ..
-	    ";\n\tfixed-address " .. ip ..";\n}\n";
-    end
---    for i = 1,16,1 do
---	-- TODO: static entrys
---    end
-
-    local if_ipaddr = self.c:getNode("interfaces." .. self.iface .. ".ipaddr"):value();
-    local r = cidr_to_net(if_ipaddr);
-    a("option domain-name \"".. self.get("domain") .."\";");
-    a("option domain-name-servers " .. r.ip ..";");
-    a("default-lease-time " .. self.get("default-lease-time") ..";");
-    a("max-lease-time ".. self.get("max-lease-time") ..";");
-    a("subnet " .. r.net .." netmask " .. r.mask .." {");
-    a("\trange " .. self.get("range.start") .. " " .. self.get("range.end") ..";");
-    a("\toption routers " .. r.ip ..";");
-    a("\toption broadcast-address " .. r.broadcast ..";");
-    a("}");
-
-end
-
-function DHCPD:write()
-
-    local f = assert(io.open(self.configfile, "w"));
-    f:write(self.conf_data);
-    f:close();
-end
-
-function DHCPD:run()
-
-    os.execute("mkdir -p /var/run/");
-    os.execute("mkdir -p /var/db/");
-    os.execute("touch /var/db/dhcpd.leases");
-    os.execute("/sbin/dhcpd -lf /var/db/dhcpd.leases -cf " .. self.configfile .. " " .. self.iface);
-end
-
-function DHCPD:stop()
-
-    os.execute("kill `cat /var/run/dhcpd.pid`");
-end
-
-mt.__index = DHCPD;
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/handler.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,305 +0,0 @@
----
---  Overview:
---  =========
---      Standard XML event handler(s) for XML parser module (xml.lua)
---
---  Features:
---  =========
---      printHandler        - Generate XML event trace
---      domHandler          - Generate DOM-like node tree
---      simpleTreeHandler   - Generate 'simple' node tree
---
---  API:
---  ====
---      Must be called as handler function from xmlParser
---      and implement XML event callbacks (see xmlParser.lua
---      for callback API definition)
---
---      printHandler:
---      -------------
---
---      printHandler prints event trace for debugging
---
---      domHandler:
---      -----------
---
---      domHandler generates a DOM-like node tree  structure with
---      a single ROOT node parent - each node is a table comprising
---      fields below.
---
---      node = { _name = <Element Name>,
---              _type = ROOT|ELEMENT|TEXT|COMMENT|PI|DECL|DTD,
---              _attr = { Node attributes - see callback API },
---              _parent = <Parent Node>
---              _children = { List of child nodes - ROOT/NODE only }
---            }
---
---      The dom structure is capable of representing any valid XML document
---
---      simpleTreeHandler
---      -----------------
---
---      simpleTreeHandler is a simplified handler which attempts
---      to generate a more 'natural' table based structure which
---      supports many common XML formats.
---
---      The XML tree structure is mapped directly into a recursive
---      table structure with node names as keys and child elements
---      as either a table of values or directly as a string value
---      for text. Where there is only a single child element this
---      is inserted as a named key - if there are multiple
---      elements these are inserted as a vector (in some cases it
---      may be preferable to always insert elements as a vector
---      which can be specified on a per element basis in the
---      options).  Attributes are inserted as a child element with
---      a key of '_attr'.
---
---      Only Tag/Text & CDATA elements are processed - all others
---      are ignored.
---
---      This format has some limitations - primarily
---
---      * Mixed-Content behaves unpredictably - the relationship
---        between text elements and embedded tags is lost and
---        multiple levels of mixed content does not work
---      * If a leaf element has both a text element and attributes
---        then the text must be accessed through a vector (to
---        provide a container for the attribute)
---
---      In general however this format is relatively useful.
---
---      It is much easier to understand by running some test
---      data through 'textxml.lua -simpletree' than to read this)
---
---  Options
---  =======
---      simpleTreeHandler.options.noReduce = { <tag> = bool,.. }
---
---          - Nodes not to reduce children vector even if only
---            one child
---
---      domHandler.options.(comment|pi|dtd|decl)Node = bool
---
---          - Include/exclude given node types
---
---  Usage
---  =====
---      Pased as delegate in xmlParser constructor and called
---      as callback by xmlParser:parse(xml) method.
---
---      See textxml.lua for examples
---  License:
---  ========
---
---      This code is freely distributable under the terms of the Lua license
---      (<a href="http://www.lua.org/copyright.html">http://www.lua.org/copyright.html</a>)
---
---  History
---  =======
---  $Id: handler.lua,v 1.1.1.1 2001/11/28 06:11:33 paulc Exp $
---
---  $Log: handler.lua,v $
---  Revision 1.1.1.1  2001/11/28 06:11:33  paulc
---  Initial Import
[email protected] Paul Chakravarti ([email protected])<p/>
-
-
----Handler to generate a string prepresentation of a table
---Convenience function for printHandler (Does not support recursive tables).
[email protected] t Table to be parsed
[email protected] Returns a string representation of table
-function showTable(t)
-    local sep = ''
-    local res = ''
-    if type(t) ~= 'table' then
-        return t
-    end
-    for k,v in pairs(t) do
-        if type(v) == 'table' then
-            v = showTable(v)
-        end
-        res = res .. sep .. string.format("%s=%s",k,v)
-        sep = ','
-    end
-    res = '{'..res..'}'
-    return res
-end
-
----Handler to generate a simple event trace
-printHandler = function()
-    local obj = {}
-    obj.starttag = function(self,t,a,s,e)
-        io.write("Start    : "..t.."\n")
-        if a then
-            for k,v in pairs(a) do
-                io.write(string.format(" + %s='%s'\n",k,v))
-            end
-        end
-    end
-    obj.endtag = function(self,t,s,e)
-        io.write("End      : "..t.."\n")
-    end
-    obj.text = function(self,t,s,e)
-        io.write("Text     : "..t.."\n")
-    end
-    obj.cdata = function(self,t,s,e)
-        io.write("CDATA    : "..t.."\n")
-    end
-    obj.comment = function(self,t,s,e)
-        io.write("Comment  : "..t.."\n")
-    end
-    obj.dtd = function(self,t,a,s,e)
-        io.write("DTD      : "..t.."\n")
-        if a then
-            for k,v in pairs(a) do
-                io.write(string.format(" + %s='%s'\n",k,v))
-            end
-        end
-    end
-    obj.pi = function(self,t,a,s,e)
-        io.write("PI       : "..t.."\n")
-        if a then
-            for k,v in pairs(a) do
-               io. write(string.format(" + %s='%s'\n",k,v))
-            end
-        end
-    end
-    obj.decl = function(self,t,a,s,e)
-        io.write("XML Decl : "..t.."\n")
-        if a then
-            for k,v in pairs(a) do
-                io.write(string.format(" + %s='%s'\n",k,v))
-            end
-        end
-    end
-    return obj
-end
-
----Handler to generate a lua table from a XML content string
-function simpleTreeHandler()
-    local obj = {}
-
-    obj.root = {}
-    obj.stack = {obj.root;n=1}
-    obj.options = {noreduce = {}}
-
-    obj.reduce = function(self,node,key,parent)
-        -- Recursively remove redundant vectors for nodes
-        -- with single child elements
-        for k,v in pairs(node) do
-            if type(v) == 'table' then
-                self:reduce(v,k,node)
-            end
-        end
-        if table.getn(node) == 1 and not self.options.noreduce[key] and
-            node._attr == nil then
-            parent[key] = node[1]
-        else
-            node.n = nil
-        end
-    end
-
-    obj.starttag = function(self,t,a)
-        local node = {}
-        if self.parseAttributes == true then
-           node._attr=a
-        end
-
-        local current = self.stack[table.getn(self.stack)]
-        if current[t] then
-            table.insert(current[t],node)
-        else
-            current[t] = {node;n=1}
-        end
-        table.insert(self.stack,node)
-    end
-
-    obj.endtag = function(self,t,s)
-        local current = self.stack[table.getn(self.stack)]
-        local prev = self.stack[table.getn(self.stack)-1]
-        if not prev[t] then
-            error("XML Error - Unmatched Tag ["..s..":"..t.."]\n")
-        end
-        if prev == self.root then
-            -- Once parsing complete recursively reduce tree
-            self:reduce(prev,nil,nil)
-        end
-        table.remove(self.stack)
-    end
-
-    obj.text = function(self,t)
-        local current = self.stack[table.getn(self.stack)]
-        table.insert(current,t)
-    end
-
-    obj.cdata = obj.text
-
-    return obj
-end
-
---- domHandler
-function domHandler()
-    local obj = {}
-    obj.options = {commentNode=1,piNode=1,dtdNode=1,declNode=1}
-    obj.root = { _children = {n=0}, _type = "ROOT" }
-    obj.current = obj.root
-    obj.starttag = function(self,t,a)
-            local node = { _type = 'ELEMENT',
-                           _name = t,
-                           _attr = a,
-                           _parent = self.current,
-                           _children = {n=0} }
-            table.insert(self.current._children,node)
-            self.current = node
-    end
-    obj.endtag = function(self,t,s)
-            if t ~= self.current._name then
-                error("XML Error - Unmatched Tag ["..s..":"..t.."]\n")
-            end
-            self.current = self.current._parent
-    end
-    obj.text = function(self,t)
-            local node = { _type = "TEXT",
-                           _parent = self.current,
-                           _text = t }
-            table.insert(self.current._children,node)
-    end
-    obj.comment = function(self,t)
-            if self.options.commentNode then
-                local node = { _type = "COMMENT",
-                               _parent = self.current,
-                               _text = t }
-                table.insert(self.current._children,node)
-            end
-    end
-    obj.pi = function(self,t,a)
-            if self.options.piNode then
-                local node = { _type = "PI",
-                               _name = t,
-                               _attr = a,
-                               _parent = self.current }
-                table.insert(self.current._children,node)
-            end
-    end
-    obj.decl = function(self,t,a)
-            if self.options.declNode then
-                local node = { _type = "DECL",
-                               _name = t,
-                               _attr = a,
-                               _parent = self.current }
-                table.insert(self.current._children,node)
-            end
-    end
-    obj.dtd = function(self,t,a)
-            if self.options.dtdNode then
-                local node = { _type = "DTD",
-                               _name = t,
-                               _attr = a,
-                               _parent = self.current }
-                table.insert(self.current._children,node)
-            end
-    end
-    obj.cdata = obj.text
-    return obj
-end
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/hostapd.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
---[[
-ieee80211d=1
-country_code=UA
-interface=wlan0
-macaddr_acl=0
-auth_algs=1
-debug=1
-hw_mode=g
-ctrl_interface=/var/run/hostapd
-ctrl_interface_group=wheel
-ssid=freebsdap
-wpa=2
-wpa_passphrase=freebsdmall
-wpa_key_mgmt=WPA-PSK
-wpa_pairwise=CCMP TKIP
-
-<hostapd>
-    <instance id="0" enable="true">
-        <ieee80211d>1</ieee80211d>
-        <country_code>UA</country_code>
-        <interface>wlan0</interface>
-        <macaddr_acl>0</macaddr_acl>
-        <auth_algs>1</auth_algs>
-        <debug>0</debug>
-        <hw_mode>g</hw_mode>
-        <ctrl_interface>/var/run/hostapd</ctrl_interface>
-        <ctrl_interface_group>wheel</ctrl_interface_group>
-        <ssid>DIR-620</ssid>
-        <!-- Open -->
-        <wpa>0</wpa>
-        <!-- WPA -->
-        <!-- <wpa>1</wpa> -->
-        <!-- RSN/WPA2 -->
-        <!-- <wpa>2</wpa> -->
-    </instance>
-    <instance id="1" enable="false">
-        <ieee80211d>1</ieee80211d>
-        <country_code>UA</country_code>
-        <interface>wlan0</interface>
-        <macaddr_acl>0</macaddr_acl>
-        <auth_algs>1</auth_algs>
-        <debug>0</debug>
-        <hw_mode>g</hw_mode>
-        <ctrl_interface>/var/run/hostapd</ctrl_interface>
-        <ctrl_interface_group>wheel</ctrl_interface_group>
-        <ssid>DIR-620</ssid>
-        <!-- WPA -->
-        <!-- <wpa>1</wpa> -->
-        <!-- RSN/WPA2 -->
-        <wpa>2</wpa>
-        <wpa_passphrase>freebsdmall</wpa_passphrase>
-        <wpa_key_mgmt>WPA-PSK</wpa_key_mgmt>
-        <wpa_pairwise>CCMP TKIP</wpa_pairwise>
-    </instance>
-</hostapd>
-
-]]
-
-HOSTAPD = {};
-local mt = {};
-
---hostapd.instance[1]
-
-
-function HOSTAPD:new(c, debug)
-    t = {};
-    t.c = c;
-    t.debug = debug;
-    t.configfile = {};
-    t.conf_data = {};
-    t.pidfile = "/var/run/hostapd.pid";
-    return setmetatable(t, mt);
-end
-
-function HOSTAPD:make_conf(i)
-
-    if self.debug == 1 then print("HOSTAPD:make_conf(".. tostring(i) .. ")"); end
-
-    local path = "hostapd.instance[" .. i .. "]";
-
-    self.conf_data[i] = "";
-
-    local function a(txt)
-	if not txt then
-	    return (nil);
-	end
-	self.conf_data[i] = self.conf_data[i] .. txt .. "\n";
-	if self.debug then print(txt); end
-    end
-
-	local iface = self.c:getNode(path .. ".interface"):value();
-	self.configfile[i] = "/tmp/hostapd_" .. iface .. ".conf";
-
-	a("ieee80211d=1");
-	a("country_code=UA");
-	a("interface=" .. iface);
-	a("macaddr_acl=0");
-	a("auth_algs=1");
-	a("debug=0");
-	a("hw_mode=g");
-	a("ctrl_interface=/var/run/hostapd");
-	a("ctrl_interface_group=wheel");
-	a("ssid=" .. self.c:getNode(path .. ".ssid"):value() .. "");
-	-- TODO: crypto support
-	a("wpa=2");
-	a("wpa_passphrase=freebsdmall");
-	a("wpa_key_mgmt=WPA-PSK");
-	a("wpa_pairwise=CCMP");
-
-end
-
-function HOSTAPD:write(i)
-
-    local f = assert(io.open(self.configfile[i], "w"));
-    f:write(self.conf_data[i]);
-    f:close();
-end
-
-function HOSTAPD:run()
-    local configs = "";
-    local i;
-    for i = 1,8,1 do
-	local vap = self.c:getNode("hostapd.instance[" .. i .. "]");
-	if vap and vap:attr("enable") == "true" then
-	    if self.debug == 1 then print("CALL self.make_conf(".. tostring(i) .. ")"); end
-	    self:make_conf(i);
-	    if self.debug == 1 then print("CALL self.write(".. tostring(i) .. ")"); end
-	    self:write(i);
-	    configs = configs .. " " .. self.configfile[i];
-	end
-    end
-
-    os.execute("mkdir -p /var/run/");
-    os.execute("/usr/sbin/hostapd -B -P " .. self.pidfile .. " " .. configs);
-end
-
-function HOSTAPD:stop()
-
-    os.execute("kill `cat " .. self.pidfile .."`");
-end
-
-mt.__index = HOSTAPD;
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/ipcalc.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-require("bit");
-
-function bits_to_hostmask(b)
-    return (2 ^ (32-b) - 1);
-end
-
-function bits_to_netmask(b)
-    return ((2 ^ 32 - 1) - bits_to_hostmask(b));
-end
-
-
-function cidr_to_net(cidr)
-    local r = {};
-    r.cidr	= cidr;
-
-    local function dotted(i)
-	local l1,l2,l3,r1,r2,r3,r4;
-	r1 =  i % 256; l1 =  i / 256;
-	r2 = l1 % 256; l2 = l1 / 256;
-	r3 = l2 % 256; l3 = l2 / 256;
-	r4 = l3 % 256;
-	return string.format("%d.%d.%d.%d", r4, r3, r2, r1);
-    end
-
-    local function toint(i1, i2, i3, i4)
-	return
-	    ((tonumber(i1) * (2^24)) +
-	     (tonumber(i2) * (2^16)) +
-	     (tonumber(i3) * ( 2^8)) +
-	     (tonumber(i4)         ));
-    end
-
-    local i1, i2, i3, i4;
-
-    i1, i2, i3, i4, r.bits = string.match(cidr, "^(%d+)%.(%d+)%.(%d+)%.(%d+)%/(%d+)$");
-
-    if r.bits then
-	r.ip = toint(i1, i2, i3, i4);
-    else
-	local i1, i2, i3, i4, m1, m2, m3, m4 = string.match(cidr,
-	    "^(%d+)%.(%d+)%.(%d+)%.(%d+)%/(%d+)%.(%d+)%.(%d+)%.(%d+)$");
-	if m4 then
-	    r.ip  = toint(i1, i2, i3, i4);
-	    r.net = toint(m1, m2, m3, m4);
-	else
-	    return nil, "Failed to parse";
-	end
-    end
-
-    r.mask 	= dotted(           bits_to_netmask (r.bits));
-    r.net 	= dotted(andL(r.ip, bits_to_netmask (r.bits)));
-    r.host 	= dotted(andL(r.ip, bits_to_hostmask(r.bits)));
-    r.broadcast = dotted(andL(r.ip, bits_to_netmask (r.bits)) + (2 ^ (32-r.bits) - 1) );
-    r.ip 	= dotted(     r.ip);
-
-    return r;
-end
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/ltn12.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,292 +0,0 @@
------------------------------------------------------------------------------
--- LTN12 - Filters, sources, sinks and pumps.
--- LuaSocket toolkit.
--- Author: Diego Nehab
--- RCS ID: $Id: ltn12.lua,v 1.31 2006/04/03 04:45:42 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module
------------------------------------------------------------------------------
-local string = require("string")
-local table = require("table")
-local base = _G
-module("ltn12")
-
-filter = {}
-source = {}
-sink = {}
-pump = {}
-
--- 2048 seems to be better in windows...
-BLOCKSIZE = 2048
-_VERSION = "LTN12 1.0.1"
-
------------------------------------------------------------------------------
--- Filter stuff
------------------------------------------------------------------------------
--- returns a high level filter that cycles a low-level filter
-function filter.cycle(low, ctx, extra)
-    base.assert(low)
-    return function(chunk)
-        local ret
-        ret, ctx = low(ctx, chunk, extra)
-        return ret
-    end
-end
-
--- chains a bunch of filters together
--- (thanks to Wim Couwenberg)
-function filter.chain(...)
-    local n = table.getn(arg)
-    local top, index = 1, 1
-    local retry = ""
-    return function(chunk)
-        retry = chunk and retry
-        while true do
-            if index == top then
-                chunk = arg[index](chunk)
-                if chunk == "" or top == n then return chunk
-                elseif chunk then index = index + 1
-                else
-                    top = top+1
-                    index = top
-                end
-            else
-                chunk = arg[index](chunk or "")
-                if chunk == "" then
-                    index = index - 1
-                    chunk = retry
-                elseif chunk then
-                    if index == n then return chunk
-                    else index = index + 1 end
-                else base.error("filter returned inappropriate nil") end
-            end
-        end
-    end
-end
-
------------------------------------------------------------------------------
--- Source stuff
------------------------------------------------------------------------------
--- create an empty source
-local function empty()
-    return nil
-end
-
-function source.empty()
-    return empty
-end
-
--- returns a source that just outputs an error
-function source.error(err)
-    return function()
-        return nil, err
-    end
-end
-
--- creates a file source
-function source.file(handle, io_err)
-    if handle then
-        return function()
-            local chunk = handle:read(BLOCKSIZE)
-            if not chunk then handle:close() end
-            return chunk
-        end
-    else return source.error(io_err or "unable to open file") end
-end
-
--- turns a fancy source into a simple source
-function source.simplify(src)
-    base.assert(src)
-    return function()
-        local chunk, err_or_new = src()
-        src = err_or_new or src
-        if not chunk then return nil, err_or_new
-        else return chunk end
-    end
-end
-
--- creates string source
-function source.string(s)
-    if s then
-        local i = 1
-        return function()
-            local chunk = string.sub(s, i, i+BLOCKSIZE-1)
-            i = i + BLOCKSIZE
-            if chunk ~= "" then return chunk
-            else return nil end
-        end
-    else return source.empty() end
-end
-
--- creates rewindable source
-function source.rewind(src)
-    base.assert(src)
-    local t = {}
-    return function(chunk)
-        if not chunk then
-            chunk = table.remove(t)
-            if not chunk then return src()
-            else return chunk end
-        else
-            table.insert(t, chunk)
-        end
-    end
-end
-
-function source.chain(src, f)
-    base.assert(src and f)
-    local last_in, last_out = "", ""
-    local state = "feeding"
-    local err
-    return function()
-        if not last_out then
-            base.error('source is empty!', 2)
-        end
-        while true do
-            if state == "feeding" then
-                last_in, err = src()
-                if err then return nil, err end
-                last_out = f(last_in)
-                if not last_out then
-                    if last_in then
-                        base.error('filter returned inappropriate nil')
-                    else
-                        return nil
-                    end
-                elseif last_out ~= "" then
-                    state = "eating"
-                    if last_in then last_in = "" end
-                    return last_out
-                end
-            else
-                last_out = f(last_in)
-                if last_out == "" then
-                    if last_in == "" then
-                        state = "feeding"
-                    else
-                        base.error('filter returned ""')
-                    end
-                elseif not last_out then
-                    if last_in then
-                        base.error('filter returned inappropriate nil')
-                    else
-                        return nil
-                    end
-                else
-                    return last_out
-                end
-            end
-        end
-    end
-end
-
--- creates a source that produces contents of several sources, one after the
--- other, as if they were concatenated
--- (thanks to Wim Couwenberg)
-function source.cat(...)
-    local src = table.remove(arg, 1)
-    return function()
-        while src do
-            local chunk, err = src()
-            if chunk then return chunk end
-            if err then return nil, err end
-            src = table.remove(arg, 1)
-        end
-    end
-end
-
------------------------------------------------------------------------------
--- Sink stuff
------------------------------------------------------------------------------
--- creates a sink that stores into a table
-function sink.table(t)
-    t = t or {}
-    local f = function(chunk, err)
-        if chunk then table.insert(t, chunk) end
-        return 1
-    end
-    return f, t
-end
-
--- turns a fancy sink into a simple sink
-function sink.simplify(snk)
-    base.assert(snk)
-    return function(chunk, err)
-        local ret, err_or_new = snk(chunk, err)
-        if not ret then return nil, err_or_new end
-        snk = err_or_new or snk
-        return 1
-    end
-end
-
--- creates a file sink
-function sink.file(handle, io_err)
-    if handle then
-        return function(chunk, err)
-            if not chunk then
-                handle:close()
-                return 1
-            else return handle:write(chunk) end
-        end
-    else return sink.error(io_err or "unable to open file") end
-end
-
--- creates a sink that discards data
-local function null()
-    return 1
-end
-
-function sink.null()
-    return null
-end
-
--- creates a sink that just returns an error
-function sink.error(err)
-    return function()
-        return nil, err
-    end
-end
-
--- chains a sink with a filter
-function sink.chain(f, snk)
-    base.assert(f and snk)
-    return function(chunk, err)
-        if chunk ~= "" then
-            local filtered = f(chunk)
-            local done = chunk and ""
-            while true do
-                local ret, snkerr = snk(filtered, err)
-                if not ret then return nil, snkerr end
-                if filtered == done then return 1 end
-                filtered = f(done)
-            end
-        else return 1 end
-    end
-end
-
------------------------------------------------------------------------------
--- Pump stuff
------------------------------------------------------------------------------
--- pumps one chunk from the source to the sink
-function pump.step(src, snk)
-    local chunk, src_err = src()
-    local ret, snk_err = snk(chunk, src_err)
-    if chunk and ret then return 1
-    else return nil, src_err or snk_err end
-end
-
--- pumps all data from a source to a sink, using a step function
-function pump.all(src, snk, step)
-    base.assert(src and snk)
-    step = step or pump.step
-    while true do
-        local ret, err = step(src, snk)
-        if not ret then
-            if err then return nil, err
-            else return 1 end
-        end
-    end
-end
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/mime.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
------------------------------------------------------------------------------
--- MIME support for the Lua language.
--- Author: Diego Nehab
--- Conforming to RFCs 2045-2049
--- RCS ID: $Id: mime.lua,v 1.29 2007/06/11 23:44:54 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
------------------------------------------------------------------------------
-local base = _G
-local ltn12 = require("ltn12")
-local mime = require("mime.core")
-local io = require("io")
-local string = require("string")
-module("mime")
-
--- encode, decode and wrap algorithm tables
-encodet = {}
-decodet = {}
-wrapt = {}
-
--- creates a function that chooses a filter by name from a given table
-local function choose(table)
-    return function(name, opt1, opt2)
-        if base.type(name) ~= "string" then
-            name, opt1, opt2 = "default", name, opt1
-        end
-        local f = table[name or "nil"]
-        if not f then
-            base.error("unknown key (" .. base.tostring(name) .. ")", 3)
-        else return f(opt1, opt2) end
-    end
-end
-
--- define the encoding filters
-encodet['base64'] = function()
-    return ltn12.filter.cycle(b64, "")
-end
-
-encodet['quoted-printable'] = function(mode)
-    return ltn12.filter.cycle(qp, "",
-        (mode == "binary") and "=0D=0A" or "\r\n")
-end
-
--- define the decoding filters
-decodet['base64'] = function()
-    return ltn12.filter.cycle(unb64, "")
-end
-
-decodet['quoted-printable'] = function()
-    return ltn12.filter.cycle(unqp, "")
-end
-
-local function format(chunk)
-    if chunk then
-        if chunk == "" then return "''"
-        else return string.len(chunk) end
-    else return "nil" end
-end
-
--- define the line-wrap filters
-wrapt['text'] = function(length)
-    length = length or 76
-    return ltn12.filter.cycle(wrp, length, length)
-end
-wrapt['base64'] = wrapt['text']
-wrapt['default'] = wrapt['text']
-
-wrapt['quoted-printable'] = function()
-    return ltn12.filter.cycle(qpwrp, 76, 76)
-end
-
--- function that choose the encoding, decoding or wrap algorithm
-encode = choose(encodet)
-decode = choose(decodet)
-wrap = choose(wrapt)
-
--- define the end-of-line normalization filter
-function normalize(marker)
-    return ltn12.filter.cycle(eol, 0, marker)
-end
-
--- high level stuffing filter
-function stuff()
-    return ltn12.filter.cycle(dot, 2)
-end
--- a/profiles/dlink.ua.web/files/etc/www/lib/mpd.lua	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/lib/mpd.lua	Thu Sep 20 15:21:29 2012 +0300
@@ -36,6 +36,7 @@
 set modem var $DialPrefix "DT"
 set modem var $Telephone "#777"
 set modem var $TryPPPEarly "yes"
+set modem var $InitString "+CGDCONT=1,\"IP\",\"internet\""
 set modem script DialPeer
 set modem idle-script Ringback
 set modem watch -cd
@@ -109,6 +110,7 @@
 end
 
 function MPD:config_bundle(path, bundle)
+    local pathl = path .. ".";
     local node;
 
     self.socket = socket.connect(self.host, self.port);
@@ -124,28 +126,34 @@
 --    self:msg("set bundle links L1");
 
     -- TODO
---    local ip = c:getNode(path .. "." .. "ipaddr")
+--    local ip = c:getNode(pathl .. "ipaddr")
 --    if ip then
 --	string.match(ip:value(), "%d+%.%d+%.%d+%.%d+%/(%d+)")
 --    end
 
-    self:msg("set iface addrs 10.254.254.1 10.254.254.2");
+    local def_local_addr = "0.0.0.0";
+    local def_perr_addr = "10.254.254.2";
+    if self.c:getNode(pathl .. "gateway"):value() then
+	def_perr_addr = self.c:getNode(pathl .. "gateway"):value();
+    end
+
+    self:msg("set iface addrs " .. def_local_addr .. " " .. def_perr_addr);
     self:msg("set iface up-script /etc/mpd-linkup");
     self:msg("set iface down-script /etc/mpd-linkdown");
-    self:msg("set ipcp ranges 0.0.0.0/0 0.0.0.0/0");
+    self:msg("set ipcp ranges " .. def_local_addr .. "/0 " .. def_perr_addr .."/0");
 
     -- We should apply default on a up-script run
 --     self:msg("set iface route default");
 
-    local dod = self.c:getNode(path .. "." .. "on-demand")
+    local dod = self.c:getNode(pathl .. "on-demand")
     if dod and dod:attr("enable") == "true" then
 	self:msg("set iface enable on-demand");
-        self:msg("set iface idle " .. self.c:getNode(path .. "." .. "idle-time"):value());
+        self:msg("set iface idle " .. self.c:getNode(pathl .. "idle-time"):value());
     end
 
     self:msg("set iface name " .. bundle);
 
-    node = self.c:getNode(path .. "." .. "nat")
+    node = self.c:getNode(pathl .. "nat")
     if node and node:attr("enable") == "true" then
 	self:msg("set iface enable nat");
     end
@@ -162,7 +170,7 @@
 end
 
 function MPD:config_link(path, link, bundle)
-
+    local pathl = path .. ".";
     self.socket = socket.connect(self.host, self.port);
 	if not self.socket then
 		print("Can't connect to " .. self.host .. ":" .. self.port);
@@ -179,10 +187,10 @@
     self:msg("create link static " .. link .. " " .. mpdtype);
     self:msg("link " .. link);
 
-    local user = self.c:getNode(path .. "." .. "username");
+    local user = self.c:getNode(pathl .. "username");
     if user and user:value() and string.len(user:value()) > 0 then
 	self:msg("set auth authname " .. user:value());
-	local passwd = self.c:getNode(path .. "." .. "username");
+	local passwd = self.c:getNode(pathl .. "password");
 	if passwd and passwd:value() then
 	    self:msg("set auth password \"" .. passwd:value() .. "\"");
 	else
@@ -191,16 +199,33 @@
     end
 
     if mpdtype == "modem" then
-	self:msg("set modem device " .. self.c:getNode(path .. "." .. "device"):value() .. "");
+	self:msg("set modem device " ..
+	    self.c:getNode(pathl .. "device"):value() .. "");
 	self:msg("set modem var $DialPrefix \"DT\"");
+	-- Try to send PPP request, for cases when modem stick at data mode
+	-- Leased Line.
 	self:msg("set modem var $TryPPPEarly \"yes\"");
-	self:msg("set modem var $Telephone \"" .. self.c:getNode(path .. "." .. "phone"):value() .. "\"");
+	self:msg("set modem var $Telephone \"" ..
+	    self.c:getNode(pathl .. "phone"):value() .. "\"");
+	local initstring = self.c:getNode(pathl .. "init_string");
+	if initstring then -- If node
+	    initstring = initstring:value();
+	    if initstring and initstring ~= "" then -- If value not empty
+		-- Escape double quotes
+		initstring = initstring:gsub("\"", "\\\"");
+		print("set modem var $InitString \"" .. initstring .. "\"");
+		self:msg("set modem var $InitString \"" .. initstring .. "\"");
+	    end
+	end
 	self:msg("set modem script DialPeer");
 	self:msg("set modem idle-script Ringback");
 	self:msg("set modem watch -cd");
     elseif mpdtype == "pppoe" then
-	self:msg("set pppoe iface " .. self.c:getNode(path .. "." .. "interface"):value() .. "");
-	self:msg("set pppoe service \"" .. self.c:getNode(path .. "." .. "service"):value() .. "\"");
+	self:msg("set pppoe iface " .. self.c:getNode(pathl .. "device"):value() .. "");
+	local service_node = self.c:getNode(pathl .. "service_name");
+	if service_node and service_node:value() then
+	    self:msg("set pppoe service \"" .. service_node:value() .. "\"");
+	end
     elseif mpdtype == "pptp" then
 	-- TODO:
 	self:msg("set pptp self 10.1.3.3");
--- a/profiles/dlink.ua.web/files/etc/www/lib/node.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
------------------------------------
------------ Node Class ------------
------------------------------------
-Node = {};
-mtNode = {};
-
-function Node:new(s, path)
-
-    if type(s) ~= "table" then return (nil); end
-    local node = setmetatable({ node = s or '' }, mtNode);
-    node.path = path;
-    return (node);
-end
-
-function Node:dump(f, v)
-    if self.node then
-	if (not f) or f == "txt" then
-	    if v then print("TEXT dump of \"" .. self.path .. "\"") end
-	    return tdump(self.node);
-	elseif f == "xml" then
-	    if v then print("XML dump of \"" .. self.path .. "\"") end
-	    return xmldump(self.node);
-	else
-	    print("Unknow format " .. f);
-	end
-    end
-end
-
-function Node:attr(attr, value)
-    if self.node._attr and type(self.node._attr) == "table" then
-	if value then
-	    self.node._attr[attr] = value;
-	    return (true);
-	else
-	    return (self.node._attr[attr] or "");
-	end
-    end
-    return (nil);
-end
-
-function Node:value(_value)
-    if self.node._children and
-	self.node._children[1] and
-	self.node._children[1]._text then
-
-	if _value then
-	    self.node._children[1]._text = _value;
-	    return (true);
-	else
-	    return (self.node._children[1]._text or "");
-	end
-
-    end
-
-    if _value then
-	if not self.node._children then
-	    self.node._children = {};
-	end
-	table.insert(self.node._children, { _text = _value, _type = "TEXT" });
-    end
-
-    return (nil);
-end
-
-mtNode.__index = Node;
------------------------------------
--------- End of Node Class --------
------------------------------------
--- a/profiles/dlink.ua.web/files/etc/www/lib/pidfile.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-
-function readpid(pidfilename)
-    local pidfile = io.open(pidfilename, "r");
-    if pidfile then
-	local pid = assert(pidfile:read("*n"));
-	pidfile:close();
-	return (pid);
-    end
-    -- TODO: rise error on read/open failures
-    return (nil);
-end
-
-
---
--- check(pidfilename)
--- check for pid file and runnig process
--- return ( 1) if process runnning
--- return (-1) if stale pid file
--- return ( 0) if no pid file
---
-
-function checkpid(pidfilename)
-    local oldpid = readpid(pidfilename);
-    if oldpid and oldpid > 0 then
-	local ret = os.execute("ps -axo command= " .. oldpid);
-	if ret == 0 then
-	    return (1); -- Process running
-	end
-	return (-1); -- Stale pid file, no process
-    end
-    return (0); -- No pid file found
-end
-
---
--- pidfile(pidfilename)
--- check for runnig process and create new pid file otherwise
--- if exit process if checked proccess running
---
-
-function pidfile(pidfilename)
-    local psx = require("posix");
-    local pid = psx.getprocessid("pid");
-
-    if checkpid(pidfilename) == 1 then
-	print("pid file ".. pidfilename .. " locked")
-	os.exit(1);
-    end
-
-    pidfile = assert(io.open(pidfilename, "w"));
-    assert(pidfile:write(pid));
-    pidfile:close();
-
-    return (true);
-end
-
-
-function pidfile_signal(pidfilename, signal)
-    return (false);
-end
-
---
---
--- Terminate running holder of pidfile, and write new pidfile
---
-
-function pidfile_replace_stop()
-end
-
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/racoon.lua	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/lib/racoon.lua	Thu Sep 20 15:21:29 2012 +0300
@@ -190,6 +190,9 @@
 	return (ret);
     end
 
+    -- XXX: We need setup routes per IPSec tunnel
+    local last_gw = nil;
+
     for i = 1,16,1 do
 	local ppath = "ipsec.remote[" ..i.. "]";
 	local node = self.c:getNode(ppath);
@@ -197,6 +200,7 @@
 	    local gw = self.c:getNode(ppath .. ".gateway"):value();
 	    local file = "/var/run/racoon." .. gw .. ".conf";
 	    local remote = gw:gsub(":", " [") .. "]";
+	    last_gw = gw:gsub(":.*", "");
 
 	    local conf = "remote\t" .. remote .. "\n";
 
@@ -232,6 +236,21 @@
 
 	end
     end
+
+    local route_up = nil;
+    local route_down = nil;
+
+    if last_gw then
+	local route_up_file = "/var/run/racoon." .. last_gw .. "_up.sh";
+	local route_down_file = "/var/run/racoon." .. last_gw .. "_down.sh";
+
+	route_up = assert(io.open(route_up_file, "w"));
+	route_down = assert(io.open(route_down_file, "w"));
+
+	route_up:write("#!/bin/sh\n");
+	route_down:write("#!/bin/sh\n");
+    end
+
     for i = 1,16,1 do
 	local ppath = "ipsec.sainfo[" ..i.. "]";
 	local node = self.c:getNode(ppath);
@@ -244,8 +263,14 @@
 	    if dst_cidr:match("%d+%.%d+%.%d+%.%d+%/%d+") then
 		-- Preinstall routes of secured remote nets
 		-- "already in table" ignored
-		print("/sbin/route add " .. dst_cidr .. " -blackhole");
-		os.execute("/sbin/route add " .. dst_cidr .. " -blackhole");
+		local cmd = string.format(
+		    "/sbin/route add %s -iface lo0 -reject", dst_cidr);
+		print(cmd);
+		os.execute(cmd);
+		if last_gw then
+		    route_up:write(string.format("/sbin/route change %s %s\n", dst_cidr, last_gw));
+		    route_down:write(string.format("/sbin/route change %s -iface lo0 -reject\n", dst_cidr));
+		end
 	    end
 
 	    local conf = "sainfo (" .. src .. " " .. dst .. ")\n";
@@ -266,6 +291,10 @@
 	    f:close();
 	end
     end
+    if last_gw then
+	route_up:close();
+	route_down:close();
+    end
 
 end
 
--- a/profiles/dlink.ua.web/files/etc/www/lib/socket.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
------------------------------------------------------------------------------
--- LuaSocket helper module
--- Author: Diego Nehab
--- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
------------------------------------------------------------------------------
-local base = _G
-local string = require("string")
-local math = require("math")
-local socket = require("socket.core")
-module("socket")
-
------------------------------------------------------------------------------
--- Exported auxiliar functions
------------------------------------------------------------------------------
-function connect(address, port, laddress, lport)
-    local sock, err = socket.tcp()
-    if not sock then return nil, err end
-    if laddress then
-        local res, err = sock:bind(laddress, lport, -1)
-        if not res then return nil, err end
-    end
-    local res, err = sock:connect(address, port)
-    if not res then return nil, err end
-    return sock
-end
-
-function bind(host, port, backlog)
-    local sock, err = socket.tcp()
-    if not sock then return nil, err end
-    sock:setoption("reuseaddr", true)
-    local res, err = sock:bind(host, port)
-    if not res then return nil, err end
-    res, err = sock:listen(backlog)
-    if not res then return nil, err end
-    return sock
-end
-
-try = newtry()
-
-function choose(table)
-    return function(name, opt1, opt2)
-        if base.type(name) ~= "string" then
-            name, opt1, opt2 = "default", name, opt1
-        end
-        local f = table[name or "nil"]
-        if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
-        else return f(opt1, opt2) end
-    end
-end
-
------------------------------------------------------------------------------
--- Socket sources and sinks, conforming to LTN12
------------------------------------------------------------------------------
--- create namespaces inside LuaSocket namespace
-sourcet = {}
-sinkt = {}
-
-BLOCKSIZE = 2048
-
-sinkt["close-when-done"] = function(sock)
-    return base.setmetatable({
-        getfd = function() return sock:getfd() end,
-        dirty = function() return sock:dirty() end
-    }, {
-        __call = function(self, chunk, err)
-            if not chunk then
-                sock:close()
-                return 1
-            else return sock:send(chunk) end
-        end
-    })
-end
-
-sinkt["keep-open"] = function(sock)
-    return base.setmetatable({
-        getfd = function() return sock:getfd() end,
-        dirty = function() return sock:dirty() end
-    }, {
-        __call = function(self, chunk, err)
-            if chunk then return sock:send(chunk)
-            else return 1 end
-        end
-    })
-end
-
-sinkt["default"] = sinkt["keep-open"]
-
-sink = choose(sinkt)
-
-sourcet["by-length"] = function(sock, length)
-    return base.setmetatable({
-        getfd = function() return sock:getfd() end,
-        dirty = function() return sock:dirty() end
-    }, {
-        __call = function()
-            if length <= 0 then return nil end
-            local size = math.min(socket.BLOCKSIZE, length)
-            local chunk, err = sock:receive(size)
-            if err then return nil, err end
-            length = length - string.len(chunk)
-            return chunk
-        end
-    })
-end
-
-sourcet["until-closed"] = function(sock)
-    local done
-    return base.setmetatable({
-        getfd = function() return sock:getfd() end,
-        dirty = function() return sock:dirty() end
-    }, {
-        __call = function()
-            if done then return nil end
-            local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
-            if not err then return chunk
-            elseif err == "closed" then
-                sock:close()
-                done = 1
-                return partial
-            else return nil, err end
-        end
-    })
-end
-
-
-sourcet["default"] = sourcet["until-closed"]
-
-source = choose(sourcet)
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/socket/ftp.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,281 +0,0 @@
------------------------------------------------------------------------------
--- FTP support for the Lua language
--- LuaSocket toolkit.
--- Author: Diego Nehab
--- RCS ID: $Id: ftp.lua,v 1.45 2007/07/11 19:25:47 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
------------------------------------------------------------------------------
-local base = _G
-local table = require("table")
-local string = require("string")
-local math = require("math")
-local socket = require("socket")
-local url = require("socket.url")
-local tp = require("socket.tp")
-local ltn12 = require("ltn12")
-module("socket.ftp")
-
------------------------------------------------------------------------------
--- Program constants
------------------------------------------------------------------------------
--- timeout in seconds before the program gives up on a connection
-TIMEOUT = 60
--- default port for ftp service
-PORT = 21
--- this is the default anonymous password. used when no password is
--- provided in url. should be changed to your e-mail.
-USER = "ftp"
-PASSWORD = "[email protected]"
-
------------------------------------------------------------------------------
--- Low level FTP API
------------------------------------------------------------------------------
-local metat = { __index = {} }
-
-function open(server, port, create)
-    local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT, create))
-    local f = base.setmetatable({ tp = tp }, metat)
-    -- make sure everything gets closed in an exception
-    f.try = socket.newtry(function() f:close() end)
-    return f
-end
-
-function metat.__index:portconnect()
-    self.try(self.server:settimeout(TIMEOUT))
-    self.data = self.try(self.server:accept())
-    self.try(self.data:settimeout(TIMEOUT))
-end
-
-function metat.__index:pasvconnect()
-    self.data = self.try(socket.tcp())
-    self.try(self.data:settimeout(TIMEOUT))
-    self.try(self.data:connect(self.pasvt.ip, self.pasvt.port))
-end
-
-function metat.__index:login(user, password)
-    self.try(self.tp:command("user", user or USER))
-    local code, reply = self.try(self.tp:check{"2..", 331})
-    if code == 331 then
-        self.try(self.tp:command("pass", password or PASSWORD))
-        self.try(self.tp:check("2.."))
-    end
-    return 1
-end
-
-function metat.__index:pasv()
-    self.try(self.tp:command("pasv"))
-    local code, reply = self.try(self.tp:check("2.."))
-    local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)"
-    local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern))
-    self.try(a and b and c and d and p1 and p2, reply)
-    self.pasvt = {
-        ip = string.format("%d.%d.%d.%d", a, b, c, d),
-        port = p1*256 + p2
-    }
-    if self.server then
-        self.server:close()
-        self.server = nil
-    end
-    return self.pasvt.ip, self.pasvt.port
-end
-
-function metat.__index:port(ip, port)
-    self.pasvt = nil
-    if not ip then
-        ip, port = self.try(self.tp:getcontrol():getsockname())
-        self.server = self.try(socket.bind(ip, 0))
-        ip, port = self.try(self.server:getsockname())
-        self.try(self.server:settimeout(TIMEOUT))
-    end
-    local pl = math.mod(port, 256)
-    local ph = (port - pl)/256
-    local arg = string.gsub(string.format("%s,%d,%d", ip, ph, pl), "%.", ",")
-    self.try(self.tp:command("port", arg))
-    self.try(self.tp:check("2.."))
-    return 1
-end
-
-function metat.__index:send(sendt)
-    self.try(self.pasvt or self.server, "need port or pasv first")
-    -- if there is a pasvt table, we already sent a PASV command
-    -- we just get the data connection into self.data
-    if self.pasvt then self:pasvconnect() end
-    -- get the transfer argument and command
-    local argument = sendt.argument or
-        url.unescape(string.gsub(sendt.path or "", "^[/\\]", ""))
-    if argument == "" then argument = nil end
-    local command = sendt.command or "stor"
-    -- send the transfer command and check the reply
-    self.try(self.tp:command(command, argument))
-    local code, reply = self.try(self.tp:check{"2..", "1.."})
-    -- if there is not a a pasvt table, then there is a server
-    -- and we already sent a PORT command
-    if not self.pasvt then self:portconnect() end
-    -- get the sink, source and step for the transfer
-    local step = sendt.step or ltn12.pump.step
-    local readt = {self.tp.c}
-    local checkstep = function(src, snk)
-        -- check status in control connection while downloading
-        local readyt = socket.select(readt, nil, 0)
-        if readyt[tp] then code = self.try(self.tp:check("2..")) end
-        return step(src, snk)
-    end
-    local sink = socket.sink("close-when-done", self.data)
-    -- transfer all data and check error
-    self.try(ltn12.pump.all(sendt.source, sink, checkstep))
-    if string.find(code, "1..") then self.try(self.tp:check("2..")) end
-    -- done with data connection
-    self.data:close()
-    -- find out how many bytes were sent
-    local sent = socket.skip(1, self.data:getstats())
-    self.data = nil
-    return sent
-end
-
-function metat.__index:receive(recvt)
-    self.try(self.pasvt or self.server, "need port or pasv first")
-    if self.pasvt then self:pasvconnect() end
-    local argument = recvt.argument or
-        url.unescape(string.gsub(recvt.path or "", "^[/\\]", ""))
-    if argument == "" then argument = nil end
-    local command = recvt.command or "retr"
-    self.try(self.tp:command(command, argument))
-    local code = self.try(self.tp:check{"1..", "2.."})
-    if not self.pasvt then self:portconnect() end
-    local source = socket.source("until-closed", self.data)
-    local step = recvt.step or ltn12.pump.step
-    self.try(ltn12.pump.all(source, recvt.sink, step))
-    if string.find(code, "1..") then self.try(self.tp:check("2..")) end
-    self.data:close()
-    self.data = nil
-    return 1
-end
-
-function metat.__index:cwd(dir)
-    self.try(self.tp:command("cwd", dir))
-    self.try(self.tp:check(250))
-    return 1
-end
-
-function metat.__index:type(type)
-    self.try(self.tp:command("type", type))
-    self.try(self.tp:check(200))
-    return 1
-end
-
-function metat.__index:greet()
-    local code = self.try(self.tp:check{"1..", "2.."})
-    if string.find(code, "1..") then self.try(self.tp:check("2..")) end
-    return 1
-end
-
-function metat.__index:quit()
-    self.try(self.tp:command("quit"))
-    self.try(self.tp:check("2.."))
-    return 1
-end
-
-function metat.__index:close()
-    if self.data then self.data:close() end
-    if self.server then self.server:close() end
-    return self.tp:close()
-end
-
------------------------------------------------------------------------------
--- High level FTP API
------------------------------------------------------------------------------
-local function override(t)
-    if t.url then
-        local u = url.parse(t.url)
-        for i,v in base.pairs(t) do
-            u[i] = v
-        end
-        return u
-    else return t end
-end
-
-local function tput(putt)
-    putt = override(putt)
-    socket.try(putt.host, "missing hostname")
-    local f = open(putt.host, putt.port, putt.create)
-    f:greet()
-    f:login(putt.user, putt.password)
-    if putt.type then f:type(putt.type) end
-    f:pasv()
-    local sent = f:send(putt)
-    f:quit()
-    f:close()
-    return sent
-end
-
-local default = {
-	path = "/",
-	scheme = "ftp"
-}
-
-local function parse(u)
-    local t = socket.try(url.parse(u, default))
-    socket.try(t.scheme == "ftp", "wrong scheme '" .. t.scheme .. "'")
-    socket.try(t.host, "missing hostname")
-    local pat = "^type=(.)$"
-    if t.params then
-        t.type = socket.skip(2, string.find(t.params, pat))
-        socket.try(t.type == "a" or t.type == "i",
-            "invalid type '" .. t.type .. "'")
-    end
-    return t
-end
-
-local function sput(u, body)
-    local putt = parse(u)
-    putt.source = ltn12.source.string(body)
-    return tput(putt)
-end
-
-put = socket.protect(function(putt, body)
-    if base.type(putt) == "string" then return sput(putt, body)
-    else return tput(putt) end
-end)
-
-local function tget(gett)
-    gett = override(gett)
-    socket.try(gett.host, "missing hostname")
-    local f = open(gett.host, gett.port, gett.create)
-    f:greet()
-    f:login(gett.user, gett.password)
-    if gett.type then f:type(gett.type) end
-    f:pasv()
-    f:receive(gett)
-    f:quit()
-    return f:close()
-end
-
-local function sget(u)
-    local gett = parse(u)
-    local t = {}
-    gett.sink = ltn12.sink.table(t)
-    tget(gett)
-    return table.concat(t)
-end
-
-command = socket.protect(function(cmdt)
-    cmdt = override(cmdt)
-    socket.try(cmdt.host, "missing hostname")
-    socket.try(cmdt.command, "missing command")
-    local f = open(cmdt.host, cmdt.port, cmdt.create)
-    f:greet()
-    f:login(cmdt.user, cmdt.password)
-    f.try(f.tp:command(cmdt.command, cmdt.argument))
-    if cmdt.check then f.try(f.tp:check(cmdt.check)) end
-    f:quit()
-    return f:close()
-end)
-
-get = socket.protect(function(gett)
-    if base.type(gett) == "string" then return sget(gett)
-    else return tget(gett) end
-end)
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/socket/http.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,350 +0,0 @@
------------------------------------------------------------------------------
--- HTTP/1.1 client support for the Lua language.
--- LuaSocket toolkit.
--- Author: Diego Nehab
--- RCS ID: $Id: http.lua,v 1.71 2007/10/13 23:55:20 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
--------------------------------------------------------------------------------
-local socket = require("socket")
-local url = require("socket.url")
-local ltn12 = require("ltn12")
-local mime = require("mime")
-local string = require("string")
-local base = _G
-local table = require("table")
-module("socket.http")
-
------------------------------------------------------------------------------
--- Program constants
------------------------------------------------------------------------------
--- connection timeout in seconds
-TIMEOUT = 60
--- default port for document retrieval
-PORT = 80
--- user agent field sent in request
-USERAGENT = socket._VERSION
-
------------------------------------------------------------------------------
--- Reads MIME headers from a connection, unfolding where needed
------------------------------------------------------------------------------
-local function receiveheaders(sock, headers)
-    local line, name, value, err
-    headers = headers or {}
-    -- get first line
-    line, err = sock:receive()
-    if err then return nil, err end
-    -- headers go until a blank line is found
-    while line ~= "" do
-        -- get field-name and value
-        name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
-        if not (name and value) then return nil, "malformed reponse headers" end
-        name = string.lower(name)
-        -- get next line (value might be folded)
-        line, err  = sock:receive()
-        if err then return nil, err end
-        -- unfold any folded values
-        while string.find(line, "^%s") do
-            value = value .. line
-            line = sock:receive()
-            if err then return nil, err end
-        end
-        -- save pair in table
-        if headers[name] then headers[name] = headers[name] .. ", " .. value
-        else headers[name] = value end
-    end
-    return headers
-end
-
------------------------------------------------------------------------------
--- Extra sources and sinks
------------------------------------------------------------------------------
-socket.sourcet["http-chunked"] = function(sock, headers)
-    return base.setmetatable({
-        getfd = function() return sock:getfd() end,
-        dirty = function() return sock:dirty() end
-    }, {
-        __call = function()
-            -- get chunk size, skip extention
-            local line, err = sock:receive()
-            if err then return nil, err end
-            local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
-            if not size then return nil, "invalid chunk size" end
-            -- was it the last chunk?
-            if size > 0 then
-                -- if not, get chunk and skip terminating CRLF
-                local chunk, err, part = sock:receive(size)
-                if chunk then sock:receive() end
-                return chunk, err
-            else
-                -- if it was, read trailers into headers table
-                headers, err = receiveheaders(sock, headers)
-                if not headers then return nil, err end
-            end
-        end
-    })
-end
-
-socket.sinkt["http-chunked"] = function(sock)
-    return base.setmetatable({
-        getfd = function() return sock:getfd() end,
-        dirty = function() return sock:dirty() end
-    }, {
-        __call = function(self, chunk, err)
-            if not chunk then return sock:send("0\r\n\r\n") end
-            local size = string.format("%X\r\n", string.len(chunk))
-            return sock:send(size ..  chunk .. "\r\n")
-        end
-    })
-end
-
------------------------------------------------------------------------------
--- Low level HTTP API
------------------------------------------------------------------------------
-local metat = { __index = {} }
-
-function open(host, port, create)
-    -- create socket with user connect function, or with default
-    local c = socket.try((create or socket.tcp)())
-    local h = base.setmetatable({ c = c }, metat)
-    -- create finalized try
-    h.try = socket.newtry(function() h:close() end)
-    -- set timeout before connecting
-    h.try(c:settimeout(TIMEOUT))
-    h.try(c:connect(host, port or PORT))
-    -- here everything worked
-    return h
-end
-
-function metat.__index:sendrequestline(method, uri)
-    local reqline = string.format("%s %s HTTP/1.1\r\n", method or "GET", uri)
-    return self.try(self.c:send(reqline))
-end
-
-function metat.__index:sendheaders(headers)
-    local h = "\r\n"
-    for i, v in base.pairs(headers) do
-        h = i .. ": " .. v .. "\r\n" .. h
-    end
-    self.try(self.c:send(h))
-    return 1
-end
-
-function metat.__index:sendbody(headers, source, step)
-    source = source or ltn12.source.empty()
-    step = step or ltn12.pump.step
-    -- if we don't know the size in advance, send chunked and hope for the best
-    local mode = "http-chunked"
-    if headers["content-length"] then mode = "keep-open" end
-    return self.try(ltn12.pump.all(source, socket.sink(mode, self.c), step))
-end
-
-function metat.__index:receivestatusline()
-    local status = self.try(self.c:receive(5))
-    -- identify HTTP/0.9 responses, which do not contain a status line
-    -- this is just a heuristic, but is what the RFC recommends
-    if status ~= "HTTP/" then return nil, status end
-    -- otherwise proceed reading a status line
-    status = self.try(self.c:receive("*l", status))
-    local code = socket.skip(2, string.find(status, "HTTP/%d*%.%d* (%d%d%d)"))
-    return self.try(base.tonumber(code), status)
-end
-
-function metat.__index:receiveheaders()
-    return self.try(receiveheaders(self.c))
-end
-
-function metat.__index:receivebody(headers, sink, step)
-    sink = sink or ltn12.sink.null()
-    step = step or ltn12.pump.step
-    local length = base.tonumber(headers["content-length"])
-    local t = headers["transfer-encoding"] -- shortcut
-    local mode = "default" -- connection close
-    if t and t ~= "identity" then mode = "http-chunked"
-    elseif base.tonumber(headers["content-length"]) then mode = "by-length" end
-    return self.try(ltn12.pump.all(socket.source(mode, self.c, length),
-        sink, step))
-end
-
-function metat.__index:receive09body(status, sink, step)
-    local source = ltn12.source.rewind(socket.source("until-closed", self.c))
-    source(status)
-    return self.try(ltn12.pump.all(source, sink, step))
-end
-
-function metat.__index:close()
-    return self.c:close()
-end
-
------------------------------------------------------------------------------
--- High level HTTP API
------------------------------------------------------------------------------
-local function adjusturi(reqt)
-    local u = reqt
-    -- if there is a proxy, we need the full url. otherwise, just a part.
-    if not reqt.proxy and not PROXY then
-        u = {
-           path = socket.try(reqt.path, "invalid path 'nil'"),
-           params = reqt.params,
-           query = reqt.query,
-           fragment = reqt.fragment
-        }
-    end
-    return url.build(u)
-end
-
-local function adjustproxy(reqt)
-    local proxy = reqt.proxy or PROXY
-    if proxy then
-        proxy = url.parse(proxy)
-        return proxy.host, proxy.port or 3128
-    else
-        return reqt.host, reqt.port
-    end
-end
-
-local function adjustheaders(reqt)
-    -- default headers
-    local lower = {
-        ["user-agent"] = USERAGENT,
-        ["host"] = reqt.host,
-        ["connection"] = "close, TE",
-        ["te"] = "trailers"
-    }
-    -- if we have authentication information, pass it along
-    if reqt.user and reqt.password then
-        lower["authorization"] =
-            "Basic " ..  (mime.b64(reqt.user .. ":" .. reqt.password))
-    end
-    -- override with user headers
-    for i,v in base.pairs(reqt.headers or lower) do
-        lower[string.lower(i)] = v
-    end
-    return lower
-end
-
--- default url parts
-local default = {
-    host = "",
-    port = PORT,
-    path ="/",
-    scheme = "http"
-}
-
-local function adjustrequest(reqt)
-    -- parse url if provided
-    local nreqt = reqt.url and url.parse(reqt.url, default) or {}
-    -- explicit components override url
-    for i,v in base.pairs(reqt) do nreqt[i] = v end
-    if nreqt.port == "" then nreqt.port = 80 end
-    socket.try(nreqt.host and nreqt.host ~= "",
-        "invalid host '" .. base.tostring(nreqt.host) .. "'")
-    -- compute uri if user hasn't overriden
-    nreqt.uri = reqt.uri or adjusturi(nreqt)
-    -- ajust host and port if there is a proxy
-    nreqt.host, nreqt.port = adjustproxy(nreqt)
-    -- adjust headers in request
-    nreqt.headers = adjustheaders(nreqt)
-    return nreqt
-end
-
-local function shouldredirect(reqt, code, headers)
-    return headers.location and
-           string.gsub(headers.location, "%s", "") ~= "" and
-           (reqt.redirect ~= false) and
-           (code == 301 or code == 302) and
-           (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
-           and (not reqt.nredirects or reqt.nredirects < 5)
-end
-
-local function shouldreceivebody(reqt, code)
-    if reqt.method == "HEAD" then return nil end
-    if code == 204 or code == 304 then return nil end
-    if code >= 100 and code < 200 then return nil end
-    return 1
-end
-
--- forward declarations
-local trequest, tredirect
-
-function tredirect(reqt, location)
-    local result, code, headers, status = trequest {
-        -- the RFC says the redirect URL has to be absolute, but some
-        -- servers do not respect that
-        url = url.absolute(reqt.url, location),
-        source = reqt.source,
-        sink = reqt.sink,
-        headers = reqt.headers,
-        proxy = reqt.proxy,
-        nredirects = (reqt.nredirects or 0) + 1,
-        create = reqt.create
-    }
-    -- pass location header back as a hint we redirected
-    headers = headers or {}
-    headers.location = headers.location or location
-    return result, code, headers, status
-end
-
-function trequest(reqt)
-    -- we loop until we get what we want, or
-    -- until we are sure there is no way to get it
-    local nreqt = adjustrequest(reqt)
-    local h = open(nreqt.host, nreqt.port, nreqt.create)
-    -- send request line and headers
-    h:sendrequestline(nreqt.method, nreqt.uri)
-    h:sendheaders(nreqt.headers)
-    -- if there is a body, send it
-    if nreqt.source then
-        h:sendbody(nreqt.headers, nreqt.source, nreqt.step)
-    end
-    local code, status = h:receivestatusline()
-    -- if it is an HTTP/0.9 server, simply get the body and we are done
-    if not code then
-        h:receive09body(status, nreqt.sink, nreqt.step)
-        return 1, 200
-    end
-    local headers
-    -- ignore any 100-continue messages
-    while code == 100 do
-        headers = h:receiveheaders()
-        code, status = h:receivestatusline()
-    end
-    headers = h:receiveheaders()
-    -- at this point we should have a honest reply from the server
-    -- we can't redirect if we already used the source, so we report the error
-    if shouldredirect(nreqt, code, headers) and not nreqt.source then
-        h:close()
-        return tredirect(reqt, headers.location)
-    end
-    -- here we are finally done
-    if shouldreceivebody(nreqt, code) then
-        h:receivebody(headers, nreqt.sink, nreqt.step)
-    end
-    h:close()
-    return 1, code, headers, status
-end
-
-local function srequest(u, b)
-    local t = {}
-    local reqt = {
-        url = u,
-        sink = ltn12.sink.table(t)
-    }
-    if b then
-        reqt.source = ltn12.source.string(b)
-        reqt.headers = {
-            ["content-length"] = string.len(b),
-            ["content-type"] = "application/x-www-form-urlencoded"
-        }
-        reqt.method = "POST"
-    end
-    local code, headers, status = socket.skip(1, trequest(reqt))
-    return table.concat(t), code, headers, status
-end
-
-request = socket.protect(function(reqt, body)
-    if base.type(reqt) == "string" then return srequest(reqt, body)
-    else return trequest(reqt) end
-end)
--- a/profiles/dlink.ua.web/files/etc/www/lib/socket/smtp.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,251 +0,0 @@
------------------------------------------------------------------------------
--- SMTP client support for the Lua language.
--- LuaSocket toolkit.
--- Author: Diego Nehab
--- RCS ID: $Id: smtp.lua,v 1.46 2007/03/12 04:08:40 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
------------------------------------------------------------------------------
-local base = _G
-local coroutine = require("coroutine")
-local string = require("string")
-local math = require("math")
-local os = require("os")
-local socket = require("socket")
-local tp = require("socket.tp")
-local ltn12 = require("ltn12")
-local mime = require("mime")
-module("socket.smtp")
-
------------------------------------------------------------------------------
--- Program constants
------------------------------------------------------------------------------
--- timeout for connection
-TIMEOUT = 60
--- default server used to send e-mails
-SERVER = "localhost"
--- default port
-PORT = 25
--- domain used in HELO command and default sendmail
--- If we are under a CGI, try to get from environment
-DOMAIN = os.getenv("SERVER_NAME") or "localhost"
--- default time zone (means we don't know)
-ZONE = "-0000"
-
----------------------------------------------------------------------------
--- Low level SMTP API
------------------------------------------------------------------------------
-local metat = { __index = {} }
-
-function metat.__index:greet(domain)
-    self.try(self.tp:check("2.."))
-    self.try(self.tp:command("EHLO", domain or DOMAIN))
-    return socket.skip(1, self.try(self.tp:check("2..")))
-end
-
-function metat.__index:mail(from)
-    self.try(self.tp:command("MAIL", "FROM:" .. from))
-    return self.try(self.tp:check("2.."))
-end
-
-function metat.__index:rcpt(to)
-    self.try(self.tp:command("RCPT", "TO:" .. to))
-    return self.try(self.tp:check("2.."))
-end
-
-function metat.__index:data(src, step)
-    self.try(self.tp:command("DATA"))
-    self.try(self.tp:check("3.."))
-    self.try(self.tp:source(src, step))
-    self.try(self.tp:send("\r\n.\r\n"))
-    return self.try(self.tp:check("2.."))
-end
-
-function metat.__index:quit()
-    self.try(self.tp:command("QUIT"))
-    return self.try(self.tp:check("2.."))
-end
-
-function metat.__index:close()
-    return self.tp:close()
-end
-
-function metat.__index:login(user, password)
-    self.try(self.tp:command("AUTH", "LOGIN"))
-    self.try(self.tp:check("3.."))
-    self.try(self.tp:command(mime.b64(user)))
-    self.try(self.tp:check("3.."))
-    self.try(self.tp:command(mime.b64(password)))
-    return self.try(self.tp:check("2.."))
-end
-
-function metat.__index:plain(user, password)
-    local auth = "PLAIN " .. mime.b64("\0" .. user .. "\0" .. password)
-    self.try(self.tp:command("AUTH", auth))
-    return self.try(self.tp:check("2.."))
-end
-
-function metat.__index:auth(user, password, ext)
-    if not user or not password then return 1 end
-    if string.find(ext, "AUTH[^\n]+LOGIN") then
-        return self:login(user, password)
-    elseif string.find(ext, "AUTH[^\n]+PLAIN") then
-        return self:plain(user, password)
-    else
-        self.try(nil, "authentication not supported")
-    end
-end
-
--- send message or throw an exception
-function metat.__index:send(mailt)
-    self:mail(mailt.from)
-    if base.type(mailt.rcpt) == "table" then
-        for i,v in base.ipairs(mailt.rcpt) do
-            self:rcpt(v)
-        end
-    else
-        self:rcpt(mailt.rcpt)
-    end
-    self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step)
-end
-
-function open(server, port, create)
-    local tp = socket.try(tp.connect(server or SERVER, port or PORT,
-        TIMEOUT, create))
-    local s = base.setmetatable({tp = tp}, metat)
-    -- make sure tp is closed if we get an exception
-    s.try = socket.newtry(function()
-        s:close()
-    end)
-    return s
-end
-
--- convert headers to lowercase
-local function lower_headers(headers)
-    local lower = {}
-    for i,v in base.pairs(headers or lower) do
-        lower[string.lower(i)] = v
-    end
-    return lower
-end
-
----------------------------------------------------------------------------
--- Multipart message source
------------------------------------------------------------------------------
--- returns a hopefully unique mime boundary
-local seqno = 0
-local function newboundary()
-    seqno = seqno + 1
-    return string.format('%s%05d==%05u', os.date('%d%m%Y%H%M%S'),
-        math.random(0, 99999), seqno)
-end
-
--- send_message forward declaration
-local send_message
-
--- yield the headers all at once, it's faster
-local function send_headers(headers)
-    local h = "\r\n"
-    for i,v in base.pairs(headers) do
-        h = i .. ': ' .. v .. "\r\n" .. h
-    end
-    coroutine.yield(h)
-end
-
--- yield multipart message body from a multipart message table
-local function send_multipart(mesgt)
-    -- make sure we have our boundary and send headers
-    local bd = newboundary()
-    local headers = lower_headers(mesgt.headers or {})
-    headers['content-type'] = headers['content-type'] or 'multipart/mixed'
-    headers['content-type'] = headers['content-type'] ..
-        '; boundary="' ..  bd .. '"'
-    send_headers(headers)
-    -- send preamble
-    if mesgt.body.preamble then
-        coroutine.yield(mesgt.body.preamble)
-        coroutine.yield("\r\n")
-    end
-    -- send each part separated by a boundary
-    for i, m in base.ipairs(mesgt.body) do
-        coroutine.yield("\r\n--" .. bd .. "\r\n")
-        send_message(m)
-    end
-    -- send last boundary
-    coroutine.yield("\r\n--" .. bd .. "--\r\n\r\n")
-    -- send epilogue
-    if mesgt.body.epilogue then
-        coroutine.yield(mesgt.body.epilogue)
-        coroutine.yield("\r\n")
-    end
-end
-
--- yield message body from a source
-local function send_source(mesgt)
-    -- make sure we have a content-type
-    local headers = lower_headers(mesgt.headers or {})
-    headers['content-type'] = headers['content-type'] or
-        'text/plain; charset="iso-8859-1"'
-    send_headers(headers)
-    -- send body from source
-    while true do
-        local chunk, err = mesgt.body()
-        if err then coroutine.yield(nil, err)
-        elseif chunk then coroutine.yield(chunk)
-        else break end
-    end
-end
-
--- yield message body from a string
-local function send_string(mesgt)
-    -- make sure we have a content-type
-    local headers = lower_headers(mesgt.headers or {})
-    headers['content-type'] = headers['content-type'] or
-        'text/plain; charset="iso-8859-1"'
-    send_headers(headers)
-    -- send body from string
-    coroutine.yield(mesgt.body)
-end
-
--- message source
-function send_message(mesgt)
-    if base.type(mesgt.body) == "table" then send_multipart(mesgt)
-    elseif base.type(mesgt.body) == "function" then send_source(mesgt)
-    else send_string(mesgt) end
-end
-
--- set defaul headers
-local function adjust_headers(mesgt)
-    local lower = lower_headers(mesgt.headers)
-    lower["date"] = lower["date"] or
-        os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE)
-    lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
-    -- this can't be overriden
-    lower["mime-version"] = "1.0"
-    return lower
-end
-
-function message(mesgt)
-    mesgt.headers = adjust_headers(mesgt)
-    -- create and return message source
-    local co = coroutine.create(function() send_message(mesgt) end)
-    return function()
-        local ret, a, b = coroutine.resume(co)
-        if ret then return a, b
-        else return nil, a end
-    end
-end
-
----------------------------------------------------------------------------
--- High level SMTP API
------------------------------------------------------------------------------
-send = socket.protect(function(mailt)
-    local s = open(mailt.server, mailt.port, mailt.create)
-    local ext = s:greet(mailt.domain)
-    s:auth(mailt.user, mailt.password, ext)
-    s:send(mailt)
-    s:quit()
-    return s:close()
-end)
--- a/profiles/dlink.ua.web/files/etc/www/lib/socket/tp.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
------------------------------------------------------------------------------
--- Unified SMTP/FTP subsystem
--- LuaSocket toolkit.
--- Author: Diego Nehab
--- RCS ID: $Id: tp.lua,v 1.22 2006/03/14 09:04:15 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
------------------------------------------------------------------------------
-local base = _G
-local string = require("string")
-local socket = require("socket")
-local ltn12 = require("ltn12")
-module("socket.tp")
-
------------------------------------------------------------------------------
--- Program constants
------------------------------------------------------------------------------
-TIMEOUT = 60
-
------------------------------------------------------------------------------
--- Implementation
------------------------------------------------------------------------------
--- gets server reply (works for SMTP and FTP)
-local function get_reply(c)
-    local code, current, sep
-    local line, err = c:receive()
-    local reply = line
-    if err then return nil, err end
-    code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
-    if not code then return nil, "invalid server reply" end
-    if sep == "-" then -- reply is multiline
-        repeat
-            line, err = c:receive()
-            if err then return nil, err end
-            current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
-            reply = reply .. "\n" .. line
-        -- reply ends with same code
-        until code == current and sep == " "
-    end
-    return code, reply
-end
-
--- metatable for sock object
-local metat = { __index = {} }
-
-function metat.__index:check(ok)
-    local code, reply = get_reply(self.c)
-    if not code then return nil, reply end
-    if base.type(ok) ~= "function" then
-        if base.type(ok) == "table" then
-            for i, v in base.ipairs(ok) do
-                if string.find(code, v) then
-                    return base.tonumber(code), reply
-                end
-            end
-            return nil, reply
-        else
-            if string.find(code, ok) then return base.tonumber(code), reply
-            else return nil, reply end
-        end
-    else return ok(base.tonumber(code), reply) end
-end
-
-function metat.__index:command(cmd, arg)
-    if arg then
-        return self.c:send(cmd .. " " .. arg.. "\r\n")
-    else
-        return self.c:send(cmd .. "\r\n")
-    end
-end
-
-function metat.__index:sink(snk, pat)
-    local chunk, err = c:receive(pat)
-    return snk(chunk, err)
-end
-
-function metat.__index:send(data)
-    return self.c:send(data)
-end
-
-function metat.__index:receive(pat)
-    return self.c:receive(pat)
-end
-
-function metat.__index:getfd()
-    return self.c:getfd()
-end
-
-function metat.__index:dirty()
-    return self.c:dirty()
-end
-
-function metat.__index:getcontrol()
-    return self.c
-end
-
-function metat.__index:source(source, step)
-    local sink = socket.sink("keep-open", self.c)
-    local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step)
-    return ret, err
-end
-
--- closes the underlying c
-function metat.__index:close()
-    self.c:close()
-	return 1
-end
-
--- connect with server and return c object
-function connect(host, port, timeout, create)
-    local c, e = (create or socket.tcp)()
-    if not c then return nil, e end
-    c:settimeout(timeout or TIMEOUT)
-    local r, e = c:connect(host, port)
-    if not r then
-        c:close()
-        return nil, e
-    end
-    return base.setmetatable({c = c}, metat)
-end
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/socket/url.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,297 +0,0 @@
------------------------------------------------------------------------------
--- URI parsing, composition and relative URL resolution
--- LuaSocket toolkit.
--- Author: Diego Nehab
--- RCS ID: $Id: url.lua,v 1.38 2006/04/03 04:45:42 diego Exp $
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module
------------------------------------------------------------------------------
-local string = require("string")
-local base = _G
-local table = require("table")
-module("socket.url")
-
------------------------------------------------------------------------------
--- Module version
------------------------------------------------------------------------------
-_VERSION = "URL 1.0.1"
-
------------------------------------------------------------------------------
--- Encodes a string into its escaped hexadecimal representation
--- Input
---   s: binary string to be encoded
--- Returns
---   escaped representation of string binary
------------------------------------------------------------------------------
-function escape(s)
-    return string.gsub(s, "([^A-Za-z0-9_])", function(c)
-        return string.format("%%%02x", string.byte(c))
-    end)
-end
-
------------------------------------------------------------------------------
--- Protects a path segment, to prevent it from interfering with the
--- url parsing.
--- Input
---   s: binary string to be encoded
--- Returns
---   escaped representation of string binary
------------------------------------------------------------------------------
-local function make_set(t)
-	local s = {}
-	for i,v in base.ipairs(t) do
-		s[t[i]] = 1
-	end
-	return s
-end
-
--- these are allowed withing a path segment, along with alphanum
--- other characters must be escaped
-local segment_set = make_set {
-    "-", "_", ".", "!", "~", "*", "'", "(",
-	")", ":", "@", "&", "=", "+", "$", ",",
-}
-
-local function protect_segment(s)
-	return string.gsub(s, "([^A-Za-z0-9_])", function (c)
-		if segment_set[c] then return c
-		else return string.format("%%%02x", string.byte(c)) end
-	end)
-end
-
------------------------------------------------------------------------------
--- Encodes a string into its escaped hexadecimal representation
--- Input
---   s: binary string to be encoded
--- Returns
---   escaped representation of string binary
------------------------------------------------------------------------------
-function unescape(s)
-    return string.gsub(s, "%%(%x%x)", function(hex)
-        return string.char(base.tonumber(hex, 16))
-    end)
-end
-
------------------------------------------------------------------------------
--- Builds a path from a base path and a relative path
--- Input
---   base_path
---   relative_path
--- Returns
---   corresponding absolute path
------------------------------------------------------------------------------
-local function absolute_path(base_path, relative_path)
-    if string.sub(relative_path, 1, 1) == "/" then return relative_path end
-    local path = string.gsub(base_path, "[^/]*$", "")
-    path = path .. relative_path
-    path = string.gsub(path, "([^/]*%./)", function (s)
-        if s ~= "./" then return s else return "" end
-    end)
-    path = string.gsub(path, "/%.$", "/")
-    local reduced
-    while reduced ~= path do
-        reduced = path
-        path = string.gsub(reduced, "([^/]*/%.%./)", function (s)
-            if s ~= "../../" then return "" else return s end
-        end)
-    end
-    path = string.gsub(reduced, "([^/]*/%.%.)$", function (s)
-        if s ~= "../.." then return "" else return s end
-    end)
-    return path
-end
-
------------------------------------------------------------------------------
--- Parses a url and returns a table with all its parts according to RFC 2396
--- The following grammar describes the names given to the URL parts
--- <url> ::= <scheme>://<authority>/<path>;<params>?<query>#<fragment>
--- <authority> ::= <userinfo>@<host>:<port>
--- <userinfo> ::= <user>[:<password>]
--- <path> :: = {<segment>/}<segment>
--- Input
---   url: uniform resource locator of request
---   default: table with default values for each field
--- Returns
---   table with the following fields, where RFC naming conventions have
---   been preserved:
---     scheme, authority, userinfo, user, password, host, port,
---     path, params, query, fragment
--- Obs:
---   the leading '/' in {/<path>} is considered part of <path>
------------------------------------------------------------------------------
-function parse(url, default)
-    -- initialize default parameters
-    local parsed = {}
-    for i,v in base.pairs(default or parsed) do parsed[i] = v end
-    -- empty url is parsed to nil
-    if not url or url == "" then return nil, "invalid url" end
-    -- remove whitespace
-    -- url = string.gsub(url, "%s", "")
-    -- get fragment
-    url = string.gsub(url, "#(.*)$", function(f)
-        parsed.fragment = f
-        return ""
-    end)
-    -- get scheme
-    url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
-        function(s) parsed.scheme = s; return "" end)
-    -- get authority
-    url = string.gsub(url, "^//([^/]*)", function(n)
-        parsed.authority = n
-        return ""
-    end)
-    -- get query stringing
-    url = string.gsub(url, "%?(.*)", function(q)
-        parsed.query = q
-        return ""
-    end)
-    -- get params
-    url = string.gsub(url, "%;(.*)", function(p)
-        parsed.params = p
-        return ""
-    end)
-    -- path is whatever was left
-    if url ~= "" then parsed.path = url end
-    local authority = parsed.authority
-    if not authority then return parsed end
-    authority = string.gsub(authority,"^([^@]*)@",
-        function(u) parsed.userinfo = u; return "" end)
-    authority = string.gsub(authority, ":([^:]*)$",
-        function(p) parsed.port = p; return "" end)
-    if authority ~= "" then parsed.host = authority end
-    local userinfo = parsed.userinfo
-    if not userinfo then return parsed end
-    userinfo = string.gsub(userinfo, ":([^:]*)$",
-        function(p) parsed.password = p; return "" end)
-    parsed.user = userinfo
-    return parsed
-end
-
------------------------------------------------------------------------------
--- Rebuilds a parsed URL from its components.
--- Components are protected if any reserved or unallowed characters are found
--- Input
---   parsed: parsed URL, as returned by parse
--- Returns
---   a stringing with the corresponding URL
------------------------------------------------------------------------------
-function build(parsed)
-    local ppath = parse_path(parsed.path or "")
-    local url = build_path(ppath)
-    if parsed.params then url = url .. ";" .. parsed.params end
-    if parsed.query then url = url .. "?" .. parsed.query end
-	local authority = parsed.authority
-	if parsed.host then
-		authority = parsed.host
-		if parsed.port then authority = authority .. ":" .. parsed.port end
-		local userinfo = parsed.userinfo
-		if parsed.user then
-			userinfo = parsed.user
-			if parsed.password then
-				userinfo = userinfo .. ":" .. parsed.password
-			end
-		end
-		if userinfo then authority = userinfo .. "@" .. authority end
-	end
-    if authority then url = "//" .. authority .. url end
-    if parsed.scheme then url = parsed.scheme .. ":" .. url end
-    if parsed.fragment then url = url .. "#" .. parsed.fragment end
-    -- url = string.gsub(url, "%s", "")
-    return url
-end
-
------------------------------------------------------------------------------
--- Builds a absolute URL from a base and a relative URL according to RFC 2396
--- Input
---   base_url
---   relative_url
--- Returns
---   corresponding absolute url
------------------------------------------------------------------------------
-function absolute(base_url, relative_url)
-    if base.type(base_url) == "table" then
-        base_parsed = base_url
-        base_url = build(base_parsed)
-    else
-        base_parsed = parse(base_url)
-    end
-    local relative_parsed = parse(relative_url)
-    if not base_parsed then return relative_url
-    elseif not relative_parsed then return base_url
-    elseif relative_parsed.scheme then return relative_url
-    else
-        relative_parsed.scheme = base_parsed.scheme
-        if not relative_parsed.authority then
-            relative_parsed.authority = base_parsed.authority
-            if not relative_parsed.path then
-                relative_parsed.path = base_parsed.path
-                if not relative_parsed.params then
-                    relative_parsed.params = base_parsed.params
-                    if not relative_parsed.query then
-                        relative_parsed.query = base_parsed.query
-                    end
-                end
-            else
-                relative_parsed.path = absolute_path(base_parsed.path or "",
-                    relative_parsed.path)
-            end
-        end
-        return build(relative_parsed)
-    end
-end
-
------------------------------------------------------------------------------
--- Breaks a path into its segments, unescaping the segments
--- Input
---   path
--- Returns
---   segment: a table with one entry per segment
------------------------------------------------------------------------------
-function parse_path(path)
-	local parsed = {}
-	path = path or ""
-	--path = string.gsub(path, "%s", "")
-	string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end)
-	for i = 1, table.getn(parsed) do
-		parsed[i] = unescape(parsed[i])
-	end
-	if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end
-	if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end
-	return parsed
-end
-
------------------------------------------------------------------------------
--- Builds a path component from its segments, escaping protected characters.
--- Input
---   parsed: path segments
---   unsafe: if true, segments are not protected before path is built
--- Returns
---   path: corresponding path stringing
------------------------------------------------------------------------------
-function build_path(parsed, unsafe)
-	local path = ""
-	local n = table.getn(parsed)
-	if unsafe then
-		for i = 1, n-1 do
-			path = path .. parsed[i]
-			path = path .. "/"
-		end
-		if n > 0 then
-			path = path .. parsed[n]
-			if parsed.is_directory then path = path .. "/" end
-		end
-	else
-		for i = 1, n-1 do
-			path = path .. protect_segment(parsed[i])
-			path = path .. "/"
-		end
-		if n > 0 then
-			path = path .. protect_segment(parsed[n])
-			if parsed.is_directory then path = path .. "/" end
-		end
-	end
-	if parsed.is_absolute then path = "/" .. path end
-	return path
-end
--- a/profiles/dlink.ua.web/files/etc/www/lib/table.save-0.94.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,183 +0,0 @@
---[[
-	Save Table to File/Stringtable
-	Load Table from File/Stringtable
-	v 0.94
-
-	Lua 5.1 compatible
-
-	Userdata and indices of these are not saved
-	Functions are saved via string.dump, so make sure it has no upvalues
-	References are saved
-	----------------------------------------------------
-	table.save( table [, filename] )
-
-	Saves a table so it can be called via the table.load function again
-	table must a object of type 'table'
-	filename is optional, and may be a string representing a filename or true/1
-
-	table.save( table )
-		on success: returns a string representing the table (stringtable)
-		(uses a string as buffer, ideal for smaller tables)
-	table.save( table, true or 1 )
-		on success: returns a string representing the table (stringtable)
-		(uses io.tmpfile() as buffer, ideal for bigger tables)
-	table.save( table, "filename" )
-		on success: returns 1
-		(saves the table to file "filename")
-	on failure: returns as second argument an error msg
-	----------------------------------------------------
-	table.load( filename or stringtable )
-
-	Loads a table that has been saved via the table.save function
-
-	on success: returns a previously saved table
-	on failure: returns as second argument an error msg
-	----------------------------------------------------
-
-	chillcode, http://lua-users.org/wiki/SaveTableToFile
-	Licensed under the same terms as Lua itself.
-]]--
-do
-	-- declare local variables
-	--// exportstring( string )
-	--// returns a "Lua" portable version of the string
-	local function exportstring( s )
-		s = string.format( "%q",s )
-		-- to replace
-		s = string.gsub( s,"\\\n","\\n" )
-		s = string.gsub( s,"\r","\\r" )
-		s = string.gsub( s,string.char(26),"\"..string.char(26)..\"" )
-		return s
-	end
-
-	--// The Save Function
-	function table.save(  tbl,filename )
-		local charS,charE = "   ","\n"
-		local file,err
-		-- create a pseudo file that writes to a string and return the string
-		if not filename then
-			file =  { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
-			charS,charE = "",""
-		-- write table to tmpfile
-		elseif filename == true or filename == 1 then
-			charS,charE,file = "","",io.tmpfile()
-		-- write table to file
-		-- use io.open here rather than io.output, since in windows when clicking on a file opened with io.output will create an error
-		else
-			file,err = io.open( filename, "w" )
-			if err then return _,err end
-		end
-		-- initiate variables for save procedure
-		local tables,lookup = { tbl },{ [tbl] = 1 }
-		file:write( "return {"..charE )
-		for idx,t in ipairs( tables ) do
-			if filename and filename ~= true and filename ~= 1 then
-				file:write( "-- Table: {"..idx.."}"..charE )
-			end
-			file:write( "{"..charE )
-			local thandled = {}
-			for i,v in ipairs( t ) do
-				thandled[i] = true
-				-- escape functions and userdata
-				if type( v ) ~= "userdata" then
-					-- only handle value
-					if type( v ) == "table" then
-						if not lookup[v] then
-							table.insert( tables, v )
-							lookup[v] = #tables
-						end
-						file:write( charS.."{"..lookup[v].."},"..charE )
-					elseif type( v ) == "function" then
-						file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
-					else
-						local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
-						file:write(  charS..value..","..charE )
-					end
-				end
-			end
-			for i,v in pairs( t ) do
-				-- escape functions and userdata
-				if (not thandled[i]) and type( v ) ~= "userdata" then
-					-- handle index
-					if type( i ) == "table" then
-						if not lookup[i] then
-							table.insert( tables,i )
-							lookup[i] = #tables
-						end
-						file:write( charS.."[{"..lookup[i].."}]=" )
-					else
-						local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
-						file:write( charS..index.."=" )
-					end
-					-- handle value
-					if type( v ) == "table" then
-						if not lookup[v] then
-							table.insert( tables,v )
-							lookup[v] = #tables
-						end
-						file:write( "{"..lookup[v].."},"..charE )
-					elseif type( v ) == "function" then
-						file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
-					else
-						local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
-						file:write( value..","..charE )
-					end
-				end
-			end
-			file:write( "},"..charE )
-		end
-		file:write( "}" )
-		-- Return Values
-		-- return stringtable from string
-		if not filename then
-			-- set marker for stringtable
-			return file.str.."--|"
-		-- return stringttable from file
-		elseif filename == true or filename == 1 then
-			file:seek ( "set" )
-			-- no need to close file, it gets closed and removed automatically
-			-- set marker for stringtable
-			return file:read( "*a" ).."--|"
-		-- close file and return 1
-		else
-			file:close()
-			return 1
-		end
-	end
-
-	--// The Load Function
-	function table.load( sfile )
-		-- catch marker for stringtable
-		if string.sub( sfile,-3,-1 ) == "--|" then
-			tables,err = loadstring( sfile )
-		else
-			tables,err = loadfile( sfile )
-		end
-
-		if err then return _,err end
-
-		tables = tables()
-
-		for idx = 1,#tables do
-			local tolinkv,tolinki = {},{}
-			for i,v in pairs( tables[idx] ) do
-				if type( v ) == "table" and tables[v[1]] then
-					table.insert( tolinkv,{ i,tables[v[1]] } )
-				end
-				if type( i ) == "table" and tables[i[1]] then
-					table.insert( tolinki,{ i,tables[i[1]] } )
-				end
-			end
-			-- link values, first due to possible changes of indices
-			for _,v in ipairs( tolinkv ) do
-				tables[idx][v[1]] = v[2]
-			end
-			-- link indices
-			for _,v in ipairs( tolinki ) do
-				tables[idx][v[2]],tables[idx][v[1]] =  tables[idx][v[1]],nil
-			end
-		end
-		return tables[1]
-	end
-	-- close do
-end
--- a/profiles/dlink.ua.web/files/etc/www/lib/test.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-
-require("ipcalc");
-
-
-print(string.format("hasbit(%08x, %08x) = %s", 0x12345678, 0x00001000, tostring(hasbit(0x12345678, 0x00004000))));
-
-print(string.format("(%08x & %08x) = %08x", 0x12345678, 0xfffff000, andL(0x12345678, 0x000fffff)));
-
-m =13
-print(string.format("%d  netmask=%08x hostmask=%08x", m, bits_to_netmask(m), bits_to_hostmask(m)));
-
-require("ipcalc");
-
-local r = cidr_to_net("213.130.11.129/23");
-
-
---[[
-r.host	0.0.1.129
-r.bits	23
-r.broadcast	213.130.11.255
-r.net	213.130.10.0
-r.mask	255.255.254.0
-r.ip	213.130.11.129
-r.cidr	213.130.11.129/23
-]]
-
-
-
-
-
-
--- a/profiles/dlink.ua.web/files/etc/www/lib/utils.lua	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/files/etc/www/lib/utils.lua	Thu Sep 20 15:21:29 2012 +0300
@@ -167,7 +167,7 @@
 		"        <h4>" .. header .."</h4>\n" ..
 		"    </div>\n" ..
 		"    <div class=\"yui3-bd\">\n" ..
-		"	<form method=\"POST\" target=\"/cmd.xml\">\n" ..
+		"	<form method=\"POST\" target=\"/cmd.xml\" onchange=\"document.getElementById('" .. id .. "_update_button').disabled = false; return true;\">\n" ..
 		"	    <input type=\"hidden\" name=\"path\" value=\"" .. rootpath .."\" />\n" ..
 		"	    <input type=\"hidden\" name=\"cmd\" value=\"setmany\" />\n" ..
 		"	<table>\n";
@@ -189,7 +189,8 @@
 		    ret = ret .. "Error parsing attr fileld at path " .. v.node;
 		else
 
-		attrvalue = c:getNode(nodestr):attr(attrstr) or "Error getting attribute value of " .. nodestr .. ":attr(" .. attrstr .. ")";
+		attrvalue = c:getNode(nodestr):attr(attrstr) or
+		    "Error getting attribute value of " .. nodestr .. ":attr(" .. attrstr .. ")";
 		local inserted = "";
 		if v.htmltype == "checkbox" then
 		    inserted = checked(attrvalue);
@@ -201,9 +202,13 @@
 		ret = ret ..
 		"            <tr>\n" ..
 		"        	<td>" .. v.label .. ":</td>\n" ..
-		"        	<td><input name=\"smattr:" .. v.node .. "\" type=\"" .. v.htmltype .. "\" " ..
+		"        	<td><input name=\"smattr:" .. v.node .. "\" " ..
+				    "type=\"" .. v.htmltype .. "\" " ..
 				    inserted ..
-				    "></td>\n" ..
+				    " onchange=\"" ..
+					"document.getElementById(" .. 
+					    "'" .. id .. "_update_button'" ..
+					").disabled = false; return true;\"/></td>\n" ..
 		"    	     </tr>\n";
 		end
 	    elseif v.type == "node" then
@@ -221,12 +226,16 @@
 		    nodevalue = "Error: node " .. nodestr .. " not found";
 		end
 
+		nodevalue = nodevalue:gsub("\"","&quot;");
+
 		ret = ret ..
 		"            <tr>\n" ..
 		"        	<td>" .. v.label .. ":</td>\n" ..
 		"    		<td><input type=\"" .. v.htmltype .. "\" name=\"sm:" .. v.node .. "\" value=\"" ..
 				    nodevalue ..
-				    "\"/></td>\n" ..
+				    "\" onchange=\"document.getElementById(" ..
+					"'" .. id .. "_update_button'" ..
+				    ").disabled = false; return true;\"/></td>\n" ..
 		"            </tr>\n";
 	    end
 	end
@@ -234,7 +243,9 @@
 	ret = ret ..
 		"            <tr>\n" ..
 		"        	<td>&nbsp;</td>\n" ..
-		"        	<td><input type=\"button\" name=\"Update\" value=\"Update\" onclick=\"send_update(this.form)\"/></td>\n" ..
+		"        	<td><input id=\"" .. id .. "_update_button\" type=\"button\" name=\"Update\" value=\"Update\" disabled onclick=\"" ..
+					"send_update(this.form, function(x) { document.getElementById('" .. id .. "_update_button').disabled = true; })" ..
+				    "\"/></td>\n" ..
 		"            </tr>\n" ..
 		"	</table>\n" ..
 		"	</form>\n" ..
@@ -244,4 +255,74 @@
 	return (ret);
 end
 
+function peritem(item, sub)
+	if type(item) == "table" then
 
+    		for k, v in pairs(item) do
+    			sub(v);
+    		end
+	else
+    		sub(item);
+	end
+end
+
+function kldload(module)
+	function kldload_one(module)
+		if debug then
+			print("kldstat -q -m " .. module .. " || kldload " .. module);
+		end
+		os.execute("kldstat -q -m " .. module .. " || kldload " .. module);
+	end
+	peritem(module, kldload_one);
+end
+
+function strip_quote (str)
+	str = str:gsub("^\"(.*)\"$", "%1");
+	str = str:gsub("^\'(.*)\'$", "%1");
+	return str;
+end
+
+function parse_kv_file (ar, file)
+	local err = nil;
+	if not file then
+		return "Filename required";
+	end
+
+	if type(ar) ~= "table" then
+		return "First argument must be table";
+	end
+
+	local f = io.open(file);
+	if not f then
+		return "Can't open \"" .. file .. "\"\n";
+	end
+
+	local count = 0;
+	while true do
+		local line = f:read('*line');
+		if line == nil then break end -- EOF
+		if count > 100 then
+			-- to much lines
+			err = "Lines count more than 100 \"" .. file .. "\n";
+			break;
+		end
+
+		line = line:gsub("#.*$", ""); -- Strip comments
+		line = line:gsub("%s*$", ""); -- Strip whitespaces
+
+		if line ~= "" then -- Do only if line not empty
+			match, _, name, value = line:find("^(.+)=(.+)%s*$");
+			if not match then
+				err = "Wrong format in \"" .. file .. "\n";
+				break;
+			end
+			ar[strip_quote(name)] = strip_quote(value);
+		end
+
+		count = count + 1;
+	end
+
+	f:close();
+	return err;
+end
+
--- a/profiles/dlink.ua.web/files/etc/www/lib/xml.lua	Thu Sep 20 13:05:46 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,472 +0,0 @@
----
---  Overview:
---  =========
---
---      This module provides a non-validating XML stream parser in Lua.
---
---  Features:
---  =========
---
---      * Tokenises well-formed XML (relatively robustly)
---      * Flexible handler based event api (see below)
---      * Parses all XML Infoset elements - ie.
---          - Tags
---          - Text
---          - Comments
---          - CDATA
---          - XML Decl
---          - Processing Instructions
---          - DOCTYPE declarations
---      * Provides limited well-formedness checking
---        (checks for basic syntax & balanced tags only)
---      * Flexible whitespace handling (selectable)
---      * Entity Handling (selectable)
---
---  Limitations:
---  ============
---
---      * Non-validating
---      * No charset handling
---      * No namespace support
---      * Shallow well-formedness checking only (fails
---        to detect most semantic errors)
---
---  API:
---  ====
---
---  The parser provides a partially object-oriented API with
---  functionality split into tokeniser and hanlder components.
---
---  The handler instance is passed to the tokeniser and receives
---  callbacks for each XML element processed (if a suitable handler
---  function is defined). The API is conceptually similar to the
---  SAX API but implemented differently.
---
---  The following events are generated by the tokeniser
---
---      handler:start       - Start Tag
---      handler:end         - End Tag
---      handler:text        - Text
---      handler:decl        - XML Declaration
---      handler:pi          - Processing Instruction
---      handler:comment     - Comment
---      handler:dtd         - DOCTYPE definition
---      handler:cdata       - CDATA
---
---  The function prototype for all the callback functions is
---
---      callback(val,attrs,start,end)
---
---  where attrs is a table and val/attrs are overloaded for
---  specific callbacks - ie.
---
---      Callback     val            attrs (table)
---      --------     ---            -------------
---      start        name           { attributes (name=val).. }
---      end          name           nil
---      text         <text>         nil
---      cdata        <text>         nil
---      decl         "xml"          { attributes (name=val).. }
---      pi           pi name        { attributes (if present)..
---                                    _text = <PI Text>
---                                  }
---      comment      <text>         nil
---      dtd          root element   { _root = <Root Element>,
---                                    _type = SYSTEM|PUBLIC,
---                                    _name = <name>,
---                                    _uri = <uri>,
---                                    _internal = <internal dtd>
---                                  }
---
---  (start & end provide the character positions of the start/end
---  of the element)
---
---  XML data is passed to the parser instance through the 'parse'
---  method (Nore: must be passed a single string currently)
---
---  Options
---  =======
---
---  Parser options are controlled through the 'self.options' table.
---  Available options are -
---
---      * stripWS
---
---        Strip non-significant whitespace (leading/trailing)
---        and do not generate events for empty text elements
---
---      * expandEntities
---
---        Expand entities (standard entities + single char
---        numeric entities only currently - could be extended
---        at runtime if suitable DTD parser added elements
---        to table (see obj._ENTITIES). May also be possible
---        to expand multibyre entities for UTF-8 only
---
---      * errorHandler
---
---        Custom error handler function
---
---  NOTE: Boolean options must be set to 'nil' not '0'
---
---  Usage
---  =====
---
---  Create a handler instance -
---
---      h = { start = function(t,a,s,e) .... end,
---            end = function(t,a,s,e) .... end,
---            text = function(t,a,s,e) .... end,
---            cdata = text }
---
---  (or use predefined handler - see handler.lua)
---
---  Create parser instance -
---
---      p = xmlParser(h)
---
---  Set options -
---
---      p.options.xxxx = nil
---
---  Parse XML data -
---
---      xmlParser:parse("<?xml... ")
---  License:
---  ========
---
---      This code is freely distributable under the terms of the Lua license
---      (http://www.lua.org/copyright.html)
---
---  History
---  =======
---  Added parameter parseAttributes (boolean) in xmlParser.parse method
---  If true, tag attributtes are parsed. The default value is true.
---  by Manoel Campos (http://manoelcampos.com)
---
---  $Id: xml.lua,v 1.1.1.1 2001/11/28 06:11:33 paulc Exp $
---
---  $Log: xml.lua,v $
---  Revision 1.1.1.1  2001/11/28 06:11:33  paulc
---  Initial Import
---
[email protected] Paul Chakravarti ([email protected])<p/>
-
-
----Parses a XML string
[email protected] handler Handler object to be used to convert the XML string
---to another formats. @see handler.lua
-xmlParser = function(handler)
-    local obj = {}
-    -- Public attributes
-
-    obj.options = {
-                    stripWS = 1,
-                    expandEntities = 1,
-                    errorHandler = function(err,pos)
-                                       error(format("%s [char=%d]\n",
-                                               err or "Parse Error",pos))
-                                   end,
-                  }
-
-    -- Public methods
-
-    obj.parse = function(self, str, parseAttributes)
-	    if parseAttributes == nil then
-	       parseAttributes = true
-	    end
-	    self._handler.parseAttributes = parseAttributes
-
-        local match,endmatch,pos = 0,0,1
-        local text,endt1,endt2,tagstr,tagname,attrs,starttext,endtext
-        local errstart,errend,extstart,extend
-        while match do
-            -- Get next tag (first pass - fix exceptions below)
-            match,endmatch,text,endt1,tagstr,endt2 = string.find(str,self._XML,pos)
-            if not match then
-                if string.find(str,self._WS,pos) then
-                    -- No more text - check document complete
-                    if table.getn(self._stack) ~= 0 then
-                        self:_err(self._errstr.incompleteXmlErr,pos)
-                    else
-                        break
-                    end
-                else
-                    -- Unparsable text
-                    self:_err(self._errstr.xmlErr,pos)
-                end
-            end
-            -- Handle leading text
-            starttext = match
-            endtext = match + string.len(text) - 1
-            match = match + string.len(text)
-            text = self:_parseEntities(self:_stripWS(text))
-            if text ~= "" and self._handler.text then
-                self._handler:text(text,nil,match,endtext)
-            end
-            -- Test for tag type
-            if string.find(string.sub(tagstr,1,5),"?xml%s") then
-                -- XML Declaration
-                match,endmatch,text = string.find(str,self._PI,pos)
-                if not match then
-                    self:_err(self._errstr.declErr,pos)
-                end
-                if match ~= 1 then
-                    -- Must be at start of doc if present
-                    self:_err(self._errstr.declStartErr,pos)
-                end
-                tagname,attrs = self:_parseTag(text)
-                -- TODO: Check attributes are valid
-                -- Check for version (mandatory)
-                if attrs.version == nil then
-                    self:_err(self._errstr.declAttrErr,pos)
-                end
-                if self._handler.decl then
-                    self._handler:decl(tagname,attrs,match,endmatch)
-                end
-            elseif string.sub(tagstr,1,1) == "?" then
-                -- Processing Instruction
-                match,endmatch,text = string.find(str,self._PI,pos)
-                if not match then
-                    self:_err(self._errstr.piErr,pos)
-                end
-                if self._handler.pi then
-                    -- Parse PI attributes & text
-                    tagname,attrs = self:_parseTag(text)
-                    local pi = string.sub(text,string.len(tagname)+1)
-                    if pi ~= "" then
-                        if attrs then
-                            attrs._text = pi
-                        else
-                            attrs = { _text = pi }
-                        end
-                    end
-                    self._handler:pi(tagname,attrs,match,endmatch)
-                end
-            elseif string.sub(tagstr,1,3) == "!--" then
-                -- Comment
-                match,endmatch,text = string.find(str,self._COMMENT,pos)
-                if not match then
-                    self:_err(self._errstr.commentErr,pos)
-                end
-                if self._handler.comment then
-                    text = self:_parseEntities(self:_stripWS(text))
-                    self._handler:comment(text,next,match,endmatch)
-                end
-            elseif string.sub(tagstr,1,8) == "!DOCTYPE" then
-                -- DTD
-                match,endmatch,attrs = self:_parseDTD(string,pos)
-                if not match then
-                    self:_err(self._errstr.dtdErr,pos)
-                end
-                if self._handler.dtd then
-                    self._handler:dtd(attrs._root,attrs,match,endmatch)
-                end
-            elseif string.sub(tagstr,1,8) == "![CDATA[" then
-                -- CDATA
-                match,endmatch,text = string.find(str,self._CDATA,pos)
-                if not match then
-                    self:_err(self._errstr.cdataErr,pos)
-                end
-                if self._handler.cdata then
-                    self._handler:cdata(text,nil,match,endmatch)
-                end
-            else
-                -- Normal tag
-
-                -- Need theck for embedded '>' in attribute value and extend
-                -- match recursively if necessary eg. <tag attr="123>456">
-
-                while 1 do
-                    errstart,errend = string.find(tagstr,self._ATTRERR1)
-                    if errend == nil then
-                        errstart,errend = string.find(tagstr,self._ATTRERR2)
-                        if errend == nil then
-                            break
-                        end
-                    end
-                    extstart,extend,endt2 = string.find(str,self._TAGEXT,endmatch+1)
-                    tagstr = tagstr .. string.sub(string,endmatch,extend-1)
-                    if not match then
-                        self:_err(self._errstr.xmlErr,pos)
-                    end
-                    endmatch = extend
-                end
-
-                -- Extract tagname/attrs
-
-                tagname,attrs = self:_parseTag(tagstr)
-
-                if (endt1=="/") then
-                    -- End tag
-                    if self._handler.endtag then
-                        if attrs then
-                            -- Shouldnt have any attributes in endtag
-                            self:_err(format("%s (/%s)",
-                                             self._errstr.endTagErr,
-                                             tagname)
-                                        ,pos)
-                        end
-                        if table.remove(self._stack) ~= tagname then
-                            self:_err(format("%s (/%s)",
-                                             self._errstr.unmatchedTagErr,
-                                             tagname)
-                                        ,pos)
-                        end
-                        self._handler:endtag(tagname,nil,match,endmatch)
-                    end
-                else
-                    -- Start Tag
-                    table.insert(self._stack,tagname)
-                    if self._handler.starttag then
-                        self._handler:starttag(tagname,attrs,match,endmatch)
-                    end
-                    -- Self-Closing Tag
-                    if (endt2=="/") then
-                        table.remove(self._stack)
-                        if self._handler.endtag then
-                            self._handler:endtag(tagname,nil,match,endmatch)
-                        end
-                    end
-                end
-            end
-            pos = endmatch + 1
-        end
-    end
-
-    -- Private attributes/functions
-
-    obj._handler    = handler
-    obj._stack      = {}
-
-    obj._XML        = '^([^<]*)<(%/?)([^>]-)(%/?)>'
-    obj._ATTR1      = '([%w-:_]+)%s*=%s*"(.-)"'
-    obj._ATTR2      = '([%w-:_]+)%s*=%s*\'(.-)\''
-    obj._CDATA      = '<%!%[CDATA%[(.-)%]%]>'
-    obj._PI         = '<%?(.-)%?>'
-    obj._COMMENT    = '<!%-%-(.-)%-%->'
-    obj._TAG        = '^(.-)%s.*'
-    obj._LEADINGWS  = '^%s+'
-    obj._TRAILINGWS = '%s+$'
-    obj._WS         = '^%s*$'
-    obj._DTD1       = '<!DOCTYPE%s+(.-)%s+(SYSTEM)%s+["\'](.-)["\']%s*(%b[])%s*>'
-    obj._DTD2       = '<!DOCTYPE%s+(.-)%s+(PUBLIC)%s+["\'](.-)["\']%s+["\'](.-)["\']%s*(%b[])%s*>'
-    obj._DTD3       = '<!DOCTYPE%s+(.-)%s*(%b[])%s*>'
-    obj._DTD4       = '<!DOCTYPE%s+(.-)%s+(SYSTEM)%s+["\'](.-)["\']%s*>'
-    obj._DTD5       = '<!DOCTYPE%s+(.-)%s+(PUBLIC)%s+["\'](.-)["\']%s+["\'](.-)["\']%s*>'
-
-    obj._ATTRERR1   = '=%s*"[^"]*$'
-    obj._ATTRERR2   = '=%s*\'[^\']*$'
-    obj._TAGEXT     = '(%/?)>'
-
-    obj._ENTITIES = { ["&lt;"] = "<",
-                      ["&gt;"] = ">",
-                      ["&amp;"] = "&",
-                      ["&quot;"] = '"',
-                      ["&apos;"] = "'",
-                      ["&#(%d+);"] = function (x)
-                                        local d = tonumber(x)
-                                        if d >= 0 and d < 256 then
-                                            return string.char(d)
-                                        else
-                                            return "&#"..d..";"
-                                        end
-                                     end,
-                      ["&#x(%x+);"] = function (x)
-                                        local d = tonumber(x,16)
-                                        if d >= 0 and d < 256 then
-                                            return string.char(d)
-                                        else
-                                            return "&#x"..x..";"
-                                        end
-                                      end,
-                    }
-
-    obj._err = function(self,err,pos)
-                   if self.options.errorHandler then
-                       self.options.errorHandler(err,pos)
-                   end
-               end
-
-    obj._errstr = { xmlErr = "Error Parsing XML",
-                    declErr = "Error Parsing XMLDecl",
-                    declStartErr = "XMLDecl not at start of document",
-                    declAttrErr = "Invalid XMLDecl attributes",
-                    piErr = "Error Parsing Processing Instruction",
-                    commentErr = "Error Parsing Comment",
-                    cdataErr = "Error Parsing CDATA",
-                    dtdErr = "Error Parsing DTD",
-                    endTagErr = "End Tag Attributes Invalid",
-                    unmatchedTagErr = "Unbalanced Tag",
-                    incompleteXmlErr = "Incomplete XML Document",
-                  }
-
-    obj._stripWS = function(self,s)
-        if self.options.stripWS then
-            s = string.gsub(s,'^%s+','')
-            s = string.gsub(s,'%s+$','')
-        end
-        return s
-    end
-
-    obj._parseEntities = function(self,s)
-        if self.options.expandEntities then
-            --for k,v in self._ENTITIES do
-            for k,v in pairs(self._ENTITIES) do
-                --print (k, v)
-                s = string.gsub(s,k,v)
-            end
-        end
-        return s
-    end
-
-    obj._parseDTD = function(self,s,pos)
-        -- match,endmatch,root,type,name,uri,internal
-        local m,e,r,t,n,u,i
-        m,e,r,t,u,i = string.find(s,self._DTD1,pos)
-        if m then
-            return m,e,{_root=r,_type=t,_uri=u,_internal=i}
-        end
-        m,e,r,t,n,u,i = string.find(s,self._DTD2,pos)
-        if m then
-            return m,e,{_root=r,_type=t,_name=n,_uri=u,_internal=i}
-        end
-        m,e,r,i = string.find(s,self._DTD3,pos)
-        if m then
-            return m,e,{_root=r,_internal=i}
-        end
-        m,e,r,t,u = string.find(s,self._DTD4,pos)
-        if m then
-            return m,e,{_root=r,_type=t,_uri=u}
-        end
-        m,e,r,t,n,u = string.find(s,self._DTD5,pos)
-        if m then
-            return m,e,{_root=r,_type=t,_name=n,_uri=u}
-        end
-        return nil
-    end
-
-    obj._parseTag = function(self,s)
-        local attrs = {}
-        local tagname = string.gsub(s,self._TAG,'%1')
-        string.gsub(s,self._ATTR1,function (k,v)
-                                attrs[string.lower(k)]=self:_parseEntities(v)
-                                attrs._ = 1
-                           end)
-        string.gsub(s,self._ATTR2,function (k,v)
-                                attrs[string.lower(k)]=self:_parseEntities(v)
-                                attrs._ = 1
-                           end)
-        if attrs._ then
-            attrs._ = nil
-        else
-            attrs = nil
-        end
-        return tagname,attrs
-    end
-
-    return obj
-
-end
-
-
--- a/profiles/dlink.ua.web/profile.mk	Thu Sep 20 13:05:46 2012 +0300
+++ b/profiles/dlink.ua.web/profile.mk	Thu Sep 20 15:21:29 2012 +0300
@@ -8,3 +8,6 @@
 WORLD_SUBDIRS_ZROUTER+= \
 	target/usr.bin/lua/
 
+WORLD_SUBDIRS_USR_SBIN+=	\
+	tcpdump
+