Commit 6a54e0db authored by Regis's avatar Regis
Browse files

Merge branch '29_display_of_free_order_tracks' into 'master'

New behaviour, selecting a free-order track now deselected every other...

See merge request a_boiteau/site-vikazimut-stage!44
parents 227404dd 6b545882
......@@ -21,4 +21,4 @@ prototype-uml/*
/upload
/config/secret/.Halite.key
/var/
/config/secret/image_keys.json
/config/secret/.image.keys
......@@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\Course;
use App\Model\CreateTrack;
use App\Model\CreateMissingControlPoint;
use ZipArchive;
use function dirname;
class DataController extends AbstractController
{
......@@ -77,40 +77,14 @@ class DataController extends AbstractController
return $this->file($course->getImage());
}
// TODO refactor
function encryptFile($encKey, $encIV, $inPath, $outPath): int
function encryptFile($encryptKey, $encryptInitializationVector, $inPath): string
{
$sourceFile = file_get_contents($inPath);
$key = base64_decode($encKey);
$iv = base64_decode($encIV);
$path_parts = pathinfo($inPath);
$fileName = $path_parts['filename'];
$outFile = $outPath.$fileName.'.bin';
$encrypter = 'aes-256-cbc';
$encryptedString = openssl_encrypt($sourceFile, $encrypter, $key, 0, $iv);
if (file_put_contents($outFile, $encryptedString) != false) {
return 1;
} else {
return 0;
}
}
$passphrase = base64_decode($encryptKey);
$initializationVector = base64_decode($encryptInitializationVector);
$cipherAlgo = 'aes-256-cbc';
// kept for future use.
function decryptFile($encKey, $encIV, $inPath, $outPath): int
{
$encryptedString = file_get_contents($inPath);
$key = base64_decode($encKey);
$iv = base64_decode($encIV);
$path_parts = pathinfo($inPath);
$fileName = $path_parts['filename'];
$outFile = $outPath.$fileName.'.jpeg';
$encrypter = 'aes-256-cbc';
$decrypted = openssl_decrypt($encryptedString, $encrypter, $key, 0, $iv);
if (file_put_contents($outFile, $decrypted) != false) {
return 1;
} else {
return 0;
}
return openssl_encrypt($sourceFile, $cipherAlgo, $passphrase, 0, $initializationVector);
}
/**
......@@ -118,62 +92,29 @@ class DataController extends AbstractController
*/
public function get_image_encrypted_archive($id): Response
{
// TODO refactor
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
return $this->json(["error" => "invalid id"]);
}
$key = 'eCAcaDxYWEQYFCAcEA0HBAoRGyALBQIQPBxcXHgAFDg=';
$iv = 'kaFADB4gHxkKCxoRGBkcBQ==';
$encryptedFilename = $id.".bin";
$compressedFilename = $encryptedFilename.".gz";
$this->encryptFile($key, $iv, $course->getImage(), "");
$data = file_get_contents($encryptedFilename);
$gzData = gzencode($data);
file_put_contents($compressedFilename, $gzData);
$response = new Response(file_get_contents($compressedFilename));
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $compressedFilename);
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/octet-stream');
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Length', filesize($compressedFilename));
return $response;
}
$encryptVariables = json_decode(file_get_contents((dirname(__DIR__, 2).'/config/secret/.image.keys')), true);
$key = $encryptVariables["image_file_key"];
$initializationVector = $encryptVariables["image_file_iv"];
$data = $this->encryptFile($key, $initializationVector, $course->getImage());
/**
* @Route("/data/{id}/img", name="img")
*/
/* public function get_image_encrypted_archive($id): Response
{
// TODO refactor
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
return $this->json(["error" => "invalid id"]);
}
$encryptedFilename = $id.".bin";
$compressedFilename = $encryptedFilename.".gz";
$encryptVariables = json_decode(file_get_contents((\dirname(__DIR__, 2).'/config/secret/image_keys.json')), true);
// $this->encryptFile($encryptVariables["image_file_key"], $encryptVariables["image_file_iv"], $course->getImage(), "");
$image_file_key = "eCAcaDxYWEQYFCAcEA0HBAoRGyALBQIQPBxcXHgAFDg=";
$image_file_iv = "kaFADB4gHxkKCxoRGBkcBQ==";
$this->encryptFile($image_file_key, $image_file_key, $course->getImage(), "");
$data = file_get_contents($encryptedFilename);
$gzData = gzencode($data);
file_put_contents($compressedFilename, $gzData);
$response = new Response(file_get_contents($compressedFilename));
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $compressedFilename);
$response = new Response($gzData);
$compressedFilename = $id.".bin".".gz";
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/octet-stream');
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $compressedFilename);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Length', filesize($compressedFilename));
$response->headers->set('Content-Length', strlen($gzData));
return $response;
}
*/
/**
* @Route("/data/{id}/kml", name="kml")
*/
......@@ -209,7 +150,12 @@ class DataController extends AbstractController
try {
$this->checkAndAddToEvent($trackCreator->getTrack());
} catch (Exception $e) {
$error = $e;
return new JsonResponse(
[
'status' => 'error',
],
JsonResponse::HTTP_BAD_REQUEST
);
}
return new JsonResponse(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment