Commit f771c096 authored by Ted Trask's avatar Ted Trask

First cut at ppp acf.

git-svn-id: svn://svn.alpinelinux.org/acf/ppp/trunk@1703 ab2d0c66-481e-0410-8bed-d214d4d58bed
parents
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
ACF for ppp
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
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
../form-html.lsp
\ No newline at end of file
../filedetails-html.lsp
\ No newline at end of file
../filedetails-html.lsp
\ No newline at end of file
../filedetails-html.lsp
\ No newline at end of file
<% local data, viewlibrary = ...
require("viewfunctions")
%>
<% viewlibrary.dispatch_component("status") %>
<% viewlibrary.dispatch_component("editpap") %>
<% viewlibrary.dispatch_component("editchap") %>
<% 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 %>
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
../status-html.lsp
\ No newline at end of file
#CAT GROUP/DESC TAB ACTION
Networking 15PPP Status status
Networking 15PPP Peers listpeers
Networking 15PPP Expert expert
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment