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
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)
else
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)
end
end
@ -51,7 +51,7 @@ local function Get_geolocation_info()
-- Get list of BSSID there should ignored
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))
end
@ -65,7 +65,7 @@ local function Get_geolocation_info()
end
end
if #scaned_bssid < 12 then
io.stdout:write("No surrounded BSSIDs found.")
io.stdout:write("No surrounded BSSIDs found.\n")
return { }
end
scaned_bssid = scaned_bssid:gsub("^,(.-),*", "%1")
@ -73,14 +73,14 @@ local function Get_geolocation_info()
-- Request position
local req = io.popen("curl --connect-timeout 15 -s http://openwifi.su/api/v1/bssids/" .. scaned_bssid)
if not req then
io.stdout:write("connection failed.")
io.stdout:write("connection failed.\n")
return { }
end
local jreq, _, err = json.parse(req:read("*a"), 1, nil)
req:close()
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 { }
end
@ -104,11 +104,11 @@ if not uci:get(GLC, "stettings", "static_location") then
uci:save(LOC)
uci:commit(LOC)
end
local timestap = io.open(TIME_STAMP, "a")
local timestap = io.open(TIME_STAMP, "w")
if timestap ~= nil then
timestap:write(os.time())
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)
end
timestap:close()