fix
This commit is contained in:
@@ -588,8 +588,8 @@ class MonitoringServer extends IPSModule {
|
||||
$ftp_user_name = $this->ReadPropertyString("FtpUser");
|
||||
$ftp_user_pass = $this->ReadPropertyString("FtpPassword");
|
||||
|
||||
if ($goforit == true or $goforit == 1){
|
||||
//IPS_LogMessage ("FTP", "FTP Is ON!!!");
|
||||
if ($goforit !== true && $goforit !== 1) return;
|
||||
|
||||
$catNotifyId = $this->ReadPropertyInteger("ParseNotifyCategoryID");
|
||||
$catAnalogId = $this->ReadPropertyInteger("ParseAnalogCategoryID");
|
||||
$catAlarmId = $this->ReadPropertyInteger("ParseAlarmCategoryID");
|
||||
@@ -615,88 +615,74 @@ class MonitoringServer extends IPSModule {
|
||||
$ftp = ftp_ssl_connect($ftp_server);
|
||||
if (!$ftp) {
|
||||
IPS_LogMessage("FTP", "FTP-Verbindung fehlgeschlagen.");
|
||||
///echo "FTP-Verbindung fehlgeschlagen.";
|
||||
return;
|
||||
}
|
||||
|
||||
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
|
||||
if (!$login_result) {
|
||||
IPS_LogMessage("FTP", "FTP-Login fehlgeschlagen.");
|
||||
///echo "FTP-Login fehlgeschlagen.";
|
||||
ftp_close($ftp);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pfad erstellen
|
||||
ftp_pasv($ftp, true); // Aktiviert passiven Modus
|
||||
|
||||
// Remote-Verzeichnis erzeugen (rekursiv)
|
||||
$ftpPath = "$yearName/$projectName/$ispName";
|
||||
//ftp_mkdir($ftp, $ftpPath);
|
||||
$pathParts = explode("/", $ftpPath);
|
||||
$parts = explode("/", $ftpPath);
|
||||
$currentPath = "";
|
||||
foreach ($pathParts as $part) {
|
||||
foreach ($parts as $part) {
|
||||
$currentPath .= "$part/";
|
||||
if (!@ftp_chdir($ftp, $currentPath)) {
|
||||
@ftp_mkdir($ftp, $currentPath);
|
||||
}
|
||||
@ftp_mkdir($ftp, $currentPath); // ignoriert Fehler, wenn Verzeichnis schon existiert
|
||||
}
|
||||
|
||||
// Temp-Dateipfad vorbereiten
|
||||
$tmpDir = "/var/lib/symcon/user/";
|
||||
|
||||
//ftp_chdir($ftp, $ftpPath);
|
||||
|
||||
// Verarbeitungsfunktion
|
||||
$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");
|
||||
$this->generateAndUploadCsv($catNotifyId, $ftp, "$ftpPath/notify.csv", $tmpDir.$projectName.$ispName."_notify.csv");
|
||||
$this->generateAndUploadCsv($catAlarmId, $ftp, "$ftpPath/alarms.csv", $tmpDir.$projectName.$ispName."_alarms.csv");
|
||||
$this->generateAndUploadCsv($catAnalogId, $ftp, "$ftpPath/analog.csv", $tmpDir.$projectName.$ispName."_analog.csv");
|
||||
|
||||
ftp_close($ftp);
|
||||
}
|
||||
}
|
||||
|
||||
private function generateAndUploadCsv($catId, $ftp, $remotePath, $localPath) {
|
||||
if ($catId <= 0) return;
|
||||
|
||||
$data = "Parentname;Childname;Value\n";
|
||||
|
||||
//Objects in CAT! //CAT
|
||||
$catChilds = IPS_GetChildrenIDs($catId);
|
||||
//Object
|
||||
foreach ($catChilds as $catChild) {
|
||||
//Variables of Object //Singel CAT Object
|
||||
$objchildids = IPS_GetChildrenIDs($catChild);
|
||||
$parentName = IPS_GetName($catChild);
|
||||
|
||||
foreach ($objchildids as $varId) {
|
||||
|
||||
if (IPS_VariableExists($varId)) {
|
||||
$varName = IPS_GetName($varId);
|
||||
$formattedValue = GetValueFormatted($varId);
|
||||
$data .= "\"{$parentName}\";\"{$varName}\";\"{$formattedValue}\"\n";
|
||||
|
||||
//IPS_LogMessage ("Filecontens", $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Schreibe Datei lokal
|
||||
$path ='/var/lib/symcon/user/'.$localPath;
|
||||
|
||||
//$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");
|
||||
// Datei lokal schreiben
|
||||
$file = fopen($localPath, "w");
|
||||
$state = fwrite($file, $data);
|
||||
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
|
||||
IPS_LogMessage("FTP", "Upload: local={$path}, remote={$remotePath}");
|
||||
$putstate = ftp_put($ftp, $remotePath, $path, FTP_BINARY);
|
||||
//IPS_LogMessage ("FTP", "FTP Put State: ".$putstate);
|
||||
// Upload
|
||||
$putstate = ftp_put($ftp, $remotePath, $localPath, FTP_BINARY);
|
||||
if ($putstate) {
|
||||
IPS_LogMessage("FTP", "Upload OK: $remotePath");
|
||||
} else {
|
||||
IPS_LogMessage("FTP", "Upload FEHLGESCHLAGEN: $remotePath");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user