Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b29f55518 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "dashboard/unifi",
|
"name": "dashboard/unifi",
|
||||||
"description": "UniFi network management, WiFi stats, and captive portal authentication for the Dashboard platform",
|
"description": "UniFi network management, WiFi stats, and captive portal authentication for the Dashboard platform",
|
||||||
"version": "1.6.1",
|
"version": "1.6.2",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ class RotatePasswords extends Command
|
|||||||
|
|
||||||
if ($rotated) {
|
if ($rotated) {
|
||||||
Setting::set('unifi.password_rotation.last_rotated_at', now()->toIso8601String());
|
Setting::set('unifi.password_rotation.last_rotated_at', now()->toIso8601String());
|
||||||
|
// Persist the active password so it can be displayed in
|
||||||
|
// the Settings page and exposed via the API endpoint.
|
||||||
|
Setting::set('unifi.password_rotation.last_password', $password);
|
||||||
$this->info('Rotated password for ' . count($rotated) . ' SSID(s).');
|
$this->info('Rotated password for ' . count($rotated) . ' SSID(s).');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,25 @@ class UnifiSettingsController extends Controller
|
|||||||
'rotationMinute' => (int) Setting::get('unifi.password_rotation.minute', 0),
|
'rotationMinute' => (int) Setting::get('unifi.password_rotation.minute', 0),
|
||||||
'rotationWordlist' => Setting::get('unifi.password_rotation.wordlist', ''),
|
'rotationWordlist' => Setting::get('unifi.password_rotation.wordlist', ''),
|
||||||
'rotationLastRotatedAt' => Setting::get('unifi.password_rotation.last_rotated_at', null),
|
'rotationLastRotatedAt' => Setting::get('unifi.password_rotation.last_rotated_at', null),
|
||||||
|
'rotationLastPassword' => Setting::get('unifi.password_rotation.last_password', null),
|
||||||
'ppskSchedulingEnabled' => (bool) Setting::get('unifi.ppsk_scheduling.enabled', false),
|
'ppskSchedulingEnabled' => (bool) Setting::get('unifi.ppsk_scheduling.enabled', false),
|
||||||
|
'apiToken' => Setting::get('unifi.api_token', null),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function regenerateApiToken()
|
||||||
|
{
|
||||||
|
$token = bin2hex(random_bytes(24));
|
||||||
|
Setting::set('unifi.api_token', $token);
|
||||||
|
return response()->json(['token' => $token]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearApiToken()
|
||||||
|
{
|
||||||
|
Setting::set('unifi.api_token', '');
|
||||||
|
return response()->json(['ok' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
public function update(Request $request)
|
public function update(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|||||||
40
src/Http/Controllers/WifiApiController.php
Normal file
40
src/Http/Controllers/WifiApiController.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Dashboard\Unifi\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token-protected JSON endpoints for external integrations (signage,
|
||||||
|
* kiosks, room displays, etc.) that need the current rotating WiFi
|
||||||
|
* password without going through the dashboard UI.
|
||||||
|
*/
|
||||||
|
class WifiApiController extends Controller
|
||||||
|
{
|
||||||
|
public function currentPassword(Request $request)
|
||||||
|
{
|
||||||
|
$expected = Setting::get('unifi.api_token');
|
||||||
|
if (! $expected) {
|
||||||
|
return response()->json(['error' => 'API token not configured'], 503);
|
||||||
|
}
|
||||||
|
|
||||||
|
$provided = $request->bearerToken() ?: $request->query('token');
|
||||||
|
if (! $provided || ! hash_equals($expected, $provided)) {
|
||||||
|
return response()->json(['error' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
$password = Setting::get('unifi.password_rotation.last_password');
|
||||||
|
if (! $password) {
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'No rotated password recorded yet — wait for the next scheduled rotation or run unifi:rotate-passwords --force.',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'password' => $password,
|
||||||
|
'rotated_at' => Setting::get('unifi.password_rotation.last_rotated_at'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ use Dashboard\Unifi\Http\Controllers\UnifiPagesAccessController;
|
|||||||
use Dashboard\Unifi\Http\Controllers\UnifiSettingsController;
|
use Dashboard\Unifi\Http\Controllers\UnifiSettingsController;
|
||||||
use Dashboard\Unifi\Http\Controllers\VlanGroupController;
|
use Dashboard\Unifi\Http\Controllers\VlanGroupController;
|
||||||
use Dashboard\Unifi\Http\Controllers\WebhookController;
|
use Dashboard\Unifi\Http\Controllers\WebhookController;
|
||||||
|
use Dashboard\Unifi\Http\Controllers\WifiApiController;
|
||||||
use Dashboard\Unifi\Http\Controllers\WifiController;
|
use Dashboard\Unifi\Http\Controllers\WifiController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
@@ -90,9 +91,20 @@ Route::middleware(['web', 'auth', 'app.access:unifi'])
|
|||||||
Route::delete('/settings/webhooks/{webhook}', [WebhookController::class, 'destroy'])->name('webhooks.destroy');
|
Route::delete('/settings/webhooks/{webhook}', [WebhookController::class, 'destroy'])->name('webhooks.destroy');
|
||||||
Route::post('/settings/webhooks/{webhook}/test', [WebhookController::class, 'test']) ->name('webhooks.test');
|
Route::post('/settings/webhooks/{webhook}/test', [WebhookController::class, 'test']) ->name('webhooks.test');
|
||||||
Route::post('/settings/webhooks/test-url', [WebhookController::class, 'testUrl'])->name('webhooks.test-url');
|
Route::post('/settings/webhooks/test-url', [WebhookController::class, 'testUrl'])->name('webhooks.test-url');
|
||||||
|
|
||||||
|
// API-token management
|
||||||
|
Route::post('/settings/api-token/regenerate', [UnifiSettingsController::class, 'regenerateApiToken'])->name('settings.api-token.regenerate');
|
||||||
|
Route::delete('/settings/api-token', [UnifiSettingsController::class, 'clearApiToken']) ->name('settings.api-token.clear');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ── Public API (token-protected) ──────────────────────────────────────────
|
||||||
|
// External integrations (signage, kiosks) hit these without session auth.
|
||||||
|
Route::prefix('api/unifi')->name('unifi.api.')->group(function () {
|
||||||
|
Route::get('/wifi/current-password', [WifiApiController::class, 'currentPassword'])
|
||||||
|
->name('wifi.current-password');
|
||||||
|
});
|
||||||
|
|
||||||
// ── Captive portal callback (public — user redirected here by UniFi) ─────
|
// ── Captive portal callback (public — user redirected here by UniFi) ─────
|
||||||
Route::middleware(['web', 'auth'])
|
Route::middleware(['web', 'auth'])
|
||||||
->get('/portal/wifi/callback', [PortalController::class, 'captiveCallback'])
|
->get('/portal/wifi/callback', [PortalController::class, 'captiveCallback'])
|
||||||
|
|||||||
Reference in New Issue
Block a user