Update source into github

This commit is contained in:
pbao9
2025-07-24 16:18:27 +07:00
parent 41419358dd
commit 69851ac7bc
2642 changed files with 284095 additions and 0 deletions
+183
View File
@@ -0,0 +1,183 @@
<?php
namespace App\Jobs\Hosting;
use App\Events\NotificationStatus;
use App\Http\Facade\SignRSA;
use App\Http\Facade\HelperFacade as Helper;
use App\Http\Services\Hosting;
use App\Http\Services\PusherNotification;
use App\Http\Services\Telegram;
use App\Jobs\Mail\SendInformationHosting;
use App\Models\ModuleHosting;
use App\Models\ModuleHostingServer;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CreateHostingJobs implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected int $product;
protected $server;
protected $telegram;
protected $push;
public int $tries = 1;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($product = 0)
{
$this->product = $product;
$this->server = new Hosting;
$this->push = new PusherNotification;
$this->telegram = new Telegram;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$product = ModuleHosting::with([
"Customer",
"Server"
])->find($this->product);
if (! $product)
{
throw new \Exception("Can't find product");
}
if (! $product->Server)
{
throw new \Exception('Invalid request.');
}
$this->server->url = $product->Server->name;
if ($product->Server->apikey)
{
$this->server->apiKey = $product->Server->apikey;
}
$ClientUser = $this->server->CheckUserClient($product->Customer);
if ($ClientUser === "Login_Again")
{
$this->server->username = $product->Server->user;
$this->server->password = SignRSA::DecryptFunc($product->Server->password);
$AuthLogin = $this->server->LoginServer();
if ($AuthLogin['error'])
{
throw new \Exception("You have entered incorrect username or password.");
}
$this->server->apiKey = $AuthLogin['data']['key'];
ModuleHostingServer::where('id',$product->Server->id)->update(['apikey' => $AuthLogin['data']['key']]);
$ClientUser = $this->server->CheckUserClient($product->Customer);
}
$PasswordHosting = Helper::general_password();
if ($ClientUser['error'] === true)
{
$ClientUser = $this->server->CreateNewClient($product,$PasswordHosting);
}
if ($ClientUser['error'] === true)
{
throw new \Exception(json_encode($ClientUser['data']));
}
$pleskUser = [];
if (array_key_exists(0,$ClientUser['data']))
{
$pleskUser = $ClientUser['data'][0];
$pleskUser['password'] = $ClientUser['data']['password'];
} else
{
$pleskUser = $ClientUser['data'];
}
$ExitsDomain = $this->server->CheckDomainExit($pleskUser['id'],$product->name);
if ($ExitsDomain['error'])
{
throw new \Exception(json_encode($ExitsDomain['data']));
}
$CreatedDomain = $this->server->CreateNewDomain($product,$product->name,$pleskUser,$PasswordHosting);
if ($CreatedDomain['error'] === true)
{
throw new \Exception(json_encode($CreatedDomain['data']));
}
$CreateDateExp = $this->server->CreateExpirationForDomain($product->name,Carbon::parse($product->next_due_date)->format("Y-m-d"));
if ($CreateDateExp['error'] === true) {
throw new \Exception(json_encode($CreateDateExp['data']));
}
$product->update([
'username' => $product->Customer->email,
'password' => SignRSA::EncryptFunc($pleskUser['password']),
'status' => 1,
'server_domain_id' => $CreatedDomain['data']['id']
]);
ModuleHostingServer::where('id',$product->Server->id)
->update(['counter' => $product->Server->counter + 1]);
$setting = Setting::where('key','setting')->first();
$data = [
'company_name' => json_decode($setting->value)->company,
'company_logo' => json_decode($setting->value)->logo,
'client_name' => $product->Customer->firstname . " " . $product->Customer->lastname,
'product_name' => $product->GetInvoiceItem()->GetItemProduct()->name,
'product_billing' => Helper::BillingCycle($product->GetInvoiceItem()->billing),
'product_price' => number_format($product->GetInvoiceItem()->amount,0,',','.'),
'service_host' => $product->Server->name,
'service_username' => $product->Customer->email,
'service_password' => $pleskUser['password'],
'service_due_exp' => Carbon::parse($product->next_due_date)->format('d/m/Y'),
'ftp_password' => $pleskUser['password'],
'ftp_account' => $product->name,
];
$mail = new SendInformationHosting($data,$product->Customer);
dispatch($mail)->delay(now()->addSeconds(5));
Event(new NotificationStatus("Created new Domain For Server #". $product->Server->name . " success",true));
}
public function failed(\Throwable $exception): void
{
Event(new NotificationStatus("Notification: " .$exception->getMessage() ,false));
$this->telegram->SendErrorMessage($exception->getMessage());
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php
namespace App\Jobs\Hosting;
use App\Http\Facade\SignRSA;
use App\Http\Services\Hosting;
use App\Models\ModuleHosting;
use App\Models\ModuleHostingServer;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Throwable;
class HostingJobs implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected int $product;
protected string $action;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($product = 0, $action = '')
{
$this->product = $product;
$this->action = $action;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Hosting $hosting)
{
trans();
$product = ModuleHosting::with('Server', 'Customer')->find($this->product);
if (!$product) {
throw new \Exception("Can't find product");
}
if (!$product->Server) {
throw new \Exception('Invalid request.');
}
$hosting->url = $product->Server->name;
if ($product->Server->apikey) {
$hosting->apiKey = $product->Server->apikey;
}
if ($product->Server->apikey) {
$hosting->apiKey = $product->Server->apikey;
}
$ClientUser = $hosting->CheckUserClient($product->Customer);
if ($ClientUser === "Login_Again") {
$hosting->username = $product->Server->user;
$hosting->password = SignRSA::DecryptFunc($product->Server->password);
$AuthLogin = $hosting->LoginServer();
if ($AuthLogin['error']) {
throw new \Exception("You have entered incorrect username or password.");
}
$hosting->apiKey = $AuthLogin['data']['key'];
ModuleHostingServer::where('id', $product->Server->id)->update(['apikey' => $AuthLogin['data']['key']]);
$ClientUser = $hosting->CheckUserClient($product->Customer);
}
if ($ClientUser['error'] === true) {
throw new \Exception('Invalid request.');
}
$statusAction = null;
switch ($this->action) {
case "Suspend":
$statusAction = $hosting->SuspendAccount($ClientUser['data']['0']['id']);
break;
case "Activate":
$statusAction = $hosting->ActivateAccount($ClientUser['data']['0']['id']);
break;
default:
break;
}
if (isset($statusAction['error'])) {
throw new \Exception($statusAction['data']);
}
}
public function failed(Throwable $exception): void
{
Log::channel('Custom')->info("\r\n");
Log::channel('Custom')->info("=================================");
Log::channel('Custom')->info("Thông báo lỗi lúc: " .Carbon::now());
Log::channel('Custom')->info($exception->getMessage());
Log::channel('Custom')->info("=================================");
}
}