Skip to content

Commit

Permalink
unify smb + hotspot password change
Browse files Browse the repository at this point in the history
  • Loading branch information
dndrks committed Apr 28, 2022
1 parent 2603a1a commit 651d7c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lua/core/menu/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ m.deinit = norns.none

m.passdone = function(txt)
if txt ~= nil then
local status = os.execute("echo 'we:"..txt.."' | sudo chpasswd")
if status then print("password changed") end
local chpasswd_status = os.execute("echo 'we:"..txt.."' | sudo chpasswd")
local smbpasswd_status = os.execute("printf '"..txt.."\n"..txt.."\n' | sudo smbpasswd -a we")
local hotspotpasswd_status;
local fd = io.open(norns.state.path.."/data/.system.hotspot_password", "w+")
if fd then
io.output(fd)
io.write(txt)
io.close(fd)
hotspotpasswd_status = true
end
if chpasswd_status then print("ssh password changed") end
if smbpasswd_status then print("samba password changed") end
if hotspotpasswd_status then print("hotspot password changed") end
end
_menu.set_page("SYSTEM")
end
Expand Down
16 changes: 14 additions & 2 deletions lua/core/wifi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ local util = require "util"
--

local HOTSPOT = "Hotspot"
local hotspot_password = "nnnnnnnn"

--
-- common functions
--

local function get_hotspot_password()
local hotspot_password;
local fd = io.open(norns.state.data..".system.hotspot_password", "r")
if fd then
io.input(fd)
hotspot_password = io.read()
io.close(fd)
else
hotspot_password = "nnnnnnnn"
end
return hotspot_password
end

local function collect_info(cmd)
local info = {}
local output = util.os_capture(cmd, true)
Expand Down Expand Up @@ -192,7 +204,7 @@ function Wifi.hotspot()
print("activating hotspot")
Wifi.ensure_radio_is_on()
os.execute("nmcli c delete Hotspot")
os.execute("nmcli dev wifi hotspot ifname wlan0 ssid $(hostname) password " .. hotspot_password)
os.execute("nmcli dev wifi hotspot ifname wlan0 ssid $(hostname) password " .. get_hotspot_password())
end

function Wifi.on(connection)
Expand Down

0 comments on commit 651d7c0

Please sign in to comment.