<?php

function generate_uuid() {
    $bytes = openssl_random_pseudo_bytes(16);
    $fields = array(
        'time_low' => bin2hex(substr($bytes, 0, 4)),
        'time_mid' => bin2hex(substr($bytes, 4, 2)),
        'time_hi_and_version' => bin2hex(substr($bytes, 6, 4)),
        'clock_seq_hi_and_reserved' => bin2hex(substr($bytes, 10, 2)),
        'node' => bin2hex(substr($bytes, 12, 6))
    );
    return vsprintf('%s-%s-%s-%s-%s', $fields);
}

$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, 'check') !== false){
	header('Content-Type: application/json');
	echo '{"result": "found", "uuid": "'. generate_uuid() .'"}';


} else if (strpos($uri, 'result') !== false){
	header('Content-Type: application/json');
	echo '{"result": "completed", "outcome": "clean", "modifications": ["added important text"], "filename":"replacement.txt"}';


} else if (strpos($uri, 'submit') !== false){
	header('Content-Type: application/json');
	echo '{"result": "accepted", "uuid": "' . generate_uuid() . '"}';


} else if (strpos($uri, 'file') !== false){
	$etag = sha1(rand());
	header('Etag: "'.$etag.'"');
	header('Content-Length: 33');
	header('Content-Type: application/octet-stream');
	header('Content-Disposition: attachment; filename=replacement.txt');
	echo 'this is the replaced file content';
}

