Issues (426)

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.

src/controllers/PriceController.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
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\RedirectAction;
15
use hipanel\actions\SmartCreateAction;
16
use hipanel\actions\SmartDeleteAction;
17
use hipanel\actions\SmartUpdateAction;
18
use hipanel\actions\ValidateFormAction;
19
use hipanel\actions\ViewAction;
20
use hipanel\base\CrudController;
21
use hipanel\filters\EasyAccessControl;
22
use hipanel\helpers\ArrayHelper;
23
use hipanel\modules\finance\actions\PriceUpdateAction;
24
use hipanel\modules\finance\collections\PricesCollection;
25
use hipanel\modules\finance\helpers\PriceSort;
26
use hipanel\modules\finance\models\Plan;
27
use hipanel\modules\finance\models\Price;
28
use hipanel\modules\finance\models\TargetObject;
29
use Yii;
30
use yii\base\Event;
31
32
/**
33
 * Class PriceController.
34
 *
35
 * @author Dmytro Naumenko <[email protected]>
36
 */
37
class PriceController extends CrudController
38
{
39 View Code Duplication
    public function behaviors()
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...
40
    {
41
        return array_merge(parent::behaviors(), [
42
            [
43
                'class' => EasyAccessControl::class,
44
                'actions' => [
45
                    'create' => 'price.create',
46
                    'update' => 'price.update',
47
                    'delete' => 'price.delete',
48
                    'create-suggested' => 'price.update',
49
                    '*' => ['plan.read', 'price.read'],
50
                ],
51
            ],
52
        ]);
53
    }
54
55
    public function actions()
56
    {
57
        return array_merge(parent::actions(), [
58
            'index' => [
59
                'class' => IndexAction::class,
60
                'on beforePerform' => function (Event $event) {
61
                    $action = $event->sender;
62
                    $action->getDataProvider()->query
63
                        ->addSelect('main_object_id')
64
                        ->joinWith('object')
65
                        ->joinWith('plan');
66
                },
67
            ],
68
            'view' => [
69
                'class' => ViewAction::class,
70
            ],
71
            'create' => [
72
                'class' => SmartCreateAction::class,
73
                'data' => function ($action, $data) {
74
                    $plan = null;
75
                    if ($plan_id = Yii::$app->request->get('plan_id')) {
76
                        $plan = Plan::findOne(['id' => $plan_id]);
77
                    }
78
79
                    return compact('plan');
80
                },
81
                'success' => Yii::t('hipanel.finance.price', 'Prices were successfully created'),
82
            ],
83
            'create-suggested' => [
84
                'class' => SmartCreateAction::class,
85
                'collection' => ['class' => PricesCollection::class],
86
                'scenario' => 'create',
87
                'POST' => [
88
                    'save' => true,
89
                    'success' => [
90
                        'class' => RedirectAction::class,
91
                        'url' => function (RedirectAction $action) {
92
                            return ['@plan/view', 'id' => $action->collection->getModel()->plan_id];
93
                        },
94
                    ],
95
                ],
96
                'success' => Yii::t('hipanel.finance.price', 'Prices were successfully created'),
97
            ],
98
            'update' => [
99
                'class' => PriceUpdateAction::class,
100
                'collection' => ['class' => PricesCollection::class],
101
                'success' => Yii::t('hipanel.finance.price', 'Prices were successfully updated'),
102
                'scenario' => 'update',
103
                'on beforeFetch' => function (Event $event) {
104
                    /** @var \hipanel\actions\SearchAction $action */
105
                    $action = $event->sender;
106
                    $dataProvider = $action->getDataProvider();
107
                    $dataProvider->query->joinWith('object');
108
                },
109
                'data' => function ($action, $data) {
110
                    $data['models'] = PriceSort::anyPrices()->values($data['models'], true);
111
112
                    return $data;
113
                },
114
            ],
115
            'delete' => [
116
                'class' => SmartDeleteAction::class,
117
                'success' => Yii::t('hipanel.finance.price', 'Prices were successfully deleted'),
118
            ],
119
            'set-note' => [
120
                'class' => SmartUpdateAction::class,
121
                'success' => Yii::t('hipanel', 'Note changed'),
122
            ],
123
            'validate-form' => [
124
                'class' => ValidateFormAction::class,
125
                'collection' => ['class' => PricesCollection::class],
126
            ],
127
        ]);
128
    }
129
130
    public function actionSuggest($plan_id, $object_id = null, $template_plan_id = null, $type = 'default')
131
    {
132
        $plan = Plan::findOne(['id' => $plan_id]);
133
134
        $suggestions = (new Price())->batchQuery('suggest', [
135
            'plan_id' => $plan_id,
136
            'object_id' => $object_id,
137
            'template_plan_id' => $template_plan_id,
138
            'type' => $type,
139
        ]);
140
141
        $models = [];
142
        foreach ($suggestions as $suggestion) {
143
            $object = ArrayHelper::remove($suggestion, 'object');
144
145
            /** @var Price $price */
146
            $price = Price::instantiate($suggestion);
147
            $price->setScenario('create');
148
            $price->setAttributes($suggestion);
149
            $price->populateRelation('object', new TargetObject($object));
150
151
            $models[] = $price;
152
        }
153
154
        $models = PriceSort::anyPrices()->values($models, true);
155
156
        return $this->render('suggested', [
157
            'type' => $type,
158
            'model' => reset($models),
159
            'models' => $models,
160
            'plan' => $plan,
161
        ]);
162
    }
163
}
164