mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 19:32:40 +01:00
ef85f49adc
Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in LICENSE file and that it didn't modify externals. Reviewers: epriestley, davidrecordon Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3886
103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
|
|
final class PhabricatorUserLog extends PhabricatorUserDAO {
|
|
|
|
const ACTION_LOGIN = 'login';
|
|
const ACTION_LOGOUT = 'logout';
|
|
const ACTION_LOGIN_FAILURE = 'login-fail';
|
|
const ACTION_RESET_PASSWORD = 'reset-pass';
|
|
|
|
const ACTION_CREATE = 'create';
|
|
const ACTION_EDIT = 'edit';
|
|
|
|
const ACTION_ADMIN = 'admin';
|
|
const ACTION_SYSTEM_AGENT = 'system-agent';
|
|
const ACTION_DISABLE = 'disable';
|
|
const ACTION_DELETE = 'delete';
|
|
|
|
const ACTION_CONDUIT_CERTIFICATE = 'conduit-cert';
|
|
const ACTION_CONDUIT_CERTIFICATE_FAILURE = 'conduit-cert-fail';
|
|
|
|
const ACTION_EMAIL_PRIMARY = 'email-primary';
|
|
const ACTION_EMAIL_REMOVE = 'email-remove';
|
|
const ACTION_EMAIL_ADD = 'email-add';
|
|
|
|
const ACTION_CHANGE_PASSWORD = 'change-password';
|
|
const ACTION_CHANGE_USERNAME = 'change-username';
|
|
|
|
protected $actorPHID;
|
|
protected $userPHID;
|
|
protected $action;
|
|
protected $oldValue;
|
|
protected $newValue;
|
|
protected $details = array();
|
|
protected $remoteAddr;
|
|
protected $session;
|
|
|
|
public static function newLog(
|
|
PhabricatorUser $actor = null,
|
|
PhabricatorUser $user = null,
|
|
$action) {
|
|
|
|
$log = new PhabricatorUserLog();
|
|
|
|
if ($actor) {
|
|
$log->setActorPHID($actor->getPHID());
|
|
}
|
|
|
|
if ($user) {
|
|
$log->setUserPHID($user->getPHID());
|
|
} else {
|
|
$log->setUserPHID('');
|
|
}
|
|
|
|
if ($action) {
|
|
$log->setAction($action);
|
|
}
|
|
|
|
return $log;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public function save() {
|
|
if (!$this->remoteAddr) {
|
|
$this->remoteAddr = idx($_SERVER, 'REMOTE_ADDR', '');
|
|
}
|
|
if (!$this->session) {
|
|
$this->setSession(idx($_COOKIE, 'phsid'));
|
|
}
|
|
$this->details['host'] = php_uname('n');
|
|
$this->details['user_agent'] = idx($_SERVER, 'HTTP_USER_AGENT');
|
|
|
|
return parent::save();
|
|
}
|
|
|
|
public function setSession($session) {
|
|
// Store the hash of the session, not the actual session key, so that
|
|
// seeing the logs doesn't compromise all the sessions which appear in
|
|
// them. This just prevents casual leaks, like in a screenshot.
|
|
if (strlen($session)) {
|
|
$this->session = PhabricatorHash::digest($session);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_SERIALIZATION => array(
|
|
'oldValue' => self::SERIALIZATION_JSON,
|
|
'newValue' => self::SERIALIZATION_JSON,
|
|
'details' => self::SERIALIZATION_JSON,
|
|
),
|
|
) + parent::getConfiguration();
|
|
}
|
|
|
|
}
|