Issues (68)

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.

controllers/DefController.php (2 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 nkostadinov\taxonomy\controllers;
4
5
use nkostadinov\taxonomy\models\TaxonomyTerms;
6
use Yii;
7
use nkostadinov\taxonomy\models\TaxonomyDef;
8
use nkostadinov\taxonomy\models\TaxonomyDefSearch;
9
use yii\base\InvalidConfigException;
10
use yii\data\ActiveDataProvider;
11
use yii\helpers\Url;
12
use yii\web\Controller;
13
use yii\web\NotFoundHttpException;
14
use yii\filters\VerbFilter;
15
16
// fcgi doesn't have STDIN and STDOUT defined by default
17
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
18
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
19
20
class Migrator extends \yii\console\controllers\MigrateController
21
{
22
    public function __construct($id, $module, $config = [])
23
    {
24
        parent::__construct($id, $module, $config); // TODO: Change the autogenerated stub
25
    }
26
27
    public function runTaxonomy($class, $migrationPath)
0 ignored issues
show
The parameter $migrationPath is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        ob_start();
30
        //$this->migrationPath = Yii::getAlias($migrationPath);
31
        if($this->beforeAction('up'))
32
            $this->migrateUp($class);
33
        $result = ob_get_contents();
34
        return $result;
35
    }
36
37
    public function removeTaxonomy($class, $migrationPath)
0 ignored issues
show
The parameter $migrationPath is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        ob_start();
40
        //$this->migrationPath = Yii::getAlias($migrationPath);
41
        if($this->beforeAction('down'))
42
            $this->migrateDown($class);
43
        $result = ob_get_contents();
44
        return $result;
45
    }
46
}
47
48
/**
49
 * DefController implements the CRUD actions for TaxonomyDef model.
50
 */
51
class DefController extends Controller
52
{
53
    public function behaviors()
54
    {
55
        return [
56
            'verbs' => [
57
                'class' => VerbFilter::className(),
58
                'actions' => [
59
                    'delete' => ['post'],
60
                ],
61
            ],
62
        ];
63
    }
64
65
    /**
66
     * Lists all TaxonomyDef models.
67
     * @return mixed
68
     * @throws InvalidConfigException
69
     */
70
    public function actionIndex()
71
    {
72
        if(!$this->getComponent()->isInstalled())
73
            throw new InvalidConfigException("Please run the migration first!");
74
75
        $searchModel = new TaxonomyDefSearch();
76
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
77
78
        return $this->render('index', [
79
            'searchModel' => $searchModel,
80
            'dataProvider' => $dataProvider,
81
        ]);
82
    }
83
84
    /**
85
     * Displays a single TaxonomyDef model.
86
     * @param integer $id
87
     * @return mixed
88
     */
89
    public function actionView($id)
90
    {
91
        $termProvider = new ActiveDataProvider([
92
            'query' => TaxonomyTerms::find()->andFilterWhere(['taxonomy_id' => $id]),
93
            'sort' => [
94
                // Set the default sort by name ASC and created_at DESC.
95
                'defaultOrder' => [
96
                    'total_count' => SORT_DESC,
97
                ]
98
            ],
99
        ]);
100
101
        return $this->render('view', [
102
            'model' => $this->findModel($id),
103
            'termProvider' => $termProvider
104
        ]);
105
    }
106
107
    /**
108
     * Creates a new TaxonomyDef model.
109
     * If creation is successful, the browser will be redirected to the 'view' page.
110
     * @return mixed
111
     */
112
    public function actionCreate()
113
    {
114
        $model = new TaxonomyDef();
115
        $definitions = $this->getComponent()->getDefinitions();
116
117
        if ($model->load(Yii::$app->request->post())) {
118
            //install the term
119
            $term = Yii::createObject($model->attributes);
120
                //$this->getComponent()->getTerm($model->name);
121
            $term->install();
122
            $migration = new Migrator('migrate', Yii::$app);
123
            $messsage = $migration->runTaxonomy($term->migration, $term->migrationPath);
124
            Yii::$app->session->setFlash('info', $messsage, true);
125
126
            return $this->redirect(['index', 'id' => $model->id]);
127
        } else {
128
            return $this->render('create', [
129
                'model' => $model,
130
                'definitions' => $definitions,
131
            ]);
132
        }
133
    }
134
135
    /**
136
     * Updates an existing TaxonomyDef model.
137
     * If update is successful, the browser will be redirected to the 'view' page.
138
     * @param integer $id
139
     * @return mixed
140
     */
141
    public function actionUpdate($id)
142
    {
143
        $model = $this->findModel($id);
144
        $definitions = $this->getComponent()->getDefinitions();
145
146
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
147
            return $this->redirect(['view', 'id' => $model->id]);
148
        } else {
149
            return $this->render('update', [
150
                'model' => $model,
151
                'definitions' => $definitions,
152
            ]);
153
        }
154
    }
155
156
    /**
157
     * Deletes an existing TaxonomyDef model.
158
     * If deletion is successful, the browser will be redirected to the 'index' page.
159
     * @param integer $id
160
     * @return mixed
161
     */
162
    public function actionDelete($id)
163
    {
164
        $model = $this->findModel($id);
165
        //UNinstall the term
166
        $term = $this->getComponent()->getTerm($model->name);
167
        $migration = new Migrator('migrate', Yii::$app);
168
        $messsage = $migration->removeTaxonomy($term->migration, $term->migrationPath);
169
        Yii::$app->session->setFlash('info', $messsage, true);
170
171
        $term->uninstall();
172
173
174
        return $this->redirect(['index']);
175
    }
176
177
    /**
178
     * Finds the TaxonomyDef model based on its primary key value.
179
     * If the model is not found, a 404 HTTP exception will be thrown.
180
     * @param integer $id
181
     * @return TaxonomyDef the loaded model
182
     * @throws NotFoundHttpException if the model cannot be found
183
     */
184
    protected function findModel($id)
185
    {
186
        if (($model = TaxonomyDef::findOne($id)) !== null) {
187
            return $model;
188
        } else {
189
            throw new NotFoundHttpException('The requested page does not exist.');
190
        }
191
    }
192
193
    public function getComponent()
194
    {
195
        if(\Yii::$app->has($this->module->component))
196
            return \Yii::$app->{$this->module->component};
197
        else
198
            throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})");
199
    }
200
201
    public function actionInstall()
202
    {
203
        if(!$this->getComponent()->isInstalled() and \Yii::$app->request->isPost) {
204
            //start installation
205
            if($this->getComponent()) {
206
                $this->getComponent()->install();
207
208
                $this->redirect(['/'.$this->module->id . '/' . $this->id . '/index']);
209
            } else
210
                throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})");
211
        }
212
        return $this->render('install');
213
    }
214
215
    public function actionInstallterm($term)
216
    {
217
        $term = $this->getComponent()->getTerm($term);
218
        $term->install();
219
    }
220
}
221