Issues (4122)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

maintenance/findMissingFiles.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 24 and the first side effect is on line 22.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @author Aaron Schulz
20
 */
21
22
require_once __DIR__ . '/Maintenance.php';
23
24
class FindMissingFiles extends Maintenance {
25
	function __construct() {
26
		parent::__construct();
27
28
		$this->addDescription( 'Find registered files with no corresponding file.' );
29
		$this->addOption( 'start', 'Start after this file name', false, true );
30
		$this->addOption( 'mtimeafter', 'Only include files changed since this time', false, true );
31
		$this->addOption( 'mtimebefore', 'Only includes files changed before this time', false, true );
32
		$this->setBatchSize( 300 );
33
	}
34
35
	function execute() {
36
		$lastName = $this->getOption( 'start', '' );
37
38
		$repo = RepoGroup::singleton()->getLocalRepo();
39
		$dbr = $repo->getSlaveDB();
40
		$be = $repo->getBackend();
41
42
		$mtime1 = $dbr->timestampOrNull( $this->getOption( 'mtimeafter', null ) );
43
		$mtime2 = $dbr->timestampOrNull( $this->getOption( 'mtimebefore', null ) );
44
45
		$joinTables = [];
46
		$joinConds = [];
47
		if ( $mtime1 || $mtime2 ) {
48
			$joinTables[] = 'page';
49
			$joinConds['page'] = [ 'INNER JOIN',
50
				[ 'page_title = img_name', 'page_namespace' => NS_FILE ] ];
51
			$joinTables[] = 'logging';
52
			$on = [ 'log_page = page_id', 'log_type' => [ 'upload', 'move', 'delete' ] ];
53
			if ( $mtime1 ) {
54
				$on[] = "log_timestamp > {$dbr->addQuotes($mtime1)}";
55
			}
56
			if ( $mtime2 ) {
57
				$on[] = "log_timestamp < {$dbr->addQuotes($mtime2)}";
58
			}
59
			$joinConds['logging'] = [ 'INNER JOIN', $on ];
60
		}
61
62
		do {
63
			$res = $dbr->select(
64
				array_merge( [ 'image' ], $joinTables ),
65
				[ 'name' => 'img_name' ],
66
				[ "img_name > " . $dbr->addQuotes( $lastName ) ],
67
				__METHOD__,
68
				// DISTINCT causes a pointless filesort
69
				[ 'ORDER BY' => 'name', 'GROUP BY' => 'name',
70
					'LIMIT' => $this->mBatchSize ],
71
				$joinConds
72
			);
73
74
			// Check if any of these files are missing...
75
			$pathsByName = [];
76
			foreach ( $res as $row ) {
77
				$file = $repo->newFile( $row->name );
78
				$pathsByName[$row->name] = $file->getPath();
79
				$lastName = $row->name;
80
			}
81
			$be->preloadFileStat( [ 'srcs' => $pathsByName ] );
82
			foreach ( $pathsByName as $path ) {
83
				if ( $be->fileExists( [ 'src' => $path ] ) === false ) {
84
					$this->output( "$path\n" );
85
				}
86
			}
87
88
			// Find all missing old versions of any of the files in this batch...
89
			if ( count( $pathsByName ) ) {
90
				$ores = $dbr->select( 'oldimage',
91
					[ 'oi_name', 'oi_archive_name' ],
92
					[ 'oi_name' => array_keys( $pathsByName ) ],
93
					__METHOD__
94
				);
95
96
				$checkPaths = [];
97
				foreach ( $ores as $row ) {
98
					if ( !strlen( $row->oi_archive_name ) ) {
99
						continue; // broken row
100
					}
101
					$file = $repo->newFromArchiveName( $row->oi_name, $row->oi_archive_name );
102
					$checkPaths[] = $file->getPath();
103
				}
104
105
				foreach ( array_chunk( $checkPaths, $this->mBatchSize ) as $paths ) {
106
					$be->preloadFileStat( [ 'srcs' => $paths ] );
107
					foreach ( $paths as $path ) {
108
						if ( $be->fileExists( [ 'src' => $path ] ) === false ) {
109
							$this->output( "$path\n" );
110
						}
111
					}
112
				}
113
			}
114
		} while ( $res->numRows() >= $this->mBatchSize );
115
	}
116
}
117
118
$maintClass = 'FindMissingFiles';
119
require_once RUN_MAINTENANCE_IF_MAIN;
120