• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/WebAccessChecker/classes/class.ilWebAccessChecker.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once "./include/inc.header.php";
00025 require_once "./Services/Utilities/classes/class.ilUtil.php";
00026 require_once "./classes/class.ilObject.php";
00027 require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
00028 
00043 class ilWebAccessChecker
00044 {
00045         var $lng;
00046         var $ilAccess;
00047         var $checked_list;
00048         
00054         var $subpath;
00055 
00061         var $file;
00062 
00068         var $params;
00069 
00070 
00076         var $disposition = "inline";
00077 
00078 
00084         var $mimetype;      
00085 
00091         var $errorcode;
00092 
00093             
00099         var $errortext;
00100 
00101 
00106         function ilWebAccessChecker()
00107         {
00108                 global $ilAccess, $lng, $ilLog;
00109 
00110                 $this->lng =& $lng;
00111                 $this->ilAccess =& $ilAccess;
00112                 $this->checked_list = & $_SESSION["WebAccessChecked"];
00113                 $this->params = array();
00114 
00115                 // get the requested file and its type
00116                 $uri = parse_url($_SERVER["REQUEST_URI"]);
00117                 parse_str($uri["query"], $this->params);
00118 
00119                 $pattern = ILIAS_WEB_DIR . "/" . CLIENT_ID;
00120                 $this->subpath = urldecode(substr($uri["path"], strpos($uri["path"], $pattern)));
00121                 $this->file = realpath(ILIAS_ABSOLUTE_PATH . "/". $this->subpath);
00122                 
00123                 /* debugging
00124                 echo "<pre>";
00125                 echo "REQUEST_URI:         ". $_SERVER["REQUEST_URI"]. "\n";
00126                 echo "Parsed URI:          ". $uri["path"]. "\n";
00127                 echo "DOCUMENT_ROOT:       ". $_SERVER["DOCUMENT_ROOT"]. "\n";
00128                 echo "PHP_SELF:            ". $_SERVER["PHP_SELF"]. "\n";
00129                 echo "SCRIPT_NAME:         ". $_SERVER["SCRIPT_NAME"]. "\n";
00130                 echo "SCRIPT_FILENAME:     ". $_SERVER["SCRIPT_FILENAME"]. "\n";
00131                 echo "PATH_TRANSLATED:     ". $_SERVER["PATH_TRANSLATED"]. "\n";
00132                 echo "ILIAS_WEB_DIR:       ". ILIAS_WEB_DIR. "\n";
00133                 echo "ILIAS_HTTP_PATH:     ". ILIAS_HTTP_PATH. "\n";
00134                 echo "ILIAS_ABSOLUTE_PATH: ". ILIAS_ABSOLUTE_PATH. "\n";
00135                 echo "CLIENT_ID:           ". CLIENT_ID. "\n";
00136                 echo "CLIENT_WEB_DIR:      ". CLIENT_WEB_DIR. "\n";
00137                 echo "subpath:             ". $this->subpath. "\n";
00138                 echo "file:                ". $this->file. "\n";
00139                 echo "</pre>";
00140                 exit;
00141                 */
00142 
00143                 if (file_exists($this->file))
00144                 {
00145                         $this->mimetype = ilObjMediaObject::getMimeType($this->file);
00146                 }
00147                 else
00148                 {
00149                         $this->errorcode = 404;
00150                         $this->errortext = $this->lng->txt("url_not_found");
00151                         return false;
00152                 }
00153         }
00154 
00159         function checkAccess()
00160         {
00161                 global $ilLog;
00162                 
00163                 // extract the object id (html/scorm learning modules)
00164                 $pos1 = strpos($this->subpath, "lm_data/lm_") + 11;
00165                 $pos2 = strpos($this->subpath, "/", $pos1);
00166 
00167                 if ($pos1 == 11 or $pos2 === false)
00168                 {
00169                         // media object
00170                         $pos1 = strpos($this->subpath, "mobs/mm_") + 8;
00171                         $pos2 = strpos($this->subpath, "/", $pos1);
00172                         if ($pos1 === false or $pos2 === false)
00173                         {
00174                                 $this->errorcode = 404;
00175                                 $this->errortext = $this->lng->txt("url_not_found");
00176                                 return false;
00177                         }
00178                         else
00179                         {
00180                                 $mob_id = substr($this->subpath, $pos1, $pos2-$pos1);
00181                                 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00182                                 $usages = ilObjMediaObject::lookupUsages($mob_id);
00183                                 foreach($usages as $usage)
00184                                 {
00185                                         //var_dump($usage);
00186                                         $oid = ilObjMediaObject::getParentObjectIdForUsage($usage, true);
00187                                         //var_dump($oid);
00188                                         if ($oid > 0)
00189                                         {
00190                                                 $obj_ids[] = $oid;
00191                                         
00192                                                 // media objects in news (media casts)
00193                                                 if ($usage["type"] == "news")
00194                                                 {
00195                                                         include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
00196                                                         include_once("./Services/News/classes/class.ilNewsItem.php");
00197                                                         
00198                                                         if (ilObjMediaCastAccess::_lookupPublicFiles($oid) &&
00199                                                                 ilNewsItem::_lookupVisibility($usage["id"]) == NEWS_PUBLIC)
00200                                                         {
00201                                                                 return true;
00202                                                         }
00203                                                 }
00204                                         }
00205                                 }
00206                         }
00207                 }
00208                 $obj_ids[] = substr($this->subpath, $pos1, $pos2-$pos1);
00209                 foreach($obj_ids as $obj_id)
00210                 {
00211                         if (!is_numeric($obj_id))
00212                         {
00213                                 $this->errorcode = 404;
00214                                 $this->errortext = $this->lng->txt("obj_not_found");
00215                                 return false;
00216                         }
00217         
00218                         // look in cache, if already checked
00219                         if (is_array($this->checked_list))
00220                         {
00221                                 if (in_array($obj_id, $this->checked_list))
00222                                 {
00223         //                              return true;
00224                                 }
00225                         }
00226         
00227                         // find the object references
00228                         $obj_type = ilObject::_lookupType($obj_id);
00229                         $ref_ids  = ilObject::_getAllReferences($obj_id);
00230                         if (!$ref_ids)
00231                         {
00232                                 $this->errorcode = 403;
00233                                 $this->errortext = $this->lng->txt("permission_denied");
00234                                 return false;
00235                         }
00236         
00237                         // check, if one of the references is readable
00238                         $readable = false;
00239         
00240                         foreach($ref_ids as $ref_id)
00241                         {
00242                                 if ($this->ilAccess->checkAccess("read", "view", $ref_id, $obj_type, $obj_id))
00243                                 {
00244                                         $readable = true;
00245                                         break;
00246                                 }
00247                         }
00248                         if ($readable)
00249                         {
00250                                 //add object to cache
00251                                 $this->checked_list[] = $obj_id;
00252                                 return true;
00253                         }
00254                 }
00255                 
00256                 $this->errorcode = 403;
00257                 $this->errortext = $this->lng->txt("permission_denied");
00258                 return false;
00259         }
00260         
00261         
00267         function setDisposition($a_disposition = "inline")
00268         {
00269                 $this->disposition = $a_disposition;
00270         }
00271 
00277         function getDisposition()
00278         {
00279                 return $this->disposition;
00280         }
00281 
00282         
00287         function sendFile()
00288         {
00289                 if ($this->getDisposition() == "attachment")
00290                 {
00291                         ilUtil::deliverFile($this->file, basename($this->file));
00292                         exit;
00293                 }
00294                 else
00295                 {
00296                         if (!isset($_SERVER["HTTPS"]))
00297                         {
00298                                 header("Cache-Control: no-cache, must-revalidate");
00299                                 header("Pragma: no-cache");
00300                         }
00301                         
00302                         header("Content-Type: " . $this->mimetype);
00303                         header("Content-Length: ".(string)(filesize($this->file)));
00304                         
00305                         if (isset($_SERVER["HTTPS"]))
00306                         {
00307                                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
00308                                 header('Pragma: public');
00309                         }
00310 
00311                         header("Connection: close");
00312 
00313                         ilUtil::readFile( $this->file);
00314                         exit;
00315                 }
00316         }
00317         
00322         function sendError()
00323         {
00324                 switch ($this->errorcode)
00325                 {
00326                         case 403:
00327                                 header("HTTP/1.0: 403 Forbidden");
00328                                 break;
00329                         case 404:
00330                                 header("HTTP/1.0: 404 Not Found");
00331                                 break;
00332                 }
00333                 exit($this->errortext);
00334         }
00335 }
00336 ?>

Generated on Fri Dec 13 2013 17:57:02 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1