Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 656

Přidáno uživatelem Jiří Sviták před více než 14 roky(ů)

Moznost presmerovat jednu IP adresu, pridany dalsi exporty dat pro presmerovani.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'back to double-entry accounts' => 'Zpět na podvojné účty',
'back to interface parameters' => 'Zpět na parametry rozhraní',
'back to interfaces list' => 'Zpět na seznam rozhraní',
'back to ip address' => 'Zpět na IP adresu',
'back to ip addresses list' => 'Zpět na seznam IP adres',
'back to list of all address points' => 'Zpět na seznam všech adresních bodů',
'back to list of routerboard backups' => 'Zpět na seznam záloh routerboardů',
......
'collateral' => 'Vedlejší',
'column headers' => 'Hlavičky sloupců',
'comment' => 'Komentář',
'comment of admin shown to user' => 'Komentář administrátora zobrazený uživateli',
'configuration files' => 'Konfigurační soubory',
'confirm' => 'Potvrdit',
'confirm password' => 'Heslo znovu',
freenetis/trunk/kohana/application/models/message.php
public static $cancel_message = 2;
public static $contact_information = 3;
// self cancel disabled, remote computer cannot cancel this message
public static $disabled = 0;
// self cancel enabled, every member's IP address has cancelled given redirection
public static $member = 1;
// self cancel enabled, redirection is canceled only for current remote computer
public static $ip = 2;
/**
* Counts all active redirections from junction table messages_ip_addresses.
......
* Gets all active redirections from junction table messages_ip_addresses.
* @return unknown_type
*/
public function get_all_redirections($limit_from = 0, $limit_results = 20, $order_by = 'ip_address_id', $order_by_direction = 'ASC', $filter_values = array())
public function get_all_redirections($limit_from = 0, $limit_results = 20, $order_by = 'ip_address', $order_by_direction = 'ASC', $filter_values = array())
{
if ($order_by == 'ip_address')
$order_by = 'inet_aton(ip_address)';
return self::$db->query("
SELECT *
SELECT ip.ip_address, m.name, mip.datetime
FROM messages_ip_addresses mip
LEFT JOIN ip_addresses ip ON ip.id = mip.ip_address_id
LEFT JOIN messages m ON m.id = mip.message_id
ORDER BY $order_by $order_by_direction
LIMIT $limit_from, $limit_results
");
......
LIMIT $limit_from, $limit_results
");
}
}
?>
freenetis/trunk/kohana/application/controllers/web_interface.php
<?php
/**
*
* Controller used for communication between Freenetis and other remote devices,
* for example network gateways, routers, access points etc.
*
* @author Jiri Svitak
*
*/
class Web_interface_Controller extends Controller
{
function __construct()
{
$this->db = new Database();
}
function index()
{
echo "interface for communication over http protocol with remote devices";
}
/**
* Prints to output all IP addresses, which never should be redirected.
* @author Jiri Svitak
* @return unknown_type
*/
function whitelist()
{
$ips = $this->db->query("
SELECT DISTINCT ip_address
FROM ip_addresses
WHERE whitelisted = 1
");
foreach($ips as $ip)
{
echo "$ip->ip_address\n";
}
}
/**
* Prints to output all subnets which have enabled redirection. Any IP address belonging to these
* subnet ranges can be redirected.
* @author Jiri Svitak
* @return unknown_type
*/
function redirected_ranges()
{
$ranges = $this->db->query("
SELECT DISTINCT CONCAT(network_address, '/', 32-log2((~inet_aton(netmask) & 0xffffffff) + 1)) AS subnet_range
FROM subnets
WHERE redirect = 1
");
foreach($ranges as $range)
{
echo "$range->subnet_range\n";
}
}
/**
* Prints all allowed IP addresses. These are registered IP addresses, which have no redirection set.
* Unknown IP addresses (not present in system) and IP addresses with a redirection set are not exported.
* @author Jiri Svitak
* @return unknown_type
*/
function allowed_ip_addresses()
{
$ips = $this->db->query("
SELECT DISTINCT ip.ip_address, m.ip_address_id
FROM ip_addresses ip
LEFT JOIN messages_ip_addresses m ON m.ip_address_id = ip.id
");
foreach($ips as $ip)
{
if (!isset($ip->ip_address_id))
echo "$ip->ip_address\n";
}
}
/**
* Prints IP addresses which have current redirection self-cancelable. IP address may have more
* redirections set in junction table, but only one (determined by self_cancel flag, system flag and
* datetime) is currently active.
* @author Jiri Svitak
* @return unknown_type
*/
function self_cancelable_ip_addresses()
{
$ips = $this->db->query("
SELECT DISTINCT ip.ip_address, m.self_cancel
FROM ip_addresses ip
JOIN messages_ip_addresses mip ON mip.ip_address_id = ip.id
JOIN messages m ON m.id = mip.message_id
ORDER BY m.self_cancel DESC, m.system ASC, mip.datetime ASC
LIMIT 1
");
foreach($ips as $ip)
{
if ($ip->self_cancel > 0)
echo "$ip->ip_address $ip->self_cancel<br>\n";
}
}
/**
* Method used for exchange of synchronization status between Freenetis and central router.
* @author Jiri Svitak
* @param $synchronized
* @return unknown_type
*/
function synchronized($synchronized = null)
{
// test if central router has send information about its synchronization status
// if necessary update synchronization status in Freenetis
if (isset($synchronized))
{
}
// if central router has not set anything, then this method returns synchronization status of Freenetis
else
{
}
}
/**
* Receives with POST method list of IP addresses which have active self-cancelable redirection and
* they have already visited canceling page. So this method cancels redirection in Freenetis database.
* @author Jiri Svitak
* @return unknown_type
*/
function already_seen()
{
}
}
?>
freenetis/trunk/kohana/application/controllers/messages.php
'url_array_ofset' => 1,
));
$grid->add_new_button(url_lang::base().'messages/show_all', url_lang::lang('texts.Messages for redirection'));
$grid->add_new_button(url_lang::base().'redirect/show_all', url_lang::lang('texts.Active Redirections'));
$grid->add_new_button(url_lang::base().'messages/show_all', url_lang::lang('texts.Messages for redirection'));
$grid->add_new_button(url_lang::base().'redirect/settings', url_lang::lang('texts.Settings'));
$grid->order_field('id')->label('ID');
$grid->order_field('name')->label(url_lang::lang('texts.Name'));
freenetis/trunk/kohana/application/controllers/redirect.php
* @param $page
* @return unknown_type
*/
function show_all($limit_results = 500, $order_by = 'id', $order_by_direction = 'desc', $page_word = null, $page = 1)
function show_all($limit_results = 500, $order_by = 'ip_address', $order_by_direction = 'desc', $page_word = null, $page = 1)
{
// access rights
if (!$this->acl_check_view('Redirection_Controller', 'redirection'))
......
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
$allowed_order_type = array('id', 'from', 'to', 'extension', 'opening_balance', 'closing_balance');
$allowed_order_type = array('ip_address', 'name', 'datetime');
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
if (strtolower($order_by_direction) != 'asc' && strtolower($order_by_direction) != 'desc')
......
// model
$message_model = new Message_Model();
$total_redirections = $message_model->count_redirections();
$total_redirections = $message_model->count_all_redirections();
if (($sql_offset = ($page - 1) * $limit_results) > $total_redirections)
$sql_offset = 0;
$redirections = $message_model->get_redirections($sql_offset, (int)$limit_results, $order_by, $order_by_direction);
$redirections = $message_model->get_all_redirections($sql_offset, (int)$limit_results, $order_by, $order_by_direction);
$headline = url_lang::lang('texts.Active redirections');
$grid = new Grid(url_lang::base().'redirect', null, array(
......
'url_array_ofset' => 1,
));
$grid->add_new_button(url_lang::base().'messages/show_all', url_lang::lang('texts.Messages for redirection'));
$grid->add_new_button(url_lang::base().'redirect/show_all', url_lang::lang('texts.Active Redirections'));
$grid->add_new_button(url_lang::base().'messages/show_all', url_lang::lang('texts.Messages for redirection'));
$grid->add_new_button(url_lang::base().'redirect/settings', url_lang::lang('texts.Settings'));
$grid->order_field('ip_address_id')->label('ID');
$grid->order_field('ip_address')->label(url_lang::lang('texts.IP address'));
$grid->order_field('name')->label(url_lang::lang('texts.Redirection'));
$grid->order_field('datetime')->label(url_lang::lang('texts.Date and time'));
/*
$grid->order_field('from')->label(url_lang::lang('texts.Date from'));
$grid->order_field('to')->label(url_lang::lang('texts.Date to'));
$grid->order_field('extension')->label(url_lang::lang('texts.Type'));
$grid->order_field('opening_balance')->label(url_lang::lang('texts.Opening balance'));
$grid->order_field('closing_balance')->label(url_lang::lang('texts.Closing balance'));
if ($this->acl_check_view('Accounts_Controller', 'bank_transfers'))
$grid->action_field('id') ->label(url_lang::lang('texts.Bank transfers'))->url(url_lang::base().'bank_transfers/show_by_bank_statement')->action(url_lang::lang('texts.Show'));
*/
......
}
/**
* Adds IP address (or including IP addreses of member, or including IP addresses in subnet)
* to junction table for redirection.
* @param $ip_address_id
* @return unknown_type
*/
function add($ip_address_id = null)
{
// access rights
//if (!$this->acl_check_edit('Members_Controller', 'redirect'))
// Controller::error(ACCESS);
if (!isset($ip_address_id))
Controller::warning(PARAMETER);
// ip address
$ip = new Ip_address_Model($ip_address_id);
if ($ip->id == 0)
Controller::error(RECORD);
//$array[0] = url_lang::lang('texts.No');
//$array[1] = url_lang::lang('texts.Yes');
// load list of usable redirection message
$message_model = new Message_Model();
$messages = $message_model->find_all();
foreach($messages as $message)
{
if ($message->type == Message_Model::$normal_message)
$message_array[$message->id] = $message->name;
}
// form
$form = new Forge(url_lang::base().'redirect/add/'.$ip_address_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('message_id')->label(url_lang::lang('texts.Redirection').':')->options($message_array);
$form->textarea('comment')->label(url_lang::lang('texts.Comment of admin shown to user').':');
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
// message_id, ip_address_id, user_id, comment, datetime
//$ip->add_redirection($form_data['message_id'], $ip->id, $this->session->get('user_id'), $form_data['comment'], date('Y-m-d'));
/*
$redir = new Messages_ip_address_Model();
$redir->message_id = $form_data['message_id'];
$redir->ip_address_id = $ip->id;
$redir->user_id = $this->session->get('user_id');
$redir->comment = $form_data['comment'];
$redir->date = date('Y-m-d');
*/
$db = new Database();
try
{
$db->insert('messages_ip_addresses', array('message_id' => $form_data['message_id'],
'ip_address_id' => $ip->id, 'user_id' => $this->session->get('user_id'),
'comment' => $form_data['comment'], 'datetime' => date('Y-m-d')));
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
}
catch(Kohana_Database_Exception $e)
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cant set redirection.'));
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
}
}
else
{
// view
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->link_back = html::anchor(url_lang::base().'ip_addresses/show/'.$ip_address_id, url_lang::lang('texts.Back to IP address'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Function tests redirection.
* @todo old version
* @author Jiri Svitak
freenetis/trunk/kohana/application/controllers/ip_addresses.php
//if ($this->acl_check_edit('Devices_Controller','ip_address'))
// $grid->action_field('id')->label(url_lang::lang('texts.Edit'))->url(url_lang::base().'ip_addresses/edit')->action(url_lang::lang('texts.Edit'))->class('center');
if ($this->acl_check_edit('Devices_Controller','ip_address'))
$grid->action_field('id')->label(url_lang::lang('texts.Redirection'))->url(url_lang::base().'redirection/addip')->action(url_lang::lang('texts.Redirect'))->class('center');
$grid->action_field('id')->label(url_lang::lang('texts.Redir'))->url(url_lang::base().'redirect/add')->action(url_lang::lang('texts.Redirect'))->class('center');
if ($this->acl_check_edit('Devices_Controller','ip_address'))
$grid->action_field('id')->label(url_lang::lang('texts.Smokeping'))->url(url_lang::base().'monitoring/add_smokeping')->action(url_lang::lang('texts.Monitor'))->class('center');
if ($this->acl_check_delete('Devices_Controller','ip_address'))
......
}
// end validate --------------------------------------------------
if ($ip_address->vlan_iface_id) $link_back = html::anchor(url_lang::base().'vlan_ifaces/show/'.$ip_address->vlan_iface_id, url_lang::lang('texts.Back to VLAN interface parameters'));
elseif ($ip_address->iface_id) $link_back = html::anchor(url_lang::base().'ifaces/show/'.$ip_address->iface_id, url_lang::lang('texts.Back to interface parameters'));
else $link_back = html::anchor(url_lang::base().'ip_addresses/show_all', url_lang::lang('texts.Back to IP addresses list'));
if ($ip_address->vlan_iface_id)
$link_back = html::anchor(url_lang::base().'vlan_ifaces/show/'.$ip_address->vlan_iface_id, url_lang::lang('texts.Back to VLAN interface parameters'));
elseif ($ip_address->iface_id)
$link_back = html::anchor(url_lang::base().'ifaces/show/'.$ip_address->iface_id, url_lang::lang('texts.Back to interface parameters'));
else
$link_back = html::anchor(url_lang::base().'ip_addresses/show_all', url_lang::lang('texts.Back to IP addresses list'));
$view = new View('main');
$view->title = url_lang::lang('texts.Edit IP address').' - '.$ip_address->ip_address;
$view->content = new View('form');
freenetis/trunk/kohana/application/views/ip_addresses_show.php
$links[] = html::anchor(url_lang::base().'ip_addresses/edit/'.$ip_address->id, url_lang::lang('texts.Edit'));
if ($this->acl_check_delete('Devices_Controller', 'ip_address'))
$links[] = html::anchor(url_lang::base().'ip_addresses/delete/'.$ip_address->id, url_lang::lang('texts.Delete'));
// @todo access rights
$links[] = html::anchor(url_lang::base().'redirect/add/'.$ip_address->id, url_lang::lang('texts.Redirect'));
echo implode(' | ', $links);
?>
<br /><br />

Také k dispozici: Unified diff