luci-app-networking_monitor的OpenWrt页面制作

在网上找了一圈,也没有找到联网监测的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
└── Makefile

12 directories, 5 files
[xujun@localhost luci-app-networking_monitor]$

luci-app-networking_monitor/Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-networking_monitor
PKG_VERSION=1.0
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/luci-app-networking_monitor
	SECTION:=luci
	CATEGORY:=LuCI
	SUBMENU:=3. Applications
	TITLE:=NETWORK MONITOR for LuCI
	PKGARCH:=all
endef

define Package/luci-app-networking_monitor/description
	This package contains LuCI configuration pages for network monitor.
endef

define Build/Prepare
endef

define Build/Configure
endef

define Build/Compile
endef

define 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.lua
endef

$(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.common
START=50

networking_monitor()
{
	local enable
	config_get_bool enable $1 enable

	if [ $enable ]; then
		local minute
		local domain

		config_get minute $1 minute
		config_get domain $1 domain

		crontab -r
		cat /tmp/reply_message.cron >>/etc/crontabs/root
		echo "*/$minute * * * * /bin/sh /etc/networking_monitor.sh $domain &" >>/etc/crontabs/root

		echo "network monitor has started."
		/etc/init.d/cron restart
	else
		crontab -r
		cat /tmp/reply_message.cron >>/etc/crontabs/root

		echo "network monitor has started."
		/etc/init.d/cron restart
	fi
}

start()
{
	config_load networking_monitor
	config_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 Interface

Copyright 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 at

	http://www.apache.org/licenses/LICENSE-2.0
]]--

require("luci.sys")

m = Map("networking_monitor", translate("联网监测"), translate("配置联网监测。"))

s = m:section(TypedSection, "login", "")
s.addremove = false
s.anonymous = true

enable = s:option(Flag, "enable", translate("Enable"))
pass = s:option(Value, "minute", translate("分"), translate("每隔一段时间执行一次联网监测程序。"))
--pass:depends("enable", "1")
pass.rmempty = false
pass.default = "10"

domain = s:option(Value, "domain", translate("ip地址或域名"))
--domain:depends("enable", "1")
domain.rmempty = false
domain.default = "114.114.114.114"

local apply = luci.http.formvalue("cbi.apply")
if apply then
	io.popen("/etc/init.d/networking_monitor restart")
end

return m

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值