-
Notifications
You must be signed in to change notification settings - Fork 325
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
Closed
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 d377f5a
gluon-geolocator: add check_site.lua
2tata f08b0c6
gluon-geolocator: add config geolocator
2tata 942027a
gluon-geolocator: add geolocator.sh
2tata 50f42ce
gluon-geolocator: add cron file
2tata 82792fc
gluon-geolocator: add upgrade script for intervall
2tata 749b942
mv to 540-geolocator-settings
2tata f96e72d
add 540-geolocator-settings
2tata 03606b2
gluon-geolocator: add luaminifyer
2tata 8483270
gluon-geolocator: change check_site.lua
2tata 44cdcbe
gluon-geolocator: rm ffnw spec stuff and add site array to geolocator.sh
2tata a8afdf8
gluon-geolocator: change lua require
2tata 1d3369b
gluon-geolocator: clean up cron file
2tata 3625d53
gluon-geolocator: use taps and chang val type in check_site.lua
2tata 46cbd16
gluon-geolocator: geolocator.sh replace spaces with taps
2tata 41d936a
gluon-geolocator: geolocator.sh rm unneeded ;
2tata 75748d1
gluon-geolocator: geolocator.sh use if/fi instead of {}
2tata 5c624e1
gluon-geolocator: upgrade script prepare for new site file
2tata 97c1598
gluon-geolocator: rm geolocator.sh
2tata 84c767c
gluon-geolocator: porting from shell to lua code
2tata aa26871
gluon-geolocator: rm .sh file ending
2tata 6c806d7
gluon-geolocator: fix line endings and write mode
2tata eb6f071
gluon-geolocator: set uci getbool fix scan for surrounded wifis
2tata 78b4396
geolocator: rm TODO commend after discussion wiht Neoraider
2tata 2ef1df3
gluon-geolocator: refactoring and spellcheck
2tata e8f1d22
gluon-geolocator: fix intervall in 540-geolocator-settings
2tata df565f7
geolocator: ensure MAC addreses are filert by uppercase matching
2tata 49cc2d8
geolocator: set table inserts in brackes
2tata d546111
geolocator: set default values in config
2tata f6a5333
geolocator: rebase site_check
2tata 5ffb482
gluon-geolocator: update to master package configuration
2tata 7d2689c
gluon-geolocator: request wifi interface once per radio and via ubus
2tata 3a7e63e
gluon-geolocator: use call BuildPackageGluon instead of BuildPackage
2tata cd1f2b6
gluon-geolocator: remove fix conf entrys otherwise site values can no…
2tata 20661a2
gluon-geolocator: use a volatile lock file
2tata 791dfe0
gluon-geolocator: geolocator replace spaces with taps
2tata 22b221a
gluon-geolocator: geolocator drop dep on nixio & use posix lockfile
2tata 2391a02
package/gluon-geolocator: only write on flash if position has change …
2tata 8346abd
package/gluon-geolocator: micrond change to default 12h intervall
2tata 1350b85
package/gluon-geolocator: geolocator remove timestamp intervall due t…
2tata 7dc702c
package/gluon-geolocator: use site.conf refresh_interval to rewrite h…
2tata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
config geolocator 'settings' | ||
option static_location '0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* */12 * * * /lib/gluon/geolocator/geolocator |
124 changes: 124 additions & 0 deletions
124
package/gluon-geolocator/luasrc/lib/gluon/geolocator/geolocator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ',')) | ||
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) |
26 changes: 26 additions & 0 deletions
26
package/gluon-geolocator/luasrc/lib/gluon/upgrade/540-geolocator-settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
And then I noticed the site has a broken HTTPS setup since some time in 2017:
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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