WHMCS作为一款流行的主机计费和客户管理软件,在主机行业流行多年,但是这个软件的流行意味着很多的黑客或会恶意搞你的网站,如果您之前在使用WHMCS的过程中遭遇过批量恶意注册,继续往下看,这篇文章或许能够帮你快速为你,这个问题曾经困扰了我很久,但是通过这个脚本算是解决了我一个困扰很久的问题。
下面代码内容:
<?php
/**
* Delete spam clients where the firstname contains %hostease%
* using advanced database interaction and the DeleteClient API
*
* @link https://developers.whmcs.com/advanced/db-interaction/
* @link https://developers.whmcs.com/api-reference/deleteclient/
*
* @author WHMCS Limited <development@whmcs.com>
* @copyright Copyright (c) WHMCS Limited 2005-2018
* @license https://www.whmcs.com/eula/ WHMCS Eula
*/
require 'init.php';
use WHMCS\Database\Capsule;
// Replace ADMIN_USERNAME with your admin username
$adminUsername = 'ADMIN_USERNAME';
echo '<pre>';
// Loop through all clients where firstname contains hostease
foreach (Capsule::table('tblclients')->where('firstname', 'like', '%hostease%')->get() as $client) {
// Delete the client with DeleteClient API
$results = localAPI('DeleteClient', ['clientid' => $client->id], $adminUsername);
// Check for errors
if ($results['result'] == 'success') {
echo "Deleted Client ID: " . $client->id;
} else {
echo "Error deleting Client ID: " . $client->id;
}
}
echo '</pre>';
其中需要修改两个地方:
1.将下面的ADMIN_USERNAME替换成你的管理员
$adminUsername = 'ADMIN_USERNAME';
2.将下面的hostease改为你需要的字符,需要主意观察你的恶意注册的账户是否具有一定的特征,比如注册的用户的firstname中都包含JamesS字符,那么你就可以将下面代码中的hostease修改为JamesS,
// Loop through all clients where firstname contains hostease
foreach (Capsule::table('tblclients')->where('firstname', 'like', '%JamesS%')->get() as $client) {
在WHMCS搜索具有特征的名字:
然后将这个代码保存为php文件,并上传到你的上传到你的WHMCS根目录,如图:
并且运行这段代码,他就会直接删除名字带有JamesS的用户。因此在运行前,需要留意是否确定为批量注册的账户。当然如果你需要查看输出结果,或者规律在Lastname,需要删除lastname,则只需要将代码中的firstname改为lastname即可,也可以根据需要自行调整。
如果后面大家有需要欢迎留言,会继续发布调整后的代码。