This commit is contained in:
SirPdboy 2023-01-31 15:49:07 +08:00 committed by GitHub
parent 1b97c3ca3b
commit 5d2ea78352
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 385 additions and 0 deletions

View File

@ -36,6 +36,12 @@ define Package/cups/description
Common UNIX Printing System (daemon)
endef
define Package/cups/conffiles
/etc/cups/classes.conf
/etc/cups/cupsd.conf
/etc/cups/printers.conf
endef
define Package/cups-bsd
$(call Package/cups/Default)
SECTION:=net
@ -56,6 +62,10 @@ $(call Package/cups/Default)
TITLE:=Common UNIX Printing System - Client commands
endef
define Package/cups-client/conffiles
/etc/cups/client.conf
endef
define Package/cups-client/description
Common UNIX Printing System - Client commands
endef
@ -218,7 +228,10 @@ define Package/cups/install
$(1)/usr/share/doc/cups/
$(INSTALL_DIR) $(1)/usr/sbin
# overwrite default config with our own
$(CP) ./files/etc/cups/* $(1)/etc/cups/
# install initscript with priority 60
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/cupsd.init $(1)/etc/init.d/cupsd
$(INSTALL_BIN) \
$(PKG_INSTALL_DIR)/usr/sbin/{cupsctl,cupsd} \
$(1)/usr/sbin/

View File

@ -0,0 +1,52 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
# Copyright (C) 2021-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-cupsd
START=99
USE_PROCD=1
PROG=/usr/sbin/cupsd
get_config() {
config_get_bool enabled $1 enabled 1
config_get_bool logger $1 logger 1
config_get port $1 port 631
}
cups_prepare() {
pgrep -f $PROG | xargs kill -9 >/dev/null 2>&1
logger -t cupsd -p warn "cupsd is stop."
}
cups_set(){
ipaddr=$(uci -q get network.lan.ipaddr 2>/dev/null)
ip=$(echo ${ipaddr%.*})'.0/24'
sed -i "s,Allow From 19.*,Allow From ${ip},g" /etc/cups/cupsd.conf
sed -i "s/Port.*/Port ${port}/g" /etc/cups/cupsd.conf
}
stop_service() {
cups_prepare
}
start_service() {
cups_prepare
config_load cupsd
config_foreach get_config cupsd
[ x$enabled == x1 ] || return 1
cups_set
[ -d /var/cache/cups ] || mkdir -m 0755 -p /var/cache/cups
[ -d /var/cups ] || mkdir -m 0755 -p /var/cups
[ -d /var/spool/cups/tmp ] || mkdir -m 0755 -p /var/spool/cups/tmp
logger -t cupsd -p warn "cupsd is start."
echo "cupsd is start."
procd_open_instance
procd_set_param command $PROG
[ "x$logger" == x1 ] && procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}
service_triggers() {
procd_add_reload_trigger "cupsd"
}

View File

@ -0,0 +1,7 @@
########################################################################
# #
# This is a sample class configuration file. This file is included #
# from the main configuration file (cups.conf) and lists all of the #
# printer classes known to the system. #
# #
########################################################################

View File

@ -0,0 +1,9 @@
########################################################################
# #
# This is the CUPS client configuration file. This file is used to #
# define client-specific parameters, such as the default server or #
# default encryption settings. #
# #
########################################################################
Encryption Never

View File

@ -0,0 +1,58 @@
########################################################################
# #
# This is the CUPS configuration file. If you are familiar with #
# Apache or any of the other popular web servers, we've followed the #
# same format. Any configuration variable used here has the same #
# semantics as the corresponding variable in Apache. If we need #
# different functionality then a different name is used to avoid #
# confusion... #
# #
########################################################################
AccessLog syslog
ErrorLog syslog
LogLevel info
PageLog syslog
PreserveJobHistory No
PreserveJobFiles No
AutoPurgeJobs Yes
MaxJobs 25
MaxPrinterHistory 10
#Printcap /etc/printcap
#PrintcapFormat BSD
RequestRoot /var/cups
#RemoteRoot remroot
#User nobody
#Group nogroup
# root permissions required to make cups work with the usb backend
User root
Group root
RIPCache auto
TempDir /var/cups
Port 631
HostNameLookups On
KeepAlive On
# No: "BrowseOrder" "BrowseAllow" "BrowseRemoteProtocols"
Browsing Yes
BrowsingWebIF Yes
BrowseLocalProtocols DNSSD
DefaultShared Yes
WebInterface Yes
Listen /var/run/cups/cups.sock
ServerAlias *
<Location />
Order Allow,Deny
Allow From 127.0.0.1
Allow From 192.168.8.0/24
</Location>
<Location /admin>
AuthType Basic
AuthClass System
Order Allow,Deny
Allow From 127.0.0.1
Allow From 192.168.8.0/24
</Location>

View File

@ -0,0 +1,23 @@
<DefaultPrinter USB>
Info USB Printer
Location
DeviceURI usb:/dev/usb/lp0
State Idle
Accepting Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>
<Printer LP>
Info Parallel Port Printer
Location
DeviceURI parallel:/dev/printers/0
State Idle
Accepting Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>

View File

@ -0,0 +1,15 @@
#
#-- Copyright (C) 2018 dz <dingzhong110@gmail.com>
# Copyright (C) 2021-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-cupsd
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Support for cupsd
LUCI_DEPENDS:= +cups
PKG_VERSION:=1.3
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,64 @@
### 访问数:[![](https://visitor-badge.glitch.me/badge?page_id=sirpdboy-visitor-badge)] [![](https://img.shields.io/badge/TG群-点击加入-FFFFFF.svg)](https://t.me/joinchat/AAAAAEpRF88NfOK5vBXGBQ)
欢迎来到sirpdboy的源码仓库
---------------
[luci-app-cupsd 打印机网络共享 ](https://github.com/sirpdboy/luci-app-cupsd)
======================
git clone https://github.com/sirpdboy/luci-app-cupsd.git
cd openwrt
echo "src-git cups https://github.com/sirpdboy/luci-app-cupsd.git" >> feeds.conf.default
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
set Network -> Printing -> cups
# other cups:
## https://github.com/Gr4ffy/lede-cups
## https://github.com/TheMMcOfficial/lede-cups
# My other project
网络速度测试 https://github.com/sirpdboy/NetSpeedTest
定时设置插件 : https://github.com/sirpdboy/luci-app-autotimeset
关机功能插件 : https://github.com/sirpdboy/luci-app-poweroffdevice
opentopd主题 : https://github.com/sirpdboy/luci-theme-opentopd
opentoks 主题: https://github.com/sirpdboy/luci-theme-opentoks [仿KOOLSAHRE主题]
btmob 主题: https://github.com/sirpdboy/luci-theme-btmob
系统高级设置 : https://github.com/sirpdboy/luci-app-advanced
ddns-go动态域名: https://github.com/sirpdboy/luci-app-ddns-go
## 捐助
-如果你觉得此项目对你有帮助,请捐助我们,以使项目能持续发展,更加完善。··请作者喝杯咖啡~~~**
-你们的支持就是我的动力!**
| <img src="https://img.shields.io/badge/-支付宝-F5F5F5.svg" href="#赞助支持本项目-" height="25" alt="图飞了<E9A39E><E4BA86><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"/> | <img src="https://img.shields.io/badge/-微信-F5F5F5.svg" height="25" alt="图飞了<E9A39E><E4BA86><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" href="#赞助支持本项目-"/> |
| :-----------------: | :-------------: |
|![xm1](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/支付宝.png) | ![xm1](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/微信.png) |
<a href="#readme">
<img src="https://img.shields.io/badge/-返回顶部-orange.svg" alt="图飞了<E9A39E><E4BA86><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" title="返回顶部" align="right"/>
</a>

View File

@ -0,0 +1,26 @@
-- Copyright (C) 2018 dz <dingzhong110@gmail.com>
-- mod by 2021-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-cupsd
module("luci.controller.cupsd", package.seeall)
function index()
if not nixio.fs.access("/etc/config/cupsd") then
return
end
entry({"admin", "services", "cupsd"},alias("admin", "services", "cupsd","basic"),_("CUPS打印服务器"),60).dependent = true
entry({"admin", "services", "cupsd","basic"}, cbi("cupsd/basic"),_("设置"),10).leaf = true
entry({"admin", "services", "cupsd","advanced"}, cbi("cupsd/advanced"),_("高级"),20).leaf = true
entry({"admin", "services", "cupsd_status"}, call("act_status"))
end
function act_status()
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor()
local port = tonumber(uci:get_first("cupsd", "cupsd", "port") )
local e = { }
e.running = sys.call("pidof cupsd > /dev/null") == 0
e.port = port or 631
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@ -0,0 +1,29 @@
local fs = require "nixio.fs"
local sys = require "luci.sys"
m = Map("cupsd", translate("<font color=\"green\">CUPS高级配置</font>"), translate("<font color=\"red\">此处修改的是/etc/cups/cupsd.conf文件。</font><input class=\"cbi-button cbi-button-apply\" type=\"submit\" value=\" "..translate("点击此处可下载并浏览添加打印机教程文件").." \" onclick=\"window.open('http://'+window.location.hostname+'/cups.pdf')\"/>"))
s = m:section(TypedSection, "cupsd")
s.anonymous=true
o = s:option(TextValue, "/etc/cups/cupsd.conf")
o.rows = 20
o.wrap = "off"
function o.cfgvalue(self, section)
return fs.readfile("/etc/cups/cupsd.conf") or ""
end
function o.write(self, section, value)
if value then
value = value:gsub("\r\n?", "\n")
fs.writefile("/tmp/cupsd.conf", value)
if (luci.sys.call("cmp -s /tmp/cupsd.conf /etc/cups/cupsd.conf") == 1) then
fs.writefile("/etc/cups/cupsd.conf", value)
luci.sys.call("/etc/init.d/cupsd reload >/dev/null")
end
fs.remove("/tmp/cupsd.conf")
end
end
return m

View File

@ -0,0 +1,32 @@
-- Copyright 2008 Yanira <forum-2008@email.de>
-- Licensed to the public under the Apache License 2.0.
-- mod by wulishui 20191205
-- mod by 2021-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-cupsd
local m, s, o
m = Map("cupsd", translate("CUPS打印服务器"))
m.description = translate("<font color=\"green\">CUPS是苹果公司为MacOS和其他类似UNIX的操作系统开发的基于标准的开源打印系统。</font>"..translate("</br>For specific usage, see:")..translate("<a href=\'https://github.com/sirpdboy/luci-app-cupsd.git' target=\'_blank\'>GitHub @sirpdboy/luci-app-cupsd </a>") )
m:section(SimpleSection).template = "cupsd_status"
s = m:section(TypedSection, "cupsd", translate("Global Settings"))
s.addremove=false
s.anonymous = true
o=s:option(Flag, "enabled", translate("Enable"))
o.default=0
o=s:option(Value, "port", translate("WEB管理端口"),translate("可随意设定为无冲突的端口,对程序运行无影响。"))
o.datatype="uinteger"
o.default=631
o:depends("enabled",1)
local e=luci.http.formvalue("cbi.apply")
if e then
io.popen("/etc/init.d/cupsd start")
end
return m

View File

@ -0,0 +1,26 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[cupsd_status]])%>', null,
function(x, data) {
var tb = document.getElementById('cupsd_status');
if (data && tb)
{
if (data.running)
{
tb.innerHTML = '<br/><em style=\"color:green\"><%:cupsd服务已启动%></em>'
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:点击打开cupsd%> \" onclick=\"window.open('http://" + window.location.hostname + ":" + data.port + "/')\"/>";
}
else
{
tb.innerHTML = '<br/><em style=\"color:red\"><%:cupsd服务未启动%></em>';
}
}
}
);
//]]></script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<legend><%:cupsd状态%></legend>
<p id="cupsd_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -0,0 +1,5 @@
config cupsd
option enabled '0'
option logger '1'
option port '631'

View File

@ -0,0 +1,15 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@cupsd[-1]
add ucitrack cupsd
set ucitrack.@cupsd[-1].init=cupsd
commit ucitrack
EOF
/etc/init.d/cupsd stop
/etc/init.d/cupsd start
rm -f /tmp/luci*
exit 0

View File

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

Binary file not shown.