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/Http/Controllers/DashboardController.php (6 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Gate;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Http\Request;
8
use App\Device;
9
use App\Site;
10
use App\Location;
11
use Carbon\Carbon;
12
13
class DashboardController extends Controller
14
{
15
    /**
16
     * Create a new controller instance.
17
     *
18
     */
19
    public function __construct()
20
    {
21
        $this->middleware('auth');
22
    }
23
24
    /**
25
     * Show the application dashboard.
26
     *
27
     * @param  Request  $request
28
     * @return \Illuminate\Http\Response||\Illuminate\Http\JsonResponse
29
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment \Illuminate\Http\Respons...inate\Http\JsonResponse at position 2 could not be parsed: Unknown type name '|' at position 2 in \Illuminate\Http\Response||\Illuminate\Http\JsonResponse.
Loading history...
30
    public function index(Request $request)
31
    {
32 View Code Duplication
        if (Gate::denies('index-dashboard'))
0 ignored issues
show
This code seems to be duplicated across 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...
33
        {
34
            if (\Request::ajax()) {
35
                return response()->json("Please contact [email protected] to request access.", 403);
36
            } else {
37
                return redirect()->route('home')
38
                    ->with('failure', 'Please contact [email protected] to request access.');
39
            }
40
        }
41
        
42
        $request->validate([
43
            'site_id' => 'sometimes|required|integer|digits_between:1,10',
44
            'location_id' => 'sometimes|required|integer|digits_between:1,10',
45
            'device_id' => 'sometimes|required|integer|digits_between:1,10',
46
            'page' => 'sometimes|required|integer|digits_between:1,10',
47
        ]);
48
    
49
        if (count($request->all()) == 0)
50
        {
51
            //Get the device, location, and site ids based on the user's preferred device
52
            $device = Auth::user()->preferredDevice ?? null;
53
            $location = $device->location ?? null;
54
            
55
            //If the location exists then set the pagination page to be where the device is located
56
            if ($location != null)
57
                $request->merge([ 'page' => $device->dashPageNum(4) ]);
0 ignored issues
show
The method dashPageNum() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
                $request->merge([ 'page' => $device->/** @scrutinizer ignore-call */ dashPageNum(4) ]);

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...
58
            $site_id = $location->site_id ?? 0;
59
            $location_id = $location->id ?? 0;
60
            $device_id = $device->id ?? 0;
61
        }
62
        else
63
        {
64
            //Get the active site, location, and device ids
65
            $site_id = $request->site_id ?? 0;
66
            $location_id = $request->location_id ?? 0;
67
            $device_id = $request->device_id ?? 0;
68
        }
69
    
70
        //Get all sites with the selected site first
71
        $sites = Site::select('id', 'name')
72
            ->orderByRaw("id = ? DESC", $site_id)
0 ignored issues
show
It seems like $site_id can also be of type integer; however, parameter $bindings of Illuminate\Database\Query\Builder::orderByRaw() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
            ->orderByRaw("id = ? DESC", /** @scrutinizer ignore-type */ $site_id)
Loading history...
73
            ->orderBy('name', 'ASC')
74
            ->get();
75
        //Get all locations for the selected site with the selected location first
76
        $locations = Location::select('id', 'name', 'site_id')
77
            ->where('site_id', '=', $sites[ 0 ]->id ?? 0)
78
            ->orderByRaw("id = ? DESC", $location_id)
79
            ->orderBy('name', 'ASC')
80
            ->get();
81
        //Get all devices for the selected location
82
        $devices = Device::publicDashData()
83
            ->leftJoin('deviceimages as image', 'devices.id', '=', 'image.device_id')
84
            ->where('location_id', '=', $locations[ 0 ]->id ?? 0)
85
            ->orderBy('name', 'ASC')
86
            ->paginate(4);
87
    
88
        //Set the active device to the device defined by the given device id
89
        $active_device = $devices->where('id', $device_id)->first();
90
        
91
        //Check if there were devices found
92
        if (!$devices->isEmpty())
93
        {
94
            //If the original device with the given device id was not found
95
            //Then assign the the first device in the device list as the active device
96
            if ($active_device == null)
97
                $active_device = $devices[ 0 ];
98
        
99
            //Add an attribute to each device defining if it is stale
100
            $devices->transform(function($item)
101
            {
102
                //Mark the device as stale if the device has missed three updates plus a minute
103
                $deviceStaleMins = ceil(($item->update_rate * 3) / 60) + 1;
104
                $item[ 'isDeviceStale' ] = ($item->last_network_update_at <= Carbon::now()->subMinute($deviceStaleMins)) ? true : false;
0 ignored issues
show
$deviceStaleMins of type double is incompatible with the type integer expected by parameter $value of Carbon\Carbon::subMinute(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
                $item[ 'isDeviceStale' ] = ($item->last_network_update_at <= Carbon::now()->subMinute(/** @scrutinizer ignore-type */ $deviceStaleMins)) ? true : false;
Loading history...
105
    
106
                //Mark the device image as stale if the device has missed three image updates plus a minute
107
                if ($item->image_updated_at != null)
108
                {
109
                    $imageStaleMins = ceil(($item->image_rate * 3) / 60) + 1;
110
                    $item[ 'isImageStale' ] = ($item->image_updated_at <= Carbon::now()->subMinute($imageStaleMins)) ? true : false;
111
                }
112
                else
113
                    $item[ 'isImageStale' ] = false;
114
                
115
                return $item;
116
            });
117
        }
118
    
119
        //Store the active site, location, and device in a collection
120
        $active_data = collect([ 'device' => $active_device, 'location' => $locations[ 0 ] ?? null, 'site' => $sites[ 0 ] ?? null ]);
121
    
122
        //Use the device_list.blade.php to generate the device table html
123
        $html_device_table = view('dashboard.device_list', [ 'devices' => $devices, 'active_data' => $active_data ])->render();
124
        
125
        if (\Request::ajax()) {
126
                    return response()->json([ 'active_data' => $active_data, 'devices' => $devices, 'locations' => $locations,
127
                'sites' => $sites, 'html_device_table' => $html_device_table ]);
128
        } else {
129
                    return view('dashboard.index', [ 'active_data' => $active_data, 'devices' => $devices,
130
                'locations' => $locations, 'sites' => $sites ]);
131
        }
132
    }
133
    
134
    /**
135
     * Show the development layouts for dashboard.
136
     *
137
     * @return \Illuminate\Http\Response
138
     */
139
    public function dev_layout()
140
    {
141
        return view('dashboard.dev_layout');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('dashboard.dev_layout') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
142
    }
143
}
144