diff options
author | Mike Mason <ms13sp@gmail.com> | 2008-11-03 15:56:43 +0000 |
---|---|---|
committer | Mike Mason <ms13sp@gmail.com> | 2008-11-03 15:56:43 +0000 |
commit | 81b9907f5e0b372af29769e3aa569aa92a9661c0 (patch) | |
tree | 2511df0d0e40a39d23a50788d3155fe197db0311 | |
download | acf-dnsmasq-81b9907f5e0b372af29769e3aa569aa92a9661c0.tar.bz2 acf-dnsmasq-81b9907f5e0b372af29769e3aa569aa92a9661c0.tar.xz |
DNSmasq added. Needs a little more work
git-svn-id: svn://svn.alpinelinux.org/acf/dnsmasq/trunk@1573 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | Makefile | 44 | ||||
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | config.mk | 10 | ||||
-rw-r--r-- | dnsmasq-config-html.lsp | 26 | ||||
-rw-r--r-- | dnsmasq-controller.lua | 23 | ||||
l--------- | dnsmasq-expert-html.lsp | 1 | ||||
-rw-r--r-- | dnsmasq-model.lua | 237 | ||||
l--------- | dnsmasq-startstop-html.lsp | 1 | ||||
l--------- | dnsmasq-status-html.lsp | 1 | ||||
-rw-r--r-- | dnsmasq.menu | 5 | ||||
-rw-r--r-- | dnsmasq.roles | 4 |
11 files changed, 358 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a431593 --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +APP_NAME=dnsmasq +PACKAGE=acf-$(APP_NAME) +VERSION=0.1.1 + +APP_DIST=\ + dnsmasq* \ + + +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 @@ -0,0 +1,6 @@ +Need to make sure all the validation is correct. +See if can split some of the fields up like the dhcp range. +Add more configuration options: +dhcp-host +log-dhcp +log-queries 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/dnsmasq-config-html.lsp b/dnsmasq-config-html.lsp new file mode 100644 index 0000000..9272f40 --- /dev/null +++ b/dnsmasq-config-html.lsp @@ -0,0 +1,26 @@ +<% local form, viewlibrary, page_info, session = ... +require("viewfunctions") +%> +<% +--[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") +--]] +%> + +<% displaycommandresults({"startstop"}, session) %> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %> + +<H1>Config</H1> +<% + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action + displayform(form) +%> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/dnsmasq-controller.lua b/dnsmasq-controller.lua new file mode 100644 index 0000000..c2b2e7e --- /dev/null +++ b/dnsmasq-controller.lua @@ -0,0 +1,23 @@ +module(..., package.seeall) + +-- Load libraries +require("controllerfunctions") + +default_action = "status" + +function status(self) + return self.model.getstatus() +end + +function startstop(self) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) +end + +function config(self) + return controllerfunctions.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Config", "Configuration Set") +end + +function expert(self) + return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config File", "Configuration File Set") +end + diff --git a/dnsmasq-expert-html.lsp b/dnsmasq-expert-html.lsp new file mode 120000 index 0000000..207f324 --- /dev/null +++ b/dnsmasq-expert-html.lsp @@ -0,0 +1 @@ +../expert-html.lsp
\ No newline at end of file diff --git a/dnsmasq-model.lua b/dnsmasq-model.lua new file mode 100644 index 0000000..aec875f --- /dev/null +++ b/dnsmasq-model.lua @@ -0,0 +1,237 @@ +module(..., package.seeall) + +-- Load libraries +require("modelfunctions") +require("fs") +require("format") +require("posix") +require("validator") + +-- Set variables +local configfile = "/etc/dnsmasq.conf" +local processname = "dnsmasq" +local packagename = "dnsmasq" +local baseurl = "/etc/" +local descr = { +} + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function validateconfig(config) + local success = true + if config.value.IPSEND and not validator.is_ipv4(config.value.IPSEND.value) then + config.value.IPSEND.errtxt = "Invalid IP address" + success = false + end + if config.value.IP and not validator.is_ipv4(config.value.IP.value) then + config.value.IP.errtxt = "Invalid IP address" + success = false + end + return success, config +end + +local function validatedomain(domain) + local success = false + local domains = getDomains() + domain.value.domain.errtxt = "Invalid domain" + for i,name in ipairs(domains.value) do + if name == domain.value.domain.value then + domain.value.domain.errtxt = nil + success = true + break + end + end + for i,name in ipairs(domain.value.iplist.value) do + if not validator.is_ipv4(name) then + domain.value.iplist.errtxt = "Invalid IP address" + success = false + break + end + end + return success, domain +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +function startstop_service(action) + return modelfunctions.startstop_service(processname, action) +end + +function getstatus() + return modelfunctions.getstatus(processname, packagename, "DNS Masq Status") +end + +function getconfig() + local conf = format.parse_ini_file(fs.read_file(configfile), "") or {} +require ("html") + + local output = {} + output.DOMAIN = cfe({ value = conf.domain or "", label="Local Domain to use", + descr="Internal Domain for your LAN" }) + output.INTERFACE = cfe({ value=conf.interface, label="Interface" }) + output.IP = cfe({ value=conf["listen-address"] or "", label="IP address to listen on" }) + output.RANGE = cfe ({value=conf["dhcp-range"] or "", label="Range of IPs", descr="First,Last,Netmask,Time in hours"}) + + -- APP.logevent(html.cfe_unpack(output)) + + return cfe({ type="group", value=output, label="DNS Masq Config" }) +end + +function setconfig(config) + local success, config = validateconfig(config) + + if success then + local file = fs.read_file(configfile) + file = format.update_ini_file(file,"","domain",config.value.LOCALD.value) + file = format.update_ini_file(file,"","interface",config.value.INTERFACE.value) + file = format.update_ini_file(file,"","listen-address",config.value.IP.value) + file = format.update_ini_file(file,"","dhcp-range",config.value.RANGE.value) + fs.write_file(configfile, file) + else + config.errtxt = "Failed to set config" + end + + return config +end + +function getconfigfile() + -- FIXME Validate + return modelfunctions.getfiledetails(configfile) +end + +function setconfigfile(filedetails) + -- FIXME Validate + return modelfunctions.setfiledetails(filedetails, {configfile}) +end + +function getIPs() + local ipdir = baseurl.."ip" + local iplist = cfe({ type="list", value={}, label="IP prefixes to respond to" }) + if fs.is_dir(ipdir) then + for i,name in ipairs(posix.dir(ipdir)) do + if not string.match(name, "^%.") then + if (fs.is_file(ipdir.."/"..name)) then + table.insert(iplist.value, name) + end + end + end + end + return cfe({ type="group", value={iplist=iplist} }) +end + +function setIPs(iplist) + local reverseIPs = {} + for i,name in ipairs(iplist.value.iplist.value) do + -- check if a valid (or partial) ip + if not validator.is_partial_ipv4(name) then + iplist.value.iplist.errtxt = "Invalid IP address" + iplist.errtxt = "Failed to set IP list" + break + end + reverseIPs[name] = i + end + if not iplist.errtxt then + local currentIPlist = getIPs() + for i,name in ipairs(currentIPlist.value.iplist.value) do + if reverseIPs[name] then + reverseIPs[name] = nil + else + -- need to delete the file + local f = io.popen("rm "..baseurl.."ip/"..name) + f:close() + end + end + for name in pairs(reverseIPs) do + -- need to create the file + local f = io.popen("touch "..baseurl.."ip/"..name) + f:close() + end + end + return iplist +end + +function getDomains() + local domaindir = baseurl.."servers" + local domainlist = cfe({ type="list", value={}, label="DNS Server Domains" }) + if fs.is_dir(domaindir) then + for i,name in ipairs(posix.dir(domaindir)) do + if not string.match(name, "^%.") then + if (fs.is_file(domaindir.."/"..name)) then + table.insert(domainlist.value, name) + end + end + end + end + return domainlist +end + +function getNewDomain() + local domain = cfe({ label="Domain" }) + return cfe({ type="group", value={domain=domain} }) +end + +function setNewDomain(domain) + if "" ~= string.gsub(domain.value.domain.value..".", "%w+%.", "") then + domain.value.domain.errtxt = "Invalid domain" + domain.errtxt = "Failed to create domain" + elseif fs.is_file(baseurl.."servers/"..domain.value.domain.value) then + domain.value.domain.errtxt = "Domain already exists" + domain.errtxt = "Failed to create domain" + else + local f = io.popen("touch "..baseurl.."servers/"..domain.value.domain.value) + f:close() + domain.descr = "Created domain" + end + return domain +end + +function getDomain(getdomainname) + local domain = cfe({ value=getdomainname, label="Domain", errtxt="Invalid domain" }) + local iplist = cfe({ type="list", value={}, label="List of DNS servers" }) + local domains = getDomains() + for i,name in ipairs(domains.value) do + if name == getdomainname then + domain.errtxt = nil + break + end + end + if not domain.errtxt then + local content = fs.read_file(baseurl.."servers/"..getdomainname) + for name in string.gmatch(content.."\n", "([^\n]+)\n") do + table.insert(iplist.value, name) + end + end + return cfe({ type="group", value={domain=domain, iplist=iplist} }) +end + +function setDomain(domain) + local success, domain = validatedomain(domain) + if success then + fs.write_file(baseurl.."servers/"..domain.value.domain.value, + table.concat(domain.value.iplist.value, "\n") ) + else + domain.errtxt = "Failed to save domain" + end + return domain +end + +function deleteDomain(domainname) + local cmdresult = cfe({ value="Domain not deleted", label="Delete domain result", errtxt="Invalid domain" }) + local domains = getDomains() + if domainname == "@" then + cmdresult.errtxt = "Cannot delete root domain" + else + for i,name in ipairs(domains.value) do + if name == domainname then + local f = io.popen("rm "..baseurl.."servers/"..name) + f:close() + cmdresult.errtxt = nil + cmdresult.value = "Domain deleted" + break + end + end + end + return cmdresult +end diff --git a/dnsmasq-startstop-html.lsp b/dnsmasq-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/dnsmasq-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp
\ No newline at end of file diff --git a/dnsmasq-status-html.lsp b/dnsmasq-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/dnsmasq-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp
\ No newline at end of file diff --git a/dnsmasq.menu b/dnsmasq.menu new file mode 100644 index 0000000..a4f1ca9 --- /dev/null +++ b/dnsmasq.menu @@ -0,0 +1,5 @@ +#CAT GROUP/DESC TAB ACTION +Networking 13DNSmasq Status status +Networking 13DNSmasq Config config +Networking 13DNSmasq Expert expert + diff --git a/dnsmasq.roles b/dnsmasq.roles new file mode 100644 index 0000000..53ac32e --- /dev/null +++ b/dnsmasq.roles @@ -0,0 +1,4 @@ +USER=dnsmasq:status,dnsmasq:startstop +EDITOR=dnsmasq:config +EXPERT=dnsmasq:expert +ADMIN=dnsmasq:status,dnsmasq:startstop,dnsmasq:config,dnsmasq:expert |