"olinuris"); $template_ok= array( "ref/", "ref/info/*", "ref/research/*", "ref/hss315/*", "ref/lit/*", "ref/cet/*", "ref/newrefbooks/*", "access/laptop/*", "access/reservenews/*", "access/reservenew/*", "access/carrels/*", "access/", "studies/*", "media/"); $template_name=$templates[$template]; if (!$template_name) die("invalid template"); if (!isset($url)) die("template: url not set"); # XXX -- not secure; we should make sure that it's a well-formed filename # and that it doesn't do anything funny with .. # truncate initial slash if it's there if($url{0}=="/") { $url=substr($url,1); }; # limit access to directories in $template_ok, terminal * is a wildcard, # which means prefix match (/access/ matches only toplevel content, # /access/* matches everything below) $url_parts=explode("/",$url); array_pop($url_parts); $dir_part=implode("/",$url_parts); $dir_part="$dir_part/"; $template_this=false; foreach($template_ok as $ok_dir) { $last_char=$ok_dir{strlen($ok_dir)-1}; if ($last_char=="*") { $test_prefix=substr($ok_dir,0,strlen($ok_dir)-1); $probe_prefix=substr($dir_part,0,strlen($ok_dir)-1); if ($test_prefix==$probe_prefix) $template_this=true; } else { if ($ok_dir==$dir_part) { $template_this=true; }; } } $search_dir=$system; $file="$search_dir/$url"; # # "@" eliminates warning message # $s=@stat($file); if(!$s) die("file $file does not exist"); $o_file=$file; if(is_dir($file)) { $last_char=$file{strlen($file)-1}; if ($last_char!="/") { header("Location: $base_url$url/"); exit(); } $file="{$file}index.html"; $s=@stat($file); if(!$s) { $file="{$o_file}index.htm"; $s=@stat($file); if(!$s) die("file $file does not exist"); } }; $ext=""; if(preg_match("/\.(.*)?$/",$file,$matches)) { $ext=$matches[1]; }; $ext=strtolower($ext); $types=array("pdf"=>"application/pdf", "html"=>"text/html", "htm"=>"text/html", "gif"=>"image/gif", "jpg"=>"image/jpg", "js"=>"application/javascript", "bmp"=>"image/bmp", "doc"=>"application/msword", "css"=>"text/css"); $type=$types[$ext]; if(!$type) // $type="text/plain"; $type="text/html"; header("Content-type: $type"); if(!$template_this || !preg_match("/(.html$|.htm$)/i",$file)) { readfile($file); exit(); }; # # handle HTML # $x=implode("\n",file($file)); $date=$s[9]; # date of last change $date_formatted=date("F j Y",$date); # # extract head for metadata # preg_match("/
(.*)<\/HEAD>/is",$x,$matches); $head=$matches[1]; preg_match("/