function execute() { echo "search class files..."; $files = find_files($this->_source_dir, array('extnames' => array('.php'), 'excludes' => array('_config'))); echo "ok\n\n"; $this->_files = $files; spl_autoload_register(array($this, 'autoload')); $classes = get_declared_classes(); $classes = array_merge($classes, get_declared_interfaces()); foreach ($files as $path) { require_once $path; } $new_classes = get_declared_classes(); $new_classes = array_merge($new_classes, get_declared_interfaces()); $found = array_diff($new_classes, $classes); $files = array(); foreach ($found as $class) { $r = new ReflectionClass($class); $files[$class] = $r->getFileName(); } $arr = array(); $len = strlen($this->_source_dir); foreach ($files as $class => $path) { $filename = str_replace(array('/', '\\'), '/', substr($path, $len + 1)); $class = strtolower($class); $arr[$class] = $filename; } $output = "<?php global \$G_CLASS_FILES;\$G_CLASS_FILES = "; $output .= str_replace(array(' ', "\n"), '', var_export($arr, true)); $output .= ";\n"; file_put_contents($this->_output_file, $output, LOCK_EX); echo "ok\n"; }
function find_files($path, $pattern) { $path = rtrim(str_replace("\\", "/", $path), '/') . '/'; $entries = array(); $matches = array(); $dir = dir($path); while (false !== ($entry = $dir->read())) { $entries[] = $entry; } $dir->close(); foreach ($entries as $entry) { $fullname = $path . $entry; if ($entry != '.' && $entry != '..' && is_dir($fullname)) { $merge = array_merge($matches, find_files($fullname, $pattern)); foreach ($merge as $m) { array_push($matches, $m); } } else { if (is_file($fullname) && preg_match($pattern, $fullname)) { array_push($matches, $fullname); } } } return array_unique($matches); }
function find_files($path, $pattern, $callback) { $path = rtrim(str_replace("\\", "/", $path), '/') . '/*'; foreach (glob($path) as $fullname) { if (is_dir($fullname)) { find_files($fullname, $pattern, $callback); } else { if (preg_match($pattern, $fullname)) { $fullname = str_replace('bin/', '', $fullname); call_user_func($callback, $fullname); } } } }
/** * Indexes the install module files * * @since 1.1 * * @return void **/ function installed () { if (!is_dir($this->path)) return false; $path = $this->path; $files = array(); find_files(".php",$path,$path,$files); if (empty($files)) return $files; foreach ($files as $file) { // Skip if the file can't be read or isn't a real file at all if (!is_readable($path.$file) && !is_dir($path.$file)) continue; // Add the module file to the registry $module = new ModuleFile($path,$file); if ($module->addon) $this->modules[$module->subpackage] = $module; else $this->legacy[] = md5_file($path.$file); } }
function scanmodules($path = false) { global $Shopp; if (!$path) { $path = $this->path; } $modfilescan = array(); find_files(".php", $path, $path, $modfilescan); if (empty($modfilescan)) { return $modfilescan; } foreach ($modfilescan as $file) { if (!is_readable($path . $file)) { continue; } $ShipCalcClass = substr(basename($file), 0, -4); $modfiles[$ShipCalcClass] = $file; } $Shopp->Settings->save('shipcalc_modules', addslashes(serialize($modfiles))); $Shopp->Settings->save('shipcalc_lastscan', mktime()); return $modfiles; }
function find_files_with_dir($dir, &$dir_array) { // Create array of current directory $files = scandir($dir); if (is_array($files)) { foreach ($files as $val) { // Skip home and previous listings if ($val == '.' || $val == '..') { continue; } // If directory then dive deeper, else add file to directory key if (is_dir($dir . '/' . $val)) { // Add value to current array, dir or file $dir_array[$dir][] = $val; find_files($dir . '/' . $val, $dir_array); } else { $dir_array[$dir][] = $val; } } } ksort($dir_array); }
function find_files($base, $needle, $function, $userdata = NULL, $depth = 1) { // Do not set $depth by hand! It is used for internal depth checking only! $dir = dir($base); while ($file = $dir->read()) { if ($file != "." && $file != "..") { $path = sprintf("%s/%s", $base, $file); if (is_dir($path)) { find_files($path, $needle, $function, $userdata, $depth + 1); } else { if (preg_match($needle, $file)) { if (empty($userdata)) { $function($path, $file); } else { $function($path, $file, $userdata); } } } } } $dir->close(); }
function find_files($path, $pattern, $callback) { global $texts; global $xml; $path = rtrim(str_replace("\\", "/", $path), '/') . '/'; $matches = array(); $entries = array(); $dir = dir($path); while (false !== ($entry = $dir->read())) { $entries[] = $entry; } $dir->close(); foreach ($entries as $entry) { $fullname = $path . $entry; if ($entry != '.' && $entry != '..' && is_dir($fullname)) { find_files($fullname, $pattern, $callback); } else { if (is_file($fullname) && preg_match($pattern, $entry)) { call_user_func($callback, $fullname); } } } }
public function testFindFiles() { $this->createTempFiles(); $path = $this->path; $filesFound = find_files($path, 0, '*'); $this->assertSame(7, count($filesFound)); $jsFilesFound = find_js_files($path); $this->assertSame(2, count($jsFilesFound)); $htmlFilesFound = find_html_files($path); $this->assertSame(2, count($htmlFilesFound)); $phpFilesFound = find_php_files($path); $this->assertSame(2, count($phpFilesFound)); // Including subdirectories $filesFound = find_files($path, 0, '*', true); $this->assertSame(10, count($filesFound)); $jsFilesFound = find_js_files($path, true); $this->assertSame(3, count($jsFilesFound)); $htmlFilesFound = find_html_files($path, true); $this->assertSame(3, count($htmlFilesFound)); $phpFilesFound = find_php_files($path, true); $this->assertSame(3, count($phpFilesFound)); $this->assertInternalType('array', find_templates()); $this->removeTempFiles(); }
/** * Moves files or complete directories * * @param $from string Can be a file or a directory. Will move either the file or all files within the directory * @param $to string Where to move the file(s) to. If not specified then will get moved to the root folder * @param $strip Used for FTP only * @return mixed: Bool true on success, error string on failure, NULL if no action was taken * * NOTE: function should preferably not return in case of failure on only one file. * The current method makes error handling difficult */ function copy_content($from, $to = '', $strip = '') { global $phpbb_root_path, $user; if (strpos($from, $phpbb_root_path) !== 0) { $from = $phpbb_root_path . $from; } // When installing a MODX 1.2.0 MOD, this happens once in a long while. // Not sure why yet. if (is_array($to)) { return NULL; } if (strpos($to, $phpbb_root_path) !== 0) { $to = $phpbb_root_path . $to; } $files = array(); if (is_dir($from)) { // get all of the files within the directory $files = find_files($from, '.*'); } else { if (is_file($from)) { $files = array($from); } } if (empty($files)) { return false; } // ftp foreach ($files as $file) { if (is_dir($to)) { $to_file = str_replace(array($phpbb_root_path, $strip), '', $file); } else { $to_file = str_replace($phpbb_root_path, '', $to); } $this->recursive_mkdir(dirname($to_file)); if (!$this->transfer->overwrite_file($file, $to_file)) { // may as well return ... the MOD is likely dependent upon // the file that is being copied return sprintf($user->lang['MODS_FTP_FAILURE'], $to_file); } } return true; }
/** * List files matching specified PCRE pattern. * * @access public * @param string Relative or absolute path to the directory to be scanned. * @param string Search pattern (perl compatible regular expression). * @param integer Number of subdirectory levels to scan (set to 1 to scan only current). * @param integer This one is used internally to control recursion level. * @return array List of all files found matching the specified pattern. */ function find_files($directory, $pattern, $max_levels = 20, $_current_level = 1) { if ($_current_level <= 1) { if (strpos($directory, '\\') !== false) { $directory = str_replace('\\', '/', $directory); } if (empty($directory)) { $directory = './'; } else { if (substr($directory, -1) != '/') { $directory .= '/'; } } } $files = array(); $subdir = array(); if (is_dir($directory)) { $handle = @opendir($directory); while (($file = @readdir($handle)) !== false) { if ($file == '.' || $file == '..') { continue; } $fullname = $directory . $file; if (is_dir($fullname)) { if ($_current_level < $max_levels) { $subdir = array_merge($subdir, find_files($fullname . '/', $pattern, $max_levels, $_current_level + 1)); } } else { if (preg_match('/^' . $pattern . '$/i', $file)) { $files[] = $fullname; } } } @closedir($handle); sort($files); } return array_merge($files, $subdir); }
/** * Recursively delete a directory * * @param string $path (required) Directory path to recursively delete * @author jasmineaura */ function recursive_unlink($path) { global $phpbb_root_path, $phpEx, $user; // Insurance - this should never really happen if ($path == $phpbb_root_path || is_file("{$path}/common.{$phpEx}")) { return false; } // Get all of the files in the source directory $files = find_files($path, '.*'); // Get all of the sub-directories in the source directory $subdirs = find_files($path, '.*', 20, true); // Delete all the files foreach ($files as $file) { if (!unlink($file)) { return sprintf($user->lang['MODS_RMFILE_FAILURE'], $file); } } // Delete all the sub-directories, in _reverse_ order (array_pop) for ($i = 0, $cnt = count($subdirs); $i < $cnt; $i++) { $subdir = array_pop($subdirs); if (!rmdir($subdir)) { return sprintf($user->lang['MODS_RMDIR_FAILURE'], $subdir); } } // Finally, delete the directory itself if (!rmdir($path)) { return sprintf($user->lang['MODS_RMDIR_FAILURE'], $path); } return true; }
function find_files($dir, $is_ext_dir = FALSE, $ignore = FALSE) { global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped, $exts_tested; $o = opendir($dir) or error("cannot open directory: {$dir}"); while (($name = readdir($o)) !== FALSE) { if (is_dir("{$dir}/{$name}") && !in_array($name, array('.', '..', 'CVS'))) { $skip_ext = $is_ext_dir && !in_array($name, $exts_to_test); if ($skip_ext) { $exts_skipped++; } find_files("{$dir}/{$name}", FALSE, $ignore || $skip_ext); } // Cleanup any left-over tmp files from last run. if (substr($name, -4) == '.tmp') { @unlink("{$dir}/{$name}"); continue; } // Otherwise we're only interested in *.phpt files. if (substr($name, -5) == '.phpt') { if ($ignore) { $ignored_by_ext++; } else { $testfile = realpath("{$dir}/{$name}"); $test_files[] = $testfile; } } } closedir($o); }
function run_test($php, $file, $env) { global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS; global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; $temp_filenames = null; $org_file = $file; if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) { $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE']; } if (is_array($file)) { $file = $file[0]; } if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => ''); $fp = fopen($file, "rt") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); if ($line === false) { $bork_info = "cannot read test"; $borked = true; } } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!$borked && strncmp('--TEST--', $line, 8)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; $secfile = false; $secdone = false; while (!feof($fp)) { $line = fgets($fp); // Match the beginning of a section. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { $section = $r[1]; if (isset($section_text[$section])) { $bork_info = "duplicated {$section} section"; $borked = true; } $section_text[$section] = ''; $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL'; $secdone = false; continue; } // Add to the section text. if (!$secdone) { $section_text[$section] .= $line; } // End of actual test? if ($secfile && preg_match('/^===DONE===\\s*$/', $line)) { $secdone = true; } } // the redirect section allows a set of tests to be reused outside of // a given test dir if (!$borked) { if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { $bork_info = "missing section --FILE--"; $borked = true; } if (@count($section_text['FILEEOF']) == 1) { $section_text['FILE'] = preg_replace("/[\r\n]+\$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } if (@count($section_text['FILE_EXTERNAL']) == 1) { // don't allow tests to retrieve files from anywhere but this subdirectory $section_text['FILE_EXTERNAL'] = dirname($file) . '/' . trim(str_replace('..', '', $section_text['FILE_EXTERNAL'])); if (file_exists($section_text['FILE_EXTERNAL'])) { $section_text['FILE'] = file_get_contents($section_text['FILE_EXTERNAL']); unset($section_text['FILE_EXTERNAL']); } else { $bork_info = "could not load --FILE_EXTERNAL-- " . dirname($file) . '/' . trim($section_text['FILE_EXTERNAL']); $borked = true; } } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; } } } fclose($fp); $shortname = str_replace($cwd . '/', '', $file); $tested_file = $shortname; if ($borked) { show_result("BORK", $bork_info, $tested_file); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); return 'BORKED'; } $tested = trim($section_text['TEST']); /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { if (isset($php_cgi)) { $old_php = $php; $php = $php_cgi . ' -C '; } else { if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; } else { if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath(dirname($php) . "/../../sapi/cgi/php-cgi") . ' -C '; } else { if (file_exists("./sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); return 'SKIPPED'; } } } } } show_test($test_idx, $shortname); if (is_array($IN_REDIRECT)) { $temp_dir = $test_dir = $IN_REDIRECT['dir']; } else { $temp_dir = $test_dir = realpath(dirname($file)); } if ($temp_source && $temp_target) { $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); } $main_file_name = basename($file, 'phpt'); $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_relative_file = str_replace(realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR, '', $test_file) . 't'; if ($temp_source && $temp_target) { $temp_skipif .= 's'; $temp_file .= 's'; $temp_clean .= 's'; $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file) . '.phps'; if (!is_dir(dirname($copy_file))) { mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); } if (isset($section_text['FILE'])) { save_text($copy_file, $section_text['FILE']); } $temp_filenames = array('file' => $copy_file, 'diff' => $diff_filename, 'log' => $log_filename, 'exp' => $exp_filename, 'out' => $output_filename, 'mem' => $memcheck_filename, 'php' => $temp_file, 'skip' => $temp_skipif, 'clean' => $temp_clean); } if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']); $tested_file = $tmp_relative_file; $section_text['FILE'] = "# original source file: {$shortname}\n" . $section_text['FILE']; } // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); @unlink($memcheck_filename); @unlink($temp_file); @unlink($test_file); @unlink($temp_skipif); @unlink($test_skipif); @unlink($tmp_post); @unlink($temp_clean); @unlink($test_clean); // Reset environment from any previous test. $env['REDIRECT_STATUS'] = ''; $env['QUERY_STRING'] = ''; $env['PATH_TRANSLATED'] = ''; $env['SCRIPT_FILENAME'] = ''; $env['REQUEST_METHOD'] = ''; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; if (!empty($section_text['ENV'])) { foreach (explode("\n", trim($section_text['ENV'])) as $e) { $e = explode('=', trim($e), 2); if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; } else { $env['USE_ZEND_ALLOC'] = '1'; } $output = system_with_timeout("{$extra} {$php} {$pass_options} -q {$ini_settings} {$test_skipif}", $env); if (!$cfg['keep']['skip']) { @unlink($test_skipif); } if (!strncasecmp('skip', ltrim($output), 4)) { if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $output, $m)) { show_result('SKIP', $tested, $tested_file, "reason: {$m['1']}", $temp_filenames); } else { show_result('SKIP', $tested, $tested_file, '', $temp_filenames); } if (isset($old_php)) { $php = $old_php; } if (!$cfg['keep']['skip']) { @unlink($test_skipif); } return 'SKIPPED'; } if (!strncasecmp('info', ltrim($output), 4)) { if (preg_match('/^\\s*info\\s*(.+)\\s*/i', $output, $m)) { $info = " (info: {$m['1']})"; } } if (!strncasecmp('warn', ltrim($output), 4)) { if (preg_match('/^\\s*warn\\s*(.+)\\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ $info = " (warn: {$m['1']})"; } } } } if (@count($section_text['REDIRECTTEST']) == 1) { $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); if (count($IN_REDIRECT['TESTS']) == 1) { if (is_array($org_file)) { $test_files[] = $org_file[1]; } else { $GLOBALS['test_files'] = $test_files; find_files($IN_REDIRECT['TESTS']); foreach ($GLOBALS['test_files'] as $f) { $test_files[] = array($f, $file); } } $test_cnt += @count($test_files) - 1; $test_idx--; show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); // set up environment $redirenv = array_merge($environment, $IN_REDIRECT['ENV']); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR; usort($test_files, "test_sort"); run_all_tests($test_files, $redirenv, $tested); show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); // a redirected test never fails $IN_REDIRECT = false; return 'REDIR'; } else { $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); } } if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { if (is_array($org_file)) { $file = $org_file[0]; } $bork_info = "Redirected test did not contain redirection info"; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); return 'BORKED'; } // We've satisfied the preconditions - run the test! show_file_block('php', $section_text['FILE'], 'TEST'); save_text($test_file, $section_text['FILE'], $temp_file); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['REDIRECT_STATUS'] = '1'; $env['QUERY_STRING'] = $query_string; $env['PATH_TRANSLATED'] = $test_file; $env['SCRIPT_FILENAME'] = $test_file; if (array_key_exists('COOKIE', $section_text)) { $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); } else { $env['HTTP_COOKIE'] = ''; } $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" 2>&1 < {$tmp_post}"; } else { if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); if (array_key_exists('GZIP_POST', $section_text) && function_exists('gzencode')) { $post = gzencode($post, 9, FORCE_GZIP); $env['HTTP_CONTENT_ENCODING'] = 'gzip'; } else { if (array_key_exists('DEFLATE_POST', $section_text) && function_exists('gzcompress')) { $post = gzcompress($post, 9); $env['HTTP_CONTENT_ENCODING'] = 'deflate'; } } save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" 2>&1 < {$tmp_post}"; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" {$args} 2>&1"; } } if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; if ($valgrind_version >= 330) { /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file={$memcheck_filename} {$cmd}"; } else { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file-exactly={$memcheck_filename} {$cmd}"; } } else { $env['USE_ZEND_ALLOC'] = '1'; } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] . "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "\nQUERY_STRING = " . $env['QUERY_STRING'] . "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] . "\nSCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "\nHTTP_COOKIE = " . $env['HTTP_COOKIE'] . "\nCOMMAND {$cmd}\n"; } $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { if (trim($section_text['CLEAN'])) { show_file_block('clean', $section_text['CLEAN']); save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { $clean_params = array(); settings2array($ini_overwrites, $clean_params); settings2params($clean_params); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; system_with_timeout("{$extra} {$php} {$pass_options} -q {$clean_params} {$test_clean}", $env); } if (!$cfg['keep']['clean']) { @unlink($test_clean); } } } @unlink($tmp_post); $leaked = false; $passed = false; if ($leak_check) { // leak check $leaked = filesize($memcheck_filename) > 0; if (!$leaked) { @unlink($memcheck_filename); } } // Does the output match what is expected? $output = preg_replace("/\r\n/", "\n", trim($out)); /* when using CGI, strip the headers from the output */ $headers = ""; if (isset($old_php) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { $output = trim($match[2]); $rh = preg_split("/[\n\r]+/", $match[1]); $headers = array(); foreach ($rh as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $headers[trim($line[0])] = trim($line[1]); } } } $failed_headers = false; if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); $lines = preg_split("/[\n\r]+/", $section_text['EXPECTHEADERS']); foreach ($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $want[trim($line[0])] = trim($line[1]); $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } $org_headers = $headers; $headers = array(); $output_headers = array(); foreach ($want as $k => $v) { if (isset($org_headers[$k])) { $headers = $org_headers[$k]; $output_headers[] = $k . ': ' . $org_headers[$k]; } if (!isset($org_headers[$k]) || $org_headers[$k] != $v) { $failed_headers = true; } } ksort($wanted_headers); $wanted_headers = join("\n", $wanted_headers); ksort($output_headers); $output_headers = join("\n", $output_headers); } show_file_block('out', $output); if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } show_file_block('exp', $wanted); $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); $wanted_re = str_replace(array('%unicode_string_optional%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $wanted_re); $wanted_re = str_replace(array('%unicode\\|string%', '%string\\|unicode%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', $wanted_re); $wanted_re = str_replace(array('%u\\|b%', '%b\\|u%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', $wanted_re); // Stick to basics $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace('%s', '[^\\r\\n]+', $wanted_re); $wanted_re = str_replace('%a', '.+', $wanted_re); $wanted_re = str_replace('%w', '\\s*', $wanted_re); $wanted_re = str_replace('%i', '[+-]?\\d+', $wanted_re); $wanted_re = str_replace('%d', '\\d+', $wanted_re); $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re); $wanted_re = str_replace('%f', '[+-]?\\.?\\d+\\.?\\d*(?:[Ee][+-]?\\d+)?', $wanted_re); $wanted_re = str_replace('%c', '.', $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match((string) "/^{$wanted_re}\$/s", $output)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (isset($old_php)) { $php = $old_php; } if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); show_file_block('exp', $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (isset($old_php)) { $php = $old_php; } if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } } $wanted_re = null; } // Test failed so we need to report details. if ($failed_headers) { $passed = false; $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; $output = $output_headers . "\n--HEADERS--\n" . $output; if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } } if ($leaked) { $restype[] = 'LEAK'; } if ($warn) { $restype[] = 'WARN'; } if (!$passed) { if (isset($section_text['XFAIL'])) { $restype[] = 'XFAIL'; } else { $restype[] = 'FAIL'; } } if (!$passed) { // write .exp if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, (string) $wanted, FILE_BINARY) === false) { error("Cannot create expected test output - {$exp_filename}"); } // write .out if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, (string) $output, FILE_BINARY) === false) { error("Cannot create test output - {$output_filename}"); } // write .diff $diff = generate_diff($wanted, $wanted_re, $output); show_file_block('diff', $diff); if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, (string) $diff, FILE_BINARY) === false) { error("Cannot create test diff - {$diff_filename}"); } // write .log if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n", FILE_BINARY) === false) { error("Cannot create test log - {$log_filename}"); error_report($file, $log_filename, $tested); } } show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames); foreach ($restype as $type) { $PHP_FAILED_TESTS[$type . 'ED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [{$tested_file}]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); } if (isset($old_php)) { $php = $old_php; } return $restype[0] . 'ED'; }
function copy_content($from, $to = '', $strip = '') { global $phpbb_root_path, $user; if (strpos($from, $phpbb_root_path) !== 0) { $from = $phpbb_root_path . $from; } if (strpos($to, $phpbb_root_path) !== 0) { $to = $phpbb_root_path . $to; } // Note: phpBB's compression class does support adding a whole directory at a time. // However, I chose not to use that function because it would not allow AutoMOD's // error handling to work the same as for FTP & Direct methods. $files = array(); if (is_dir($from)) { // get all of the files within the directory $files = find_files($from, '.*'); } else { if (is_file($from)) { $files = array($from); } } if (empty($files)) { return false; } foreach ($files as $file) { if (is_dir($to)) { // this would find the directory part specified in MODX $to_file = str_replace(array($phpbb_root_path, $strip), '', $to); // and this fetches any subdirectories and the filename of the destination file $to_file .= substr($file, strpos($file, $to_file) + strlen($to_file)); } else { $to_file = str_replace($phpbb_root_path, '', $to); } // filename calculation is involved here: // and prepend the "files" directory if (!$this->compress->add_custom_file($file, 'files/' . $to_file)) { return sprintf($user->lang['WRITE_MANUAL_FAIL'], $to_file); } } // return true since we are now taking an action - NULL implies no action return true; }
function find_files($dirname, $ext, $file_list = array()) { global $file_list; // Loop through the folder $dir = dir($dirname); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Deep find directories if (is_dir($dirname . DS . $entry)) { find_files($dirname . DS . $entry, $ext, $file_list); } else { foreach ($ext as $key => $value) { if (substr($entry, -$value) == $key) { $file_list[] = $dirname . DS . $entry; } } } } // Clean up $dir->close(); return $file_list; }
$file->close(); } catch (IOException $e) { error($e->getMessage() . ' "' . $file->getFilepath() . '"'); } } $shell =& new RuntimeContext(new ShellContext()); $paramsHastable =& $shell->getParams(); if ($paramsHastable->size() != 2 || '--help' == $paramsHastable->get(1)) { help(); } else { $path = $paramsHastable->get(1); if (!SysDirectory::exists($path)) { error('Le répertoire ' . $path . ' est inaccessible !'); } else { $files =& new Queue(); find_files($path, $files); if (0 == $files->size()) { error('Aucun fichier php a scanner'); } else { $shell->set('scan_results', new Queue()); $iterator =& $files->getIterator(); while ($iterator->hasNext()) { $entry =& $iterator->next(); scan_file($entry, $shell); } unset($files); $iterator =& $shell->get('scan_results')->getIterator(); while ($iterator->hasNext()) { $filepath = System::find_class_filepath($iterator->next()); scan_file(new SysFile($filepath), $shell); }
?> ?search=@php_uname" title="Tìm @php_uname"><font color="#00EE00">@php_uname</a></font> <!-- <a href="<?php echo $_SERVER['PHP_SELF']; ?> ?search=eval(gzinflate(base64_decode(" title="Tìm evaleval(gzinflate(base64_decode("><font color="00EE00">eval(gzinflate(base64_decode(</a></font> || <a href="<?php echo $_SERVER['PHP_SELF']; ?> ?search=/etc/passwd" title="Tìm /etc/passwd/"><font color="$00EE00">/etc/passwd</a></font> || --> </div><hr/><div style="font: normal 12px/2.4em Menlo, 'Andale Mono', 'Courier New', sans-serif;"><?php error_reporting(NULL); header("Content-Type: text/html; charset=utf-8"); find_files('.'); function find_files($seed) { if (!is_dir($seed)) { return false; } $files = array(); $dirs = array($seed); while (NULL !== ($dir = array_pop($dirs))) { if ($dh = opendir($dir)) { while (false !== ($file = readdir($dh))) { if ($file == '.' || $file == '..') { continue; } $path = $dir . '/' . $file; if (is_dir($path)) {
function process_edits($editor, $actions, $details, $change = false, $display = true, $reverse = false) { global $template, $user, $db, $phpbb_root_path, $force_install, $mod_installed; global $dest_inherits, $dest_template, $children, $config; $mod_installed = true; if ($reverse) { global $rev_actions; if (empty($rev_actions)) { // maybe should allow for potential extensions here $actions = parser::reverse_edits($actions); } else { $actions = $rev_actions; unset($rev_actions); } } $template->assign_vars(array('S_DISPLAY_DETAILS' => (bool) $display, 'S_CHANGE_FILES' => (bool) $change)); if (!empty($details['PHPBB_VERSION']) && $details['PHPBB_VERSION'] != $config['version']) { $version_warnig = sprintf($user->lang['VERSION_WARNING'], $details['PHPBB_VERSION'], $config['version']); $template->assign_vars(array('VERSION_WARNING' => $version_warnig, 'S_PHPBB_VESION' => true)); } if (!empty($details['AUTHOR_NOTES']) && $details['AUTHOR_NOTES'] != $user->lang['UNKNOWN_MOD_AUTHOR-NOTES']) { $template->assign_vars(array('S_AUTHOR_NOTES' => true, 'AUTHOR_NOTES' => nl2br($details['AUTHOR_NOTES']))); } // not all MODs will have edits (!) if (isset($actions['EDITS'])) { $template->assign_var('S_EDITS', true); foreach ($actions['EDITS'] as $filename => $edits) { // see if the file to be opened actually exists if (!file_exists("{$phpbb_root_path}{$filename}")) { $is_inherit = strpos($filename, 'styles/') !== false && !empty($dest_inherits) ? true : false; $template->assign_block_vars('edit_files', array('S_MISSING_FILE' => $is_inherit ? false : true, 'INHERIT_MSG' => $is_inherit ? sprintf($user->lang['INHERIT_NO_CHANGE'], $dest_template, $dest_inherits) : '', 'FILENAME' => $filename)); $mod_installed = $is_inherit ? $mod_installed : false; continue; } else { $template->assign_block_vars('edit_files', array('S_SUCCESS' => false, 'FILENAME' => $filename)); // If installing - not pre_install nor (pre_)uninstall, backup the file // This is to make sure it works with editor_ftp because write_method is // forced to direct when in preview modes, and ignored in editor_manual! if ($change && !$reverse) { $status = $editor->open_file($filename, $this->backup_root); } else { $status = $editor->open_file($filename); } if (is_string($status)) { $template->assign_block_vars('error', array('ERROR' => $status)); $mod_installed = false; continue; } $edit_success = true; foreach ($edits as $finds) { $comment = ''; foreach ($finds as $find => $commands) { if (isset($finds['comment']) && !$comment && $finds['comment'] != $user->lang['UNKNOWN_MOD_COMMENT']) { $comment = $finds['comment']; unset($finds['comment']); } if ($find == 'comment') { continue; } $find_tpl = array('FIND_STRING' => htmlspecialchars($find), 'COMMENT' => htmlspecialchars($comment)); $offset_ary = $editor->find($find); // special case for FINDs with no action associated if (is_null($commands)) { continue; } foreach ($commands as $type => $contents) { if (!$offset_ary) { $offset_ary['start'] = $offset_ary['end'] = false; } $status = false; $inline_template_ary = array(); $contents_orig = $contents; switch (strtoupper($type)) { case 'AFTER ADD': $status = $editor->add_string($find, $contents, 'AFTER', $offset_ary['start'], $offset_ary['end']); break; case 'BEFORE ADD': $status = $editor->add_string($find, $contents, 'BEFORE', $offset_ary['start'], $offset_ary['end']); break; case 'INCREMENT': case 'OPERATION': //$contents = ""; $status = $editor->inc_string($find, '', $contents); break; case 'REPLACE WITH': $status = $editor->replace_string($find, $contents, $offset_ary['start'], $offset_ary['end']); break; case 'IN-LINE-EDIT': // these aren't quite as straight forward. Still have multi-level arrays to sort through $inline_comment = ''; foreach ($contents as $inline_edit_id => $inline_edit) { if ($inline_edit_id === 'inline-comment') { // This is a special case for tucking comments in the array if ($inline_edit != $user->lang['UNKNOWN_MOD_INLINE-COMMENT']) { $inline_comment = $inline_edit; } continue; } foreach ($inline_edit as $inline_find => $inline_commands) { foreach ($inline_commands as $inline_action => $inline_contents) { // inline finds are pretty cantankerous, so do them in the loop $line = $editor->inline_find($find, $inline_find, $offset_ary['start'], $offset_ary['end']); if (!$line) { // find failed $status = $mod_installed = false; $inline_template_ary[] = array('FIND' => array('S_SUCCESS' => $status, 'NAME' => $user->lang[$type], 'COMMAND' => htmlspecialchars($inline_find)), 'ACTION' => array()); continue 2; } $inline_contents = $inline_contents[0]; $contents_orig = $inline_find; switch (strtoupper($inline_action)) { case 'IN-LINE-': $editor->last_string_offset = $line['string_offset'] + $line['find_length'] - 1; $status = true; continue 2; break; case 'IN-LINE-BEFORE-ADD': $status = $editor->inline_add($find, $inline_find, $inline_contents, 'BEFORE', $line['array_offset'], $line['string_offset'], $line['find_length']); break; case 'IN-LINE-AFTER-ADD': $status = $editor->inline_add($find, $inline_find, $inline_contents, 'AFTER', $line['array_offset'], $line['string_offset'], $line['find_length']); break; case 'IN-LINE-REPLACE': case 'IN-LINE-REPLACE-WITH': $status = $editor->inline_replace($find, $inline_find, $inline_contents, $line['array_offset'], $line['string_offset'], $line['find_length']); break; case 'IN-LINE-OPERATION': $status = $editor->inc_string($find, $inline_find, $inline_contents); break; default: $message = sprintf($user->lang['UNRECOGNISED_COMMAND'], $inline_action); trigger_error($message, E_USER_WARNING); // ERROR! break; } $inline_template_ary[] = array('FIND' => array('S_SUCCESS' => $status, 'NAME' => $user->lang[$type], 'COMMAND' => is_array($contents_orig) ? $user->lang['INVALID_MOD_INSTRUCTION'] : htmlspecialchars($contents_orig)), 'ACTION' => array('S_SUCCESS' => $status, 'NAME' => $user->lang[$inline_action], 'COMMAND' => is_array($inline_contents) ? $user->lang['INVALID_MOD_INSTRUCTION'] : htmlspecialchars($inline_contents))); } if (!$status) { $mod_installed = false; } $editor->close_inline_edit(); } } break; default: $message = sprintf($user->lang['UNRECOGNISED_COMMAND'], $type); trigger_error($message, E_USER_WARNING); // ERROR! break; } $template->assign_block_vars('edit_files.finds', array_merge($find_tpl, array('S_SUCCESS' => $status))); if (!$status) { $edit_success = false; $mod_installed = false; } if (sizeof($inline_template_ary)) { foreach ($inline_template_ary as $inline_template) { // We must assign the vars for the FIND first $template->assign_block_vars('edit_files.finds.actions', $inline_template['FIND']); // And now the vars for the ACTION $template->assign_block_vars('edit_files.finds.actions.inline', $inline_template['ACTION']); } $inline_template_ary = array(); } else { if (!is_array($contents_orig)) { $template->assign_block_vars('edit_files.finds.actions', array('S_SUCCESS' => $status, 'NAME' => $user->lang[$type], 'COMMAND' => htmlspecialchars($contents_orig))); } } } } $editor->close_edit(); } $template->alter_block_array('edit_files', array('S_SUCCESS' => $edit_success), true, 'change'); } if ($change) { $status = $editor->close_file("{$this->edited_root}{$filename}"); if (is_string($status)) { $template->assign_block_vars('error', array('ERROR' => $status)); $mod_installed = false; } } } } // end foreach // Move included files if (isset($actions['NEW_FILES']) && !empty($actions['NEW_FILES'])) { $template->assign_var('S_NEW_FILES', true); // Because foreach operates on a copy of the specified array and not the array itself, // we cannot rely on the array pointer while using it, so we use a while loop w/ each() // We need array pointer to rewind the loop when is_array($target) (See Ticket #62341) while (list($source, $target) = each($actions['NEW_FILES'])) { if (is_array($target)) { // If we've shifted off all targets, we're done w/ that element if (empty($target)) { continue; } // Shift off first target, then rewind array pointer to get next target $target = array_shift($actions['NEW_FILES'][$source]); prev($actions['NEW_FILES']); } if ($change && ($mod_installed || $force_install)) { $status = $editor->copy_content($this->mod_root . str_replace('*.*', '', $source), str_replace('*.*', '', $target)); if ($status !== true && !is_null($status)) { $mod_installed = false; } $template->assign_block_vars('new_files', array('S_SUCCESS' => $status === true ? true : false, 'S_NO_COPY_ATTEMPT' => is_null($status) ? true : false, 'SOURCE' => $source, 'TARGET' => $target)); } else { if ($display && !$change) { $template->assign_block_vars('new_files', array('SOURCE' => $source, 'TARGET' => $target)); } else { if ($change && $display && !$mod_installed && !$force_install) { $template->assign_block_vars('new_files', array('S_NO_COPY_ATTEMPT' => true, 'FILENAME' => $target)); } } } } } // Delete (or reverse-delete) installed files if (!empty($actions['DELETE_FILES'])) { $template->assign_var('S_REMOVING_FILES', true); // Dealing with a reverse-delete, must heed to the dangers ahead! if ($reverse) { $directories = array(); $directories['src'] = array(); $directories['dst'] = array(); $directories['del'] = array(); // Because foreach operates on a copy of the specified array and not the array itself, // we cannot rely on the array pointer while using it, so we use a while loop w/ each() // We need array pointer to rewind the loop when is_array($target) (See Ticket #62341) while (list($source, $target) = each($actions['DELETE_FILES'])) { if (is_array($target)) { // If we've shifted off all targets, we're done w/ that element if (empty($target)) { continue; } // Shift off first target, then rewind array pointer to get next target $target = array_shift($actions['DELETE_FILES'][$source]); prev($actions['DELETE_FILES']); } // Some MODs include 'umil/', avoid deleting! if (strpos($target, 'umil/') === 0) { unset($actions['DELETE_FILES'][$source]); continue; } else { if (strpos($source, '*.*') !== false) { // This could be phpbb_root_path, if "Copy: root/*.* to: *.*" syntax was used // or root/custom_dir if "Copy: root/custom/*.* to: custom/*.*", etc. $source = $this->mod_root . str_replace('*.*', '', $source); $target = str_replace('*.*', '', $target); // Get all of the files in the source directory $files = find_files($source, '.*'); // And translate into destination files $files = str_replace($source, $target, $files); // Get all of the sub-directories in the source directory $directories['src'] = find_files($source, '.*', 20, true); // And translate it into destination sub-directories $directories['dst'] = str_replace($source, $target, $directories['src']); // Compare source and destination subdirs, if any, in _reverse_ order! (array_pop) for ($i = 0, $cnt = count($directories['dst']); $i < $cnt; $i++) { $dir_source = array_pop($directories['src']); $dir_target = array_pop($directories['dst']); // Some MODs include 'umil/', avoid deleting! if (strpos($dir_target, 'umil/') === 0) { continue; } $src_file_cnt = directory_num_files($dir_source, false, true); $dst_file_cnt = directory_num_files($phpbb_root_path . $dir_target, false, true); $src_dir_cnt = directory_num_files($dir_source, true, true); $dst_dir_cnt = directory_num_files($phpbb_root_path . $dir_target, true, true); // Do we have a match in recursive file count and match in recursive subdir count? // This could be vastly improved.. if ($src_file_cnt == $dst_file_cnt && $src_dir_cnt == $dst_dir_cnt) { $directories['del'][] = $dir_target; } unset($dir_source, $dir_target, $src_file_cnt, $dst_file_cnt, $src_dir_cnt, $dst_dir_cnt); //cleanup } foreach ($files as $file) { // Some MODs include 'umil/', avoid deleting! if (strpos($file, 'umil/') === 0) { continue; } else { if (!file_exists($phpbb_root_path . $file) && ($change || $display)) { $template->assign_block_vars('removing_files', array('S_MISSING_FILE' => true, 'S_NO_DELETE_ATTEMPT' => true, 'FILENAME' => $file)); } else { if ($change && ($mod_installed || $force_install)) { $status = $editor->remove($file); $template->assign_block_vars('removing_files', array('S_SUCCESS' => $status === true ? true : false, 'S_NO_DELETE_ATTEMPT' => is_null($status) ? true : false, 'FILENAME' => $file)); } else { if ($display && !$change) { $template->assign_block_vars('removing_files', array('FILENAME' => $file)); } else { if ($change && $display && !$mod_installed && !$force_install) { $template->assign_block_vars('removing_files', array('S_NO_DELETE_ATTEMPT' => true, 'FILENAME' => $file)); } } } } } } unset($files); //cleanup } else { if (!file_exists($phpbb_root_path . $target) && ($change || $display)) { $template->assign_block_vars('removing_files', array('S_MISSING_FILE' => true, 'S_NO_DELETE_ATTEMPT' => true, 'FILENAME' => $target)); } else { if ($change && ($mod_installed || $force_install)) { $status = $editor->remove($target); $template->assign_block_vars('removing_files', array('S_SUCCESS' => $status === true ? true : false, 'S_NO_DELETE_ATTEMPT' => is_null($status) ? true : false, 'FILENAME' => $target)); } else { if ($display && !$change) { $template->assign_block_vars('removing_files', array('FILENAME' => $target)); } else { if ($change && $display && !$mod_installed && !$force_install) { $template->assign_block_vars('removing_files', array('S_NO_DELETE_ATTEMPT' => true, 'FILENAME' => $target)); } } } } } } } // Delete wildcard directories, if any, which should now be empty anyway (no recursive delete needed) if ($cnt = count($directories['del'])) { for ($i = 0; $i < $cnt; $i++) { if ($change && ($mod_installed || $force_install)) { $status = $editor->remove($directories['del'][$i]); $template->assign_block_vars('removing_files', array('S_SUCCESS' => $status === true ? true : false, 'S_NO_DELETE_ATTEMPT' => is_null($status) ? true : false, 'FILENAME' => $directories['del'][$i])); } else { if ($display && !$change) { $template->assign_block_vars('removing_files', array('FILENAME' => $directories['del'][$i])); } else { if ($change && $display && !$mod_installed && !$force_install) { $template->assign_block_vars('removing_files', array('S_NO_DELETE_ATTEMPT' => true, 'FILENAME' => $directories['del'][$i])); } } } } unset($directories['del']); //cleanup } } else { if ($mod_installed || $force_install) { foreach ($actions['DELETE_FILES'] as $file) { $wildcards = strpos($file, '*.*'); $file = str_replace('*.*', '', $file); if (!file_exists($phpbb_root_path . $file) && ($change || $display)) { $template->assign_block_vars('removing_files', array('S_MISSING_FILE' => true, 'S_NO_DELETE_ATTEMPT' => true, 'FILENAME' => $file)); } else { if ($wildcards || is_file($phpbb_root_path . $file)) { if ($change) { // Delete, recursively if needed $status = $editor->remove($file, true); $template->assign_block_vars('removing_files', array('S_SUCCESS' => $status === true ? true : false, 'S_NO_DELETE_ATTEMPT' => is_null($status) ? true : false, 'FILENAME' => $file)); } else { if ($display) { $template->assign_block_vars('removing_files', array('FILENAME' => $file)); } } } } } } } } // Perform SQL queries last -- Queries usually cannot be done a second // time, so do them only if the edits were successful. Still complies // with the MODX spec in this location if (!empty($actions['SQL']) && ($mod_installed || $force_install || $display && !$change)) { $template->assign_var('S_SQL', true); parser::parse_sql($actions['SQL']); $db->sql_return_on_error(true); foreach ($actions['SQL'] as $query) { if ($change) { $query_success = $db->sql_query($query); if ($query_success) { $template->assign_block_vars('sql_queries', array('S_SUCCESS' => true, 'QUERY' => $query)); } else { $error = $db->sql_error(); $template->assign_block_vars('sql_queries', array('S_SUCCESS' => false, 'QUERY' => $query, 'ERROR_MSG' => $error['message'], 'ERROR_CODE' => $error['code'])); $mod_installed = false; } } else { if ($display) { $template->assign_block_vars('sql_queries', array('QUERY' => $query)); } } } $db->sql_return_on_error(false); } else { $template->assign_var('S_SQL', false); } return $mod_installed; }
<?php /** * @package FacePress * @version $Id$ * @copyright (c) 2010 JiffSoft * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3 */ $sub_action = strtolower(strlen($_POST['sub']) > 0 ? $_POST['sub'] : 'list'); if (strlen($_POST['tid']) > 0) { // Gather the post ID we are talking about $post = FPBDatabase::Instance()->GatherPostById($_POST['tid']); } echo '<h3>Plugin Management</h3>'; // Load plugin list $yaml_files = find_files(BASEDIR . '/fpb-content/plugins', '/ya?ml$/i'); $plugins = array(); foreach ($yaml_files as $yaml) { array_push($plugins, Spyc::YAMLLoad($yaml)); } switch ($sub_action) { case 'activate': break; case 'deactivate': /** * @todo Deactivation should look for if the plugin is core (MissionCritical: true) in the YML, or * if it is required (RequiresPlugins:) from another plugin */ break; case 'list': default:
} $is_verbose = false; foreach ($argv as $arg) { $is_verbose = $is_verbose || $arg == '--verbose' || $arg == '-v'; } function verbose($str) { global $is_verbose; if ($is_verbose) { echo $str; } } $passes = 0; $failures = 0; $runs = 0; foreach (find_files(realpath(dirname(__FILE__) . '/..'), '/test\\.php$/') as $filename) { chdir(dirname($filename)); $path = realpath(dirname(__FILE__) . '/../lib') . PATH_SEPARATOR . ini_get("include_path"); $xml = shell_exec('php -d include_path=' . escapeshellarg($path) . ' ' . escapeshellarg(basename($filename)) . ' -x'); verbose("-------------------------------------------\n"); verbose("Running suite: " . $filename . "\n"); $doc = new DomDocument(); if (@$doc->loadXml($xml)) { $q = new DomXpath($doc); $passes += $q->query('//pass')->length; $failures += $q->query('//fail')->length; foreach ($q->query('//fail') as $fail) { verbose($fail->nodeValue . "\n"); } verbose($q->query('//pass')->length . " passes, "); verbose($q->query('//fail')->length . " failues" . "\n");
if ($sNibLocation === null) { $sNibLocation = ResourceFinder::findResource(array(DIRNAME_LIB, DIRNAME_VENDOR, 'nib')); } foreach (ResourceFinder::create()->addPath(DIRNAME_LIB, 'stylus_includes')->searchSiteFirst()->noCache()->all()->find() as $sIncludeDir) { array_unshift($aStylFiles, '-I', $sIncludeDir); } array_unshift($aStylFiles, '-u', $sNibLocation); if (!$aOptions['u']) { array_unshift($aStylFiles, '-c'); } if ($aOptions['d']) { array_unshift($aStylFiles, '-f', '-l'); } call_parser('stylus', $aStylFiles); } $aCoffeeFiles = find_files('coffee'); if (count($aCoffeeFiles) > 0) { array_unshift($aCoffeeFiles, '-c'); if ($aOptions['d']) { array_unshift($aCoffeeFiles, '-l'); } call_parser('coffee', $aCoffeeFiles); } if ($aOptions['w']) { if (function_exists('pcntl_signal')) { pcntl_signal(SIGTERM, 'trap'); pcntl_signal(SIGINT, 'trap'); } while (true) { sleep(100); }
* filename. * * That is, if we have three files: * test.scss * test.sass * test.css * * The tester will compile test.scss and test.sass seperately * and compare their outputs both to each other and to test.css * * Testing is eased by stripping out all whitespace, which may * introduce bugs of their own. */ include 'SassParser.php'; $test_dir = './tests'; $files = find_files($test_dir); $i = 0; foreach ($files['by_name'] as $name => $test) { if (isset($_GET['name']) && $name != $_GET['name']) { continue; } if (isset($_GET['skip']) && $name && preg_match('/(^|,)(' . preg_quote($name) . ')(,|$)/', $_GET['skip'])) { continue; } if (count($test) > 1) { $result = test_files($test, $test_dir); if ($result === TRUE) { print "\n\t<p class='pass'><em>PASS</em> {$name}</p>"; } else { print "\n\t<p class='fail'><em>FAIL</em> {$name}</p>"; print "<pre>{$result}</pre>";
/** * Find HTML files in the given path * * @param $paths * @param bool $includeSubDirectories * * @return array */ function find_html_files($paths, $includeSubDirectories = false) { return find_files($paths, 0, '*.html', $includeSubDirectories); }
function run_test($php, $file, $env) { global $log_format, $ini_overwrites, $cwd, $PHP_FAILED_TESTS; global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; global $SHOW_ONLY_GROUPS; global $no_file_cache; $temp_filenames = null; $org_file = $file; if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) { $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE']; } if (isset($env['TEST_PHPDBG_EXECUTABLE'])) { $phpdbg = $env['TEST_PHPDBG_EXECUTABLE']; } if (is_array($file)) { $file = $file[0]; } if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => ''); $fp = fopen($file, "rb") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); if ($line === false) { $bork_info = "cannot read test"; $borked = true; } } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!$borked && strncmp('--TEST--', $line, 8)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; $secfile = false; $secdone = false; while (!feof($fp)) { $line = fgets($fp); if ($line === false) { break; } // Match the beginning of a section. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { $section = $r[1]; settype($section, 'string'); if (isset($section_text[$section])) { $bork_info = "duplicated {$section} section"; $borked = true; } $section_text[$section] = ''; $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL'; $secdone = false; continue; } // Add to the section text. if (!$secdone) { $section_text[$section] .= $line; } // End of actual test? if ($secfile && preg_match('/^===DONE===\\s*$/', $line)) { $secdone = true; } } // the redirect section allows a set of tests to be reused outside of // a given test dir if (!$borked) { if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { $bork_info = "missing section --FILE--"; $borked = true; } if (@count($section_text['FILEEOF']) == 1) { $section_text['FILE'] = preg_replace("/[\r\n]+\$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } foreach (array('FILE', 'EXPECT', 'EXPECTF', 'EXPECTREGEX') as $prefix) { $key = $prefix . '_EXTERNAL'; if (@count($section_text[$key]) == 1) { // don't allow tests to retrieve files from anywhere but this subdirectory $section_text[$key] = dirname($file) . '/' . trim(str_replace('..', '', $section_text[$key])); if (file_exists($section_text[$key])) { $section_text[$prefix] = file_get_contents($section_text[$key], FILE_BINARY); unset($section_text[$key]); } else { $bork_info = "could not load --" . $key . "-- " . dirname($file) . '/' . trim($section_text[$key]); $borked = true; } } } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; } } } fclose($fp); $shortname = str_replace($cwd . '/', '', $file); $tested_file = $shortname; if ($borked) { show_result("BORK", $bork_info, $tested_file); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); junit_mark_test_as('BORK', $shortname, $tested_file, 0, $bork_info); return 'BORKED'; } if (isset($section_text['CAPTURE_STDIO'])) { $captureStdIn = stripos($section_text['CAPTURE_STDIO'], 'STDIN') !== false; $captureStdOut = stripos($section_text['CAPTURE_STDIO'], 'STDOUT') !== false; $captureStdErr = stripos($section_text['CAPTURE_STDIO'], 'STDERR') !== false; } else { $captureStdIn = true; $captureStdOut = true; $captureStdErr = true; } if ($captureStdOut && $captureStdErr) { $cmdRedirect = ' 2>&1'; } else { $cmdRedirect = ''; } $tested = trim($section_text['TEST']); /* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['GZIP_POST']) || !empty($section_text['DEFLATE_POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['PUT']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { if (isset($php_cgi)) { $old_php = $php; $php = $php_cgi . ' -C '; } else { if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; } else { if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath(dirname($php) . "/../../sapi/cgi/php-cgi") . ' -C '; } else { if (file_exists("./sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { if (file_exists(dirname($php) . "/php-cgi")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); junit_init_suite(junit_get_suitename_for($shortname)); junit_mark_test_as('SKIP', $shortname, $tested, 0, 'CGI not available'); return 'SKIPPED'; } } } } } $uses_cgi = true; } /* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */ if (array_key_exists('PHPDBG', $section_text)) { if (!isset($section_text['STDIN'])) { $section_text['STDIN'] = $section_text['PHPDBG'] . "\n"; } if (isset($phpdbg)) { $old_php = $php; $php = $phpdbg . ' -qIb'; } else { show_result('SKIP', $tested, $tested_file, "reason: phpdbg not available"); junit_init_suite(junit_get_suitename_for($shortname)); junit_mark_test_as('SKIP', $shortname, $tested, 0, 'phpdbg not available'); return 'SKIPPED'; } } if (!$SHOW_ONLY_GROUPS) { show_test($test_idx, $shortname); } if (is_array($IN_REDIRECT)) { $temp_dir = $test_dir = $IN_REDIRECT['dir']; } else { $temp_dir = $test_dir = realpath(dirname($file)); } if ($temp_source && $temp_target) { $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); } $main_file_name = basename($file, 'phpt'); $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; $sh_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'sh'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_relative_file = str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $test_file) . 't'; if ($temp_source && $temp_target) { $temp_skipif .= 's'; $temp_file .= 's'; $temp_clean .= 's'; $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file) . '.phps'; if (!is_dir(dirname($copy_file))) { mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); } if (isset($section_text['FILE'])) { save_text($copy_file, $section_text['FILE']); } $temp_filenames = array('file' => $copy_file, 'diff' => $diff_filename, 'log' => $log_filename, 'exp' => $exp_filename, 'out' => $output_filename, 'mem' => $memcheck_filename, 'sh' => $sh_filename, 'php' => $temp_file, 'skip' => $temp_skipif, 'clean' => $temp_clean); } if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']); $tested_file = $tmp_relative_file; } // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); @unlink($memcheck_filename); @unlink($sh_filename); @unlink($temp_file); @unlink($test_file); @unlink($temp_skipif); @unlink($test_skipif); @unlink($tmp_post); @unlink($temp_clean); @unlink($test_clean); // Reset environment from any previous test. $env['REDIRECT_STATUS'] = ''; $env['QUERY_STRING'] = ''; $env['PATH_TRANSLATED'] = ''; $env['SCRIPT_FILENAME'] = ''; $env['REQUEST_METHOD'] = ''; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $env['TZ'] = ''; if (!empty($section_text['ENV'])) { foreach (explode("\n", trim($section_text['ENV'])) as $e) { $e = explode('=', trim($e), 2); if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // Additional required extensions if (array_key_exists('EXTENSIONS', $section_text)) { $ext_dir = `{$php} -r 'echo ini_get("extension_dir");'`; $extensions = preg_split("/[\n\r]+/", trim($section_text['EXTENSIONS'])); $loaded = explode(",", `{$php} -n -r 'echo implode(",", get_loaded_extensions());'`); foreach ($extensions as $req_ext) { if (!in_array($req_ext, $loaded)) { if ($req_ext == 'opcache') { $ini_settings['zend_extension'][] = $ext_dir . DIRECTORY_SEPARATOR . $req_ext . '.' . PHP_SHLIB_SUFFIX; } else { $ini_settings['extension'][] = $ext_dir . DIRECTORY_SEPARATOR . $req_ext . '.' . PHP_SHLIB_SUFFIX; } } } } // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; $env['ZEND_DONT_UNLOAD_MODULES'] = 1; } else { $env['USE_ZEND_ALLOC'] = '1'; $env['ZEND_DONT_UNLOAD_MODULES'] = 0; } junit_start_timer($shortname); $output = system_with_timeout("{$extra} {$php} {$pass_options} -q {$ini_settings} {$no_file_cache} -d display_errors=0 \"{$test_skipif}\"", $env); junit_finish_timer($shortname); if (!$cfg['keep']['skip']) { @unlink($test_skipif); } if (!strncasecmp('skip', ltrim($output), 4)) { if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $output, $m)) { show_result('SKIP', $tested, $tested_file, "reason: {$m['1']}", $temp_filenames); } else { show_result('SKIP', $tested, $tested_file, '', $temp_filenames); } if (!$cfg['keep']['skip']) { @unlink($test_skipif); } $message = !empty($m[1]) ? $m[1] : ''; junit_mark_test_as('SKIP', $shortname, $tested, null, $message); return 'SKIPPED'; } if (!strncasecmp('info', ltrim($output), 4)) { if (preg_match('/^\\s*info\\s*(.+)\\s*/i', $output, $m)) { $info = " (info: {$m['1']})"; } } if (!strncasecmp('warn', ltrim($output), 4)) { if (preg_match('/^\\s*warn\\s*(.+)\\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ $info = " (warn: {$m['1']})"; } } } } if (!extension_loaded("zlib") && (array_key_exists("GZIP_POST", $section_text) || array_key_exists("DEFLATE_POST", $section_text))) { $message = "ext/zlib required"; show_result('SKIP', $tested, $tested_file, "reason: {$message}", $temp_filenames); junit_mark_test_as('SKIP', $shortname, $tested, null, $message); return 'SKIPPED'; } if (@count($section_text['REDIRECTTEST']) == 1) { $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); if (!empty($IN_REDIRECT['TESTS'])) { if (is_array($org_file)) { $test_files[] = $org_file[1]; } else { $GLOBALS['test_files'] = $test_files; find_files($IN_REDIRECT['TESTS']); foreach ($GLOBALS['test_files'] as $f) { $test_files[] = array($f, $file); } } $test_cnt += @count($test_files) - 1; $test_idx--; show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); // set up environment $redirenv = array_merge($environment, $IN_REDIRECT['ENV']); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR; usort($test_files, "test_sort"); run_all_tests($test_files, $redirenv, $tested); show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); // a redirected test never fails $IN_REDIRECT = false; junit_mark_test_as('PASS', $shortname, $tested); return 'REDIR'; } else { $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); } } if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { if (is_array($org_file)) { $file = $org_file[0]; } $bork_info = "Redirected test did not contain redirection info"; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); junit_mark_test_as('BORK', $shortname, $tested, null, $bork_info); return 'BORKED'; } // We've satisfied the preconditions - run the test! if (isset($section_text['FILE'])) { show_file_block('php', $section_text['FILE'], 'TEST'); save_text($test_file, $section_text['FILE'], $temp_file); } else { $test_file = $temp_file = ""; } if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['REDIRECT_STATUS'] = '1'; if (empty($env['QUERY_STRING'])) { $env['QUERY_STRING'] = $query_string; } if (empty($env['PATH_TRANSLATED'])) { $env['PATH_TRANSLATED'] = $test_file; } if (empty($env['SCRIPT_FILENAME'])) { $env['SCRIPT_FILENAME'] = $test_file; } if (array_key_exists('COOKIE', $section_text)) { $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); } else { $env['HTTP_COOKIE'] = ''; } $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request'); return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } elseif (array_key_exists('PUT', $section_text) && !empty($section_text['PUT'])) { $post = trim($section_text['PUT']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'PUT'; if (empty($request)) { junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request'); return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); $content_length = strlen($post); save_text($tmp_post, $post); $env['REQUEST_METHOD'] = 'POST'; if (empty($env['CONTENT_TYPE'])) { $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; } if (empty($env['CONTENT_LENGTH'])) { $env['CONTENT_LENGTH'] = $content_length; } $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text['GZIP_POST'])) { $post = trim($section_text['GZIP_POST']); $post = gzencode($post, 9, FORCE_GZIP); $env['HTTP_CONTENT_ENCODING'] = 'gzip'; save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text['DEFLATE_POST'])) { $post = trim($section_text['DEFLATE_POST']); $post = gzcompress($post, 9); $env['HTTP_CONTENT_ENCODING'] = 'deflate'; save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" {$args}{$cmdRedirect}"; } } } } if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; $env['ZEND_DONT_UNLOAD_MODULES'] = 1; /* --vex-iropt-register-updates=allregs-at-mem-access is necessary for phpdbg watchpoint tests */ if (version_compare($valgrind_version, '3.8.0', '>=')) { /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --vex-iropt-register-updates=allregs-at-mem-access --log-file={$memcheck_filename} {$cmd}"; } elseif (version_compare($valgrind_version, '3.3.0', '>=')) { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --vex-iropt-precise-memory-exns=yes --log-file={$memcheck_filename} {$cmd}"; } else { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --vex-iropt-precise-memory-exns=yes --log-file-exactly={$memcheck_filename} {$cmd}"; } } else { $env['USE_ZEND_ALLOC'] = '1'; $env['ZEND_DONT_UNLOAD_MODULES'] = 0; } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] . "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "\nQUERY_STRING = " . $env['QUERY_STRING'] . "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] . "\nSCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "\nHTTP_COOKIE = " . $env['HTTP_COOKIE'] . "\nCOMMAND {$cmd}\n"; } junit_start_timer($shortname); $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null, $captureStdIn, $captureStdOut, $captureStdErr); junit_finish_timer($shortname); if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { if (trim($section_text['CLEAN'])) { show_file_block('clean', $section_text['CLEAN']); save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { $clean_params = array(); settings2array($ini_overwrites, $clean_params); settings2params($clean_params); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; system_with_timeout("{$extra} {$php} {$pass_options} -q {$clean_params} {$no_file_cache} \"{$test_clean}\"", $env); } if (!$cfg['keep']['clean']) { @unlink($test_clean); } } } @unlink($tmp_post); $leaked = false; $passed = false; if ($leak_check) { // leak check $leaked = filesize($memcheck_filename) > 0; if (!$leaked) { @unlink($memcheck_filename); } } // Does the output match what is expected? $output = preg_replace("/\r\n/", "\n", trim($out)); /* when using CGI, strip the headers from the output */ $headers = array(); if (!empty($uses_cgi) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { $output = trim($match[2]); $rh = preg_split("/[\n\r]+/", $match[1]); foreach ($rh as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $headers[trim($line[0])] = trim($line[1]); } } } $failed_headers = false; if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); $lines = preg_split("/[\n\r]+/", $section_text['EXPECTHEADERS']); foreach ($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $want[trim($line[0])] = trim($line[1]); $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } $output_headers = array(); foreach ($want as $k => $v) { if (isset($headers[$k])) { $output_headers[] = $k . ': ' . $headers[$k]; } if (!isset($headers[$k]) || $headers[$k] != $v) { $failed_headers = true; } } ksort($wanted_headers); $wanted_headers = implode("\n", $wanted_headers); ksort($output_headers); $output_headers = implode("\n", $output_headers); } show_file_block('out', $output); if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } show_file_block('exp', $wanted); $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { // do preg_quote, but miss out any %r delimited sections $temp = ""; $r = "%r"; $startOffset = 0; $length = strlen($wanted_re); while ($startOffset < $length) { $start = strpos($wanted_re, $r, $startOffset); if ($start !== false) { // we have found a start tag $end = strpos($wanted_re, $r, $start + 2); if ($end === false) { // unbalanced tag, ignore it. $end = $start = $length; } } else { // no more %r sections $start = $end = $length; } // quote a non re portion of the string $temp = $temp . preg_quote(substr($wanted_re, $startOffset, $start - $startOffset), '/'); // add the re unquoted. if ($end > $start) { $temp = $temp . '(' . substr($wanted_re, $start + 2, $end - $start - 2) . ')'; } $startOffset = $end + 2; } $wanted_re = $temp; $wanted_re = str_replace(array('%binary_string_optional%'), 'string', $wanted_re); $wanted_re = str_replace(array('%unicode_string_optional%'), 'string', $wanted_re); $wanted_re = str_replace(array('%unicode\\|string%', '%string\\|unicode%'), 'string', $wanted_re); $wanted_re = str_replace(array('%u\\|b%', '%b\\|u%'), '', $wanted_re); // Stick to basics $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace('%s', '[^\\r\\n]+', $wanted_re); $wanted_re = str_replace('%S', '[^\\r\\n]*', $wanted_re); $wanted_re = str_replace('%a', '.+', $wanted_re); $wanted_re = str_replace('%A', '.*', $wanted_re); $wanted_re = str_replace('%w', '\\s*', $wanted_re); $wanted_re = str_replace('%i', '[+-]?\\d+', $wanted_re); $wanted_re = str_replace('%d', '\\d+', $wanted_re); $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re); $wanted_re = str_replace('%f', '[+-]?\\.?\\d+\\.?\\d*(?:[Ee][+-]?\\d+)?', $wanted_re); $wanted_re = str_replace('%c', '.', $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (!$leaked && !$failed_headers) { if (isset($section_text['XFAIL'])) { $warn = true; $info = " (warn: XFAIL section but test passes)"; } else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); junit_mark_test_as('PASS', $shortname, $tested); return 'PASSED'; } } } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); show_file_block('exp', $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (!$leaked && !$failed_headers) { if (isset($section_text['XFAIL'])) { $warn = true; $info = " (warn: XFAIL section but test passes)"; } else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); junit_mark_test_as('PASS', $shortname, $tested); return 'PASSED'; } } } $wanted_re = null; } // Test failed so we need to report details. if ($failed_headers) { $passed = false; $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; $output = $output_headers . "\n--HEADERS--\n" . $output; if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } } if ($leaked) { $restype[] = 'LEAK'; } if ($warn) { $restype[] = 'WARN'; } if (!$passed) { if (isset($section_text['XFAIL'])) { $restype[] = 'XFAIL'; $info = ' XFAIL REASON: ' . rtrim($section_text['XFAIL']); } else { $restype[] = 'FAIL'; } } if (!$passed) { // write .exp if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, $wanted, FILE_BINARY) === false) { error("Cannot create expected test output - {$exp_filename}"); } // write .out if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, $output, FILE_BINARY) === false) { error("Cannot create test output - {$output_filename}"); } // write .diff $diff = generate_diff($wanted, $wanted_re, $output); if (is_array($IN_REDIRECT)) { $diff = "# original source file: {$shortname}\n" . $diff; } show_file_block('diff', $diff); if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, $diff, FILE_BINARY) === false) { error("Cannot create test diff - {$diff_filename}"); } // write .sh if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, "#!/bin/sh\n\n{$cmd}\n", FILE_BINARY) === false) { error("Cannot create test shell script - {$sh_filename}"); } chmod($sh_filename, 0755); // write .log if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n", FILE_BINARY) === false) { error("Cannot create test log - {$log_filename}"); error_report($file, $log_filename, $tested); } } show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames); foreach ($restype as $type) { $PHP_FAILED_TESTS[$type . 'ED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [{$tested_file}]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); } $diff = empty($diff) ? '' : preg_replace('/\\e/', '<esc>', $diff); junit_mark_test_as($restype, str_replace($cwd . '/', '', $tested_file), $tested, null, $info, $diff); return $restype[0] . 'ED'; }
function validate_addons() { $addons = array(); $gateway_path = $this->basepath . DIRECTORY_SEPARATOR . "gateways"; find_files(".php", $gateway_path, $gateway_path, $gateways); foreach ($gateways as $file) { if (in_array(basename($file), $this->coremods)) { continue; } $addons[] = md5_file($gateway_path . $file); } $shipping_path = $this->basepath . DIRECTORY_SEPARATOR . "shipping"; find_files(".php", $shipping_path, $shipping_path, $shipmods); foreach ($shipmods as $file) { if (in_array(basename($file), $this->coremods)) { continue; } $addons[] = md5_file($shipping_path . $file); } return $addons; }
/** * Recursively searches directories and one-level deep of * sub-directories for files with a specific extension * NOTE: Files are saved to the $found parameter, * an array passed by reference, not a returned value */ function find_files($extension, $directory, $root, &$found) { if (is_dir($directory)) { $Directory = @dir($directory); if ($Directory) { while (($file = $Directory->read()) !== false) { if (substr($file, 0, 1) == "." || substr($file, 0, 1) == "_") { continue; } // Ignore .dot files and _directories if (is_dir($directory . DIRECTORY_SEPARATOR . $file) && $directory == $root) { // Scan one deep more than root find_files($extension, $directory . DIRECTORY_SEPARATOR . $file, $root, $found); } // but avoid recursive scans if (substr($file, strlen($extension) * -1) == $extension) { $found[] = substr($directory, strlen($root)) . DIRECTORY_SEPARATOR . $file; } // Add the file to the found list } return true; } } return false; }
function run_test($php, $file, $test_cnt, $test_idx) { global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS, $pass_options, $DETAILED, $IN_REDIRECT; if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => '', 'SKIPIF' => '', 'GET' => '', 'ARGS' => ''); $fp = @fopen($file, "r") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!ereg('^--TEST--', $line, $r)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; while (!feof($fp)) { $line = fgets($fp); // Match the beginning of a section. if (ereg('^--([A-Z]+)--', $line, $r)) { $section = $r[1]; $section_text[$section] = ''; continue; } // Add to the section text. $section_text[$section] .= $line; } // the redirect section allows a set of tests to be reused outside of // a given test dir if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (@count($section_text['FILE']) != 1) { $bork_info = "missing section --FILE-- [{$file}]"; $borked = true; } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX-- [{$file}]"; $borked = true; print_r($section_text); } } fclose($fp); if ($borked) { echo "BORK {$bork_info} [{$file}]\n"; $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => $bork_info); return 'BORKED'; } /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST'])) { if (file_exists("./sapi/cgi/php")) { $old_php = $php; $php = realpath("./sapi/cgi/php") . ' -C '; } } $shortname = str_replace($cwd . '/', '', $file); $tested = trim($section_text['TEST']) . " [{$shortname}]"; echo "TEST {$test_idx}/{$test_cnt} [{$shortname}]\r"; flush(); if (is_array($IN_REDIRECT)) { $tmp = $IN_REDIRECT['dir']; } else { $tmp = realpath(dirname($file)); } $diff_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.diff', basename($file)); $log_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.log', basename($file)); $exp_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.exp', basename($file)); $output_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.out', basename($file)); $tmp_skipif = $tmp . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_file = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.php', basename($file)); $tmp_post = $tmp . DIRECTORY_SEPARATOR . uniqid('/phpt.'); if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']) . " [{$tmp_file}]"; $section_text['FILE'] = "# original source file: {$shortname}\n" . $section_text['FILE']; } @unlink($tmp_skipif); @unlink($tmp_file); @unlink($tmp_post); // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); // Reset environment from any previous test. putenv("REDIRECT_STATUS="); putenv("QUERY_STRING="); putenv("PATH_TRANSLATED="); putenv("SCRIPT_FILENAME="); putenv("REQUEST_METHOD="); putenv("CONTENT_TYPE="); putenv("CONTENT_LENGTH="); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { $skipif_params = array(); settings2array($ini_overwrites, $skipif_params); settings2params($skipif_params); save_text($tmp_skipif, $section_text['SKIPIF']); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; $output = system_with_timeout("{$extra} {$php} -q {$skipif_params} {$tmp_skipif}"); @unlink($tmp_skipif); if (eregi("^skip", trim($output))) { echo "SKIP {$tested}"; $reason = eregi("^skip[[:space:]]*(.+)\$", trim($output)) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { echo " (reason: {$reason})\n"; } else { echo "\n"; } if (isset($old_php)) { $php = $old_php; } return 'SKIPPED'; } if (eregi("^info", trim($output))) { $reason = ereg("^info[[:space:]]*(.+)\$", trim($output)) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { $info = " (info: {$reason})"; } } if (eregi("^warn", trim($output))) { $reason = ereg("^warn[[:space:]]*(.+)\$", trim($output)) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { $warn = true; /* only if there is a reason */ $info = " (warn: {$reason})"; } } } } if (@count($section_text['REDIRECTTEST']) == 1) { global $test_files, $test_results, $failed_tests_file; $saved_test_files = $test_files; $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); find_files($IN_REDIRECT['TESTS']); $test_cnt += count($test_files); $GLOBALS['test_cnt'] = $test_cnt; echo "---> {$IN_REDIRECT['TESTS']} ({$tested})\n"; // set up environment foreach ($IN_REDIRECT['ENV'] as $k => $v) { putenv("{$k}={$v}"); } putenv("REDIR_TEST_DIR=" . realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR); usort($test_files, "test_sort"); foreach ($test_files as $name) { $result = run_test($php, $name, $test_cnt, ++$test_idx); $test_results[$tested . ': ' . $name] = $result; if ($failed_tests_file && ($result == 'FAILED' || $result == 'WARNED')) { fwrite($failed_tests_file, "{$tested}: {$name}\n"); } } echo "---> {$IN_REDIRECT['TESTS']} ({$tested}) done\n"; $GLOBALS['test_idx'] = $test_idx; $test_files = $saved_test_files; // clean up environment foreach ($IN_REDIRECT['ENV'] as $k => $v) { putenv("{$k}="); } putenv("REDIR_TEST_DIR="); // a redirected test never fails $IN_REDIRECT = false; return 'PASSED'; } // Default ini settings $ini_settings = array(); // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // We've satisfied the preconditions - run the test! save_text($tmp_file, $section_text['FILE']); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } if (!empty($section_text['ENV'])) { foreach (explode("\n", $section_text['ENV']) as $env) { $env = trim($env) and putenv($env); } } putenv("REDIRECT_STATUS=1"); putenv("QUERY_STRING={$query_string}"); putenv("PATH_TRANSLATED={$tmp_file}"); putenv("SCRIPT_FILENAME={$tmp_file}"); $args = $section_text['ARGS'] ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); save_text($tmp_post, $post); $content_length = strlen($post); putenv("REQUEST_METHOD=POST"); putenv("CONTENT_TYPE=application/x-www-form-urlencoded"); putenv("CONTENT_LENGTH={$content_length}"); $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$tmp_file}\" 2>&1 < {$tmp_post}"; } else { putenv("REQUEST_METHOD=GET"); putenv("CONTENT_TYPE="); putenv("CONTENT_LENGTH="); if (empty($section_text['ENV'])) { $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$tmp_file}\" {$args} 2>&1"; } else { $cmd = "{$php}{$pass_options}{$ini_settings} < \"{$tmp_file}\" {$args} 2>&1"; } } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . getenv("CONTENT_LENGTH") . "\nCONTENT_TYPE = " . getenv("CONTENT_TYPE") . "\nPATH_TRANSLATED = " . getenv("PATH_TRANSLATED") . "\nQUERY_STRING = " . getenv("QUERY_STRING") . "\nREDIRECT_STATUS = " . getenv("REDIRECT_STATUS") . "\nREQUEST_METHOD = " . getenv("REQUEST_METHOD") . "\nSCRIPT_FILENAME = " . getenv("SCRIPT_FILENAME") . "\nCOMMAND {$cmd}\n"; } // $out = `$cmd`; $out = system_with_timeout($cmd); if (!empty($section_text['ENV'])) { foreach (explode("\n", $section_text['ENV']) as $env) { $env = explode('=', $env); putenv($env[0] . '='); } } @unlink($tmp_post); // Does the output match what is expected? $output = trim($out); $output = preg_replace('/\\r\\n/', "\n", $output); /* when using CGI, strip the headers from the output */ if (isset($old_php) && ($pos = strpos($output, "\n\n")) !== FALSE) { $output = substr($output, $pos + 2); } if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); // Stick to basics $wanted_re = str_replace("%e", '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy $wanted_re = str_replace("%i", "[+\\-]?[0-9]+", $wanted_re); $wanted_re = str_replace("%d", "[0-9]+", $wanted_re); $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re); $wanted_re = str_replace("%f", "[+\\-]?\\.?[0-9]+\\.?[0-9]*(E-?[0-9]+)?", $wanted_re); $wanted_re = str_replace("%c", ".", $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { @unlink($tmp_file); echo "PASS {$tested}\n"; if (isset($old_php)) { $php = $old_php; } return 'PASSED'; } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); // compare and leave on success $ok = 0 == strcmp($output, $wanted); if ($ok) { @unlink($tmp_file); echo "PASS {$tested}\n"; if (isset($old_php)) { $php = $old_php; } return 'PASSED'; } $wanted_re = NULL; } // Test failed so we need to report details. if ($warn) { echo "WARN {$tested}{$info}\n"; } else { echo "FAIL {$tested}{$info}\n"; } $PHP_FAILED_TESTS['FAILED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested, 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); // write .exp if (strpos($log_format, 'E') !== FALSE) { $log = fopen($exp_filename, 'w') or error("Cannot create test log - {$exp_filename}"); fwrite($log, $wanted); fclose($log); } // write .out if (strpos($log_format, 'O') !== FALSE) { $log = fopen($output_filename, 'w') or error("Cannot create test log - {$output_filename}"); fwrite($log, $output); fclose($log); } // write .diff if (strpos($log_format, 'D') !== FALSE) { $log = fopen($diff_filename, 'w') or error("Cannot create test log - {$diff_filename}"); fwrite($log, generate_diff($wanted, $wanted_re, $output)); fclose($log); } // write .log if (strpos($log_format, 'L') !== FALSE) { $log = fopen($log_filename, 'w') or error("Cannot create test log - {$log_filename}"); fwrite($log, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n"); fclose($log); error_report($file, $log_filename, $tested); } if (isset($old_php)) { $php = $old_php; } return $warn ? 'WARNED' : 'FAILED'; }
function copy_content($from, $to = '') { global $phpbb_root_path, $user; if (strpos($from, $phpbb_root_path) !== 0) { $from = $phpbb_root_path . $from; } if (strpos($to, $phpbb_root_path) !== 0) { $to = $phpbb_root_path . $to; } // Note: phpBB's compression class does support adding a whole directory at a time. // However, I chose not to use that function because it would not allow AutoMOD's // error handling to work the same as for FTP & Direct methods. $files = array(); if (is_dir($from)) { $files = find_files($from, '.*'); $to_is_dir = true; } else { if (is_file($from)) { $files = array($from); $to_is_dir = false; } } if (empty($files)) { return false; } foreach ($files as $file) { if ($to_is_dir) { $dest = str_replace($from, $to, $file); } else { $dest = $to; } // Replace root path with the "files/" directory that goes in the zip $dest = str_replace($phpbb_root_path, 'files/', $dest); if (!$this->compress->add_custom_file($file, $dest)) { return sprintf($user->lang['WRITE_MANUAL_FAIL'], $dest); } } // return true since we are now taking an action - NULL implies no action return true; }
} $is_verbose = false; foreach ($argv as $arg) { $is_verbose = $is_verbose || $arg == '--verbose' || $arg == '-v'; } function verbose($str) { global $is_verbose; if ($is_verbose) { echo $str; } } $passes = 0; $failures = 0; $runs = 0; foreach (find_files(getcwd(), '/\\.test\\.php$/') as $filename) { chdir(dirname($filename)); $path = realpath(dirname(__FILE__) . '/../lib') . PATH_SEPARATOR . ini_get("include_path"); $xml = shell_exec('php -d include_path=' . escapeshellarg($path) . ' ' . escapeshellarg(basename($filename)) . ' -x'); verbose("-------------------------------------------\n"); verbose("Running suite: " . $filename . "\n"); $doc = new DomDocument(); if (@$doc->loadXml($xml)) { $q = new DomXpath($doc); $passes += $q->query('//pass')->length; $failures += $q->query('//fail')->length; foreach ($q->query('//fail') as $fail) { verbose($fail->nodeValue . "\n"); } verbose($q->query('//pass')->length . " passes, "); verbose($q->query('//fail')->length . " failures" . "\n");