@@ -25,7 +25,6 @@ |
||
| 25 | 25 | |
| 26 | 26 | namespace App\DataTables; |
| 27 | 27 | |
| 28 | -use App\Models\DeviceGroup; |
|
| 29 | 28 | use App\Models\Device; |
| 30 | 29 | |
| 31 | 30 | class DeviceDataTable extends BaseDataTable |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace App\Http\Controllers; |
| 4 | 4 | |
| 5 | 5 | use App\DataTables\DeviceDataTable; |
| 6 | -use App\DataTables\DeviceGroupDataTable; |
|
| 7 | 6 | use App\Models\DeviceGroup; |
| 8 | 7 | use Dingo\Api\Http; |
| 9 | 8 | use Dingo\Api\Routing\Helpers; |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | * |
| 19 | 19 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
| 20 | 20 | */ |
| 21 | - public function index(DeviceDataTable $dataTable, $group_id=-1) |
|
| 21 | + public function index(DeviceDataTable $dataTable, $group_id = -1) |
|
| 22 | 22 | { |
| 23 | 23 | $group_name = ""; |
| 24 | - if($group_id >= 0) { |
|
| 24 | + if ($group_id >= 0) { |
|
| 25 | 25 | $dataTable->addScope(new \App\DataTables\Scopes\DeviceGroup($group_id)); |
| 26 | 26 | $group_name = DeviceGroup::find($group_id)->name; |
| 27 | 27 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * Store a newly created resource in storage. |
| 59 | 59 | * |
| 60 | 60 | * @param \Illuminate\Http\Request $request |
| 61 | - * @return \Illuminate\Http\Response |
|
| 61 | + * @return \Illuminate\Http\JsonResponse |
|
| 62 | 62 | */ |
| 63 | 63 | public function store(DeviceGroupRequest $request) |
| 64 | 64 | { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * Display the specified resource. |
| 72 | 72 | * |
| 73 | 73 | * @param int $id |
| 74 | - * @return \Illuminate\Http\Response |
|
| 74 | + * @return \Illuminate\Http\RedirectResponse |
|
| 75 | 75 | */ |
| 76 | 76 | public function show($id) |
| 77 | 77 | { |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @param \Illuminate\Http\Request $request |
| 97 | 97 | * @param int $id |
| 98 | - * @return \Illuminate\Http\Response |
|
| 98 | + * @return \Illuminate\Http\JsonResponse |
|
| 99 | 99 | */ |
| 100 | 100 | public function update(DeviceGroupRequest $request, $id) |
| 101 | 101 | { |
@@ -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) |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace App\Api\Controllers; |
| 4 | 4 | |
| 5 | 5 | use DB; |
| 6 | -use App\Http\Requests; |
|
| 7 | 6 | use Illuminate\Http\Request; |
| 8 | 7 | |
| 9 | 8 | class ApiController extends Controller |
@@ -195,7 +195,8 @@ |
||
| 195 | 195 | $user = \Auth::user(); |
| 196 | 196 | if (!is_null($user) && $user->isAdmin()) { |
| 197 | 197 | return false; |
| 198 | - } else { |
|
| 198 | + } |
|
| 199 | + else { |
|
| 199 | 200 | return 'auth'; |
| 200 | 201 | } |
| 201 | 202 | } |
@@ -203,7 +203,7 @@ |
||
| 203 | 203 | * Convert a v1 device group pattern to v2 style |
| 204 | 204 | * |
| 205 | 205 | * @param $pattern |
| 206 | - * @return array |
|
| 206 | + * @return string |
|
| 207 | 207 | */ |
| 208 | 208 | private function convertV1Pattern($pattern) |
| 209 | 209 | { |
@@ -177,7 +177,7 @@ |
||
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | foreach (Settings::get('alert.macros.group', []) as $macro => $value) { |
| 180 | - $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex |
|
| 180 | + $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex |
|
| 181 | 181 | if (!str_contains($macro, ' ')) { |
| 182 | 182 | $pattern = str_replace('macros.'.$macro, '('.$value.')', $pattern); |
| 183 | 183 | } |
@@ -145,7 +145,8 @@ discard block |
||
| 145 | 145 | $query = null; |
| 146 | 146 | if (count($tables) == 1) { |
| 147 | 147 | $query = DB::table($tables[0])->select('device_id'); |
| 148 | - } else { |
|
| 148 | + } |
|
| 149 | + else { |
|
| 149 | 150 | $query = DB::table('devices')->select('devices.device_id')->distinct(); |
| 150 | 151 | |
| 151 | 152 | foreach ($tables as $table) { |
@@ -186,7 +187,8 @@ discard block |
||
| 186 | 187 | if (str_contains($pattern, 'macros.')) { |
| 187 | 188 | if (++$x < 30) { |
| 188 | 189 | $pattern = self::applyGroupMacros($pattern, $x); |
| 189 | - } else { |
|
| 190 | + } |
|
| 191 | + else { |
|
| 190 | 192 | return false; |
| 191 | 193 | } |
| 192 | 194 | } |
@@ -253,14 +255,16 @@ discard block |
||
| 253 | 255 | if (starts_with($cur, '%')) { |
| 254 | 256 | // table and column or macro |
| 255 | 257 | $out .= substr($cur, 1).' '; |
| 256 | - } elseif (substr($cur, -1) == '~') { |
|
| 258 | + } |
|
| 259 | + elseif (substr($cur, -1) == '~') { |
|
| 257 | 260 | // like operator |
| 258 | 261 | $content = $parts[++$i]; // grab the content so we can format it |
| 259 | 262 | |
| 260 | 263 | if (str_contains($content, '@')) { |
| 261 | 264 | // contains wildcard |
| 262 | 265 | $content = str_replace('@', '%', $content); |
| 263 | - } else { |
|
| 266 | + } |
|
| 267 | + else { |
|
| 264 | 268 | // assume substring |
| 265 | 269 | $content = '%'.$content.'%'; |
| 266 | 270 | } |
@@ -272,14 +276,18 @@ discard block |
||
| 272 | 276 | |
| 273 | 277 | $out .= "LIKE('".$content."') "; |
| 274 | 278 | |
| 275 | - } elseif ($cur == '&&') { |
|
| 279 | + } |
|
| 280 | + elseif ($cur == '&&') { |
|
| 276 | 281 | $out .= 'AND '; |
| 277 | - } elseif ($cur == '||') { |
|
| 282 | + } |
|
| 283 | + elseif ($cur == '||') { |
|
| 278 | 284 | $out .= 'OR '; |
| 279 | - } elseif (in_array($cur, $ops)) { |
|
| 285 | + } |
|
| 286 | + elseif (in_array($cur, $ops)) { |
|
| 280 | 287 | // pass-through operators |
| 281 | 288 | $out .= $cur.' '; |
| 282 | - } else { |
|
| 289 | + } |
|
| 290 | + else { |
|
| 283 | 291 | // user supplied input |
| 284 | 292 | $out .= "'".trim($cur, '"\'')."' "; // TODO: remove trim, only needed with invalid input |
| 285 | 293 | } |
@@ -38,6 +38,9 @@ |
||
| 38 | 38 | return json_encode(self::generateMacroFilter('alert.macros.rule', self::generateTableFilter())); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | + /** |
|
| 42 | + * @param string $setting |
|
| 43 | + */ |
|
| 41 | 44 | private static function generateMacroFilter($setting, $filter = []) |
| 42 | 45 | { |
| 43 | 46 | foreach (Settings::get($setting, []) as $key => $value) { |