Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # .htaccess
  2.  
  3. ```
  4. <FilesMatch "\.(pdf)$">
  5. RewriteRule (.+\.pdf)$ /extensions/local/nesec/pdfManager/pdf-manager.php
  6. </FilesMatch>
  7. ```
  8. # /extensions/local/nesec/pdfManager/pdf-manager.php
  9.  
  10. ```
  11. // since loading the pdf is outside the app I'm manually including the main index.php file to initate bolt cms
  12. require $_SERVER['DOCUMENT_ROOT'] . '/index.php';
  13. ```
  14.  
  15. # Extension.php
  16. where the auth happens
  17.  
  18. ```
  19. ...
  20. // execute if URI contains .pdf extenstion
  21. if (preg_match('/\.pdf/i', $_SERVER['REQUEST_URI'])) {
  22. $this->app->match($_SERVER['REQUEST_URI'], array($this, 'initExtension'));
  23. } else {
  24. return;
  25. }
  26. ...
  27.  
  28. public function initExtension(){
  29. // check if file is inside broker-pdf limited access directory
  30. $brokerDir = preg_match('/broker\-pdf/', $_SERVER['REQUEST_URI']);
  31.  
  32. // check auth or render pdf
  33. if ($brokerDir) {
  34. $this->isAuth();
  35. } else {
  36. $this->renderPdf();
  37. }
  38. }
  39. ...
  40.  
  41. public function isAuth(){
  42. // bolt authentication function
  43. if ( $this->app['users']->isValidSession() ) {
  44. $this->renderPdf();
  45. } else {
  46. // redirect to login page
  47. header( 'Location: ' . $app['resources']->getUrl('hosturl') . '/login' );
  48. }
  49. }
  50. ...
  51. public function renderPdf(){
  52. header("Content-type:application/pdf");
  53. // echo pdf content;
  54. echo file_get_contents($this->app['resources']->getPath('root') . $this->app['request']->getPathInfo());
  55. // prevent app from fully executing
  56. exit();
  57. }
  58. ...
  59. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement