2011-07-18 17:02:00 +02:00
|
|
|
<?php
|
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
final class PhabricatorSettingsPanelConduit
|
|
|
|
extends PhabricatorSettingsPanel {
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelKey() {
|
|
|
|
return 'conduit';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelName() {
|
|
|
|
return pht('Conduit');
|
|
|
|
}
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelGroup() {
|
|
|
|
return pht('Authentication');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest(AphrontRequest $request) {
|
2011-07-18 17:02:00 +02:00
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
if (!$request->isDialogFormPost()) {
|
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog->setUser($user);
|
|
|
|
$dialog->setTitle('Really regenerate session?');
|
2012-08-13 21:37:26 +02:00
|
|
|
$dialog->setSubmitURI($this->getPanelURI());
|
2011-07-18 17:02:00 +02:00
|
|
|
$dialog->addSubmitButton('Regenerate');
|
2012-08-13 21:37:26 +02:00
|
|
|
$dialog->addCancelbutton($this->getPanelURI());
|
2011-07-18 17:02:00 +02:00
|
|
|
$dialog->appendChild(
|
|
|
|
'<p>Really destroy the old certificate? Any established '.
|
|
|
|
'sessions will be terminated.');
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
$conn = $user->establishConnection('w');
|
|
|
|
queryfx(
|
|
|
|
$conn,
|
|
|
|
'DELETE FROM %T WHERE userPHID = %s AND type LIKE %>',
|
|
|
|
PhabricatorUser::SESSION_TABLE,
|
|
|
|
$user->getPHID(),
|
|
|
|
'conduit');
|
|
|
|
|
|
|
|
// This implicitly regenerates the certificate.
|
|
|
|
$user->setConduitCertificate(null);
|
|
|
|
$user->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
2012-08-13 21:37:26 +02:00
|
|
|
->setURI($this->getPanelURI('?regenerated=true'));
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->getStr('regenerated')) {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
|
|
|
$notice->setTitle('Certificate Regenerated');
|
2013-02-07 01:53:49 +01:00
|
|
|
$notice->appendChild(phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(),
|
|
|
|
'Your old certificate has been destroyed and you have been issued '.
|
2011-07-18 17:02:00 +02:00
|
|
|
'a new certificate. Sessions established under the old certificate '.
|
2013-02-07 01:53:49 +01:00
|
|
|
'are no longer valid.'));
|
2011-07-18 17:02:00 +02:00
|
|
|
$notice = $notice->render();
|
|
|
|
} else {
|
|
|
|
$notice = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cert_form = new AphrontFormView();
|
|
|
|
$cert_form
|
|
|
|
->setUser($user)
|
2013-02-07 23:39:04 +01:00
|
|
|
->appendChild(hsprintf(
|
2011-07-18 17:02:00 +02:00
|
|
|
'<p class="aphront-form-instructions">This certificate allows you to '.
|
|
|
|
'authenticate over Conduit, the Phabricator API. Normally, you just '.
|
2013-02-07 23:39:04 +01:00
|
|
|
'run <tt>arc install-certificate</tt> to install it.'))
|
2011-07-18 17:02:00 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel('Certificate')
|
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
|
|
|
|
->setValue($user->getConduitCertificate()));
|
|
|
|
|
|
|
|
$cert = new AphrontPanelView();
|
|
|
|
$cert->setHeader('Arcanist Certificate');
|
|
|
|
$cert->appendChild($cert_form);
|
2013-01-16 16:49:05 +01:00
|
|
|
$cert->setNoBackground();
|
2011-07-18 17:02:00 +02:00
|
|
|
|
|
|
|
$regen_form = new AphrontFormView();
|
|
|
|
$regen_form
|
|
|
|
->setUser($user)
|
2012-08-13 21:37:26 +02:00
|
|
|
->setAction($this->getPanelURI())
|
|
|
|
->setWorkflow(true)
|
2013-02-07 23:39:04 +01:00
|
|
|
->appendChild(hsprintf(
|
2011-07-18 17:02:00 +02:00
|
|
|
'<p class="aphront-form-instructions">You can regenerate this '.
|
|
|
|
'certificate, which will invalidate the old certificate and create '.
|
2013-02-07 23:39:04 +01:00
|
|
|
'a new one.</p>'))
|
2011-07-18 17:02:00 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Regenerate Certificate'));
|
|
|
|
|
|
|
|
$regen = new AphrontPanelView();
|
|
|
|
$regen->setHeader('Regenerate Certificate');
|
|
|
|
$regen->appendChild($regen_form);
|
2013-01-16 16:49:05 +01:00
|
|
|
$regen->setNoBackground();
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
return array(
|
|
|
|
$notice,
|
|
|
|
$cert,
|
|
|
|
$regen,
|
|
|
|
);
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|