Issues (3099)

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.

GeneratorBundle/Command/GeneratePageCommand.php (3 issues)

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
2
3
namespace Kunstmaan\GeneratorBundle\Command;
4
5
use Kunstmaan\GeneratorBundle\Generator\PageGenerator;
6
use Symfony\Component\Console\Input\InputOption;
7
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
8
9
/**
10
 * Generates a new page
11
 */
12
class GeneratePageCommand extends KunstmaanGenerateCommand
13
{
14
    /**
15
     * @var BundleInterface
16
     */
17
    private $bundle;
18
19
    /**
20
     * @var string
21
     */
22
    private $prefix;
23
24
    /**
25
     * @var string
26
     */
27
    private $pageName;
28
29
    /**
30
     * @var array
31
     */
32
    private $fields;
33
34
    /**
35
     * @var array
36
     */
37
    private $template;
38
39
    /**
40
     * @var array
41
     */
42
    private $sections = array();
43
44
    /**
45
     * @var array
46
     */
47
    private $parentPages = array();
48
49
    /**
50
     * @see Command
51
     */
52
    protected function configure()
53
    {
54
        $this->setDescription('Generates a new page')
55
            ->setHelp(<<<'EOT'
56
The <info>kuma:generate:page</info> command generates a new page and its configuration.
57
58
<info>php bin/console kuma:generate:page</info>
59
EOT
60
            )
61
            ->addOption('prefix', '', InputOption::VALUE_OPTIONAL, 'The prefix to be used in the table name of the generated entity')
62
            ->setName('kuma:generate:page');
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    protected function getWelcomeText()
69
    {
70
        return 'Welcome to the Kunstmaan page generator';
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function doExecute()
77
    {
78
        $this->assistant->writeSection('Page generation');
79
80
        $this->createGenerator()->generate($this->bundle, $this->pageName, $this->prefix, $this->fields, $this->template, $this->sections, $this->parentPages);
81
82
        $this->assistant->writeSection('Page successfully created', 'bg=green;fg=black');
83
84 View Code Duplication
        if (count($this->parentPages) == 0) {
0 ignored issues
show
This code seems to be duplicated across 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...
85
            $this->assistant->writeLine(array(
86
                'To use this page you must first add the definition below to the <comment>getPossibleChildTypes</comment> funtion of the parent page:',
87
                '<comment>    [</comment>',
88
                "<comment>        'name' => '".$this->pageName."',</comment>",
89
                "<comment>        'class'=> '".$this->bundle->getNamespace().'\\Entity\\Pages\\'.$this->pageName."'</comment>",
90
                '<comment>    ],</comment>',
91
                '',
92
            ));
93
        }
94
95
        $this->assistant->writeLine(array(
96
            'Make sure you update your database first before you use the page:',
97
            '    Directly update your database:          <comment>bin/console doctrine:schema:update --force</comment>',
98
            '    Create a Doctrine migration and run it: <comment>bin/console doctrine:migrations:diff && bin/console doctrine:migrations:migrate</comment>',
99
            '',
100
        ));
101
102
        return 0;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    protected function doInteract()
109
    {
110
        if (!$this->isBundleAvailable('KunstmaanPagePartBundle')) {
111
            $this->assistant->writeError('KunstmaanPagePartBundle not found', true);
112
        }
113
114
        $this->assistant->writeLine(array("This command helps you to generate a new page.\n"));
115
116
        /*
117
         * Ask for which bundle we need to create the pagepart
118
         */
119
        $this->bundle = $this->askForBundleName('page');
120
121
        /*
122
         * Ask the database table prefix
123
         */
124
        $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
125
126
        /*
127
         * Ask the name of the pagepart
128
         */
129
        $this->assistant->writeLine(array(
130
            '',
131
            'The name of your Page: For example: <comment>SponsorPage</comment>, <comment>NewsOverviewPage</comment>',
132
            '',
133
        ));
134
        $generator = $this->getGenerator();
135
        $bundlePath = $this->bundle->getPath();
136
137
        $name = $this->assistant->askAndValidate(
138
            'Page name',
139 View Code Duplication
            function ($name) use ($generator, $bundlePath) {
140
                // Check reserved words
141
                if ($generator->isReservedKeyword($name)) {
142
                    throw new \InvalidArgumentException(sprintf('"%s" is a reserved word', $name));
143
                }
144
145
                // Name should end on Page
146
                if (!preg_match('/Page$/', $name)) {
147
                    throw new \InvalidArgumentException('The page name must end with Page');
148
                }
149
150
                // Name should contain more characters than Page
151
                if (strlen($name) <= strlen('Page') || !preg_match('/^[a-zA-Z]+$/', $name)) {
152
                    throw new \InvalidArgumentException('Invalid page name');
153
                }
154
155
                // Check that entity does not already exist
156
                if (file_exists($bundlePath . '/Entity/Pages/' . $name . '.php')) {
157
                    throw new \InvalidArgumentException(sprintf('Page or entity "%s" already exists', $name));
158
                }
159
160
                return $name;
161
            }
162
        );
163
        $this->pageName = $name;
164
165
        /*
166
         * Ask which fields need to be present
167
         */
168
        $this->assistant->writeLine(array("\nInstead of starting with a blank page, you can add some fields now.\n"));
169
        $fields = $this->askEntityFields($this->bundle, array('title', 'pageTitle', 'parent', 'id'));
170
        $this->fields = array();
171
        foreach ($fields as $fieldInfo) {
172
            $this->fields[] = $this->getEntityFields(
173
                $this->bundle,
174
                $this->pageName,
175
                $this->prefix,
176
                $fieldInfo['name'],
177
                $fieldInfo['type'],
178
                $fieldInfo['extra'],
179
                true,
180
                $fieldInfo['minHeight'],
181
                $fieldInfo['maxHeight'],
182
                $fieldInfo['minWidth'],
183
                $fieldInfo['maxWidth'],
184
                $fieldInfo['mimeTypes']
185
            );
186
        }
187
188
        /**
189
         * Ask which default page template we need to use
190
         */
191
        $templateSelect = $this->getTemplateList();
192
        if (empty($templateSelect)) {
193
            throw new \RuntimeException('You need to define at least one page template before running the page generator!');
194
        }
195
196
        $this->assistant->writeLine('');
197
        $templateId = $this->assistant->askSelect('Which page template do you want to use', $templateSelect);
198
        $templateConfigs = $this->getAvailableTemplates($this->bundle);
199
        $templateConfig = $templateConfigs[$templateId];
200
        $this->template = $templateConfig['file'];
201
202
        /*
203
         * Ask for which sections pagepart configuration the end user wants to use for the different sections
204
         */
205
        $this->assistant->writeLine(array("\nThe select page template consists of these contexts: " . implode(', ', $templateConfig['contexts'])));
206
        $this->sections = array();
207
        foreach ($templateConfig['contexts'] as $context) {
208
            $question = "Which pagepart configuration would you like to use for the '$context' context";
209
            $section = $this->askForSections($question, $this->bundle, false, $context);
210
            if (is_null($section)) {
211
                $this->assistant->writeError(sprintf('No section pagepart configuration found for context "%s"', $context), true);
212
            }
213
            $this->sections[] = $section;
214
        }
215
216
        /**
217
         * Ask the parent pages
218
         */
219
        $parentPages = $this->getAvailablePages($this->bundle);
220
        $pagesSelect = array_map(function ($item) {
221
            return $item['name'];
222
        }, $parentPages);
223 View Code Duplication
        if (count($pagesSelect) > 0) {
0 ignored issues
show
This code seems to be duplicated across 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...
224
            $this->assistant->writeLine('');
225
            $parentPageIds = $this->assistant->askSelect('Which existing page(s) can have the new page as sub-page (multiple possible, separated by comma)', $pagesSelect, null, true);
226
            foreach ($parentPageIds as $id) {
227
                $this->parentPages[] = $parentPages[$id]['path'];
228
            }
229
        }
230
    }
231
232
    /**
233
     * Get the generator.
234
     *
235
     * @return PageGenerator
236
     */
237 View Code Duplication
    protected function createGenerator()
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...
238
    {
239
        $filesystem = $this->getContainer()->get('filesystem');
240
        $registry = $this->getContainer()->get('doctrine');
241
242
        return new PageGenerator($filesystem, $registry, '/page', $this->assistant, $this->getContainer());
243
    }
244
245
    /**
246
     * Get all the available default templates.
247
     *
248
     * @return array
249
     */
250
    private function getTemplateList()
251
    {
252
        $templates = $this->getAvailableTemplates($this->bundle);
253
254
        $types = array();
255
        foreach ($templates as $key => $template) {
256
            $types[$key] = $template['name'];
257
        }
258
259
        return $types;
260
    }
261
}
262