/usr/lib/nanoweb/modules/mod_static.php is in nanoweb 2.2.9-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | <?php
/*
Nanoweb Static Content module
=============================
Copyright (C) 2002-2003 Vincent Negrier aka. sIX <six@aegis-corp.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
class mod_static {
function mod_static() {
$this->modtype="parser_static";
$this->modname="Static content support";
}
function parser_open($args, $filename, &$rq_err, &$cgi_headers) {
global $conf, $htreq_headers;
unset($this->fp);
// Generate ETag value for resource
$fmt=filemtime($filename);
$fs=filesize($filename);
$etag="\"".dechex(fileinode($filename)).":6r0x:".dechex($fmt).":".dechex($fs)."\"";
$rq_ifm=$rq_ifnm=$rq_ims=$rq_ius=true;
// Test If-Match request header (cache helper)
if ($hdr_inm=$htreq_headers["IF-MATCH"]) {
$rq_ifm=false;
$inms=explode(",", trim($hdr_inm));
foreach ($inms as $inm_tag) {
$inm_tag=trim($inm_tag);
if ($inm_tag==$etag || $inm_tag=="*") {
$rq_err=304;
$cgi_headers["ETag"]=$etag;
$rq_ifm=true;
}
}
}
// Test If-None-Match request header (cache helper)
if ($hdr_inm=$htreq_headers["IF-NONE-MATCH"]) {
$inms=explode(",", trim($hdr_inm));
foreach ($inms as $inm_tag) {
$inm_tag=trim($inm_tag);
if ($inm_tag==$etag || $inm_tag=="*") {
$rq_err=304;
$cgi_headers["ETag"]=$etag;
$rq_ifnm=false;
}
}
}
// Test If-Unmodified-Since request header (cache helper)
if ($lmdate=$htreq_headers["IF-UNMODIFIED-SINCE"]) {
$lmdate=(float)strtotime($lmdate);
if ($fmt>$lmdate) {
$rq_err=304;
$cgi_headers["Last-Modified"]=gmdate("D, d M Y H:i:s T", $fmt);
$rq_ims=false;
}
}
// Test If-Modified-Since request header (cache helper)
if ($lmdate=$htreq_headers["IF-MODIFIED-SINCE"]) {
$lmdate=(float)strtotime($lmdate);
if ($fmt<=$lmdate) {
$rq_err=304;
$cgi_headers["Last-Modified"]=gmdate("D, d M Y H:i:s T", $fmt);
$rq_ius=false;
}
}
if (!($rq_ifm && $rq_ifnm && $rq_ims && $rq_ius)) {
$this->peof=true;
return(false);
}
// Cache helpers end
$this->rng_from=0;
$this->content_length=$this->rng_to=$fs;
$cgi_headers["Last-Modified"]=gmdate("D, d M Y H:i:s T", $fmt);
$cgi_headers["ETag"]=$etag;
$cgi_headers["Accept-Ranges"]="bytes";
if ($rngt=trim($htreq_headers["IF-RANGE"])) {
$process_range=($rngt==$etag);
} else $process_range=true;
if (($process_range) && ($rhdr=$htreq_headers["RANGE"])) {
// Client asked HTTP Resume
if (!access_query("staticdisablepartial", 0)) {
$tmparr=explode("=", $rhdr);
if (strtolower(trim($tmparr[0]))=="bytes") {
$rngarr=explode("-", $tmparr[1]);
if ($rngarr[0]==="") {
// Range: bytes=-###
if ($rngarr[1]>$fs) {
$rng_from="*";
} else {
$rng_from=$fs-$rngarr[1];
$rng_to=$fs-1;
}
} else if ($rngarr[1]=="") {
// Range: bytes=###-
if ($rngarr[0]>$fs) {
$rng_from="*";
} else {
$rng_from=$rngarr[0];
$rng_to=$fs-1;
}
} else {
// Range: bytes=###-###
if (($rngarr[0]>$fs) || ($rngarr[1]>$fs) || ($rngarr[0]>$rngarr[1])) {
$rng_from="*";
} else {
$rng_from=$rngarr[0];
$rng_to=$rngarr[1];
}
}
} else {
// Ranges unit not supported
$rng_from="*";
}
if ($rng_from==="*") {
// Send all content with 416
$rq_err=416;
$cgi_headers["Content-Range"]="*";
} else {
// Send partial content
$rq_err=206;
$this->rng_from=$rng_from;
$this->rng_to=$rng_to;
$this->content_length=($rng_to-$rng_from)+1;
$cgi_headers["Content-Range"]="bytes ".$rng_from."-".$rng_to."/".$fs;
}
} else {
// Partial content has been disabled in conf
$rq_err=416;
$cgi_headers["Content-Range"]="*";
}
}
if ($this->fp=@fopen($filename, NW_BSAFE_READ_OPEN)) {
if ($this->rng_from) {
fseek($this->fp, $rng_from);
$this->cur_ptr=$rng_from;
} else {
$this->cur_ptr=0;
}
$this->peof=false;
// Return a static_response if possible
if ($this->content_length<=$conf["global"]["staticbuffersize"][0]) {
$content=fread($this->fp, $this->content_length);
$this->parser_close();
return(new static_response($content));
}
} else {
$rq_err=404;
$this->peof=true;
}
}
function parser_get_output() {
if ($this->fp) {
$sbf=$GLOBALS["conf"]["global"]["staticbuffersize"][0];
if ($this->cur_ptr+$sbf<=$this->rng_to) $read_len=$sbf;
else $read_len=$this->rng_to-$this->cur_ptr+1;
$content=fread($this->fp, $read_len);
$this->cur_ptr+=$read_len;
$this->peof=$this->cur_ptr>=$this->rng_to;
return($content);
}
}
function parser_eof() {
return($this->fp && $this->peof);
}
function parser_close() {
if ($this->fp) fclose($this->fp);
unset($this->content_length);
}
}
?>
|