From 06574b6d554762128d592a1aa269a7114e53c900 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Fri, 8 Jun 2018 15:03:05 +0800 Subject: [PATCH] update vlmcsd luci to fit new luci --- .../luasrc/controller/vlmcsd.lua | 8 ++++ .../luasrc/model/cbi/vlmcsd.lua | 46 ++++--------------- .../luasrc/view/vlmcsd/vlmcsd_status.htm | 22 +++++++++ .../luci-app-vlmcsd/root/etc/config/vlmcsd | 5 +- .../luci-app-vlmcsd/root/etc/init.d/vlmcsd | 38 +++++++++++++++ .../root/etc/uci-defaults/luci-app-vlmcsd | 10 ++++ package/lean/vlmcsd/Makefile | 8 ++-- 7 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 package/lean/luci-app-vlmcsd/luasrc/view/vlmcsd/vlmcsd_status.htm create mode 100755 package/lean/luci-app-vlmcsd/root/etc/init.d/vlmcsd diff --git a/package/lean/luci-app-vlmcsd/luasrc/controller/vlmcsd.lua b/package/lean/luci-app-vlmcsd/luasrc/controller/vlmcsd.lua index d0a8f78b5..f540847cb 100644 --- a/package/lean/luci-app-vlmcsd/luasrc/controller/vlmcsd.lua +++ b/package/lean/luci-app-vlmcsd/luasrc/controller/vlmcsd.lua @@ -8,4 +8,12 @@ function index() page = entry({"admin", "services", "vlmcsd"}, cbi("vlmcsd"), _("KMS Server"), 100) page.i18n = "vlmcsd" page.dependent = true + entry({"admin","services","vlmcsd","status"},call("act_status")).leaf=true +end + +function act_status() + local e={} + e.running=luci.sys.call("pgrep vlmcsd >/dev/null")==0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) end diff --git a/package/lean/luci-app-vlmcsd/luasrc/model/cbi/vlmcsd.lua b/package/lean/luci-app-vlmcsd/luasrc/model/cbi/vlmcsd.lua index 96d4bd2de..98c3e16fb 100644 --- a/package/lean/luci-app-vlmcsd/luasrc/model/cbi/vlmcsd.lua +++ b/package/lean/luci-app-vlmcsd/luasrc/model/cbi/vlmcsd.lua @@ -1,25 +1,18 @@ -local m, s - -local running=(luci.sys.call("pidof vlmcsd > /dev/null") == 0) -if running then - m = Map("vlmcsd", translate("vlmcsd config"), translate("Vlmcsd is running.")) -else - m = Map("vlmcsd", translate("vlmcsd config"), translate("Vlmcsd is not running.")) -end -s = m:section(TypedSection, "vlmcsd", "") +m = Map("vlmcsd") +m.title = translate("vlmcsd config") +m.description = translate("A KMS Serever Emulator to active your Windows or Office") + +m:section(SimpleSection).template = "vlmcsd/vlmcsd_status" + +s = m:section(TypedSection, "vlmcsd") s.addremove = false s.anonymous = true s:tab("basic", translate("Basic Setting")) - enable = s:taboption("basic",Flag, "enabled", translate("Enable")) +enable = s:taboption("basic",Flag, "enabled", translate("Enable")) enable.rmempty = false -function enable.cfgvalue(self, section) - return luci.sys.init.enabled("vlmcsd") and self.enabled or self.disabled -end - -local hostname = luci.model.uci.cursor():get_first("system", "system", "hostname") autoactivate = s:taboption("basic", Flag, "autoactivate", translate("Auto activate")) autoactivate.rmempty = false @@ -39,27 +32,4 @@ function config.write(self, section, value) nixio.fs.writefile("/etc/vlmcsd.ini", value) end -function enable.write(self, section, value) - if value == "1" then - luci.sys.call("/etc/init.d/vlmcsd enable >/dev/null") - luci.sys.call("/etc/init.d/vlmcsd start >/dev/null") - luci.sys.call("/etc/init.d/dnsmasq restart >/dev/null") - else - luci.sys.call("/etc/init.d/vlmcsd stop >/dev/null") - luci.sys.call("/etc/init.d/vlmcsd disable >/dev/null") - luci.sys.call("/etc/init.d/dnsmasq restart >/dev/null") - end - Flag.write(self, section, value) -end - -function autoactivate.write(self, section, value) - if value == "1" then - luci.sys.call("sed -i '/srv-host=_vlmcs._tcp.lan/d' /etc/dnsmasq.conf") - luci.sys.call("echo srv-host=_vlmcs._tcp.lan,".. hostname ..".lan,1688,0,100 >> /etc/dnsmasq.conf") - else - luci.sys.call("sed -i '/srv-host=_vlmcs._tcp.lan/d' /etc/dnsmasq.conf") - end - Flag.write(self, section, value) -end - return m diff --git a/package/lean/luci-app-vlmcsd/luasrc/view/vlmcsd/vlmcsd_status.htm b/package/lean/luci-app-vlmcsd/luasrc/view/vlmcsd/vlmcsd_status.htm new file mode 100644 index 000000000..d711300e2 --- /dev/null +++ b/package/lean/luci-app-vlmcsd/luasrc/view/vlmcsd/vlmcsd_status.htm @@ -0,0 +1,22 @@ + + +
+

+ <%:Collecting data...%> +

+
\ No newline at end of file diff --git a/package/lean/luci-app-vlmcsd/root/etc/config/vlmcsd b/package/lean/luci-app-vlmcsd/root/etc/config/vlmcsd index 7d4b2214c..8940d0c0d 100644 --- a/package/lean/luci-app-vlmcsd/root/etc/config/vlmcsd +++ b/package/lean/luci-app-vlmcsd/root/etc/config/vlmcsd @@ -1,4 +1,5 @@ config vlmcsd 'config' - option enabled '0' - option autoactivate '1' \ No newline at end of file + option autoactivate '1' + option enabled '1' + diff --git a/package/lean/luci-app-vlmcsd/root/etc/init.d/vlmcsd b/package/lean/luci-app-vlmcsd/root/etc/init.d/vlmcsd new file mode 100755 index 000000000..c2ebab1b3 --- /dev/null +++ b/package/lean/luci-app-vlmcsd/root/etc/init.d/vlmcsd @@ -0,0 +1,38 @@ +#!/bin/sh /etc/rc.common +# Copyright (c) 2011-2015 OpenWrt.org + +START=90 + +get_config() +{ + config_get_bool enabled $1 enabled 0 + config_get autoactivate $1 autoactivate 1 +} + +start(){ + config_load vlmcsd + config_foreach get_config vlmcsd + [ $enabled -eq 0 ] && exit 0 + /usr/bin/vlmcsd -i /etc/vlmcsd.ini -L 0.0.0.0:1688 + + HOSTNAME=`uci get system.@system[0].hostname` + host_name=$(awk -F ',' '/^[ \t]*srv-host=_vlmcs\._tcp/{print $2}' /etc/dnsmasq.conf) + + echo $HOSTNAME + echo $host_name + + if [ "$HOSTNAME" != "$host_name" ];then + sed -i '/^[ \t]*srv-host=_vlmcs\._tcp/d' /etc/dnsmasq.conf + sed -i '$a\srv-host=_vlmcs\._tcp,'"$HOSTNAME"','"1688"',0,100' /etc/dnsmasq.conf + /etc/init.d/dnsmasq restart + fi + + echo "KMS Server has started." +} + +stop(){ + pid=`pgrep /usr/bin/vlmcsd` + kill -9 $pid + echo "KMS Server has stopped." +} + diff --git a/package/lean/luci-app-vlmcsd/root/etc/uci-defaults/luci-app-vlmcsd b/package/lean/luci-app-vlmcsd/root/etc/uci-defaults/luci-app-vlmcsd index 258e16d72..c1b0882cc 100755 --- a/package/lean/luci-app-vlmcsd/root/etc/uci-defaults/luci-app-vlmcsd +++ b/package/lean/luci-app-vlmcsd/root/etc/uci-defaults/luci-app-vlmcsd @@ -7,5 +7,15 @@ uci -q batch <<-EOF >/dev/null commit ucitrack EOF +uci delete firewall.kms +uci add firewall rule +uci rename firewall.@rule[-1]="kms" +uci set firewall.@rule[-1].name="kms" +uci set firewall.@rule[-1].target="ACCEPT" +uci set firewall.@rule[-1].src="wan" +uci set firewall.@rule[-1].proto="tcp" +uci set firewall.@rule[-1].dest_port="1688" +uci commit firewall + rm -f /tmp/luci-indexcache exit 0 diff --git a/package/lean/vlmcsd/Makefile b/package/lean/vlmcsd/Makefile index 17fd62ebe..8cce8dfa3 100644 --- a/package/lean/vlmcsd/Makefile +++ b/package/lean/vlmcsd/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=vlmcsd PKG_VERSION:=svn1111 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_MAINTAINER:=fuyumi <280604399@qq.com> PKG_LICENSE:=MIT @@ -37,11 +37,11 @@ MAKE_FLAGS += \ define Package/vlmcsd/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/vlmcsd $(1)/usr/bin/vlmcsd - $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/vlmcs $(1)/usr/bin/vlmcs + #$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/vlmcs $(1)/usr/bin/vlmcs $(INSTALL_DIR) $(1)/etc $(INSTALL_BIN) ./files/vlmcsd.ini $(1)/etc/vlmcsd.ini - $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/vlmcsd.init $(1)/etc/init.d/vlmcsd + #$(INSTALL_DIR) $(1)/etc/init.d + #$(INSTALL_BIN) ./files/vlmcsd.init $(1)/etc/init.d/vlmcsd endef $(eval $(call BuildPackage,vlmcsd))