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

@ -265,7 +265,8 @@ end
function NetworkItem:saveAndConnectToNetwork(password_input)
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{
text = _("Password cannot be empty."),
})
@ -286,7 +287,7 @@ function NetworkItem:onEditNetwork()
password_input = InputDialog:new{
title = self.info.ssid,
input = self.info.password,
input_hint = "password",
input_hint = _("password (leave empty if open network)"),
input_type = "text",
text_type = "password",
buttons = {
@ -328,7 +329,7 @@ function NetworkItem:onAddNetwork()
password_input = InputDialog:new{
title = self.info.ssid,
input = "",
input_hint = "password",
input_hint = _("password (leave empty if open network)"),
input_type = "text",
text_type = "password",
buttons = {
@ -355,9 +356,11 @@ function NetworkItem:onAddNetwork()
end
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{
text = _("Networks without WPA/WPA2 encryption are not supported.")
text = _("Networks with WEP encryption are not supported.")
})
return
end

Loading…
Cancel
Save