eriktorsner/wp-checksum

检查插件和主题的一致性

安装数: 2,594

依赖项: 0

建议者: 0

安全性: 0

星标: 43

关注者: 7

分支: 4

开放问题: 7

类型:wp-cli-package

0.3.0 2017-01-14 13:09 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:36:53 UTC


README

Build Status codecov license

wp-checksum 是一个 wp-cli 子命令,用于验证主题和插件的校验和数据。它检查每个插件和主题内部所有文件的 md5 校验和,并将其与 WordPress 仓库中相同插件/主题的外观进行比较。核心 wp-cli 命令为此功能提供了支持,这个子命令为插件和主题提供了相同的功能。

wp-checksum 会检查添加、删除或修改的文件,并打印出关于与 .org 仓库中原始文件不匹配的文件的信息。

后端 API

wp-checksum 使用后端 API(《https://api.wpessentials.io》 https://api.wpessentials.io)从我们的数据库中检索已知插件和主题的校验和。也可以在本地模式下运行 wp-checksum。在这种情况下,wp-checksum 将直接从 WordPress.org 仓库下载 zip 文件,避免使用 API。与本地模式相比,使用 API 有几个优点:

  • 性能
  • 可靠性
  • WordPress.org 并不保留所有插件的所有版本的 zip 文件,大约 15% 的插件受影响。远程 API 可以提供这些插件的校验和数据,但在本地运行 wp-checksum 时则不可行。
  • diff 子命令目前仅支持远程 API

有关 API 和每小时速率限制如何工作的更多信息,请参阅下面的“后端 API 和速率限制”部分。

已知问题

  • 不忽略插件/主题的 readme.txt 文件中的细微变化。这可能导致假阳性
  • 如果官方仓库中的插件或主题与本地开发的插件或主题名称相同,则可能会触发假阳性。
  • 不知道如何验证付费插件。
  • 一些插件和主题可能没有所有历史版本可用,因此无法进行检查(但谁会使用旧的插件版本呢?)
  • 一些插件将文件添加到自己的安装文件夹中。这将触发假阳性

安装

全局,作为 wp-cli 包

wp package install eriktorsner/wp-checksum

通过 composer

wp-checksum 还可以通过手动或 composer 安装。

$ composer require eriktorsner/wp-checksum

要激活通过 composer 本地安装的 wp-checksum,您需要编辑(或创建)您的 wp-cli.yml 文件,确保它包含 vendor/autoload.php 文件。

require:
    - vendor/autoload.php
path: /path/to/my/wordpress/installation

运行 wp-checksum

### SYNOPSIS

  wp checksum <command>

### SUBCOMMANDS

  all           Verify integrity of plugins and themes by comparing file checksums
  plugin        Verify integrity of all plugins by comparing file checksums
  theme         Verify integrity of all themes by comparing file checksums
  diff          Diff a file in your local WordPress install with it's original
  apikey        Get or set the api key stored in WordPress options table
  quota         Print API rate limits for current api key
  register      Register email address for the current api key to increase hourly quota.

全局选项

  • --format 可选。如何格式化输出。表(默认),json,csv 或 yaml
  • --apikey 可选。指定密钥以覆盖默认密钥
  • --local 可选。在本地模式下运行。从 wordpress.org 下载 zip 文件进行本地提取和比较。
  • --localcache 可选。指定 wp-checksum 存储下载的 zip 文件的目录。默认为 /tmp

wp checksum all|theme|plugin

wp-checksum 的基本功能。验证所有(all)、所有插件(plugin)或所有主题(theme)的本地校验和数据。对于插件和主题子命令,您可以可选地指定一个 slug 以仅验证特定的插件或主题。

选项

  • slug 可选。要检查的特定插件或主题的名称。留空以检查所有已安装的
  • --format 可选。如何格式化输出。表(默认),json,csv 或 yaml
  • --details 可选。设置此标志以输出有关所有修改/添加/删除文件的所有详细信息
  • --apikey 可选。指定密钥以覆盖默认密钥

wp checksum diff <type> [<slug>] <path>

比较本地 WordPress 安装中的文件与其原始版本

选项

  • type 核心文件、主题或插件
  • slug 识别插件或主题的 slug。对于核心文件,跳过此参数
  • path 要检查的文件的路径,相对于核心、主题或插件的根目录

diff命令确定要比较的对象的本地版本,然后检索相应的原始文件。如果两个文件都找到,则使用diff命令比较这两个文件。输出被着色,以便于显示本地版本中新或更改的行是红色的。

wp校验和配额

显示当前的API速率限制使用情况。

选项

  • --apikey 可选。指定密钥以覆盖默认密钥

wp校验和apikey <action> [<apikey>]

获取或设置当前WordPress安装中存储的API密钥。

选项

  • action 必需的。获取(打印)或设置(存储)默认密钥
  • apikey 对于action=set必需。指定要存储为WP选项表中默认密钥的密钥

wp校验和register <email>

将您的电子邮件地址连接到默认(或通过--apikey指定的)密钥,以提高您的小时API速率限制。

选项

  • email 必需的。获取(打印)或设置(存储)默认密钥

示例

# Check themes and plugins, format output as table (default), use API
$ wp checksum all
# Check themes and plugins, use locally stored zipfiles in /tmp 
$ wp checksum all --local
# Check themes and plugins, use locally stored zipfiles in /var/zipcache 
$ wp checksum all --local --localcache=/var/zipcache
# Only check themes, format as json and include details
$ wp checksum theme --format=json --details
# Check a specific theme, format as yaml and include details
$ wp checksum theme twentysixteen --format=yaml --details
# Only check plugins, omit all output except the actual data table
$ wp checksum plugin --quiet
# Check a specific plugin
$ wp checksum plugin jetpack
# Diff a core file
$ wp checksum diff core wp-admin/about.php
# Diff a plugin file
$ wp checksum diff plugin hello-dolly hello.php
# Diff a theme file
$ wp checksum diff theme twentytwelve 404.php
# Check the current API rate limit for the current api key
$ wp checksum quota
# Check the current API rate limit for a specific api key
$ wp checksum quota --apikey=ABC123
# Register email address to trigger validation email
$ wp checksum register me@example.com
# See the default api key
$ wp checksum apikey get
# Set a new default api key
$ wp checksum apikey set ABC123

输出

默认情况下,wp-checksum将输出一个包含检测到的更改数量的信息表;

在这个例子中,有两个付费插件和两个来自仓库的插件。付费插件无法进行检查。其中一个被检查的插件有问题,另一个没有问题

$ wp checksum plugin --quiet
+--------+-----------------------------------+-----------+---------+------------------+--------+
| Type   | Slug                              | Status    | Version | Result           | Issues |
+--------+-----------------------------------+-----------+---------+------------------+--------+
| plugin | homepage-control                  | Checked   | 2.0.2   | Changes detected | 2      |
| plugin | storefront-designer               | Unchecked | 1.8.4   |                  |        |
| plugin | storefront-woocommerce-customiser | Unchecked | 1.9.1   |                  |        |
| plugin | wp-cfm                            | Checked   | 1.4.5   | Ok               | 0      |
+--------+-----------------------------------+-----------+---------+------------------+--------+

要获取更多详细信息,可以使用--details开关

$ wp checksum plugin --quiet --details
+--------+-----------------------------------+-----------+---------+------------------+----------------------------------------------------+
| Type   | Slug                              | Status    | Version | Result           | Issues                                             |
+--------+-----------------------------------+-----------+---------+------------------+----------------------------------------------------+
| plugin | homepage-control                  | Checked   | 2.0.2   | Changes detected | {"index.php":"MODIFIED","warez_virus.php":"ADDED"} |
| plugin | storefront-designer               | Unchecked | 1.8.4   |                  |                                                    |
| plugin | storefront-woocommerce-customiser | Unchecked | 1.9.1   |                  |                                                    |
| plugin | wp-cfm                            | Checked   | 1.4.5   | Ok               |                                                    |
+--------+-----------------------------------+-----------+---------+------------------+----------------------------------------------------+

当然,在yaml或json中使用详细输出更有意义

[{
	"Type": "plugin",
	"Slug": "homepage-control",
	"Status": "Checked",
	"Version": "2.0.2",
	"Result": "Changes detected",
	"Issues": {
		"index.php": "MODIFIED",
		"warez_virus.php": "ADDED"
	}
}, {
	"Type": "plugin",
	"Slug": "storefront-designer",
	"Status": "Unchecked",
	"Version": "1.8.4",
	"Result": null,
	"Issues": null
}, {
	"Type": "plugin",
	"Slug": "storefront-woocommerce-customiser",
	"Status": "Unchecked",
	"Version": "1.9.1",
	"Result": null,
	"Issues": null
}, {
	"Type": "plugin",
	"Slug": "wp-cfm",
	"Status": "Checked",
	"Version": "1.4.5",
	"Result": "Ok",
	"Issues": null
}]

windows-cli.yml中的参数

参数 apikeydetailslocallocalcacheformat 的默认值可以输入到wp-cli.yml文件中。添加一个名为checksum的章节

checksum:
  details: yes
  format: json
  apikey: ABC123
  local: yes
  localcache: /var/zipcache

指定API密钥

API密钥可以通过多种方式指定。wp-checksum将按以下顺序尝试定位API密钥

  1. 通过--apikey命令行参数传入
  2. 在wp-cli.yml文件中指定
  3. 在环境变量WP_CHKSM_APIKEY中指定
  4. 在当前WordPress安装的选项表中找到

如果在上述任何位置都没有找到API密钥,wp-checksum将尝试创建一个匿名API密钥并将其存储在WordPress选项表中。如果从同一源IP地址同时生成太多新密钥,则创建匿名API密钥可能会失败。

后端API和每小时速率限制

后端API和数据库仍在开发中,需要大量的工作。为了最大限度地减少各种滥用,API有一个每小时速率限制。您第一次使用wp-checksum时,将生成并存储在WordPress选项表中的匿名API密钥。匿名密钥每小时最多提供30个API请求(可能有所变动)。如果您注册并验证您的电子邮件地址,您的小时限制将提高到每小时100个请求(可能有所变动)。如果您需要每小时超过100个请求,您欢迎订阅服务并支付(少量)月费。如果您这样做,还应该知道,您正在支持一个我认为可以对WordPress社区产生很多积极影响的项目。提前感谢。

请访问https://www.wpessentials.io/product-category/api-access/ 订阅付费API密钥。

我之前宣布了一个计划,将后端API的代码作为开源发布。虽然我没有完全放弃这个计划,但在短期内(2017年)它不会是一个高优先级。主要原因是因为后端API比最初要复杂得多,同时维护该服务和支持其他用户是不切实际的。

变更日志

版本0.3.0

添加了新的子命令diff。添加了单元测试,覆盖率97%。

版本0.2.0

更改了默认行为。之前的裸命令"wp checksum"是子命令"wp checksum all"的简写。现在裸命令只是显示用法信息。