2017-12-01 11:34:27 +01:00

131 lines
3.6 KiB
PHP

<?php
class Suspect extends ObjectModel
{
const VERIFY = 2;
const SUSPECT = 1;
public static $states = array(
0 => array(
'name' => "A vérifier",
'icon' => 'anticon anticon-hour-glass text-orange',
),
1 => array(
'name' => "Suspect",
'icon' => 'anticon anticon-target text-rose',
),
2 => array(
'name' => "Verifié",
'icon' => 'anticon anticon-checkmark text-green-light',
),
);
public $id_suspect;
public $id_customer;
public $email;
public $page;
public $referrer;
public $user_agent;
public $remote_host;
public $remote_ip;
public $condition;
public $is_suspect;
public $date_add;
public $date_upd;
protected $fieldsRequired = array('email');
protected $fieldsValidate = array(
'id_suspect' => 'isUnsignedId',
'id_customer' => 'isUnsignedId',
'email' => 'isEmail',
'page' => 'isString',
'referrer' => 'isString',
'user_agent' => 'isString',
'remote_host' => 'isString',
'remote_ip' => 'isString',
'condition' => 'isString',
'is_suspect' => 'isInt',
'date_add' => 'isDate',
'date_upd' => 'isDate',
);
protected $table = 'ant_alerthack_suspect';
protected $identifier = 'id_suspect';
public function getFields()
{
parent::validateFields();
$fields['id_suspect'] = (int)$this->id_suspect;
$fields['id_customer'] = (int)$this->id_customer;
$fields['email'] = pSQL($this->email);
$fields['page'] = pSQL($this->page);
$fields['referrer'] = pSQL($this->referrer);
$fields['user_agent'] = pSQL($this->user_agent);
$fields['remote_host'] = pSQL($this->remote_host);
$fields['remote_ip'] = pSQL($this->remote_ip);
$fields['condition'] = pSQL($this->condition);
$fields['is_suspect'] = (int)$this->is_suspect;
$fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd);
return $fields;
}
public function delete()
{
return true;
}
/**
* Get suspects
* @param $states array get only suspects in specific states
* @return Array Groups
*/
public static function getSuspects($states = array(), $where = false)
{
if($where){
return Db::getInstance()->executeS('
SELECT *
FROM `'._DB_PREFIX_.'ant_alerthack_suspect` s
WHERE '.$where.'
');
} else {
return Db::getInstance()->executeS('
SELECT *
FROM `'._DB_PREFIX_.'ant_alerthack_suspect` s
WHERE 1
'.(!empty($states) ? 'AND s.`is_suspect` IN ('.implode(',',$states).')' : '').'
ORDER BY s.date_add DESC
');
}
}
public function save($nullValues = false, $autodate = true)
{
if (parent::save()) {
return true;
}
}
public static function isBannished($email)
{
$domain_name = substr(strrchr($email, '@'), 1);
if ($domain_name == 'qq.com') {
return true;
}
$suspect = Db::getInstance()->getRow('
SELECT `is_suspect`
FROM `'._DB_PREFIX_.'ant_alerthack_suspect`
WHERE `email` = "'.pSQL($email).'"
');
if((int)$suspect['is_suspect'] == 1){
return true;
}
return false;
}
}