/** * Append all the extra PDFs */ protected function attachPdfs() { foreach ($this->appendQueue as $blob) { $pdfPath = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; if ($pdftkPath = $this->_controller->getConfig()->getPdftkPath()) { $tmpFile = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; file_put_contents($tmpFile, $blob); $output = array(); $status = 0; $return = exec("{$pdftkPath} {$tmpFile} output {$pdfPath} flatten", $output, $status); if ($status != 0) { throw new \Jazzee\Exception("Problem flattening PDF, return: {$return}, status: {$status}, output was: " . var_export($output, true)); } unlink($tmpFile); } else { $this->_controller->log("You do not have PDFTK installed or you have not set the pdftkPath configuration variable. Some PDFs may be generated without all of their data."); file_put_contents($pdfPath, $blob); } $doc = $this->pdf->open_pdi_document($pdfPath, 'shrug=true'); //loop through each page for ($i = 1; $i <= $this->pdf->pcos_get_number($doc, "length:pages"); $i++) { $page = $this->pdf->open_pdi_page($doc, $i, ''); $this->pdf->begin_page_ext($this->pageWidth, $this->pageHeight, ""); $this->pdf->fit_pdi_page($page, 0, 20, 'adjustpage'); $this->pdf->close_pdi_page($page); $this->pdf->end_page_ext(''); } $this->pdf->close_pdi_document($doc); unlink($pdfPath); } }
public function loginUser() { $form = $this->getLoginForm(); if ($input = $form->processInput($_POST)) { $allowedIps = explode(',', $this->_controller->getConfig()->getApiFormAuthenticationIpAddresses()); if (in_array($_SERVER['REMOTE_ADDR'], $allowedIps)) { if ($this->_user = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\User')->findOneBy(array('apiKey' => $input->get('apiKey'), 'isActive' => true))) { $this->_controller->getStore()->expire(); $this->_controller->getStore()->touchAuthentication(); $this->_controller->getStore()->set(self::SESSION_VAR_ID, $this->_user->getId()); } else { $form->getElementByName('apiKey')->addMessage('That is not a valid ID'); return false; } } else { throw new \Jazzee\Exception("{$_SERVER['REMOTE_ADDR']} is not a valid ip address for ApiFormAuthentication: {$allowedIps}. Add it to the apiFormAuthenticationIpAddresses configuration to continue."); } } }
/** * Check an IP address against the allowed address list * @param string $clientIp * @return boolean */ protected function isAllowedIp($clientIp) { $allowedIps = explode(',', $this->_controller->getConfig()->getNoAuthIpAddresses()); if (in_array($clientIp, $allowedIps)) { return true; } foreach ($allowedIps as $allowedIp) { if (\Foundation\Utility::ipInRange($clientIp, $allowedIp)) { return true; } } return false; }
protected function generatePDF(array $elements) { $pdf = $this->getPdf(); $pdf->set_info("Title", $pdf->convert_to_unicode('utf8', $elements['applicant']['fullName'], '') . ' Application'); $document = $pdf->open_pdi_document($this->_template->getTmpFilePath(), ''); $pagecount = $pdf->pcos_get_number($document, "length:pages"); for ($pageNum = 0; $pageNum < $pagecount; $pageNum++) { $page = $pdf->open_pdi_page($document, $pageNum + 1, ""); $width = $pdf->pcos_get_number($document, "pages[{$pageNum}]/width"); $height = $pdf->pcos_get_number($document, "pages[{$pageNum}]/height"); $pdf->begin_page_ext($width, $height, ""); $pdf->fit_pdi_page($page, 0, 0, ""); $blockcount = $pdf->pcos_get_number($document, "length:pages[{$pageNum}]/blocks"); for ($blockNum = 0; $blockNum < $blockcount; $blockNum++) { $blockName = $pdf->pcos_get_string($document, "pages[{$pageNum}]/blocks[{$blockNum}]/Name"); $blockType = $pdf->pcos_get_string($document, "pages[{$pageNum}]/blocks[{$blockNum}]/Subtype"); if ($this->_template->hasBlock($blockName)) { $string = ''; $blockData = $this->_template->getBlock($blockName); switch ($blockData['type']) { case 'applicant': $string = $elements['applicant'][$blockData['element']]; break; case 'page': if (array_key_exists($blockData['pageId'], $elements['pages']) and array_key_exists($blockData['elementId'], $elements['pages'][$blockData['pageId']])) { $string = $elements['pages'][$blockData['pageId']][$blockData['elementId']]; } break; } switch ($blockType) { case 'Text': $mime = $this->binarymimetype($string); if ($mime === false) { $string = $pdf->convert_to_unicode('utf8', $string, ''); $length = strlen($string); $pdf->fill_textblock($page, $blockName, $string, "encoding=unicode textlen={$length}"); } else { $this->_controller->log("Binary data found in Text field, mime:" . $mime . ", page: " . $page . ", block: " . $blockName . ", block num: " . $blockNum, \Monolog\Logger::ERROR); } break; case 'PDF': if ($string) { $pdfPath = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; if ($pdftkPath = $this->_controller->getConfig()->getPdftkPath()) { $tmpFile = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; file_put_contents($tmpFile, $string); $output = array(); $status = 0; $return = exec("{$pdftkPath} {$tmpFile} output {$pdfPath} flatten", $output, $status); if ($status != 0) { throw new \Jazzee\Exception("Problem flattening PDF, return: {$return}, status: {$status}, output was: " . var_export($output, true)); } unlink($tmpFile); } else { $this->_controller->log("You do not have PDFTK installed or you have not set the pdftkPath configuration variable. Some PDFs may be generated without all of their data."); file_put_contents($pdfPath, $string); } $doc = $pdf->open_pdi_document($pdfPath, 'shrug=true'); $contents = $pdf->open_pdi_page($doc, 1, ''); $pdf->fill_pdfblock($page, $blockName, $contents, ''); $pdf->close_pdi_document($doc); unlink($pdfPath); } break; } } } $pdf->end_page_ext(""); $pdf->close_pdi_page($page); } $pdf->end_document(""); $pdf->close_pdi_document($document); return $pdf->get_buffer(); }