| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 | 
							- <?php
 
- require_once(dirname(__FILE__).'/vendor/PHPMailer/class.phpmailer.php');
 
- require_once(dirname(__FILE__).'/vendor/PHPMailer/class.smtp.php');
 
- $smtpConfDefault = array('host' => "smtp.1und1.de", 'secure' => true, 'auth' => true, 'port' => 465, 'from' => "smtp@global-cube.de", 'username' => "smtp@global-cube.de", 'password' => "gcbssmtp");
 
- $config = parse_ini_file(dirname(__FILE__) . "/../../GAPS.ini");
 
- $smtpConfXml = getSmtpConfFromIni($config);
 
- function checkProtocolDirectory($path, $all = false)
 
- {
 
- 	$result = array();
 
- 	$protDir = dir($path);
 
- 	while ($filename = $protDir->read()) {
 
- 		if (!preg_match('/\.log$/i', $filename))
 
- 			continue;
 
- 		$log = new Logfile("{$path}\\{$filename}");
 
- 		if ($all || $log->ErrorLevel < 3 || $log->LastChangedDays >= 4) {
 
- 			$result[] = $log;
 
- 		}
 
- 	}
 
- 	return $result;
 
- }
 
- function getSmtpConfFromIni($config) {
 
- 	$conf = array();
 
- 	$conf['host'] = (@$config['SMTP_FEHLERBERICHT'] != "N") ? $config['SMTP_HOST'] : "";
 
- 	$conf['port'] = $config['SMTP_PORT'];
 
- 	$conf['from'] = $config['SMTP_FROM'];
 
- 	$conf['username'] = $config['SMTP_USER'];
 
- 	$conf['password'] = $config['SMTP_PW'];
 
- 	$conf['secure'] = ($config['SMTP_SSL'] == "J");
 
- 	$conf['auth'] = ($conf['username'] != "");
 
- 	return $conf;
 
- }
 
- /**
 
-  * @param $mail PHPMailer
 
-  * @param $conf array
 
-  * @param $mailFrom string
 
-  * @return bool
 
-  */
 
- function setSmtpConf($mail, $conf, $mailFrom) {
 
- 	$mail->IsSMTP();
 
- 	$mail->Host = $conf['host'];
 
- 	$mail->SMTPAuth = $conf['auth'];
 
- 	$mail->Port = $conf['port'];
 
- 	$mail->Username = $conf['username'];
 
- 	$mail->Password = $conf['password'];
 
- 	$mail->SMTPSecure = ($conf['secure']) ? "ssl" : false;
 
- 	$mail->Sender = '';
 
- 	$mail->SetFrom($conf['from'], $mailFrom);
 
- 	//$mail->SMTPDebug = true;
 
- 	return true;
 
- }
 
- function mailFormat($list) {
 
- 	$result = "";
 
- 	$addresses = explode(";", $list);
 
- 	foreach ($addresses as $address) {
 
- 		$result .= "<a href=\"mailto:{$address}\">{$address}</a><br/>";
 
- 	}
 
- 	return $result;
 
- }
 
- function sendMail($logs, $mailFrom)
 
- {
 
- 	$today = date("d.m.Y");
 
- 	$total = count($logs);
 
- 	ob_start();
 
- 	include('fehlerbericht_template.php');
 
- 	$body = ob_get_clean();
 
- 	$mail = new PHPMailer();
 
- 	$mail->AddAddress('fehlerbericht@global-cube.de', 'Global Cube');
 
- 	$mail->Subject = "{$mailFrom}: Fehlerbericht vom {$today}, {$total} Fehler";
 
- 	$mail->AltBody = json_encode($logs);
 
- 	$mail->MsgHTML($body);
 
- 	foreach ($logs as $logfile) {
 
- 		if ($logfile->Type == "Modell") {
 
- 			$mail->AddAttachment($logfile->Filename);
 
- 		}
 
- 	}
 
- 	if (send($mail, $mailFrom)) {
 
- 		echo "  Fehlerbericht gesendet!\r\n";
 
- 	}
 
- }
 
- /**
 
-  * @param $mail PHPMailer
 
-  * @param $mailFrom string
 
-  * @return bool
 
-  */
 
- function send ($mail, $mailFrom) {
 
- 	global $smtpConfDefault;
 
- 	global $smtpConfXml;
 
- 	setSmtpConf($mail, $smtpConfDefault, $mailFrom);		
 
- 	if ($mail->Send()) {
 
- 		$mail->SmtpClose();
 
- 		return true;
 
- 	}
 
- 	$mail->SmtpClose();
 
- 	sleep(10);
 
- 	$mail->Port = 25;
 
- 	$mail->SMTPSecure = false;
 
- 	if ($mail->Send()) {
 
- 		$mail->SmtpClose();
 
- 		return true;
 
- 	}
 
- 	$mail->SmtpClose();
 
- 	sleep(10);
 
- 	if ($smtpConfXml['host']!="") {
 
- 		setSmtpConf($mail, $smtpConfXml, $mailFrom);
 
- 		if ($mail->Send()) {
 
- 			$mail->SmtpClose();
 
- 			return true;
 
- 		}
 
- 		$mail->SmtpClose();
 
- 	}
 
- 	echo "  Fehler im Mailversand: " . $mail->ErrorInfo . "\r\n";
 
- 	return false;
 
- }
 
- function sendStatusMail($mailFrom, $startTime, $endTime, $errorCount, $batchFile, $attachments) {
 
-     global $config;
 
- 	$mail = new PHPMailer();
 
- 	$mail->AddAddress('status@global-cube.de', 'Global Cube');
 
- 	$today = date("Y-m-d");
 
- 	
 
- 	$content = array('subject' => "{$mailFrom};{$startTime};{$endTime};{$today};{$errorCount};{$batchFile}");
 
- 	$mail->Subject = $content['subject'];
 
- 	$mail->isHTML(false); 
 
- 	$mail->Body = "[]";
 
- 	foreach($attachments as $key => $file) {
 
- 		if (file_exists($file)) {
 
- 			$content[$key] = file_get_contents($file);
 
- 			$mail->AddAttachment($file);
 
- 		}
 
- 	}
 
- 	
 
- 	if (send($mail, $mailFrom)) {
 
- 		echo "  Statusbericht gesendet!\r\n";
 
- 	} else {
 
- 		$opts = array('http' =>
 
- 			array(
 
- 				'method'  => 'POST',
 
- 				'header'  => "Content-type: application/json\r\n",
 
- 				'content' => json_encode($content),
 
- 				'timeout' => 60
 
- 			 )
 
- 		);
 
- 		if (isset($config['PROXY'])) {
 
- 			$opt['http']['proxy'] = $config['PROXY'];
 
- 			$opt['http']['request_fulluri'] = true;
 
- 		}
 
- 		$context  = stream_context_create($opts);
 
- 		$result = file_get_contents('http://dev.global-cube.de/statusmail/', false, $context, -1, 40000);
 
- 		echo "  " . $result;
 
- 	}
 
- 	return true;
 
- }
 
- function checkStarterLogs($path, $dirMatch)
 
- {
 
- 	$today = date("d.m.Y");
 
- 	$result = array();
 
- 	$protDir = dir($path);
 
- 	while ($filename = $protDir->read()) {
 
- 		if (!preg_match('/\.' . $dirMatch . '\.log$/i', $filename))
 
- 			continue;
 
- 		foreach (file("{$path}\\{$filename}") as $line) {
 
- 			if (strpos($line, $today)) {
 
- 				$result[] = json_decode($line);
 
- 			}
 
- 		}
 
- 	}
 
- 	return $result;
 
- }
 
- function checkStarter($path)
 
- {
 
- 	$result = array();
 
- 	$logPath = $path . "\\logs";
 
- 	
 
- 	$protDir = dir($logPath);
 
- 	while ($filename = $protDir->read()) {
 
- 		if (!preg_match('/\.log$/i', $filename) || $filename == "gcstarter.log") {
 
- 			continue;
 
- 		}
 
- 		$result[$filename] = json_decode("[" . implode(",", file("{$logPath}\\{$filename}")) . "]");
 
- 	}
 
- 	$result['gcstarter.xml'] = file_get_contents($path . "\\config\gcstarter.xml");
 
- 	return $result;
 
- }
 
- function sendUpdateMail($logs)
 
- {
 
- 	global $smtpConfDefault;
 
- 	global $smtpConfXml;
 
- 	global $config;
 
- 	$today = date("d.m.Y");
 
- 	ob_start();
 
- 	include('statusbericht_template.php');
 
- 	$body = ob_get_clean();
 
- 	$mail = new PHPMailer();
 
- 	$mail->AddAddress($config['STATUSBERICHT']);
 
- 	$mail->Subject = "{$config['KUNDE']} - Kontenaktualisierung GAPS";
 
- 	$mail->MsgHTML($body);
 
- 	if (send($mail, "Global Cube")) {
 
- 		echo "  Updatebericht gesendet!\r\n";
 
- 		return true;
 
- 	}
 
- 	return false;
 
- }
 
 
  |