Issues (362)

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.

AdminModule/presenters/CloningPresenter.php (14 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
/**
4
 * Webcms2 admin module package.
5
 */
6
7
namespace AdminModule;
8
9
use Nette\Application\UI;
10
11
/**
12
 * @author Tomáš Voslař <tomas.voslar at webcook.cz>
13
 * @package WebCMS2
14
 */
15
class CloningPresenter extends BasePresenter
16
{
17 1
    public function renderDefault()
18
    {
19 1
        $this->reloadContent();
20 1
    }
21
22 1
    public function createComponentCloningForm()
23
    {
24 1
        $form = $this->createForm();
25
26 1
        $langs = $this->getAllLanguages();
27 1
        $packages = \WebCMS\Helpers\SystemHelper::getPackages();
28
29 1
        $form->addGroup('Copy structures');
30
31 1
        $form->addSelect('languageFrom', 'Copy from', $langs)->setRequired('Please pick up language.')->setAttribute('class', 'form-control');
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32 1
        $form->addSelect('languageTo', 'Copy to', $langs)->setRequired('Please pick up language.')->setAttribute('class', 'form-control');
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33 1
        $form->addCheckbox('removeData', 'Remove data?');
34
35 1
        $form->addGroup('Copy data from modules');
36
37 1 View Code Duplication
        foreach ($packages as $key => $package) {
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...
38
            if ($package['vendor'] === 'webcms2' && $package['package'] !== 'webcms2') {
39
                $object = $this->createObject($package['package']);
40
41
                if ($object->isCloneable()) {
42
                    $form->addCheckbox(str_replace('-', '_', $package['package']), $package['package']);
43
                } else {
44
                    $form->addCheckbox(str_replace('-', '_', $package['package']), $package['package'].' not clonable.')->setDisabled(true);
45
                }
46
            }
47 1
        }
48
49 1
        $form->onSuccess[] = callback($this, 'cloningFormSubmitted');
50 1
        $form->addSubmit('send', 'Clone');
51
52 1
        return $form;
53
    }
54
55
    public function cloningFormSubmitted(UI\Form $form)
56
    {
57
        $values = $form->getValues();
58
59
        $languageFrom = $this->em->getRepository('WebCMS\Entity\Language')->find($values->languageFrom);
60
        $languageTo = $this->em->getRepository('WebCMS\Entity\Language')->find($values->languageTo);
61
        $removeData = $values->removeData;
62
        
63
        $values = $this->normalizeValues($values);
64
65
        // remove data first
66
        if ($removeData) {
67
            $this->removeData($languageTo);
68
        }
69
70
        // clone page structure
71
        $transformTable = array();
72
73
        $pages = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array(
74
            'language' => $languageFrom,
75
            ), array('lft' => 'asc'));
76
77
        foreach ($pages as $page) {
78
            $new = $this->createNewPage($languageTo, $page);
79
80
            if ($page->getParent()) {
81
                $new->setParent($transformTable[$page->getParent()->getId()]);
82
            }
83
84
            $this->em->persist($new);
85
            $this->em->flush();
86
87
            $new = $this->setPagePath($new);
88
89
            $this->em->flush();
90
91
            $transformTable[$page->getId()] = $new;
92
        }
93
94
        foreach ($pages as $page) {
95
            $this->pageCreateBoxes($page, $transformTable);
96
        }
97
98
        // clone all data
99
        $this->cloneData($values, $languageFrom, $languageTo, $transformTable);
100
101
        // persist all changes into database
102
        $this->em->flush();
103
104
        $this->flashMessage('Cloning has been successfuly done.', 'success');
105
        if (!$this->isAjax()) {
106
            $this->forward('Languages:cloning');
107
        }
108
    }
109
110
    /**
111
     *
112
     *
113
     * @param \WebCMS\Entity\Page $new [description]
114
     */
115 1 View Code Duplication
    private function setPagePath($new)
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...
116
    {
117
        $path = $this->em->getRepository('WebCMS\Entity\Page')->getPath($new);
118
        $final = array();
119
        foreach ($path as $p) {
120 1
            if ($p->getParent() != NULL) {
121
                $final[] = $p->getSlug();
122
            }
123
        }
124
125
        $new->setPath(implode('/', $final));
126
127
        return $new;
128
    }
129
130
    /**
131
     *
132
     *
133
     * @param  [type] $values [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
134
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
135
     */
136
    private function normalizeValues($values)
137
    {
138
        unset($values->languageFrom);
139
        unset($values->languageTo);
140
        unset($values->removeData);
141
142
        return $values;
143
    }
144
145
    /**
146
     *
147
     *
148
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
149
     */
150
    private function pageCreateBoxes($page, $transformTable)
151
    {
152
        $boxes = $this->em->getRepository('WebCMS\Entity\Box')->findBy(array(
153
            'pageTo' => $page,
154
        ));
155
156
        foreach ($boxes as $box) {
157
            $newBox = $this->createNewBox($box, $transformTable);
158
            $this->em->persist($newBox);
159
        }
160
    }
161
162
    /**
163
     *
164
     *
165
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
166
     */
167
    private function cloneData($values, $languageFrom, $languageTo, $transformTable)
168
    {
169
        foreach ($values as $key => $value) {
170
            if ($value) {
171
                $module = $this->createObject(str_replace('_', '-', $key));
172
                if ($module->isCloneable()) {
173
                    $module->cloneData($this->em, $languageFrom, $languageTo, $transformTable);
174
                }
175
            }
176
        }
177
    }
178
179
    /**
180
     *
181
     *
182
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
183
     */
184
    private function removeData($languageTo)
185
    {
186
        $pages = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array(
187
            'language' => $languageTo,
188
            'parent' => NULL,
189
        ));
190
191
        foreach ($pages as $page) {
192
            $this->em->remove($page);
193
        }
194
    }
195
196
    /**
197
     *
198
     *
199
     * @param  [type] $languageTo [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
200
     * @param  [type] $page       [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
201
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
202
     */
203
    private function createNewPage($languageTo, $page)
204
    {
205
        $new = new \WebCMS\Entity\Page();
206
        $new->setLanguage($languageTo);
207
        $new->setTitle($page->getTitle());
208
        $new->setPresenter($page->getPresenter());
209
        $new->setPath('tmp');
210
        $new->setVisible($page->getVisible());
211
        $new->setDefault($page->getDefault());
212
        $new->setClass($page->getClass());
213
        $new->setModule($page->getModule());
214
        $new->setModuleName($page->getModuleName());
215
        $new->setLayout($page->getLayout());
216
217
        return $new;
218
    }
219
220
    /**
221
     *
222
     *
223
     * @param  [type] $box [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
224
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
225
     */
226 1
    private function createNewBox($box, $transformTable)
227
    {
228
        $newBox = new \WebCMS\Entity\Box();
229
        $newBox->setBox($box->getBox());
230
        $newBox->setFunction($box->getFunction());
231
        $newBox->setModuleName($box->getModuleName());
232
        $newBox->setPresenter($box->getPresenter());
233
        $newBox->setPageFrom($transformTable[$box->getPageFrom()->getId()]);
234
        $newBox->setPageTo($transformTable[$box->getPageTo()->getId()]);
235
236
        return $newBox;
237 1
    }
238
}
239