public static function shortcut($fdi, $format, $emailTo, $config, $LOG_LEVEL = Logger::WARNING)
 {
     $dm = new Downloader(null, $LOG_LEVEL);
     $conMan = new ConfigManager($config, $dm, $LOG_LEVEL);
     $am = new AesManager($fdi->getIsTest() ? "CBC" : "ECB");
     // as of 2016-06-27, the production server still uses ECB
     $rm = new RsaManager($conMan, $am);
     $tmtr = new Transmitter($fdi, $conMan, $rm, $LOG_LEVEL);
     $tmtr->start();
     $tmtr->toXml();
     # convert to xml
     if ($format != "xml") {
         $exitCond = in_array($format, array("email", "emailAndUpload", "upload", "zip"));
         if (!$tmtr->validateXml("payload")) {
             # validate
             $msg = 'Payload xml did not pass its xsd validation';
             if ($exitCond) {
                 throw new \Exception($msg);
             } else {
                 print $msg;
             }
             Utils::libxml_display_errors();
         }
         if (!$tmtr->validateXml("metadata")) {
             # validate
             $msg = 'Metadata xml did not pass its xsd validation';
             if ($exitCond) {
                 throw new \Exception($msg);
             } else {
                 print $msg;
             }
             Utils::libxml_display_errors();
         }
     }
     $tmtr->toXmlSigned();
     if (!$tmtr->verifyXmlSigned()) {
         die("Verification of signature failed");
     }
     $tmtr->toCompressed();
     $tmtr->toEncrypted();
     $tmtr->rm->encryptAesKeyFile();
     //	if(!$tmtr->rm->verifyAesKeyFileEncrypted()) die("Verification of aes key encryption failed");
     $tmtr->toZip(true);
     if (array_key_exists("ZipBackupFolder", $config)) {
         $fnDest = $config["ZipBackupFolder"] . "/includeUnencrypted_" . $tmtr->file_name;
         copy($tmtr->tf4, $fnDest);
     }
     $tmtr->toZip(false);
     if (array_key_exists("ZipBackupFolder", $config)) {
         $fnDest = $config["ZipBackupFolder"] . "/submitted_" . $tmtr->file_name;
         copy($tmtr->tf4, $fnDest);
     }
     return $tmtr;
 }
Esempio n. 2
0
 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;
 }
 function get($remote, $local)
 {
     // puts an x-byte file named filename.remote on the SFTP server,
     // where x is the size of filename.local
     $this->log->info("Downloading file '" . $remote . "'");
     $prefix = "Inbox/840";
     $this->sftp->get($prefix . "/" . $remote, $local);
     $this->log->info("Downloaded");
     if (!file_exists($local)) {
         throw new \Exception("Error downloading latest file '" . $prefix . "/" . $remote . "' into '" . $local . "'");
     }
     // check that this is a zip file
     if (!Utils::isZip($local)) {
         throw new \Exception("Only zip files accepted. Rejecting '" . $local . "'");
     }
     $this->log->info("Downloaded file '" . $local . "'");
 }