From a79b8c473b8ac136ede9f1333be891b11d068f76 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Wed, 14 Mar 2012 16:45:59 +1100 Subject: use system account --- tools/inc/cli.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tools/inc/cli.php (limited to 'tools/inc') diff --git a/tools/inc/cli.php b/tools/inc/cli.php new file mode 100644 index 00000000..5305c1ac --- /dev/null +++ b/tools/inc/cli.php @@ -0,0 +1,10 @@ + -1, + 'type' => ADMIN, + 'username' => '?', + 'boards' => Array('*') +); + + -- cgit v1.3 From 64c1f6821c90297cf3d1c4b8a4bbec6fe4449016 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 15 Mar 2012 01:44:29 +1100 Subject: get_httpd_privileges() function for CLI scripts --- tools/inc/cli.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/rebuild.php | 33 +------------------------- 2 files changed, 72 insertions(+), 32 deletions(-) (limited to 'tools/inc') diff --git a/tools/inc/cli.php b/tools/inc/cli.php index 5305c1ac..fbb3cfc5 100644 --- a/tools/inc/cli.php +++ b/tools/inc/cli.php @@ -1,5 +1,36 @@ -1, 'type' => ADMIN, @@ -7,4 +38,44 @@ $mod = 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); +} diff --git a/tools/rebuild.php b/tools/rebuild.php index 56f94aa9..0dfd9899 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -1,12 +1,5 @@ #!/usr/bin/php Date: Thu, 15 Mar 2012 02:11:38 +1100 Subject: $TINYBOARD_PATH environment varaible --- tools/inc/cli.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'tools/inc') diff --git a/tools/inc/cli.php b/tools/inc/cli.php index fbb3cfc5..fcf1c26a 100644 --- a/tools/inc/cli.php +++ b/tools/inc/cli.php @@ -2,6 +2,7 @@ /* * This script will look for Tinyboard in the following places (in order): + * - $TINYBOARD_PATH environment varaible * - ./ * - ./Tinyboard/ * - ../ @@ -9,7 +10,9 @@ $shell_path = getcwd(); -if(file_exists('inc/functions.php')) +if(getenv('TINYBOARD_PATH') !== false) + $dir = getenv('TINYBOARD_PATH'); +elseif(file_exists('inc/functions.php')) $dir = false; elseif(file_exists('Tinyboard') && is_dir('Tinyboard') && file_exists('Tinyboard/inc/functions.php')) $dir = 'Tinyboard'; @@ -21,8 +24,12 @@ else if($dir && !chdir($dir)) die('Could not change directory to ' . $dir . '!'); -// follow symlink -chdir(realpath('inc') . '/..'); +if(!getenv('TINYBOARD_PATH')) { + // follow symlink + chdir(realpath('inc') . '/..'); +} + +echo 'Tinyboard: ' . getcwd() . "\n"; require 'inc/functions.php'; require 'inc/display.php'; -- cgit v1.3 From 9e20b4071f485e63b63d7c93249af00e8e2df3b0 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 15 Mar 2012 03:14:09 +1100 Subject: copy environment when dropping privileges --- tools/inc/cli.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'tools/inc') diff --git a/tools/inc/cli.php b/tools/inc/cli.php index fcf1c26a..8fdb6c39 100644 --- a/tools/inc/cli.php +++ b/tools/inc/cli.php @@ -8,6 +8,7 @@ * - ../ */ +set_time_limit(0); $shell_path = getcwd(); if(getenv('TINYBOARD_PATH') !== false) @@ -56,21 +57,33 @@ function get_httpd_privileges() { 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'; + $inc_filename = '.' . md5(rand()) . '.php'; echo "Copying rebuilder to web directory...\n"; - copy($shell_path . '/' . $_SERVER['PHP_SELF'], $filename); - copy(__FILE__, 'inc/cli.php'); + // replace "/inc/cli.php" with its new filename + passthru("cat " . escapeshellarg($shell_path . '/' . $_SERVER['PHP_SELF']) . " | sed \"s/'\/inc\/cli\.php'/'\/{$inc_filename}'/\" > {$filename}"); + + // copy environment + $inc_header = " Date: Thu, 15 Mar 2012 22:16:26 +1100 Subject: pass command line arguments to http client --- tools/inc/cli.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tools/inc') diff --git a/tools/inc/cli.php b/tools/inc/cli.php index 8fdb6c39..1dcf12a6 100644 --- a/tools/inc/cli.php +++ b/tools/inc/cli.php @@ -30,7 +30,7 @@ if(!getenv('TINYBOARD_PATH')) { chdir(realpath('inc') . '/..'); } -echo 'Tinyboard: ' . getcwd() . "\n"; +putenv('TINYBOARD_PATH=' . getcwd()); require 'inc/functions.php'; require 'inc/display.php'; @@ -47,7 +47,7 @@ $mod = Array( ); function get_httpd_privileges() { - global $config, $shell_path; + global $config, $shell_path, $argv; if(php_sapi_name() != 'cli') die("get_httpd_privileges(): invoked from HTTP client.\n"); @@ -65,15 +65,18 @@ function get_httpd_privileges() { // replace "/inc/cli.php" with its new filename passthru("cat " . escapeshellarg($shell_path . '/' . $_SERVER['PHP_SELF']) . " | sed \"s/'\/inc\/cli\.php'/'\/{$inc_filename}'/\" > {$filename}"); - // copy environment $inc_header = " Date: Sun, 18 Mar 2012 00:36:51 +1100 Subject: Don't forget new lines on error. --- tools/inc/cli.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/inc') diff --git a/tools/inc/cli.php b/tools/inc/cli.php index 1dcf12a6..4dc19412 100644 --- a/tools/inc/cli.php +++ b/tools/inc/cli.php @@ -20,10 +20,10 @@ elseif(file_exists('Tinyboard') && is_dir('Tinyboard') && file_exists('Tinyboard elseif(file_exists('../inc/functions.php')) $dir = '..'; else - die('Could not locate Tinyboard directory!'); + die("Could not locate Tinyboard directory!\n"); if($dir && !chdir($dir)) - die('Could not change directory to ' . $dir . '!'); + die("Could not change directory to {$dir}\n"); if(!getenv('TINYBOARD_PATH')) { // follow symlink -- cgit v1.3