This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/eokm/main.php

53 lines
1.7 KiB
PHP
Raw Normal View History

2020-08-23 14:40:58 +00:00
<?php declare(strict_types=1);
class Eokm extends Extension
{
public function get_priority(): int
{
return 40;
} // early, to veto ImageUploadEvent
public function onImageAddition(ImageAdditionEvent $event)
{
global $config;
$username = $config->get_string("eokm_username");
$password = $config->get_string("eokm_password");
if($username && $password) {
$ch = curl_init("https://api.eokmhashdb.nl/v1/check/md5");
// 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);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close($ch);
if($return == "false") {
// all ok
}
elseif($return == "true") {
log_warning("eokm", "User tried to upload banned image {$event->image->hash}");
throw new UploadException("Image banned");
}
else {
log_warning("eokm", "Unexpected return from EOKM: $return");
}
}
}
public function onSetupBuilding(SetupBuildingEvent $event)
{
$sb = new SetupBlock("EOKM Filter");
$sb->start_table();
$sb->add_text_option("eokm_username", "Username", true);
$sb->add_text_option("eokm_password", "Password", true);
$sb->end_table();
$event->panel->add_block($sb);
}
}