Issues (144)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

app/Sensor.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spatie\Activitylog\Traits\LogsActivity;
7
use Illuminate\Support\Facades\Auth;
8
9
class Sensor extends Model 
10
{
11
    use LogsActivity;
12
13
    protected $table = 'sensors';
14
15
    /**
16
     * Update the updated_at and created_at timestamps?
17
     *
18
     * @var array
19
     */
20
    public $timestamps = false;
21
22
    /**
23
     * The attributes that are mass assignable.
24
     *
25
     * @var array
26
     */
27
    protected $fillable = array('device_id', 'name', 'type');
28
29
    /**
30
     * The attributes that are visible.
31
     *
32
     * @var array
33
     */
34
    protected $visible = array('id', 'device_id', 'name', 'type');
35
36
    /**
37
     * The attributes to log in the Activity Log
38
     *
39
     * @var array
40
     */
41
    protected static $logAttributes = array('id', 'device_id', 'name', 'type');
42
43
    /**
44
     * Only log those that have actually changed after the update.
45
     *
46
     * @var array
47
     */
48
    protected static $logOnlyDirty = true;
49
50
    /**
51
     * Get the device associated with the sensor.
52
     */
53
    public function device()
54
    {
55
        return $this->belongsTo('App\Device');
56
    }
57
58
    /**
59
     * Get the sensor data associated with the sensor.
60
     */
61
    public function data()
62
    {
63
        return $this->hasMany('App\SensorData');
64
    }
65
    
66
    /**
67
     * Get the latest sensor data entry associated with the sensor.
68
     */
69
    public function getLatestDataAttribute()
70
    {
71
        return SensorData::whereRaw('id = (SELECT MAX(id)
72
                                                    FROM sensor_data
73
                                                    WHERE sensor_id = ?)', [ $this->id ])->first() ?? (object) [ ];
74
    }
75
    
76
    /**
77
     * Get the last hour's sensor data averaged by the minute for the sensor.
78
     */
79
    public function getLastHourMinutelyAvgDataAttribute()
80
    {
81
        return $this->hasMany('App\SensorData')
82
            ->selectRaw("DATE_FORMAT(created_at, '%Y-%m-%d %H:%i') AS date, AVG(value) AS value")
83
            ->whereRaw("created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)")
84
            ->groupBy("date")
85
            ->get();
86
    }
87
    
88
    /**
89
     * Get the last day's sensor data averaged hourly for the sensor.
90
     */
91
    public function getLastDayHourlyAvgDataAttribute()
92
    {
93
        return $this->hasMany('App\SensorData')
94
            ->selectRaw("DATE_FORMAT(created_at, '%Y-%m-%d %H') AS date, AVG(value) AS value")
95
            ->whereRaw("created_at > DATE_SUB(NOW(), INTERVAL 1 DAY)")
96
            ->groupBy("date")
97
            ->get();
98
    }
99
    
100
    /**
101
     * Get the last weeks's sensor data averaged daily for the sensor.
102
     */
103
    public function getLastWeekDailyAvgDataAttribute()
104
    {
105
        return $this->hasMany('App\SensorData')
106
            ->selectRaw("DATE_FORMAT(created_at, '%Y-%m-%d') AS date, AVG(value) AS value")
107
            ->whereRaw("created_at > DATE_SUB(NOW(), INTERVAL 7 DAY)")
108
            ->groupBy("date")
109
            ->get();
110
    }
111
    
112
    /**
113
     * Get the last months's sensor data averaged daily for the sensor.
114
     */
115
    public function getLastMonthDailyAvgDataAttribute()
116
    {
117
        return $this->hasMany('App\SensorData')
118
            ->selectRaw("DATE_FORMAT(created_at, '%Y-%m-%d') AS date, AVG(value) AS value")
119
            ->whereRaw("created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)")
120
            ->groupBy("date")
121
            ->get();
122
    }
123
    
124
    /**
125
     * Get the last year's sensor data averaged monthly for the sensor.
126
     */
127
    public function getLastYearMonthlyAvgDataAttribute()
128
    {
129
        return $this->hasMany('App\SensorData')
130
            ->selectRaw("DATE_FORMAT(created_at, '%Y-%m') AS date, AVG(value) AS value")
131
            ->whereRaw("created_at > DATE_SUB(NOW(), INTERVAL 1 YEAR)")
132
            ->groupBy("date")
133
            ->get();
134
    }
135
    
136
    /**
137
     * Accessor: Get the sensor's last update time in seconds/minutes/hours since update or converted to user
138
     * friendly readable format.
139
     * If the time is less then a day old then display time since it last updated
140
     * If the time is greater then a day old then display the time in the format of Month day, year 12hour:mins am/pm
141
     * and using the user's preferred timezone
142
     *
143
     *
144
     * @return string
145
     */
146 View Code Duplication
    public function getUpdatedAtHumanAttribute()
147
    {
148
        if ($this->updated_at->diffInDays() > 0) {
0 ignored issues
show
The property updated_at does not seem to exist on App\Sensor. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
149
                    return $this->updated_at->setTimezone(Auth::user()->timezone)->format('M d, Y h:i a');
150
        } else {
151
                    return $this->updated_at->diffForHumans();
152
        }
153
    }
154
    
155
    /**
156
     * Accessor: Get the sensor's creation time in seconds/minutes/hours since update or converted to user
157
     * friendly readable format.
158
     * If the time is less then a day old then display time since creation
159
     * If the time is greater then a day old then display the time in the format of Month day, year 12hour:mins am/pm
160
     * and using the user's preferred timezone
161
     *
162
     *
163
     * @return string
164
     */
165 View Code Duplication
    public function getCreatedAtHumanAttribute()
166
    {
167
        if ($this->created_at->diffInDays() > 0) {
0 ignored issues
show
The property created_at does not seem to exist on App\Sensor. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
168
                    return $this->created_at->setTimezone(Auth::user()->timezone)->format('M d, Y h:i a');
169
        } else {
170
                    return $this->created_at->diffForHumans();
171
        }
172
    }
173
}