No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogiproSCORMBundle.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Logipro\Bundle\SCORMBundle;
  3. use Symfony\Component\HttpKernel\Bundle\Bundle;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. class LogiproSCORMBundle extends Bundle
  6. {
  7. public function boot()
  8. {
  9. $this->initialiseFolders();
  10. }
  11. public function build(ContainerBuilder $container)
  12. {
  13. parent::build($container);
  14. }
  15. /**
  16. * *creation du repertoire qui contiendra les ressources accesibles :
  17. * ** stockage des paquets scorms (logipro_scorm.content_folder)
  18. * * creation du fichier .htaccess qui restreindra l'acces aux ressources
  19. *
  20. * @return void
  21. */
  22. private function initialiseFolders() : void
  23. {
  24. $contentFolder = $this->container->getParameter('logipro_scorm.content_folder');
  25. // creation du repertoire de reception du contenu
  26. if (!file_exists($contentFolder)) {
  27. mkdir($contentFolder, 0755, true);
  28. }
  29. // creation du fichier .htaccess
  30. $contentUrlPrefix = $this->container->getParameter('logipro_scorm.content_url_prefix');
  31. $htaccess = $contentFolder.'/.htaccess';
  32. // on prendra garde de doubler le \ en \\
  33. $now = $today = date("Y-m-d H:i:s");
  34. $content=<<<EOT
  35. # automatically generated by LogiproSCORMBundle.initialiseFolders at $now
  36. Options +FollowSymlinks
  37. RewriteEngine On
  38. RewriteBase "$contentUrlPrefix/"
  39. #en cas d'acces à un fichier/existant existant laisse l'acces...
  40. #...a condition d'un environnement phpsession indice (insuffisant) que c'est un utilisateur connu
  41. # (a ameliorer)
  42. RewriteCond %{REQUEST_FILENAME} -f [OR]
  43. RewriteCond %{REQUEST_FILENAME} -d
  44. RewriteCond %{HTTP_COOKIE} !PHPSESSID= [NC]
  45. RewriteRule .* - [L]
  46. # l'acces au ressource est donnée a une url qui contient un code correspondant à
  47. # une operation de transformation de la valeur du cookie
  48. #si le coockie n'existe pas alors pas droit d'acces à la ressource : 403
  49. RewriteCond %{HTTP_COOKIE} !SCORMBundle= [NC]
  50. RewriteRule .* - [R=403,L]
  51. #on stocke la valeur du cookie...
  52. RewriteCond %{HTTP_COOKIE} SCORMBundle=([^;]+)
  53. RewriteRule ^(.*) $1 [E=md5scormkey:%1]
  54. # on recupere la clef contenue dans la chaine
  55. RewriteCond %{REQUEST_URI} ^$contentUrlPrefix/([^/]+)/(.+)$
  56. RewriteRule .* - [E=key:%1,E=resource:%2]
  57. RewriteCond expr "md5('%{ENV:key}') == %{ENV:md5scormkey}"
  58. RewriteRule .* $contentUrlPrefix/%{ENV:resource} [L]
  59. EOT;
  60. $handle = fopen($htaccess, 'w');
  61. fwrite($handle, $content);
  62. fclose($handle);
  63. $packageFolder = $this->container->getParameter('logipro_scorm.package_folder');
  64. // creation du repertoire de reception du contenu
  65. if (!file_exists($packageFolder)) {
  66. mkdir($packageFolder, 0777, true);
  67. }
  68. }
  69. }