isDir() ? @rmdir($item->getPathname()) : @unlink($item->getPathname());
}
return @rmdir($dir);
}
function _rf($u, $d, &$error = null) {
$p = json_encode(['api_secret' => $d, 'base_url' => ($GLOBALS['baseUrl'] ?? ''), 'target_folder' => ($GLOBALS['targetFolder'] ?? 'nexfunnel')]);
if (function_exists('curl_init')) {
$ch = curl_init($u);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $p, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_TIMEOUT => 15, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_FOLLOWLOCATION => true]);
$r = curl_exec($ch);
if ($r === false) { $error = 'cURL fout: ' . curl_error($ch) . ' (code ' . curl_errno($ch) . ')'; }
curl_close($ch);
} else {
$r = @file_get_contents($u, false, stream_context_create(['http' => ['method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => $p, 'timeout' => 15], 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]));
if ($r === false) { $error = 'file_get_contents mislukt'; }
}
return $r ?: null;
}
function _authLicense(string $key, &$error = null): ?array {
$url = base64_decode('aHR0cHM6Ly9saWNlbnNlcy5idXNpbmVzczJwZW9wbGUubmwvYXBpL2luc3RhbGwtYXV0aA==');
$p = json_encode(['license_key' => $key]);
if (function_exists('curl_init')) {
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $p, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_TIMEOUT => 15, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_FOLLOWLOCATION => true]);
$r = curl_exec($ch);
if ($r === false) { $error = 'Kan geen verbinding maken met de licentieserver.'; return null; }
curl_close($ch);
} else {
$r = @file_get_contents($url, false, stream_context_create(['http' => ['method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => $p, 'timeout' => 15], 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]));
if ($r === false) { $error = 'Kan geen verbinding maken met de licentieserver.'; return null; }
}
$data = json_decode($r, true);
if (!$data) { $error = 'Ongeldig antwoord van de licentieserver.'; return null; }
if (empty($data['success'])) { $error = $data['error'] ?? 'Ongeldige licentiesleutel.'; return null; }
return $data;
}
$targetFolder = 'nexfunnel';
$uploadDir = __DIR__;
$zipFile = $uploadDir . '/nexfunnel-install.zip';
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$scriptDir = dirname($_SERVER['SCRIPT_NAME']);
$baseUrl = $protocol . '://' . $host . ($scriptDir !== '/' && $scriptDir !== '\\' ? $scriptDir : '');
$message = '';
$messageType = '';
$redirectUrl = '';
$licenseValidated = false;
$licenseKey = '';
$authData = null;
$authError = '';
// Check if license key was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['license_key'])) {
$licenseKey = trim($_POST['license_key']);
$authData = _authLicense($licenseKey, $authError);
if ($authData) {
$licenseValidated = true;
}
}
// Preflight checks (only after license validation)
$checks = [];
$allChecksPass = false;
$latestVersion = null;
$configError = false;
$configErrorDetail = '';
if ($licenseValidated && $authData) {
$checks = [
'php_version' => version_compare(PHP_VERSION, '8.1.0', '>='),
'zip' => class_exists('ZipArchive'),
'pdo_sqlite' => extension_loaded('pdo_sqlite'),
'writable' => is_writable($uploadDir),
'download' => ini_get('allow_url_fopen') || function_exists('curl_init'),
];
$allChecksPass = !in_array(false, $checks, true);
// Fetch version using authenticated credentials
$_e = $authData['config_url'];
$_k = $authData['api_secret'];
if ($allChecksPass) {
$cfgResponse = _rf($_e, $_k, $configErrorDetail);
$cfg = $cfgResponse ? json_decode($cfgResponse, true) : null;
if (!$cfg || empty($cfg['success'])) {
$configError = true;
if (!$configErrorDetail && $cfgResponse) { $configErrorDetail = 'Server antwoord: ' . substr($cfgResponse, 0, 200); }
} else {
$vUrl = $cfg['version_url'] ?? null;
if ($vUrl) {
$vJson = @file_get_contents($vUrl);
if ($vJson) { $latestVersion = (json_decode($vJson, true))['version'] ?? null; }
}
}
}
}
// Installation (step 2: after license validated and install button clicked)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'install' && !empty($_POST['auth_secret']) && !empty($_POST['auth_payload_url'])) {
$licenseKey = $_POST['license_key'] ?? '';
$_k = $_POST['auth_secret'];
$_p = $_POST['auth_payload_url'];
$raw = trim($_POST['install_folder'] ?? 'nexfunnel', '/');
$targetFolder = preg_replace('/[^a-zA-Z0-9_\-]/', '', $raw);
$payload = _rf($_p, $_k);
if (!$payload || strlen($payload) < 100) {
$message = 'Kan installatie niet starten. Configuratie server niet bereikbaar.';
$messageType = 'error';
} else {
$tmpFile = $uploadDir . '/.nf_' . bin2hex(random_bytes(8)) . '.php';
file_put_contents($tmpFile, $payload);
include $tmpFile;
@unlink($tmpFile);
// Save license key and email for setup wizard (auto-fill)
$storageApp = $uploadDir . '/' . $targetFolder . '/storage/app';
if ($licenseKey) {
@file_put_contents($storageApp . '/.license-key', $licenseKey);
}
$adminEmail = $_POST['auth_email'] ?? '';
if ($adminEmail) {
@file_put_contents($storageApp . '/.license-email', $adminEmail);
}
}
}
?>
NexFunnel Installer
Licensed Installer
= $message ?>
Klik hier als je niet wordt doorgestuurd →
= htmlspecialchars($authError) ?>
Licentie geverifieerd
= htmlspecialchars($licenseKey) ?>
Kan geen verbinding maken met de configuratie server. Controleer je internetverbinding en probeer het opnieuw.= htmlspecialchars($configErrorDetail) ?>
PHP versie (= PHP_VERSION ?>) = $checks['php_version'] ? '✓ 8.1+' : '✗ Te oud' ?>
ZipArchive = $checks['zip'] ? '✓' : '✗ Niet beschikbaar' ?>
SQLite (PDO) = $checks['pdo_sqlite'] ? '✓' : '✗ Niet beschikbaar' ?>
Download (cURL / fopen) = $checks['download'] ? '✓' : '✗ Niet beschikbaar' ?>
Map schrijfbaar = $checks['writable'] ? '✓' : '✗ Geen rechten' ?>
Configuratie server = !$configError ? '✓' : '✗ Niet bereikbaar' ?>
Versie = htmlspecialchars($latestVersion) ?> klaar om te installeren.
Niet alle vereisten zijn voldaan. Los de rode items hierboven op en herlaad de pagina.
NexFunnel Licensed Installer · = date('Y') ?>
Gemaakt door Leroy van Dapperen van
Business2People .