Commit 4aab7764 authored by Regis's avatar Regis
Browse files

Merge branch '78_map_image_security_and_encryption' into 'master'

78 map image security and encryption

See merge request a_boiteau/site-vikazimut-stage!36
parents 78c8646d f3f15ba8
......@@ -45,7 +45,7 @@ function calculateCorner(kml) {
function generateMap(map_div) {
let map = new L.Map(map_div);
let osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
let osm = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'});
map.addLayer(osm);
L.control.scale({metric: true, imperial: false}).addTo(map);
......
......@@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\Course;
use App\Model\CreateTrack;
use App\Model\CreateMissingControlPoint;
use ZipArchive;
class DataController extends AbstractController
{
......@@ -58,7 +59,7 @@ class DataController extends AbstractController
$response = new Response($fileContent);
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$id . "." . "xml"
$id."."."xml"
);
$response->headers->set('Content-Disposition', $disposition);
......@@ -78,6 +79,98 @@ class DataController extends AbstractController
return $this->file($course->getImage());
}
/**
* @Route("/data/{id}/img", name="img")
*/
/* public function get_image_encrypted_archive($id): Response TODO version zip
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
return $this->json(["error" => "invalid id"]);
}
$zip = new ZipArchive;
$zip->open($id.".zip", ZipArchive::CREATE);
$zip->setPassword('test');
$zip->addFile($course->getImage(), $id.".jpeg");
$zip->setEncryptionName($id.".jpeg", ZipArchive::EM_TRAD_PKWARE);
$zip->close();
$response = new Response(file_get_contents($id.".zip"));
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$id."."."zip"
);
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/zip');
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Length', filesize($id.".zip"));
return $response;
}*/
function encryptFile($encKey, $encIV, $inPath, $outPath): int
{
$sourceFile = file_get_contents($inPath);
$key = base64_decode($encKey);
$iv = base64_decode($encIV);
$path_parts = pathinfo($inPath);
$fileName = $path_parts['filename'];
$outFile = $outPath.$fileName.'.himu';
$encrypter = 'aes-256-cbc';
$encryptedString = openssl_encrypt($sourceFile, $encrypter, $key, 0, $iv);
if (file_put_contents($outFile, $encryptedString) != false) {
return 1;
} else {
return 0;
}
}
// 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.'.jpoeg';
$encrypter = 'aes-256-cbc';
$decrypted = openssl_decrypt($encryptedString, $encrypter, $key, 0, $iv);
if(file_put_contents($outFile, $decrypted)!= false) return 1;
else return 0;
}
/**
* @Route("/data/{id}/img", name="img")
*/
public function get_image_encrypted_archive($id): Response
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
return $this->json(["error" => "invalid id"]);
}
$key = 'FCAcEA0HBAoRGyALBQIeCAcaDxYWEQQPBxcXHgAFDgY=';
$iv = 'DB4gHxkcBQkKCxoRGBkaFA==';
$this->encryptFile($key, $iv, $course->getImage(), "");
/* $zip = new ZipArchive;
$zip->open($id.".zip", ZipArchive::CREATE);
$zip->setPassword('test');
$zip->addFile($course->getImage(), $id.".jpeg");
$zip->setEncryptionName($id.".jpeg", ZipArchive::EM_TRAD_PKWARE);
$zip->close();*/
$response = new Response(file_get_contents($id.".himu"));
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $id.".himu");
$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($id.".himu"));
return $response;
}
/**
* @Route("/data/{id}/kml", name="kml")
*/
......@@ -91,7 +184,7 @@ class DataController extends AbstractController
$response = new Response($fileContent);
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$id . "." . "kml"
$id."."."kml"
);
$response->headers->set('Content-Disposition', $disposition);
......@@ -115,6 +208,7 @@ class DataController extends AbstractController
} catch (Exception $e) {
$error = $e;
}
return new JsonResponse(
[
'status' => 'ok',
......
......@@ -48,7 +48,7 @@
minZoom: 1,
});
let osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
let osm = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
noWrap: true
......@@ -58,10 +58,21 @@
let locations = [];
{% for course in courses %}
locations.push(["{{ course.latitude }}", "{{ course.longitude }}", "{{ course.name }}", "{{ course.club }}"]);
locations.push(["{{ course.latitude }}", "{{ course.longitude }}", "{{ course.name }}"]);
{% endfor %}
// Concatenate course at the same position
let dotsOnMap = {}
locations.forEach(function (loc) {
const key = loc[0] + loc[1];
if (key in dotsOnMap) {
const dot = dotsOnMap[key];
dot[2] += "<br>" + loc[2];
} else {
dotsOnMap[key] = [loc[0], loc[1], loc[2]];
}
});
// Display only one dot per position
Object.values(dotsOnMap).forEach(function (loc) {
let dot = L.circleMarker([loc[0], loc[1]], {
radius: 8.0,
fillColor: '#ff0000',
......@@ -71,9 +82,9 @@
fillOpacity: 0.8
}).addTo(map);
let popupContent = loc[2] + "<br>";
if (loc[3].length > 0) {
/*if (loc[3].length > 0) {
popupContent += '(' + loc[3] + ')';
}
}*/
dot.on("click", function () {
window.location.href = '{{ path('course') }}' + '/{' + loc[0] + '}-{' + loc[1] + "}";
});
......
......@@ -224,7 +224,7 @@
<img src="{{ asset('/public/images/vikazim_logo.png') }}" height="130"/>
<h3>{% trans %}homepage.vikazim.title{% endtrans %}</h3>
<p>{% trans %}homepage.vikazim.description{% endtrans %}</p>
<p><a class="btn btn-secondary" href="http://vikazim.fr/" role="button">{% trans %}read.more{% endtrans %} &raquo;</a></p>
<p><a class="btn btn-secondary" href="https://vikazim.fr/" role="button">{% trans %}read.more{% endtrans %} &raquo;</a></p>
</div>
<div class="col-md-4">
<img src="{{ asset('/public/images/ensi_logo.png') }}" height="130"/>
......
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