Add Turnstile protection and harden export workflow

This commit is contained in:
2026-07-22 08:54:31 +02:00
parent 67c7b5ccff
commit 4b9a5d7e78
17 changed files with 1572 additions and 276 deletions
+36 -11
View File
@@ -1,5 +1,5 @@
<?php
include 'env_vars.php';
require_once __DIR__ . '/app.php';
$username = getenv("username");
$password = getenv("password");
@@ -22,13 +22,16 @@ function sendAPICompanyInfoRequest(string $username, string $password, string $u
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
error_log('ZEFIX company info request failed: ' . curl_error($ch));
}
// Close cURL session
curl_close($ch);
@@ -61,13 +64,16 @@ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
error_log('ZEFIX company search request failed: ' . curl_error($ch));
}
// Close cURL session
curl_close($ch);
@@ -94,13 +100,16 @@ function sendAPICommunityRequest(string $username, string $password): string|boo
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
error_log('ZEFIX community request failed: ' . curl_error($ch));
}
// Close cURL session
curl_close($ch);
@@ -110,8 +119,15 @@ function sendAPICommunityRequest(string $username, string $password): string|boo
function communityCSV(string $username, string $password): string {
$response = sendAPICommunityRequest($username, $password);
if (!is_string($response)) {
return '';
}
$communityArray = json_decode($response, true);
if (!is_array($communityArray)) {
return '';
}
$csvOutput = "id,bfsId,Kanton,Gemeindename,registryOfCommerceId,replacedById\n";
foreach ($communityArray as $item) {
@@ -150,13 +166,16 @@ function sendAPILegalFormRequest(string $username, string $password): string|boo
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
error_log('ZEFIX legal form request failed: ' . curl_error($ch));
}
// Close cURL session
curl_close($ch);
@@ -166,8 +185,14 @@ function sendAPILegalFormRequest(string $username, string $password): string|boo
function legalFormCSV(string $username, string $password): string {
$response = sendAPILegalFormRequest($username, $password);
if (!is_string($response)) {
return '';
}
$legalformArray = json_decode($response, true);
$csvOutput = 'id,name\n';
if (!is_array($legalformArray)) {
return '';
}
$csvOutput = "id,name\n";
// Create CSV rows
foreach ($legalformArray as $item) {
@@ -176,4 +201,4 @@ function legalFormCSV(string $username, string $password): string {
return $csvOutput;
}
?>
?>