This commit is contained in:
jhartworks
2025-07-04 15:39:43 +02:00
parent bec34154c8
commit 98b8167ac6
+32 -46
View File
@@ -582,14 +582,14 @@ class MonitoringServer extends IPSModule {
} }
} }
public function sendFtp(){ public function sendFtp() {
$goforit = $this->ReadPropertyBoolean("SendFtp"); $goforit = $this->ReadPropertyBoolean("SendFtp");
$ftp_server = $this->ReadPropertyString("FtpHost"); $ftp_server = $this->ReadPropertyString("FtpHost");
$ftp_user_name = $this->ReadPropertyString("FtpUser"); $ftp_user_name = $this->ReadPropertyString("FtpUser");
$ftp_user_pass = $this->ReadPropertyString("FtpPassword"); $ftp_user_pass = $this->ReadPropertyString("FtpPassword");
if ($goforit == true or $goforit == 1){ if ($goforit !== true && $goforit !== 1) return;
//IPS_LogMessage ("FTP", "FTP Is ON!!!");
$catNotifyId = $this->ReadPropertyInteger("ParseNotifyCategoryID"); $catNotifyId = $this->ReadPropertyInteger("ParseNotifyCategoryID");
$catAnalogId = $this->ReadPropertyInteger("ParseAnalogCategoryID"); $catAnalogId = $this->ReadPropertyInteger("ParseAnalogCategoryID");
$catAlarmId = $this->ReadPropertyInteger("ParseAlarmCategoryID"); $catAlarmId = $this->ReadPropertyInteger("ParseAlarmCategoryID");
@@ -603,7 +603,7 @@ class MonitoringServer extends IPSModule {
elseif ($catAnalogId > 0) $usedCat = $catAnalogId; elseif ($catAnalogId > 0) $usedCat = $catAnalogId;
elseif ($catAlarmId > 0) $usedCat = $catAlarmId; elseif ($catAlarmId > 0) $usedCat = $catAlarmId;
if ($usedCat > 0){ if ($usedCat > 0) {
$parentid = IPS_GetParent($usedCat); $parentid = IPS_GetParent($usedCat);
$ispName = IPS_GetName($parentid); $ispName = IPS_GetName($parentid);
$projectId = IPS_GetParent($parentid); $projectId = IPS_GetParent($parentid);
@@ -614,89 +614,75 @@ class MonitoringServer extends IPSModule {
$ftp = ftp_ssl_connect($ftp_server); $ftp = ftp_ssl_connect($ftp_server);
if (!$ftp) { if (!$ftp) {
IPS_LogMessage ("FTP", "FTP-Verbindung fehlgeschlagen."); IPS_LogMessage("FTP", "FTP-Verbindung fehlgeschlagen.");
///echo "FTP-Verbindung fehlgeschlagen.";
return; return;
} }
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass); $login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
if (!$login_result) { if (!$login_result) {
IPS_LogMessage ("FTP", "FTP-Login fehlgeschlagen."); IPS_LogMessage("FTP", "FTP-Login fehlgeschlagen.");
///echo "FTP-Login fehlgeschlagen.";
ftp_close($ftp); ftp_close($ftp);
return; return;
} }
// Pfad erstellen ftp_pasv($ftp, true); // Aktiviert passiven Modus
// Remote-Verzeichnis erzeugen (rekursiv)
$ftpPath = "$yearName/$projectName/$ispName"; $ftpPath = "$yearName/$projectName/$ispName";
//ftp_mkdir($ftp, $ftpPath); $parts = explode("/", $ftpPath);
$pathParts = explode("/", $ftpPath);
$currentPath = ""; $currentPath = "";
foreach ($pathParts as $part) { foreach ($parts as $part) {
$currentPath .= "$part/"; $currentPath .= "$part/";
if (!@ftp_chdir($ftp, $currentPath)) { @ftp_mkdir($ftp, $currentPath); // ignoriert Fehler, wenn Verzeichnis schon existiert
@ftp_mkdir($ftp, $currentPath);
}
} }
// Temp-Dateipfad vorbereiten $tmpDir = "/var/lib/symcon/user/";
//ftp_chdir($ftp, $ftpPath); $this->generateAndUploadCsv($catNotifyId, $ftp, "$ftpPath/notify.csv", $tmpDir.$projectName.$ispName."_notify.csv");
$this->generateAndUploadCsv($catAlarmId, $ftp, "$ftpPath/alarms.csv", $tmpDir.$projectName.$ispName."_alarms.csv");
// Verarbeitungsfunktion $this->generateAndUploadCsv($catAnalogId, $ftp, "$ftpPath/analog.csv", $tmpDir.$projectName.$ispName."_analog.csv");
$this->generateAndUploadCsv($catNotifyId, $ftp, "$ftpPath/notify.csv", $projectName.$ispName."notify.csv");
$this->generateAndUploadCsv($catAlarmId, $ftp, "$ftpPath/alarms.csv", $projectName.$ispName."alarms.csv");
$this->generateAndUploadCsv($catAnalogId, $ftp, "$ftpPath/analog.csv", $projectName.$ispName."analog.csv");
ftp_close($ftp); ftp_close($ftp);
} }
}
private function generateAndUploadCsv($catId, $ftp, $remotePath, $localPath) { private function generateAndUploadCsv($catId, $ftp, $remotePath, $localPath) {
if ($catId <= 0) return; if ($catId <= 0) return;
$data = "Parentname;Childname;Value\n"; $data = "Parentname;Childname;Value\n";
//Objects in CAT! //CAT
$catChilds = IPS_GetChildrenIDs($catId); $catChilds = IPS_GetChildrenIDs($catId);
//Object
foreach ($catChilds as $catChild) { foreach ($catChilds as $catChild) {
//Variables of Object //Singel CAT Object
$objchildids = IPS_GetChildrenIDs($catChild); $objchildids = IPS_GetChildrenIDs($catChild);
$parentName = IPS_GetName($catChild); $parentName = IPS_GetName($catChild);
foreach ($objchildids as $varId) { foreach ($objchildids as $varId) {
if (IPS_VariableExists($varId)) { if (IPS_VariableExists($varId)) {
$varName = IPS_GetName($varId); $varName = IPS_GetName($varId);
$formattedValue = GetValueFormatted($varId); $formattedValue = GetValueFormatted($varId);
$data .= "\"{$parentName}\";\"{$varName}\";\"{$formattedValue}\"\n"; $data .= "\"{$parentName}\";\"{$varName}\";\"{$formattedValue}\"\n";
//IPS_LogMessage ("Filecontens", $data);
} }
} }
} }
// Schreibe Datei lokal // Datei lokal schreiben
$path ='/var/lib/symcon/user/'.$localPath; $file = fopen($localPath, "w");
//$state = file_put_contents($localPath, $data);
IPS_LogMessage("FTP", "Lokaler Pfad: " . $path);
IPS_LogMessage("FTP", "Remote Pfad: " . $remotePath);
IPS_LogMessage("FTP", "Dateigröße lokal: " . filesize($path));
$file = fopen($path, "w");
$state = fwrite($file, $data); $state = fwrite($file, $data);
fclose($file); fclose($file);
//IPS_LogMessage ("File Create", "File Put State/Size: ".$state); // Logging
IPS_LogMessage("FTP", "Lokaler Pfad: " . $localPath);
IPS_LogMessage("FTP", "Remote Pfad: " . $remotePath);
IPS_LogMessage("FTP", "Dateigröße lokal: " . filesize($localPath));
// Lade hoch // Upload
IPS_LogMessage("FTP", "Upload: local={$path}, remote={$remotePath}"); $putstate = ftp_put($ftp, $remotePath, $localPath, FTP_BINARY);
$putstate = ftp_put($ftp, $remotePath, $path, FTP_BINARY); if ($putstate) {
//IPS_LogMessage ("FTP", "FTP Put State: ".$putstate); IPS_LogMessage("FTP", "Upload OK: $remotePath");
} else {
IPS_LogMessage("FTP", "Upload FEHLGESCHLAGEN: $remotePath");
} }
}
} }
?> ?>