403Webshell
Server IP : 138.197.107.151  /  Your IP : 216.73.217.7
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux BloxBy-Builder 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User : wpbetasites_mrakzqskir ( 1022)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/silversharkdev/app/Console/Commands/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/silversharkdev/app/Console/Commands/AttachDomainsCommand.php
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Website;
use Symfony\Component\Process\Process;
use Illuminate\Support\Facades\Cache;

class AttachDomainsCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:attach-domains-command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Attach domains for websites in new/pending state, rotating in batches of 5';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        //
        $lastProcessedId = Cache::get('domain_attach_last_id', 0);

        // Pick up to 5 new or pending websites after last processed
        $websites = Website::whereIn('domain_status', ['pending'])
            ->where('id', '>', $lastProcessedId)
            ->where('domain','!=',null)
            ->orderBy('id', 'asc')
            ->limit(5)
            ->get();
        
        if ($websites->isEmpty()) {
            $websites = Website::whereIn('domain_status', ['new', 'pending'])
                ->orderBy('id', 'asc')
                ->limit(5)
                ->get();

            $lastProcessedId = 0;
        }
        if ($websites->isEmpty()) {
            //$this->info("No new or pending domains found.");
            return true;
        }
        foreach ($websites as $website) {

            $domain = $website->domain;

            $website->domain_status = "inprogress";
            $website->domain_error = null;
            $website->save();

            
            $ip = gethostbyname($domain);

            
            if (!$ip || $ip !== env("SERVER_IP")) {
                $website->domain_status = "pending";
                $website->domain_error  = "Domain not pointed yet or still propagating.";
                $website->save();                
                $lastProcessedId = $website->id;
                continue;
            }

            // Step 2: Run attach script
            $server_meta = json_decode($website->server_meta, true);

            $process = new Process([
                'sudo',
                '/var/bloxbycommands/attach_domain.sh',
                $server_meta["domain"].".". \config('app.SITE_DOMAIN'),
                $domain,
                "/var/www/".$server_meta["folder"]."/".$server_meta["sftp_user"]."/public_html"
            ]);

            $process->setTimeout(300);
            $process->run();

            $output = trim($process->getOutput());
            $exitCode = $process->getExitCode();
            $errorOutput = trim($process->getErrorOutput());

            if ($exitCode === 0) {
                $website->domain_status = "completed";
                $website->domain_error  = null;
                $website->save();

                
            } else {
                $website->domain_status = "error";
                $website->domain_error  = $errorOutput ?: $output ?: "Unknown error";
                $website->save();

            }

            $lastProcessedId = $website->id;
        }

        // Save last processed ID for next run
        Cache::put('domain_attach_last_id', $lastProcessedId, now()->addHours(1));

        return true;

    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit