本文共 2797 字,大约阅读时间需要 9 分钟。
OpenWrt ?????Linux???????????????????????????????????????Luci?Lua Configuration Interface?? OpenWrt ????????????Lua??????????????
MVC?Model-View-Controller????????????Web?????Model ??????????View ?????????Controller ?????????? OpenWrt ???????? Lua ??????????
Luci ????? Lua ????? HTML?CSS ? JavaScript????? Web ?????Luci ????????????????? Luci ??????
module("luci.controller.addtest", package.seeall)function index() entry({ "admin", "system", "addtest" }, alias("admin", "system", "addtest", "set"), _("AddTest"), 99).index = true entry({ "admin", "system", "addtest", "set" }, cbi("addtest"), _("Set"), 1) entry({ "admin", "system", "addtest", "info" }, call("action_info"), _("Info"), 2)endfunction action_info() if not nixio.fs.access("/tmp/addtest") then return end local info = nixio.fs.readfile("/tmp/addtest") luci.template.render("addtest_info", { info = info })end UCI?Unified Configuration Interface?? OpenWrt ??????????? /etc/config/ ??????????????? UCI ???
config arguments option interval '' option content ''
???Model?? OpenWrt ????? Lua ??????????????????
m = Map("addtest", translate("Luci??"), translate("fat cheng's test"))s = m:section(TypedSection, "arguments", "")s.addremove = trues.anonymous = falses:option(Flag, "enable", translate("??"))s:option(Value, "interval", translate("??"))s:option(Value, "content", translate("??"))local apply = luci.http.formvalue("cbi.apply")if apply then io.popen("/etc/init.d/addtestd restart")endreturn m ??????????????????????????? init ???
#!/bin/sh/etc/rc.commonSTART=50run_addtest() { local enable=$1 config_get_bool enable $1 enable if [ $enable ]; then local interval=$2 local content=$3 addtest $interval $content fi}start() { config_load addtest config_foreach run_addtest arguments}stop() { result=$(pidof addtest) kill -9 $result echo "addtest has stopped"}$0 $@ 2>/dev/null ???????????????????????????? Makefile?
addtest: addtest.o $(CC) addtest.o -o addtestaddtest.o: addtest.c $(CC) -c addtest.cclean: rm -f *.o addtest
??????? HTML?CSS ? JavaScript ????????????????
AddTest Info AddTest Info
? OpenWrt ?????????????
MVC????
Luci ? UCI ??????
???? OpenWrt ?????????
/etc/rc.local ? /etc/init.d/ ???????????????????????????OpenWrt ? Luci ??????????????????????????????????????????????????????????????????????????? OpenWrt ?????????????????
转载地址:http://rnpfk.baihongyu.com/