| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @author Victor Dubiniuk <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Copyright (c) 2015, ownCloud, Inc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license AGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This code is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * it under the terms of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * as published by the Free Software Foundation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * You should have received a copy of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | namespace Owncloud\Updater\Utils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class Locator { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * absolute path to ownCloud root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * @var string  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	protected $owncloudRootPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * absolute path to updater root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	protected $updaterRootPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * @param string $baseDir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	public function __construct($baseDir){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$this->updaterRootPath = $baseDir; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$this->owncloudRootPath = dirname($baseDir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	public function getOwncloudRootPath(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		return $this->owncloudRootPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	 * expected items in the core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	public function getRootDirContent(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			"config/config.sample.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			"core", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			"l10n", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			"lib", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			"ocs", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			"ocs-provider", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			"resources", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			"settings", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			".htaccess", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			".mailmap", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			".tag", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			".user.ini", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			"AUTHORS", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			"console.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			"COPYING-AGPL", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			"cron.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			"db_structure.xml", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			"index.html", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			"index.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			"indie.json", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			"occ", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			"public.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			"remote.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			"robots.txt", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			"status.php", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			"version.php" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * Absolute path to core root dir content | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 	public function getRootDirItems(){ | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 		$items = $this->getRootDirContent(); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  | 		$items = array_map( | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 			function($item){ return $this->owncloudRootPath . "/" . $item;	}, | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 			$items | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 		return $items; | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	public function getDataDir(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		return $this->updaterRootPath . '/data'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	public function getCheckpointDir(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		return $this->getDataDir() . '/checkpoint'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	public function getDownloadBaseDir(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		return $this->getDataDir() . '/download'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	public function getExtractionBaseDir(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		 return $this->owncloudRootPath . "/_oc_upgrade"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	public function getPathToOccFile(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		return $this->owncloudRootPath . '/occ'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	public function getInstalledVersion(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		include $this->getPathToVersionFile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		/** @var $OC_Version string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		return $OC_Version; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	public function getBuild(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		include $this->getPathToVersionFile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		/** @var $OC_Build string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 		return $OC_Build; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	public function getPathtoConfigFiles($filePostfix = 'config.php'){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		// Only config.php for now | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 			$this->owncloudRootPath . '/config/' . $filePostfix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	public function getPathToVersionFile(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 		return $this->owncloudRootPath . '/version.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 160 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 161 |  |  |  | 
            
                        
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.