Premier commit

This commit is contained in:
jeremy bayse
2026-02-09 11:27:21 +01:00
commit 89a369964d
114 changed files with 17837 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Console\Commands;
use App\Models\Contract;
use App\Models\User;
use App\Mail\ContractExpiringNotification;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Log;
class SendContractAlerts extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'contracts:check-expirations';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check for expiring contracts and notify admins';
/**
* Execute the console command.
*/
public function handle()
{
$this->info('Checking for expiring contracts...');
$expiringContracts = Contract::where('status', '!=', 'expired') // Assuming 'active' or 'pending'
->where('end_date', '<=', now()->addDays(30))
->where('end_date', '>=', now())
->get();
if ($expiringContracts->isEmpty()) {
$this->info('No contracts expiring soon.');
return;
}
$admins = User::where('role', 'admin')->get();
if ($admins->isEmpty()) {
$this->warn('No admins found to notify.');
return;
}
foreach ($admins as $admin) {
// In a real app, you might group these or send one email per contract/batch
// Here we just simulate sending a notification for the batch
// Or send individual emails
// Simplification: Send one email with list
try {
Mail::to($admin->email)->send(new ContractExpiringNotification($expiringContracts));
$this->info("Notification sent to {$admin->email}");
} catch (\Exception $e) {
$this->error("Failed to send email to {$admin->email}: " . $e->getMessage());
Log::error($e);
}
}
$this->info('Done.');
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Console\Commands;
use App\Services\CortexXdrService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
class TestCortexConnection extends Command
{
protected $signature = 'cortex:test';
protected $description = 'Test connectivity to Cortex XDR API and display results.';
public function handle(CortexXdrService $cortexService)
{
$this->info("--- Cortex XDR Connectivity Test ---");
// 1. Config Check
$key = Config::get('services.cortex.key');
$id = Config::get('services.cortex.id');
$url = Config::get('services.cortex.url');
$this->line("\n1. Checking Environment Variables:");
$this->line(" - API Key: " . ($key ? 'OK (' . substr($key, 0, 5) . '...)' : 'MISSING'));
$this->line(" - API Key ID: " . ($id ? 'OK (' . $id . ')' : 'MISSING'));
$this->line(" - Base URL: " . ($url ? 'OK (' . $url . ')' : 'MISSING'));
if (!$key || !$id || !$url) {
$this->error("\n[ERROR] Configuration is incomplete.");
$this->line("You need to add the following variables to your .env file:");
if (!$key) $this->line(" - CORTEX_XDR_API_KEY=your_api_key");
if (!$id) $this->line(" - CORTEX_XDR_API_KEY_ID=your_key_id (Integer ID)");
if (!$url) $this->line(" - CORTEX_XDR_BASE_URL=https://api-fqdn.xdr.cortex.paloaltonetworks.com");
$this->warn("\nIMPORTANT: After editing .env, you may need to restart 'php artisan serve' for the web app to see changes.");
return 1;
}
// 2. Test Incidents
$this->info("\n2. Testing API Connection (Incidents)...");
try {
$incidents = $cortexService->getIncidents();
if (empty($incidents)) {
$this->warn("No incidents returned. (This might be normal if no incidents exist, or check API permissions).");
} else {
$this->info("SUCCESS: Fetched " . count($incidents) . " incidents.");
if (count($incidents) > 0) {
$this->line("DEBUG: First Incident ID: " . ($incidents[0]['incident_id'] ?? 'N/A'));
$this->line("DEBUG: Incident keys: " . print_r(array_keys($incidents[0]), true));
$this->line("DEBUG: Incident values: " . print_r(array_values($incidents[0]), true));
}
$this->line("Latest Incident ID: " . ($incidents[0]['incident_id'] ?? 'N/A'));
}
} catch (\Exception $e) {
$this->error("EXCEPTION: " . $e->getMessage());
}
// 3. Test Endpoints
$this->info("\n3. Testing API Connection (Endpoints)...");
try {
$endpoints = $cortexService->getEndpoints();
if (empty($endpoints)) {
$this->warn("No endpoints returned.");
} else {
$this->info("SUCCESS: Fetched " . count($endpoints) . " endpoints.");
if (count($endpoints) > 0) {
$ep = $endpoints[0];
$this->line("DEBUG: First Endpoint Status key: 'endpoint_status' => " . ($ep['endpoint_status'] ?? 'N/A'));
$this->line("DEBUG: Keys available: " . print_r(array_keys($ep), true));
$this->line("DEBUG: First Endpoint Status key: 'endpoint_status' => " . ($ep['endpoint_status'] ?? 'N/A'));
}
}
} catch (\Exception $e) {
$this->error("EXCEPTION: " . $e->getMessage());
}
return 0;
}
}