|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filament\Resources\ServiceProccessResource\Pages; |
| 4 | + |
| 5 | +use App\Filament\Resources\ServiceProccessResource; |
| 6 | +use Filament\Resources\Pages\Concerns\InteractsWithRecord; |
| 7 | +use Filament\Resources\Pages\Page; |
| 8 | +use Livewire\Attributes\On; |
| 9 | + |
| 10 | +class ServiceDetails extends Page |
| 11 | +{ |
| 12 | + use InteractsWithRecord; |
| 13 | + |
| 14 | + protected static string $resource = ServiceProccessResource::class; |
| 15 | + |
| 16 | + protected static string $view = 'filament.resources.service-proccess-resource.pages.service-details'; |
| 17 | + |
| 18 | + public object $commandSource; |
| 19 | + |
| 20 | + public array $commandSOurceList = [ |
| 21 | + 'bash' => [ |
| 22 | + 'name' => "Bash", |
| 23 | + 'fullname' => "Bourne-Again SHell", |
| 24 | + 'image' => "/icons/bash.svg", |
| 25 | + 'isDefault' => true, |
| 26 | + 'commands' => null |
| 27 | + ], |
| 28 | + 'php' => [ |
| 29 | + 'name' => "PHP", |
| 30 | + 'fullname' => "PHP: Hypertext Preprocessor", |
| 31 | + 'image' => "/icons/php.svg", |
| 32 | + 'isDefault' => false, |
| 33 | + 'commands' => ['php'] |
| 34 | + ], |
| 35 | + 'python' => [ |
| 36 | + 'name' => "Python", |
| 37 | + 'fullname' => "Python", |
| 38 | + 'image' => "/icons/python.svg", |
| 39 | + 'isDefault' => false, |
| 40 | + 'commands' => ['python', 'python2', 'python3', 'pip', 'py'] |
| 41 | + |
| 42 | + ], |
| 43 | + 'laravel' => [ |
| 44 | + 'name' => "Laravel", |
| 45 | + 'fullname' => "Laravel", |
| 46 | + 'image' => "/icons/laravel.svg", |
| 47 | + 'isDefault' => false, |
| 48 | + 'commands' => ['artisan'] |
| 49 | + |
| 50 | + ], |
| 51 | + 'nodejs' => [ |
| 52 | + 'name' => "NodeJs", |
| 53 | + 'fullname' => "NodeJs", |
| 54 | + 'image' => "/icons/node-js.svg", |
| 55 | + 'isDefault' => false, |
| 56 | + 'commands' => ['node', 'npm', 'npx'] |
| 57 | + ], |
| 58 | + 'java' => [ |
| 59 | + 'name' => "Java", |
| 60 | + 'fullname' => "Java enviroment", |
| 61 | + 'image' => "/icons/java-original.svg", |
| 62 | + 'isDefault' => false, |
| 63 | + 'commands' => ['java', 'javac'] |
| 64 | + ], |
| 65 | + 'git' => [ |
| 66 | + 'name' => "Git", |
| 67 | + 'fullname' => "Git", |
| 68 | + 'image' => "/icons/git.svg", |
| 69 | + 'isDefault' => false, |
| 70 | + 'commands' => ['git'] |
| 71 | + ], |
| 72 | + 'golang' => [ |
| 73 | + 'name' => "Go", |
| 74 | + 'fullname' => "Go Lang", |
| 75 | + 'image' => "/icons/golang.svg", |
| 76 | + 'isDefault' => false, |
| 77 | + 'commands' => ['go'] |
| 78 | + ], |
| 79 | + 'rust' => [ |
| 80 | + 'name' => "Rust", |
| 81 | + 'fullname' => "Rust", |
| 82 | + 'image' => "/icons/rust.svg", |
| 83 | + 'isDefault' => false, |
| 84 | + 'commands' => ['cargo', 'rustc'] |
| 85 | + ], |
| 86 | + 'docker' => [ |
| 87 | + 'name' => "Docker", |
| 88 | + 'fullname' => "Docker", |
| 89 | + 'image' => "/icons/docker.svg", |
| 90 | + 'isDefault' => false, |
| 91 | + 'commands' => ['docker'] |
| 92 | + ], |
| 93 | + ]; |
| 94 | + |
| 95 | + private static function determineSoftware($command) { |
| 96 | + // Define a list of patterns and corresponding software |
| 97 | + $patterns = [ |
| 98 | + 'bash' => '/^(ls|cd|mv|cp|rm|echo|cat|grep|find|chmod|chown|mkdir|rmdir|touch|sudo|apt|yum|\.\/)/', |
| 99 | + 'laravel' => '/^php artisan/', |
| 100 | + 'php' => '/^php( |$)/', |
| 101 | + 'python' => '/^python[0-9]* /', |
| 102 | + 'nodejs' => '/^(node|npm|npx) /', |
| 103 | + 'ruby' => '/^(ruby|rails|rake|gem) /', |
| 104 | + 'java' => '/^(java|javac) /', |
| 105 | + 'golang' => '/^(go) /', |
| 106 | + 'rust' => '/^(cargo|rustc) /', |
| 107 | + 'docker' => '/^(docker|docker-compose) /', |
| 108 | + 'git' => '/^git /', |
| 109 | + 'composer' => '/^composer /', |
| 110 | + 'make' => '/^make /', |
| 111 | + 'perl' => '/^perl /', |
| 112 | + 'curl' => '/^curl /', |
| 113 | + 'wget' => '/^wget /', |
| 114 | + 'powershell' => '/^(powershell|pwsh) /', |
| 115 | + 'ansible' => '/^ansible /', |
| 116 | + 'terraform' => '/^terraform /', |
| 117 | + ]; |
| 118 | + |
| 119 | + // Iterate over the patterns and return the corresponding software if a match is found |
| 120 | + foreach ($patterns as $software => $pattern) { |
| 121 | + if (preg_match($pattern, $command)) { |
| 122 | + return $software; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + // Return 'unknown' if no pattern matches |
| 127 | + return 'bash'; |
| 128 | + } |
| 129 | + |
| 130 | + public function mount(int | string $record): void |
| 131 | + { |
| 132 | + $this->record = $this->resolveRecord($record); |
| 133 | + $this->dispatch('page-process-details', record: $this->record); |
| 134 | + } |
| 135 | + |
| 136 | + #[On('determine-command-type')] |
| 137 | + public function DetermineCommandType(string $command) |
| 138 | + { |
| 139 | + // dd($command); |
| 140 | + $type = static::determineSoftware($command); |
| 141 | + // dd($type); |
| 142 | + $this->commandSource = (object)$this->commandSOurceList[$type]; |
| 143 | + } |
| 144 | +} |
0 commit comments