mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-22 07:43:41 +00:00
Merge pull request 'Blockbot: Logging of AP actors' (#1510) from heluecht/friendica-addons:ap-actor-logging into 2024.06-rc
Reviewed-on: https://git.friendi.ca/friendica/friendica-addons/pulls/1510
This commit is contained in:
commit
27e362213f
1 changed files with 34 additions and 1 deletions
|
@ -15,6 +15,7 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Network\HTTPException\ForbiddenException;
|
use Friendica\Network\HTTPException\ForbiddenException;
|
||||||
|
use Friendica\Util\HTTPSignature;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
@ -76,6 +77,8 @@ function blockbot_init_1()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockbot_log_activitypub($_SERVER['REQUEST_URI'], $_SERVER['HTTP_USER_AGENT']);
|
||||||
|
|
||||||
if (blockbot_is_crawler($parts)) {
|
if (blockbot_is_crawler($parts)) {
|
||||||
Logger::debug('Crawler found - reject', $logdata);
|
Logger::debug('Crawler found - reject', $logdata);
|
||||||
blockbot_reject();
|
blockbot_reject();
|
||||||
|
@ -169,7 +172,7 @@ function blockbot_init_1()
|
||||||
|
|
||||||
function blockbot_save($database, $userAgent)
|
function blockbot_save($database, $userAgent)
|
||||||
{
|
{
|
||||||
if (!DI::config()->get('blockbot', 'training') || !function_exists('dba_open')) {
|
if (!DI::config()->get('blockbot', 'logging') || !function_exists('dba_open')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +184,36 @@ function blockbot_save($database, $userAgent)
|
||||||
dba_close($resource);
|
dba_close($resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function blockbot_log_activitypub(string $url, string $agent)
|
||||||
|
{
|
||||||
|
if (!DI::config()->get('blockbot', 'logging')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bot = ['/.well-known/nodeinfo', '/nodeinfo/2.0', '/nodeinfo/1.0'];
|
||||||
|
if (in_array($url, $bot)) {
|
||||||
|
blockbot_save('activitypub-stats', $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bot = ['/api/v1/instance', '/api/v2/instance', '/api/v1/instance/extended_description',
|
||||||
|
'/api/v1/instance/peers'];
|
||||||
|
if (in_array($url, $bot)) {
|
||||||
|
blockbot_save('activitypub-api-stats', $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($url, 0, 6) == '/api/v') {
|
||||||
|
blockbot_save('activitypub-api', $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($_SERVER['REQUEST_METHOD'] == 'POST') && in_array('inbox', explode('/', parse_url($url, PHP_URL_PATH)))) {
|
||||||
|
blockbot_save('activitypub-inbox-agents', $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_SERVER['HTTP_SIGNATURE']) && !empty(HTTPSignature::getSigner('', $_SERVER))) {
|
||||||
|
blockbot_save('activitypub-signature-agents', $agent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function blockbot_check_login_attempt(string $url, array $logdata)
|
function blockbot_check_login_attempt(string $url, array $logdata)
|
||||||
{
|
{
|
||||||
if (in_array(trim(parse_url($url, PHP_URL_PATH), '/'), ['login', 'lostpass', 'register'])) {
|
if (in_array(trim(parse_url($url, PHP_URL_PATH), '/'), ['login', 'lostpass', 'register'])) {
|
||||||
|
|
Loading…
Reference in a new issue