summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-02-18 20:04:42 +0000
committerMika Havela <mika.havela@gmail.com>2008-02-18 20:04:42 +0000
commitf67ad7952b1fc9516c78c10e55db6ee4c2051b53 (patch)
treea752f5360fcba96cf585870d900f5e5ddef99a02 /app
parent3d45676a1116e285018c0072ebd23f2095523bff (diff)
downloadacf-core-f67ad7952b1fc9516c78c10e55db6ee4c2051b53.tar.bz2
acf-core-f67ad7952b1fc9516c78c10e55db6ee4c2051b53.tar.xz
Moved password-model (temporary - This will go to authenticator-plaintext)
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@751 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'app')
-rwxr-xr-xapp/acf-util/password-model.lua109
1 files changed, 109 insertions, 0 deletions
diff --git a/app/acf-util/password-model.lua b/app/acf-util/password-model.lua
new file mode 100755
index 0000000..e2e4293
--- /dev/null
+++ b/app/acf-util/password-model.lua
@@ -0,0 +1,109 @@
+module(..., package.seeall)
+
+local configfile = "/etc/acf/passwd"
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local function get_roles()
+ local output = cfe({
+ name="roles",
+ label="Available roles",
+ type="checkbox",
+ option={"CREATE","UPDATE","DELETE","READ"},
+ })
+ return output
+end
+
+-- Return a table with the account-details
+local function get_usersettings(userid)
+ local output = {}
+ local filecontent = fs.read_file_as_array(configfile)
+ for i=1,table.maxn(filecontent) do
+ local l = filecontent[i]
+ if not (string.find ( l, "^[;#].*" )) and not (string.find (l, "^%s*$")) then
+ local useroptions = format.string_to_table(l,":")
+ local userroles = {}
+ for k,v in pairs(format.string_to_table(useroptions[4],",")) do
+ userroles[v] = true
+ end
+ if not (userid) or ( (userid) and (userid == useroptions[1]) ) then
+ table.insert(output, cfe({
+ name=useroptions[1],
+ value=useroptions[1],
+ label=useroptions[1],
+ fulltext=string.match(l,"(.-)%s*$"),
+ -- password=useroptions[2],
+ descr=useroptions[3],
+ roles=userroles,
+ -- errtxt="Account is locked!",
+ }))
+ end
+ end
+ end
+ return output
+end
+
+--setup so that it will compare password input
+local function set (self, userid, 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
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+-- Present some general status
+function getstatus()
+ local status = {}
+ status.users = get_usersettings()
+
+ local roles = ""
+ --Rewrite roles into a presentable textstring
+ for k,v in pairs(status.users) do
+ for kk,vv in pairs(v.roles) do
+ roles = kk.. " / " .. roles
+ end
+ v.roles = roles
+ roles = ""
+ end
+
+
+-- status.roles = get_roles()
+ return status
+end
+
+function getsettings(userid)
+ local settings = {}
+ local usersettings = get_usersettings(userid)
+
+ settings.userid = usersettings[1]
+ settings.userid.label = "User id"
+
+ settings.roles = get_roles()
+
+---[[
+ settings.descr = cfe({
+ name="descr",
+ value=usersettings[1].descr,
+ label="Description",
+-- fulltext=string.match(l,"(.-)%s*$"),
+-- password=useroptions[2],
+-- descr=useroptions[3],
+-- roles=userroles,
+-- errtxt="Account is locked!",
+ })
+--]]
+ return settings
+end