diff --git a/public/assets/img/icon-192.png b/public/assets/img/icon-192.png new file mode 100644 index 0000000..60d8238 Binary files /dev/null and b/public/assets/img/icon-192.png differ diff --git a/public/assets/img/icon-512.png b/public/assets/img/icon-512.png new file mode 100644 index 0000000..a8acbfd Binary files /dev/null and b/public/assets/img/icon-512.png differ diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..2ff7373 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,26 @@ +{ + "name": "ServerManager", + "short_name": "SM", + "description": "Linux Server Management Platform", + "start_url": "/dashboard", + "display": "standalone", + "background_color": "#0f1117", + "theme_color": "#6366f1", + "categories": ["productivity", "utilities"], + "lang": "en", + "orientation": "any", + "icons": [ + { + "src": "/assets/img/icon-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any maskable" + }, + { + "src": "/assets/img/icon-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any maskable" + } + ] +} diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..f6fda07 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,71 @@ +const CACHE = 'sm-v1'; +const STATIC_ASSETS = [ + '/assets/css/style.css', + '/assets/js/app.js', + '/assets/js/main.js', + '/assets/img/server.svg', + '/assets/img/icon-192.png', + '/assets/img/icon-512.png', + '/manifest.json', + '/offline', +]; + +self.addEventListener('install', function(e) { + e.waitUntil( + caches.open(CACHE).then(function(cache) { + return cache.addAll(STATIC_ASSETS); + }).then(function() { + return self.skipWaiting(); + }) + ); +}); + +self.addEventListener('activate', function(e) { + e.waitUntil( + caches.keys().then(function(keys) { + return Promise.all( + keys.filter(function(k) { return k !== CACHE; }).map(function(k) { return caches.delete(k); }) + ); + }).then(function() { + return self.clients.claim(); + }) + ); +}); + +self.addEventListener('fetch', function(e) { + var url = new URL(e.request.url); + + if (url.pathname.startsWith('/api/')) { + return; + } + + if ( + url.pathname.startsWith('/assets/') || + url.pathname === '/manifest.json' + ) { + e.respondWith( + caches.open(CACHE).then(function(cache) { + return cache.match(e.request).then(function(cached) { + var fetchPromise = fetch(e.request).then(function(response) { + cache.put(e.request, response.clone()); + return response; + }); + return cached || fetchPromise; + }); + }) + ); + return; + } + + e.respondWith( + fetch(e.request).catch(function() { + return caches.match(e.request).then(function(cached) { + if (cached) return cached; + if (e.request.mode === 'navigate') { + return caches.match('/offline'); + } + return new Response('Offline', { status: 503 }); + }); + }) + ); +}); diff --git a/routes/web.php b/routes/web.php index c813489..ce1921d 100755 --- a/routes/web.php +++ b/routes/web.php @@ -27,6 +27,11 @@ $router->get('/notifications', [DashboardController::class, 'notifications'], [A $router->get('/privacy', [DashboardController::class, 'privacy']); $router->get('/terms', [DashboardController::class, 'terms']); +$router->get('/offline', function () { + $view = \ServerManager\Core\App::getInstance()->getView(); + $view->display('errors.offline', ['title' => 'Offline']); +}); + $router->get('/login', [AuthController::class, 'loginForm']); $router->post('/login', [AuthController::class, 'login'], [CSRFMiddleware::class, RateLimitMiddleware::class]); $router->get('/register', [AuthController::class, 'registerForm']); diff --git a/views/errors/offline.php b/views/errors/offline.php new file mode 100644 index 0000000..a555f8f --- /dev/null +++ b/views/errors/offline.php @@ -0,0 +1,21 @@ + + + + + + Offline — ServerManager + + + +
+
📡
+

You're Offline

+

ServerManager needs an internet connection to manage your servers.
Check your connection and try again.

+
+ + Retry + +
+
+ + diff --git a/views/layouts/auth.php b/views/layouts/auth.php index d14013b..9b92c52 100755 --- a/views/layouts/auth.php +++ b/views/layouts/auth.php @@ -5,6 +5,8 @@ <?= htmlspecialchars($title ?? 'ServerManager') ?> + + diff --git a/views/layouts/main.php b/views/layouts/main.php index ceb4611..c62d367 100755 --- a/views/layouts/main.php +++ b/views/layouts/main.php @@ -21,6 +21,11 @@ if (!isset($user) || $user === null) { + + + + + @@ -225,5 +230,10 @@ if (!isset($user) || $user === null) { +