diff --git a/ext/eokm/info.php b/ext/eokm/info.php new file mode 100644 index 00000000..23a5fb4c --- /dev/null +++ b/ext/eokm/info.php @@ -0,0 +1,13 @@ +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)); + curl_setopt($ch, CURLOPT_HEADER, 1); + 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); + } +} diff --git a/ext/eokm/test.php b/ext/eokm/test.php new file mode 100644 index 00000000..fda6adaa --- /dev/null +++ b/ext/eokm/test.php @@ -0,0 +1,27 @@ +log_in_as_user(); + $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->assert_no_text("Image too large"); + $this->assert_no_text("Image too small"); + $this->assert_no_text("ratio"); + } + + /* + public function testFail() + { + $this->log_in_as_user(); + try { + $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->assertTrue(false, "Invalid-size image was allowed"); + } catch (UploadException $e) { + $this->assertEquals("Image too small", $e->getMessage()); + } + } + */ +}