commit 1d1607e307970300538a5c36c4ccdb8779f082bf Author: NekoMonci12 Date: Sat Apr 26 11:18:20 2025 +0700 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/admin/controller.php b/admin/controller.php new file mode 100644 index 0000000..bf861ea --- /dev/null +++ b/admin/controller.php @@ -0,0 +1,138 @@ +has('save_driver')) { + \Artisan::call('config:clear'); + $driver = $request->input('APP_BACKUP_DRIVER'); + if (!in_array($driver, ['s3', 'wings'])) { + // Use the 'message' variable to pass a message to the view + $message = 'Invalid backup driver selected.'; + return $this->view->make( + 'admin.extensions.{identifier}.index', [ + 'root' => "/admin/extensions/{identifier}", + 'blueprint' => $this->blueprint, + 'message' => $message, // Pass the message to the view + ] + ); + } + + $this->setEnvironmentValue([ + 'APP_BACKUP_DRIVER' => $driver, + ]); + + $message = 'Backup driver updated successfully!'; + } + + // Only validate and save S3-related values if `save_env` was used + if ($request->has('save_env')) { + \Artisan::call('config:clear'); + $endpoint = rtrim($request->input('AWS_ENDPOINT'), '/'); + $validatedUrl = filter_var($endpoint, FILTER_VALIDATE_URL); + + if (!$validatedUrl) { + $message = 'Invalid endpoint URL.'; + return $this->view->make( + 'admin.extensions.{identifier}.index', [ + 'root' => "/admin/extensions/{identifier}", + 'blueprint' => $this->blueprint, + 'message' => $message, + ] + ); + } + + $allowedStorageClasses = ['STANDARD', 'STANDARD_IA', 'GLACIER']; + $storageClass = strtoupper($request->input('AWS_BACKUPS_STORAGE_CLASS')); + + if (!in_array($storageClass, $allowedStorageClasses)) { + $message = 'Invalid storage class selected.'; + return $this->view->make( + 'admin.extensions.{identifier}.index', [ + 'root' => "/admin/extensions/{identifier}", + 'blueprint' => $this->blueprint, + 'message' => $message, + ] + ); + } + + $maxPartSizeGB = min((int) $request->input('BACKUP_MAX_PART_SIZE_GB'), 5); + $maxPartSizeBytes = $maxPartSizeGB * 1024 * 1024 * 1024; + + $this->setEnvironmentValue([ + 'AWS_DEFAULT_REGION' => $request->input('AWS_DEFAULT_REGION'), + 'AWS_ACCESS_KEY_ID' => $request->input('AWS_ACCESS_KEY_ID'), + 'AWS_SECRET_ACCESS_KEY' => $request->input('AWS_SECRET_ACCESS_KEY'), + 'AWS_BACKUPS_BUCKET' => $request->input('AWS_BACKUPS_BUCKET'), + 'AWS_ENDPOINT' => $validatedUrl, + 'AWS_USE_PATH_STYLE_ENDPOINT' => $request->input('AWS_USE_PATH_STYLE_ENDPOINT') === 'true' ? 'true' : 'false', + 'AWS_BACKUPS_STORAGE_CLASS' => $storageClass, + 'BACKUP_MAX_PART_SIZE' => $maxPartSizeBytes, + 'BACKUP_PRESIGNED_URL_LIFESPAN' => (int) $request->input('BACKUP_PRESIGNED_URL_LIFESPAN'), + ]); + + $message = 'Environment variables updated successfully!'; + } + + // Return the view with the message + return $this->view->make( + 'admin.extensions.{identifier}.index', [ + 'root' => "/admin/extensions/{identifier}", + 'blueprint' => $this->blueprint, + 'message' => $message, // Pass the message to the view + ] + ); + } + + + /** + * Handle POST requests by delegating to index(). + */ + public function post(Request $request): View + { + return $this->index($request); + } + + protected function setEnvironmentValue(array $values) + { + $envPath = base_path('.env'); + $envContent = File::get($envPath); + + foreach ($values as $key => $value) { + // If the key already exists, replace it with the new value. + $pattern = "/^$key=.*$/m"; + $replacement = $key . '=' . $value; + + if (preg_match($pattern, $envContent)) { + // If the key exists, replace the line. + $envContent = preg_replace($pattern, $replacement, $envContent); + } else { + // If the key doesn't exist, append it to the end of the file. + $envContent .= "\n$replacement"; + } + } + + // Write the updated content back to the .env file. + File::put($envPath, $envContent); + } +} diff --git a/admin/view.blade.php b/admin/view.blade.php new file mode 100644 index 0000000..64d1864 --- /dev/null +++ b/admin/view.blade.php @@ -0,0 +1,109 @@ + +
+
+

Information

+
+
+

+ An Extension For Managing S3 Storage Credentials. +

+
+
+ +
+
+

Backup Driver

+
+
+
+ @csrf + +
+ + +
+ +
+ +
+
+
+
+ +
+
+

Management

+
+
+ + @if(isset($message) && $message) +
+ {{ $message }} +
+ @endif +
+ @csrf + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
diff --git a/conf.yml b/conf.yml new file mode 100644 index 0000000..e472573 --- /dev/null +++ b/conf.yml @@ -0,0 +1,37 @@ +info: + name: "S3 Manager" + identifier: "s3manager" + description: "Setup S3 Bucket For Backups System" + flags: "" + version: "1.0.0" + target: "beta-2024-12" + author: "nekomonci12" + icon: "public/S3Manager.png" + website: "" + +admin: + view: "admin/view.blade.php" + controller: "admin/controller.php" + css: "" + wrapper: "" + +dashboard: + css: "" + wrapper: "" + components: "" + +data: + directory: "" + public: "" + console: "" + +requests: + views: "" + app: "" + routers: + application: "" + client: "" + web: "" + +database: + migrations: "" diff --git a/public/S3Manager.png b/public/S3Manager.png new file mode 100644 index 0000000..61150f0 Binary files /dev/null and b/public/S3Manager.png differ