Issues (3)

Security Analysis    no request data  

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.

src/NewCommand.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 namespace Laravel\Installer\Console;
2
3
ini_set('memory_limit', '1G');
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Event\ProgressEvent;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Helper\ProgressBar;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Process\Process;
14
use ZipArchive;
15
16
class NewCommand extends Command {
17
18
    private $input;
19
20
    private $output;
21
22
    private $directory;
23
24
    private $zipFile;
25
26
    private $progress = 0;
27
28
    /**
29
     * Configure the command options.
30
     *
31
     * @return void
32
     */
33
    protected function configure()
34
    {
35
        $this->setName('new')
36
             ->setDescription('Create a new Laravel application.')
37
             ->addArgument('name', InputArgument::REQUIRED)
38
             ->addOption('slim', null, InputOption::VALUE_NONE)
39
             ->addOption('force', null, InputOption::VALUE_NONE)
40
             ->addOption('laravelOnly', null, InputOption::VALUE_NONE)
41
             ->addOption('lumen', null, InputOption::VALUE_NONE)
42
             ->addOption('lumenOnly', null, InputOption::VALUE_NONE);
43
    }
44
45
    /**
46
     * Execute the command.
47
     *
48
     * @param  InputInterface  $input
49
     * @param  OutputInterface $output
50
     *
51
     * @return void
52
     */
53
    protected function execute(InputInterface $input, OutputInterface $output)
54
    {
55
        $this->input     = $input;
56
        $this->output    = $output;
57
        $this->directory = getcwd() . '/' . $input->getArgument('name');
58
        $this->zipFile   = $this->makeFilename();
59
60
        $output->writeln('<info>Crafting NukaCode application...</info>');
61
62
63
        $this->verifyApplicationDoesntExist();
64
65
        $this->download();
66
67
        $this->extract();
68
69
        // Lumen does not have composer post install scripts.
70
        if (!$this->input->getOption('lumen') && !$this->input->getOption('lumenOnly')) {
71
            $this->runComposerCommands();
72
        }
73
74
        $output->writeln('<comment>Application ready! Build something amazing.</comment>');
75
    }
76
77
    /**
78
     * Verify that the application does not already exist.
79
     *
80
     * @return void
81
     */
82
    protected function verifyApplicationDoesntExist()
83
    {
84
        $this->output->writeln('<info>Checking application path for existing site...</info>');
85
86
        if (is_dir($this->directory)) {
87
            $this->output->writeln('<error>Application already exists!</error>');
88
89
            exit(1);
90
        }
91
92
        $this->output->writeln('<info>Check complete...</info>');
93
    }
94
95
    /**
96
     * Download the temporary Zip to the given file.
97
     *
98
     * @return $this
99
     */
100
    protected function download()
101
    {
102
        $buildUrl = $this->getBuildFileLocation();
103
104
        if ($this->input->getOption('force')) {
105
            $this->output->writeln('<info>--force command given. Deleting old build files...</info>');
106
107
            $this->cleanUp();
108
109
            $this->output->writeln('<info>complete...</info>');
110
        }
111
112
        if ($this->checkIfServerHasNewerBuild()) {
113
            $this->cleanUp();
114
            $this->downloadFileWithProgressBar($buildUrl);
115
        }
116
117
        return $this;
118
    }
119
120
    /**
121
     * Extract the zip file into the given directory.
122
     *
123
     *
124
     * @return $this
125
     */
126
    protected function extract()
127
    {
128
        $this->output->writeln('<info>Extracting files...</info>');
129
130
        $archive = new ZipArchive;
131
132
        $archive->open($this->zipFile);
133
134
        $archive->extractTo($this->directory);
135
136
        $archive->close();
137
138
        $this->output->writeln('<info>Extracting complete...</info>');
139
140
        return $this;
141
    }
142
143
    /**
144
     * Run post install composer commands
145
     *
146
     * @return void
147
     */
148
    protected function runComposerCommands()
149
    {
150
        $this->output->writeln('<info>Running post install scripts...</info>');
151
152
        $composer = $this->findComposer();
153
154
        $commands = [
155
            $composer . ' run-script post-install-cmd',
156
            $composer . ' run-script post-create-project-cmd',
157
        ];
158
159
        $process = new Process(implode(' && ', $commands), $this->directory, null, null, null);
160
161
        $process->run(function ($type, $line) {
162
            $this->output->write($line);
163
        });
164
165
        $this->output->writeln('<info>Scripts complete...</info>');
166
    }
167
168
    /**
169
     * Clean-up the Zip file.
170
     *
171
     * @return $this
172
     */
173
    protected function cleanUp()
174
    {
175
        @chmod($this->zipFile, 0777);
176
        @unlink($this->zipFile);
177
178
        return $this;
179
    }
180
181
    /**
182
     * Get the composer command for the environment.
183
     *
184
     * @return string
185
     */
186
    protected function findComposer()
187
    {
188
        if (file_exists(getcwd() . '/composer.phar')) {
189
            return '"' . PHP_BINARY . '" composer.phar';
190
        }
191
192
        return 'composer';
193
    }
194
195
    /**
196
     * Generate a random temporary filename.
197
     *
198
     * @return string
199
     */
200
    protected function makeFilename()
201
    {
202
        if ($this->input->getOption('lumen')) {
203
            return dirname(__FILE__) . '/lumen.zip';
204
        }
205
206
        if ($this->input->getOption('lumenOnly')) {
207
            return dirname(__FILE__) . '/lumen_only.zip';
208
        }
209
210
        if ($this->input->getOption('laravelOnly')) {
211
            return dirname(__FILE__) . '/laravel_only.zip';
212
        }
213
214
        if ($this->input->getOption('slim')) {
215
            return dirname(__FILE__) . '/laravel_slim.zip';
216
        }
217
218
        return dirname(__FILE__) . '/laravel_full.zip';
219
    }
220
221
    /**
222
     * Get the build file location based on the flags passed in.
223
     *
224
     * @return string
225
     */
226
    protected function getBuildFileLocation()
227
    {
228
        if ($this->input->getOption('lumen')) {
229
            return 'http://builds.nukacode.com/lumen/latest.zip';
230
        }
231
232
        if ($this->input->getOption('lumenOnly')) {
233
            return 'http://cabinet.laravel.com/latest_lumen.zip';
234
        }
235
236
        if ($this->input->getOption('laravelOnly')) {
237
            return 'http://cabinet.laravel.com/latest.zip';
238
        }
239
240
        if ($this->input->getOption('slim')) {
241
            return 'http://builds.nukacode.com/slim/latest.zip';
242
        }
243
244
        return 'http://builds.nukacode.com/full/latest.zip';
245
    }
246
247
    /**
248
     * Download the nukacode build files and display progress bar.
249
     *
250
     * @param $buildUrl
251
     */
252 View Code Duplication
    protected function downloadFileWithProgressBar($buildUrl)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
253
    {
254
        $this->output->writeln('<info>Begin file download...</info>');
255
256
        $progressBar = new ProgressBar($this->output, 100);
257
        $progressBar->start();
258
259
        $client  = new Client();
260
        $request = $client->createRequest('GET', $buildUrl);
261
        $request->getEmitter()->on('progress', function (ProgressEvent $e) use ($progressBar) {
262
            if ($e->downloaded > 0) {
263
                $localProgress = floor(($e->downloaded / $e->downloadSize * 100));
264
265
                if ($localProgress != $this->progress) {
266
                    $this->progress = (integer)$localProgress;
267
                    $progressBar->advance();
268
                }
269
            }
270
        });
271
272
        $response = $client->send($request);
273
274
        $progressBar->finish();
275
276
        file_put_contents($this->zipFile, $response->getBody());
277
278
        $this->output->writeln("\n<info>File download complete...</info>");
279
    }
280
281
    /**
282
     * Check if the server has a newer version of the nukacode build.
283
     *
284
     * @return bool
285
     */
286
    protected function checkIfServerHasNewerBuild()
287
    {
288
        if (file_exists($this->zipFile)) {
289
            $client   = new Client();
290
            $response = $client->get('http://builds.nukacode.com/files.php');
291
292
            // The downloaded copy is the same as the one on the server.
293
            if (in_array(md5_file($this->zipFile), $response->json())) {
294
                return false;
295
            }
296
        }
297
298
        return true;
299
    }
300
}
301