2012-03-14 06:45:59 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-14 15:44:29 +01:00
|
|
|
/*
|
|
|
|
* This script will look for Tinyboard in the following places (in order):
|
2012-03-14 16:11:38 +01:00
|
|
|
* - $TINYBOARD_PATH environment varaible
|
2012-03-14 15:44:29 +01:00
|
|
|
* - ./
|
|
|
|
* - ./Tinyboard/
|
|
|
|
* - ../
|
|
|
|
*/
|
|
|
|
|
2013-12-25 23:08:19 +01:00
|
|
|
ini_set('display_errors', 1);
|
|
|
|
error_reporting(E_ALL);
|
2012-03-14 17:14:09 +01:00
|
|
|
set_time_limit(0);
|
2012-03-14 15:44:29 +01:00
|
|
|
$shell_path = getcwd();
|
|
|
|
|
2012-03-14 16:11:38 +01:00
|
|
|
if(getenv('TINYBOARD_PATH') !== false)
|
|
|
|
$dir = getenv('TINYBOARD_PATH');
|
|
|
|
elseif(file_exists('inc/functions.php'))
|
2012-03-14 15:44:29 +01:00
|
|
|
$dir = false;
|
|
|
|
elseif(file_exists('Tinyboard') && is_dir('Tinyboard') && file_exists('Tinyboard/inc/functions.php'))
|
|
|
|
$dir = 'Tinyboard';
|
|
|
|
elseif(file_exists('../inc/functions.php'))
|
|
|
|
$dir = '..';
|
|
|
|
else
|
2012-03-17 14:36:51 +01:00
|
|
|
die("Could not locate Tinyboard directory!\n");
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
if($dir && !chdir($dir))
|
2012-03-17 14:36:51 +01:00
|
|
|
die("Could not change directory to {$dir}\n");
|
2012-03-14 15:44:29 +01:00
|
|
|
|
2012-03-14 16:11:38 +01:00
|
|
|
if(!getenv('TINYBOARD_PATH')) {
|
|
|
|
// follow symlink
|
|
|
|
chdir(realpath('inc') . '/..');
|
|
|
|
}
|
|
|
|
|
2012-03-15 12:16:26 +01:00
|
|
|
putenv('TINYBOARD_PATH=' . getcwd());
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
require 'inc/functions.php';
|
2013-09-06 16:10:32 +02:00
|
|
|
require 'inc/mod/auth.php';
|
2012-03-14 15:44:29 +01:00
|
|
|
|
2012-03-14 06:45:59 +01:00
|
|
|
$mod = Array(
|
|
|
|
'id' => -1,
|
|
|
|
'type' => ADMIN,
|
|
|
|
'username' => '?',
|
|
|
|
'boards' => Array('*')
|
|
|
|
);
|
|
|
|
|
2012-03-14 15:44:29 +01:00
|
|
|
function get_httpd_privileges() {
|
2012-03-15 12:16:26 +01:00
|
|
|
global $config, $shell_path, $argv;
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
if(php_sapi_name() != 'cli')
|
|
|
|
die("get_httpd_privileges(): invoked from HTTP client.\n");
|
|
|
|
|
|
|
|
echo "Dropping priviledges...\n";
|
|
|
|
|
|
|
|
if(!is_writable('.'))
|
|
|
|
die("get_httpd_privileges(): web directory is not writable\n");
|
|
|
|
|
|
|
|
$filename = '.' . md5(rand()) . '.php';
|
2012-03-14 17:14:09 +01:00
|
|
|
$inc_filename = '.' . md5(rand()) . '.php';
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
echo "Copying rebuilder to web directory...\n";
|
|
|
|
|
2012-03-14 17:14:09 +01:00
|
|
|
// replace "/inc/cli.php" with its new filename
|
|
|
|
passthru("cat " . escapeshellarg($shell_path . '/' . $_SERVER['PHP_SELF']) . " | sed \"s/'\/inc\/cli\.php'/'\/{$inc_filename}'/\" > {$filename}");
|
|
|
|
|
|
|
|
$inc_header = "<?php\n";
|
|
|
|
|
2012-03-15 12:16:26 +01:00
|
|
|
// copy environment
|
2012-03-14 17:14:09 +01:00
|
|
|
$env = explode("\n", shell_exec('printenv | grep ^TINYBOARD'));
|
|
|
|
foreach($env as $line) {
|
|
|
|
if(!empty($line))
|
|
|
|
$inc_header .= "putenv('" . addslashes($line) . "');\n";
|
|
|
|
}
|
|
|
|
|
2012-03-15 12:16:26 +01:00
|
|
|
// copy command line arguments
|
|
|
|
$inc_header .= "\$argv = " . var_export($argv, true) . ";\n";
|
|
|
|
|
2012-03-14 17:14:09 +01:00
|
|
|
// copy this file
|
|
|
|
file_put_contents($inc_filename, $inc_header . substr($inc = file_get_contents(__FILE__), strpos($inc, "\n")));
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
chmod($filename, 0666);
|
2012-03-14 17:14:09 +01:00
|
|
|
chmod($inc_filename, 0666);
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
if(preg_match('/^https?:\/\//', $config['root'])) {
|
|
|
|
$url = $config['root'] . $filename;
|
2012-03-14 17:14:09 +01:00
|
|
|
} elseif($host = getenv('TINYBOARD_HOST')) {
|
|
|
|
$url = 'http://' . $host . $config['root'] . $filename;
|
2012-03-14 15:44:29 +01:00
|
|
|
} else {
|
|
|
|
// assume localhost
|
|
|
|
$url = 'http://localhost' . $config['root'] . $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Downloading $url\n";
|
|
|
|
|
|
|
|
passthru('curl -s -N ' . escapeshellarg($url));
|
|
|
|
|
|
|
|
unlink($filename);
|
2012-03-14 17:14:09 +01:00
|
|
|
unlink($inc_filename);
|
2012-03-14 15:44:29 +01:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
2012-03-14 06:45:59 +01:00
|
|
|
|