X-Git-Url: http://git.openwrt.org/?p=feed%2Frouting.git;a=blobdiff_plain;f=bird-openwrt%2Fbird6-openwrt%2Fsrc%2Fmodel%2Ffunctions.lua;fp=bird-openwrt%2Fbird6-openwrt%2Fsrc%2Fmodel%2Ffunctions.lua;h=466056be2b87ef9818244b2de82c4beeb8a90adc;hp=0000000000000000000000000000000000000000;hb=7cb7b83325a35053913d10a0d54ca2a997ce444b;hpb=e35a8f9dc9e029fd76e571210b985ea33adf1364 diff --git a/bird-openwrt/bird6-openwrt/src/model/functions.lua b/bird-openwrt/bird6-openwrt/src/model/functions.lua new file mode 100644 index 0000000..466056b --- /dev/null +++ b/bird-openwrt/bird6-openwrt/src/model/functions.lua @@ -0,0 +1,77 @@ +--[[ +Copyright (C) 2014-2017 - Eloi Carbo + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +]]-- + +local fs = require "nixio.fs" +local functions_dir = "/etc/bird6/functions/" +local lock_file = "/etc/bird6/function_lock" + +m = SimpleForm("bird6", "Bird6 Functions", "INFO: New files are created using Timestamps.
In order to make it easier to handle, use SSH to connect to your terminal and rename those files.
If your file is not correctly shown in the list, please, refresh your browser.") + +s = m:section(SimpleSection) +files = s:option(ListValue, "Files", "Function Files:") +local new_function = functions_dir .. os.date("function-%Y%m%d-%H%M") + +-- New File Entry +files:value(new_function, "New File (".. new_function .. ")") +files.default = new_function + +local i, file_list = 0, { } +for filename in io.popen("find " .. functions_dir .. " -type f"):lines() do + i = i + 1 + files:value(filename, filename) +end + +ld = s:option(Button, "_load", "Load File") +ld.inputstyle = "reload" + +st_file = s:option(DummyValue, "_stfile", "Editing file:") +function st_file.cfgvalue(self, section) + if ld:formvalue(section) then + fs.writefile(lock_file, files:formvalue(section)) + return files:formvalue(section) + else + fs.writefile(lock_file, "") + return "" + end +end + +area = s:option(Value, "_functions") +area.template = "bird6/tvalue" +area.rows = 30 +function area.cfgvalue(self,section) + if ld:formvalue(section) then + local contents = fs.readfile(files:formvalue(section)) + if contents then + return contents + else + return "" + end + else + return "" + end +end + +function area.write(self, section) + local locked_file = fs.readfile(lock_file) + if locked_file and not ld:formvalue(section) then + local text = self:formvalue(section):gsub("\r\n?", "\n") + fs.writefile(locked_file, text) + fs.writefile(lock_file, "") + end +end + +return m