The file “versionen.php” is in the “dataplace” folder in all defined domain-accounts.
I would like to use the following script to read and output the “$software_version” variable for all defined domains on an external domain.
The “$software_version” variable is in the “versionen.php” file and is also displayed correctly locally.
The URL is loaded correctly, which is also displayed correctly by the Else branch of “if ($content === false) {“.
The domains are displayed correctly in the test output, but “Software-Empty” is always displayed for “$version”.
I just can’t get the content of the “$software_version” variable to work.
What have I not taken into account? What needs to be changed/added?
error_reporting(E_ALL);
ini_set('display_errors', '1');
// FTP-Zugangsdaten für alle URLs (1 bis x) | FTP access data for all URLs (1 to x)
$ftpCredentialsList = array(
1 => array("hostname" => "url-1.tld", "username" => "xxxxxxxx", "password" => "yyyyyyyy"),
2 => array("hostname" => "url-2.tld", "username" => "xxxxxxxx", "password" => "yyyyyyyy"),
3 => array("hostname" => "url-3.tld", "username" => "xxxxxxxx", "password" => "yyyyyyyy"),
4 => array("hostname" => "url-4.tld", "username" => "xxxxxxxx", "password" => "yyyyyyyy"),
5 => array("hostname" => "url-5.tld", "username" => "xxxxxxxx", "password" => "yyyyyyyy"),
);
########## Software-Release ##########
// Funktion, um die Software-Version einer URL abzurufen | Function to retrieve the software version of a URL
function getSoftwareVersion($url) {
// cURL-Verbindung erstellen | Create cURL connection
$curl = curl_init($url);
// Optionen für cURL festlegen | Setting options for cURL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // Folge Umleitungen | Follow redirects
// Inhalt der Datei abrufen | Retrieve file contents
$content = curl_exec($curl);
if ($content === false) {
die("Fehler beim Abrufen der Software-Version für $url: " . curl_error($curl)"| Error retrieving software version for $url: " . curl_error($curl));
} else {
// echo 'Abruf der Software-Version für '.$url.' war erfolgreich. | Retrieving the software version for '.$url.' was successful.<br>';
}
// Die Variable $software_version aus dem Inhalt extrahieren | Extract the variable $software_version from the content
preg_match('/$software_versions*=s*(.*?);/i', $content, $matches);
$softwareVersion = isset($matches[1]) ? $matches[1] : null;
// Debugging-Ausgabe | Debugging output
echo "Regex-Matches: ";
var_dump($matches);
echo "<br>";
echo "Software-Version: ";
var_dump($softwareVersion);
echo "<br>";
// Ende Debugging
curl_close($curl);
return $softwareVersion;
}
// Ergebnisse speichern | Save results
$softwareVersions = array();
foreach ($ftpCredentialsList as $index => $ftpCredentials) {
$url = "https://{$ftpCredentials['hostname']}/dataplace/versionen.php";
$softwareVersion = getSoftwareVersion($url);
// Überprüfen, ob die Software-Version gültig ist, bevor Farbe zugewiesen wird
// Check if the software version is valid before assigning color
$colorClass = 'software_empty'; // Standardfarbe, wenn die Software-Version leer ist | Default color if the software-version is empty
if ($softwareVersion !== null) {
$colorClass = (stripos($softwareVersion, 'software_red') !== false ? 'software_red' : 'software_green');
}
// Ergebnisse in Array speichern | Save results in array
$softwareVersions[$ftpCredentials['hostname']] = (empty($softwareVersion) ? "Software-Empty" : htmlspecialchars($softwareVersion));
// Farbinformationen zusätzlich speichern | Store additional color information
$softwareVersions['color'][$ftpCredentials['hostname']] = $colorClass;
}
// Testausgabe | Test issue
foreach ($softwareVersions as $hostname => $version) {
if (!is_array($version)) { // Überprüfen, ob $version kein Array ist | Check if $version is not an array
echo "<b>Hostname: <span style="color: #00F;">$hostname</span> > Software-Version: <span style="color: #00F;">$version</span><br>";
}
}