Issues (843)

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.

scripts/update_db.php (1 issue)

Labels
Severity

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
#!/usr/bin/php
2
<?php
3
/**
4
* This script is used to update databases with external data and archive old data
5
* Should be run as cronjob no more than every 2 weeks if NOTAM is not activated, once a day if NOTAM is activated and every hour if METAR is activated.
6
*/
7
$runningUpdateScript = TRUE;
8
require_once(dirname(__FILE__).'/../require/settings.php');
9
if ($globalInstalled === FALSE) {
10
	echo "Install script MUST be run before this script. Use your web browser to run install/index.php";
11
	die();
12
}
13
// Check if script is not already running... (dirty)
14
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!isset($globalDisableUpdateCheck) || $globalDisableUpdateCheck === FALSE)) {
15
	if(function_exists('exec')) {
16
		exec("ps ux", $output, $result);
17
		$j = 0;
18
		foreach ($output as $line) if(strpos($line, dirname(__FILE__)."/update_db.php") && !strpos($line, "sh ") && !strpos($line, "sudo ")) $j++;
0 ignored issues
show
The expression $output of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
19
		if ($j > 1) {
20
			echo "Script is already runnning...";
21
			die();
22
		}
23
	}
24
}
25
require(dirname(__FILE__).'/../install/class.update_db.php');
26
$update_db = new update_db();
27
28
if ($update_db->check() === false) die();
29
30
if ((!isset($globalMasterServer) || !$globalMasterServer) && (!isset($globalOffline) || $globalOffline === FALSE)) {
31
	if (isset($globalNOTAM) && $globalNOTAM && $update_db->check_last_notam_update()) {
32
		echo "updating NOTAM...";
33
		if (!isset($globalNOTAMSource) || $globalNOTAMSource == '') {
34
			$update_db->update_notam_fam();
35
		} else {
36
			$update_db->update_notam();
37
		}
38
		$update_db->insert_last_notam_update();
39
	} elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) echo "NOTAM are only updated once a day.\n";
40
	if ((!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft)) && ($update_db->check_last_update() && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS))) {
41
		$update_db->update_all();
42
	//	require_once(dirname(__FILE__).'/../require/class.Spotter.php');
43
	//	$Spotter = new Spotter();
44
	//	$Spotter->updateFieldsFromOtherTables();
45
		$update_db->insert_last_update();
46
	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalVA) || !$globalVA) && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n";
47
	if (isset($globalWaypoints) && $globalWaypoints && $update_db->check_last_airspace_update()) {
48
		echo "Check if new airspace version exist...";
49
		echo $update_db->update_airspace_fam();
50
		$update_db->insert_last_airspace_update();
51
	}
52
	if (isset($globalGeoid) && $globalGeoid && $update_db->check_last_geoid_update()) {
53
		echo "Check if new geoid version exist...";
54
		$error = $update_db->update_geoid_fam();
55
		if ($error == '') $update_db->insert_last_geoid_update();
56
		else echo $error;
57
	}
58
	if (isset($globalMarine) && $globalMarine && (!isset($globalVM) || $globalVM === FALSE) && $update_db->check_last_marine_identity_update()) {
59
		echo "Check if new marine identity version exist...";
60
		echo $update_db->update_marine_identity_fam();
61
		$update_db->insert_last_marine_identity_update();
62
	}
63
	if ((!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft)) && ($update_db->check_last_owner_update() && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS))) {
64
		echo "Updating aircraft's owners...\n";
65
		if (isset($globalMasterSource) && $globalMasterSource) {
66
			$update_db->update_owner();
67
		} else {
68
			$update_db->update_owner_fam();
69
			//echo "Delete duplicate owner...";
70
			//$update_db->delete_duplicateowner();
71
			//echo "Done";
72
		}
73
		$update_db->insert_last_owner_update();
74
	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Owner are only updated every 15 days.\n";
75
76
	if ((!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft)) && ($update_db->check_last_airlines_update() && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS))) {
77
		echo "Updating airlines...\n";
78
		echo $update_db->update_airlines_fam();
79
		$update_db->insert_last_airlines_update();
80
	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Airlines are only updated every 15 days.\n";
81
82
	if ((!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft)) && (isset($globalAccidents) && $globalAccidents && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS))) {
83
		require_once(dirname(__FILE__).'/../require/class.Accident.php');
84
		$Accident = new Accident();
85
		echo "Updating accidents...";
86
		if ($Accident->check_last_accidents_update()) {
87
			$Accident->download_update();
88
			$Accident->insert_last_accidents_update();
89
		} else echo "Accidents are updated once a day.\n";
90
	}
91
  
92
}
93
94
if (!isset($globalOffline) || $globalOffline === FALSE) {
95
	if (isset($globalMETAR) && isset($globalMETARcycle) && $globalMETAR && $globalMETARcycle) {
96
		echo "updating METAR...";
97
		require_once(dirname(__FILE__).'/../require/class.METAR.php');
98
		$METAR = new METAR();
99
		if ($METAR->check_last_update()) {
100
			$METAR->addMETARCycle();
101
			$METAR->insert_last_update();
102
		} else echo "METAR are only updated every 30 minutes.\n";
103
	}
104
105
	if ((!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft)) && (isset($globalSchedules) && $globalSchedules && $update_db->check_last_schedules_update() && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS))) {
106
		echo "Updating schedules...";
107
		//$update_db->update_oneworld();
108
		$update_db->update_skyteam();
109
		$update_db->insert_last_schedules_update();
110
	} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalVA) || !$globalVA) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Schedules are only updated every 15 days.\n";
111
}
112
113
if (isset($globalArchiveMonths) && $globalArchiveMonths > 0) {
114
	echo "Updating statistics and archive old data...\n";
115
	require_once(dirname(__FILE__).'/../require/class.Stats.php');
116
	$Stats = new Stats();
117
	echo $Stats->addOldStats();
118
}
119
120
if (isset($globalArchive) && $globalArchive) {
121
	if (isset($globalArchiveKeepMonths) && $globalArchiveKeepMonths > 0) {
122
		echo "Deleting archive old data...";
123
		require_once(dirname(__FILE__).'/../require/class.SpotterArchive.php');
124
		$SpotterArchive = new SpotterArchive();
125
		$SpotterArchive->deleteSpotterArchiveData();
126
		require_once(dirname(__FILE__).'/../require/class.TrackerArchive.php');
127
		$TrackerArchive = new TrackerArchive();
128
		$TrackerArchive->deleteTrackerArchiveData();
129
		require_once(dirname(__FILE__).'/../require/class.MarineArchive.php');
130
		$MarineArchive = new MarineArchive();
131
		$MarineArchive->deleteMarineArchiveData();
132
	}
133
	if (isset($globalArchiveKeepTrackMonths) && $globalArchiveKeepTrackMonths > 0) {
134
		echo "Deleting archive track old data...";
135
		require_once(dirname(__FILE__).'/../require/class.SpotterArchive.php');
136
		$SpotterArchive = new SpotterArchive();
137
		$SpotterArchive->deleteSpotterArchiveTrackData();
138
		echo "Done\n";
139
		echo "Deleting tracker archive track old data...";
140
		require_once(dirname(__FILE__).'/../require/class.TrackerArchive.php');
141
		$TrackerArchive = new TrackerArchive();
142
		$TrackerArchive->deleteTrackerArchiveTrackData();
143
		echo "Done\n";
144
		echo "Deleting marine archive track old data...";
145
		require_once(dirname(__FILE__).'/../require/class.MarineArchive.php');
146
		$MarineArchive = new MarineArchive();
147
		$MarineArchive->deleteMarineArchiveTrackData();
148
		echo "Done\n";
149
	}
150
}
151
if (isset($globalACARSArchiveKeepMonths) && $globalACARSArchiveKeepMonths > 0) {
152
	echo "Deleting ACARS old data...";
153
	require_once(dirname(__FILE__).'/../require/class.ACARS.php');
154
	$ACARS = new ACARS();
155
	$ACARS->deleteArchiveAcarsData();
156
	echo "Done\n";
157
}
158
if (((isset($globalAircraft) && $globalAircraft) || (isset($globalTracker) && $globalTracker)) && isset($globalGroundAltitude) && $globalGroundAltitude && (!isset($globalOffline) || $globalOffline === FALSE)) {
159
	echo "Adding ground altitude files...\n";
160
	require_once(dirname(__FILE__).'/../require/class.Elevation.php');
161
	$Elevation = new Elevation();
162
	$Elevation->downloadNeeded();
163
	//echo "Done\n";
164
}
165
166
if (isset($globalFires) && $globalFires && $update_db->check_last_fires_update() && (!isset($globalOffline) || $globalOffline === FALSE)) {
167
	echo "Update fires data...";
168
	echo $update_db->update_fires();
169
	$update_db->insert_last_fires_update();
170
	echo "Done\n";
171
}
172
173
174
if (isset($globalMap3D) && $globalMap3D && (!isset($globalOffline) || $globalOffline === FALSE)) {
175
	if (isset($globalSatellite) && $globalSatellite && $update_db->check_last_tle_update()) {
176
		echo "Updating tle for satellites position...";
177
		$update_db->update_tle();
178
		$update_db->insert_last_tle_update();
179
		echo "Done\n";
180
	}
181
	if (!isset($globalMasterServer) || !$globalMasterServer) {
182
		if (isset($globalSatellite) && $globalSatellite && $update_db->check_last_satellite_update()) {
183
			echo $update_db->update_satellite_fam();
184
			$update_db->insert_last_satellite_update();
185
		}
186
		if (!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft)) {
187
			$update_db->update_models();
188
			if (isset($globalMap3DLiveries) && $globalMap3DLiveries) {
189
				$update_db->update_liveries();
190
			}
191
		}
192
		if (isset($globalSatellite) && $globalSatellite) {
193
			$update_db->update_space_models();
194
		}
195
		if ((isset($globalTracker) && $globalTracker) || (isset($globalMarine) && $globalMarine)) {
196
			$update_db->update_vehicules_models();
197
		}
198
		$update_db->update_weather_models();
199
	} elseif (isset($globalMasterServer) && $globalMasterServer) {
200
		if ($update_db->check_last_satellite_update()) {
201
			echo "Updating satellite data...";
202
			echo $update_db->update_celestrak();
203
			$update_db->insert_last_satellite_update();
204
			echo "Done\n";
205
		}
206
	}
207
}
208
?>
209