2022-11-28 14:54:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2022-12-06 09:35:57 +00:00
|
|
|
use App\Exceptions\EmqxSupportException;
|
2022-11-28 14:54:00 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2023-01-19 15:09:01 +00:00
|
|
|
use App\Jobs\Support\EMQXKickClientJob;
|
2022-11-28 14:54:00 +00:00
|
|
|
use App\Support\EmqxSupport;
|
2023-01-10 13:42:27 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2022-11-28 14:54:00 +00:00
|
|
|
use Illuminate\Http\Request;
|
2023-01-10 13:42:27 +00:00
|
|
|
use Illuminate\View\View;
|
2022-11-28 14:54:00 +00:00
|
|
|
|
|
|
|
class DeviceController extends Controller
|
|
|
|
{
|
2023-01-10 13:42:27 +00:00
|
|
|
public function index(Request $request): RedirectResponse|View
|
2022-11-28 14:54:00 +00:00
|
|
|
{
|
|
|
|
$emqx = new EmqxSupport();
|
|
|
|
|
2022-12-06 09:35:57 +00:00
|
|
|
try {
|
|
|
|
$clients = $emqx->clients([
|
2023-01-10 13:42:27 +00:00
|
|
|
'clientid' => $request->input('client_id'),
|
|
|
|
'username' => $request->input('username'),
|
|
|
|
'page' => $request->input('page'),
|
2022-12-06 09:35:57 +00:00
|
|
|
]);
|
2023-01-10 13:42:27 +00:00
|
|
|
} catch (EmqxSupportException $e) {
|
2022-12-06 09:35:57 +00:00
|
|
|
return back()->with('error', $e->getMessage());
|
|
|
|
}
|
2022-11-28 14:54:00 +00:00
|
|
|
|
|
|
|
return view('admin.device.index', compact('clients'));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// public function show(Request $request, $client_id)
|
|
|
|
// {
|
|
|
|
// $emqx = new EmqxSupport();
|
|
|
|
//
|
|
|
|
// $client = $emqx->clients(['clientid' => $client_id]);
|
|
|
|
//
|
|
|
|
// return view('admin.device.show', compact('client'));
|
|
|
|
// }
|
|
|
|
|
2023-01-19 15:09:01 +00:00
|
|
|
public function destroy(Request $request): RedirectResponse
|
2022-11-28 14:54:00 +00:00
|
|
|
{
|
|
|
|
$emqx = new EmqxSupport();
|
|
|
|
|
2023-01-19 15:09:01 +00:00
|
|
|
if ($request->filled('client_id')) {
|
|
|
|
$emqx->kickClient($request->input('client_id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('username')) {
|
|
|
|
$username = $request->input('username');
|
|
|
|
$module_name = explode('.', $username)[0];
|
|
|
|
|
|
|
|
$this->dispatch(new EMQXKickClientJob(null, $module_name, false));
|
|
|
|
$this->dispatch(new EMQXKickClientJob(null, $module_name . '.', true));
|
|
|
|
}
|
2022-11-28 14:54:00 +00:00
|
|
|
|
2023-01-19 15:09:01 +00:00
|
|
|
return back()->with('success', '正在让它们下线。');
|
2022-11-28 14:54:00 +00:00
|
|
|
}
|
|
|
|
}
|