diff --git a/kms/Changelog.txt b/kms/Changelog.txt new file mode 100644 index 0000000..25cd8c5 --- /dev/null +++ b/kms/Changelog.txt @@ -0,0 +1,22 @@ +Koolshare Asuswrt-Merlin kms Changelog +=========================================== +0.1 + - add kms tools +0.2 + - fix auto start +0.3 + - fix error +0.4 + - you know. ah! +0.5 + - you know. ah! +0.6 + - you know. ah! +0.7 + - fix auto active! +0.8 + - fix scripts error. +1.3 + - update binary + - fix port open + - update start up diff --git a/kms/README.md b/kms/README.md new file mode 100644 index 0000000..e511b46 --- /dev/null +++ b/kms/README.md @@ -0,0 +1,2 @@ +# merlin-kms +Office Kms Auto Active diff --git a/kms/backup.sh b/kms/backup.sh new file mode 100755 index 0000000..7a727dc --- /dev/null +++ b/kms/backup.sh @@ -0,0 +1,25 @@ +#! /bin/sh + +# you can do something here +# this shell scripts will run at the end of build.py scripts + + + +mkdir -p history +if [ ! -f ./history/version ];then + touch ./history/version +fi + +version_old=`cat history/version | awk '{print $1}' | sort -rn |sed -n 1p` +version_new=`cat config.json.js |grep "version"|cut -d"\"" -f 4` +md5_old=`cat history/version | sort -nk1 | awk '{print $1}' |sed -n 1p` +md5_new=` md5sum kms.tar.gz | awk '{print $1}'` + +if [ -f ./kms.tar.gz ];then + if [ "$version_old" != "$version_new" ];then + mkdir ./history/$version_new/ + cp ./kms.tar.gz ./history/$version_new/ + echo $version_new $md5_new >> ./history/version + fi +fi + diff --git a/kms/build.py b/kms/build.py new file mode 100755 index 0000000..758dd80 --- /dev/null +++ b/kms/build.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# _*_ coding:utf-8 _*_ + +import os +import json +import codecs +import hashlib +from string import Template + +parent_path = os.path.dirname(os.path.realpath(__file__)) + +def md5sum(full_path): + with open(full_path, 'rb') as rf: + return hashlib.md5(rf.read()).hexdigest() + +def get_or_create(): + conf_path = os.path.join(parent_path, "config.json.js") + conf = {} + if not os.path.isfile(conf_path): + print u"config.json.js 文件找不到,build.py 一定得放插件根目录。自动为您生成一个config.json.js,其它信息请您自己修改。" + module_name = os.path.basename(parent_path) + conf["module"] = module_name + conf["version"] = "0.0.1" + conf["home_url"] = ("Module_%s.asp" % module_name) + conf["title"] = "title of " + module_name + conf["description"] = "description of " + module_name + else: + with codecs.open(conf_path, "r", "utf-8") as fc: + conf = json.loads(fc.read()) + return conf + +def build_module(): + try: + conf = get_or_create() + except: + print u"config.json.js 文件格式错误" + traceback.print_exc() + if "module" not in conf: + print u"没有 module 在 config.json.js 里" + return + module_path = os.path.join(parent_path, conf["module"]) + if not os.path.isdir(module_path): + print u"找不到对应的 %s 文件夹,config.json.js 里面的 module 值不对?" % module_path + return + install_path = os.path.join(parent_path, conf["module"], "install.sh") + if not os.path.isfile(install_path): + print u"找不到对应的 %s 文件,插件确实 install.sh 文件" + return + print u"生成中..." + t = Template("cd $parent_path && rm -f $module.tar.gz && tar -zcf $module.tar.gz $module") + os.system(t.substitute({"parent_path": parent_path, "module": conf["module"]})) + conf["md5"] = md5sum(os.path.join(parent_path, conf["module"] + ".tar.gz")) + conf_path = os.path.join(parent_path, "config.json.js") + with codecs.open(conf_path, "w", "utf-8") as fw: + json.dump(conf, fw, sort_keys = True, indent = 4, ensure_ascii=False, encoding='utf8') + print u"生成完成", conf["module"] + ".tar.gz" + hook_path = os.path.join(parent_path, "backup.sh") + if os.path.isfile(hook_path): + os.system(hook_path) + +build_module() diff --git a/kms/build.sh b/kms/build.sh new file mode 100755 index 0000000..17661a5 --- /dev/null +++ b/kms/build.sh @@ -0,0 +1,30 @@ +#!/bin/sh + + +MODULE=kms +VERSION=1.5 +TITLE=kms +DESCRIPTION=kms +HOME_URL=Module_kms.asp + +# Check and include base +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +if [ "$MODULE" == "" ]; then + echo "module not found" + exit 1 +fi + +if [ -f "$DIR/$MODULE/$MODULE/install.sh" ]; then + echo "install script not found" + exit 2 +fi + +# now include build_base.sh +. $DIR/../softcenter/build_base.sh + +# change to module directory +cd $DIR + +# do something here + +do_build_result diff --git a/kms/config.json.js b/kms/config.json.js new file mode 100644 index 0000000..2c24c30 --- /dev/null +++ b/kms/config.json.js @@ -0,0 +1,8 @@ +{ +"version":"1.5", +"md5":"647a16ede1b4cea1615391b6465b1525", +"home_url":"Module_kms.asp", +"title":"kms", +"description":"kms", +"build_date":"2018-12-06_13:29:29" +} diff --git a/kms/history/1.4/kms.tar.gz b/kms/history/1.4/kms.tar.gz new file mode 100644 index 0000000..5193258 Binary files /dev/null and b/kms/history/1.4/kms.tar.gz differ diff --git a/kms/history/1.5/kms.tar.gz b/kms/history/1.5/kms.tar.gz new file mode 100644 index 0000000..c448b9d Binary files /dev/null and b/kms/history/1.5/kms.tar.gz differ diff --git a/kms/history/version b/kms/history/version new file mode 100644 index 0000000..c7e7372 --- /dev/null +++ b/kms/history/version @@ -0,0 +1,2 @@ +1.4 be5771db13551ef1b87d4dc77eff3fde +1.5 647a16ede1b4cea1615391b6465b1525 diff --git a/kms/kms.tar.gz b/kms/kms.tar.gz new file mode 100644 index 0000000..c448b9d Binary files /dev/null and b/kms/kms.tar.gz differ diff --git a/kms/kms/bin/vlmcsd b/kms/kms/bin/vlmcsd new file mode 100755 index 0000000..42c35e7 Binary files /dev/null and b/kms/kms/bin/vlmcsd differ diff --git a/kms/kms/install.sh b/kms/kms/install.sh new file mode 100644 index 0000000..b3356cc --- /dev/null +++ b/kms/kms/install.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# stop kms first +enable=`dbus get kms_enable` +if [ "$enable" == "1" ];then + restart=1 + dbus set kms_enable=0 + sh /jffs/softcenter/scripts/k3c_kms.sh +fi + +# cp files +cp -rf /tmp/kms/scripts/* /jffs/softcenter/scripts/ +cp -rf /tmp/kms/bin/* /jffs/softcenter/bin/ +cp -rf /tmp/kms/webs/* /jffs/softcenter/webs/ +cp -rf /tmp/kms/res/* /jffs/softcenter/res/ + +# delete install tar +rm -rf /tmp/kms* >/dev/null 2>&1 + +chmod a+x /jffs/softcenter/scripts/k3c_kms.sh +chmod 0755 /jffs/softcenter/bin/vlmcsd + +# re-enable kms +if [ "$restart" == "1" ];then + dbus set kms_enable=1 + sh /jffs/softcenter/scripts/k3c_kms.sh +fi + + + diff --git a/kms/kms/res/icon-kms.png b/kms/kms/res/icon-kms.png new file mode 100644 index 0000000..d971c1f Binary files /dev/null and b/kms/kms/res/icon-kms.png differ diff --git a/kms/kms/scripts/k3c_kms.sh b/kms/kms/scripts/k3c_kms.sh new file mode 100644 index 0000000..e0bbd00 --- /dev/null +++ b/kms/kms/scripts/k3c_kms.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# load path environment in dbus databse +eval `dbus export kms` +source /jffs/softcenter/scripts/base.sh +CONFIG_FILE=/tmp/etc/dnsmasq.user/kms.conf +FIREWALL_START=/jffs/scripts/firewall-start + +start_kms(){ + /jffs/softcenter/bin/vlmcsd + echo "srv-host=_vlmcs._tcp.lan,`uname -n`.lan,1688,0,100" > $CONFIG_FILE + nvram set lan_domain=lan + nvram commit + service restart_dnsmasq + # creating iptables rules to firewall-start + mkdir -p /jffs/scripts + if [ ! -f $FIREWALL_START ]; then + cat > $FIREWALL_START <<-EOF + #!/bin/sh + EOF + fi + + # creat start_up file + if [ ! -L "/jffs/softcenter/init.d/S97Kms.sh" ]; then + ln -sf /jffs/softcenter/scripts/kms.sh /jffs/softcenter/init.d/S97Kms.sh + fi +} +stop_kms(){ + # clear start up command line in firewall-start + killall vlmcsd + rm $CONFIG_FILE + service restart_dnsmasq +} + +open_port(){ + ifopen=`iptables -S -t filter | grep INPUT | grep dport |grep 1688` + if [ -z "$ifopen" ];then + iptables -t filter -I INPUT -p tcp --dport 1688 -j ACCEPT + fi + + if [ ! -f $FIREWALL_START ]; then + cat > $FIREWALL_START <<-EOF + #!/bin/sh + EOF + fi + + fire_rule=$(cat $FIREWALL_START | grep 1688) + if [ -z "$fire_rule" ];then + cat >> $FIREWALL_START <<-EOF + iptables -t filter -I INPUT -p tcp --dport 1688 -j ACCEPT + EOF + fi +} + +close_port(){ + ifopen=`iptables -S -t filter | grep INPUT | grep dport |grep 1688` + if [ ! -z "$ifopen" ];then + iptables -t filter -D INPUT -p tcp --dport 1688 -j ACCEPT + fi + + fire_rule=$(cat $FIREWALL_START | grep 1688) + if [ ! -z "$fire_rule" ];then + sed -i '/1688/d' $FIREWALL_START >/dev/null 2>&1 + fi +} + +case $ACTION in +start) + if [ "$kms_enable" == "1" ]; then + logger "[软件中心]: 启动KMS!" + start_kms + [ "$kms_wan_port" == "1" ] && open_port + else + logger "[软件中心]: KMS未设置开机启动,跳过!" + fi + ;; +stop) + close_port >/dev/null 2>&1 + stop_kms + ;; +*) + if [ "$kms_enable" == "1" ]; then + close_port >/dev/null 2>&1 + stop_kms + start_kms + [ "$kms_wan_port" == "1" ] && open_port + else + close_port + stop_kms + fi + ;; +esac diff --git a/kms/kms/uninstall.sh b/kms/kms/uninstall.sh new file mode 100644 index 0000000..7d5d08f --- /dev/null +++ b/kms/kms/uninstall.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +rm /jffs/softcenter/bin/vlmcsd +rm /jffs/softcenter/res/icon-kms.png +rm /jffs/softcenter/scripts/k3c_kms.sh +rm /jffs/softcenter/webs/Module_kms.asp diff --git a/kms/kms/webs/Module_kms.asp b/kms/kms/webs/Module_kms.asp new file mode 100644 index 0000000..600e6cd --- /dev/null +++ b/kms/kms/webs/Module_kms.asp @@ -0,0 +1,216 @@ + + +
+ + + + + + +