teamneusta /
php-cli-hosts
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the teamneusta/hosts project. |
||
| 4 | * Copyright (c) 2017 neusta GmbH | Ein team neusta Unternehmen |
||
| 5 | * For the full copyright and license information, please view the LICENSE file that was distributed with this source code. |
||
| 6 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
| 7 | * |
||
| 8 | */ |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class UpdateManifest |
||
| 12 | */ |
||
| 13 | class UpdateManifest extends Task |
||
|
0 ignored issues
–
show
|
|||
| 14 | { |
||
| 15 | private $_baseUrl = 'http://teamneusta.github.io/php-cli-hosts/releases/'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var VersionManager |
||
| 19 | */ |
||
| 20 | protected $versionManager; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Basic information to be provided/filled for release; |
||
| 24 | * |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | private $_baseData = [ |
||
| 28 | "name" => "hosts.phar", |
||
| 29 | "sha1" => "", |
||
| 30 | "url" => "", |
||
| 31 | "version" => "" |
||
| 32 | ]; |
||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $baseDir = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $manifestPath; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $downloadPath; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * UpdateManifest constructor. |
||
| 50 | * |
||
| 51 | * @codeCoverageIgnore |
||
| 52 | * |
||
| 53 | * @param VersionManager|null $versionManager |
||
| 54 | */ |
||
| 55 | public function __construct(VersionManager $versionManager = null) |
||
| 56 | { |
||
| 57 | if ($versionManager == null) { |
||
| 58 | $versionManager = new VersionManager(); |
||
| 59 | } |
||
| 60 | |||
| 61 | $this->versionManager = $versionManager; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The setter for the attribute "basedir" |
||
| 66 | */ |
||
| 67 | 4 | public function setBaseDir($baseDir) |
|
| 68 | { |
||
| 69 | 4 | $this->baseDir = $baseDir; |
|
| 70 | 4 | } |
|
| 71 | |||
| 72 | /** |
||
| 73 | * The setter for the attribute "basedir" |
||
| 74 | */ |
||
| 75 | 4 | public function setManifestPath($manifestPath) |
|
| 76 | { |
||
| 77 | 4 | $this->manifestPath = $manifestPath; |
|
| 78 | 4 | } |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @param $downloadPath |
||
| 82 | */ |
||
| 83 | 4 | public function setDownloadPath($downloadPath) |
|
| 84 | { |
||
| 85 | 4 | $this->downloadPath = $downloadPath; |
|
| 86 | 4 | } |
|
| 87 | |||
| 88 | /** |
||
| 89 | * The main entry point method. |
||
| 90 | */ |
||
| 91 | 4 | public function main() |
|
| 92 | { |
||
| 93 | 4 | $sha1 = sha1_file($this->baseDir . 'hosts.phar'); |
|
| 94 | |||
| 95 | 4 | $targetFileName = $this->getTargetFileName(); |
|
| 96 | |||
| 97 | 4 | copy($this->baseDir . 'hosts.phar', |
|
| 98 | 4 | $this->baseDir . $this->downloadPath . DIRECTORY_SEPARATOR . $targetFileName); |
|
| 99 | |||
| 100 | $releaseData = [ |
||
| 101 | 4 | 'sha1' => $sha1, |
|
| 102 | 4 | 'url' => $this->_baseUrl . $targetFileName, |
|
| 103 | 4 | 'version' => $this->getVersion() |
|
| 104 | ]; |
||
| 105 | |||
| 106 | 4 | $releaseData = array_merge($this->_baseData, $releaseData); |
|
| 107 | |||
| 108 | 4 | $manifest = $this->addReleaseData($releaseData); |
|
| 109 | 4 | $manifestEncoded = json_encode($manifest); |
|
| 110 | |||
| 111 | 4 | file_put_contents($this->manifestPath, $manifestEncoded); |
|
| 112 | 4 | } |
|
| 113 | |||
| 114 | 4 | private function getTargetFileName() |
|
| 115 | { |
||
| 116 | 4 | $version = $this->getVersion(); |
|
| 117 | 4 | $projectName = $this->getProject()->getName(); |
|
| 118 | |||
| 119 | 4 | $fileName = $projectName . "-" . $version . '.phar'; |
|
| 120 | |||
| 121 | 4 | return $fileName; |
|
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return mixed |
||
| 126 | */ |
||
| 127 | 4 | private function getVersion() |
|
| 128 | { |
||
| 129 | 4 | return $this->versionManager->getVersion(); |
|
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param $releaseData |
||
| 134 | * @return array|mixed|string |
||
| 135 | */ |
||
| 136 | 4 | private function addReleaseData($releaseData) |
|
| 137 | { |
||
| 138 | 4 | $manifest = @file_get_contents($this->manifestPath); |
|
| 139 | |||
| 140 | 4 | if (strlen($manifest) > 0) { |
|
| 141 | 3 | $manifest = json_decode($manifest, true); |
|
| 142 | } else { |
||
| 143 | 1 | $manifest = []; |
|
| 144 | } |
||
| 145 | |||
| 146 | 4 | $sha = $releaseData['sha1']; |
|
| 147 | 4 | $version = $releaseData['version']; |
|
| 148 | |||
| 149 | 4 | $manifest = array_filter($manifest, function($item) use ($sha,$version){ |
|
| 150 | 2 | $shaToCompare = $item['sha1'] ?? null; |
|
| 151 | 2 | $versionToCompare = $item['version'] ?? null; |
|
| 152 | |||
| 153 | 2 | return !($shaToCompare === $sha || $versionToCompare === $version); |
|
| 154 | 4 | }); |
|
| 155 | |||
| 156 | 4 | $manifest[] = $releaseData; |
|
| 157 | 4 | return array_values($manifest); |
|
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Class VersionManager |
||
| 163 | * |
||
| 164 | * @codeCoverageIgnore |
||
| 165 | */ |
||
| 166 | class VersionManager |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 167 | { |
||
| 168 | public function getVersion() |
||
| 169 | { |
||
| 170 | exec("git tag", $latestTag); |
||
| 171 | return array_pop($latestTag); |
||
| 172 | } |
||
| 173 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.