Show sourcecode
The following files exists in this folder. Click to view.
Webserver1/Ovningar/Slutprojekt/
.env
DEBUG/
Media/
account.js
account.php
callback_log.txt
change_account_details.php
composer.json
composer.lock
forgot_pass.php
forgot_pass_new_pass.php
header.php
index.php
login.php
mediaplayer.php
node_modules/
package-lock.json
package.json
signup.php
style.css
upload.js
upload_callback.php
upload_callback_simulated.php
upload_chunk.php
upload_errors.log
upload_form.php
upload_handler.php
upload_success.log
vendor/
verify_file.php
verifypage.php
upload_callback_simulated.php
93 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
<?php
// Denna fil kommer att kallas på när Sightengine har något viktigt att säga
ignore_user_abort(true);
set_time_limit(0);
file_put_contents(__DIR__ . "/callback_log.txt", "HIT\n", FILE_APPEND);
define("MAX_SEXUAL_THRESHOLD", 0.4);
define("MAX_GORE_THRESHOLD", 0.5);
/**
* @var PDO $dbconn
* @var bool $local
* @var class DBManager
*/
include('../../incl/dbconnection.php');
$payload = file_get_contents("php://input");
$content = json_decode($payload, true);
$dbmanager = new DBManager();
// You now have access to the following:
// the media id => $content['media']['id']
// the moderation data => $content['data']
// the moderation status => $content['data']['status']
$output = "Confirmation recieved for: "
. $content['media']['id']
. "\nStatus: "
. $content['data']['status']
. "\n";
file_put_contents(__DIR__ . "/callback_log.txt", $output, FILE_APPEND);
$med_id = $content['media']['id'];
$req_id = $content['request'];
$status = $content['data']['status'];
$frames = $content['data']['frames'];
http_response_code(200);
// Wait 1 minute to simulate asynchronous background moderation
sleep(60);
if ($status == "finished" || $status == "ongoing") {
$allowed = true;
foreach ($frames as $frame) {
$sexual_activity = $frame['nudity']['sexual_activity'] ?? 0.0;
$sexual_display = $frame['nudity']['sexual_display'] ?? 0.0;
$suggestive = $frame['nudity']['suggestive'] ?? 0.0;
$very_bloody = $frame['gore']['very_bloody'] ?? 0.0;
$corpse = $frame['gore']['corpse'] ?? 0.0;
$serious_injury = $frame['gore']['serious_injury'] ?? 0.0;
$animated = $frame['gore']['type']['animated'] ?? 0.0;
if (max($sexual_activity, $sexual_display, $suggestive) > MAX_SEXUAL_THRESHOLD) {
$allowed = false;
break;
}
elseif (max($very_bloody, $corpse, $serious_injury) > MAX_GORE_THRESHOLD) {
# Tillåt animerat men inte riktigt våld
if ($animated < 0.8) {
$allowed = false;
break;
}
}
}
if ($allowed) {
$dbmanager->update_table_values("bay_media", ["hidden" => 0], ["media_id" => $med_id]);
file_put_contents(__DIR__ . "/callback_log.txt", "Media approved!\n", FILE_APPEND);
}
else {
$paths = $dbmanager->fetch_from_table(["href_video", "href_thumb"], "bay_media", ["media_id" => $med_id]);
$video_path = $paths[0]['href_video'] ?? "";
$thumb_path = $paths[0]['href_thumb'] ?? "";
if (file_exists($video_path)) {
unlink($video_path);
}
if (file_exists($thumb_path)) {
unlink($thumb_path);
}
$dbmanager->remove_from_table("bay_media", ["media_id" => $med_id]);
file_put_contents(__DIR__ . "/callback_log.txt", "Media rejected!\n", FILE_APPEND);
}
}
http_response_code(200);