Revize 570
Přidáno uživatelem harryhk před téměř 15 roky(ů)
freenetis/trunk/kohana/application/helpers/redirection_log.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class redirection_log_Core {
|
||
public static function log($admin = null, $action, $ip_address){
|
||
//username + email
|
||
if ($admin==null){
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
$admin = $user_model->login;
|
||
}
|
||
|
||
$log = new Redirection_log_Model();
|
||
$log->admin = $admin;
|
||
$log->action = $action;
|
||
$log->ip_address = $ip_address;
|
||
$log->time = date("Y-m-d H:i:s");
|
||
|
||
return $log->save();;
|
||
}
|
||
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/redirection.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class Redirection_Model extends ORM {
|
||
//protected $belongs_to = array('user','confirmed_by' => 'user');
|
||
public $arr_sql = array('id' => 'r.id', 'ip_address' => 'r.ip_address', 'duration' => 'r.duration', 'destination' => 'r.destination', 'admin'=>'r.admin', 'message' => 'r.message', 'note' => 'r.note', 'locksign' => 'r.locksign');
|
||
|
||
|
||
public function get_all_redirections($limit_from = 0, $limit_results = 20, $order_by = 'id', $order_by_direction = 'ASC', $user_id = null, $filters = array())
|
||
{
|
||
if (in_array($order_by, $this->arr_sql))
|
||
$order_by = $this->arr_sql[$order_by];
|
||
$where = '';
|
||
if(count($filters) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filters as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
$where .= ($key!='duration' AND $key!='member_id') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
|
||
}
|
||
}
|
||
|
||
return self::$db->query("SELECT
|
||
r.id, r.duration, r.destination, r.ip_address,
|
||
IFNULL(fdest.translated_term, edest.value) AS dest,
|
||
IFNULL(fdur.translated_term, edur.value) AS dur,
|
||
IF(strcmp(r.message,'null'),'●','-') AS message,
|
||
IF(strcmp(r.note,'null'),'●','-') AS note,
|
||
IF(strcmp(r.locksign,0),'●','-') AS locksign,
|
||
r.admin, r.email, r.selfaccess
|
||
FROM redirections r
|
||
LEFT JOIN enum_types edest on r.destination = edest.id
|
||
LEFT JOIN enum_types edur on r.duration = edur.id
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fdest ON edest.value = fdest.original_term
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fdur ON edur.value = fdur.original_term
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results"
|
||
);
|
||
}
|
||
|
||
public function get_redirection($redirection_id)
|
||
{
|
||
return self::$db->query("SELECT
|
||
r.id, r.duration, r. destination, r.ip_address,
|
||
IFNULL(fdest.translated_term, edest.value) AS dest,
|
||
IFNULL(fdur.translated_term, edur.value) AS dur,
|
||
r.message, r.note, r.locksign, r.admin, r.email, r.selfaccess
|
||
FROM redirections r
|
||
LEFT JOIN enum_types edest on r.destination = edest.id
|
||
LEFT JOIN enum_types edur on r.duration = edur.id
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fdest ON edest.value = fdest.original_term
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fdur ON edur.value = fdur.original_term
|
||
WHERE
|
||
r.id = $redirection_id
|
||
"
|
||
);
|
||
}
|
||
|
||
public function delete_redirections($total_redirections, $limit_results = 20, $filters=array(), $login = null)
|
||
{
|
||
$where = 'WHERE ';
|
||
$ip=$filters[0];
|
||
$admin=$filters[1];
|
||
$dur=$filters[2];
|
||
$dest=$filters[3];
|
||
$and = 0;
|
||
if($ip!=0){
|
||
$where .= 'ip_address LIKE \'%'.$ip.'%\' ';
|
||
$and = 1;
|
||
}
|
||
if($admin!=0){
|
||
if ($and) $where.= 'AND ';
|
||
$where .= 'admin = \''.$admin.'\'';
|
||
$and = 1;
|
||
}
|
||
if($dur!=0){
|
||
if ($and) $where.= 'AND ';
|
||
$where .= 'duration = \''.$dur.'\'';
|
||
$and = 1;
|
||
}
|
||
if($dest!=0){
|
||
if ($and) $where.= 'AND ';
|
||
$where .= 'destination = \''.$dest.'\'';
|
||
}
|
||
|
||
if($total_redirections<$limit_results)
|
||
$limit = $total_redirections;
|
||
else
|
||
$limit = $limit_results;
|
||
|
||
$result = self::$db->query("SELECT id,ip_address,admin,locksign from redirections $where LIMIT 0, $limit");
|
||
|
||
foreach ($result as $row)
|
||
{
|
||
if(!($row->locksign && ($row->admin != $login))){
|
||
redirection_log::log($login, 78, $row->ip_address);
|
||
self::$db->query("DELETE FROM redirections WHERE id=$row->id");
|
||
}
|
||
}
|
||
|
||
return;
|
||
|
||
}
|
||
|
||
public function count_all_records($filter_values = array())
|
||
{
|
||
$where = '';
|
||
if (count($filter_values) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
//$where .= ($key!='device_type' AND $key!='member_id') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
|
||
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
$redirections = self::$db->query("SELECT
|
||
r.id, r.duration, r. destination, r.ip_address,
|
||
IFNULL(fdest.translated_term, edest.value) AS dest,
|
||
IFNULL(fdur.translated_term, edur.value) AS dur,
|
||
IF(strcmp(r.message,'null'),'●','-') AS message,
|
||
IF(strcmp(r.note,'null'),'●','-') AS note,
|
||
IF(strcmp(r.locksign,0),'●','-') AS locksign,
|
||
r.admin, r.email, r.selfaccess
|
||
FROM redirections r
|
||
LEFT JOIN enum_types edest on r.destination = edest.id
|
||
LEFT JOIN enum_types edur on r.duration = edur.id
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fdest ON edest.value = fdest.original_term
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fdur ON edur.value = fdur.original_term
|
||
$where"
|
||
);
|
||
return count($redirections);
|
||
/*
|
||
return self::$db->query('SELECT
|
||
COUNT(*) AS total
|
||
FROM redirections r
|
||
')->current()->total;
|
||
*/
|
||
}
|
||
|
||
public function count_deleted_records($filters=array())
|
||
{
|
||
$where = 'WHERE ';
|
||
$ip=$filters[0];
|
||
$admin=$filters[1];
|
||
$dur=$filters[2];
|
||
$dest=$filters[3];
|
||
$and = 0;
|
||
if($ip!=0){
|
||
$where .= 'ip_address LIKE \'%'.$ip.'%\' ';
|
||
$and = 1;
|
||
}
|
||
if($admin!=0){
|
||
if ($and) $where.= 'AND ';
|
||
$where .= 'admin = \''.$admin.'\'';
|
||
$and = 1;
|
||
}
|
||
if($dur!=0){
|
||
if ($and) $where.= 'AND ';
|
||
$where .= 'duration = \''.$dur.'\'';
|
||
$and = 1;
|
||
}
|
||
if($dest!=0){
|
||
if ($and) $where.= 'AND ';
|
||
$where .= 'destination = \''.$dest.'\'';
|
||
}
|
||
|
||
$redirections = self::$db->query("SELECT id FROM redirections $where"
|
||
);
|
||
|
||
return count($redirections);
|
||
}
|
||
|
||
public function get_all_logs($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'DESC', $user_id = null, $filters = array())
|
||
{
|
||
if (in_array($order_by, $this->arr_sql))
|
||
$order_by = $this->arr_sql[$order_by];
|
||
$where = '';
|
||
if(count($filters) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filters as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
$where .= ($key!='duration' AND $key!='member_id') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
|
||
}
|
||
}
|
||
|
||
return self::$db->query("SELECT
|
||
l.id, l.admin, l.ip_address, l.action
|
||
FROM redirection_logs l
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results"
|
||
);
|
||
}
|
||
|
||
public function count_all_logs($filter_values = array())
|
||
{
|
||
$where = '';
|
||
if (count($filter_values) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
//$where .= ($key!='device_type' AND $key!='member_id') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
|
||
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
$redirections = self::$db->query("SELECT
|
||
l.id
|
||
FROM redirection_logs l
|
||
$where"
|
||
);
|
||
return count($redirections);
|
||
}
|
||
|
||
public function count_member_ips($user_id = null){
|
||
$ip_addresses = self::$db->query("SELECT
|
||
ip.ip_address
|
||
FROM users u
|
||
LEFT JOIN devices d ON u.id = d.user_id
|
||
LEFT JOIN ifaces i ON d.id = i.device_id
|
||
LEFT JOIN ip_addresses ip ON i.id = ip.iface_id
|
||
WHERE u.member_id = $user_id
|
||
");
|
||
return count($ip_addresses);
|
||
}
|
||
|
||
public function select_member_ips($user_id = null){
|
||
$ip_addresses = self::$db->query("SELECT
|
||
ip.ip_address
|
||
FROM users u
|
||
LEFT JOIN devices d ON u.id = d.user_id
|
||
LEFT JOIN ifaces i ON d.id = i.device_id
|
||
LEFT JOIN ip_addresses ip ON i.id = ip.iface_id
|
||
WHERE u.member_id = $user_id
|
||
");
|
||
return $ip_addresses;
|
||
}
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/area.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class Area_Model extends ORM {
|
||
//protected $belongs_to = array('user','confirmed_by' => 'user');
|
||
//public $arr_sql = array('id' => 'r.id', 'ip_address' => 'r.ip_address', 'duration' => 'r.duration', 'destination' => 'r.destination', 'admin'=>'r.admin', 'message' => 'r.message', 'note' => 'r.note', 'locksign' => 'r.locksign');
|
||
|
||
public function get_area_prefixes(){
|
||
return self::$db->query("SELECT
|
||
ap.id, ap.prefix, a.area_name
|
||
FROM area_prefix ap
|
||
LEFT JOIN areas a ON ap.area_id = a.id
|
||
ORDER BY ap.prefix
|
||
"
|
||
);
|
||
}
|
||
|
||
public function get_areas(){
|
||
return self::$db->query("SELECT
|
||
a.id, a.area_name
|
||
FROM areas a
|
||
ORDER BY a.id
|
||
"
|
||
);
|
||
}
|
||
|
||
public function get_records_by_prefix($area_prefix){
|
||
return self::$db->query("SELECT
|
||
ip.ip_address, ip.gateway, u.login, a.area_name
|
||
FROM subnets s
|
||
LEFT JOIN ip_addresses ip ON s.id = ip.subnet_id
|
||
LEFT JOIN ifaces i ON ip.iface_id = i.id
|
||
LEFT JOIN devices d ON i.device_id = d.id
|
||
LEFT JOIN users u ON d.user_id = u.id
|
||
LEFT JOIN area_prefix ap ON $area_prefix = ap.prefix
|
||
LEFT JOIN areas a ON ap.area_id = a.id
|
||
WHERE s.network_address LIKE '10.107.$area_prefix.%'
|
||
ORDER BY INET_ATON(ip.ip_address)"
|
||
);
|
||
}
|
||
|
||
public function get_prefixes_by_area($area){
|
||
return self::$db->query("SELECT ap.prefix FROM area_prefix ap WHERE ap.area_id=$area ORDER BY ap.prefix"
|
||
);
|
||
}
|
||
|
||
public function get_records_by_prefix2($area_prefix){
|
||
return self::$db->query("SELECT
|
||
ip.ip_address, ip.gateway, u.login
|
||
FROM subnets s
|
||
LEFT JOIN ip_addresses ip ON s.id = ip.subnet_id
|
||
LEFT JOIN ifaces i ON ip.iface_id = i.id
|
||
LEFT JOIN devices d ON i.device_id = d.id
|
||
LEFT JOIN users u ON d.user_id = u.id
|
||
WHERE s.network_address LIKE '10.107.$area_prefix.%'
|
||
ORDER BY INET_ATON(ip.ip_address)"
|
||
);
|
||
}
|
||
|
||
public function get_records_by_area($area){
|
||
$result = self::$db->query("SELECT ap.prefix FROM area_prefix ap WHERE ap.area_id=$area");
|
||
|
||
$prefixes = 0;
|
||
foreach ($result as $row){
|
||
if($prefixes==0){
|
||
$where = "WHERE s.network_address LIKE '10.107.";
|
||
$where.=$row->prefix.".%'";
|
||
}else{
|
||
$where.=" OR s.network_address LIKE '10.107.".$row->prefix.".%'";
|
||
}
|
||
$prefixes++;
|
||
}
|
||
|
||
return self::$db->query("SELECT
|
||
ip.ip_address, ip.gateway, u.login
|
||
FROM subnets s
|
||
LEFT JOIN ip_addresses ip ON s.id = ip.subnet_id
|
||
LEFT JOIN ifaces i ON ip.iface_id = i.id
|
||
LEFT JOIN devices d ON i.device_id = d.id
|
||
LEFT JOIN users u ON d.user_id = u.id
|
||
$where
|
||
ORDER BY INET_ATON(ip.ip_address)"
|
||
);
|
||
}
|
||
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/redirection_setting.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class Redirection_setting_Model extends ORM {
|
||
//protected $belongs_to = array('user','confirmed_by' => 'user');
|
||
//public $arr_sql = array('id' => 'r.id', 'ip_address' => 'r.ip_address', 'duration' => 'r.duration', 'destination' => 'r.destination', 'admin'=>'r.admin', 'message' => 'r.message', 'note' => 'r.note', 'locksign' => 'r.locksign');
|
||
|
||
|
||
public function get_all_rules($order_by = 'admin_id', $order_by_direction = 'ASC')
|
||
{
|
||
return self::$db->query("SELECT
|
||
rs.admin_id, u.login
|
||
FROM redirection_settings rs
|
||
LEFT JOIN users u ON rs.admin_id = u.id
|
||
ORDER BY $order_by $order_by_direction"
|
||
);
|
||
//return $result;
|
||
}
|
||
|
||
public function count_all_rules()
|
||
{
|
||
$rules = self::$db->query("SELECT
|
||
rs.admin_id, u.login
|
||
FROM redirection_settings rs
|
||
LEFT JOIN users u ON rs.admin_id = u.id
|
||
"
|
||
);
|
||
return count($rules);
|
||
}
|
||
|
||
public function import_admins()
|
||
{
|
||
$result = self::$db->query("SELECT a.admin_id FROM areas a");
|
||
$total = count($result);
|
||
$values = "";
|
||
$total_values = 0;
|
||
foreach ($result as $row){
|
||
$total--;
|
||
$result2 = count(self::$db->query("SELECT admin_id FROM redirection_settings WHERE admin_id=$row->admin_id"));
|
||
if ($result2==0){
|
||
if ($total_values!=0){
|
||
$values .= ",";
|
||
}
|
||
$values .= "(".$row->admin_id.")";
|
||
$total_values++;
|
||
}
|
||
}
|
||
if($total_values){
|
||
return self::$db->query("INSERT INTO
|
||
redirection_settings (admin_id)
|
||
VALUES $values"
|
||
);
|
||
} else {
|
||
return;
|
||
}
|
||
}
|
||
|
||
public function addadmin($admin_id=null,$subnet_id=0)
|
||
{
|
||
$result = count(self::$db->query("SELECT admin_id FROM redirection_settings WHERE admin_id=$admin_id"));
|
||
if ($result == 0){
|
||
$values = "($admin_id,$subnet_id)";
|
||
return self::$db->query("INSERT INTO
|
||
redirection_settings (admin_id, subnet_id)
|
||
VALUES $values"
|
||
);
|
||
}
|
||
}
|
||
|
||
public function delete_admin($admin_id)
|
||
{
|
||
return self::$db->query("DELETE
|
||
FROM redirection_settings
|
||
WHERE admin_id = $admin_id"
|
||
);
|
||
//return $result;
|
||
}
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/config_file.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class Config_file_Model extends ORM {
|
||
//protected $belongs_to = array('user','confirmed_by' => 'user');
|
||
//public $arr_sql = array('id' => 'r.id', 'ip_address' => 'r.ip_address', 'duration' => 'r.duration', 'destination' => 'r.destination', 'admin'=>'r.admin', 'message' => 'r.message', 'note' => 'r.note', 'locksign' => 'r.locksign');
|
||
|
||
/*public function get_dhcp_users($subnet_id = null){
|
||
return self::$db->query("SELECT
|
||
ip.ip_address, i.mac
|
||
FROM ip_addresses ip
|
||
LEFT JOIN ifaces i ON ip.iface_id = i.id
|
||
WHERE subnet_id=$subnet_id"
|
||
);
|
||
}*/
|
||
|
||
public function get_dhcp_users($subnet_id = null){
|
||
return self::$db->query("SELECT
|
||
ip.ip_address, i.mac, u.login
|
||
FROM ip_addresses ip
|
||
LEFT JOIN ifaces i ON ip.iface_id = i.id
|
||
LEFT JOIN devices d ON i.device_id = d.id
|
||
LEFT JOIN users u ON d.user_id = u.id
|
||
WHERE subnet_id=$subnet_id
|
||
ORDER BY INET_ATON(ip.ip_address)"
|
||
);
|
||
}
|
||
|
||
public function get_mac_users($subnet_id = null){
|
||
return self::$db->query("SELECT
|
||
ip.ip_address, i.mac, u.login
|
||
FROM ip_addresses ip
|
||
LEFT JOIN ifaces i ON ip.iface_id = i.id
|
||
LEFT JOIN devices d ON i.device_id = d.id
|
||
LEFT JOIN users u ON d.user_id = u.id
|
||
WHERE subnet_id=$subnet_id
|
||
ORDER BY i.mac"
|
||
);
|
||
}
|
||
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/backup.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class Backup_Model extends ORM {
|
||
//protected $belongs_to = array('user','confirmed_by' => 'user');
|
||
public $arr_sql = array('id' => 'b.id', 'user_id' => 'b.user_id', 'locksign' => 'b.locksign', 'platform' => 'b.platform', 'name'=>'b.name');
|
||
|
||
public function get_all_backups($limit_from = 0, $limit_results = 20, $order_by = 'id', $order_by_direction = 'ASC', $user_id = null, $filters = array())
|
||
{
|
||
if (in_array($order_by, $this->arr_sql))
|
||
$order_by = $this->arr_sql[$order_by];
|
||
$where = '';
|
||
if(count($filters) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filters as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
|
||
return self::$db->query("SELECT
|
||
b.id, b.user_id, b.name
|
||
IFNULL(f.translated_term, e.value) AS platform,
|
||
IF(strcmp(b.locksign,0),'●','-') AS locksign,
|
||
FROM backup b
|
||
LEFT JOIN enum_types e on b.platform = e.id
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') f ON e.value = f.original_term
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results"
|
||
);
|
||
}
|
||
|
||
|
||
public function count_all_backups($limit_from = 0, $limit_results = 20, $order_by = 'id', $order_by_direction = 'ASC', $user_id = null, $filters = array())
|
||
{
|
||
if (in_array($order_by, $this->arr_sql))
|
||
$order_by = $this->arr_sql[$order_by];
|
||
$where = '';
|
||
if(count($filters) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filters as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
|
||
$backups = self::$db->query("SELECT
|
||
b.id, b.user_id, b.name
|
||
IFNULL(f.translated_term, e.value) AS platform,
|
||
IF(strcmp(b.locksign,0),'●','-') AS locksign,
|
||
FROM backup b
|
||
LEFT JOIN enum_types e on b.platform = e.id
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') f ON e.value = f.original_term
|
||
$where");
|
||
return count($backups);
|
||
}
|
||
|
||
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/redirection_log.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
|
||
class Redirection_log_Model extends ORM {
|
||
//protected $belongs_to = array('user','confirmed_by' => 'user');
|
||
public $arr_sql = array('id' => 'l.id', 'ip_address' => 'l.ip_address', 'action' => 'l.action', 'admin'=>'l.admin', 'time'=>'l.time');
|
||
|
||
public function get_all_logs($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'DESC', $user_id = null, $filters = array())
|
||
{
|
||
if (in_array($order_by, $this->arr_sql))
|
||
$order_by = $this->arr_sql[$order_by];
|
||
$where = '';
|
||
if(count($filters) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filters as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
//$where .= ($key!='device_type' AND $key!='member_id') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
|
||
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
|
||
return self::$db->query("SELECT
|
||
l.id, l.ip_address, l.admin,l.time,
|
||
IFNULL(fact.translated_term, eact.value) AS action
|
||
FROM redirection_logs l
|
||
LEFT JOIN enum_types eact on l.action = eact.id
|
||
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') fact ON eact.value = fact.original_term
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results"
|
||
);
|
||
}
|
||
|
||
public function count_all_logs($filter_values = array())
|
||
{
|
||
$where = '';
|
||
if (count($filter_values) > 0)
|
||
$where .= 'WHERE ';
|
||
foreach($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='WHERE ')
|
||
$where .= ' AND ';
|
||
//$where .= ($key!='action') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
|
||
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
$redirections = self::$db->query("SELECT
|
||
l.id, l.action
|
||
FROM redirection_logs l
|
||
$where"
|
||
);
|
||
return count($redirections);
|
||
}
|
||
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/controllers/download.php | ||
---|---|---|
<?php
|
||
$file = urldecode ($_GET['file']);
|
||
$path_parts = pathinfo ($file);
|
||
|
||
header("Content-Disposition: attachment; filename=" . urlencode($path_parts['basename']));
|
||
header("Content-Type: application/force-download");
|
||
header("Content-Type: application/octet-stream");
|
||
header("Content-Type: application/download");
|
||
header("Content-Description: File Transfer");
|
||
header("Content-Length: " . filesize($file));
|
||
|
||
readfile($file);
|
||
?>
|
freenetis/trunk/kohana/application/controllers/redirection.php | ||
---|---|---|
<?php
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
class Redirection_Controller extends Controller{
|
||
function index(){
|
||
url::redirect(url_lang::base().'redirection/show_all');
|
||
}
|
||
|
||
function addip(){
|
||
//duration type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/addip", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
|
||
$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
$redirection = new Redirection_Model();
|
||
$ip_address = $form_data['ip_address'];
|
||
$redirection->ip_address = $ip_address;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_model->login;
|
||
$redirection->email = $user_model->email;
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
redirection_log::log($user_model->login, 76, $ip_address);
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect IP address');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect IP address');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function addrange(){
|
||
//duration type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/addrange", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
$this->form->input('ip_range1')->label(url_lang::lang('texts.Range of IP addresses - first host').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
$this->form->input('ip_range2')->label(url_lang::lang('texts.Range of IP addresses - last host').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip2'));
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
list($ip1p1, $ip1p2, $ip1p3, $ip1p4) = split('[.]', $form_data['ip_range1']);
|
||
list($ip2p1, $ip2p2, $ip2p3, $ip2p4) = split('[.]', $form_data['ip_range2']);
|
||
$range_length=$ip2p4 - $ip1p4 + 1;
|
||
|
||
for ($i=0; $i<$range_length; $i++){
|
||
$redirected_ip = $ip1p1.".".$ip1p2.".".$ip1p3.".".($ip1p4+$i);
|
||
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address = $redirected_ip;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_model->login;
|
||
$redirection->email = $user_model->email;
|
||
|
||
if($i!=$range_length-1)
|
||
$redirection->save();
|
||
redirection_log::log($user_model->login, 76, $redirected_ip);
|
||
}
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect range of ip addresses');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect range of ip addresses');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function addsubnet($member_id=null){
|
||
//duration type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/addsubnet", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
$this->form->input('ip_subnet')->label(url_lang::lang('texts.Subnet').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
$this->form->input('ip_subnet_mask')->label(url_lang::lang('texts.Subnet netmask').':')->rules('required|length[1,2]')->callback(array($this, 'callback_valid_mask'));
|
||
$this->form->checkbox('remove_network')->label(url_lang::lang('texts.Remove network IP address'))->value('1')->checked(TRUE);
|
||
$this->form->checkbox('remove_broadcast')->label(url_lang::lang('texts.Remove broadcast IP address'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
list($ip1, $ip2, $ip3, $ip4) = split('[.]', $form_data['ip_subnet']);
|
||
$ip_subnet_mask = $form_data['ip_subnet_mask'];
|
||
$network_bits = 32-$ip_subnet_mask;
|
||
$network_ip_addresses = 1;
|
||
for($i=0; $i<$network_bits; $i++){
|
||
$network_ip_addresses*=2;
|
||
}
|
||
$number_of_blocks=256/$network_ip_addresses;
|
||
$network=0;
|
||
for($i=0; $i<$number_of_blocks; $i++){
|
||
if($network<=$ip4 && $ip4<($network+$network_ip_addresses)){
|
||
$my_network=$network;
|
||
}
|
||
$network=$network+$network_ip_addresses;
|
||
}
|
||
if(isset($_REQUEST["remove_broadcast"]))
|
||
$network_ip_addresses--;
|
||
|
||
for ($i=0; $i<$network_ip_addresses; $i++){
|
||
if(isset($_REQUEST["remove_network"]) && $i==0)
|
||
$i++;
|
||
$redirected_ip = $ip1.".".$ip2.".".$ip3.".".($my_network+$i);
|
||
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address = $redirected_ip;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_model->login;
|
||
$redirection->email = $user_model->email;
|
||
|
||
if($i!=$network_ip_addresses-1)
|
||
$redirection->save();
|
||
|
||
redirection_log::log($user_model->login, 76, $redirected_ip);
|
||
}
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect ip subnet');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect ip subnet');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function adduser($member_id=null){
|
||
//duration type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base().'redirection/adduser/'.$member_id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
|
||
//$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
$this->form->input('userid')->label(url_lang::lang('texts.User ID').':')->rules('required');
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
//retrieving IP from user ID
|
||
$userid = $form_data['userid'];
|
||
$usermodel = new User_Model();
|
||
$usermodel->find($userid);
|
||
if ($usermodel->id == 0){
|
||
Controller::error(RECORD);
|
||
exit;
|
||
}
|
||
$redirection = new Redirection_Model();
|
||
$total_addresses = $redirection->count_member_ips($userid);
|
||
$result = $redirection->select_member_ips($userid);
|
||
foreach ($result as $row){
|
||
if ($row->ip_address!=null)
|
||
$ip_addresses[]=$row->ip_address;
|
||
else
|
||
$total_addresses--;
|
||
}
|
||
|
||
for ($i=0; $i<$total_addresses; $i++){
|
||
$redirected_ip = $ip_addresses[$i];
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address = $redirected_ip;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_model->login;
|
||
$redirection->email = $user_model->email;
|
||
|
||
if($i!=$total_addresses-1)
|
||
$redirection->save();
|
||
redirection_log::log($user_model->login, 76, $redirected_ip);
|
||
}
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect the user');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect the user');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
|
||
}
|
||
|
||
function show_all($limit_results = 20, $order_by = 'id', $order_by_direction = 'ASC', $page_word = null, $page = 1){
|
||
//if (!$this->acl_check_view(get_class($this),'devices'))
|
||
// Controller::error(ACCESS);
|
||
|
||
//duration type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
asort($types_duration);
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
$filter=new Table_Form(url_lang::base()."redirection/show_all", "get", array(
|
||
new Table_Form_Item('text','ip_address','IP address'),
|
||
new Table_Form_Item('text','admin','Admin'),
|
||
"tr",
|
||
new Table_Form_Item('select','duration','Duration',$types_duration),
|
||
new Table_Form_Item('select','destination','Destination',$types_destination),
|
||
"tr",
|
||
"td",
|
||
new Table_Form_Item('submit','submit','Filter')
|
||
)
|
||
);
|
||
$filter_values = $filter->values();
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->get('record_per_page')))
|
||
$limit_results = (int) $this->input->get('record_per_page');
|
||
|
||
$redirection_model = new Redirection_Model();
|
||
$total_redirections = $redirection_model->count_all_records($filter_values);
|
||
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_redirections)
|
||
$sql_offset = 0;
|
||
|
||
$query = $redirection_model->get_all_redirections($sql_offset, (int)$limit_results, $order_by, $order_by_direction, NULL, $filter_values);
|
||
|
||
$grid = new Grid(url_lang::base().'redirection', null,array(
|
||
//'separator' => '<br />-----------',
|
||
'use_paginator' => true,
|
||
'use_selector' => true,
|
||
'current' => $limit_results, // current selected 'records_per_page' value
|
||
'selector_increace' => 20, // increace
|
||
'selector_min' => 20, // minimum where selector start
|
||
'selector_max_multiplier' => 10,
|
||
'base_url' => Config::item('locale.lang').'/redirection/show_all/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
|
||
'uri_vlan' => 'page', // pass a string as uri_vlan to trigger former 'label' functionality
|
||
'total_items' => $total_redirections, // use db count query here of course
|
||
'items_per_page' => $limit_results, // it may be handy to set defaults for stuff like this in config/pagination.php
|
||
'style' => 'classic',
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results,
|
||
//'query_string' => $query_string,
|
||
'filter' => $filter->view
|
||
));
|
||
|
||
//if ($this->acl_check_new('Devices_Controller','vlan')){
|
||
$grid->add_new_button(url_lang::base().'redirection/addip', url_lang::lang('texts.Redirect IP address'));
|
||
$grid->add_new_button(url_lang::base().'redirection/addrange', url_lang::lang('texts.Redirect range of IP addresses'));
|
||
$grid->add_new_button(url_lang::base().'redirection/addsubnet', url_lang::lang('texts.Redirect IP subnet'));
|
||
$grid->add_new_button(url_lang::base().'redirection/adduser', url_lang::lang('texts.Redirect the user'));
|
||
if (isset($_REQUEST["submit"])){
|
||
if($_GET['ip_address']!=null) $ip_address = $_GET['ip_address'];
|
||
else $ip_address = 0;
|
||
if($_GET['admin']!=null) $admin = $_GET['admin'];
|
||
else $admin = 0;
|
||
if($_GET['duration']!=null) $duration = $_GET['duration'];
|
||
else $duration = 0;
|
||
if($_GET['destination']!=null) $destination = $_GET['destination'];
|
||
else $destination = 0;
|
||
$grid->add_new_button(url_lang::base().'redirection/delete_list/'.$limit_results.'/'.$ip_address.'/'.$admin.'/'.$duration.'/'.$destination, url_lang::lang('texts.Delete selection'));
|
||
}
|
||
//}
|
||
|
||
//$grid->order_field('id')->label('ID')->class('center');
|
||
$grid->order_field('ip_address')->label(url_lang::lang('texts.IP address'));
|
||
$grid->order_field('dur')->label(url_lang::lang('texts.Duration'))->class('center');
|
||
$grid->order_field('dest')->label(url_lang::lang('texts.Destination website'))->class('center');
|
||
$grid->order_field('admin')->label(url_lang::lang('texts.Admin'))->class('center');
|
||
$grid->order_field('message')->label(url_lang::lang('texts.Message'))->class('center');
|
||
$grid->order_field('note')->label(url_lang::lang('texts.Comment'))->class('center');
|
||
$grid->order_field('locksign')->label(url_lang::lang('texts.Lock'))->class('center');
|
||
//if ($this->acl_check_view('Devices_Controller','vlan'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Show')) ->url(url_lang::base().'redirection/show') ->action(url_lang::lang('texts.Show'))->class('center');
|
||
//if ($this->acl_check_edit('Devices_Controller','vlan'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Edit')) ->url(url_lang::base().'redirection/edit') ->action(url_lang::lang('texts.Edit'))->class('center');
|
||
//if ($this->acl_check_edit('Devices_Controller','vlan'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'redirection/delete')->action(url_lang::lang('texts.Delete'))->class('center')->script('onclick="return potvrd(\''.url_lang::lang('texts.Do you want to cancel this redirection').'\');"');
|
||
// $grid->action_field('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'redirection/delete')->action(url_lang::lang('texts.Delete'))->script('onclick="return potvrd(\''.url_lang::lang('texts.Do you want to delete this user').'\');"');
|
||
$grid->datasource( $query );
|
||
$this->template->content = $grid;
|
||
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.List of all redirected records');
|
||
$view->content = new View('show_all');
|
||
$view->content->headline = url_lang::lang('texts.List of all redirected records');
|
||
$view->content->table = $grid;
|
||
$view->render(TRUE);
|
||
|
||
}
|
||
|
||
function show($redirection_id = NULL){
|
||
$redirection = new Redirection_Model($redirection_id);
|
||
if (!$redirection_id || !$redirection->id){
|
||
Controller::error(RECORD);
|
||
//url::redirect(url_lang::base().'redirection');
|
||
}
|
||
$enum_type_model = new Enum_type_Model();
|
||
$duration = $enum_type_model->get_value($redirection->duration);
|
||
$destination = $enum_type_model->get_value($redirection->destination);
|
||
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($redirection->locksign && $redirection->admin != $user_model->login){
|
||
$this->session->set_flash('message', url_lang::lang('texts.You have no permission to access redirection'));
|
||
$linkback = url_lang::base()."redirection/show_all/";
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
// access control
|
||
//if (!$this->acl_check_view('Users_Controller','work',$work->user->member_id))
|
||
// Controller::error(ACCESS);
|
||
|
||
$link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Show redirection');
|
||
$view->content = new View('redirection/show');
|
||
$view->content->duration = $duration;
|
||
$view->content->destination = $destination;
|
||
$view->content->redirection = $redirection;
|
||
$view->content->link_back = $link_back;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function edit($redirection_id = null)
|
||
{
|
||
if (!isset($redirection_id))
|
||
Controller::warning(PARAMETER);
|
||
$redirection = new Redirection_Model($redirection_id);
|
||
if ($redirection->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($redirection->locksign && $redirection->admin != $user_model->login){
|
||
$this->session->set_flash('message', url_lang::lang('texts.You have no permission to edit redirection'));
|
||
$linkback = url_lang::base()."redirection/show_all/";
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
//if (!$this->acl_check_edit(get_class($this),'devices',$redirection->user->member_id))
|
||
// Controller::error(ACCESS);
|
||
|
||
//duration
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
//destination
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
$this->user_id = $user_id;
|
||
|
||
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/edit/".$redirection_id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic data'));
|
||
$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'))->value($redirection->ip_address);
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required')->selected($redirection->duration);
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked($redirection->selfaccess);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required')->selected($redirection->destination);
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value($redirection->message);
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value($redirection->note);
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked($redirection->locksign);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked($redirection->sendmail);
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Update'));
|
||
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
$redirection = new Redirection_Model($redirection_id);
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
//$redirection = new Redirection_Model();
|
||
$ip_address = $form_data['ip_address'];
|
||
$redirection->ip_address = $ip_address;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_model->login;
|
||
$redirection->email = $user_model->email;
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
redirection_log::log($user_model->login, 77, $ip_address);
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully updated.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Edit IP address redirection');
|
||
$view->content = new View('form');
|
||
$view->content->form = $this->form->html();
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Edit IP address redirection');
|
||
$view->render(TRUE);
|
||
} // end of function edit
|
||
|
||
function delete($redirection_id = NULL)
|
||
{
|
||
if (!isset($redirection_id))
|
||
Controller::warning(PARAMETER);
|
||
|
||
$redirection_model = new Redirection_Model($redirection_id);
|
||
$ip_address = $redirection_model->ip_address;
|
||
|
||
//if (!$this->acl_check_delete('Devices_Controller', 'ip_address', $member_id))
|
||
// Controller::error(ACCESS);
|
||
|
||
$linkback = url_lang::base()."redirection/show_all/";
|
||
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($redirection_model->locksign && $redirection_model->admin != $user_model->login){
|
||
$this->session->set_flash('message', url_lang::lang('texts.You have no permission to delete redirection'));
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
if ($redirection_model->delete()){
|
||
$this->session->set_flash('message', url_lang::lang('texts.IP address has been successfully deleted.'));
|
||
redirection_log::log($user_model->login, 78, $ip_address);
|
||
} else {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cant delete ip address.'));
|
||
}
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
function delete_list($limit_results=20, $ip_address=0, $admin=0, $duration=0, $destination=0){
|
||
//if (!$this->acl_check_view(get_class($this),'devices'))
|
||
// Controller::error(ACCESS);
|
||
|
||
//username
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
$login = $user_model->login;
|
||
|
||
$filter_values = array();
|
||
|
||
$linkback = url_lang::base()."redirection/show_all/";
|
||
if($ip_address==0 && $admin==0 && $duration==0 && $destination==0){
|
||
$this->session->set_flash('message', url_lang::lang('texts.No filter values has been selected.'));
|
||
}else{
|
||
$filter_values[] = $ip_address;
|
||
$filter_values[] = $admin;
|
||
$filter_values[] = $duration;
|
||
$filter_values[] = $destination;
|
||
|
||
$redirection_model = new Redirection_Model();
|
||
$total_redirections = $redirection_model->count_deleted_records($filter_values);
|
||
|
||
if($total_redirections==0){
|
||
$this->session->set_flash('message', url_lang::lang('texts.No IP address was deleted.'));
|
||
}else{
|
||
$query = $redirection_model->delete_redirections($total_redirections, (int)$limit_results, $filter_values, $login);
|
||
$this->session->set_flash('message', url_lang::lang('texts.IP addresses has been successfully deleted.'));
|
||
}
|
||
}
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
function callback_valid_ip($input)
|
||
{
|
||
|
||
// $ip_subnet_mask = $_REQUEST["ip_subnet_mask"];
|
||
|
||
if (isset($_REQUEST["ip_address"])){
|
||
$ip = $_REQUEST["ip_address"];
|
||
} else if (isset($_REQUEST["ip_range1"])){
|
||
$ip = $_REQUEST["ip_range1"];
|
||
} else if (isset($_REQUEST["ip_subnet"])){
|
||
$ip = $_REQUEST["ip_subnet"];
|
||
}
|
||
if ($ip!=""){
|
||
if(!ereg("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", $ip)){
|
||
$input->add_error('required', url_lang::lang('texts.Invalid IP address'));
|
||
return false;
|
||
}
|
||
}else {
|
||
return false;
|
||
}
|
||
} // end of valid_ip
|
||
|
||
function callback_valid_ip2($input)
|
||
{
|
||
$ip = $_REQUEST["ip_range2"];
|
||
|
||
if ($ip!=""){
|
||
if(!ereg("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", $ip)){
|
||
$input->add_error('required', url_lang::lang('texts.Invalid IP address'));
|
||
return false;
|
||
}
|
||
}else {
|
||
return false;
|
Také k dispozici: Unified diff