From ff697004b08630d16d55f699f353147dc7e60f0c Mon Sep 17 00:00:00 2001 From: Marcin Ɓabanowski Date: Fri, 2 Mar 2012 22:41:04 +0100 Subject: a command-line tool for rebuilding js, html, etc.; based on mod.php; also introduced dynamic main.js names in order to prevent aggressive caching, based on filemtime of templates/main.js --- tools/rebuild.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 tools/rebuild.php (limited to 'tools') diff --git a/tools/rebuild.php b/tools/rebuild.php new file mode 100755 index 00000000..8be13f27 --- /dev/null +++ b/tools/rebuild.php @@ -0,0 +1,67 @@ +#!/usr/bin/php + "{$config['dir']['template']}/cache" + )); + $twig->clearCacheFiles(); + + echo 'Regenerating theme files...'."\n"; + rebuildThemes('all'); + + echo 'Generating Javascript file...'."\n"; + buildJavascript(); + + $boards = listBoards(); + + foreach($boards as &$board) { + echo "Opening board /{$board['uri']}/...\n"; + openBoard($board['uri']); + + echo 'Creating index pages...'+"\n"; + buildIndex(); + + $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); + while($post = $query->fetch()) { + echo "Rebuilding #{$post['id']}...\n"; + buildThread($post['id']); + } + } + echo 'Complete!'."\n"; + + printf('Took %g seconds.'."\n", microtime(true) - $start); + + //modLog('Rebuilt everything using tools/rebuild.php'); +?> -- cgit v1.3 From a2d29860e6773b181e1c0670e2458e43321e2cd2 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Wed, 14 Mar 2012 15:55:12 +1100 Subject: rebuild.php revision --- tools/rebuild.php | 70 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'tools') diff --git a/tools/rebuild.php b/tools/rebuild.php index 8be13f27..8bb8373b 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -1,67 +1,75 @@ #!/usr/bin/php "{$config['dir']['template']}/cache" )); $twig->clearCacheFiles(); - - echo 'Regenerating theme files...'."\n"; + + echo "Regenerating theme files...\n"; rebuildThemes('all'); - - echo 'Generating Javascript file...'."\n"; + + echo "Generating Javascript file...\n"; buildJavascript(); - + $boards = listBoards(); - + foreach($boards as &$board) { echo "Opening board /{$board['uri']}/...\n"; openBoard($board['uri']); - - echo 'Creating index pages...'+"\n"; + + echo "Creating index pages...\n"; buildIndex(); - + $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while($post = $query->fetch()) { echo "Rebuilding #{$post['id']}...\n"; buildThread($post['id']); } } - echo 'Complete!'."\n"; + + printf("Complete! Took %g seconds\n", microtime(true) - $start); + + // modLog('Rebuilt everything using tools/rebuild.php'); - printf('Took %g seconds.'."\n", microtime(true) - $start); - - //modLog('Rebuilt everything using tools/rebuild.php'); -?> -- cgit v1.3 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 ++++++++++ tools/rebuild.php | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tools/inc/cli.php (limited to 'tools') 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('*') +); + + diff --git a/tools/rebuild.php b/tools/rebuild.php index 8bb8373b..9099ffeb 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -7,7 +7,14 @@ require 'inc/user.php'; require 'inc/mod.php'; - set_time_limit($config['mod']['rebuild_timelimit']); + require dirname(__FILE__) . '/inc/cli.php'; + + $mod = Array( + 'id' => -1, + 'type' => ADMIN, + 'username' => '?', + 'boards' => Array('*') + ); $start = microtime(true); @@ -71,5 +78,5 @@ printf("Complete! Took %g seconds\n", microtime(true) - $start); - // modLog('Rebuilt everything using tools/rebuild.php'); + modLog('Rebuilt everything using tools/rebuild.php'); -- cgit v1.3 From 9df2ce179e87694eed2be5bac4293f9cccaf7870 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Wed, 14 Mar 2012 21:55:22 +1100 Subject: per-board javascript files --- tools/rebuild.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools') diff --git a/tools/rebuild.php b/tools/rebuild.php index 9099ffeb..56f94aa9 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -60,6 +60,8 @@ echo "Generating Javascript file...\n"; buildJavascript(); + $main_js = $config['file_script']; + $boards = listBoards(); foreach($boards as &$board) { @@ -69,6 +71,12 @@ echo "Creating index pages...\n"; buildIndex(); + if($config['file_script'] != $main_js) { + // different javascript file + echo "Generating Javascript file...\n"; + buildJavascript(); + } + $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while($post = $query->fetch()) { echo "Rebuilding #{$post['id']}...\n"; -- 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') 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') 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') 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 03:15:45 +1100 Subject: remove redundant code --- tools/rebuild.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'tools') diff --git a/tools/rebuild.php b/tools/rebuild.php index 0dfd9899..29331ce4 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -2,13 +2,6 @@ -1, - 'type' => ADMIN, - 'username' => '?', - 'boards' => Array('*') - ); - $start = microtime(true); echo "== Tinyboard {$config['version']} ==\n"; -- cgit v1.3 From 224c7763076bc6c59aaddaa6fb47091b95ffb46e Mon Sep 17 00:00:00 2001 From: Michael Save 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') 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: Thu, 15 Mar 2012 22:37:43 +1100 Subject: rebuild.php command line switches (--quiet, --board, etc.) --- tools/rebuild.php | 80 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/rebuild.php b/tools/rebuild.php index 29331ce4..0e63dc74 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -1,25 +1,56 @@ #!/usr/bin/php + * Rebuild only the specified board. + * + * -f, --full + * Rebuild replies as well as threads (re-markup). + * + */ + require dirname(__FILE__) . '/inc/cli.php'; - $start = microtime(true); - - echo "== Tinyboard {$config['version']} ==\n"; - if(!is_writable($config['file_script'])) { get_httpd_privileges(); } - echo "Clearing template cache...\n"; + $start = microtime(true); + + // parse command line + $opts = getopt('qfb:', Array('board:', 'quick', 'full', 'quiet')); + $options = Array(); + + $options['board'] = isset($opts['board']) ? $opts['board'] : (isset($opts['b']) ? $opts['b'] : false); + $options['quiet'] = isset($opts['q']) || isset($opts['quiet']); + $options['quick'] = isset($opts['quick']); + $options['full'] = isset($opts['full']) || isset($opts['f']); + + if(!$options['quiet']) + echo "== Tinyboard {$config['version']} ==\n"; + + if(!$options['quiet']) + echo "Clearing template cache...\n"; $twig = new Twig_Environment($loader, Array( 'cache' => "{$config['dir']['template']}/cache" )); $twig->clearCacheFiles(); - echo "Regenerating theme files...\n"; + if(!$options['quiet']) + echo "Regenerating theme files...\n"; rebuildThemes('all'); - echo "Generating Javascript file...\n"; + if(!$options['quiet']) + echo "Generating Javascript file...\n"; buildJavascript(); $main_js = $config['file_script']; @@ -27,26 +58,47 @@ $boards = listBoards(); foreach($boards as &$board) { - echo "Opening board /{$board['uri']}/...\n"; - openBoard($board['uri']); + if($options['board'] && $board['uri'] != $options['board']) + continue; - echo "Creating index pages...\n"; - buildIndex(); + if(!$options['quiet']) + echo "Opening board /{$board['uri']}/...\n"; + openBoard($board['uri']); if($config['file_script'] != $main_js) { // different javascript file - echo "Generating Javascript file...\n"; + if(!$options['quiet']) + echo "Generating Javascript file...\n"; buildJavascript(); } + + if(!$options['quiet']) + echo "Creating index pages...\n"; + buildIndex(); + + if($options['quick']) + continue; // do no more + + if($options['full']) { + $query = query(sprintf("SELECT `id` FROM `posts_%s`", $board['uri'])) or error(db_error()); + while($post = $query->fetch()) { + if(!$options['quiet']) + echo "Rebuilding #{$post['id']}...\n"; + rebuildPost($post['id']); + } + } + $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while($post = $query->fetch()) { - echo "Rebuilding #{$post['id']}...\n"; + if(!$options['quiet']) + echo "Rebuilding #{$post['id']}...\n"; buildThread($post['id']); } } - printf("Complete! Took %g seconds\n", microtime(true) - $start); + if(!$options['quiet']) + printf("Complete! Took %g seconds\n", microtime(true) - $start); modLog('Rebuilt everything using tools/rebuild.php'); -- cgit v1.3 From 7d3938458175f03d0ca864bd4d08bc7f03306581 Mon Sep 17 00:00:00 2001 From: Michael Save 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') 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 From 0c8941fc5b463c4d8225e314ffd5da517953f98a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 18 Mar 2012 01:00:58 +1100 Subject: benchmark.php: Benchmark thumbnailing methods --- tools/benchmark.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 tools/benchmark.php (limited to 'tools') diff --git a/tools/benchmark.php b/tools/benchmark.php new file mode 100755 index 00000000..60aba638 --- /dev/null +++ b/tools/benchmark.php @@ -0,0 +1,52 @@ +#!/usr/bin/php +resize( + $config['thumb_ext'] ? $config['thumb_ext'] : $extension, + $config['thumb_width'], + $config['thumb_height'] + ); + + $thumb->to($out); + $thumb->_destroy(); + $image->destroy(); + } + $end = microtime(true); + + printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = ($count / ($end - $start)), 1000 / $rate); + + unlink($out); + } + + benchmark('gd'); + benchmark('imagick'); + benchmark('convert'); + -- cgit v1.3 From 8208d7151bc952462c9220304877525dcc398cea Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 18 Mar 2012 20:47:45 +1100 Subject: Close board before writing modlog entry. --- tools/rebuild.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/rebuild.php b/tools/rebuild.php index 0e63dc74..1560893c 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -100,5 +100,6 @@ if(!$options['quiet']) printf("Complete! Took %g seconds\n", microtime(true) - $start); + unset($board); modLog('Rebuilt everything using tools/rebuild.php'); -- cgit v1.3