/** * Add a new personal root certificate to the users' trust store * * @NoAdminRequired * @NoSubadminRequired * @return array */ public function addPersonalRootCertificate() { if ($this->isCertificateImportAllowed() === false) { return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN); } $file = $this->request->getUploadedFile('rootcert_import'); if (empty($file)) { return new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY); } try { $certificate = $this->certificateManager->addCertificate(file_get_contents($file['tmp_name']), $file['name']); return new DataResponse(['name' => $certificate->getName(), 'commonName' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), 'validFrom' => $certificate->getIssueDate()->getTimestamp(), 'validTill' => $certificate->getExpireDate()->getTimestamp(), 'validFromString' => $this->l10n->l('date', $certificate->getIssueDate()), 'validTillString' => $this->l10n->l('date', $certificate->getExpireDate()), 'issuer' => $certificate->getIssuerName(), 'issuerOrganization' => $certificate->getIssuerOrganization()]); } catch (\Exception $e) { return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY); } }
/** * Add a new personal root certificate to the users' trust store * * @NoAdminRequired * @NoSubadminRequired * @return array */ public function addPersonalRootCertificate() { $headers = []; if ($this->request->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE_8])) { // due to upload iframe workaround, need to set content-type to text/plain $headers['Content-Type'] = 'text/plain'; } if ($this->isCertificateImportAllowed() === false) { return new DataResponse(['message' => 'Individual certificate management disabled'], Http::STATUS_FORBIDDEN, $headers); } $file = $this->request->getUploadedFile('rootcert_import'); if (empty($file)) { return new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY, $headers); } try { $certificate = $this->certificateManager->addCertificate(file_get_contents($file['tmp_name']), $file['name']); return new DataResponse(['name' => $certificate->getName(), 'commonName' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), 'validFrom' => $certificate->getIssueDate()->getTimestamp(), 'validTill' => $certificate->getExpireDate()->getTimestamp(), 'validFromString' => $this->l10n->l('date', $certificate->getIssueDate()), 'validTillString' => $this->l10n->l('date', $certificate->getExpireDate()), 'issuer' => $certificate->getIssuerName(), 'issuerOrganization' => $certificate->getIssuerOrganization()], Http::STATUS_OK, $headers); } catch (\Exception $e) { return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY, $headers); } }
protected function execute(InputInterface $input, OutputInterface $output) { $outputType = $input->getOption('output'); if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { $certificates = array_map(function (ICertificate $certificate) { return ['name' => $certificate->getName(), 'common_name' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), 'expire' => $certificate->getExpireDate()->format(\DateTime::ATOM), 'issuer' => $certificate->getIssuerName(), 'issuer_organization' => $certificate->getIssuerOrganization(), 'issue_date' => $certificate->getIssueDate()->format(\DateTime::ATOM)]; }, $this->certificateManager->listCertificates()); if ($outputType === self::OUTPUT_FORMAT_JSON) { $output->writeln(json_encode(array_values($certificates))); } else { $output->writeln(json_encode(array_values($certificates), JSON_PRETTY_PRINT)); } } else { $table = new Table($output); $table->setHeaders(['File Name', 'Common Name', 'Organization', 'Valid Until', 'Issued By']); $rows = array_map(function (ICertificate $certificate) { return [$certificate->getName(), $certificate->getCommonName(), $certificate->getOrganization(), $this->l->l('date', $certificate->getExpireDate()), $certificate->getIssuerName()]; }, $this->certificateManager->listCertificates()); $table->setRows($rows); $table->render(); } }
/** * create mail body for plain text and html mail * * @param string $filename the shared file * @param string $link link to the shared file * @param int $expiration expiration date (timestamp) * @return array an array of the html mail body and the plain text mail body */ private function createMailBody($filename, $link, $expiration) { $formattedDate = $expiration ? $this->l->l('date', $expiration) : null; $html = new \OC_Template("core", "mail", ""); $html->assign('link', $link); $html->assign('user_displayname', $this->senderDisplayName); $html->assign('filename', $filename); $html->assign('expiration', $formattedDate); $htmlMail = $html->fetchPage(); $plainText = new \OC_Template("core", "altmail", ""); $plainText->assign('link', $link); $plainText->assign('user_displayname', $this->senderDisplayName); $plainText->assign('filename', $filename); $plainText->assign('expiration', $formattedDate); $plainTextMail = $plainText->fetchPage(); return [$htmlMail, $plainTextMail]; }