Path: blob/master/src/applications/passphrase/controller/PassphraseCredentialRevealController.php
12256 views
<?php12final class PassphraseCredentialRevealController3extends PassphraseController {45public function handleRequest(AphrontRequest $request) {6$viewer = $request->getViewer();7$id = $request->getURIData('id');89$credential = id(new PassphraseCredentialQuery())10->setViewer($viewer)11->withIDs(array($id))12->requireCapabilities(13array(14PhabricatorPolicyCapability::CAN_VIEW,15PhabricatorPolicyCapability::CAN_EDIT,16))17->needSecrets(true)18->executeOne();19if (!$credential) {20return new Aphront404Response();21}2223$view_uri = $credential->getURI();2425$is_locked = $credential->getIsLocked();2627if ($is_locked) {28return $this->newDialog()29->setUser($viewer)30->setTitle(pht('Credential is locked'))31->appendChild(32pht(33'This credential can not be shown, because it is locked.'))34->addCancelButton($view_uri);35}3637if ($request->isFormOrHisecPost()) {38$secret = $credential->getSecret();39if (!$secret) {40$body = pht('This credential has no associated secret.');41} else if (!strlen($secret->openEnvelope())) {42$body = pht('This credential has an empty secret.');43} else {44$body = id(new PHUIFormLayoutView())45->appendChild(46id(new AphrontFormTextAreaControl())47->setLabel(pht('Plaintext'))48->setReadOnly(true)49->setCustomClass('PhabricatorMonospaced')50->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)51->setValue($secret->openEnvelope()));52}5354// NOTE: Disable workflow on the cancel button to reload the page so55// the viewer can see that their view was logged.5657$dialog = id(new AphrontDialogView())58->setUser($viewer)59->setWidth(AphrontDialogView::WIDTH_FORM)60->setTitle(pht('Credential Secret (%s)', $credential->getMonogram()))61->appendChild($body)62->setDisableWorkflowOnCancel(true)63->addCancelButton($view_uri, pht('Done'));6465$type_secret = PassphraseCredentialLookedAtTransaction::TRANSACTIONTYPE;66$xactions = array(67id(new PassphraseCredentialTransaction())68->setTransactionType($type_secret)69->setNewValue(true),70);7172$editor = id(new PassphraseCredentialTransactionEditor())73->setActor($viewer)74->setCancelURI($view_uri)75->setContinueOnNoEffect(true)76->setContentSourceFromRequest($request)77->applyTransactions($credential, $xactions);7879return id(new AphrontDialogResponse())->setDialog($dialog);80}8182$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');8384if ($is_serious) {85$body = pht(86'The secret associated with this credential will be shown in plain '.87'text on your screen.');88} else {89$body = pht(90'The secret associated with this credential will be shown in plain '.91'text on your screen. Before continuing, wrap your arms around '.92'your monitor to create a human shield, keeping it safe from '.93'prying eyes. Protect company secrets!');94}95return $this->newDialog()96->setUser($viewer)97->setTitle(pht('Really show secret?'))98->appendChild($body)99->addSubmitButton(pht('Show Secret'))100->addCancelButton($view_uri);101}102103}104105106