Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pkg gluon-geolocator from google summer of code 2017 #1201

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
37bff43
add new pkg gluon-geolocator
2tata Jul 28, 2017
d377f5a
gluon-geolocator: add check_site.lua
2tata Jul 28, 2017
f08b0c6
gluon-geolocator: add config geolocator
2tata Jul 28, 2017
942027a
gluon-geolocator: add geolocator.sh
2tata Jul 28, 2017
50f42ce
gluon-geolocator: add cron file
2tata Jul 28, 2017
82792fc
gluon-geolocator: add upgrade script for intervall
2tata Jul 28, 2017
749b942
mv to 540-geolocator-settings
2tata Aug 4, 2017
f96e72d
add 540-geolocator-settings
2tata Aug 4, 2017
03606b2
gluon-geolocator: add luaminifyer
2tata Aug 4, 2017
8483270
gluon-geolocator: change check_site.lua
2tata Aug 4, 2017
44cdcbe
gluon-geolocator: rm ffnw spec stuff and add site array to geolocator.sh
2tata Aug 4, 2017
a8afdf8
gluon-geolocator: change lua require
2tata Aug 12, 2017
1d3369b
gluon-geolocator: clean up cron file
2tata Aug 12, 2017
3625d53
gluon-geolocator: use taps and chang val type in check_site.lua
2tata Aug 12, 2017
46cbd16
gluon-geolocator: geolocator.sh replace spaces with taps
2tata Aug 12, 2017
41d936a
gluon-geolocator: geolocator.sh rm unneeded ;
2tata Aug 12, 2017
75748d1
gluon-geolocator: geolocator.sh use if/fi instead of {}
2tata Aug 12, 2017
5c624e1
gluon-geolocator: upgrade script prepare for new site file
2tata Aug 13, 2017
97c1598
gluon-geolocator: rm geolocator.sh
2tata Aug 16, 2017
84c767c
gluon-geolocator: porting from shell to lua code
2tata Aug 16, 2017
aa26871
gluon-geolocator: rm .sh file ending
2tata Aug 16, 2017
6c806d7
gluon-geolocator: fix line endings and write mode
2tata Aug 17, 2017
eb6f071
gluon-geolocator: set uci getbool fix scan for surrounded wifis
2tata Aug 18, 2017
78b4396
geolocator: rm TODO commend after discussion wiht Neoraider
2tata Sep 3, 2017
2ef1df3
gluon-geolocator: refactoring and spellcheck
2tata Dec 26, 2017
e8f1d22
gluon-geolocator: fix intervall in 540-geolocator-settings
2tata Dec 26, 2017
df565f7
geolocator: ensure MAC addreses are filert by uppercase matching
2tata Jan 24, 2018
49cc2d8
geolocator: set table inserts in brackes
2tata Feb 13, 2018
d546111
geolocator: set default values in config
2tata Feb 14, 2018
f6a5333
geolocator: rebase site_check
2tata Feb 19, 2018
5ffb482
gluon-geolocator: update to master package configuration
2tata Jul 15, 2018
7d2689c
gluon-geolocator: request wifi interface once per radio and via ubus
2tata Jul 16, 2018
3a7e63e
gluon-geolocator: use call BuildPackageGluon instead of BuildPackage
2tata Jul 16, 2018
cd1f2b6
gluon-geolocator: remove fix conf entrys otherwise site values can no…
2tata Jul 16, 2018
20661a2
gluon-geolocator: use a volatile lock file
2tata Jul 16, 2018
791dfe0
gluon-geolocator: geolocator replace spaces with taps
2tata Feb 7, 2019
22b221a
gluon-geolocator: geolocator drop dep on nixio & use posix lockfile
2tata Feb 8, 2019
2391a02
package/gluon-geolocator: only write on flash if position has change …
2tata Apr 15, 2019
8346abd
package/gluon-geolocator: micrond change to default 12h intervall
2tata Apr 17, 2019
1350b85
package/gluon-geolocator: geolocator remove timestamp intervall due t…
2tata Apr 17, 2019
7dc702c
package/gluon-geolocator: use site.conf refresh_interval to rewrite h…
2tata Apr 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions package/gluon-geolocator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=gluon-geolocator
PKG_VERSION:=1
PKG_RELEASE:=1

include ../gluon.mk

define Package/gluon-geolocator
TITLE:=Provide the geolocator to receive positions over wifi
DEPENDS:=+gluon-node-info +micrond
endef

$(eval $(call BuildPackageGluon,gluon-geolocator))
2 changes: 2 additions & 0 deletions package/gluon-geolocator/check_site.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
need_boolean(in_site({'geolocator', 'autolocation'}), false)
need_number(in_site({'geolocator', 'interval'}), false)
2 changes: 2 additions & 0 deletions package/gluon-geolocator/files/etc/config/geolocator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config geolocator 'settings'
option static_location '0'
1 change: 1 addition & 0 deletions package/gluon-geolocator/files/usr/lib/micron.d/geolocator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* */12 * * * /lib/gluon/geolocator/geolocator
124 changes: 124 additions & 0 deletions package/gluon-geolocator/luasrc/lib/gluon/geolocator/geolocator
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/lua

local bit = require('bit')
local unistd = require('posix.unistd')
local fcntl = require('posix.fcntl')
local uci = require('simple-uci').cursor()
local json = require ("jsonc")
local ubus = require 'ubus'
local iwinfo = require("iwinfo")

local LOC="gluon-node-info"
local GLC="geolocator"

if not uci:get_bool(GLC, "settings", "auto_location") then
os.exit(0)
end

-- PID file to ensure the geolocator isn't running parallel
local lockfile = '/var/lock/geolocator.lock'
local lockfd, err = fcntl.open(lockfile, bit.bor(fcntl.O_WRONLY, fcntl.O_CREAT), 384) -- mode 0600

if not lockfd then
io.stderr:write(err, '\n')
os.exit(1)
end

local ok, _ = fcntl.fcntl(lockfd, fcntl.F_SETLK, {
l_start = 0,
l_len = 0,
l_type = fcntl.F_WRLCK,
l_whence = unistd.SEEK_SET,
})

if not ok then
io.stderr:write(string.format(
"Unable to lock file %s. Make sure there is no other instance of the geolocator running.\n",
lockfile
))
os.exit(1)
end

-- Iterates over all active WLAN interfaces
-- Returning true from the callback function will skip all remaining
-- interfaces of the same radio
local function foreach_radio(f)
local uconn = assert(ubus.connect(), 'failed to connect to ubus')
local status = uconn:call('network.wireless', 'status', {})
ubus.close(uconn)

for _, radio in pairs(status) do
for _, iface in ipairs(radio.interfaces) do
if f(iface.ifname) then
break
end
end
end
end

local function receive_json(request)
local f = assert(io.popen(string.format("exec wget -T 15 -q -O- '%s'", request)), 'failed to run wget')
local data = f:read('*a')
f:close()

return json.parse(data)
end

-- Get position
local function locate()
local done_bssids = {}
local found_bssids = {}
foreach_radio(function(ifname)
local iw = iwinfo[iwinfo.type(ifname)]
if not iw then
-- Skip other ifaces of this radio, as they
-- will have the same type
return true
end

local scanlist = iw.scanlist(ifname)
if not scanlist then
return false
end

for _, entry in ipairs(scanlist) do
if entry.mode:match("Master") then
local bssid = string.upper(entry.bssid:gsub(":", ""))
if not done_bssids[bssid] then
table.insert(found_bssids, bssid)
done_bssids[bssid] = true
end
end
end

return true
end)

assert(#found_bssids > 0, 'insufficient BSSIDs found')

local data = receive_json('http://openwifi.su/api/v1/bssids/' .. table.concat(found_bssids, ','))
Copy link
Contributor

@mweinelt mweinelt Feb 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a hard time with the privacy aspect of announcing your neighbouring WiFi networks in plain over the internet. What's it gonna take to get HTTPS up and running here? Just under 400 kB.

root@64289-rocket-carrier:~# opkg info libustream-wolfssl
Package: libustream-wolfssl
Version: 2018-07-30-23a3f283-1
Depends: libc, libubox, libwolfssl
Status: unknown ok not-installed
Section: libs
Architecture: powerpc_8540
Size: 4444
Filename: libustream-wolfssl_2018-07-30-23a3f283-1_powerpc_8540.ipk
Description: ustream SSL Library (wolfssl)

root@64289-rocket-carrier:~# opkg info ca-bundle
Package: ca-bundle
Version: 20180409-2
Depends: libc
Status: unknown ok not-installed
Section: base
Architecture: all
Size: 120447
Filename: ca-bundle_20180409-2_all.ipk
Description: System CA certificates as a bundle

root@64289-rocket-carrier:~# opkg info libwolfssl
Package: libwolfssl
Version: 3.15.3-stable-1
Depends: libc
Provides: libcyassl
Status: install ok installed
Section: libs
Architecture: powerpc_8540
Size: 270414
Filename: libwolfssl_3.15.3-stable-1_powerpc_8540.ipk
Description: wolfSSL (formerly CyaSSL) is an SSL library optimized for small
 footprint, both on disk and for memory use.
Installed-Time: 1549301037

And then I noticed the site has a broken HTTPS setup since some time in 2017:

openwifi.su uses an invalid security certificate. 
The certificate expired on 23. October 2017, 04:20:00 GMT+2. 
The current time is February 9, 2019, 4:01 AM. Error code: SEC_ERROR_EXPIRED_CERTIFICATE

In fact I believe that sending what might be personal data to a third-party is a questionable thing to do. If this happens the user needs to actively acknowledge this fact IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not so happy with pushing though data plain over the internet. But the images will be to big with ssl on board. I have an another Idea to only send hashes of SSID+mac but this need time to implement and also time to be filled with datas. So actually there is only this solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we are going to cross the 4 MB either way. I'm not afraid of that, it just means lower end device will not be able to receive all possible features, which is reasonable, given the size constraint. On the other hand we would be able to build more interesting applications for properly sized routers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for notice, openwifi.su has fixed the outdated ssl certificate aprox 2019-06-12

assert(type(data) == 'table' and data.lon and data.lat, 'location not available')

return data
end

local pos = locate()
if not next(pos) then
os.exit(1)
end

if not uci:get_bool(GLC, "settings", "static_location") then

local old_lat = uci:get(LOC, uci:get_first(LOC, 'location'), 'latitude')
local old_lon = uci:get(LOC, uci:get_first(LOC, 'location'), 'longitude')

uci:set(LOC, uci:get_first(LOC, 'location'), 'latitude', pos.lat)
uci:set(LOC, uci:get_first(LOC, 'location'), 'longitude', pos.lon)
uci:save(LOC)

-- Commit only if no coordinates have been stored before or the Nodes Pos have change significantly +- 22m
if (old_lat == nil or old_lon == nil) or ( math.abs(math.abs(old_lat) - math.abs(pos.lat)) > 0.0002 or math.abs(math.abs(old_lon) - math.abs(pos.lon)) > 0.0002 ) then
uci:commit(LOC)
end
end
os.exit(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/lua

local site = require 'gluon.site'
2tata marked this conversation as resolved.
Show resolved Hide resolved
local uci = require('simple-uci').cursor()

local config = 'geolocator'

local static_location = uci:get(config, 'settings', 'static_location')

local auto_location = uci:get(config, 'settings', 'auto_location')
if not auto_location then
auto_location = site.geolocator.autolocation(false)
end

uci:delete(config, 'settings')
uci:section(config, config, 'settings', {
static_location = static_location,
auto_location = auto_location,
})

local refresh_interval = site.geolocator.interval(12) -- default: 12h

local f = io.open('/usr/lib/micron.d/geolocator', 'w')
f:write(string.format('* */%i * * * /lib/gluon/geolocator/geolocator\n', refresh_interval))
f:close()
uci:save(config)