Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1082

Přidáno uživatelem Jiří Sviták před asi 13 roky(ů)

Upusteno od puvodniho napadu generovani statickych stranek, prace dynamickem skriptu v cistem php (rychlostni duvody) umistenem ve slozce redirection. Promazani starych metod. V existujicich .htaccess souborech v korenovem adresari je pak treba zrusit vyjimku pro stary adresar static a pridat vyjimku pro novy redirection.

Zobrazit rozdíly:

freenetis/branches/redirection/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 $this->db->query("SELECT
l.id, l.ip_address_id, l.admin, l.time, ip.ip_address,
IFNULL(fact.translated_term, eact.value) AS action
FROM redirection_logs l
LEFT JOIN ip_addresses ip ON l.ip_address_id = ip.id
LEFT JOIN enum_types eact on l.action = eact.id
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::get('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 = $this->db->query("SELECT
l.id, l.action
FROM redirection_logs l
$where"
);
return count($redirections);
}
}
?>
freenetis/branches/redirection/application/models/redirection_duration.php
<?php
/**
* @author Lubomir Buben
*/
class Redirection_duration_Model extends ORM {
/**
* @author Lubomir Buben
* Function gets all duration types
* @return unknown_type
*/
public function get_values(){
return $this->db->query("SELECT
rdur.id, rdur.duration, rdur.translation
FROM redirection_durations rdur"
);
}
/**
* @author Lubomir Buben
* Function gets duration types suitable for select list
* @return unknown_type
*/
public function get_select_list(){
return $this->db->query("SELECT
rdur.id, rdur.duration, rdur.translation
FROM redirection_durations rdur
WHERE id>3"
);
}
}
?>
freenetis/branches/redirection/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' => 'ip.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 $this->db->query("SELECT
r.id, r.duration, r.destination, r.ip_address_id, ip.ip_address,
rdur.translation AS dur,
IFNULL(fdest.translated_term, edest.value) AS dest,
IF(strcmp(r.message,'null'),'●','-') AS message,
IF(strcmp(r.note,'null'),'●','-') AS note,
IF(strcmp(r.locksign,0),'●','-') AS locksign,
r.admin, r.selfaccess
FROM redirections r
LEFT JOIN ip_addresses ip ON r.ip_address_id = ip.id
LEFT JOIN enum_types edest on r.destination = edest.id
LEFT JOIN redirection_durations rdur on r.duration = rdur.id
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::get('lang')."') fdest ON edest.value = fdest.original_term
$where
ORDER BY $order_by $order_by_direction
LIMIT $limit_from, $limit_results"
);
}
public function get_redirection($redirection_id){
return $this->db->query("SELECT
r.id, r.duration, r. destination, r.ip_address_id, ip.ip_address,
rdur.translation AS dur,
IFNULL(fdest.translated_term, edest.value) AS dest,
r.message, r.note, r.locksign, r.admin, r.selfaccess
FROM redirections r
LEFT JOIN ip_addresses ip ON r.ip_address_id = ip.id
LEFT JOIN enum_types edest ON r.destination = edest.id
LEFT JOIN redirection_durations rdur on r.duration = rdur.id
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::get('lang')."') fdest ON edest.value = fdest.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_id 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 = $this->db->query("SELECT id,ip_address_id,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_id);
$this->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 = $this->db->query("SELECT
r.id
FROM redirections r
LEFT JOIN ip_addresses ip ON r.ip_address_id = ip.id
$where"
);
return count($redirections);
}
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_id 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 = $this->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 $this->db->query("SELECT
l.id, l.admin, l.ip_address_id, 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 = $this->db->query("SELECT
l.id
FROM redirection_logs l
$where"
);
return count($redirections);
}
public function count_member_ips($user_id = null){
$ip_addresses = $this->db->query("SELECT
ip.id
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 = $this->db->query("SELECT
ip.id
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;
}
/**
* @author Lubomir Buben
* Function being called every hour by cron, maintaining redirection records
* @return unknown_type
*/
public function select_hourly(){
return $this->db->query("SELECT
r.id
FROM redirections r
WHERE r.duration < '900'"
);
}
/**
* @author Lubomir Buben
* Function being called every day by cron, maintaining redirection records
* @return unknown_type
*/
public function select_daily(){
return $this->db->query("SELECT
r.id
FROM redirections r
WHERE r.duration = 1000"
);
}
/**
* @author Lubomir Buben
* Function being called every month by cron, maintaining redirection records
* @return unknown_type
*/
public function select_monthly(){
return $this->db->query("SELECT
r.id
FROM redirections r
WHERE r.duration = 1010"
);
}
}
?>
freenetis/branches/redirection/application/controllers/web_interface.php
}
}
/*
// asi neni nutne resit posilani zpravy z centralniho routeru, proste kdyz jsem prijde, tak je synchornizovany
function synchronized()
{
......
// return synchronization status to central router
return $synchronized;
}
*
*/
/**
* Receives with POST method list of IP addresses which have active self-cancelable redirection and
freenetis/branches/redirection/application/controllers/members.php
$membership_interrupts_grid->field('from')->label(url_lang::lang('texts.Date from'));
$membership_interrupts_grid->field('to')->label(url_lang::lang('texts.Date to'));
$membership_interrupts_grid->field('comment')->label(url_lang::lang('texts.Comment'));
if ($this->acl_check_edit(get_class($this), 'membership_interrupts', $member_id))
$membership_interrupts_grid->action_field('id') ->label(url_lang::lang('texts.Membership interrupts'))->url(url_lang::base().'membership_interrupts/edit')->action(url_lang::lang('texts.Edit'));
if ($this->acl_check_delete(get_class($this), 'membership_interrupts'))
$membership_interrupts_grid->action_field('id') ->label(url_lang::lang('texts.Membership interrupts'))->url(url_lang::base().'membership_interrupts/delete')->action(url_lang::lang('texts.Delete'))->class('delete_link');
$membership_interrupts_grid->datasource($membership_interrupts);
// active redirections of member, including short statistic of whitelisted IP addresses
$ip_model = new Ip_address_Model();
$ip_addresses = $ip_model->get_ips_and_redirections_of_member($member_id);
$redir_grid = new Grid(url_lang::base().'members', null, array(
'use_paginator' => false,
'use_selector' => false
));
if ($this->acl_check_new('Messages_Controller', 'member'))
{
$redir_grid->add_new_button(url_lang::base().'redirect/activate_to_member/'.$member_id, url_lang::lang('texts.Activate redirection to member'), array(), help::hint('activate_redirection_to_member'));
$redir_grid->add_new_button(url_lang::base().'redirect/set_whitelist/'.$member_id, url_lang::lang('texts.Set whitelist to member'), array(), help::hint('set_whitelist_to_member'));
}
$redir_grid->callback_field('ip_address')->label(url_lang::lang('texts.IP address'))->callback('callback::ip_address_field');
$redir_grid->callback_field('whitelisted')->label(url_lang::lang('texts.Whitelist'))->callback('callback::whitelisted_field');
$redir_grid->callback_field('message')->label(url_lang::lang('texts.Active redirection'))->callback('callback::message_field');
if ($this->acl_check_delete('Messages_Controller', 'ip_address'))
$redir_grid->callback_field('redirection')->label(url_lang::lang('texts.Canceling of message for redirection'))->callback("callback::cancel_redirection_of_member");
$redir_grid->datasource($ip_addresses);
/************************************************************** BUILDING OF LINKS ****************************************************************************/
$member_links = array();
......
$view->content->users_grid = $users_grid;
$view->content->voip_grid = $voip_grid;
$view->content->membership_interrupts_grid = $membership_interrupts_grid;
$view->content->redir_grid = $redir_grid;
$view->content->contacts = $contacts;
$view->content->contact_types = $contact_types;
$view->content->expiration_date = $expiration_date;
freenetis/branches/redirection/application/controllers/messages.php
<?php
class Messages_Controller extends Controller
{
function __construct()
{
parent::__construct();
if (!is_writable('static'))
{
Controller::error(WRITABLE, url_lang::lang('texts.Directory "static" is not writable, change access rights.'));
}
}
function index()
{
......
$grid->order_field('id')->label('ID');
$grid->order_callback_field('message')->label(url_lang::lang('texts.Name'))->callback('callback::message_field');
$grid->callback_field('type')->label(url_lang::lang('texts.Type'))->callback('callback::message_type_field');
if ($this->acl_check_view('Messages_Controller', 'message'))
$grid->callback_field('id')->label(url_lang::lang('texts.Preview'))->callback('callback::message_preview_field');
//if ($this->acl_check_view('Messages_Controller', 'message'))
// $grid->callback_field('id')->label(url_lang::lang('texts.Preview'))->callback('callback::message_preview_field');
if ($this->acl_check_edit('Messages_Controller', 'message'))
$grid->action_field('id') ->label(url_lang::lang('texts.Edit'))->url(url_lang::base().'messages/edit')->action(url_lang::lang('texts.Edit'));
if ($this->acl_check_edit('Messages_Controller', 'message'))
$grid->callback_field('id')->label(url_lang::lang('texts.Update'))->callback('callback::message_update_field');
//if ($this->acl_check_edit('Messages_Controller', 'message'))
// $grid->callback_field('id')->label(url_lang::lang('texts.Update'))->callback('callback::message_update_field');
if ($this->acl_check_delete('Messages_Controller', 'message'))
$grid->callback_field('id')->label(url_lang::lang('texts.Delete'))->callback('callback::message_delete_field');
$grid->datasource($messages);
......
* @author Jiri Svitak
* @param $message_id
*/
/*
function preview($message_id)
{
$message = new Message_Model($message_id);
......
$footer = $message->self_cancel > 0 ? $cancel_link : '';
echo Redirect_Controller::get_static_page($ip_address, $contact, $content, $footer);
}
*/
/**
* Edits message parameters.
......
// choose which message to update
switch($message->type)
{
/*
case Message_Model::$cancel_message:
// cancel message must be set somewhere else than in static folder
//Redirection_Controller::update('cancel_message', $contact, $content, '');
......
case Message_Model::$unknown_device_message:
Redirection_Controller::update('unknown_device_message', $contact, $content, '');
break;
*/
case Message_Model::$interrupted_membership_message:
// delete old redirections
$database->delete('messages_ip_addresses', array('message_id' => $message_id));
......
foreach($ips as $ip)
{
// replace special tags
/*
foreach ($ip as $key => $value)
{
$content = str_replace('{'.$key.'}', $value, $content);
}
Redirection_Controller::update($ip->ip_address, $contact, $content, '');
}*/
//Redirection_Controller::update($ip->ip_address, $contact, $content, '');
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
......
foreach($ips as $ip)
{
// replace special tags
/*
foreach ($ip as $key => $value)
{
$content = str_replace('{'.$key.'}', $value, $content);
}
Redirection_Controller::update($ip->ip_address, $contact, $content, '');
*
*/
//Redirection_Controller::update($ip->ip_address, $contact, $content, '');
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
......
foreach($ips as $ip)
{
// replace special tags
/*
foreach ($ip as $key => $value)
{
$content = str_replace('{'.$key.'}', $value, $content);
}
$cancel_link = html::anchor($this->settings->get('self_cancel_url'), url_lang::lang('texts.I accept this message and I want to cancel this redirection'));
Redirection_Controller::update($ip->ip_address, $contact, $content, $cancel_link);
}*/
//$cancel_link = html::anchor($this->settings->get('self_cancel_url'), url_lang::lang('texts.I accept this message and I want to cancel this redirection'));
//Redirection_Controller::update($ip->ip_address, $contact, $content, $cancel_link);
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
freenetis/branches/redirection/application/controllers/redirect.php
*/
class Redirect_Controller extends Controller
{
function __construct()
{
parent::__construct();
/*if (!is_writable('static'))
{
Controller::error(WRITABLE, url_lang::lang('texts.Directory "static" is not writable, change access rights.'));
}*/
}
/**
* Gets redirection links.
......
/**
* Updates static html file with redirection message.
* @param $ip_address
* @return unknown_type
*/
static function update($ip_address)
{
$page = file_get_contents(url_lang::base().'web_interface/redirect_content/'.$ip_address);
$filename = $ip_address.'.html';
$file = fopen('static/'.$filename,'w+');
fputs($file, $page);
fclose($file);
}
/**
* Replaces special tags in curly brackets {tag} by value associated to target's member IP address.
* Unknown values for tags are replaced by question mark ?.
* @author Jiri Svitak
......
// member can cancel optional message and payment notice
if ($redir == 8 || $redir == 4)
{
// previous version
/*
$ip_address = ORM::factory('ip_address')->where('ip_address', server::remote_addr())->find();
$member = new Member_Model($ip_address->iface->device->user->member_id);
$member->redirect &= ~(int) $redir;
$member->redirect &= 15;
$member->save();
*/
// other possible solution
/*
$db = new Database();
$db->query("
UPDATE members m,
(
SELECT m2.id FROM members m2
JOIN users u ON u.member_id = m2.id
JOIN devices d ON d.user_id = u.id
JOIN ifaces i ON i.device_id = d.id
JOIN ip_addresses ip ON ip.iface_id = i.id
WHERE ip.ip_address = '".server::remote_addr()."'
) q
SET m.redirect = m.redirect & ~$redir
WHERE q.id = m.id
");
*/
// fastest query, found out by apache benchmark
$db = new Database();
$db->query("
......
}
/**
* Generates .htaccess file in static directory. This .htaccess file is used
* for used for redirecting IP address to proper static html. Selection
* is made by html referer IP address.
* @author Jiri Svitak
*/
function generate_htaccess()
{
// access rights
if (!$this->acl_check_new('Messages_Controller', 'message'))
Controller::error(ACCESS);
$htaccess =
"
Order deny,allow
# access from internet is denied
Deny from all
# allow access from localhost through IPv6 and IPv4, useful for development
#Allow from ::1
Allow from 127.0.0.1
# allow access from your local network, for example network 10.0.0.0/8
Allow from 10.0.0.0/8
RewriteEngine On
# condition if requested URL contains at the end string 'static'
RewriteCond %{REQUEST_URI} static/$
# this rule causes opening of html file with name of visitor's IP address
# visitor is shown his personalised redirection message (static html page)
RewriteRule .* /freenetis/static/%{REMOTE_ADDR}.html [L]
# if visitor's IP address has not file with its name, then document is not found
# in this case not found page has the meaning that IP address is unidentified
ErrorDocument 404 /freenetis/static/unknown_device_message.html
";
$page = $htaccess;
// save page to file
$file = fopen('static/.htaccess', 'w+');
fputs($file, $page);
fclose($file);
}
/**
* Returns string of html page of redirection.
* @author Jiri Svitak
* @param <type> $ip_address
* @param <type> $contact
* @param <type> $content
* @param string $footer
* @return string
*/
static function get_static_page($ip_address, $contact, $content, $footer)
{
// html code to contact
$to_contact =
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php // useful settings for expiration prevent caching of this website ?>
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Cache-Control" content="No-Cache" />
<title>'.url_lang::lang('texts.Redirection').'</title>
'.str_replace('https', 'http', html::stylesheet('media/css/style.css', 'screen')).'
<style type="text/css">
#content-padd h2 {margin: 10px 0px;}
#content-padd h3 {margin: 10px 0px;}
#content-padd li {margin-left: 20px;}
#content-padd a {font-weight: bold;}
td {width: 100px;}
</style>
</head>
<body>
<div id="main">
<div id="header">
<h1 id="logo"><span>Freenetis</span></h1>
<div class="status">
</div>
<div class="map"></div>
</div>
<div id="middle">
<div id="menu">
<div id="menu-padd">';
// html code to content
$to_content =
' </div>
</div>
<div id="content">
<div id="content-padd" style="margin:10px">';
// html code to footer
$to_footer =
' </div>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<div id="footer-padd" style="text-align:center;">';
// html code after footer
$after_footer =
' </div>
</div>
</div>
</body>
</html>';
if ($footer != '')
$footer = '<strong>'.$footer.'</strong>';
// generate page
$page = $to_contact.$contact.$to_content.$content.$to_footer.$footer.$after_footer;
return $page;
}
/**
* Updates static html file with redirection message.
* @author Jiri Svitak
* @param $ip_address
* @return unknown_type
*/
static function update($ip_address, $contact, $content, $footer)
{
// save page to file
$filename = $ip_address.'.html';
$file = fopen('static/'.$filename,'w+');
fputs($file, Redirect_Controller::get_static_page($ip_address, $contact, $content, $footer));
fclose($file);
}
/**
* Finds current redirection for given IP address and updates its static html page.
* @author Jiri Svitak
* @param <type> $ip_address
*/
static function find_current_redirection_and_update($ip_address)
{
// contact information
$contact_message = ORM::factory('message')->where(array('type' => Message_Model::$contact_information))->find();
$contact = $contact_message->text;
// find current redirection for ip
$ip_model = new Ip_address_Model();
$messages = $ip_model->get_current_redirection_of_ip_address($ip_address);
//if (count($messages) > 0)
}
function subnet($subnet_id = NULL)
{
// access rights
if (!$this->acl_check_edit('Members_Controller', 'redirect'))
Controller::error(ACCESS);
if (!isset($subnet_id))
Controller::warning(PARAMETER);
$subnet = new Subnet_Model($subnet_id);
if ($subnet->id == 0)
Controller::error(RECORD);
$array[0] = url_lang::lang('texts.No');
$array[1] = url_lang::lang('texts.Yes');
// form
$form = new Forge(url_lang::base().'redirect/subnet/'.$subnet_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Redirection'));
//$form->dropdown('payment_notice')->label(url_lang::lang('texts.Payment notice').':')->options($array)->selected(0);
$form->dropdown('optional_message')->label(url_lang::lang('texts.Optional message').':')->options($array)->selected(0);
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$message = $messages->current();
$content = $message->text;
foreach ($message as $key => $value)
{
$content = str_replace('{'.$key.'}', $value, $content);
}
$cancel_link = html::anchor(settings::get('self_cancel_url'), url_lang::lang('texts.I accept this message and I want to cancel this redirection'));
self::update($ip_address, $contact, $content, $message->self_cancel > 0 ? $cancel_link : '');
}
else
{
// view
$breadcrumbs[] = ($this->acl_check_view('Devices_Controller','subnet')) ? html::anchor(url_lang::base().'subnets/show_all', url_lang::lang('texts.Subnets')) : url_lang::lang('texts.Subnets');
$breadcrumbs[] = ($this->acl_check_view('Devices_Controller','subnet')) ? html::anchor(url_lang::base().'subnets/show/'.$subnet->id, $subnet->name." ($subnet->network_address/". network::netmask2cidr($subnet->netmask) .")") : $subnet->name." ($subnet->network_address/". network::netmask2cidr($subnet->netmask) .")";
$breadcrumbs[] = url_lang::lang('texts.Redirection');
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->breadcrumbs = implode(' » ',$breadcrumbs);
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
//$view->content->link_back = html::anchor(url_lang::base().'subnets/show/'.$subnet_id, url_lang::lang('texts.Back to the subnet'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
}
?>
freenetis/branches/redirection/application/views/members_show.php
<br class = "clear" />
<br />
<? if (!$former && $this->acl_check_edit('Messages_Controller', 'member')) { ?>
<h3><?php echo url_lang::lang('texts.Users')?></h3>
<?php echo $users_grid ?>
<br />
<? if ($this->acl_check_edit('Messages_Controller', 'member')) { ?>
<h3><?php echo url_lang::lang('texts.Ip addresses')?></h3>
<?php echo $redir_grid ?>
<br />
<?php } ?>
<h3><?php echo url_lang::lang('texts.Users')?></h3>
<?php echo $users_grid ?>
<br />
<h3><?php echo url_lang::lang('texts.VoIP')?></h3>
<?php echo $voip_grid ?>
<br />
freenetis/branches/redirection/redirection/index.php
<?php
/**
* Shows redirection page, written in pure PHP due to performance reasons,
* it is not necessary to load whole Kohana framework.
* @author Jiri Svitak
*/
// loading to access database password
define('SYSPATH', str_replace('\\', '/', realpath('system')).'/');
require '../config.php';
// connect to database
$link = mysql_connect($config['db_host'], $config['db_user'], $config['db_password']) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8", $link) or die(mysql_error());
mysql_query("SET NAMES utf8", $link) or die(mysql_error());
mysql_select_db($config['db_name']) or die(mysql_error());
// obtain remote ip address
$ip_address = $_SERVER['REMOTE_ADDR'];
// content of redirection message
$message_query = "
SELECT *
FROM
(
SELECT m.id, m.text, m.self_cancel, ip.ip_address, ip.whitelisted, s.name AS subnet_name,
members.name AS member_name, members.id AS member_id,
members.variable_symbol, a.balance, mip.comment
FROM messages m
JOIN messages_ip_addresses mip ON m.id = mip.message_id
JOIN ip_addresses ip ON ip.id = mip.ip_address_id
JOIN subnets s ON s.id = ip.subnet_id
JOIN ifaces i ON i.id = ip.iface_id
JOIN devices d ON d.id = i.device_id
JOIN users u ON u.id = d.user_id
JOIN members ON members.id = u.member_id
LEFT JOIN accounts a ON a.member_id = m.id AND m.id <> 1
WHERE ip.ip_address = '$ip_address'
ORDER BY m.self_cancel DESC, mip.datetime ASC
) q
GROUP BY q.id";
$message_result = mysql_query($message_query, $link) or die(mysql_error());
$message = mysql_fetch_array($message_result);
if ($message !== false)
{
$content = $message['text'];
}
// if no message found for given ip address, than redirection cancelled message will appear
else
{
$message_query = "SELECT * FROM messages WHERE ID = 2";
$message_result = mysql_query($message_query, $link) or die(mysql_error());
$message = mysql_fetch_array($message_result);
$content = $message['text'];
}
// text in left contact panel,
// it asssumed that after installation, there is always contact message with ID 1
$contact_query = "SELECT * FROM messages WHERE ID = 1";
$contact_result = mysql_query($contact_query, $link) or die(mysql_error());
$contact_array = mysql_fetch_array($contact_result) or die(mysql_error());
$contact = $contact_array['text'];
// replace tags in curly brackets to contain particular values associated to visitor
foreach ($message as $key => $value)
{
if ($key != 'text')
{
$content = str_replace('{'.$key.'}', $value, $content);
$contact = str_replace('{'.$key.'}', $value, $contact);
}
}
if ($message['self_cancel'] > 0)
$footer = '<a href="config.php">Beru na vědomí tuto zprávu a chci zrušit toto přesměrování</a>';
else
$footer = '';
// close database connection
mysql_close($link);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php // useful settings for expiration prevent caching of this website ?>
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Cache-Control" content="No-Cache" />
<title>Freenetis</title>
<?php // echo str_replace('https', 'http', html::stylesheet('media/css/style.css', 'screen')) ?>
<link href="../media/css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#content-padd h2 {margin: 10px 0px;}
#content-padd h3 {margin: 10px 0px;}
#content-padd li {margin-left: 20px;}
#content-padd a {font-weight: bold;}
td {width: 100px;}
</style>
</head>
<body>
<div id="main">
<div id="header">
<h1 id="logo"><span>Freenetis</span></h1>
<div class="status">
</div>
<div class="map"></div>
</div>
<div id="middle">
<div id="menu">
<div id="menu-padd">
<?php echo $contact ?>
</div>
</div>
<div id="content">
<div id="content-padd" style="margin:10px">
<?php echo $content; ?>
</div>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<div id="footer-padd" style="text-align:center;">
<?php //echo number_format(memory_get_usage() / 1024 / 1024, 2).' MB'; ?>
<?php echo $footer ?>
</div>
</div>
</div>
</body>
</html>

Také k dispozici: Unified diff