-
Notifications
You must be signed in to change notification settings - Fork 23
Add PasteFox Share plugin #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fcadc95
Add PasteFox Share plugin
FlexKleks 86e45fa
Add update URL and update.json for pastefox-share
FlexKleks a2e2a80
Remove auto-update, set update_url to null
FlexKleks e63f698
Add admin settings page in sidebar
FlexKleks b1684fb
Add optional API key, effects, password, theme settings
FlexKleks 941e842
Fix lint: remove unused imports and whitespace
FlexKleks 4e5f3a1
Sync plugin settings modal with admin page settings
FlexKleks 58166f8
Fix indentation
FlexKleks 44e6071
Add Server Folders plugin
FlexKleks 8a8d480
Update Server Folders & PasteFox Share
FlexKleks 2bb3502
Add role-based folder sharing to Server Folders
FlexKleks 9278497
Fix lint errors in Server Folders
FlexKleks 4fbebdd
PasteFox Share: Use HasPluginSettings instead of separate page
FlexKleks 6e8a927
Remove server-folders (will be separate PR)
FlexKleks 7bba610
Update pastefox-share/src/PasteFoxSharePlugin.php
FlexKleks 81c95b3
Update pastefox-share/src/Filament/Components/Actions/UploadLogsActio…
FlexKleks f691b6b
Fix indentation in UploadLogsAction.php
FlexKleks d8daef7
Fix indentation and update .env reference in messages
FlexKleks f08fce2
Add translations for settings page, update README and plugin URL
FlexKleks 6ab97d1
cleanup readme
Boy132 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # PasteFox Share | ||
|
|
||
| Share console logs via [pastefox.com](https://pastefox.com) with one click. | ||
|
|
||
| ## Features | ||
|
|
||
| - One-click log sharing from server console | ||
| - Configurable visibility (PUBLIC/PRIVATE) | ||
| - Fetches up to 5000 log lines | ||
| - Admin settings page in sidebar | ||
|
|
||
| ## Installation | ||
|
|
||
| 1. Download and extract to `/var/www/pelican/plugins/pastefox-share` | ||
| 2. Run `php artisan p:plugin:install` | ||
| 3. Configure in Admin → Advanced → PasteFox | ||
|
|
||
| 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 | ||
|
|
||
| ## Coming Soon | ||
|
|
||
| - File sharing | ||
| - Custom domains | ||
| - Folders | ||
| - Syntax highlighting themes | ||
|
|
||
| ## License | ||
|
|
||
| MIT | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'api_key' => env('PASTEFOX_API_KEY'), | ||
| 'visibility' => env('PASTEFOX_VISIBILITY', 'PUBLIC'), | ||
| 'effect' => env('PASTEFOX_EFFECT', 'NONE'), | ||
| 'theme' => env('PASTEFOX_THEME', 'dark'), | ||
| 'password' => env('PASTEFOX_PASSWORD'), | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'share_logs' => 'Share Logs', | ||
| 'share_file' => 'Share', | ||
FlexKleks marked this conversation as resolved.
Show resolved
Hide 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.', | ||
FlexKleks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'expires_7_days' => '⚠️ Without API key, paste expires in 7 days', | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/FlexKleks/PelicanPasteFox", | ||
| "update_url": null, | ||
| "namespace": "FlexKleks\\PasteFoxShare", | ||
| "class": "PasteFoxSharePlugin", | ||
| "panels": ["admin", "server"], | ||
| "panel_version": null, | ||
| "composer_packages": null | ||
| } |
156 changes: 156 additions & 0 deletions
156
pastefox-share/src/Filament/Admin/Pages/PasteFoxSettings.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| <?php | ||
FlexKleks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace FlexKleks\PasteFoxShare\Filament\Admin\Pages; | ||
|
|
||
| use App\Traits\EnvironmentWriterTrait; | ||
FlexKleks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| use Filament\Actions\Action; | ||
| use Filament\Forms\Components\Select; | ||
| use Filament\Forms\Components\TextInput; | ||
| use Filament\Forms\Components\Toggle; | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| use Filament\Forms\Concerns\InteractsWithForms; | ||
| use Filament\Notifications\Notification; | ||
| use Filament\Pages\Concerns\InteractsWithFormActions; | ||
| use Filament\Pages\Page; | ||
| use Filament\Schemas\Components\Component; | ||
| use Filament\Schemas\Components\Section; | ||
| use Filament\Schemas\Components\Utilities\Get; | ||
| use Filament\Schemas\Schema; | ||
|
|
||
| /** | ||
| * @property Schema $form | ||
| */ | ||
| class PasteFoxSettings extends Page | ||
| { | ||
| use EnvironmentWriterTrait; | ||
| use InteractsWithFormActions; | ||
| use InteractsWithForms; | ||
|
|
||
| protected static string|\BackedEnum|null $navigationIcon = 'tabler-share'; | ||
|
|
||
| protected string $view = 'filament.server.pages.server-form-page'; | ||
|
|
||
| /** @var array<mixed>|null */ | ||
| public ?array $data = []; | ||
|
|
||
| public function getTitle(): string | ||
| { | ||
| return 'PasteFox Settings'; | ||
| } | ||
|
|
||
| public static function getNavigationLabel(): string | ||
| { | ||
| return 'PasteFox'; | ||
| } | ||
|
|
||
| public static function getNavigationGroup(): ?string | ||
| { | ||
| return trans('admin/dashboard.advanced'); | ||
| } | ||
|
|
||
| public function mount(): void | ||
| { | ||
| $this->form->fill([ | ||
| 'api_key' => config('pastefox-share.api_key'), | ||
| 'visibility' => config('pastefox-share.visibility', 'PUBLIC'), | ||
| 'effect' => config('pastefox-share.effect', 'NONE'), | ||
| 'password' => config('pastefox-share.password'), | ||
| 'theme' => config('pastefox-share.theme', 'dark'), | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @return Component[] | ||
| */ | ||
| public function getFormSchema(): array | ||
| { | ||
| return [ | ||
| Section::make('API Configuration') | ||
| ->description('Without API key, pastes expire after 7 days and are always public.') | ||
| ->schema([ | ||
| TextInput::make('api_key') | ||
| ->label('API Key') | ||
| ->password() | ||
| ->revealable() | ||
| ->helperText('Optional - Get your API key from https://pastefox.com/dashboard'), | ||
| ]), | ||
|
|
||
| Section::make('Paste Settings') | ||
| ->schema([ | ||
| Select::make('visibility') | ||
| ->label('Visibility') | ||
| ->options([ | ||
| 'PUBLIC' => 'Public', | ||
| 'PRIVATE' => 'Private (requires API key)', | ||
| ]) | ||
| ->default('PUBLIC') | ||
| ->helperText('Private pastes require an API key'), | ||
|
|
||
| Select::make('effect') | ||
| ->label('Visual Effect') | ||
| ->options([ | ||
| 'NONE' => 'None', | ||
| 'MATRIX' => 'Matrix Rain', | ||
| 'GLITCH' => 'Glitch', | ||
| 'CONFETTI' => 'Confetti', | ||
| 'SCRATCH' => 'Scratch Card', | ||
| 'PUZZLE' => 'Puzzle Reveal', | ||
| 'SLOTS' => 'Slot Machine', | ||
| 'SHAKE' => 'Shake', | ||
| 'FIREWORKS' => 'Fireworks', | ||
| 'TYPEWRITER' => 'Typewriter', | ||
| 'BLUR' => 'Blur Reveal', | ||
| ]) | ||
| ->default('NONE'), | ||
|
|
||
| Select::make('theme') | ||
| ->label('Theme') | ||
| ->options([ | ||
| 'dark' => 'Dark', | ||
| 'light' => 'Light', | ||
| ]) | ||
| ->default('dark'), | ||
|
|
||
| TextInput::make('password') | ||
| ->label('Password Protection') | ||
| ->password() | ||
| ->revealable() | ||
| ->minLength(4) | ||
| ->maxLength(100) | ||
| ->helperText('Optional - 4-100 characters'), | ||
| ]), | ||
| ]; | ||
| } | ||
FlexKleks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| protected function getFormStatePath(): ?string | ||
| { | ||
| return 'data'; | ||
| } | ||
|
|
||
| protected function getHeaderActions(): array | ||
| { | ||
| return [ | ||
| Action::make('save') | ||
| ->label(trans('filament-panels::resources/pages/edit-record.form.actions.save.label')) | ||
| ->action('save') | ||
| ->keyBindings(['mod+s']), | ||
| ]; | ||
| } | ||
|
|
||
| public function save(): void | ||
| { | ||
| $data = $this->form->getState(); | ||
|
|
||
| $this->writeToEnvironment([ | ||
| 'PASTEFOX_API_KEY' => $data['api_key'] ?? '', | ||
| 'PASTEFOX_VISIBILITY' => $data['visibility'] ?? 'PUBLIC', | ||
| 'PASTEFOX_EFFECT' => $data['effect'] ?? 'NONE', | ||
| 'PASTEFOX_THEME' => $data['theme'] ?? 'dark', | ||
| 'PASTEFOX_PASSWORD' => $data['password'] ?? '', | ||
| ]); | ||
|
|
||
| Notification::make() | ||
| ->title('Settings saved') | ||
| ->success() | ||
| ->send(); | ||
| } | ||
FlexKleks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
122 changes: 122 additions & 0 deletions
122
pastefox-share/src/Filament/Components/Actions/UploadLogsAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| <?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 = config('pastefox-share.api_key'); | ||
| $hasApiKey = !empty($apiKey); | ||
|
|
||
| // Build request payload | ||
| $payload = [ | ||
| 'content' => $logs, | ||
| 'title' => 'Console Logs: '.$server->name.' - '.now()->format('Y-m-d H:i:s'), | ||
| 'language' => 'log', | ||
| 'effect' => config('pastefox-share.effect', 'NONE'), | ||
| 'theme' => config('pastefox-share.theme', 'dark'), | ||
| ]; | ||
|
|
||
| // Only add these options if API key is present | ||
| if ($hasApiKey) { | ||
| $payload['visibility'] = config('pastefox-share.visibility', 'PUBLIC'); | ||
|
|
||
| $password = config('pastefox-share.password'); | ||
| if (!empty($password)) { | ||
| $payload['password'] = $password; | ||
| } | ||
| } | ||
|
|
||
| // Build HTTP request | ||
| $request = Http::withHeaders(['Content-Type' => 'application/json']) | ||
| ->timeout(30) | ||
| ->connectTimeout(5); | ||
|
|
||
| // Add API key header if available | ||
| if ($hasApiKey) { | ||
| $request = $request->withHeaders(['X-API-Key' => $apiKey]); | ||
| } | ||
|
|
||
| $response = $request | ||
| ->throw() | ||
| ->post('https://pastefox.com/api/pastes', $payload) | ||
| ->json(); | ||
|
|
||
| if ($response['success']) { | ||
| $url = 'https://pastefox.com/'.$response['data']['slug']; | ||
|
|
||
| $body = $url; | ||
| if (!$hasApiKey) { | ||
| $body .= "\n" . trans('pastefox-share::messages.expires_7_days'); | ||
| } | ||
|
|
||
| Notification::make() | ||
| ->title(trans('pastefox-share::messages.uploaded')) | ||
| ->body($body) | ||
| ->persistent() | ||
| ->success() | ||
| ->send(); | ||
| } else { | ||
| Notification::make() | ||
| ->title(trans('pastefox-share::messages.upload_failed')) | ||
| ->body($response['error'] ?? 'Unknown error') | ||
| ->danger() | ||
| ->send(); | ||
| } | ||
| } catch (Exception $exception) { | ||
| report($exception); | ||
|
|
||
| Notification::make() | ||
| ->title(trans('pastefox-share::messages.upload_failed')) | ||
| ->body($exception->getMessage()) | ||
| ->danger() | ||
| ->send(); | ||
| } | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.