2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-08-23 14:40:58 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-08-23 14:40:58 +00:00
|
|
|
class Eokm extends Extension
|
|
|
|
{
|
|
|
|
public function get_priority(): int
|
|
|
|
{
|
|
|
|
return 40;
|
|
|
|
} // early, to veto ImageUploadEvent
|
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onImageAddition(ImageAdditionEvent $event): void
|
2020-08-23 14:40:58 +00:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$username = $config->get_string("eokm_username");
|
|
|
|
$password = $config->get_string("eokm_password");
|
|
|
|
|
2020-09-18 23:18:51 +00:00
|
|
|
if ($username && $password) {
|
2024-02-20 00:22:25 +00:00
|
|
|
$ch = \Safe\curl_init("https://api.eokmhashdb.nl/v1/check/md5");
|
2020-08-23 14:40:58 +00:00
|
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
|
2020-08-26 19:43:11 +00:00
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
2020-08-23 14:40:58 +00:00
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $event->image->hash);
|
2020-09-18 23:18:51 +00:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
2020-08-23 14:40:58 +00:00
|
|
|
$return = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
/** @noinspection PhpStatementHasEmptyBodyInspection */
|
2020-09-18 23:18:51 +00:00
|
|
|
if ($return == "false") {
|
2020-08-23 14:40:58 +00:00
|
|
|
// all ok
|
2020-09-18 23:18:51 +00:00
|
|
|
} elseif ($return == "true") {
|
2020-08-23 14:40:58 +00:00
|
|
|
log_warning("eokm", "User tried to upload banned image {$event->image->hash}");
|
2020-10-26 15:22:58 +00:00
|
|
|
throw new UploadException("Post banned");
|
2020-09-18 23:18:51 +00:00
|
|
|
} else {
|
2020-08-23 14:40:58 +00:00
|
|
|
log_warning("eokm", "Unexpected return from EOKM: $return");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event): void
|
2020-08-23 14:40:58 +00:00
|
|
|
{
|
2020-10-26 15:13:28 +00:00
|
|
|
$sb = $event->panel->create_new_block("EOKM Filter");
|
2020-08-23 14:40:58 +00:00
|
|
|
|
|
|
|
$sb->start_table();
|
|
|
|
$sb->add_text_option("eokm_username", "Username", true);
|
|
|
|
$sb->add_text_option("eokm_password", "Password", true);
|
|
|
|
$sb->end_table();
|
|
|
|
}
|
|
|
|
}
|