public static function shortcut($config, $zipFn = null, $credentials = null, $idesServer = null, $LOG_LEVEL = Logger::WARNING) { assert(is_null($zipFn) xor is_null($credentials)); $dm = new Downloader(null, $LOG_LEVEL); $cm = new ConfigManager($config, $dm, $LOG_LEVEL); $am = new AesManager(); $rm = new RsaManager($cm, $am); if (is_null($zipFn)) { assert(is_array($credentials) && array_key_exists("username", $credentials) && array_key_exists("password", $credentials)); assert(!is_null($idesServer) && in_array($idesServer, array("live", "test"))); $sftp = SftpWrapper::getSFTP($idesServer); $sw = new SftpWrapper($sftp, $LOG_LEVEL); $err = $sw->login($credentials["username"], $credentials["password"]); if (!!$err) { throw new \Exception($err); } $remote = $sw->listLatest(); if (array_key_exists("ZipBackupFolder", $cm->config)) { $zipFn = $cm->config["ZipBackupFolder"] . "/" . $remote; } else { $zipFn = Utils::myTempnam("zip"); unlink($zipFn); } if (!file_exists($zipFn)) { $sw->get($remote, $zipFn); } else { $sw->log->debug("Using cached file '" . $zipFn . "'"); } } $rx = new Receiver($cm, $rm); $rx->start(); $rx->fromZip($zipFn); $rx->rm->decryptAesKey(); $rx->fromEncrypted(); $rx->fromCompressed(); return $rx; }
public function toEmail($emailTo, $swiftmailerConfig) { Transmitter::verifySwiftmailerConfig($swiftmailerConfig); $emailFrom = $swiftmailerConfig["reply"]; $emailName = $swiftmailerConfig["name"]; $emailReply = $swiftmailerConfig["reply"]; // save to files $fnH = Utils::myTempnam('html'); file_put_contents($fnH, $this->fdi->toHtml()); $fnX = Utils::myTempnam('xml'); file_put_contents($fnX, $this->dataXmlSigned); $fnM = Utils::myTempnam('xml'); file_put_contents($fnM, $this->getMetadata()); $fnZ1 = Utils::myTempnam('zip'); copy($this->tf4, $fnZ1); // zip to avoid getting blocked on server $z = new \ZipArchive(); $fnZ2 = Utils::myTempnam('zip'); $z->open($fnZ2, \ZIPARCHIVE::CREATE); $z->addEmptyDir("IDES data"); $z->addFile($fnH, "IDES data/data.html"); $z->addFile($fnX, "IDES data/data.xml"); $z->addFile($fnM, "IDES data/metadata.xml"); $z->addFile($fnZ1, "IDES data/data.zip"); $z->close(); // send email $subj = sprintf("IDES data: %s", date("Y-m-d H:i:s")); $this->log->debug("Sending attachment email"); $res = Utils::mail_attachment(array($fnZ2), $emailTo, $emailFrom, $emailName, $emailReply, $subj . " (attachment)", "Attached: html, xml, metadata, zip formats", $swiftmailerConfig); if (!$res) { throw new \Exception("Failed to send attachment email. Aborting."); } $this->log->debug("Done emailing"); }