Issues (84)

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/Base.php (7 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 namespace jlourenco\base;
2
3
use jlourenco\base\Repositories\SettingsRepositoryInterface;
4
use jlourenco\base\Repositories\UserRepositoryInterface;
5
use jlourenco\base\Repositories\LogRepositoryInterface;
6
use jlourenco\base\Repositories\VisitsRepositoryInterface;
7
use jlourenco\base\Repositories\JobsRepositoryInterface;
8
use BadMethodCallException;
9
use Request;
10
use Jenssegers\Agent\Agent;
11
use GeoIP;
12
use Sentinel;
13
14
class Base
15
{
16
17
    /**
18
     * The Settings repository.
19
     *
20
     * @var \jlourenco\base\Repositories\SettingsRepositoryInterface
21
     */
22
    protected $settings;
23
24
    /**
25
     * The User repository.
26
     *
27
     * @var \jlourenco\base\Repositories\UserRepositoryInterface
28
     */
29
    protected $user;
30
31
    /**
32
     * The Log repository.
33
     *
34
     * @var \jlourenco\base\Repositories\LogRepositoryInterface
35
     */
36
    protected $logs;
37
38
    /**
39
     * The Job repository.
40
     *
41
     * @var \jlourenco\base\Repositories\JobsRepositoryInterface
42
     */
43
    protected $jobs;
44
45
    /**
46
     * The Visits repository.
47
     *
48
     * @var \jlourenco\base\Repositories\VisitsRepositoryInterface
49
     */
50
    protected $visits;
51
52
    /**
53
     * Cached, available methods on the settings repository, used for dynamic calls.
54
     *
55
     * @var array
56
     */
57
    protected $settingsMethods = [];
58
59
    /**
60
     * Create a new Base instance.
61
     *
62
     * @param  \jlourenco\base\Repositories\SettingsRepositoryInterface  $settings
63
     * @param  \jlourenco\base\Repositories\UserRepositoryInterface  $user
64
     * @param  \jlourenco\base\Repositories\LogRepositoryInterface  $log
65
     * @param  \jlourenco\base\Repositories\VisitsRepositoryInterface  $visits
66
     */
67
    public function __construct(SettingsRepositoryInterface $settings, UserRepositoryInterface $user, LogRepositoryInterface $log, VisitsRepositoryInterface $visits, JobsRepositoryInterface $jobs)
68
    {
69
        $this->settings = $settings;
70
        $this->user = $user;
71
        $this->logs = $log;
72
        $this->visits = $visits;
73
        $this->jobs = $jobs;
74
    }
75
76
    /**
77
     * Returns the settings repository.
78
     *c
79
     * @return \jlourenco\base\Repositories\SettingsRepositoryInterface
80
     */
81
    public function getSettingsRepository()
82
    {
83
        return $this->settings;
84
    }
85
86
    /**
87
     * Sets the ettings repository.
88
     *
89
     * @param  \jlourenco\base\Repositories\SettingsRepositoryInterface $settings
90
     * @return void
91
     */
92
    public function setSettingsRepository(SettingsRepositoryInterface $settings)
93
    {
94
        $this->settings = $settings;
95
    }
96
97
    /**
98
     * Returns the ers repository.
99
     *c
100
     * @return \jlourenco\base\Repositories\UserRepositoryInterface
101
     */
102
    public function getUsersRepository()
103
    {
104
        return $this->user;
105
    }
106
107
    /**
108
     * Sets the ettings repository.
109
     *
110
     * @param  \jlourenco\base\Repositories\UserRepositoryInterface $user
111
     * @return void
112
     */
113
    public function setUsersRepository(UserRepositoryInterface $user)
114
    {
115
        $this->user = $user;
116
    }
117
118
    /**
119
     * Returns the log repository.
120
     *c
121
     * @return \jlourenco\base\Repositories\LogRepositoryInterface
122
     */
123
    public function getLogsRepository()
124
    {
125
        return $this->logs;
126
    }
127
128
    /**
129
     * Sets the log repository.
130
     *
131
     * @param  \jlourenco\base\Repositories\LogRepositoryInterface $log
132
     * @return void
133
     */
134
    public function setLogsRepository(LogRepositoryInterface $log)
135
    {
136
        $this->logs = $log;
137
    }
138
139
    /**
140
     * Returns the visits repository.
141
     *c
142
     * @return \jlourenco\base\Repositories\VisitsRepositoryInterface
143
     */
144
    public function getVisitsRepository()
145
    {
146
        return $this->visits;
147
    }
148
149
    /**
150
     * Sets the visits repository.
151
     *
152
     * @param  \jlourenco\base\Repositories\VisitsRepositoryInterface $visits
153
     * @return void
154
     */
155
    public function setVisitsRepository(VisitsRepositoryInterface $visits)
156
    {
157
        $this->visits = $visits;
158
    }
159
160
    /**
161
     * Returns the jobs repository.
162
     *c
163
     * @return \jlourenco\base\Repositories\JobsRepositoryInterface
164
     */
165
    public function getJobsRepository()
166
    {
167
        return $this->jobs;
168
    }
169
170
    /**
171
     * Sets the jobs repository.
172
     *
173
     * @param  \jlourenco\base\Repositories\JobsRepositoryInterface $jobs
174
     * @return void
175
     */
176
    public function setJobsRepository(JobsRepositoryInterface $jobs)
177
    {
178
        $this->jobs = $jobs;
179
    }
180
181
    /**
182
     * Returns all accessible methods on the associated settings repository.
183
     *
184
     * @return array
185
     */
186
    protected function getSettingsMethods()
187
    {
188
        if (empty($this->settingsMethods)) {
189
            $settings = $this->getSettingsRepository();
190
191
            $methods = get_class_methods($settings);
192
193
            $this->settingsMethods = array_diff($methods, ['__construct']);
194
        }
195
196
        return $this->settingsMethods;
197
    }
198
199
    /**
200
     * Dynamically pass missing methods to Base.
201
     *
202
     * @param  string  $method
203
     * @param  array  $parameters
204
     * @return mixed
205
     * @throws \BadMethodCallException
206
     */
207
    public function __call($method, $parameters)
208
    {
209
        $methods = $this->getSettingsMethods();
210
211
        if (in_array($method, $methods)) {
212
            $users = $this->getSettingsRepository();
213
214
            return call_user_func_array([$users, $method], $parameters);
215
        }
216
217
        throw new BadMethodCallException("Call to undefined method {$method}()");
218
    }
219
220
    /**
221
     * Create a log
222
     *
223
     * @param $logMessage
224
     */
225
    public function Log($logMessage)
226
    {
227
        $target = null;
228
229
        if ($user = Sentinel::getUser())
230
            if ($user != null)
231
                $target = $user->id;
232
233
        $log = $this->getLogsRepository()->create(['log' => $logMessage, 'ip' => Request::ip(), 'target' => $target]);
0 ignored issues
show
The method create() does not seem to exist on object<jlourenco\base\Re...LogRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
$log is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
234
    }
235
236
    /**
237
     * Create a log and associates it to a user
238
     *
239
     * @param $logMessage
240
     * @param $userTarget
241
     */
242
    public function TargettedLog($logMessage, $userTarget)
243
    {
244
        $log = $this->getLogsRepository()->create(['log' => $logMessage, 'target' => $userTarget, 'ip' => Request::ip()]);
0 ignored issues
show
The method create() does not seem to exist on object<jlourenco\base\Re...LogRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
$log is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
245
    }
246
247
    public function RegisterVisit()
248
    {
249
        $agent = new Agent();
250
        $browser = $agent->browser();
251
        $version = $agent->version($browser);
252
253
        $platform = $agent->platform();
254
        $pversion = $agent->version($platform);
255
256
        $browserString = $browser . ' version ' . $version . ' | ' . $platform . ' version ' . $pversion;
257
258
259
        $visit = $this->getVisitsRepository()->create(['url' => Request::url(), 'ip' => Request::ip(), 'browser' => $browserString]);
0 ignored issues
show
The method create() does not seem to exist on object<jlourenco\base\Re...itsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
$visit is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
260
    }
261
262
    public function CompleteVisits()
263
    {
264
        $visits = $this->getVisitsRepository()->getUnChecked();
0 ignored issues
show
The method getUnChecked() does not seem to exist on object<jlourenco\base\Re...itsRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
265
266
        foreach ($visits as $visit)
267
        {
268
            $location = GeoIP::getLocation($visit->ip);
269
270
            if (!$location['default'])
271
            {
272
                $visit->isoCode = $location['isoCode'];
273
                $visit->country = $location['country'];
274
                $visit->city = $location['city'];
275
                $visit->state = $location['state'];
276
                $visit->postal_code = $location['postal_code'];
277
                $visit->lat = $location['lat'];
278
                $visit->lon = $location['lon'];
279
                $visit->timezone = $location['timezone'];
280
                $visit->continent = $location['continent'];
281
            }
282
283
            $visit->checked = 1;
284
            $visit->save();
285
        }
286
    }
287
288
}
289