2014-01-14 20:05:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSettingsPanelSessions
|
|
|
|
extends PhabricatorSettingsPanel {
|
|
|
|
|
|
|
|
public function getPanelKey() {
|
|
|
|
return 'sessions';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelName() {
|
|
|
|
return pht('Sessions');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelGroup() {
|
|
|
|
return pht('Authentication');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$accounts = id(new PhabricatorExternalAccountQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withUserPHIDs(array($viewer->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$identity_phids = mpull($accounts, 'getPHID');
|
|
|
|
$identity_phids[] = $viewer->getPHID();
|
|
|
|
|
|
|
|
$sessions = id(new PhabricatorAuthSessionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIdentityPHIDs($identity_phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($identity_phids)
|
|
|
|
->execute();
|
|
|
|
|
2014-01-23 23:01:35 +01:00
|
|
|
$current_key = PhabricatorHash::digest(
|
|
|
|
$request->getCookie(PhabricatorCookies::COOKIE_SESSION));
|
2014-01-14 20:05:45 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
$rowc = array();
|
|
|
|
foreach ($sessions as $session) {
|
|
|
|
if ($session->getSessionKey() == $current_key) {
|
|
|
|
$rowc[] = 'highlighted';
|
2014-03-17 23:02:01 +01:00
|
|
|
$button = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => 'small grey button disabled',
|
|
|
|
),
|
|
|
|
pht('Current'));
|
2014-01-14 20:05:45 +01:00
|
|
|
} else {
|
|
|
|
$rowc[] = null;
|
2014-03-17 23:02:01 +01:00
|
|
|
$button = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/auth/session/terminate/'.$session->getID().'/',
|
|
|
|
'class' => 'small grey button',
|
|
|
|
'sigil' => 'workflow',
|
|
|
|
),
|
|
|
|
pht('Terminate'));
|
2014-01-14 20:05:45 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 02:31:11 +02:00
|
|
|
$hisec = ($session->getHighSecurityUntil() - time());
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$rows[] = array(
|
|
|
|
$handles[$session->getUserPHID()]->renderLink(),
|
2014-03-17 23:02:01 +01:00
|
|
|
substr($session->getSessionKey(), 0, 6),
|
2014-01-14 20:05:45 +01:00
|
|
|
$session->getType(),
|
2014-04-28 02:31:11 +02:00
|
|
|
($hisec > 0)
|
|
|
|
? phabricator_format_relative_time($hisec)
|
|
|
|
: null,
|
2014-01-14 20:05:45 +01:00
|
|
|
phabricator_datetime($session->getSessionStart(), $viewer),
|
2014-03-17 23:02:01 +01:00
|
|
|
phabricator_date($session->getSessionExpires(), $viewer),
|
|
|
|
$button,
|
2014-01-14 20:05:45 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setNoDataString(pht("You don't have any active sessions."));
|
|
|
|
$table->setRowClasses($rowc);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
pht('Identity'),
|
|
|
|
pht('Session'),
|
|
|
|
pht('Type'),
|
2014-04-28 02:31:11 +02:00
|
|
|
pht('HiSec'),
|
2014-01-14 20:05:45 +01:00
|
|
|
pht('Created'),
|
2014-01-15 22:56:16 +01:00
|
|
|
pht('Expires'),
|
2014-03-17 23:02:01 +01:00
|
|
|
pht(''),
|
2014-01-14 20:05:45 +01:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'wide',
|
|
|
|
'n',
|
|
|
|
'',
|
|
|
|
'right',
|
2014-01-15 22:56:16 +01:00
|
|
|
'right',
|
2014-04-28 02:31:11 +02:00
|
|
|
'right',
|
2014-03-17 23:02:01 +01:00
|
|
|
'action',
|
2014-01-14 20:05:45 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
|
2014-03-17 23:02:01 +01:00
|
|
|
$terminate_icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
|
|
|
|
->setSpriteIcon('warning');
|
|
|
|
$terminate_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Terminate All Sessions'))
|
|
|
|
->setHref('/auth/session/terminate/all/')
|
|
|
|
->setTag('a')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setIcon($terminate_icon);
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
2014-03-17 23:02:01 +01:00
|
|
|
->setHeader(pht('Active Login Sessions'))
|
|
|
|
->addActionLink($terminate_button);
|
2014-01-14 20:05:45 +01:00
|
|
|
|
2014-04-28 02:31:11 +02:00
|
|
|
$hisec = ($viewer->getSession()->getHighSecurityUntil() - time());
|
|
|
|
if ($hisec > 0) {
|
|
|
|
$hisec_icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
|
|
|
|
->setSpriteIcon('lock');
|
|
|
|
$hisec_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Leave High Security'))
|
|
|
|
->setHref('/auth/session/downgrade/')
|
|
|
|
->setTag('a')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setIcon($hisec_icon);
|
|
|
|
$header->addActionLink($hisec_button);
|
|
|
|
}
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$panel = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($table);
|
|
|
|
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|