55 lines
2.1 KiB
PHP
55 lines
2.1 KiB
PHP
<?php
|
|
// OPUS5 CRM AUDIT - volumes live + history compare + root cause
|
|
header('Content-Type: application/json');
|
|
$R = ['ts'=>date('c'), 'tables'=>[], 'api_endpoints'=>[], 'front_sources'=>[]];
|
|
|
|
$tables = [
|
|
'admin.pipeline_deals', 'admin.pipeline_contacts', 'admin.pipeline_companies',
|
|
'admin.pipeline_activities', 'admin.pipeline_enrichments', 'admin.pipeline_state',
|
|
'admin.crm_leads', 'admin.crm_contacts', 'admin.crm_stats_by_isp',
|
|
'admin.office_accounts', 'admin.send_contacts',
|
|
'public.weval_leads', 'public.linkedin_profiles',
|
|
'ethica.medecins_real'
|
|
];
|
|
|
|
foreach ($tables as $t) {
|
|
$start = microtime(true);
|
|
$cmd = "timeout 8 env PGPASSWORD=admin123 psql -h 10.1.0.3 -U admin -d adx_system -tAc 'SELECT COUNT(*) FROM $t' 2>&1";
|
|
$out = @shell_exec($cmd);
|
|
$ms = round((microtime(true) - $start) * 1000);
|
|
$count = trim((string)$out);
|
|
$R['tables'][$t] = [
|
|
'count' => is_numeric($count) ? (int)$count : $count,
|
|
'ms' => $ms
|
|
];
|
|
}
|
|
|
|
// What API endpoints does the CRM front consume?
|
|
$crm_html = @file_get_contents('/var/www/html/crm.html');
|
|
if ($crm_html) {
|
|
preg_match_all('#fetch\(["\']([^"\']+/api/[^"\']+)["\']#', $crm_html, $m);
|
|
$R['front_sources']['crm.html'] = array_unique($m[1] ?? []);
|
|
}
|
|
|
|
// Check pipeline APIs (usually in admin or api/)
|
|
$pipe_apis = glob('/var/www/html/api/pipeline-*.php') ?: [];
|
|
$pipe_apis = array_merge($pipe_apis, glob('/var/www/html/api/crm-*.php') ?: []);
|
|
$R['api_endpoints']['files'] = array_map(fn($p) => basename($p), $pipe_apis);
|
|
|
|
// Test one pipeline API
|
|
foreach (['pipeline-deals.php', 'pipeline-api.php', 'crm-api.php', 'crm-deals.php'] as $api) {
|
|
if (file_exists("/var/www/html/api/$api")) {
|
|
$ch = curl_init("http://127.0.0.1/api/$api");
|
|
curl_setopt_array($ch, [CURLOPT_TIMEOUT=>5, CURLOPT_RETURNTRANSFER=>true]);
|
|
$resp = curl_exec($ch);
|
|
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
$R['api_endpoints']['tests'][$api] = [
|
|
'http' => $http,
|
|
'body_preview' => substr((string)$resp, 0, 200)
|
|
];
|
|
}
|
|
}
|
|
|
|
echo json_encode($R, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
|