From 4329b7b6da85440f537da8e4c1b9da1150912df3 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 13 Oct 2008 20:51:39 +0000 Subject: Added alpine-baselayout hostname and password edit. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1556 ab2d0c66-481e-0410-8bed-d214d4d58bed --- Makefile | 1 + alpine-baselayout.roles | 2 +- hostname-controller.lua | 20 +++++--------------- hostname-edit-html.lsp | 1 + hostname-html.lsp | 9 ++++++--- hostname-model.lua | 26 ++++++++++++++++---------- password-controller.lua | 9 +++++---- password-edit-html.lsp | 12 ++++++++++++ password-model.lua | 46 ++++++++++++++++++++++++++++++---------------- password-read-html.lsp | 2 -- 10 files changed, 77 insertions(+), 51 deletions(-) create mode 120000 hostname-edit-html.lsp create mode 100644 password-edit-html.lsp delete mode 100644 password-read-html.lsp diff --git a/Makefile b/Makefile index 45c4372..27ff7fa 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ APP_DIST=\ syslog* \ skins* \ rc* \ + password* \ EXTRA_DIST=README Makefile config.mk diff --git a/alpine-baselayout.roles b/alpine-baselayout.roles index 0c25ac9..31a04d0 100644 --- a/alpine-baselayout.roles +++ b/alpine-baselayout.roles @@ -1,5 +1,5 @@ CREATE=interfaces:create,interfaces:editintfile READ=health:storage,health:proc,health:network,health:modules,health:networkstats,interfaces:status,interfaces:read,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,syslog:status,syslog:loginfo,rc:status -UPDATE=interfaces:update,interfaces:ifup,interfaces:ifdown,interfaces:restart,skins:update,skins:read,syslog:startstop,syslog:config,syslog:expert,rc:edit +UPDATE=hostname:edit,interfaces:update,interfaces:ifup,interfaces:ifdown,interfaces:restart,password:edit,skins:update,skins:read,syslog:startstop,syslog:config,syslog:expert,rc:edit DELETE=interfaces:delete,logfiles:delete ALL=health:system,hostname:read diff --git a/hostname-controller.lua b/hostname-controller.lua index 3164ac6..10ab81c 100644 --- a/hostname-controller.lua +++ b/hostname-controller.lua @@ -1,24 +1,14 @@ -- the hostname controller - module (..., package.seeall) --- Public methods --- /hostname/get +require("controllerfunctions") default_action = "read" -read = function (self ) - return self.model:get() -end - -update = function (self) - return self.model:set(cfe({value=self.clientdata.hostname})) +read = function(self) + return self.model.get() end ---[[ -delete = function (self) - return ({hostname = self.model:set(cfe({value=""}))}) +edit = function(self) + return controllerfunctions.handle_form(self, self.model.read_name, self.model.update_name, self.clientdata, "Save", "Edit Hostname", "Hostname Set") end - -create = update ---]] diff --git a/hostname-edit-html.lsp b/hostname-edit-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/hostname-edit-html.lsp @@ -0,0 +1 @@ +../form-html.lsp \ No newline at end of file diff --git a/hostname-html.lsp b/hostname-html.lsp index b27d0d5..cae18ae 100644 --- a/hostname-html.lsp +++ b/hostname-html.lsp @@ -1,4 +1,7 @@ <% local view = ... %> -

Hostname

-
The Hostname is
-
<%= view.value %>
+<% require("viewfunctions") %> + +

<%= view.label %>

+
+<% displayitem(view) %> +
diff --git a/hostname-model.lua b/hostname-model.lua index ba0c117..7d4238e 100644 --- a/hostname-model.lua +++ b/hostname-model.lua @@ -1,24 +1,30 @@ -- hostname model methods module (..., package.seeall) --- no initializer in model - use controller.init for that - +require("fs") get = function (self) local f = io.popen("/bin/hostname") local n = f:read("*a") or "unknown" f:close() - return (cfe{value=n, label="hostname"}) + return cfe({value=n, label="Hostname"}) +end + + +read_name = function () + return cfe({ type="group", value={hostname=get()}, label="Hostname" }) end +update_name = function(name) + local success = true -set = function (self, name) - local f = io.open ("/etc/hostname", "w") - if f then - f:write(name.value) + if success then + fs.write_file("/etc/hostname", name.value.hostname.value) + local f = io.popen("/bin/hostname -F /etc/hostname") f:close() + else + name.errtxt = "Failed to set hostname" end - f = io.popen("/bin/hostname -F /etc/hostname") - f:close() - return get(self) + + return name end diff --git a/password-controller.lua b/password-controller.lua index a9e28c7..3060e76 100644 --- a/password-controller.lua +++ b/password-controller.lua @@ -1,9 +1,10 @@ -- the password controller - module (..., package.seeall) -default_action = "update" +require("controllerfunctions") + +default_action = "edit" -update = function (self,self.sessionid.userid) - return ( {report = self.model:set() }) +edit = function (self) + return controllerfunctions.handle_form(self, self.model.read_password, self.model.update_password, self.clientdata, "Save", "Set System Password", "Password Set") end diff --git a/password-edit-html.lsp b/password-edit-html.lsp new file mode 100644 index 0000000..d9582bf --- /dev/null +++ b/password-edit-html.lsp @@ -0,0 +1,12 @@ +<% local form, viewlibrary, page_info = ... +require("viewfunctions") +%> + +

<%= form.label %>

+<% + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action + form.value.password.type = "password" + form.value.password_confirm.type = "password" + local order = {"user", "password"} + displayform(form, order) +%> diff --git a/password-model.lua b/password-model.lua index 376c0e2..ba74e45 100644 --- a/password-model.lua +++ b/password-model.lua @@ -1,24 +1,38 @@ -- password model methods module (..., package.seeall) -require "format" --- no initializer in model - use controller.init for that +require ("fs") + +read_password = function() + pw = {} + pw.user = cfe({ label="User Name" }) + pw.password = cfe({ label="Password" }) + pw.password_confirm = cfe({ label="Password (confirm)" }) + return cfe({ type="group", value=pw, label="System Password" }) +end --setup so that it will compare password input -set = function (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." +update_password = function (pw) + local success = true + if pw.value.password.value == "" or pw.value.password.value ~= pw.value.password_confirm.value then + pw.value.password.errtxt = "Invalid or non matching password" + success = false + end + local filecontent = "\n"..fs.read_file("/etc/shadow") + if pw.value.user.value == "" or not string.find(filecontent, "\n"..pw.value.user.value..":") then + pw.value.user.errtxt = "Unknown user" + success = false end - return( cfe{value=report, name="report"}) -end + if success then + local f = io.popen("/usr/bin/cryptpw " .. pw.value.password.value) + local newpass = f:read("*l") + f:close() + local new = string.gsub(filecontent, "(\n"..pw.value.user.value..":)[^:]*", "%1"..newpass) + fs.write_file("/etc/shadow", string.sub(new, 2)) + else + pw.errtxt = "Failed to set password" + end + return pw +end diff --git a/password-read-html.lsp b/password-read-html.lsp deleted file mode 100644 index 1636cdc..0000000 --- a/password-read-html.lsp +++ /dev/null @@ -1,2 +0,0 @@ -<% local view = ... %> -

The local root password is <%= view.password.value %>

-- cgit v1.2.3