This commit is contained in:
2026-02-19 11:45:25 +01:00
parent a8caee15f9
commit c718f15f09
9 changed files with 129 additions and 239 deletions

View File

@@ -187,39 +187,102 @@ function checkRateLimit($ip) {
function sendToWebhook($data, $webhookUrl = null) {
$url = $webhookUrl ?? WEBHOOK_URL;
$jsonData = json_encode($data);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'User-Agent: Profice-Web-API/2.0'
],
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false, // Disable SSL verification for n8n connection
CURLOPT_SSL_VERIFYHOST => false, // Disable host verification
CURLOPT_FOLLOWLOCATION => true
]);
// Log the attempt
error_log("Webhook attempt - URL: " . $url . " - Data length: " . strlen($jsonData));
// Try cURL first if available
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $jsonData,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json',
'User-Agent: Profice-Web-API/2.0'
],
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
$errno = curl_errno($ch);
curl_close($ch);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
$errno = curl_errno($ch);
curl_close($ch);
if ($error) {
error_log("Webhook Error [$errno]: " . $error . " - URL: " . $url);
return ['success' => false, 'error' => $error, 'errno' => $errno, 'response' => $response];
error_log("Webhook cURL response - HTTP: $httpCode, Error: $error, Response: " . substr($response, 0, 500));
if (!$error && $httpCode > 0) {
return [
'success' => $httpCode >= 200 && $httpCode < 300,
'http_code' => $httpCode,
'response' => $response,
'error' => $error,
'method' => 'curl'
];
}
error_log("Webhook cURL failed [$errno]: $error - trying file_get_contents fallback");
}
// Fallback to file_get_contents if cURL fails or unavailable
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\nAccept: application/json\r\nUser-Agent: Profice-Web-API/2.0\r\n",
'content' => $jsonData,
'timeout' => 30,
'ignore_errors' => true
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$response = @file_get_contents($url, false, $context);
// Get HTTP response code from headers
$httpCode = 0;
if (isset($http_response_header) && is_array($http_response_header)) {
foreach ($http_response_header as $header) {
if (preg_match('/^HTTP\/\d+\.?\d*\s+(\d+)/', $header, $matches)) {
$httpCode = (int)$matches[1];
}
}
}
error_log("Webhook file_get_contents response - HTTP: $httpCode, Response: " . substr($response ?: '', 0, 500));
if ($response !== false) {
return [
'success' => $httpCode >= 200 && $httpCode < 300,
'http_code' => $httpCode,
'response' => $response,
'error' => null,
'method' => 'file_get_contents'
];
}
$lastError = error_get_last();
error_log("Webhook all methods failed - Last error: " . json_encode($lastError));
return [
'success' => $httpCode >= 200 && $httpCode < 300,
'http_code' => $httpCode,
'response' => $response,
'error' => $error
'success' => false,
'error' => $lastError['message'] ?? 'All HTTP methods failed',
'errno' => 0,
'response' => null,
'method' => 'none'
];
}

View File

@@ -145,10 +145,16 @@ class KIChat {
this.isTyping = true;
try {
const response = await fetch('/scripts/add/send.php', {
// Use relative path that works from any page location
const basePath = window.location.pathname.includes('/') ?
window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1) : '/';
const apiUrl = new URL('/scripts/add/send.php', window.location.origin).href;
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
type: 'chat',

View File

@@ -1,22 +1,9 @@
// leads.js
// ==========================================
// 1. MENU TOGGLE
// 1. MENU TOGGLE (REMOVED)
// ==========================================
const menuToggle = document.getElementById('menuToggle');
const slideMenu = document.getElementById('slideMenu');
const overlay = document.getElementById('overlay');
if (menuToggle && slideMenu && overlay) {
function toggleMenu() {
menuToggle.classList.toggle('active');
slideMenu.classList.toggle('active');
overlay.classList.toggle('active');
}
menuToggle.addEventListener('click', toggleMenu);
overlay.addEventListener('click', toggleMenu);
}
// Menu toggle functionality has been removed
// ==========================================
// 2. LEADS TABLE LOGIC

View File

@@ -199,22 +199,10 @@ document.addEventListener("DOMContentLoaded", function() {
initPhoneCallFunctionality();
// ==========================================
// 2. MENU TOGGLE
// 2. MENU TOGGLE (REMOVED)
// ==========================================
const menuToggle = document.getElementById('menuToggle');
const slideMenu = document.getElementById('slideMenu');
const overlay = document.getElementById('overlay');
if (menuToggle && slideMenu && overlay) {
const toggleMenu = () => {
menuToggle.classList.toggle('active');
slideMenu.classList.toggle('active');
overlay.classList.toggle('active');
};
menuToggle.addEventListener('click', toggleMenu);
overlay.addEventListener('click', toggleMenu);
}
// Menu toggle functionality has been removed
// ==========================================
// 3. LOGIN BUTTON (REMOVED)