fix
This commit is contained in:
@@ -588,8 +588,8 @@ class MonitoringServer extends IPSModule {
|
|||||||
$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");
|
||||||
@@ -615,88 +615,74 @@ 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");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user