Issues (1020)

Security Analysis    no vulnerabilities found

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.

models/Location.php (11 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
 * @property integer $id
4
 * @property array $missions
5
 * @property array $missionTypes
6
 * @property string $name
7
 * @property string $county
8
 * @property integer $routine
9
 * @property array $routineStars
10
 * @property string $routineImages
11
 * @property array $navigationLinks
12
 */
13
class Location extends CModel
14
{
15
    private $id;
16
    private $routine;
17
    private $skill_extended_at_visit;
18
19
    private $county = ['', 'Baranya', 'Bács-Kiskun', 'Jász-Nagykun-Szolnok', 'Csongrád', 'Békés', 'Hajdú-Bihar', 'Szabolcs-Szatmár-Bereg', 'Borsod-Abaúj-Zemplén', 'Heves', 'Nógrád', 'Pest', 'Komárom-Esztergom', 'Győr-Moson-Sopron', 'Fejér', 'Veszprém', 'Vas', 'Zala', 'Somogy', 'Tolna'];
20
    private $missions = [];
21
    private $missionTypes = ['simple'=>[], 'gate'=>[]];
22
    private $visitedGates = [];
23
24
    public function attributeNames()
25
    {
26
        return [];
27
    }
28
29
    /**
30
     * @param integer $id
31
     */
32
    public function setId($id)
33
    {
34
        $this->id = (int)$id;
35
    }
36
37
    public function getId()
38
    {
39
        return $this->id;
40
    }
41
42
    public function getMissions()
43
    {
44
        return $this->missions;
45
    }
46
47
    public function getMissionTypes()
48
    {
49
        return $this->missionTypes;
50
    }
51
52
    public function getName($id = 0)
53
    {
54
        if (!$id) {
55
            $id = $this->id;
56
        }
57
58
        $res = $this->fetchWater($id);
59
        return $res['title'];
60
    }
61
62
    public function getCounty($id = 0)
63
    {
64
        if (!$id) {
65
            $id = $this->id;
66
        }
67
68
        $res = $this->fetchWater($id);
69
        $countyId = $res['county_id'];
70
71
        $county = @$this->county[$countyId];
72
        if (!$county) {
73
            $county = '?';
74
        }
75
76
        return $county;
77
    }
78
79
    public function getRoutine()
80
    {
81
        return $this->routine;
82
    }
83
    public function incrementRoutine()
84
    {
85
        return $this->routine++;
86
    }
87
88
    public function getRoutineStars($r = 0)
89
    {
90
        if (!$r) {
91
            $r = $this->routine;
92
        }
93
94
        $d = floor($r / 81);
95
96
        $eRem = $r % 81;
97
        $e = floor($eRem / 27);
98
99
        $gRem = $r % 27;
100
        $g = floor($gRem / 9);
101
102
        $sRem = $r % 9;
103
        $s = floor($sRem / 3);
104
105
        $bRem = $r % 3;
106
        $b = $bRem;
107
108
        $ret = ['routine'=>$r, 'diamant'=>$d, 'emerald'=>$e, 'gold'=>$g, 'silver'=>$s, 'bronze'=>$b];
109
        return $ret;
110
    }
111
112
    public function getRoutineImages($routine)
113
    {
114
        $txt = '';
115
        foreach (['diamant', 'emerald', 'gold', 'silver', 'bronze'] as $star) {
116
            for ($i=0; $i<$routine[$star]; $i++) {
117
                $txt .= '<span class="spr star-'.$star[0].'"></span>';
118
            }
119
        }
120
        return $txt;
121
    }
122
    
123
    public function getNavigationLinks()
124
    {
125
        $nav = [];
126
        //previous locations
127
        $res = $this->fetchWater($this->id);
128
129
        foreach (['from', 'from2'] as $id) {
130
            if ($res[$id]) {
131
                $navId = (int)$res[$id];
132
                $link = [
133
                    'id' => $navId,
134
                    'type' => 'prev',
135
                    'title' => $this->getName($navId),
136
                    'active' => true,
137
                    ];
138
                $nav[] = $link;
139
            }
140
        }
141
142
        //next locations
143
        foreach ($this->missionTypes['gate'] as $missionId) {
144
            $nextId = (int)$this->missions[$missionId]->gate;
145
            $visited = $this->isVisited($nextId);
146
            $this->visitedGates[$nextId] = $visited;
147
148
            $link = [
149
                'id' => $nextId,
150
                'type' => 'next',
151
                'title' => $this->getName($nextId),
152
                'active' => $this->visitedGates[$nextId],
153
                ];
154
            $nav[] = $link;
155
        }
156
157
        return $nav;
158
    }
159
160
    public function isVisited($id = 0)
161
    {
162
        if (!$id) {
163
            $id = $this->id;
164
        }
165
166
        $uid = Yii::app()->player->model->uid;
167
168
        $visited = Yii::app()->db->createCommand()
169
            ->select('*')
170
            ->from('visited')
171
            ->where('uid=:uid AND water_id=:id', [':uid'=>$uid, ':id'=>$id])
172
            ->queryScalar();
173
174
        if (!$visited && $id==1) {
175
            //visit 1. location
176
            Yii::app()->db->createCommand()
177
                ->insert('visited', [
178
                'uid'=>$uid,
179
                'water_id'=>$id,
180
                ]);
181
            $visited = true;
182
            Yii::app()->gameLogger->log(['type'=>'travel', 'traveled_to'=>$id]);
183
        }
184
185
        return $visited ? true : false;
186
    }
187
188
    public function setActive()
189
    {
190
        $player = Yii::app()->player->model;
191
        if ($player->last_location == $this->id) {
192
            return false;
193
        }
194
195
        $attr = ['last_location'=>$this->id];
196
        
197
        if ($this->id > 1 && $player->tutorial_mission==6) {
198
            $attr['tutorial_mission'] = 7;
199
        }
200
        
201
        $player->rewriteAttributes($attr);
202
        Yii::app()->badge->model->triggerTravel($this->id);
203
        return true;
204
    }
205
206
    public function fetchMissions()
207
    {
208
        $res = Yii::app()->db->createCommand()
209
            ->select('id')
210
            ->from('missions')
211
            ->where('water_id=:id', [':id'=>$this->id])
212
            ->order('id ASC')
213
            ->queryAll();
214
215
        $this->fetchSkill_extended_at_visit();
216
217
        foreach ($res as $mission) {
218
            $m = new Mission();
219
            $m->id = $mission['id'];
0 ignored issues
show
The property id cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
220
            $m->skill_extended_at_visit = $this->skill_extended_at_visit;
0 ignored issues
show
The property skill_extended_at_visit cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
221
            $m->req_energy_expansion = $this->getEnergyExpansion();
0 ignored issues
show
The property req_energy_expansion cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
222
            $m->fetch();
223
            if ($m->gate) {
0 ignored issues
show
The property gate cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
224
                $m->gate_name = $this->getName($m->gate);
0 ignored issues
show
The property gate_name cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
The property gate cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
225
                $m->gate_visited = $this->isVisited($m->gate);
0 ignored issues
show
The property gate_visited cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
The property gate cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
226
                $this->visitedGates[$m->gate] = $m->gate_visited;
0 ignored issues
show
The property gate cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
The property gate_visited cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
227
            }
228
229
            $this->missions[$mission['id']] = $m;
230
            $key = $m->gate ? 'gate' : 'simple';
0 ignored issues
show
The property gate cannot be accessed from this context as it is declared private in class Mission.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
231
            $this->missionTypes[$key][] = $mission['id'];
232
        }
233
    }
234
235
    private function getEnergyExpansion()
236
    {
237
        $exp = 0;
238
239
        if ($this->routine >= 27) {
240
            $exp = 1; // gold
241
        }
242
243
        if ($this->routine >= 243) {
244
            $exp = 2; // diamant
245
        }
246
247
        return $exp;
248
    }
249
250
    public function fetchRoutine()
251
    {
252
        $res = Yii::app()->db->createCommand()
253
            ->select('routine')
254
            ->from('visited')
255
            ->where('uid=:uid AND water_id=:water_id', [':uid'=>Yii::app()->player->model->uid, ':water_id'=>$this->id])
256
            ->queryScalar();
257
        $this->routine = (int)$res;
258
    }
259
260
    public function fetchSkill_extended_at_visit()
261
    {
262
        $dependency = new CExpressionDependency('Yii::app()->params["visited_version"]');
263
        $res = Yii::app()->db->cache(Yii::app()->params['cacheDuration'], $dependency)->createCommand()
264
            ->select('skill_extended_at_visit')
265
            ->from('visited')
266
            ->where('uid=:uid AND water_id=:water_id', [':uid'=>Yii::app()->player->model->uid, ':water_id'=>$this->id])
267
            ->queryScalar();
268
        $this->skill_extended_at_visit = (int)$res;
269
    }
270
271
    public function listVisited()
272
    {
273
        $res = Yii::app()->db->createCommand()
274
            ->select('water_id, routine')
275
            ->from('visited')
276
            ->where('uid=:uid', [':uid'=>Yii::app()->player->model->uid])
277
            ->queryAll();
278
        $visited = [];
279
        foreach ($res as $l) {
280
            $water = $this->fetchWater($l['water_id']);
281
            if ($l['water_id'] == Yii::app()->player->model->last_location) {
282
                $water['last']=1;
283
            }
284
285
            $water['routine'] = $l['routine'];
286
            $visited[$l['water_id']] = $water;
287
        }
288
        return $visited;
289
    }
290
291
    private function fetchWater($id)
292
    {
293
        $dependency = new CExpressionDependency('Yii::app()->params["waters_version"]');
294
        $res = Yii::app()->db->cache(Yii::app()->params['cacheDuration'], $dependency)->createCommand()
295
            ->select('*')
296
            ->from('waters')
297
            ->where('id=:id', [':id'=>(int)$id])
298
            ->queryRow();
299
        return $res;
300
    }
301
}
302