Beispiel #1
0
 /**
  * Handles AJAX from /logs.
  * Used to delete logs.
  */
 public function ajax_delete_logs($handler_vars)
 {
     Utils::check_request_method(array('POST'));
     $count = 0;
     $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
     if ($handler_vars['digest'] != $wsse['digest']) {
         Session::error(_t('WSSE authentication failed.'));
         echo Session::messages_get(true, array('Format', 'json_messages'));
         return;
     }
     foreach ($_POST as $id => $delete) {
         // skip POST elements which are not log ids
         if (preg_match('/^p\\d+$/', $id) && $delete) {
             $id = (int) substr($id, 1);
             $ids[] = array('id' => $id);
         }
     }
     if ((!isset($ids) || empty($ids)) && $handler_vars['action'] != 'purge') {
         Session::notice(_t('No logs selected.'));
         echo Session::messages_get(true, array('Format', 'json_messages'));
         return;
     }
     switch ($handler_vars['action']) {
         case 'delete':
             $to_delete = EventLog::get(array('date' => 'any', 'where' => $ids, 'nolimit' => 1));
             foreach ($to_delete as $log) {
                 $log->delete();
                 $count++;
             }
             Session::notice(_t('Deleted %d logs.', array($count)));
             break;
         case 'purge':
             $result = EventLog::purge();
             Session::notice(_t('Logs purged.'));
             break;
     }
     echo Session::messages_get(true, array('Format', 'json_messages'));
 }
Beispiel #2
0
 private function fetch_logs()
 {
     // load all the values for our filter drop-downs
     $dates = $this->fetch_log_dates();
     $users = $this->fetch_log_users();
     $ips = $this->fetch_log_ips();
     extract($this->fetch_log_modules_types());
     // $modules and $types
     $severities = LogEntry::list_severities();
     // parse out the arguments we'll fetch logs for
     // the initial arguments
     $arguments = array('limit' => Controller::get_var('limit', 20), 'offset' => Controller::get_var('offset', 0));
     // filter for the search field
     $search = Controller::get_var('search', '');
     if ($search != '') {
         $arguments['criteria'] = $search;
     }
     // filter by date
     $date = Controller::get_var('date', 'any');
     if ($date != 'any') {
         $d = DateTime::create($date);
         // ! means fill any non-specified pieces with default Unix Epoch ones
         $arguments['year'] = $d->format('Y');
         $arguments['month'] = $d->format('m');
     }
     // filter by user
     $user = Controller::get_var('user', 'any');
     if ($user != 'any') {
         $arguments['user_id'] = $user;
     }
     // filter by ip
     $ip = Controller::get_var('address', 'any');
     if ($ip != 'any') {
         $arguments['ip'] = $ip;
     }
     // filter modules and types
     // @todo get events of a specific type in a specific module, instead of either of the two
     // the interface doesn't currently make any link between module and type, so we won't worry about it for now
     $module = Controller::get_var('module', 'any');
     $type = Controller::get_var('type', 'any');
     if ($module != 'any') {
         // we get a slugified key back, get the actual module name
         $arguments['module'] = $modules[$module];
     }
     if ($type != 'any') {
         // we get a slugified key back, get the actual type name
         $arguments['type'] = $types[$type];
     }
     // filter by severity
     $severity = Controller::get_var('severity', 0);
     if ($severity != 0) {
         $arguments['severity'] = $severity;
     }
     // get the logs!
     $logs = EventLog::get($arguments);
     // last, but not least, generate the list of years used for the timeline
     $months = EventLog::get(array_merge($arguments, array('month_cts' => true)));
     $years = array();
     foreach ($months as $m) {
         $years[$m->year][] = $m;
     }
     // assign all our theme values in one spot
     // first the filter options
     $this->theme->dates = $dates;
     $this->theme->users = $users;
     $this->theme->addresses = $ips;
     $this->theme->modules = $modules;
     $this->theme->types = $types;
     $this->theme->severities = $severities;
     // next the filter criteria we used
     $this->theme->search_args = $search;
     $this->theme->date = $date;
     $this->theme->user = $user;
     $this->theme->address = $ip;
     $this->theme->module = $module;
     $this->theme->type = $type;
     $this->theme->severity = $severity;
     $this->theme->logs = $logs;
     $this->theme->years = $years;
     $form = new FormUI('logs_batch', 'logs_batch');
     $form->append(FormControlAggregate::create('entries')->set_selector('.log_entry')->set_value(array())->label('None Selected'));
     $form->append($actions = FormControlDropbutton::create('actions'));
     $actions->append(FormControlSubmit::create('delete_selected')->on_success(function (FormUI $form) {
         $ids = $form->entries->value;
         $count = 0;
         /** @var LogEntry $log */
         foreach ($ids as $id) {
             $logs = EventLog::get(array('id' => $id));
             foreach ($logs as $log) {
                 $log->delete();
                 $count++;
             }
         }
         Session::notice(_t('Deleted %d logs.', array($count)));
         $form->bounce(false);
     })->set_caption(_t('Delete Selected')));
     $actions->append(FormControlSubmit::create('purge_logs')->on_success(function (FormUI $form) {
         if (EventLog::purge()) {
             Session::notice(_t('Logs purged.'));
         } else {
             Session::notice(_t('There was a problem purging the event logs.'));
         }
         $form->bounce(false);
     })->set_caption(_t('Purge Logs')));
     $this->theme->form = $form;
     $this->theme->wsse = Utils::WSSE();
     // prepare a WSSE token for any ajax calls
 }