Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/tools/components/bans.php
Строк: 178
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_tools_bans
{
    private 
$db;
    private 
$option;
    private 
$filter;
    public function 
__construct()
    {
        
$this->db        VF::factory('database');
        
$this->filter    VF::factory('filter');
        
$this->option    = array(
            
'ip' => '''reason' => '''expire' => '''sort' => 'ip''order' => 'DESC''display' => 20
        
);
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        if (isset(
$_POST['action']) && isset($_POST['ban_id'])) {
            
$action    trim($_POST['action']);
            
$ban_id    = (int) trim($_POST['ban_id']);
            if (
$ban_id) {
                if (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__ban WHERE ban_id = ".$ban_id." LIMIT 1");
                    
$messages[] = 'Ban removed!';
                } else {
                    
$errors[]    = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[]    = 'Invalid id! Are you sure this ip exists!?';
            }
        }
        
        if (isset(
$_POST['submit_actions'])) {
            
$ids $this->get_checkbox_ids();
            if (
$ids) {
                
$action    trim($_POST['action']);
                if (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__ban WHERE ban_id IN (".implode(','$ids).")");
                    
$messages[] = 'Selects ips unbaned!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'Please select at least one id to unban!';
            }
        }
        
        
$ban        = array('ip' => '''reason' => '''expire' => '''submitted' => FALSE);
        if (isset(
$_POST['submit_add_ban'])) {
            
$ip        $this->filter->get('ip');
            
$reason    $this->filter->get('reason');
            
$expire    $this->filter->get('expire');
            
            if (
$ip == '') {
                
$errors[]    = 'Please enter the banned ip!';
            } elseif (!
VValid::ip($ip)) {
                
$errors[]   = 'Ip is not a valid ip address!';
            } else {
                
$ip_long sprintf('%u'ip2long($ip));
                
$this->db->query("SELECT ip FROM #__ban WHERE ip = ".$ip_long." LIMIT 1");
                if (
$this->db->affected_rows()) {
                    
$errors[] = 'Ip is already banned!';
                } else {
                    
$ban['ip']     = $ip;
                }
            }
            
            if (
$reason == '') {
                
$errors[]    = 'Please enter ban reason (used for searching)!';
            } elseif (
strlen($reason) > 255) {
                
$errors[]    = 'Ban reason can contain maximum 255 characters!';
            } else {
                
$ban['reason']    = $reason;
            }
            
            if (
$expire != '' AND $expire != 'never') {
                
$expire_time strtotime($expire);
                if (!
$expire_time) {
                    
$errors[]    = 'Expire date is not a valid date (use: yyyy-mm-dd)!';
                } elseif (
$expire_time time()) {
                    
$errors[]    = 'Expire date is in the past!';
                } else {
                    
$ban['expire'] = $expire;
                }
            }
            
            
$ban['submitted'] = TRUE;
            
            if (!
$errors) {
                
$exp $expire;
                if (
$exp == '' OR $exp == 'never') {
                  
$exp date('Y-m-d'mktime(000112037));
                }
            
                
$this->db->query("INSERT INTO #__ban
                                  SET ip = "
.$ip_long.",
                                      reason = '"
.$this->db->escape($reason)."',
                                      expire = '"
.$this->db->escape($exp)."',
                                      add_date = '"
.date('Y-m-d h:i:s')."'");
                
$messages[] = 'Ban added!';
            }
        }
    
        if (isset(
$_SESSION['search_ban_option']) &&
            !isset(
$_POST['submit_reset'])) {
            
$this->option $_SESSION['search_ban_option'];
        }
    
        
$page            = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
        
$search         $this->search_bans();
        
$total_bans       $this->db->get_field($search['sql_count'], 'total_bans');
        
$pagination     VPagination::get($page$total_bans$search['display']);
        
$bans             $this->db->get_rows($search['sql'].' LIMIT '.$pagination['limit']);
    
        
$tpl    VF::factory('template');
        
$tpl->menu            'tools';
        
$tpl->submenu        'bans';
        
$tpl->meta_title    'Admin::Tools::Bans';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->option        $this->option;
        
$tpl->ban            $ban;
        
$tpl->bans            $bans;
        
$tpl->pagination    $pagination;
        
$tpl->load(array('header''tools_bans''footer'));
        
$tpl->display();
    }
    
    private function 
search_bans()
    {
        
$sql        'SELECT * FROM #__ban';
        
$sql_count    'SELECT COUNT(ip) AS total_bans FROM #__ban';
        
$sql_add    ' WHERE';
        if (isset(
$_POST['submit_search'])) {
            
$this->option['ip']            = $this->filter->get('ip');
            
$this->option['reason']        = $this->filter->get('reason');
            
$this->option['expire']        = $this->filter->get('expire');
            
$this->option['sort']        = $this->filter->get('sort');
            
$this->option['order']        = ($_POST['order'] == 'ASC') ? 'ASC' 'DESC';
            
$this->option['display']    = (int) trim($_POST['display']);
        }
        
        if (
$this->option['ip'] != '') {
            if (
VValid::ip($this->option['ip'])) {
                
$ip_long     sprintf('%u'ip2long($this->option['ip']));
                
$sql        .= $sql_add.' ip = '.$ip_long;
                
$sql_count    .= $sql_add.' ip = '.$ip_long;
                
$sql_add     ' AND';
            } else {
                
$this->option['ip'] = '';
            }
        }
        
        if (
$this->option['reason'] != '') {
            
$sql        .= $sql_add.' reason LIKE '%'.$this->db->escape($this->option['reason']).'%'';
            
$sql_count    .= $sql_add.' reason LIKE '%'.$this->db->escape($this->option['reason']).'%'';
            
$sql_add     ' AND';
        }
        
        if (
$this->option['expire'] != '') {
            if (
strtotime($this->option['expire']) AND strlen($this->option['expire']) !== 9) {
                
$sql        .= $sql_add.' expire > ''.$this->db->escape($this->option['expire']).''';
                
$sql_count    .= $sql_add.' expire > ''.$this->db->escape($this->option['expire']).''';
            } else {
                
$this->option['expire'] = '';
            }
        }
        
        
$_SESSION['search_ban_option'] = $this->option;
        
        return array(
            
'sql'        => $sql.' ORDER BY '.$this->db->escape($this->option['sort']).' '.$this->db->escape($this->option['order']),
            
'sql_count'    => $sql_count,
            
'display'     => 20
        
);
    }

    private function 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key'checkbox_ban_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_ban_'''$key);
            }
        }

        return 
$ids;
    }
}
?>
Онлайн: 2
Реклама