parseFile( $file ); } err( "\n" ); $functions = array(); $all_local_functions = array(); foreach( $parser->parsed_objects as $function ) { $file = str_replace( "$CODE_PATH/", '', $function['file'] ); if( strpos( $file, 'libs/' ) === 0 ) { $functions[$function['name']] = array( 'used' => 0, 'file' => $function['file'] ); } if( !is_array( $all_local_functions[$file] ) ) { $all_local_functions[$file] = array(); } $all_local_functions[$file][] = $function['name']; } $functions['eval'] = array( 'used' => 0, 'file' => 'Evil Eval' ); $php_files = `find {$CODE_PATH}{$SCAN_PATH} -name '*.php'`; $php_files = split( "\n", $php_files ); $counters = array( 'files' => 0, 'errors' => 0, 'warnings' => 0, 'failed' => 0 ); $file_requires = array(); err( "Parsing Files\n" ); $parser->reset( PHPPARSER_FETCH_INCLUDES + PHPPARSER_FETCH_CALLS + PHPPARSER_FETCH_INTERNAL ); $counter = 0; $total = count( $php_files ); $lastpct = 0; foreach( $php_files as $file ) { $counter++; if( $counter == 1 ) { err( 0 ); } else { $pct = intval( $counter / $total * 100 ); if( $pct != $lastpct && $pct % 2 == 0 ) { err( $pct % 10 == 0 ? $pct : '.' ); $lastpct = $pct; } } $file = trim( $file ); if( empty( $file ) ) { continue; } $filename = $file; $file = str_replace( "$CODE_PATH/", '', $file ); $file_requires[$file] = array( 'parsed' => false, 'bad' => 0, 'warning' => 0, 'libs' => array(), 'errors' => array() ); // If the file has bad syntax, don't even bother with it $output = array(); exec( "php -l '$filename'", $output, $result ); if( $result != 0 ) { $counters['failed']++; foreach( $output as $linterror ) { $matches = array(); if( preg_match( '/error:.*?on line (\d+)$/i', $linterror, $matches ) == 0 ) { continue; } $file_requires[$file]['errors'][] = array( 'line' => $matches[1], 'message' => $matches[0] ); } continue; } $file_requires[$file]['parsed'] = true; $local_functions = isset( $all_local_functions[$file] ) ? $all_local_functions[$file] : array(); $includes = array(); $parser->reset(); $parser->parseFile( $filename ); //echo "
", print_r( $parser->parsed_objects ), ''; foreach( $parser->parsed_objects as $object ) { switch( $object['type'] ) { case PHPPARSER_INCLUDE: $includes[] = $object; $current_dir = dirname( $file ); if( $object['name'] == 'global.php' ) { $object['name'] = 'libs/security/lib_security_input.php'; $includes[] = $object; $object['name'] = 'libs/get/lib_get_portal.php'; $includes[] = $object; $object['name'] = 'libs/logging/lib_logging_errors.php'; $includes[] = $object; } $local_functions = array_merge( $local_functions, isset( $all_local_functions[$object['name']] ) ? $all_local_functions[$object['name']] : array() ); break; case PHPPARSER_FUNCTION_CALL: if( !in_array( $object['name'], array_keys( $functions ) ) ) { if( !in_array( $object['name'], $parser->internal_functions ) && !in_array( $object['name'], $local_functions ) ) { $file_requires[$file]['errors'][] = array( 'line' => $object['line'], 'message' => "Undefined function '{$object['name']}'" ); $file_requires[$file]['warnings']++; } continue; } $include = $functions[$object['name']]['file']; $include = str_replace( "$CODE_PATH/", '', $include ); if( $include == $file ) { break; } $functions[$object['name']]['used']++; if( !isset( $file_requires[$file]['libs'][$include] ) ) { $file_requires[$file]['libs'][$include] = array( 'lines' => array(), 'calls' => array() ); } $lib =& $file_requires[$file]['libs'][$include]; $bad = $warning = true; foreach( $includes as $libinc ) { if( $libinc['name'] != $include || !in_array( $libinc['in_function'], array( '', $object['in_function'] ) ) ) { continue; } $inc = $libinc; $bad = false; /* Holy shit, what a fucked up check this used to be... $warning = !$bad && $libinc['depth'] > ( empty( $object['in_function'] ) ? 0 : 1 ) && ( $object['depth'] < $libinc['depth'] || ( $object['depth'] >= $libinc['depth'] && ( $object['block'] - ( $object['depth'] - $libinc['depth'] ) ) != $libinc['block'] ) ); */ $warning = !$bad && !in_array( $libinc['block'], $object['open_blocks'] ); if( !$bad && !$warning ) { break; } } $open_blocks = is_array( $object['open_blocks'] ) ? implode( ',', $object['open_blocks'] ) : ''; $object['bad'] = $bad; $object['warning'] = $warning; $object['info'] = "called[l={$object['line']};b={$object['block']};d={$object['depth']}]" . ( !$bad ? ", required[l={$inc['line']};b={$inc['block']};d={$inc['depth']}] open[{$open_blocks}]" : '' ); $lib['lines'][] = $object['line']; $lib['calls'][] = $object; $file_requires[$file]['bad'] += $bad ? 1 : 0; $file_requires[$file]['warning'] += $warning ? 1 : 0; break; } } $counters['files']++; if( $file_requires[$file]['bad'] > 0 ) { $counters['errors']++; } if( $file_requires[$file]['warning'] > 0 ) { $counters['warnings']++; } if( !$file_requires[$file]['parsed'] ) { $counters['failed']++; } } err( "\n" ); fclose( $stderr ); $files =& $php_files; foreach( $files as $key => $value ) { $files[$key] = str_replace( "$CODE_PATH/", '', $value ); } function ispath( $string ) { return strpos( $string, '/' ) === false ? false: true; } function notpath( $string ) { return strpos( $string, '/' ) === false ? true: false; } sort( $files ); $files1 = array_filter( $files, 'notpath' ); sort( $files1 ); $files2 = array_filter( $files, 'ispath' ); sort( $files2 ); $files = array_merge( $files1, $files2 ); ?>
php -l filename
)