get_httpd_privileges() function for CLI scripts
This commit is contained in:
parent
2482723ff2
commit
64c1f6821c
|
@ -1,5 +1,36 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This script will look for Tinyboard in the following places (in order):
|
||||||
|
* - ./
|
||||||
|
* - ./Tinyboard/
|
||||||
|
* - ../
|
||||||
|
*/
|
||||||
|
|
||||||
|
$shell_path = getcwd();
|
||||||
|
|
||||||
|
if(file_exists('inc/functions.php'))
|
||||||
|
$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
|
||||||
|
die('Could not locate Tinyboard directory!');
|
||||||
|
|
||||||
|
if($dir && !chdir($dir))
|
||||||
|
die('Could not change directory to ' . $dir . '!');
|
||||||
|
|
||||||
|
// follow symlink
|
||||||
|
chdir(realpath('inc') . '/..');
|
||||||
|
|
||||||
|
require 'inc/functions.php';
|
||||||
|
require 'inc/display.php';
|
||||||
|
require 'inc/template.php';
|
||||||
|
require 'inc/database.php';
|
||||||
|
require 'inc/user.php';
|
||||||
|
require 'inc/mod.php';
|
||||||
|
|
||||||
$mod = Array(
|
$mod = Array(
|
||||||
'id' => -1,
|
'id' => -1,
|
||||||
'type' => ADMIN,
|
'type' => ADMIN,
|
||||||
|
@ -7,4 +38,44 @@ $mod = Array(
|
||||||
'boards' => Array('*')
|
'boards' => Array('*')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function get_httpd_privileges() {
|
||||||
|
global $config, $shell_path;
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
if(!is_writable('inc/'))
|
||||||
|
die("get_httpd_privileges(): inc/ directory is not writable\n");
|
||||||
|
|
||||||
|
$filename = '.' . md5(rand()) . '.php';
|
||||||
|
|
||||||
|
echo "Copying rebuilder to web directory...\n";
|
||||||
|
|
||||||
|
copy($shell_path . '/' . $_SERVER['PHP_SELF'], $filename);
|
||||||
|
copy(__FILE__, 'inc/cli.php');
|
||||||
|
|
||||||
|
chmod($filename, 0666);
|
||||||
|
chmod('inc/cli.php', 0666);
|
||||||
|
|
||||||
|
if(preg_match('/^https?:\/\//', $config['root'])) {
|
||||||
|
$url = $config['root'] . $filename;
|
||||||
|
} else {
|
||||||
|
// assume localhost
|
||||||
|
$url = 'http://localhost' . $config['root'] . $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Downloading $url\n";
|
||||||
|
|
||||||
|
passthru('curl -s -N ' . escapeshellarg($url));
|
||||||
|
|
||||||
|
unlink($filename);
|
||||||
|
unlink('inc/cli.php');
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
#!/usr/bin/php
|
#!/usr/bin/php
|
||||||
<?php
|
<?php
|
||||||
require 'inc/functions.php';
|
|
||||||
require 'inc/display.php';
|
|
||||||
require 'inc/template.php';
|
|
||||||
require 'inc/database.php';
|
|
||||||
require 'inc/user.php';
|
|
||||||
require 'inc/mod.php';
|
|
||||||
|
|
||||||
require dirname(__FILE__) . '/inc/cli.php';
|
require dirname(__FILE__) . '/inc/cli.php';
|
||||||
|
|
||||||
$mod = Array(
|
$mod = Array(
|
||||||
|
@ -21,31 +14,7 @@
|
||||||
echo "== Tinyboard {$config['version']} ==\n";
|
echo "== Tinyboard {$config['version']} ==\n";
|
||||||
|
|
||||||
if(!is_writable($config['file_script'])) {
|
if(!is_writable($config['file_script'])) {
|
||||||
echo "Dropping priviledges... (I can't operate as user; I need PHP's rights.)\n";
|
get_httpd_privileges();
|
||||||
|
|
||||||
$filename = '.' . md5(rand()) . '.php';
|
|
||||||
|
|
||||||
echo "Copying rebuilder to web directory...\n";
|
|
||||||
copy(__FILE__, $filename);
|
|
||||||
chmod($filename, 0666);
|
|
||||||
|
|
||||||
if(preg_match('/^https?:\/\//', $config['root'])) {
|
|
||||||
$url = $config['root'] . $filename;
|
|
||||||
} else {
|
|
||||||
// assume localhost
|
|
||||||
$url = 'http://localhost' . $config['root'] . $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Downloading $url\n";
|
|
||||||
|
|
||||||
passthru('curl -s -N ' . escapeshellarg($url));
|
|
||||||
|
|
||||||
echo "\n".'Cleaning up afterwards...'."\n";
|
|
||||||
|
|
||||||
unlink($filename);
|
|
||||||
|
|
||||||
echo "Bye!\n";
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Clearing template cache...\n";
|
echo "Clearing template cache...\n";
|
||||||
|
|
Loading…
Reference in New Issue