summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile44
-rw-r--r--README1
-rw-r--r--config.mk10
-rw-r--r--ppp-controller.lua34
l---------ppp-createpeer-html.lsp1
l---------ppp-editchap-html.lsp1
l---------ppp-editpap-html.lsp1
l---------ppp-editpeer-html.lsp1
-rw-r--r--ppp-expert-html.lsp8
-rw-r--r--ppp-listpeers-html.lsp30
-rw-r--r--ppp-model.lua108
l---------ppp-status-html.lsp1
-rw-r--r--ppp.menu4
-rw-r--r--ppp.roles4
14 files changed, 248 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e762a42
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,44 @@
+APP_NAME=ppp
+PACKAGE=acf-$(APP_NAME)
+VERSION=0.1.0
+
+APP_DIST=\
+ ppp* \
+
+
+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 -a $(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..fda56b1
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+ACF for ppp
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/ppp-controller.lua b/ppp-controller.lua
new file mode 100644
index 0000000..175e8ee
--- /dev/null
+++ b/ppp-controller.lua
@@ -0,0 +1,34 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("controllerfunctions")
+
+default_action = "status"
+
+function status(self)
+ return self.model.getstatus()
+end
+
+function editpap(self)
+ return controllerfunctions.handle_form(self, self.model.read_papfiledetails, self.model.update_papfiledetails, self.clientdata, "Save", "Edit Config", "Configuration Set")
+end
+
+function editchap(self)
+ return controllerfunctions.handle_form(self, self.model.read_chapfiledetails, self.model.update_chapfiledetails, self.clientdata, "Save", "Edit Config", "Configuration Set")
+end
+
+function listpeers(self)
+ return self.model.list_peers()
+end
+
+function createpeer(self)
+ return controllerfunctions.handle_form(self, self.model.get_newpeer, self.model.create_peer, self.clientdata, "Create", "Create New Peer File", "Peer File Created")
+end
+
+function deletepeer(self)
+ return self:redirect_to_referrer(self.model.delete_peer(self.clientdata.name))
+end
+
+function editpeer(self)
+ return controllerfunctions.handle_form(self, function() return self.model.read_peerfile(self.clientdata.name) end, self.model.update_peerfile, self.clientdata, "Save", "Edit PPP Peer", "Peer Configuration Set")
+end
diff --git a/ppp-createpeer-html.lsp b/ppp-createpeer-html.lsp
new file mode 120000
index 0000000..4b6b762
--- /dev/null
+++ b/ppp-createpeer-html.lsp
@@ -0,0 +1 @@
+../form-html.lsp \ No newline at end of file
diff --git a/ppp-editchap-html.lsp b/ppp-editchap-html.lsp
new file mode 120000
index 0000000..15b1930
--- /dev/null
+++ b/ppp-editchap-html.lsp
@@ -0,0 +1 @@
+../filedetails-html.lsp \ No newline at end of file
diff --git a/ppp-editpap-html.lsp b/ppp-editpap-html.lsp
new file mode 120000
index 0000000..15b1930
--- /dev/null
+++ b/ppp-editpap-html.lsp
@@ -0,0 +1 @@
+../filedetails-html.lsp \ No newline at end of file
diff --git a/ppp-editpeer-html.lsp b/ppp-editpeer-html.lsp
new file mode 120000
index 0000000..15b1930
--- /dev/null
+++ b/ppp-editpeer-html.lsp
@@ -0,0 +1 @@
+../filedetails-html.lsp \ No newline at end of file
diff --git a/ppp-expert-html.lsp b/ppp-expert-html.lsp
new file mode 100644
index 0000000..af70cc6
--- /dev/null
+++ b/ppp-expert-html.lsp
@@ -0,0 +1,8 @@
+<% local data, viewlibrary = ...
+require("viewfunctions")
+%>
+
+<% viewlibrary.dispatch_component("status") %>
+
+<% viewlibrary.dispatch_component("editpap") %>
+<% viewlibrary.dispatch_component("editchap") %>
diff --git a/ppp-listpeers-html.lsp b/ppp-listpeers-html.lsp
new file mode 100644
index 0000000..79cae6c
--- /dev/null
+++ b/ppp-listpeers-html.lsp
@@ -0,0 +1,30 @@
+<% local form, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% displaycommandresults({"deletepeer", "editpeer"}, session) %>
+<% displaycommandresults({"createpeer"}, session, true) %>
+
+<h1>Peer Files</h1>
+<TABLE>
+ <TR style="background:#eee;font-weight:bold;">
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD>
+ <TD style="white-space:nowrap;text-align:left;" class="header">Peer File</TD>
+ </TR>
+<% for i,file in ipairs(form.value) do %>
+ <TR>
+ <TD style="padding-right:20px;white-space:nowrap;">
+ <%
+ if session.permissions[page_info.controller].deletepeer then io.write(html.link{value = "deletepeer?name=" .. file, label="Delete " }) end
+ if session.permissions[page_info.controller].editpeer then io.write(html.link{value = "editpeer?name=" .. file.."&redir="..page_info.orig_action, label="Edit " }) end
+ %>
+ </TD>
+ <TD style="white-space:nowrap;" width="90%"><%= html.html_escape(string.gsub(file, "^.*/", "")) %></TD>
+ </TR>
+<% end %>
+</TABLE>
+
+<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].createpeer then
+ viewlibrary.dispatch_component("createpeer")
+end %>
+
diff --git a/ppp-model.lua b/ppp-model.lua
new file mode 100644
index 0000000..0260533
--- /dev/null
+++ b/ppp-model.lua
@@ -0,0 +1,108 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("modelfunctions")
+require("processinfo")
+require("fs")
+require("validator")
+
+-- Set variables
+local processname = "pppd"
+local packagename = "ppp"
+local papfile = "/etc/ppp/pap-secrets"
+local chapfile = "/etc/ppp/chap-secrets"
+local peerspath = "/etc/ppp/peers/"
+
+local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function getstatus()
+ local status = {}
+
+ local value, errtxt = processinfo.package_version(packagename)
+ status.version = cfe({
+ label="Program version",
+ value=value,
+ errtxt=errtxt,
+ name=packagename
+ })
+
+ status.status = modelfunctions.getenabled(processname)
+
+ return cfe({ type="group", value=status, label="PPP Status" })
+end
+
+function read_papfiledetails()
+ return modelfunctions.getfiledetails(papfile)
+end
+
+function update_papfiledetails(filedetails)
+ return modelfunctions.setfiledetails(filedetails, {papfile})
+end
+
+function read_chapfiledetails()
+ return modelfunctions.getfiledetails(chapfile)
+end
+
+function update_chapfiledetails(filedetails)
+ return modelfunctions.setfiledetails(filedetails, {chapfile})
+end
+
+function list_peers()
+ return cfe({ type="list", value=fs.find_files_as_array(nil, peerspath), label="Peers" })
+end
+
+function get_newpeer()
+ local newpeer = {}
+ newpeer.name = cfe({ label="Name" })
+ return cfe({ type="group", value=newpeer, label="New Peer" })
+end
+
+function create_peer(newpeer)
+ newpeer.errtxt = "Failed to create peer"
+ local path = newpeer.value.name.value
+ if not string.find(path, "/") then
+ path = peerspath .. path
+ end
+
+ if validator.is_valid_filename(path, peerspath) then
+ if (posix.stat(path)) then
+ newpeer.value.name.errtxt = "Peer already exists"
+ else
+ fs.create_file(path)
+ newpeer.errtxt = nil
+ end
+ else
+ newpeer.value.name.errtxt = "Invalid name"
+ end
+
+ return newpeer
+end
+
+function delete_peer(name)
+ local retval = cfe({ value="Failed to delete peer", label="Delete Peer Result", errtxt="Peer not found" })
+
+ for file in fs.find(nil, peerspath) do
+ if name == file then
+ os.remove(file)
+ retval.value = "Peer Deleted"
+ retval.errtxt = nil
+ break
+ end
+ end
+
+ return retval
+end
+
+function read_peerfile(name)
+ return modelfunctions.getfiledetails(name, fs.find_files_as_array(nil, peerspath))
+end
+
+function update_peerfile(filedetails)
+ return modelfunctions.setfiledetails(filedetails, fs.find_files_as_array(nil, peerspath))
+end
diff --git a/ppp-status-html.lsp b/ppp-status-html.lsp
new file mode 120000
index 0000000..b2f8480
--- /dev/null
+++ b/ppp-status-html.lsp
@@ -0,0 +1 @@
+../status-html.lsp \ No newline at end of file
diff --git a/ppp.menu b/ppp.menu
new file mode 100644
index 0000000..7e6ae64
--- /dev/null
+++ b/ppp.menu
@@ -0,0 +1,4 @@
+#CAT GROUP/DESC TAB ACTION
+Networking 15PPP Status status
+Networking 15PPP Peers listpeers
+Networking 15PPP Expert expert
diff --git a/ppp.roles b/ppp.roles
new file mode 100644
index 0000000..236825a
--- /dev/null
+++ b/ppp.roles
@@ -0,0 +1,4 @@
+USER=ppp:status
+EDITOR=ppp:listpeers,ppp:createpeer,ppp:deletepeer,ppp:editpeer
+EXPERT=ppp:expert,ppp:editpap,ppp:editchap
+ADMIN=ppp:status,ppp:listpeers,ppp:createpeer,ppp:deletepeer,ppp:editpeer,ppp:expert,ppp:editpap,ppp:editchap