Example #1
0
    public function RenderWidget()
    {
        $query = new WSAL_Models_OccurrenceQuery();
        $bid = (int) $this->get_view_site_id();
        if ($bid) {
            $query->addCondition("site_id = %s ", $bid);
        }
        $query->addOrderBy("created_on", true);
        $query->setLimit($this->_plugin->settings->GetDashboardWidgetMaxAlerts());
        $results = $query->getAdapter()->Execute($query);
        ?>
<div><?php 
        if (!count($results)) {
            ?>
<p><?php 
            _e('No alerts found.', 'wp-security-audit-log');
            ?>
</p><?php 
        } else {
            ?>
<table class="wp-list-table widefat" cellspacing="0" cellpadding="0"
                       style="display: block; overflow-x: auto;">
                    <thead>
                        <th class="manage-column" style="width: 15%;" scope="col"><?php 
            _e('User', 'wp-security-audit-log');
            ?>
</th>
                        <th class="manage-column" style="width: 85%;" scope="col"><?php 
            _e('Description', 'wp-security-audit-log');
            ?>
</th>
                    </thead>
                    <tbody><?php 
            $url = 'admin.php?page=' . $this->_plugin->views->views[0]->GetSafeViewName();
            $fmt = array(new WSAL_AuditLogListView($this->_plugin), 'meta_formatter');
            foreach ($results as $entry) {
                ?>
<tr>
                                <td><?php 
                echo ($un = $entry->GetUsername()) ? esc_html($un) : '<i>unknown</i>';
                ?>
</td>
                                <td>
                                    <a href="<?php 
                echo $url . '#Event' . $entry->id;
                ?>
"><?php 
                echo $entry->GetMessage($fmt);
                ?>
</a>
                                </td>
                            </tr><?php 
            }
            ?>
</tbody>
                </table><?php 
        }
        ?>
</div><?php 
    }
Example #2
0
 public function CleanUp()
 {
     $now = current_time('timestamp');
     $max_sdate = $this->plugin->settings->GetPruningDate();
     $max_count = $this->plugin->settings->GetPruningLimit();
     $is_date_e = $this->plugin->settings->IsPruningDateEnabled();
     $is_limt_e = $this->plugin->settings->IsPruningLimitEnabled();
     if (!$is_date_e && !$is_limt_e) {
         return;
     }
     // pruning disabled
     $occ = new WSAL_Models_Occurrence();
     $cnt_items = $occ->Count();
     // Check if there is something to delete
     if ($is_limt_e && $cnt_items < $max_count) {
         return;
     }
     $max_stamp = $now - (strtotime($max_sdate) - $now);
     $max_items = (int) max($cnt_items - $max_count + 1, 0);
     $query = new WSAL_Models_OccurrenceQuery();
     $query->addOrderBy("created_on", false);
     // TO DO Fixing data
     if ($is_date_e) {
         $query->addCondition('created_on <= %s', intval($max_stamp));
     }
     if ($is_limt_e) {
         $query->setLimit($max_items);
     }
     if ($max_items - 1 == 0) {
         return;
     }
     // nothing to delete
     $result = $query->getAdapter()->GetSqlDelete($query);
     $deletedCount = $query->getAdapter()->Delete($query);
     if ($deletedCount == 0) {
         return;
     }
     // nothing to delete
     // keep track of what we're doing
     $this->plugin->alerts->Trigger(03, array('Message' => 'Running system cleanup.', 'Query SQL' => $result['sql'], 'Query Args' => $result['args']), true);
     // notify system
     do_action('wsal_prune', $deletedCount, vsprintf($result['sql'], $result['args']));
 }
 public function prepare_items()
 {
     $per_page = $this->_plugin->settings->GetViewPerPage();
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     //$this->process_bulk_action();
     //TO DO: Get rid of OccurrenceQuery and use the Occurence Model
     $query = new WSAL_Models_OccurrenceQuery();
     $bid = (int) $this->get_view_site_id();
     if ($bid) {
         $query->addCondition("site_id = %s ", $bid);
     }
     $query = apply_filters('wsal_auditlog_query', $query);
     $total_items = $query->getAdapter()->Count($query);
     if (empty($_REQUEST["orderby"])) {
         $query->addOrderBy("created_on", true);
     } else {
         $orderByField = $_REQUEST["orderby"];
         $isDescending = true;
         if (!empty($_REQUEST['order']) && $_REQUEST["order"] == "asc") {
             $isDescending = false;
         }
         //TO DO: Allow order by meta values
         if ($orderByField == "scip") {
             $query->addMetaJoin();
             $query->addOrderBy('CASE WHEN meta.name = "ClientIP" THEN meta.value END', $isDescending);
         } else {
             if ($orderByField == "user") {
                 $query->addMetaJoin();
                 $query->addOrderBy('CASE WHEN meta.name = "CurrentUserID" THEN meta.value END', $isDescending);
             } else {
                 $tmp = new WSAL_Models_Occurrence();
                 //Making sure the field exists to order by
                 if (isset($tmp->{$orderByField})) {
                     // TODO we used to use a custom comparator ... is it safe to let MySQL do the ordering now?
                     $query->addOrderBy($_REQUEST["orderby"], $isDescending);
                 } else {
                     $query->addOrderBy("created_on", true);
                 }
             }
         }
     }
     /** @todo Modify $query instead */
     /** @deprecated */
     //$data = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page);
     $query->setOffset(($this->get_pagenum() - 1) * $per_page);
     $query->setLimit($per_page);
     $this->items = $query->getAdapter()->Execute($query);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }