Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
<?php
|
|
|
|
|
2014-04-28 02:31:35 +02:00
|
|
|
final class PhabricatorUserLog extends PhabricatorUserDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
|
|
|
|
const ACTION_LOGIN = 'login';
|
|
|
|
const ACTION_LOGOUT = 'logout';
|
|
|
|
const ACTION_LOGIN_FAILURE = 'login-fail';
|
|
|
|
const ACTION_RESET_PASSWORD = 'reset-pass';
|
|
|
|
|
|
|
|
const ACTION_CREATE = 'create';
|
2012-05-25 16:30:44 +02:00
|
|
|
const ACTION_EDIT = 'edit';
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
|
|
|
|
const ACTION_ADMIN = 'admin';
|
2012-08-29 20:07:29 +02:00
|
|
|
const ACTION_SYSTEM_AGENT = 'system-agent';
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
const ACTION_DISABLE = 'disable';
|
2013-11-13 20:24:18 +01:00
|
|
|
const ACTION_APPROVE = 'approve';
|
2012-06-16 02:02:20 +02:00
|
|
|
const ACTION_DELETE = 'delete';
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
|
2011-06-14 21:17:14 +02:00
|
|
|
const ACTION_CONDUIT_CERTIFICATE = 'conduit-cert';
|
|
|
|
const ACTION_CONDUIT_CERTIFICATE_FAILURE = 'conduit-cert-fail';
|
|
|
|
|
2012-05-25 16:30:44 +02:00
|
|
|
const ACTION_EMAIL_PRIMARY = 'email-primary';
|
|
|
|
const ACTION_EMAIL_REMOVE = 'email-remove';
|
|
|
|
const ACTION_EMAIL_ADD = 'email-add';
|
|
|
|
|
|
|
|
const ACTION_CHANGE_PASSWORD = 'change-password';
|
2012-06-06 16:09:56 +02:00
|
|
|
const ACTION_CHANGE_USERNAME = 'change-username';
|
2012-05-25 16:30:44 +02:00
|
|
|
|
2014-04-28 02:32:09 +02:00
|
|
|
const ACTION_ENTER_HISEC = 'hisec-enter';
|
|
|
|
const ACTION_EXIT_HISEC = 'hisec-exit';
|
|
|
|
|
2014-04-28 18:27:11 +02:00
|
|
|
const ACTION_MULTI_ADD = 'multi-add';
|
|
|
|
const ACTION_MULTI_REMOVE = 'multi-remove';
|
|
|
|
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
protected $actorPHID;
|
|
|
|
protected $userPHID;
|
|
|
|
protected $action;
|
|
|
|
protected $oldValue;
|
|
|
|
protected $newValue;
|
|
|
|
protected $details = array();
|
|
|
|
protected $remoteAddr;
|
|
|
|
protected $session;
|
|
|
|
|
2014-04-28 02:31:35 +02:00
|
|
|
public static function getActionTypeMap() {
|
|
|
|
return array(
|
|
|
|
self::ACTION_LOGIN => pht('Login'),
|
|
|
|
self::ACTION_LOGIN_FAILURE => pht('Login Failure'),
|
|
|
|
self::ACTION_LOGOUT => pht('Logout'),
|
|
|
|
self::ACTION_RESET_PASSWORD => pht('Reset Password'),
|
|
|
|
self::ACTION_CREATE => pht('Create Account'),
|
|
|
|
self::ACTION_EDIT => pht('Edit Account'),
|
|
|
|
self::ACTION_ADMIN => pht('Add/Remove Administrator'),
|
|
|
|
self::ACTION_SYSTEM_AGENT => pht('Add/Remove System Agent'),
|
|
|
|
self::ACTION_DISABLE => pht('Enable/Disable'),
|
|
|
|
self::ACTION_APPROVE => pht('Approve Registration'),
|
|
|
|
self::ACTION_DELETE => pht('Delete User'),
|
|
|
|
self::ACTION_CONDUIT_CERTIFICATE
|
|
|
|
=> pht('Conduit: Read Certificate'),
|
|
|
|
self::ACTION_CONDUIT_CERTIFICATE_FAILURE
|
|
|
|
=> pht('Conduit: Read Certificate Failure'),
|
|
|
|
self::ACTION_EMAIL_PRIMARY => pht('Email: Change Primary'),
|
|
|
|
self::ACTION_EMAIL_ADD => pht('Email: Add Address'),
|
|
|
|
self::ACTION_EMAIL_REMOVE => pht('Email: Remove Address'),
|
|
|
|
self::ACTION_CHANGE_PASSWORD => pht('Change Password'),
|
|
|
|
self::ACTION_CHANGE_USERNAME => pht('Change Username'),
|
2014-04-28 02:32:09 +02:00
|
|
|
self::ACTION_ENTER_HISEC => pht('Hisec: Enter'),
|
|
|
|
self::ACTION_EXIT_HISEC => pht('Hisec: Exit'),
|
2014-04-28 18:27:11 +02:00
|
|
|
self::ACTION_MULTI_ADD => pht('Multi-Factor: Add Factor'),
|
|
|
|
self::ACTION_MULTI_REMOVE => pht('Multi-Factor: Remove Factor'),
|
2014-04-28 02:31:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-14 20:05:26 +01:00
|
|
|
public static function initializeNewLog(
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
PhabricatorUser $actor = null,
|
2014-01-14 20:05:26 +01:00
|
|
|
$object_phid,
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
$action) {
|
|
|
|
|
|
|
|
$log = new PhabricatorUserLog();
|
|
|
|
|
|
|
|
if ($actor) {
|
|
|
|
$log->setActorPHID($actor->getPHID());
|
2014-04-28 02:31:35 +02:00
|
|
|
if ($actor->hasSession()) {
|
|
|
|
$session = $actor->getSession();
|
|
|
|
|
|
|
|
// NOTE: This is a hash of the real session value, so it's safe to
|
|
|
|
// store it directly in the logs.
|
|
|
|
$log->setSession($session->getSessionKey());
|
|
|
|
}
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
}
|
|
|
|
|
2014-01-14 20:05:26 +01:00
|
|
|
$log->setUserPHID((string)$object_phid);
|
|
|
|
$log->setAction($action);
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
|
2014-04-28 02:31:35 +02:00
|
|
|
$log->remoteAddr = idx($_SERVER, 'REMOTE_ADDR', '');
|
|
|
|
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
return $log;
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:17:14 +02:00
|
|
|
public static function loadRecentEventsFromThisIP($action, $timespan) {
|
|
|
|
return id(new PhabricatorUserLog())->loadAllWhere(
|
|
|
|
'action = %s AND remoteAddr = %s AND dateCreated > %d
|
|
|
|
ORDER BY dateCreated DESC',
|
|
|
|
$action,
|
|
|
|
idx($_SERVER, 'REMOTE_ADDR'),
|
|
|
|
time() - $timespan);
|
|
|
|
}
|
|
|
|
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
public function save() {
|
|
|
|
$this->details['host'] = php_uname('n');
|
2013-02-10 00:01:57 +01:00
|
|
|
$this->details['user_agent'] = AphrontRequest::getHTTPHeader('User-Agent');
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'oldValue' => self::SERIALIZATION_JSON,
|
|
|
|
'newValue' => self::SERIALIZATION_JSON,
|
|
|
|
'details' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2014-04-28 02:31:35 +02:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
if ($viewer->getIsAdmin()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$viewer_phid = $viewer->getPHID();
|
|
|
|
if ($viewer_phid) {
|
|
|
|
$user_phid = $this->getUserPHID();
|
|
|
|
if ($viewer_phid == $user_phid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$actor_phid = $this->getActorPHID();
|
|
|
|
if ($viewer_phid == $actor_phid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return array(
|
|
|
|
pht('Users can view their activity and activity that affects them.'),
|
|
|
|
pht('Administrators can always view all activity.'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Provide an activity log for login and administrative actions
Summary: This isn't complete, but I figured I'd ship it for review while it's still smallish.
Provide an activity log for high-level system actions (logins, admin actions). This basically allows two things to happen:
- The log itself is useful if there are shenanigans.
- Password login can check it and start CAPTCHA'ing users after a few failed attempts.
I'm going to change how the admin stuff works a little bit too, since right now you can make someone an agent, grab their certificate, revert them back to a normal user, and then act on their behalf over Conduit. This is a little silly, I'm going to move "agent" to the create workflow instead. I'll also add a confirm/email step to the administrative password reset flow.
Test Plan: Took various administrative and non-administrative actions, they appeared in the logs. Filtered the logs in a bunch of different ways.
Reviewers: jungejason, tuomaspelkonen, aran
CC:
Differential Revision: 302
2011-05-18 03:42:21 +02:00
|
|
|
}
|