update 2024-10-16 19:54:17

This commit is contained in:
kenzok8 2024-10-16 19:54:17 +08:00
parent bf4e497300
commit 829155c9d9
25 changed files with 709 additions and 0 deletions

View File

@ -0,0 +1,18 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=USB Printer Share via TCP/IP
LUCI_DEPENDS:=+p910nd +kmod-usb-printer
PKG_VERSION:=1.0
PKG_RELEASE:=2
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature
#applications/luci-app-usb-printer/
#applications/luci-app-usb-printer/

View File

@ -0,0 +1,6 @@
#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] || {
( . /etc/uci-defaults/luci-usb-printer ) && rm -f /etc/uci-defaults/luci-usb-printer
exit 0
}

View File

@ -0,0 +1,30 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.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
$Id$
]]--
require("luci.sys")
module("luci.controller.usb_printer", package.seeall)
function index()
if not nixio.fs.access("/etc/config/usb_printer") then
return
end
entry({"admin", "nas"}, firstchild(), "NAS", 44).dependent = false
local page
page = entry({"admin", "nas", "usb_printer"}, cbi("usb_printer"), _("USB Printer Server"), 50)
page.acl_depends = { "luci-app-usb-printer" }
end

View File

@ -0,0 +1,130 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2005-2013 hackpascal <hackpascal@gmail.com>
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
$Id$
]]--
require "luci.util"
local uci = luci.model.uci.cursor_state()
local net = require "luci.model.network"
m = Map("usb_printer", translate("USB Printer Server"),
translate("Shares multiple USB printers via TCP/IP.<br />When modified bingings, re-plug usb connectors to take effect.<br />This module requires kmod-usb-printer."))
function hex_align(hex, num)
local len = num - string.len(hex)
return string.rep("0", len) .. hex
end
function detect_usb_printers()
local data = {}
local lps = luci.util.execi("/usr/bin/detectlp")
for value in lps do
local row = {}
--[[
detectlp
VID/PID/?,
]]--
local pos = string.find(value, ",")
local devname = string.sub(value, 1, pos - 1)
local value = string.sub(value, pos + 1, string.len(value))
pos = string.find(value, ",")
local product = string.sub(value, 1, pos - 1)
value = string.sub(value, pos + 1, string.len(value))
pos = string.find(value, ",")
local model = string.sub(value, 1, pos - 1)
local name = string.sub(value, pos + 1, string.len(value))
pos = string.find(product, "/");
local vid = string.sub(product, 1, pos - 1)
local pid = string.sub(product, pos + 1, string.len(product))
pos = string.find(pid, "/")
pid = string.sub(pid, 1, pos - 1)
row["description"] = name
row["model"] = model
row["id"] = hex_align(vid, 4) .. ":" .. hex_align(pid, 4)
row["name"] = devname
row["product"] = product
table.insert(data, row)
end
return data
end
local printers = detect_usb_printers()
v = m:section(Table, printers, translate("Detected printers"))
v:option(DummyValue, "description", translate("Description"))
v:option(DummyValue, "model", translate("Printer Model"))
v:option(DummyValue, "id", translate("VID/PID"))
v:option(DummyValue, "name", translate("Device Name"))
net = net.init(m.uci)
s = m:section(TypedSection, "printer", translate("Bindings"))
s.addremove = true
s.anonymous = true
s:option(Flag, "enabled", translate("enable"))
d = s:option(Value, "device", translate("Device"))
d.rmempty = true
for key, item in ipairs(printers) do
d:value(item["product"], item["description"] .. " [" .. item["id"] .. "]")
end
b = s:option(Value, "bind", translate("Interface"), translate("Specifies the interface to listen on."))
b.template = "cbi/network_netlist"
b.nocreate = true
b.unspecified = true
function b.cfgvalue(...)
local v = Value.cfgvalue(...)
if v then
return (net:get_status_by_address(v))
end
end
function b.write(self, section, value)
local n = net:get_network(value)
if n and n:ipaddr() then
Value.write(self, section, n:ipaddr())
end
end
p = s:option(ListValue, "port", translate("Port"), translate("TCP listener port."))
p.rmempty = true
for i = 0, 9 do
p:value(i, 9100 + i)
end
s:option(Flag, "bidirectional", translate("Bidirectional mode"))
return m

View File

@ -0,0 +1 @@
zh_Hans

View File

@ -0,0 +1,83 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: PACKAGE VERSION\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: zh-Hans\n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
#: luasrc/model/cbi/usb_printer.lua:128
msgid "Bidirectional mode"
msgstr "双向模式"
#: luasrc/model/cbi/usb_printer.lua:90
msgid "Bindings"
msgstr "绑定"
#: luasrc/model/cbi/usb_printer.lua:83
msgid "Description"
msgstr ""
#: luasrc/model/cbi/usb_printer.lua:81
msgid "Detected printers"
msgstr "检测到的打印机"
#: luasrc/model/cbi/usb_printer.lua:96
msgid "Device"
msgstr "设备"
#: luasrc/model/cbi/usb_printer.lua:86
msgid "Device Name"
msgstr "设备名"
#: luasrc/model/cbi/usb_printer.lua:103
msgid "Interface"
msgstr ""
#: luasrc/model/cbi/usb_printer.lua:122
msgid "Port"
msgstr "端口"
#: luasrc/model/cbi/usb_printer.lua:84
msgid "Printer Model"
msgstr "打印机型号"
#: luasrc/model/cbi/usb_printer.lua:21
msgid ""
"Shares multiple USB printers via TCP/IP.<br />When modified bingings, re-"
"plug usb connectors to take effect.<br />This module requires kmod-usb-"
"printer."
msgstr ""
"通过 TCP/IP 共享 USB 打印机。<br />修改设置后,请重新连接打印机以使设置生效。"
"<br />此模块需要 kmod-usb-printer 支持。"
#: luasrc/model/cbi/usb_printer.lua:103
msgid "Specifies the interface to listen on."
msgstr "指定要监听的接口。"
#: luasrc/model/cbi/usb_printer.lua:122
msgid "TCP listener port."
msgstr "TCP 监听端口。"
#: luasrc/controller/usb_printer.lua:28 luasrc/model/cbi/usb_printer.lua:20
msgid "USB Printer Server"
msgstr "USB 打印服务器"
#: luasrc/model/cbi/usb_printer.lua:85
msgid "VID/PID"
msgstr ""
#: luasrc/model/cbi/usb_printer.lua:94
msgid "enable"
msgstr "启用"
#~ msgid "Settings"
#~ msgstr "设置"
#~ msgid "NAS"
#~ msgstr "网络存储"
#~ msgid "Architecture"
#~ msgstr "架构"

View File

@ -0,0 +1,65 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-05-18 01:34+0800\n"
"PO-Revision-Date: 2014-05-18 01:34+0800\n"
"Last-Translator: hackpascal <hackpascal@gmail.com>\n"
"Language-Team: \n"
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Pootle 2.0.6\n"
msgid "Bidirectional mode"
msgstr "双向模式"
msgid "Bindings"
msgstr "绑定"
msgid "Device"
msgstr "设备"
msgid "Device Name"
msgstr "设备名"
msgid "Detected printers"
msgstr "检测到的打印机"
msgid ""
"Shares multiple USB printers via TCP/IP.<br />"
"When modified bingings, re-plug usb connectors to take effect.<br />"
"This module requires kmod-usb-printer."
msgstr ""
"通过 TCP/IP 共享 USB 打印机。<br />修改设置后,请重新连接打印机以使设置生效。<br />"
"此模块需要 kmod-usb-printer 支持。"
msgid "Port"
msgstr "端口"
msgid "Printer Model"
msgstr "打印机型号"
msgid "Settings"
msgstr "设置"
msgid "TCP listener port."
msgstr "TCP 监听端口。"
msgid "enable"
msgstr "启用"
msgid "USB Printer Server"
msgstr "USB 打印服务器"
msgid "Specifies the interface to listen on."
msgstr "指定要监听的接口。"
msgid "NAS"
msgstr "网络存储"
msgid "Architecture"
msgstr "架构"

View File

@ -0,0 +1,7 @@
#!/bin/sh
# Copyright (C) 2005-2014 NowRush Studio
# Author: hackpascal <hackpascal@gmail.com>
if [ x"$INTERFACE" = x"7/1/1" ] || [ x"$INTERFACE" = x"7/1/2" ]; then
/usr/bin/usb_printer_hotplug "$PRODUCT" "$ACTION"
fi

View File

@ -0,0 +1,22 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2005-2013 NowRush Studio
# Author: hackpascal <hackpascal@gmail.com>
START=70
stop() {
killall p910nd 2>/dev/null
}
start() {
for lps in `/usr/bin/detectlp`; do
product=`echo $lps | cut -d , -f 2`
/usr/bin/usb_printer_hotplug "$product" add
done
}
restart() {
stop
start
}

View File

@ -0,0 +1,5 @@
#!/bin/sh
[ -f /etc/init.d/p910nd ] && /etc/init.d/p910nd disable
exit 0

View File

@ -0,0 +1,20 @@
#!/bin/sh
lp_path=/sys/class/usbmisc
if ! [ -d "$lp_path" ]; then
exit
fi
cd $lp_path
for lps in `ls`; do
desc_file=$lp_path/$lps/device/ieee1284_id
uevent_file=$lp_path/$lps/device/uevent
name=`cat $desc_file | sed 's/.*DES:\(.*\);.*/\1/' | cut -d ';' -f 1`
model=`cat $desc_file | sed 's/.*MDL:\(.*\);.*/\1/' | cut -d ';' -f 1`
product=`cat $uevent_file | grep PRODUCT= | sed 's/PRODUCT=\(.*\)/\1/'`
echo $lps,$product,$model,$name;
done

View File

@ -0,0 +1,72 @@
#!/bin/sh
# Copyright (C) 2005-2014 NowRush Studio
# Author: hackpascal <hackpascal@gmail.com>
. $IPKG_INSTROOT/lib/functions.sh
PRODUCT=$1
ACTION=$2
DEVICES=
check_printer() {
local cfg=$1
local enabled
local device_id
local bind_ip
local port
local bidirect
local device_file
local args=""
local pid_file
config_get_bool enabled "$cfg" enabled 0
[ "$enabled" -eq 0 ] && return 0
config_get device_id "$cfg" device ""
config_get bind_ip "$cfg" bind "0.0.0.0"
config_get port "$cfg" port ""
config_get_bool bidirect "$cfg" bidirectional "0"
if [ -z "$device_id" ] || [ -z "$port" ]; then
return
fi
if [ x"$PRODUCT" != x"$device_id" ]; then
return
fi
device_file=`echo "$DEVICES" | grep $device_id | cut -d , -f 1`
if [ "$ACTION" = "add" ] && [ -z "$device_file" ]; then
return
fi
pid_file=/var/run/p910${port}d.pid
[ -f $pid_file ] && kill `cat $pid_file` 2>/dev/null
if [ "$ACTION" = "add" ]; then
if [ "$bidirect" != 0 ]; then
args='-b'
fi
logger "usb_printer: start p910nd on $bind_ip:$port for /dev/usb/$device_file"
/usr/sbin/p910nd $args -f /dev/usb/$device_file -i $bind_ip $port
fi
}
if [ -z "$PRODUCT" ] || [ -z "$ACTION" ]; then
echo "Arguements required"
exit 1
fi
if [ "$ACTION" != "add" ] && [ "$ACTION" != "remove" ]; then
echo "Invalid action arguement"
exit 1
fi
DEVICES=`/usr/bin/detectlp`
config_load usb_printer
config_foreach check_printer printer

View File

@ -0,0 +1,11 @@
{
"luci-app-usb-printer": {
"description": "Grant UCI access for luci-app-usb-printer",
"read": {
"uci": [ "usb_printer" ]
},
"write": {
"uci": [ "usb_printer" ]
}
}
}

View File

@ -0,0 +1,4 @@
{
"config": "usb_printer",
"init": [ "usb_printer" ]
}

18
luci-app-vlmcsd/Makefile Normal file
View File

@ -0,0 +1,18 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI page for KMS
LUCI_DEPENDS:=+vlmcsd
PKG_VERSION:=1.0
PKG_RELEASE:=5
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,20 @@
module("luci.controller.vlmcsd", package.seeall)
function index()
if not nixio.fs.access("/etc/config/vlmcsd") then
return
end
local page
page = entry({"admin", "services", "vlmcsd"}, cbi("vlmcsd"), _("KMS Server"), 100)
page.i18n = "vlmcsd"
page.dependent = true
page.acl_depends = { "luci-app-vlmcsd" }
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

View File

@ -0,0 +1,35 @@
m = Map("vlmcsd")
m.title = translate("vlmcsd config")
m.description = translate("A KMS Server 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.rmempty = false
autoactivate = s:taboption("basic", Flag, "autoactivate", translate("Auto activate"))
autoactivate.rmempty = false
s:tab("config", translate("Config File"))
config = s:taboption("config", Value, "config", translate("configfile"), translate("This file is /etc/vlmcsd.ini."), "")
config.template = "cbi/tvalue"
config.rows = 13
config.wrap = "off"
function config.cfgvalue(self, section)
return nixio.fs.readfile("/etc/vlmcsd.ini")
end
function config.write(self, section, value)
value = value:gsub("\r\n?", "\n")
nixio.fs.writefile("/etc/vlmcsd.ini", value)
end
return m

View File

@ -0,0 +1,22 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[vlmcsd]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('vlmcsd_status');
if (data && tb) {
if (data.running) {
var links = '<em><b><font color=green>KMS <%:RUNNING%></font></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em><b><font color=red>KMS <%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="vlmcsd_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

1
luci-app-vlmcsd/po/zh-cn Symbolic link
View File

@ -0,0 +1 @@
zh_Hans

View File

@ -0,0 +1,40 @@
msgid ""
msgstr ""
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
msgid "vlmcsd config"
msgstr "KMS 服务器设置"
msgid "KMS Server"
msgstr "KMS 服务器"
msgid "Basic Setting"
msgstr "基本设置"
msgid "Config File"
msgstr "配置文件"
msgid "A KMS Server Emulator to active your Windows or Office"
msgstr "KMS服务器可用于激活Windows或Office"
msgid "<b><font color=green>Vlmcsd is running.</font></b>"
msgstr "<b><font color=green>KMS 服务器运行中</font></b>"
msgid "<b><font color=red>Vlmcsd is not running.</font></b>"
msgstr "<b><font color=red>KMS 服务器未运行</font></b>"
msgid "Enable"
msgstr "启用"
msgid "Auto activate"
msgstr "自动激活局域网客户端"
msgid "configfile"
msgstr "配置文件"
msgid "This file is /etc/vlmcsd.ini."
msgstr "这个文件在 /etc/vlmcsd.ini 下,可以增加新的产品主密钥。"

View File

@ -0,0 +1,40 @@
msgid ""
msgstr ""
"Language: zh_Hant\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
msgid "vlmcsd config"
msgstr "KMS 伺服器設定"
msgid "KMS Server"
msgstr "KMS 伺服器"
msgid "Basic Setting"
msgstr "基礎設定"
msgid "Config File"
msgstr "設定檔案"
msgid "A KMS Server Emulator to active your Windows or Office"
msgstr "KMS 伺服器可用於啟用 Windows 或 Office"
msgid "<b><font color=green>Vlmcsd is running.</font></b>"
msgstr "<b><font color=green>KMS 伺服器正在執行</font></b>"
msgid "<b><font color=red>Vlmcsd is not running.</font></b>"
msgstr "<b><font color=red>KMS 伺服器尚未執行</font></b>"
msgid "Enable"
msgstr "啟用"
msgid "Auto activate"
msgstr "自動啟用"
msgid "configfile"
msgstr "設定檔案"
msgid "This file is /etc/vlmcsd.ini."
msgstr "檔案路徑在 /etc/vlmcsd.ini"

View File

@ -0,0 +1,5 @@
config vlmcsd 'config'
option autoactivate '1'
option enabled '1'

View File

@ -0,0 +1,43 @@
#!/bin/sh /etc/rc.common
# Copyright (c) 2011-2015 OpenWrt.org
START=90
USE_PROCD=1
start_instance() {
config_get_bool enabled $1 enabled 0
config_get autoactivate $1 autoactivate 1
[ $enabled -eq 0 ] && return 0
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 >/dev/null 2>&1
fi
procd_open_instance
procd_set_param command /usr/bin/vlmcsd -D -i /etc/vlmcsd.ini -L 0.0.0.0:1688 -L [::]:1688
procd_append_param command -l /var/log/vlmcsd.log
procd_set_param respawn
procd_set_param file /etc/vlmcsd.ini
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
start_service() {
config_load vlmcsd
config_foreach start_instance vlmcsd
}
service_triggers() {
procd_add_reload_trigger "vlmcsd"
}

View File

@ -0,0 +1,11 @@
{
"luci-app-vlmcsd": {
"description": "Grant UCI access for luci-app-vlmcsd",
"read": {
"uci": [ "vlmcsd" ]
},
"write": {
"uci": [ "vlmcsd" ]
}
}
}