re-add luci-app-usb printer

This commit is contained in:
coolsnowwolf 2018-10-19 13:26:06 +08:00
parent 64c72766f4
commit 29c8928eea
11 changed files with 374 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:=1
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,29 @@
--[[
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)
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,58 @@
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_CN\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 "指定要监听的接口。"

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,12 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@usb_printer[-1]
add ucitrack usb_printer
set ucitrack.@usb_printer[-1].init=usb_printer
commit ucitrack
EOF
[ -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