Add passwordless wifi support

pull/8207/head
Mel-kior 3 years ago committed by Frans de Jonge
parent dd1b10332e
commit 224e167309

@ -59,7 +59,7 @@ end
--- Authenticates network. --- Authenticates network.
function WpaSupplicant:authenticateNetwork(network) function WpaSupplicant:authenticateNetwork(network)
local err, wcli, nw_id local err, wcli, nw_id
--- @todo support passwordless network
wcli, err = WpaClient.new(self.wpa_supplicant.ctrl_interface) wcli, err = WpaClient.new(self.wpa_supplicant.ctrl_interface)
if not wcli then if not wcli then
return false, T(CLIENT_INIT_ERR_MSG, err) return false, T(CLIENT_INIT_ERR_MSG, err)
@ -73,14 +73,24 @@ function WpaSupplicant:authenticateNetwork(network)
wcli:removeNetwork(nw_id) wcli:removeNetwork(nw_id)
return false, _("An error occurred while selecting network.") return false, _("An error occurred while selecting network.")
end end
if not network.psk then -- if password is empty its an open AP
network.psk = calculatePsk(network.ssid, network.password) if network.password and (network.password == nil or string.len(network.password) == 0) then -- Open AP
self:saveNetwork(network) re = wcli:setNetwork(nw_id, "key_mgmt", "NONE")
end if re == 'FAIL' then
re = wcli:setNetwork(nw_id, "psk", network.psk) wcli:removeNetwork(nw_id)
if re == 'FAIL' then return false, _("An error occurred while setting passwordless mode.")
wcli:removeNetwork(nw_id) end
return false, _("An error occurred while setting password.") -- else its a WPA AP
else
if not network.psk then
network.psk = calculatePsk(network.ssid, network.password)
self:saveNetwork(network)
end
re = wcli:setNetwork(nw_id, "psk", network.psk)
if re == 'FAIL' then
wcli:removeNetwork(nw_id)
return false, _("An error occurred while setting password.")
end
end end
wcli:enableNetworkByID(nw_id) wcli:enableNetworkByID(nw_id)

@ -265,7 +265,8 @@ end
function NetworkItem:saveAndConnectToNetwork(password_input) function NetworkItem:saveAndConnectToNetwork(password_input)
local new_passwd = password_input:getInputText() local new_passwd = password_input:getInputText()
if new_passwd == nil or string.len(new_passwd) == 0 then -- Dont set a empty password if WPA encryption, go through if its an open AP
if (new_passwd == nil or string.len(new_passwd) == 0) and string.find(self.info.flags, "WPA") then
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("Password cannot be empty."), text = _("Password cannot be empty."),
}) })
@ -286,7 +287,7 @@ function NetworkItem:onEditNetwork()
password_input = InputDialog:new{ password_input = InputDialog:new{
title = self.info.ssid, title = self.info.ssid,
input = self.info.password, input = self.info.password,
input_hint = "password", input_hint = _("password (leave empty if open network)"),
input_type = "text", input_type = "text",
text_type = "password", text_type = "password",
buttons = { buttons = {
@ -328,7 +329,7 @@ function NetworkItem:onAddNetwork()
password_input = InputDialog:new{ password_input = InputDialog:new{
title = self.info.ssid, title = self.info.ssid,
input = "", input = "",
input_hint = "password", input_hint = _("password (leave empty if open network)"),
input_type = "text", input_type = "text",
text_type = "password", text_type = "password",
buttons = { buttons = {
@ -355,9 +356,11 @@ function NetworkItem:onAddNetwork()
end end
function NetworkItem:onTapSelect(arg, ges_ev) function NetworkItem:onTapSelect(arg, ges_ev)
if not string.find(self.info.flags, "WPA") then -- Open AP dont have specific flag so we cant include them alongside WPA
-- so we exclude WEP instead (more encryption to exclude? not really future proof)
if string.find(self.info.flags, "WEP") then
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("Networks without WPA/WPA2 encryption are not supported.") text = _("Networks with WEP encryption are not supported.")
}) })
return return
end end

Loading…
Cancel
Save