summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2008-06-14 20:55:20 +0000
committerNatanael Copa <natanael.copa@gmail.com>2008-06-14 20:55:20 +0000
commit9c1669a4343097cbb2453a51ac09b9417ad95f70 (patch)
treedcf2576cf3463c1d6c0d88b76f73835d3bdf5e44
downloadacf-openssh-9c1669a4343097cbb2453a51ac09b9417ad95f70.tar.bz2
acf-openssh-9c1669a4343097cbb2453a51ac09b9417ad95f70.tar.xz
added initial acf for opensshv0.1
git-svn-id: svn://svn.alpinelinux.org/acf/openssh/trunk@1218 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--Makefile44
-rw-r--r--README17
-rw-r--r--config.mk10
-rw-r--r--openssh-config-html.lsp67
-rw-r--r--openssh-controller.lua166
-rw-r--r--openssh-model.lua107
-rw-r--r--openssh.menu5
-rw-r--r--openssh.roles2
8 files changed, 418 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8a5d22b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,44 @@
+APP_NAME=openssh
+PACKAGE=acf-$(APP_NAME)
+VERSION=0.1
+
+APP_DIST=\
+ openssh* \
+
+
+EXTRA_DIST=README Makefile config.mk
+
+DISTFILES=$(APP_DIST) $(EXTRA_DIST)
+
+TAR=tar
+
+P=$(PACKAGE)-$(VERSION)
+tarball=$(P).tar.bz2
+install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME)
+
+all:
+clean:
+ rm -rf $(tarball) $(P)
+
+dist: $(tarball)
+
+install:
+ mkdir -p "$(install_dir)"
+ cp -a $(APP_DIST) "$(install_dir)"
+
+$(tarball): $(DISTFILES)
+ rm -rf $(P)
+ mkdir -p $(P)
+ cp $(DISTFILES) $(P)
+ $(TAR) -jcf $@ $(P)
+ rm -rf $(P)
+
+# target that creates a tar package, unpacks is and install from package
+dist-install: $(tarball)
+ $(TAR) -jxf $(tarball)
+ $(MAKE) -C $(P) install DESTDIR=$(DESTDIR)
+ rm -rf $(P)
+
+include config.mk
+
+.PHONY: all clean dist install dist-install
diff --git a/README b/README
new file mode 100644
index 0000000..d5e7bf8
--- /dev/null
+++ b/README
@@ -0,0 +1,17 @@
+Started to do a simple sshd configurator.
+
+This only supports the config options that "makes sense". That means:
+ * Port (chenge to non-standard port)
+ * ListenAddress (bind to single ip or interface)
+ * PermitRootLogin (forbid root to log in. To force use of sudo/su)
+ * PasswordAuthentication (turn off to use public keys only)
+ * UseDNS (will most likely needed to be turned off)
+
+TODO:
+ * Status
+ * submit changes (controller)
+ * validation/CFE'ify
+ * Posibility to upload public keys
+ * remove reminders from openntd (which the files were copied from)
+ * expert tab
+ * log file
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..45f4d21
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,10 @@
+prefix=/usr
+datadir=${prefix}/share
+sysconfdir=${prefix}/etc
+localstatedir=${prefix}/var
+acfdir=${datadir}/acf
+wwwdir=${acfdir}/www
+cgibindir=${acfdir}/cgi-bin
+appdir=${acfdir}/app
+acflibdir=${acfdir}/lib
+sessionsdir=${localstatedir}/lib/acf/sessions
diff --git a/openssh-config-html.lsp b/openssh-config-html.lsp
new file mode 100644
index 0000000..bec5e56
--- /dev/null
+++ b/openssh-config-html.lsp
@@ -0,0 +1,67 @@
+<? local form = ...
+require("viewfunctions")
+?>
+
+<!-- <?
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(form))
+io.write("</span>")
+?> --!>
+
+<?
+function checked(b)
+ if b then
+ return "checked"
+ end
+ return ""
+end
+
+port = form.config.Port
+listen_address = form.config.ListenAddress
+use_dns = checked(form.config.UseDNS)
+password_authentication = checked(form.config.PasswordAuthentication)
+permit_root_login = checked(form.config.PermitRootLogin)
+
+?>
+
+<H1>SSH Configuration</H1>
+<DL>
+<?
+local myform = form.status
+local tags = { "status", "version", "autostart", }
+-- displayinfo(myform,tags,"viewonly")
+?>
+</DL>
+
+<form name="cmd" action="" method="POST">
+<dl>
+ <dt><label for="port">Port</label></dt>
+ <dd><input class="text" type="text" id="port" value="<?= port ?>"/></dd>
+
+ <dt><label for="address">Listen address</label></dt>
+ <dd><input class="text" type="text" id="address" value="<?= listen_address ?>"/></dd>
+
+ <dt><label for="PermitRootLogin">Permit Root Login</label></dt>
+ <dd><input type="checkbox" name="PermitRootLogin" id="PermitRootLogin"
+ <?= permit_root_login ?> />
+
+ <dt><label for="PasswordAuthentication">Password Authentication</label></dt>
+ <dd><input type="checkbox" name="PasswordAuthentication" id="PasswordAuthentication" <?= password_authentication ?>/>
+
+ <dt><label for="UseDNS">Use DNS</label></dt>
+ <dd><input type="checkbox" name="UseDNS" id="UseDNS" <?= use_dns ?>/>
+
+ <dt>&nbsp;</dt>
+ <dd><input type="submit" id="Apply" value="Apply"/></dd>
+</dl>
+<?
+-- Management buttons
+local myform = form.management
+local tags = { "start", "stop", "restart" }
+if (myform) then
+ io.write("<H1>MANAGEMENT</H1>\n<DL>")
+ displaymanagement(myform,tags)
+ io.write("</DL>")
+end
+?>
+</form>
diff --git a/openssh-controller.lua b/openssh-controller.lua
new file mode 100644
index 0000000..767c5fd
--- /dev/null
+++ b/openssh-controller.lua
@@ -0,0 +1,166 @@
+module (..., package.seeall)
+
+-- Load libraries
+require("posix")
+require("validator")
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local function displaycmdmanagement(pidofstatus)
+ -- Add a management buttons
+ local management = {}
+ management.start = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Start",
+ type="submit",
+ })
+ management.stop = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Stop",
+ type="submit",
+ })
+ management.restart = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Restart",
+ type="submit",
+ })
+ -- next CFE can be used to present the result of the previous action
+ management.actionresult = cfe({ name="actionresult",
+ label="Previous action result",
+ })
+
+ -- Disable management buttons based on if the process is running or not
+ if (pidofstatus) then
+ management.start.disabled = "yes"
+ else
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
+
+ return management
+end
+
+local function displaycmdsave(self)
+ -- Add a cmd button to the view
+ local cmdsave = cfe({ name="cmdsave",
+ label="Save/Apply above settings",
+ value="Save",
+ type="submit",
+ })
+ return cmdsave
+end
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+default_action = "config"
+
+function config(self)
+ local errors = {}
+ local modify_opts = nil
+ local cmdsavereply = {}
+ local cmdsaveresult = {}
+
+ -- Start/Stop/Restart process
+ local cmdmanagement, actionresult
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
+ }),
+ })
+ actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ end
+
+ return ( {status = status,
+ config = self.model.read_config(),
+ management = management,
+ url = url,
+ errors = errors,
+ cmdsavereply = cmdsavereply,
+ cmdsaveresult = cmdsaveresult,
+ modify_opts = modify_opts,
+ clientdata = self.clientdata,
+ } )
+end
+
+function logfile(self)
+
+ local status = self.model:getstatus(self)
+ local logfile = self.model:get_logfile()
+
+ return ({
+ status = status,
+ logfile = logfile,
+ url = url,
+ })
+end
+
+function status (self)
+ local cmd = self.clientdata.cmd
+ local url = self.conf.script .. self.conf.prefix .. self.conf.controller
+ return ( {status = "whoops", url = url } )
+end
+
+function expert (self)
+ local modifications = self.clientdata.filecontent or ""
+ if ( self.clientdata.cmdsave ) then
+ modifications = self.model:update_filecontent(modifications)
+ end
+ local url = self.conf.script .. self.conf.prefix .. self.conf.controller
+
+ -- Start/Stop/Restart process
+ local cmdmanagement, actionresult
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
+ }),
+ })
+ actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ end
+
+ local status = self.model:getstatus(self)
+ local file = self.model:get_filedetails()
+
+ -- Add buttons
+ file.cmdsave = cfe ({
+ name="cmdsave",
+ label="Apply settings",
+ value="Apply",
+ type="submit",
+ })
+ if (self.clientdata.cmdsave) then
+ file.cmdsave.descr="* Changes has been saved!"
+ end
+
+
+ -- Management buttons (Hide/show buttons
+ local pidofstatus
+ if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end
+ management = displaycmdmanagement(pidofstatus)
+ if (actionresult) then
+ management.actionresult.descr=cmdmanagement.descr
+ management.actionresult.errtxt=cmdmanagement.errtxt
+ end
+ if (status) and (status.version) and (#status.version.value == 0) then
+ management.start.disabled = "yes"
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
+
+ return ( {
+ status = status,
+ file = file,
+ modifications = modifications,
+ management = management,
+ url = url, } )
+end
+
diff --git a/openssh-model.lua b/openssh-model.lua
new file mode 100644
index 0000000..2debc11
--- /dev/null
+++ b/openssh-model.lua
@@ -0,0 +1,107 @@
+module (..., package.seeall)
+
+require("fs")
+require("posix")
+-- require("procps")
+-- require("daemoncontrol")
+-- require("processinfo")
+
+-- Set variables
+local config_file = "/etc/ssh/sshd_config"
+local packagename = "openssh"
+local processname = "sshd"
+
+-- valid keywords and default config
+local default = {
+ Port = 22,
+ ListenAddress = "0.0.0.0",
+ PermitRootLogin = true,
+ PasswordAuthentication = true,
+ UseDNS = true
+}
+
+
+-- This function is used to get config_content.
+local function process_status_text(procname)
+ local t = procps.pidof(procname)
+ if (t) and (#t > 0) then
+ return "Enabled"
+ else
+ return "Disabled"
+ end
+end
+
+-- return "Yes" or "No" on true/false or value as string
+local function config_value(value)
+ if type(value) == "boolean" then
+ if value then
+ return "Yes"
+ else
+ return "No"
+ end
+ end
+ return tostring(value)
+end
+
+function read_config()
+ local conf = {}
+ local f = io.open(config_file, "r")
+ local line, key, _, k, v
+
+ if not f then
+ return nil
+ end
+
+ -- clone default conf
+ for k, v in pairs(default) do
+ conf[k] = v
+ end
+
+ for line in f:lines() do
+ line = string.gsub(line, "#.*", "")
+ for key, _ in pairs(default) do
+ local k,v = string.match(line, "^("..key..")%s+(.*)")
+ if k then
+ conf[k] = v
+ end
+ end
+ end
+ f:close()
+ return conf
+end
+
+function write_config(config)
+ local k, v, lines, i,j
+ local conf = {}
+
+ -- filter out unsupported keys
+ for k,v in pairs(config) do
+ if default[k] ~= nil then
+ conf[k] = v
+ end
+ end
+
+ lines = fs.read_file_as_array(config_file)
+ for i, j in ipairs(lines) do
+ for k, v in pairs(conf) do
+ if string.match(j, "^#?"..k.."%s+") then
+ lines[i] = k .. " " .. config_value(v)
+ conf[k] = nil
+ end
+ end
+ end
+
+ -- append config opts to end
+ for k,v in pairs(conf) do
+ table.insert(lines, k .. " " .. config_value(v))
+ end
+
+ -- write file
+ posix.mkdir(posix.dirname(config_file))
+ local f = io.open(config_file, "w")
+ for _,i in ipairs(lines) do
+ f:write(i.."\n")
+ end
+ f:close()
+end
+
diff --git a/openssh.menu b/openssh.menu
new file mode 100644
index 0000000..f9a010e
--- /dev/null
+++ b/openssh.menu
@@ -0,0 +1,5 @@
+#CAT GROUP/DESC TAB ACTION
+Networking 20SSH Status status
+Networking 20SSH Config config
+Networking 20SSH Expert expert
+Networking 20SSH Logfile logfile
diff --git a/openssh.roles b/openssh.roles
new file mode 100644
index 0000000..38a3c65
--- /dev/null
+++ b/openssh.roles
@@ -0,0 +1,2 @@
+READ=openssh:status,openssh:logfile
+UPDATE=openssh:expert,openssh:config