blob: 90fa50d0670f5e5fa721422a8acdae2dce1fc80b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
-- password model methods
module (..., package.seeall)
strsplit = require "split"
require "fs"
-- no initializer in model - use controller.init for that
get = function (self)
f = io.open ("/etc/shadow")
c = f:read("*l")
temp = strsplit(":", c)
if temp[2] == "!" then
status = "not set"
else
status = "set"
end
f:close()
return (cfe{value=status, name="password"})
end
--setup so that it will compare password input
set = function (self, cmd1, cmd2)
if cmd1 ~= cmd2 then report = "Invalid or non matching password. Try again"
else
command = "/usr/bin/cryptpw" .. " " .. cmd1
f = io.popen(command)
c = f:read("*l")
f:close()
--this is hardcoded for root should be easy to change
newpass = "root:" .. c
t = fs.search_replace("/etc/shadow", "root:[!%w%$%/%.]+", newpass)
fs.write_file("/etc/shadow", fs.ipairs_string(t))
report = "Success. New password set."
end
return( cfe{value=report, name="report"})
end
|