Openwrt LuCI模块练习详细步骤
发布日期:2025-04-29 07:34:46 浏览次数:17 分类:精选文章

本文共 2797 字,大约阅读时间需要 9 分钟。

OpenWrt?Luci?????????

OpenWrt??

OpenWrt ?????Linux???????????????????????????????????????Luci?Lua Configuration Interface?? OpenWrt ????????????Lua??????????????

MVC??

MVC?Model-View-Controller????????????Web?????Model ??????????View ?????????Controller ?????????? OpenWrt ???????? Lua ??????????

Luci????

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??

UCI?Unified Configuration Interface?? OpenWrt ??????????? /etc/config/ ??????????????? UCI ???

config arguments    option interval ''    option content ''

Model??

???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??

??????????????????????????? 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 ?????????????

  • ???Include???????? OpenWrt ??????
  • ???Compile????????
  • ???Sign??????????
  • ???Package???????????????
  • ????

    Q&A

  • MVC????

    • MVC ? Model-View-Controller ???????????????????????
  • Luci ? UCI ??????

    • Luci ? OpenWrt ???????? Lua ???
    • UCI ? OpenWrt ????????????????????
  • ???? OpenWrt ?????????

    • ?? /etc/rc.local ? /etc/init.d/ ?????????????????
  • ??

    ??????????OpenWrt ? Luci ??????????????????????????????????????????????????????????????????????????? OpenWrt ?????????????????

    上一篇:openwrt_git_pull命令提示merger冲突时如何解决?
    下一篇:OpenVSwtich(OVS)Vlan间路由实战 附实验环境

    发表评论

    最新留言

    路过按个爪印,很不错,赞一个!
    [***.219.124.196]2026年06月14日 03时08分52秒