hsdn / pwhoisd
PHP Whois 服务器守护进程
dev-master
2020-05-07 12:31 UTC
This package is auto-updated.
Last update: 2024-09-07 23:31:35 UTC
README
简单且性能优越的 Whois 服务器守护进程,符合 RFC 3912 标准,使用 TCP 端口 43(服务 "whois")。使用 PHP 编写,采用多线程架构。守护进程支持 MySQL 数据库和灵活的数据输出格式配置。还基于 ACL 有一个良好的访问控制系统。
通用特性
- 完全符合 RFC 3912 标准。
- 基于 PCNTL 函数的多线程架构。
- 将数据存储在 MySQL 数据库中(一个或多个数据表)。
- 基于 ACL 的强大访问控制和请求速率限制控制系统。
- 使用标准的 PHP 函数和方法格式化 Whois 输出。
- 支持客户端请求中的特殊标志,以更改数据源或输出格式。
- 完全支持 IPv6 协议(包括 ACL)。
- 支持不同日志级别的日志文件保存。
有关服务器功能完整信息的详细信息,请参阅文件: src/config.php。
系统要求
- PHP 版本 5.4.0 及以上,并支持 POSIX 函数。
- PCNTL PHP 扩展。
- Filter PHP 扩展。
- GMP 或 BCMATH PHP 扩展。
- Sockets PHP 扩展。
安装
- 将文件 bin/pwhoisd.phar 复制到您的可执行文件目录,例如 /usr/local/sbin。
- 将配置文件 src/config.php 复制到您的 etc/pwhoisd 目录,例如 /usr/local/etc/pwhoisd。
- 编辑 pwhoisd 的配置文件中的参数。
- 创建 MySQL 数据库,并从 SQL 文件 share/example_pwhoisd.sql 中导入示例表。
- 使用命令运行服务器进行测试: php /usr/local/sbin/pwhoisd.phar --config=/usr/local/etc/pwhoisd/config.php。
- 使用 telnet 或 whois 命令测试服务器: whois -h 127.0.0.1 "hsdn.ru"(您应该得到下面的示例输出)。
作为守护进程运行服务器
要作为守护进程启动服务器,请使用命令行参数 --daemon。可选地,您可以使用参数 --pidfile=/var/run/pwhoisd.pid 指定 PID 文件的路径。
服务器还可以使用启动 rc 脚本运行。FreeBSD 系统的脚本如下所示
#!/bin/sh # PROVIDE: pwhoisd # REQUIRE: DAEMON # BEFORE: LOGIN # KEYWORD: shutdown # Define these pwhoisd_* variables in one of these files: # /etc/rc.conf # /etc/rc.conf.local # # DO NOT CHANGE THESE DEFAULT VALUES HERE # pwhoisd_enable=${pwhoisd_enable-"NO"} . /etc/rc.subr name="pwhoisd" rcvar=`set_rcvar` load_rc_config $name : ${pwhoisd_enable="NO"} : ${pwhoisd_conf="/usr/local/etc/pwhoisd/config.php"} : ${pwhoisd_piddir="/var/run"} pidfile="${pwhoisd_piddir}/pwhoisd.pid" command_interpreter="php" command_args="--config=${pwhoisd_conf} --pidfile=${pidfile} --daemon" command="/usr/local/sbin/pwhoisd.phar" run_rc_command "$1"
- 将此脚本复制到您的 rc.d 目录 /usr/local/etc/rc.d/,文件名为 pwhoisd
- 设置权限: chmod 555 /usr/local/etc/rc.d/pwhoisd。
- 使用命令运行服务器守护进程: /usr/local/etc/rc.d/pwhoisd start。
注意:确保文件的正确路径,并且不要忘记在 /etc/rc.conf 中添加一行 pwhoisd_enable="YES"。
服务器命令行参数
用法: pwhoisd.phar [--config=file] [--pidfile=file] [--uid=identifier] [--gid=identifier] [--daemon]
- --config 主要配置文件
- --pidfile 保存进程 ID 的文件
- --uid 指定进程的 UID
- --gid 指定进程的 GID
- --daemon 在后台模式下运行进程
- --help 仅显示此帮助信息
ACL 配置
默认情况下,所有连接都被允许,并且不应用任何限制。
访问规则格式
['ACTION'(, 'MESSAGE')(, ['VARIABLE', 'OPERATOR', 'VALUE/UNIT'])(, ['VARIABLE', 'OPERATOR', 'VALUE/UNIT'])(, ...)]
ACTION
- allow 允许客户端连接和请求。
- deny 向客户端打印指定的消息(可选)并断开连接。
- drop 静默地断开客户端连接。不发送任何消息。
MESSAGE
在此指定消息数组配置中的部分名称。
VARIABLE
- client_ip 客户端连接IP地址(用于IP/子网检查)。
- requests 用于指定针对特定客户端连接的请求速率限制。
- rate 用于指定针对所有客户端连接的全局服务器请求速率限制。
操作符
允许的操作符之一。不得用于IP规则。允许的操作符包括
- < 小于。
- == 等于。
- <= 小于或等于。
- > 大于。
- >= 大于或等于。
值
对于请求速率规则,指定一个带有单位(见下文)的数值。它也可以是单个IP地址(子网,CIDR格式)或IP地址(子网)数组。
单位
允许的单位之一。不得用于IP规则。允许的单位包括
- sec 秒。
- hr 小时。
- min 分钟。
- day 天。
ACL规则示例
'rules' => [ // Drop all connections if server rate more 20 requests per one seconds // This rule will work with the previous rules (sets a global server rate limits). ['drop', ['rate', '>', '20/sec']], // Allow all connections from IP 127.0.0.1. // It is owerride previous (bottom) 'deny' rule for this IP (limits do not works) ['allow', ['client_ip', '127.0.0.1']], // Deny any client if rate more 50 requests per one minute. ['deny', 'limit_exceeded', ['requests', '>', '50/min']], // Permit all connections (it is first rule). ['allow'], ],
演示
示例:从数据库中输出的ICANN PIR/PDR格式的Whois输出
Domain Name:PIR.ORG
Domain ID:D96207-LROR
Creation Date:1996-02-18T05:00:00Z
Updated Date:2015-02-20T01:41:55Z
Registry Expiry Date:2016-02-19T05:00:00Z
Sponsoring Registrar:GoDaddy.com, LLC (R91-LROR)
Sponsoring Registrar IANA ID:146
WHOIS Server:
Referral URL:
Domain Status:serverDeleteProhibited
Domain Status:serverTransferProhibited
Domain Status:serverUpdateProhibited
Registrant ID:GODA-02131674
Registrant Name:Registration Private
Registrant Organization:Domains By Proxy, LLC
Registrant Street: DomainsByProxy.com
Registrant Street: 14747 N Northsight Blvd Suite 111, PMB 309
Registrant City:Scottsdale
Registrant State/Province:Arizona
Registrant Postal Code:85260
Registrant Country:US
Registrant Phone:+1.4806242599
Registrant Phone Ext:
Registrant Fax: +1.4806242598
Registrant Fax Ext:
Registrant Email:
...
Name Server:NS1.AMS1.AFILIAS-NST.INFO
Name Server:NS1.MIA1.AFILIAS-NST.INFO
Name Server:NS1.SEA1.AFILIAS-NST.INFO
Name Server:NS1.YYZ1.AFILIAS-NST.INFO
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
DNSSEC:signedDelegation
DS Created 1:2010-03-26T16:52:50Z
DS Key Tag 1:54135
Algorithm 1:5
Digest Type 1:1
Digest 1:225F055ACB65C8B60AD18B3640062E8C23A5FD89
DS Maximum Signature Life 1:1814400 seconds
示例:从数据库中输出的RIPN格式的Whois输出
% By submitting a query to RIPN's Whois Service
% you agree to abide by the following terms of use:
% http://www.ripn.net/about/servpol.html#3.2 (in Russian)
% http://www.ripn.net/about/en/servpol.html#3.2 (in English).
domain: HSDN.RU
nserver: ns1.hsdn.org.
nserver: ns2.hsdn.org.
nserver: ns3.hsdn.org.
nserver: ns4.hsdn.org.
state: REGISTERED, DELEGATED, VERIFIED
org: OOO "Informacionnye Seti"
registrar: NAUNET-RU
created: 2009.02.05
paid-till: 2016.02.05
free-date: 2016.03.07
source: TCI
Last updated on 2015.04.20 05:01:51 MSK
许可证
PHP Whois Server Daemon
The MIT License (MIT)
Copyright (c) 2015 Information Networks, Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.