Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pastefox-share/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# PasteFox Share

Share console logs via [pastefox.com](https://pastefox.com).

## Installation

1. Download and extract to `/var/www/pelican/plugins/pastefox-share`
2. Enable the plugin in Admin → Plugins
3. Add your PasteFox API key to `.env`:

```env
PASTEFOX_API_KEY=pk_your_api_key_here
PASTEFOX_VISIBILITY=PUBLIC
```

Get your API key from https://pastefox.com/dashboard

## Usage

1. Open a server console
2. Click the "Share Logs" button
3. Copy the generated link from the notification

## Configuration

| Variable | Default | Description |
|----------|---------|-------------|
| `PASTEFOX_API_KEY` | - | Your PasteFox API key (required) |
| `PASTEFOX_VISIBILITY` | `PUBLIC` | `PUBLIC` or `PRIVATE` |

## License

MIT
Comment thread
FlexKleks marked this conversation as resolved.
Outdated
10 changes: 10 additions & 0 deletions pastefox-share/lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'share_logs' => 'Share Logs',
'share_file' => 'Share',
Comment thread
FlexKleks marked this conversation as resolved.
'uploaded' => 'Logs uploaded to PasteFox',
'file_uploaded' => 'File uploaded to PasteFox',
'upload_failed' => 'Upload failed',
'api_key_missing' => 'PasteFox API key not configured. Add PASTEFOX_API_KEY to your .env file.',
Comment thread
FlexKleks marked this conversation as resolved.
Outdated
];
15 changes: 15 additions & 0 deletions pastefox-share/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "pastefox-share",
"name": "PasteFox Share",
"author": "FlexKleks",
"version": "1.0.0",
"description": "Share console logs via pastefox.com",
"category": "plugin",
"url": "https://github.com/pelican-dev/plugins/tree/main/pastefox-share",
"update_url": null,
"namespace": "FlexKleks\\PasteFoxShare",
"class": "PasteFoxSharePlugin",
"panels": ["server"],
"panel_version": null,
"composer_packages": null
}
106 changes: 106 additions & 0 deletions pastefox-share/src/Filament/Components/Actions/UploadLogsAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace FlexKleks\PasteFoxShare\Filament\Components\Actions;

use App\Models\Server;
use Exception;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Filament\Support\Enums\Size;
use Illuminate\Support\Facades\Http;

class UploadLogsAction extends Action
{
public static function getDefaultName(): ?string
{
return 'upload_logs_pastefox';
}

protected function setUp(): void
{
parent::setUp();

$this->hidden(function () {
/** @var Server $server */
$server = Filament::getTenant();

return $server->retrieveStatus()->isOffline();
});

$this->label(fn () => trans('pastefox-share::messages.share_logs'));

$this->icon('tabler-share');

$this->color('primary');

$this->size(Size::ExtraLarge);

$this->action(function () {
/** @var Server $server */
$server = Filament::getTenant();

try {
$logs = Http::daemon($server->node)
->get("/api/servers/{$server->uuid}/logs", [
'size' => 5000,
])
->throw()
->json('data');

$logs = is_array($logs) ? implode(PHP_EOL, $logs) : $logs;

$apiKey = env('PASTEFOX_API_KEY');

if (empty($apiKey)) {
Notification::make()
->title(trans('pastefox-share::messages.api_key_missing'))
->danger()
->send();

return;
}

$response = Http::withHeaders([
'X-API-Key' => $apiKey,
'Content-Type' => 'application/json',
])
->timeout(30)
->connectTimeout(5)
->throw()
->post('https://pastefox.com/api/pastes', [
'content' => $logs,
'title' => 'Console Logs: '.$server->name.' - '.now()->format('Y-m-d H:i:s'),
'language' => 'log',
'visibility' => env('PASTEFOX_VISIBILITY', 'PUBLIC'),
])
->json();

if ($response['success']) {
$url = 'https://pastefox.com/'.$response['data']['slug'];

Notification::make()
->title(trans('pastefox-share::messages.uploaded'))
->body($url)
->persistent()
->success()
->send();
} else {
Notification::make()
->title(trans('pastefox-share::messages.upload_failed'))
->body($response['error'] ?? 'Unknown error')
->danger()
->send();
}
Comment thread
FlexKleks marked this conversation as resolved.
} catch (Exception $exception) {
report($exception);

Notification::make()
->title(trans('pastefox-share::messages.upload_failed'))
->body($exception->getMessage())
->danger()
->send();
}
});
}
}
Comment thread
FlexKleks marked this conversation as resolved.
18 changes: 18 additions & 0 deletions pastefox-share/src/PasteFoxSharePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace FlexKleks\PasteFoxShare;

use Filament\Contracts\Plugin;
use Filament\Panel;

class PasteFoxSharePlugin implements Plugin
{
public function getId(): string
{
return 'pastefox-share';
}

public function register(Panel $panel): void {}

public function boot(Panel $panel): void {}
}
18 changes: 18 additions & 0 deletions pastefox-share/src/Providers/PasteFoxSharePluginProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace FlexKleks\PasteFoxShare\Providers;

use App\Enums\HeaderActionPosition;
use App\Filament\Server\Pages\Console;
use FlexKleks\PasteFoxShare\Filament\Components\Actions\UploadLogsAction;
use Illuminate\Support\ServiceProvider;

class PasteFoxSharePluginProvider extends ServiceProvider
{
public function register(): void
{
Console::registerCustomHeaderActions(HeaderActionPosition::Before, UploadLogsAction::make());
}

public function boot(): void {}
}