diff --git a/.gitignore b/.gitignore index d44a862..550d94e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,10 @@ Thumbs.db *.tmp *.temp +# Local configuration & credentials +config.json +admin/config/admin.json + # No content content/ !content/.gitkeep diff --git a/admin/src/AdminAuth.php b/admin/src/AdminAuth.php index b20b914..48e5e91 100644 --- a/admin/src/AdminAuth.php +++ b/admin/src/AdminAuth.php @@ -20,10 +20,35 @@ class AdminAuth private function loadAdminConfig(): array { $path = $this->config['admin_config']; + $examplePath = dirname($path) . '/admin.json.example'; + if (!file_exists($path)) { - return ['users' => [], 'security' => []]; + if (file_exists($examplePath)) { + @copy($examplePath, $path); + } else { + $defaultAdminConfig = [ + 'users' => [ + [ + 'username' => 'admin', + 'password_hash' => password_hash('admin', PASSWORD_BCRYPT), + 'role' => 'admin', + 'created' => date('Y-m-d'), + ] + ], + 'security' => [ + 'session_timeout' => 1800, + 'max_login_attempts' => 5, + 'lockout_duration' => 900, + ] + ]; + $dir = dirname($path); + if (!is_dir($dir)) { + @mkdir($dir, 0755, true); + } + @file_put_contents($path, json_encode($defaultAdminConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + } } - $data = json_decode(file_get_contents($path), true); + $data = file_exists($path) ? json_decode(file_get_contents($path), true) : null; return is_array($data) ? $data : ['users' => [], 'security' => []]; } diff --git a/admin/templates/layout.php b/admin/templates/layout.php index c092622..1653113 100644 --- a/admin/templates/layout.php +++ b/admin/templates/layout.php @@ -86,6 +86,11 @@ $layoutSidebarColor = $layoutThemeConfig['header_color'] ?? '#0a369d'; Logs +