Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/passphrase/controller/PassphraseCredentialRevealController.php
12256 views
1
<?php
2
3
final class PassphraseCredentialRevealController
4
extends PassphraseController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
$id = $request->getURIData('id');
9
10
$credential = id(new PassphraseCredentialQuery())
11
->setViewer($viewer)
12
->withIDs(array($id))
13
->requireCapabilities(
14
array(
15
PhabricatorPolicyCapability::CAN_VIEW,
16
PhabricatorPolicyCapability::CAN_EDIT,
17
))
18
->needSecrets(true)
19
->executeOne();
20
if (!$credential) {
21
return new Aphront404Response();
22
}
23
24
$view_uri = $credential->getURI();
25
26
$is_locked = $credential->getIsLocked();
27
28
if ($is_locked) {
29
return $this->newDialog()
30
->setUser($viewer)
31
->setTitle(pht('Credential is locked'))
32
->appendChild(
33
pht(
34
'This credential can not be shown, because it is locked.'))
35
->addCancelButton($view_uri);
36
}
37
38
if ($request->isFormOrHisecPost()) {
39
$secret = $credential->getSecret();
40
if (!$secret) {
41
$body = pht('This credential has no associated secret.');
42
} else if (!strlen($secret->openEnvelope())) {
43
$body = pht('This credential has an empty secret.');
44
} else {
45
$body = id(new PHUIFormLayoutView())
46
->appendChild(
47
id(new AphrontFormTextAreaControl())
48
->setLabel(pht('Plaintext'))
49
->setReadOnly(true)
50
->setCustomClass('PhabricatorMonospaced')
51
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
52
->setValue($secret->openEnvelope()));
53
}
54
55
// NOTE: Disable workflow on the cancel button to reload the page so
56
// the viewer can see that their view was logged.
57
58
$dialog = id(new AphrontDialogView())
59
->setUser($viewer)
60
->setWidth(AphrontDialogView::WIDTH_FORM)
61
->setTitle(pht('Credential Secret (%s)', $credential->getMonogram()))
62
->appendChild($body)
63
->setDisableWorkflowOnCancel(true)
64
->addCancelButton($view_uri, pht('Done'));
65
66
$type_secret = PassphraseCredentialLookedAtTransaction::TRANSACTIONTYPE;
67
$xactions = array(
68
id(new PassphraseCredentialTransaction())
69
->setTransactionType($type_secret)
70
->setNewValue(true),
71
);
72
73
$editor = id(new PassphraseCredentialTransactionEditor())
74
->setActor($viewer)
75
->setCancelURI($view_uri)
76
->setContinueOnNoEffect(true)
77
->setContentSourceFromRequest($request)
78
->applyTransactions($credential, $xactions);
79
80
return id(new AphrontDialogResponse())->setDialog($dialog);
81
}
82
83
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
84
85
if ($is_serious) {
86
$body = pht(
87
'The secret associated with this credential will be shown in plain '.
88
'text on your screen.');
89
} else {
90
$body = pht(
91
'The secret associated with this credential will be shown in plain '.
92
'text on your screen. Before continuing, wrap your arms around '.
93
'your monitor to create a human shield, keeping it safe from '.
94
'prying eyes. Protect company secrets!');
95
}
96
return $this->newDialog()
97
->setUser($viewer)
98
->setTitle(pht('Really show secret?'))
99
->appendChild($body)
100
->addSubmitButton(pht('Show Secret'))
101
->addCancelButton($view_uri);
102
}
103
104
}
105
106