gluon-geolocator: fix line endings and write mode

This commit is contained in:
Jan-Tarek Butt 2017-08-17 09:12:37 +02:00
parent aa268718b5
commit 6c806d77dc

View File

@ -20,11 +20,11 @@ local function file_exsist(file)
end end
if file_exsist(PID_PART) then if file_exsist(PID_PART) then
io.stdout:write("The geolocator is still running") io.stdout:write("The geolocator is still running.\n")
os.exit(0) os.exit(0)
else else
if io.open(PID_PART, "w") == nil then if io.open(PID_PART, "w") == nil then
io.stdout:write("Can`t create pid file on "..PID_PART) io.stdout:write("Can`t create pid file on " .. PID_PART .. "\n")
os.exit(1) os.exit(1)
end end
end end
@ -51,7 +51,7 @@ local function Get_geolocation_info()
-- Get list of BSSID there should ignored -- Get list of BSSID there should ignored
local blacklist_bssid = { } local blacklist_bssid = { }
for bl_bssid in ipairs(uci:get(GLC, "stettings", "blacklist")) do for _, bl_bssid in ipairs(uci:get(GLC, "stettings", "blacklist")) do
table.insert(blacklist_bssid,string.upper(bl_bssid)) table.insert(blacklist_bssid,string.upper(bl_bssid))
end end
@ -65,7 +65,7 @@ local function Get_geolocation_info()
end end
end end
if #scaned_bssid < 12 then if #scaned_bssid < 12 then
io.stdout:write("No surrounded BSSIDs found.") io.stdout:write("No surrounded BSSIDs found.\n")
return { } return { }
end end
scaned_bssid = scaned_bssid:gsub("^,(.-),*", "%1") scaned_bssid = scaned_bssid:gsub("^,(.-),*", "%1")
@ -73,14 +73,14 @@ local function Get_geolocation_info()
-- Request position -- Request position
local req = io.popen("curl --connect-timeout 15 -s http://openwifi.su/api/v1/bssids/" .. scaned_bssid) local req = io.popen("curl --connect-timeout 15 -s http://openwifi.su/api/v1/bssids/" .. scaned_bssid)
if not req then if not req then
io.stdout:write("connection failed.") io.stdout:write("connection failed.\n")
return { } return { }
end end
local jreq, _, err = json.parse(req:read("*a"), 1, nil) local jreq, _, err = json.parse(req:read("*a"), 1, nil)
req:close() req:close()
if err or jreq.lon == nil or jreq.lat == nil then if err or jreq.lon == nil or jreq.lat == nil then
io.stdout:write("openwifi.su doesn't gif a location.") io.stdout:write("openwifi.su doesn't gif a location.\n")
return { } return { }
end end
@ -104,11 +104,11 @@ if not uci:get(GLC, "stettings", "static_location") then
uci:save(LOC) uci:save(LOC)
uci:commit(LOC) uci:commit(LOC)
end end
local timestap = io.open(TIME_STAMP, "a") local timestap = io.open(TIME_STAMP, "w")
if timestap ~= nil then if timestap ~= nil then
timestap:write(os.time()) timestap:write(os.time())
else else
io.stdout:write("Can`t create pid file on "..TIME_STAMP) io.stdout:write("Can`t create pid file on " .. TIME_STAMP .. "\n")
exit(1) exit(1)
end end
timestap:close() timestap:close()