|
@ -218,6 +218,25 @@ |
|
|
} else return false; |
|
|
} else return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function purge($uri) { |
|
|
|
|
|
global $config; |
|
|
|
|
|
$uri = (str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) == '/' ? '/' : str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) . '/') . $uri; |
|
|
|
|
|
$request = "PURGE {$uri} HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\nUser-Agent: Tinyboard\r\nConnection: Close\r\n\r\n"; |
|
|
|
|
|
|
|
|
|
|
|
foreach($config['purge'] as &$purge) { |
|
|
|
|
|
$host = $purge[0]; |
|
|
|
|
|
$port = $purge[1]; |
|
|
|
|
|
if($fp = fsockopen($host, $port, $errno, $errstr, $config['purge_timeout'])) { |
|
|
|
|
|
fwrite($fp, $request); |
|
|
|
|
|
fclose($fp); |
|
|
|
|
|
} else { |
|
|
|
|
|
// Cannot connect? |
|
|
|
|
|
error('Could not PURGE for ' . $host); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function file_write($path, $data) { |
|
|
function file_write($path, $data) { |
|
|
global $config; |
|
|
global $config; |
|
|
if(preg_match('/^scp:\/\/(.+)$/', $path, $m)) { |
|
|
if(preg_match('/^scp:\/\/(.+)$/', $path, $m)) { |
|
@ -233,6 +252,15 @@ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(isset($config['purge']) && isset($_SERVER['HTTP_HOST'])) { |
|
|
|
|
|
// Purge cache |
|
|
|
|
|
if(basename($path) == $config['file_index']) { |
|
|
|
|
|
// Index file (/index.html); purge "/" as well |
|
|
|
|
|
purge(dirname($path) . '/'); |
|
|
|
|
|
} |
|
|
|
|
|
purge($path); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(!$fp = fopen($path, 'c')) |
|
|
if(!$fp = fopen($path, 'c')) |
|
|
error('Unable to open file for writing: ' . $path); |
|
|
error('Unable to open file for writing: ' . $path); |
|
|
|
|
|
|
|
|