Пример #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 
    }
Пример #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']));
 }