Developing lightweight computation at the DSG edge

Commit 7792777b authored by Jorge L. Florit's avatar Jorge L. Florit
Browse files

Move Guifi oneclick files to a separate package.

parent 0d7ee7d5
# Copyright (C) 2013 Quick Mesh Project
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
#
# Contributors:
# Jorge L. Florit
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=qmp-guifi
PKG_RELEASE:=1.0.1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/qmp-guifi
TITLE:=Guifi Oneclick for qMp.
SECTION:=net
CATEGORY:=qMp
URL:=http://guifi.net
DEPENDS:= \
+qmp-system
endef
define Package/qmp-guifi/description
Guifi Oneclick for qMp. Easy configuration for Guifi.net community network Mesh nodes.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/qmp-guifi/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,qmp-guifi))
......@@ -25,17 +25,18 @@ QMP_PATH="/etc/qmp"
QMP_VERSION="$QMP_PATH/qmp.version"
ONECLICK_CGI=0
[ -z $ONECLICK_CGI ] && ONECLICK_CGI=0
ONECLICK_FILE="/tmp/guifi_oneclick"
ONECLICK_PATTERN="qMp Guifi-oneclick"
ONECLICK_URL="/view/unsolclic"
ONECLICK_URL_BASE="http://guifi.net/guifi/device/"
ONECLICK_VARS="nodename devname devmodel ip mask zone"
ONECLICK_ZONES="GS='124+' RAV='136' VLLC='108+'"
ONECLICK_VARS="nodename devname devmodel ssid ip mask zone"
#ONECLICK_ZONES="GS='124+' RAV='136' VLLC='108+'"
qmp_guifi_get_url() {
get_url() {
echo "Getting oneclick config:"
if [ -z $1 ]; then
if [ $ONECLICK_CGI -eq 1 ]; then echo "ERROR: No URL specified."; exit 1;
else qmp_error "No URL specified. USE: 'qmp_guifi_get <${ONECLICK_URL_BASE}#####/> <FILE>'"
......@@ -54,6 +55,8 @@ qmp_guifi_get_url() {
fi
}
# CHECK IF ID OR URL GIVEN
# CHECK IF UNSOLCLIC OR DEVICE URL GIVEN
local oneclick_url
echo $1 | grep -q "/view/unsolclic$" 2>/dev/null
......@@ -73,8 +76,9 @@ qmp_guifi_get_url() {
return 0
}
qmp_guifi_check() {
check() {
echo "Checking oneclick config:"
[ -z $1 ] && {
if [ $ONECLICK_CGI -eq 1 ]; then echo "ERROR: No file given."; exit 1;
else qmp_error "No file given. USE: 'qmp_guifi_check <FILE>'";
......@@ -106,7 +110,7 @@ qmp_guifi_check() {
return 0
}
qmp_guifi_print() {
print() {
echo "Showing variables:"
[ -z $1 ] && {
if [ $ONECLICK_CGI -eq 1 ]; then echo "ERROR: No file given"; exit 1;
......@@ -118,7 +122,6 @@ qmp_guifi_print() {
else qmp_error "File $1 not found."
fi
}
local var
for var in $ONECLICK_VARS; do
echo " $var='`grep "$var" $1 | awk '{FS="="; print $2}' | tr -d "'" | sed 's/\ /_/g'`'"
......@@ -127,8 +130,9 @@ qmp_guifi_print() {
return 0
}
qmp_guifi_configure() {
configure() {
echo "Configuring the node, please wait..."
[ -z $1 ] && {
if [ $ONECLICK_CGI -eq 1 ]; then echo "ERROR: No file given"; exit 1;
else qmp_error "No file given: USE: 'qmp_guifi_configure <FILE>'"
......@@ -164,14 +168,15 @@ qmp_guifi_configure() {
local zone="`grep "zone" $1 | awk '{FS="="; print $2}' | tr -d "'" | sed 's/\ /_/g'`"
local nodename="`grep "nodename" $1 | awk '{FS="="; print $2}' | tr -d "'" | sed 's/\ /_/g'`"
local devname="`grep "devname" $1 | awk '{FS="="; print $2}' | tr -d "'" | sed 's/\ /_/g'`"
#local ssid="`grep "ssid" $1 | awk '{FS="="; print $2}' | tr -d "'" | sed 's/\ /_/g'`"
# GET CHANNEL (140- by default)
local var zone_channel
for var in $ONECLICK_ZONES; do
zone_channel="`echo $var | grep $zone | awk '{FS="="; print $2}' | tr -d "'"`"
[ ! -z $zone_channel ] && break;
done
[ -z $zone_channel ] && zone_channel="140-"
#local var zone_channel
#for var in $ONECLICK_ZONES; do
# zone_channel="`echo $var | grep $zone | awk '{FS="="; print $2}' | tr -d "'"`"
# [ ! -z $zone_channel ] && break;
#done
#[ -z $zone_channel ] && zone_channel="140-"
# SET NODE NAME
# TO DO: SET ZONE ID IN NAME
......@@ -181,7 +186,8 @@ qmp_guifi_configure() {
#...
# SET SSID
# echo " set SSID: guifi.net/$nodename"
## TO DO: if "guifi.net" is not in $ssid then ssid=guifi.net/$nodename
# echo " set SSID: $ssid"
# SET CHANNEL
# echo " set channel: $zone_channel"
......@@ -189,35 +195,35 @@ qmp_guifi_configure() {
echo;
uci commit
sleep 1
qmpcontrol configure_network ; qmpcontrol configure_wifi ; /etc/init.d/bmx6 restart
qmpcontrol configure_network ; qmpcontrol configure_wifi # ; /etc/init.d/bmx6 restart
return 0
}
qmp_guifi_apply() {
oneclick() {
[ ! -z $1 ] && oneclick_url=$1 || exit 1
[ ! -z $2 ] && oneclick_file=$2 || oneclick_file=$ONECLICK_FILE
# GETTING ONECLICK CONFIG
qmp_guifi_get_url $oneclick_url $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected error in qmp_guifi_get function"
get_url $oneclick_url $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected error in qmpguifi get_url function"
echo;
# CHECKING DOWNLOADED CONFIG
qmp_guifi_check $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected error in qmp_guifi_check function"
check $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected error in qmpguifi check function"
echo;
# PRINTING CONFIG VARIABLES
qmp_guifi_print $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected error in qmp_guifi_print function"
print $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected error in qmpguifi print function"
echo;
# CONFIGURING QMP SYSTEM
read -p "Do you want to configure your node with this settings? [N,y]" a
echo;
if [ "$a" == "y" ]; then
qmp_guifi_configure $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected in qmp_guifi_configure function"
configure $oneclick_file
[ $? -ne 0 ] && qmp_error "Unexpected in qmpguifi configure function"
echo "Configuration done!"; echo;
rm -f $oneclick_file
return 0
......@@ -228,3 +234,19 @@ qmp_guifi_apply() {
fi
}
help() {
echo "Use: $0 <function> [params]"
echo ""
echo "get_url [URL] : Get oneclick file."
echo "check [FILE] : Check if valid onelick file."
echo "print [FILE] : Print oneclick file values."
echo "configure [FILE] : Configure node with oneclick file values (recommended to check file before)."
echo "-"
echo "oneclick [URL] : Do all configuration based on Guifi.net website data."
echo ""
exit 1
}
[ -z "$1" ] && help
$@
/etc/qmp/qmp_guifi.sh
\ No newline at end of file
--[[
Copyright (C) 2013 Quick Mesh Project
Contributors:
Jorge L. Florit
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
--]]
module("luci.controller.guifi", package.seeall)
function index()
-- setting place from pre-defined value
local place = {"qmp","Guifi"}
-- setting position of menu
local position = "6"
-- Guifi oneclick menu entry
entry(place,call("action_guifi"),place[#place],tonumber(position))
table.remove(place)
end
function action_guifi()
package.path = package.path .. ";/etc/qmp/?.lua"
local qmp = require "qmpinfo"
local key = qmp.get_key()
luci.template.render("qmp/guifi",{key=key})
end
......@@ -18,7 +18,7 @@ function option(url,key,option) {
case "apply":
window.setTimeout('this.toggle("confirm",1)',150); // Unhide button
window.setTimeout('this.toggle("cancel",1)',200); // Unhide button
document.getElementById("guifidiv").style.height = '270px';
document.getElementById("guifidiv").style.height = '290px';
break;
case "cancel":
output.innerHTML="";
......@@ -29,6 +29,8 @@ function option(url,key,option) {
document.getElementById("guifidiv").style.height = '140px';
break;
}
}
else {
//var lines=output.innerHTML.split(/\r\n|\r|\n/).length;
}
} )
......
#!/bin/sh
QMP_PATH="/etc/qmp"
[ -z "$SOURCE_GUIFI_ONECLICK" ] && . $QMP_PATH/qmp_guifi.sh
GUIFI_TEMP=/tmp/guifi_oneclick
echo "content-type: text/plain"
......@@ -22,31 +19,32 @@ KEY="$(cat $KEY_F)"
guifi_apply() {
[ ! -z "$QUERY_DATA" ] && {
ONECLICK_CGI=1
qmp_guifi_get_url $QUERY_DATA $GUIFI_TEMP
echo;
qmp_guifi_check $GUIFI_TEMP
echo;
qmp_guifi_print $GUIFI_TEMP
ONECLICK_CGI=0
export ONECLICK_CGI=1
/etc/qmp/qmp_guifi.sh get_url $QUERY_DATA $GUIFI_TEMP
[ $? -ne 0 ] && exit 1 || echo;
/etc/qmp/qmp_guifi.sh check $GUIFI_TEMP
[ $? -ne 0 ] && exit 1 || echo;
/etc/qmp/qmp_guifi.sh print $GUIFI_TEMP
[ $? -ne 0 ] && exit 1
export ONECLICK_CGI=0
}
}
guifi_cancel() {
[ -f $GUIFI_TEMP ] && rm -r $GUIFI_TEMP
ONECLICK_CGI=0
export ONECLICK_CGI=0
}
guifi_confirm() {
[ ! -z "$QUERY_DATA" ] && {
ONECLICK_CGI=1
# qmp_guifi_get_url $QUERY_DATA $GUIFI_TEMP
# /etc/qmp/qmp_guifi.sh get_url $QUERY_DATA $GUIFI_TEMP
# echo;
qmp_guifi_check $GUIFI_TEMP
echo;
qmp_guifi_configure $GUIFI_TEMP
export ONECLICK_CGI=1
/etc/qmp/qmp_guifi.sh check $GUIFI_TEMP
[ $? -ne 0 ] && exit 1 || echo;
/etc/qmp/qmp_guifi.sh configure $GUIFI_TEMP
[ -f $GUIFI_TEMP ] && rm -r $GUIFI_TEMP
ONECLICK_CGI=0
export ONECLICK_CGI=0
}
}
......
......@@ -31,7 +31,6 @@ QMP_PATH="/etc/qmp"
. $QMP_PATH/qmp_network.sh
. $QMP_PATH/qmp_update.sh
. $QMP_PATH/qmp_system.sh
. $QMP_PATH/qmp_guifi.sh
offer_default_gw() {
qmp_gw_default offer $1
......@@ -90,11 +89,6 @@ configure_system() {
/etc/init.d/uhttpd restart
}
guifi_oneclick() {
[ -z "$1" ] && echo " Use: $0 guifi_oneclick <url>"
qmp_guifi_apply $1
}
enable_ns_ppt() {
echo 8 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio8/direction
......@@ -179,7 +173,6 @@ help() {
echo " configure_wifi : Configure all WiFi devices"
echo " reset_wifi : Reset, rescan and configure all the WiFi devices"
echo " configure_gw : Configure and apply gateways settings"
echo " guifi_oneclick [URL] : Configure node based on Guifi.net website data"
echo ""
echo "Safe configuration:"
......
......@@ -39,7 +39,6 @@ function index()
entry({"qmp","configuration"}, cbi("qmp/wizard"), "Configuration", 4).dependent=false
entry({"qmp","configuration","wizard"}, cbi("qmp/wizard"), "Wizard", 1).dependent=false
entry({"qmp","configuration","wizard","guifi"}, call("action_guifi"), "Guifi-oneclick", 1).dependent=false
entry({"qmp","configuration","node"}, cbi("qmp/node"), "Node", 2).dependent=false
entry({"qmp","configuration","network"}, cbi("qmp/network"), "Network", 3).dependent=false
entry({"qmp","configuration","network","advanced"}, cbi("qmp/network_adv"), "Advanced networking", 1).dependent=false
......@@ -66,13 +65,6 @@ function action_status()
luci.template.render("qmp/overview",{ipv4=ipv4,hostname=hostname,uname=uname,version=version})
end
function action_guifi()
package.path = package.path .. ";/etc/qmp/?.lua"
local qmp = require "qmpinfo"
local key = qmp.get_key()
luci.template.render("qmp/guifi",{key=key})
end
function action_tools()
package.path = package.path .. ";/etc/qmp/?.lua"
local qmp = require "qmpinfo"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment