@@ -46,7 +46,7 @@ |
||
| 46 | 46 | */ |
| 47 | 47 | public function register() |
| 48 | 48 | { |
| 49 | - \App::bind('settings', function () { |
|
| 49 | + \App::bind('settings', function() { |
|
| 50 | 50 | return new \App\Settings; |
| 51 | 51 | }); |
| 52 | 52 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | // match the current password for the supplied user id |
| 42 | 42 | Validator::extend( |
| 43 | 43 | 'password', |
| 44 | - function ($attribute, $value, $parameters, $validator) { |
|
| 44 | + function($attribute, $value, $parameters, $validator) { |
|
| 45 | 45 | return Auth::validate([ |
| 46 | 46 | 'user_id' => $parameters[0], |
| 47 | 47 | 'password' => $value, |
@@ -39,18 +39,18 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | return $this->datatables |
| 41 | 41 | ->eloquent($this->query()) |
| 42 | - ->editColumn('device.hostname', function ($log) { |
|
| 42 | + ->editColumn('device.hostname', function($log) { |
|
| 43 | 43 | $hostname = is_null($log->device) ? trans('devices.text.deleted') : $log->device->hostname; |
| 44 | 44 | return '<a href="'.url("devices/".$log->device_id).'">'.$hostname.'</a>'; |
| 45 | 45 | }) |
| 46 | - ->editColumn('rule.name', function ($log) { |
|
| 46 | + ->editColumn('rule.name', function($log) { |
|
| 47 | 47 | if ($log->rule_id) { |
| 48 | 48 | return '<a href="'.url("alerting/rules/".$log->rule_id).'">'.$log->rule->name.'</a>'; |
| 49 | 49 | } else { |
| 50 | 50 | return trans('alerting.general.text.invalid'); |
| 51 | 51 | } |
| 52 | 52 | }) |
| 53 | - ->editColumn('state', function ($log) { |
|
| 53 | + ->editColumn('state', function($log) { |
|
| 54 | 54 | $icon = ''; |
| 55 | 55 | $colour = ''; |
| 56 | 56 | $text = ''; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | return '<b><span class="fa fa-'.$icon.'" style="color:'.$colour.'"></span> '.$text.'</b>'; |
| 79 | 79 | }) |
| 80 | - ->editColumn('time_logged', function ($log) { |
|
| 80 | + ->editColumn('time_logged', function($log) { |
|
| 81 | 81 | return date('Y-m-d H:i:s', $log->time_logged / 1000); |
| 82 | 82 | }) |
| 83 | 83 | ->make(true); |
@@ -46,7 +46,8 @@ discard block |
||
| 46 | 46 | ->editColumn('rule.name', function ($log) { |
| 47 | 47 | if ($log->rule_id) { |
| 48 | 48 | return '<a href="'.url("alerting/rules/".$log->rule_id).'">'.$log->rule->name.'</a>'; |
| 49 | - } else { |
|
| 49 | + } |
|
| 50 | + else { |
|
| 50 | 51 | return trans('alerting.general.text.invalid'); |
| 51 | 52 | } |
| 52 | 53 | }) |
@@ -58,19 +59,23 @@ discard block |
||
| 58 | 59 | $icon = 'check'; |
| 59 | 60 | $colour = 'green'; |
| 60 | 61 | $text = trans('alerting.logs.text.ok'); |
| 61 | - } elseif ($log->state == 1) { |
|
| 62 | + } |
|
| 63 | + elseif ($log->state == 1) { |
|
| 62 | 64 | $icon = 'times'; |
| 63 | 65 | $colour = 'red'; |
| 64 | 66 | $text = trans('alerting.logs.text.fail'); |
| 65 | - } elseif ($log->state == 2) { |
|
| 67 | + } |
|
| 68 | + elseif ($log->state == 2) { |
|
| 66 | 69 | $icon = 'volume-off'; |
| 67 | 70 | $colour = 'lightgrey'; |
| 68 | 71 | $text = trans('alerting.logs.text.ack'); |
| 69 | - } elseif ($log->state == 3) { |
|
| 72 | + } |
|
| 73 | + elseif ($log->state == 3) { |
|
| 70 | 74 | $icon = 'arrow-down'; |
| 71 | 75 | $colour = 'orange'; |
| 72 | 76 | $text = trans('alerting.logs.text.worse'); |
| 73 | - } elseif ($log->state == 4) { |
|
| 77 | + } |
|
| 78 | + elseif ($log->state == 4) { |
|
| 74 | 79 | $icon = 'arrow-up'; |
| 75 | 80 | $colour = 'khaki'; |
| 76 | 81 | $text = trans('alerting.logs.text.better'); |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | @else |
| 50 | 50 | <div class="label label-default">UNKNOWN</div> |
| 51 | 51 | @endif') |
| 52 | - ->editColumn('rule.name', function ($alert) { |
|
| 52 | + ->editColumn('rule.name', function($alert) { |
|
| 53 | 53 | return '<a href="'.url("alerting/rules/".$alert->rule_id).'">'.$alert->rule->name.'</a>'; |
| 54 | 54 | }) |
| 55 | - ->editColumn('device.hostname', function ($alert) { |
|
| 55 | + ->editColumn('device.hostname', function($alert) { |
|
| 56 | 56 | $hostname = is_null($alert->device) ? trans('devices.text.deleted') : $alert->device->hostname; |
| 57 | 57 | return '<a href="'.url("devices/".$alert->device_id).'">'.$hostname.'</a>'; |
| 58 | 58 | }) |
| 59 | - ->addColumn('actions', function ($alert) { |
|
| 59 | + ->addColumn('actions', function($alert) { |
|
| 60 | 60 | if ($alert->state == 2) { |
| 61 | 61 | $btn = "btn-danger"; |
| 62 | 62 | $icon = "volume-off"; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | return '<a id="alerts-ack" data-id="'.$alert->id.'" data-state="'.$alert->state.'" class="btn btn-xs '.$btn.'"><i class="fa fa-'.$icon.' fa-fw"></i></a>'; |
| 68 | 68 | }) |
| 69 | - ->editColumn('rule.severity', function ($alert) { |
|
| 69 | + ->editColumn('rule.severity', function($alert) { |
|
| 70 | 70 | return $alert->rule->severity; |
| 71 | 71 | }) |
| 72 | 72 | ->make(true); |
@@ -60,7 +60,8 @@ |
||
| 60 | 60 | if ($alert->state == 2) { |
| 61 | 61 | $btn = "btn-danger"; |
| 62 | 62 | $icon = "volume-off"; |
| 63 | - } else { |
|
| 63 | + } |
|
| 64 | + else { |
|
| 64 | 65 | $btn = "btn-success"; |
| 65 | 66 | $icon = "volume-up"; |
| 66 | 67 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * Store a newly created resource in storage. |
| 58 | 58 | * |
| 59 | 59 | * @param \Illuminate\Http\Request $request |
| 60 | - * @return \Illuminate\Http\Response |
|
| 60 | + * @return \Illuminate\Http\JsonResponse |
|
| 61 | 61 | */ |
| 62 | 62 | public function store(DeviceGroupRequest $request) |
| 63 | 63 | { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * Display the specified resource. |
| 71 | 71 | * |
| 72 | 72 | * @param int $id |
| 73 | - * @return \Illuminate\Http\Response |
|
| 73 | + * @return \Illuminate\Http\RedirectResponse |
|
| 74 | 74 | */ |
| 75 | 75 | public function show($id) |
| 76 | 76 | { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @param \Illuminate\Http\Request $request |
| 96 | 96 | * @param int $id |
| 97 | - * @return \Illuminate\Http\Response |
|
| 97 | + * @return \Illuminate\Http\JsonResponse |
|
| 98 | 98 | */ |
| 99 | 99 | public function update(DeviceGroupRequest $request, $id) |
| 100 | 100 | { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @param \Illuminate\Http\Request $request |
| 112 | 112 | * @param int $id |
| 113 | - * @return \Illuminate\Http\Response |
|
| 113 | + * @return \Illuminate\Http\JsonResponse |
|
| 114 | 114 | * @throws \Exception |
| 115 | 115 | */ |
| 116 | 116 | public function destroy(AdminOnlyRequest $request, $id) |
@@ -118,7 +118,8 @@ |
||
| 118 | 118 | $group = DeviceGroup::find($id); |
| 119 | 119 | if ($group && $group->delete()) { |
| 120 | 120 | return response()->json(['message' => trans('devices.groups.deleted', ['name' => $group->name])]); |
| 121 | - } else { |
|
| 121 | + } |
|
| 122 | + else { |
|
| 122 | 123 | return response()->json(['message' => trans('devices.groups.deletefailed', ['name' => $group ? $group->name : ""])], 422); |
| 123 | 124 | } |
| 124 | 125 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Store a newly created resource in storage. |
| 44 | 44 | * |
| 45 | 45 | * @param CreateUserRequest $request |
| 46 | - * @return \Illuminate\Http\Response |
|
| 46 | + * @return \Illuminate\Http\JsonResponse |
|
| 47 | 47 | */ |
| 48 | 48 | public function store(CreateUserRequest $request) |
| 49 | 49 | { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * Remove the specified resource from storage. |
| 120 | 120 | * |
| 121 | 121 | * @param int $user_id |
| 122 | - * @return \Illuminate\Http\Response |
|
| 122 | + * @return \Illuminate\Http\JsonResponse |
|
| 123 | 123 | */ |
| 124 | 124 | public function destroy(DeleteUserRequest $request, $user_id) |
| 125 | 125 | { |
@@ -108,7 +108,8 @@ |
||
| 108 | 108 | $user->update($request->all()); |
| 109 | 109 | if ($request->input('update') == 'password') { |
| 110 | 110 | $message = trans('user.text.pwdupdated'); |
| 111 | - } else { |
|
| 111 | + } |
|
| 112 | + else { |
|
| 112 | 113 | $message = trans('user.text.updated', ['username' => $user->username]); |
| 113 | 114 | } |
| 114 | 115 | |
@@ -207,7 +207,7 @@ |
||
| 207 | 207 | * Convert a v1 device group pattern to sql that can be ingested by jQuery-QueryBuilder |
| 208 | 208 | * |
| 209 | 209 | * @param $pattern |
| 210 | - * @return array |
|
| 210 | + * @return string |
|
| 211 | 211 | */ |
| 212 | 212 | private function convertV1Pattern($pattern) |
| 213 | 213 | { |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | foreach (Settings::get('alert.macros.group', []) as $macro => $value) { |
| 175 | - $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex |
|
| 175 | + $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex |
|
| 176 | 176 | if (!str_contains($macro, ' ')) { |
| 177 | 177 | $pattern = str_replace('macros.'.$macro, '('.$value.')', $pattern); |
| 178 | 178 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $sql = $this->pattern; |
| 299 | 299 | |
| 300 | 300 | // fill in parameters |
| 301 | - foreach ((array)$this->params as $value) { |
|
| 301 | + foreach ((array) $this->params as $value) { |
|
| 302 | 302 | if (!is_numeric($value) && !starts_with($value, "'")) { |
| 303 | 303 | $value = "'".$value."'"; |
| 304 | 304 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | $related = $this->getRelation('deviceCountRelation')->first(); |
| 324 | 324 | |
| 325 | 325 | // then return the count directly |
| 326 | - return ($related) ? (int)$related->count : 0; |
|
| 326 | + return ($related) ? (int) $related->count : 0; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -126,7 +126,8 @@ discard block |
||
| 126 | 126 | // can't build sql |
| 127 | 127 | return []; |
| 128 | 128 | } |
| 129 | - } else { |
|
| 129 | + } |
|
| 130 | + else { |
|
| 130 | 131 | $params = $this->params; |
| 131 | 132 | } |
| 132 | 133 | } |
@@ -137,7 +138,8 @@ discard block |
||
| 137 | 138 | $query = null; |
| 138 | 139 | if (count($tables) == 1) { |
| 139 | 140 | $query = DB::table($tables[0])->select('device_id')->distinct(); |
| 140 | - } else { |
|
| 141 | + } |
|
| 142 | + else { |
|
| 141 | 143 | $query = DB::table('devices')->select('devices.device_id')->distinct(); |
| 142 | 144 | |
| 143 | 145 | foreach ($tables as $table) { |
@@ -153,7 +155,8 @@ discard block |
||
| 153 | 155 | // match the device ids |
| 154 | 156 | if (is_null($params)) { |
| 155 | 157 | return $query->whereRaw($statement)->pluck('device_id')->toArray(); |
| 156 | - } else { |
|
| 158 | + } |
|
| 159 | + else { |
|
| 157 | 160 | return $query->whereRaw($statement, $params)->pluck('device_id')->toArray(); |
| 158 | 161 | } |
| 159 | 162 | } |
@@ -181,7 +184,8 @@ discard block |
||
| 181 | 184 | if (str_contains($pattern, 'macros.')) { |
| 182 | 185 | if (++$x < 30) { |
| 183 | 186 | $pattern = self::applyGroupMacros($pattern, $x); |
| 184 | - } else { |
|
| 187 | + } |
|
| 188 | + else { |
|
| 185 | 189 | return false; |
| 186 | 190 | } |
| 187 | 191 | } |
@@ -225,7 +229,8 @@ discard block |
||
| 225 | 229 | if (starts_with($cur, '%')) { |
| 226 | 230 | // table and column or macro |
| 227 | 231 | $out .= substr($cur, 1).' '; |
| 228 | - } elseif (substr($cur, -1) == '~') { |
|
| 232 | + } |
|
| 233 | + elseif (substr($cur, -1) == '~') { |
|
| 229 | 234 | // like operator |
| 230 | 235 | $content = $parts[++$i]; // grab the content so we can format it |
| 231 | 236 | |
@@ -235,14 +240,18 @@ discard block |
||
| 235 | 240 | } |
| 236 | 241 | |
| 237 | 242 | $out .= "LIKE('".$this->convertRegexToLike($content)."') "; |
| 238 | - } elseif ($cur == '&&') { |
|
| 243 | + } |
|
| 244 | + elseif ($cur == '&&') { |
|
| 239 | 245 | $out .= 'AND '; |
| 240 | - } elseif ($cur == '||') { |
|
| 246 | + } |
|
| 247 | + elseif ($cur == '||') { |
|
| 241 | 248 | $out .= 'OR '; |
| 242 | - } elseif (in_array($cur, $ops)) { |
|
| 249 | + } |
|
| 250 | + elseif (in_array($cur, $ops)) { |
|
| 243 | 251 | // pass-through operators |
| 244 | 252 | $out .= $cur.' '; |
| 245 | - } else { |
|
| 253 | + } |
|
| 254 | + else { |
|
| 246 | 255 | // user supplied input |
| 247 | 256 | $out .= "'".trim($cur, '"\'')."' "; // TODO: remove trim, only needed with invalid input |
| 248 | 257 | } |
@@ -273,7 +282,8 @@ discard block |
||
| 273 | 282 | // add ends appropriately |
| 274 | 283 | if ($startAnchor && !$endAnchor) { |
| 275 | 284 | $pattern .= '%'; |
| 276 | - } elseif (!$startAnchor && $endAnchor) { |
|
| 285 | + } |
|
| 286 | + elseif (!$startAnchor && $endAnchor) { |
|
| 277 | 287 | $pattern = '%'.$pattern; |
| 278 | 288 | } |
| 279 | 289 | |
@@ -19,7 +19,8 @@ |
||
| 19 | 19 | if (!Auth::guard($guard)->user()->isAdmin()) { |
| 20 | 20 | if ($request->ajax() || $request->wantsJson()) { |
| 21 | 21 | return response(trans('general.text.unauthorized'), 401); |
| 22 | - } else { |
|
| 22 | + } |
|
| 23 | + else { |
|
| 23 | 24 | //FIXME: Errors not working |
| 24 | 25 | return redirect('/')->withErrors(['msg', trans('general.text.unauthorized')]); |
| 25 | 26 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | if ($this->input('update') == 'password') { |
| 54 | 54 | $user_id = $this->input('user_id'); |
| 55 | 55 | $rules = ['password' => 'required|min:6|max:255', |
| 56 | - 'password_confirmation' => 'required|same:password', |
|
| 56 | + 'password_confirmation' => 'required|same:password', |
|
| 57 | 57 | ]; |
| 58 | 58 | if (!Auth::user()->isAdmin() || Auth::id() == $user_id) { |
| 59 | 59 | $rules['current_password'] = 'required|password:'.$user_id; |
@@ -59,7 +59,8 @@ |
||
| 59 | 59 | $rules['current_password'] = 'required|password:'.$user_id; |
| 60 | 60 | } |
| 61 | 61 | return $rules; |
| 62 | - } else { |
|
| 62 | + } |
|
| 63 | + else { |
|
| 63 | 64 | $user = User::find($this->input('user_id')); |
| 64 | 65 | return ['username' => 'required|max:20|unique:users,username,'.$user->username.',username', |
| 65 | 66 | 'email' => 'required|email|max:60|unique:users,email,'.$user->username.',username', |