luci-app-networking_monitor的OpenWrt页面制作

来源:互联网 发布:2017成都 网络视听大会 编辑:程序博客网 时间:2024/06/06 18:07

在网上找了一圈,也没有找到联网监测的OpenWrt页面,于是自己动手写了个luci-app-networking_monitor。

将luci-app-networking_monitor目录放到OpenWrt源码的package/utils下:

[xujun@localhost luci-app-networking_monitor]$ tree.├── files│   └── root│       ├── etc│       │   ├── config│       │   │   └── networking_monitor│       │   └── init.d│       │       └── networking_monitor│       └── usr│           └── lib│               └── lua│                   └── luci│                       ├── controller│                       │   └── networking_monitor.lua│                       └── model│                           └── cbi│                               └── networking_monitor.lua└── Makefile12 directories, 5 files[xujun@localhost luci-app-networking_monitor]$

luci-app-networking_monitor/Makefile

include $(TOPDIR)/rules.mkPKG_NAME:=luci-app-networking_monitorPKG_VERSION=1.0PKG_RELEASE:=1PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)include $(INCLUDE_DIR)/package.mkdefine Package/luci-app-networking_monitorSECTION:=luciCATEGORY:=LuCISUBMENU:=3. ApplicationsTITLE:=NETWORK MONITOR for LuCIPKGARCH:=allendefdefine Package/luci-app-networking_monitor/descriptionThis package contains LuCI configuration pages for network monitor.endefdefine Build/Prepareendefdefine Build/Configureendefdefine Build/Compileendefdefine Package/luci-app-networking_monitor/install$(INSTALL_DIR) $(1)/etc/config$(INSTALL_DIR) $(1)/etc/init.d$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller$(INSTALL_CONF) ./files/root/etc/config/networking_monitor $(1)/etc/config/networking_monitor$(INSTALL_BIN) ./files/root/etc/init.d/networking_monitor $(1)/etc/init.d/networking_monitor$(INSTALL_DATA) ./files/root/usr/lib/lua/luci/model/cbi/networking_monitor.lua $(1)/usr/lib/lua/luci/model/cbi/networking_monitor.lua$(INSTALL_DATA) ./files/root/usr/lib/lua/luci/controller/networking_monitor.lua $(1)/usr/lib/lua/luci/controller/networking_monitor.luaendef$(eval $(call BuildPackage,luci-app-networking_monitor))

luci-app-networking_monitor/files/root/etc/config

config login#option enable '1'option minute '10'option domain '114.114.114.114'

luci-app-networking_monitor/files/root/etc/init.d

#!/bin/sh /etc/rc.commonSTART=50networking_monitor(){local enableconfig_get_bool enable $1 enableif [ $enable ]; thenlocal minutelocal domainconfig_get minute $1 minuteconfig_get domain $1 domaincrontab -rcat /tmp/reply_message.cron >>/etc/crontabs/rootecho "*/$minute * * * * /bin/sh /etc/networking_monitor.sh $domain &" >>/etc/crontabs/rootecho "network monitor has started."/etc/init.d/cron restartelsecrontab -rcat /tmp/reply_message.cron >>/etc/crontabs/rootecho "network monitor has started."/etc/init.d/cron restartfi}start(){config_load networking_monitorconfig_foreach networking_monitor login}stop(){echo "network monitor has stoped."}

luci-app-networking_monitor/files/root/usr/lib/lua/luci/controller

module("luci.controller.networking_monitor", package.seeall)function index()        entry({"admin", "network", "ping_Monitor"}, cbi("networking_monitor"), _("联网监测"), 101)        end

luci-app-networking_monitor/files/root/usr/lib/lua/luci/model/cbi/networking_monitor.lua

--[[LuCI - Lua Configuration InterfaceCopyright 2010 Jo-Philipp Wich <xm@subsignal.org>Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0]]--require("luci.sys")m = Map("networking_monitor", translate("联网监测"), translate("配置联网监测。"))s = m:section(TypedSection, "login", "")s.addremove = falses.anonymous = trueenable = s:option(Flag, "enable", translate("Enable"))pass = s:option(Value, "minute", translate("分"), translate("每隔一段时间执行一次联网监测程序。"))--pass:depends("enable", "1")pass.rmempty = falsepass.default = "10"domain = s:option(Value, "domain", translate("ip地址或域名"))--domain:depends("enable", "1")domain.rmempty = falsedomain.default = "114.114.114.114"local apply = luci.http.formvalue("cbi.apply")if apply thenio.popen("/etc/init.d/networking_monitor restart")endreturn m

最后make menuconfig,可看到luci-app-networking_monitor。

0 0
原创粉丝点击