From 651d7c08ce8fe96f1a300c9756318a1004ceab15 Mon Sep 17 00:00:00 2001 From: dan derks Date: Thu, 28 Apr 2022 11:46:21 -0400 Subject: [PATCH] unify smb + hotspot password change --- lua/core/menu/system.lua | 15 +++++++++++++-- lua/core/wifi.lua | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lua/core/menu/system.lua b/lua/core/menu/system.lua index 2c53773a2..1cc951a2b 100644 --- a/lua/core/menu/system.lua +++ b/lua/core/menu/system.lua @@ -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 diff --git a/lua/core/wifi.lua b/lua/core/wifi.lua index e2344437d..26fa9f822 100644 --- a/lua/core/wifi.lua +++ b/lua/core/wifi.lua @@ -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) @@ -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)