Revize 454
Přidáno uživatelem Jiří Sviták před asi 15 roky(ů)
freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'rating' => 'Ohodnocení',
|
||
'really delete this account' => 'Opravdu smazat tento účet',
|
||
'received member fees' => 'Přijaté členské příspěvky',
|
||
'redir' => 'Přesm',
|
||
'redirect' => 'Přesměrování',
|
||
'redirect as debtor' => 'Přesměrovat jako dlužníka',
|
||
'reg' => 'Přih.',
|
||
'register' => 'Registrovat',
|
freenetis/trunk/kohana/application/models/ipset.php | ||
---|---|---|
<?php
|
||
class Ipset_Model extends ORM
|
||
{
|
||
protected $has_and_belongs_to_many = array('ip_addresses');
|
||
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/subnet.php | ||
---|---|---|
|
||
protected $has_many = array('ip_addresses');
|
||
|
||
public function count_all_subnets()
|
||
/**
|
||
* Function counts all subnets specified by filter.
|
||
* @param $filter_values
|
||
* @return unknown_type
|
||
*/
|
||
public function count_all_subnets($filter_values = array())
|
||
{
|
||
return self::$db->count_records('subnets');
|
||
$where = '';
|
||
foreach($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if ($where == '')
|
||
$where = 'WHERE '.$key.' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
else
|
||
$where .= ' AND '.$key.' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
return self::$db->query("SELECT COUNT(*) AS total
|
||
FROM subnets
|
||
$where
|
||
")->current()->total;
|
||
}
|
||
|
||
/**
|
||
* Function gets all subnets specified by filter.
|
||
* @param $limit_from
|
||
* @param $limit_results
|
||
* @param $order_by
|
||
* @param $order_by_direction
|
||
* @param $filter_values
|
||
* @return unknown_type
|
||
*/
|
||
public function get_all_subnets($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'ASC', $filter_values = array())
|
||
{
|
||
$where = '';
|
||
foreach($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if ($where == '')
|
||
$where = 'WHERE '.$key.' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
else
|
||
$where .= ' AND '.$key.' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
|
||
}
|
||
}
|
||
return self::$db->query("SELECT *
|
||
FROM subnets
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results
|
||
");
|
||
}
|
||
|
||
/**
|
||
* Function gets subnets with slash notation like 192.168.0.0/24. Gateway redirect rules are applied
|
||
* to these ip address range. These ranges are downloaded by main gateway on address redirect/ipset/ranges.
|
||
* @return unknown_type
|
||
*/
|
||
public function get_subnets_to_redirect()
|
||
{
|
||
return self::$db->query("SELECT
|
||
CONCAT(network_address, '/', 32-log2((~inet_aton(netmask) & 0xffffffff) + 1)) AS range
|
||
FROM subnets
|
||
WHERE redirect = 1
|
||
");
|
||
}
|
||
|
||
/**
|
||
* Function gets items of subnet to export.
|
||
* @param $subnet_id
|
||
* @return unknown_type
|
freenetis/trunk/kohana/application/models/ip_address.php | ||
---|---|---|
class Ip_address_Model extends ORM {
|
||
|
||
protected $belongs_to = array('iface','subnet','vlan_iface');
|
||
protected $has_and_belongs_to_many = array('ipsets');
|
||
|
||
/**
|
||
* Function counts all ip addresses.
|
freenetis/trunk/kohana/application/controllers/subnets.php | ||
---|---|---|
Controller::error(ACCESS);
|
||
// get new selector
|
||
if (is_numeric($this->input->get('record_per_page'))) $limit_results = (int) $this->input->get('record_per_page');
|
||
|
||
// creates fields for filtering members
|
||
$filter=new Table_Form(url_lang::base()."subnets/show_all", "get", array(
|
||
new Table_Form_Item('text','name','Name'),
|
||
new Table_Form_Item('text','network_address','Network address'),
|
||
"tr", "td", "td", "td",
|
||
new Table_Form_Item('submit','submit','Filter')
|
||
)
|
||
);
|
||
$arr_gets = array();
|
||
foreach ($this->input->get() as $key=>$value)
|
||
$arr_gets[] = $key.'='.$value;
|
||
$query_string = '?'.implode('&',$arr_gets);
|
||
|
||
$subnet_model = new Subnet_Model();
|
||
$total_subnets = $subnet_model->count_all_subnets();
|
||
$total_subnets = $subnet_model->count_all_subnets($filter->values());
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_subnets)
|
||
$sql_offset = 0;
|
||
$query = $subnet_model->orderby($order_by,$order_by_direction)->limit($limit_results,$sql_offset)->find_all();
|
||
|
||
//$query = $subnet_model->orderby($order_by,$order_by_direction)->limit($limit_results,$sql_offset)->find_all();
|
||
$query = $subnet_model->get_all_subnets($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter->values());
|
||
|
||
$grid = new Grid(url_lang::base().'subnets', null,array(
|
||
//'separator' => '<br />-----------',
|
||
//'use_paginator' => false,
|
||
... | ... | |
'style' => 'classic',
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results
|
||
'limit_results' => $limit_results,
|
||
'filter' => $filter->view,
|
||
'query_string' => $query_string
|
||
));
|
||
|
||
if ($this->acl_check_new('Devices_Controller', 'subnet'))
|
||
... | ... | |
$grid->order_field('name')->label(url_lang::lang('texts.name'));
|
||
$grid->order_field('network_address')->label(url_lang::lang('texts.Network address'));
|
||
$grid->order_field('netmask')->label(url_lang::lang('texts.Netmask'));
|
||
$grid->order_field('redirect')->label(url_lang::lang('texts.Redir').'.')->bool(array(url_lang::lang('texts.No'),url_lang::lang('texts.Yes')))->class('center');
|
||
//$grid->order_field('OSPF_area_id')->label(url_lang::lang('texts.OSPF area ID'));
|
||
if ($this->acl_check_view('Devices_Controller', 'subnet'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Subnet')) ->url(url_lang::base().'subnets/show') ->action(url_lang::lang('texts.Show'))->class('center');
|
||
... | ... | |
if (!$this->acl_check_new('Devices_Controller', 'subnet'))
|
||
Controller::error(ACCESS);
|
||
|
||
$redirect[0] = url_lang::lang('texts.No');
|
||
$redirect[1] = url_lang::lang('texts.Yes');
|
||
$form = new Forge(url_lang::base()."subnets/add/", '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
$form->group('')->label(url_lang::lang('texts.Basic data'));
|
||
... | ... | |
$form->input('netmask')->label(url_lang::lang('texts.Netmask').':')
|
||
->rules('required|length[1,250]');
|
||
$form->input('OSPF_area_id')->label(url_lang::lang('texts.OSPF area ID').':')->rules('valid_digit');
|
||
$form->dropdown('redirect')->label(url_lang::lang('texts.Redirect'))->options($redirect)->selected(0);
|
||
$form->submit('submit')->value(url_lang::lang('texts.Save'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
... | ... | |
if($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
foreach($form_data as $key => $value)
|
||
{
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
$subnet = new Subnet_Model();
|
||
|
||
$subnet->name = $form_data['name'];
|
||
$subnet->network_address = $form_data['network_address'];
|
||
$subnet->netmask = $form_data['netmask'];
|
||
$subnet->OSPF_area_id = $form_data['OSPF_area_id'];
|
||
$subnet->redirect = $form_data['redirect'];
|
||
|
||
unset($form_data);
|
||
|
||
... | ... | |
Controller::error(RECORD);
|
||
if (!$this->acl_check_edit('Devices_Controller', 'subnet'))
|
||
Controller::error(ACCESS);
|
||
|
||
$redirect[0] = url_lang::lang('texts.No');
|
||
$redirect[1] = url_lang::lang('texts.Yes');
|
||
$this->form = $form = new Forge(url_lang::base()."subnets/edit/".$subnet_id, '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
$form->group('')->label(url_lang::lang('texts.Basic data'));
|
||
... | ... | |
$form->input('netmask')->label(url_lang::lang('texts.Netmask').':')
|
||
->rules('required|length[1,250]')->value($subnet->netmask);
|
||
$form->input('OSPF_area_id')->label(url_lang::lang('texts.OSPF area ID').':')->rules('valid_digit')->value($subnet->OSPF_area_id);
|
||
$form->dropdown('redirect')->label(url_lang::lang('texts.Redirect'))->options($redirect)->selected($subnet->redirect);
|
||
$form->submit('submit')->value(url_lang::lang('texts.update'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
if($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
foreach($form_data as $key => $value)
|
||
{
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
$subnet = new Subnet_Model($subnet_id);
|
||
|
||
$subnet->name = $form_data['name'];
|
||
$subnet->network_address = $form_data['network_address'];
|
||
$subnet->netmask = $form_data['netmask'];
|
||
$subnet->OSPF_area_id = $form_data['OSPF_area_id'];
|
||
|
||
$subnet->redirect = $form_data['redirect'];
|
||
|
||
unset($form_data);
|
||
|
||
if ($subnet->save())
|
freenetis/trunk/kohana/application/controllers/redirect.php | ||
---|---|---|
// list of network address ranges to redirect
|
||
case 'ranges':
|
||
$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model
|
||
->select("id","name","network_address as net_str",
|
||
"inet_aton(network_address) as net",
|
||
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")
|
||
->orderby('net')->find_all();
|
||
$subnets = $subnet_model->get_subnets_to_redirect();
|
||
foreach ($subnets as $subnet)
|
||
{
|
||
echo "$subnet->net_str/$subnet->mask\n";
|
||
echo "$subnet->range\n";
|
||
}
|
||
break;
|
||
// special list of ip addresses - some ip addresses are never redirected
|
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql.php | ||
---|---|---|
|
||
// array of sql queries that upgrade database
|
||
$upgrade_sql[get_SVN_rev()] = array(
|
||
"ALTER TABLE `members` ADD `redirect` TINYINT NULL DEFAULT NULL COMMENT 'Bit mask for types of redirect' AFTER `organization_identifier` ",
|
||
"ALTER TABLE `subnets` ADD `redirect` TINYINT NULL DEFAULT NULL COMMENT 'Bit mask for types of redirect' AFTER `netmask` ",
|
||
"DROP TABLE `ipsets`",
|
||
"DROP TABLE `ipsets_ip_addresses`",
|
||
"ALTER TABLE `ip_addresses` DROP `redirect` "
|
||
"ALTER TABLE `transfers` ADD `user_id` INT NULL AFTER `member_id` "
|
||
);
|
||
|
||
|
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql_453.php | ||
---|---|---|
<?php
|
||
$upgrade_sql[453] = array(
|
||
"ALTER TABLE `members` ADD `redirect` TINYINT NULL DEFAULT NULL COMMENT 'Bit mask for types of redirect' AFTER `organization_identifier` ",
|
||
"ALTER TABLE `subnets` ADD `redirect` TINYINT NULL DEFAULT NULL COMMENT 'Bit mask for types of redirect' AFTER `netmask` ",
|
||
"DROP TABLE `ipsets`",
|
||
"DROP TABLE `ipsets_ip_addresses`",
|
||
"ALTER TABLE `ip_addresses` DROP `redirect` "
|
||
);
|
||
?>
|
freenetis/trunk/kohana/application/libraries/MY_Controller.php | ||
---|---|---|
switch ($type)
|
||
{
|
||
case $this->ICON_ERROR:
|
||
$view->header->title = 'Error';
|
||
$view->title = 'Error';
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/error.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
break;
|
||
case $this->ICON_GOOD:
|
||
$view->header->title = 'Good';
|
||
$view->title = 'Good';
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/good.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
break;
|
||
case $this->ICON_HELP:
|
||
$view->header->title = 'Help';
|
||
$view->title = 'Help';
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/help.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
break;
|
||
case $this->ICON_INFO:
|
||
$view->header->title = 'Info';
|
||
$view->title = 'Info';
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/info.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
break;
|
||
case $this->ICON_WARNING:
|
||
$view->header->title = 'Warning';
|
||
$view->title = 'Warning';
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/warning.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
break;
|
||
}
|
freenetis/trunk/kohana/application/views/show_subnet.php | ||
---|---|---|
<th><?php echo url_lang::lang('texts.OSPF area ID') ?></th>
|
||
<td><?php echo $subnet->OSPF_area_id ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo url_lang::lang('texts.Redirect') ?></th>
|
||
<td><?php echo ($subnet->redirect == 1) ? url_lang::lang('texts.Yes') : url_lang::lang('texts.No') ?></td>
|
||
</tr>
|
||
</table>
|
||
|
||
|
freenetis/trunk/kohana/application/views/menu.php | ||
---|---|---|
<?php if ($this->acl_check_2D('menu', 'my_users')) { ?>
|
||
<li><?php echo html::anchor(url_lang::base().'users/show_by_member/'.$this->session->get('member_id'), url_lang::lang('texts.My users')) ?></li>
|
||
<?php } ?>
|
||
<?php if ($this->acl_check_2D('menu', 'my_transfers')) { ?>
|
||
<li><?php echo html::anchor(url_lang::base().'transfers/show_by_member/'.$this->session->get('member_id'), url_lang::lang('texts.My transfers')) ?></li>
|
||
<?php if ($this->acl_check_2D('menu', 'my_transfers') && $this->session->get('member_id') != 1) {
|
||
$account = ORM::factory('account')->find_by_member_id($this->session->get('member_id'));
|
||
?>
|
||
<li><?php echo html::anchor(url_lang::base().'transfers/show_by_account/'.$account->id, url_lang::lang('texts.My transfers')) ?></li>
|
||
<?php } ?>
|
||
<?php if ($this->acl_check_2D('menu', 'my_devices')) { ?>
|
||
<li><?php echo html::anchor(url_lang::base().'devices/show_by_user/'.$this->session->get('user_id'), url_lang::lang('texts.My devices')) ?></li>
|
||
<?php } ?>
|
||
<?php if ($this->acl_check_2D('menu', 'my_works')) { ?>
|
||
<?php if ($this->acl_check_2D('menu', 'my_works') && $this->session->get('member_id') != 1) { ?>
|
||
<li><?php echo html::anchor(url_lang::base().'works/show_by_user/'.$this->session->get('user_id'), url_lang::lang('texts.My works')) ?></li>
|
||
<?php } ?>
|
||
</ul>
|
Také k dispozici: Unified diff
Opravy chyb. V tabulce prevodu pridano user_id pro evidenci uzivatele, ktery prevod provedl. Pridan filtr pro podsite a moznost nastaveni presmerovani pro podsit. Vypis podsiti v presmerovani je na redirect/ipset/ranges. Pro vybrane podsite se tedy budou na centralnim routeru aplikovat pravidla. Pokud IP adresa patrici do presmerovane podsite neni v seznamu povolenych ip adres na redirect/ipset/members, pak je presmerovana na stranku redirect. Freenetis si sam ohlida duvody presmerovani a vypise je (napr. dluznik, neznamy pocitac, pozvanka na valnou hromadu, atd.).