.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
class AuditComponent extends Object {
var $controller;
/**
* Save a reference to the controller on startup
* @param object &$controller the controller using this component
*/
function startup(&$controller) {
$this->controller =& $controller;
}
/**
* Helper for creating an HTML link.
*/
function link($title, $url) {
return "controller->url($url)}\">{$title}";
}
/**
* Helper for creating a link where the title is the end of the URL.
* NOTE: $urlBase should have a trailing slash.
*/
function linkTitle($id, $urlBase) {
return $this->link($id, $urlBase.$id);
}
function explainLog($logs) {
$newLog = array();
if (!empty($logs)) {
foreach ($logs as $log) {
$userInfo = $this->controller->User->findById($log['Eventlog']['user_id'], null, null, -1);
$user = $this->link($userInfo['User']['firstname'].' '.$userInfo['User']['lastname'], '/users/info/'.$log['Eventlog']['user_id']);
switch ($log['Eventlog']['type']) {
case 'admin':
switch ($log['Eventlog']['action']) {
case 'addon_status':
$status = $this->controller->Amo->getApprovalStatus($log['Eventlog']['added']);
$addonInfo = $this->controller->Addon->findById($log['Eventlog']['changed_id'], null, null, -1);
$addon = $this->link($addonInfo['Translation']['name']['string'], '/admin/addons/status/'.$log['Eventlog']['changed_id']);
$entry = "{$user} changed the status of {$addon} to {$status}";
break;
case 'file_recalchash':
$entry = "{$user} recalculated the hash for file {$log['Eventlog']['changed_id']}";
break;
case 'application_create':
case 'application_edit':
$applicationInfo = $this->controller->Application->findById($log['Eventlog']['changed_id'], null, null, -1);
$application = $this->link($applicationInfo['Translation']['name']['string'], '/admin/applications');
if ($log['Eventlog']['action'] == 'application_create') {
$entry = "{$user} created application {$application}";
}
elseif ($log['Eventlog']['action'] == 'application_edit') {
$entry = "{$user} edited application {$application}";
}
break;
case 'appversion_create':
case 'appversion_delete':
$applicationInfo = $this->controller->Application->findById($log['Eventlog']['notes'], null, null, -1);
$application = $this->link($applicationInfo['Translation']['name']['string'], '/admin/applications');
if ($log['Eventlog']['action'] == 'appversion_create') {
$entry = "{$user} created version {$log['Eventlog']['added']} for {$application}";
}
elseif ($log['Eventlog']['action'] == 'appversion_delete') {
$entry = "{$user} deleted version {$log['Eventlog']['removed']} for {$application}";
}
break;
case 'tag_create':
case 'tag_edit':
$tagInfo = $this->controller->Tag->findById($log['Eventlog']['changed_id'], null, null, -1);
$tag = $this->link($tagInfo['Translation']['name']['string'], '/admin/tags');
if ($log['Eventlog']['action'] == 'tag_create') {
$entry = "{$user} created tag {$tag}";
}
elseif ($log['Eventlog']['action'] == 'tag_edit') {
$entry = "{$user} edited category {$tag}";
}
break;
case 'tag_delete':
$entry = "{$user} deleted category {$log['Eventlog']['removed']} (ID {$log['Eventlog']['changed_id']})";
break;
case 'platform_create':
case 'platform_edit':
$platformInfo = $this->controller->Platform->findById($log['Eventlog']['changed_id'], null, null, -1);
$platform = $this->link($platformInfo['Translation']['name']['string'], '/admin/platforms');
if ($log['Eventlog']['action'] == 'platform_create') {
$entry = "{$user} created platform {$platform}";
}
elseif ($log['Eventlog']['action'] == 'platform_edit') {
$entry = "{$user} edited platform {$platform}";
}
break;
case 'platform_delete':
$entry = "{$user} deleted platform {$log['Eventlog']['removed']} (ID {$log['Eventlog']['changed_id']})";
break;
case 'feature_add':
case 'feature_edit':
$featureInfo = $this->controller->Feature->findById($log['Eventlog']['changed_id'], null, null, -1);
$entry = "{$user} changed a feature for {$featureInfo['Feature']['locale']} locale";
break;
case 'feature_remove':
$entry = "{$user} removed feature {$log['Eventlog']['removed']}";
break;
case 'group_create':
case 'group_edit':
$groupInfo = $this->controller->Group->findById($log['Eventlog']['changed_id'], null, null, -1);
$group = $this->link($groupInfo['Group']['name'], '/admin/groups');
if ($log['Eventlog']['action'] == 'group_create') {
$entry = "{$user} created group {$group}";
}
elseif ($log['Eventlog']['action'] == 'group_edit') {
$entry = "{$user} edited group {$group}";
}
break;
case 'group_delete':
$entry = "{$user} deleted group {$log['Eventlog']['removed']} (ID {$log['Eventlog']['changed_id']})";
break;
case 'group_addmember':
case 'group_removemember':
$groupInfo = $this->controller->Group->findById($log['Eventlog']['changed_id'], null, null, -1);
$group = $this->link($groupInfo['Group']['name'], '/admin/groups');
if ($log['Eventlog']['action'] == 'group_addmember') {
$memberInfo = $this->controller->User->findById($log['Eventlog']['added'], null, null, -1);
$member = $this->link($memberInfo['User']['firstname'].' '.$memberInfo['User']['lastname'], '/admin/users/'.$log['Eventlog']['added']);
$entry = "{$user} added {$member} to group {$group}";
}
elseif ($log['Eventlog']['action'] == 'group_removemember') {
$memberInfo = $this->controller->User->findById($log['Eventlog']['removed'], null, null, -1);
$member = $this->link($memberInfo['User']['firstname'].' '.$memberInfo['User']['lastname'], '/admin/users/'.$log['Eventlog']['removed']);
$entry = "{$user} removed {$member} from group {$group}";
}
break;
case 'response_create':
case 'response_edit':
$responseInfo = $this->controller->Cannedresponse->findById($log['Eventlog']['changed_id'], null, null, -1);
$response = $this->link($responseInfo['Translation']['name']['string'], '/admin/responses');
if ($log['Eventlog']['action'] == 'response_create') {
$entry = "{$user} created response {$response}";
}
elseif ($log['Eventlog']['action'] == 'response_edit') {
$entry = "{$user} edited response {$response}";
}
break;
case 'response_delete':
$entry = "{$user} deleted response {$log['Eventlog']['removed']} (ID {$log['Eventlog']['changed_id']})";
break;
case 'config':
$entry = "{$user} changed config '{$log['Eventlog']['field']}' from '{$log['Eventlog']['removed']}' to '{$log['Eventlog']['added']}'";
break;
case 'user_edit':
$userInfo = $this->controller->User->findById($log['Eventlog']['changed_id'], null, null, -1);
$userLink = $this->link($userInfo['User']['firstname'].' '.$userInfo['User']['lastname'], '/admin/users/'.$log['Eventlog']['changed_id']);
$entry = "{$user} edited {$userLink}'s user information";
break;
default:
$entry = "{$user} committed unknown admin action {$log['Eventlog']['action']} to ID {$log['Eventlog']['changed_id']}";
break;
}
break;
case 'editor':
switch ($log['Eventlog']['action']) {
case 'feature_add':
$addonLink = $this->linkTitle($log['Eventlog']['added'], '/addon/');
$entry = "{$user} added addon {$addonLink} to feature list";
break;
case 'feature_remove':
$addonLink = $this->linkTitle($log['Eventlog']['removed'], '/addon/');
$entry = "{$user} removed addon {$addonLink} from feature list";
break;
case 'feature_locale_change':
$addonLink = $this->linkTitle($log['Eventlog']['changed_id'], '/addon/');
$entry = "{$user} changed locales for addon {$addonLink} on feature list";
break;
case 'review_approve':
$entry = "{$user} approved review {$log['Eventlog']['changed_id']}";
break;
case 'review_delete':
if ($this->controller->SimpleAcl->actionAllowed('Admin', 'logs', $this->controller->Session->read('User'))) {
$entry = "{$user} deleted review ".$this->link($log['Eventlog']['changed_id'], "/admin/logs/{$log['Eventlog']['id']}");
}
else {
$entry = "{$user} deleted review {$log['Eventlog']['changed_id']}";
}
break;
default:
$entry = "{$user} committed unknown editor action {$log['Eventlog']['action']} to ID {$log['Eventlog']['changed_id']}";
break;
}
break;
case 'l10n':
switch ($log['Eventlog']['action']) {
case 'update_applications':
$entry = "{$user} updated application translations for ".$this->linkTitle($log['Eventlog']['notes'], "/localizers/applications/?userlang=");
break;
case 'update_tags':
$entry = "{$user} updated category translations for ".$this->linkTitle($log['Eventlog']['notes'], "/localizers/tags/?userlang=");
break;
case 'update_platforms':
$entry = "{$user} updated platform translations for ".$this->linkTitle($log['Eventlog']['notes'], "/localizers/platforms/?userlang=");
break;
case 'update_blog':
$entry = "{$user} updated blog post translations for ".$this->linkTitle($log['Eventlog']['notes'], "/localizers/platforms/?userlang=");
break;
default:
$entry = "{$user} committed unknown action {$log['Eventlog']['action']} for {$log['Eventlog']['notes']}";
break;
}
break;
case 'security':
switch ($log['Eventlog']['action']) {
case 'reauthentication_failure':
$entry = "{$user} failed to re-authenticate to access {$log['Eventlog']['notes']}.";
break;
case 'modify_locked_group':
$groupInfo = $this->controller->Group->findById($log['Eventlog']['changed_id'], null, null, -1);
$group = $this->link($groupInfo['Group']['name'], '/admin/groups');
$entry = "{$user} attempted to modify locked group {$group}";
break;
case 'modify_other_locale':
$entry = "{$user} attempted to modify translations in {$log['Eventlog']['notes']} without permission";
break;
default:
$entry = "{$user} committed unknown security action {$log['Eventlog']['action']} to ID {$log['Eventlog']['changed_id']}";
break;
}
break;
case 'user':
switch ($log['Eventlog']['action']) {
case 'group_associated':
$groupInfo = $this->controller->Group->findById($log['Eventlog']['changed_id'], null, null, -1);
$group = $this->link($groupInfo['Group']['name'], '/admin/groups');
$entry = "{$user} associated themselves with {$group}";
break;
}
break;
default:
break;
}
$newLog[] = array(
'time' => $log['Eventlog']['created'],
'entry' => $entry
);
}
}
return $newLog;
}
}
?>