Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 955

Přidáno uživatelem Michal Kliment před více než 13 roky(ů)

Snad dodelana vetev pro prirazeni podsiti k clenovi. Zbyva otestovat a pak mergovat do testingu.

Zobrazit rozdíly:

freenetis/branches/subnets_assigning/application/i18n/cs_CZ/texts.php
'deduction of device repayments' => 'Stržení splátek zařízení',
'deduction of entrance fees' => 'Stržení vstupních příspěvků',
'default approval template' => 'Výchozí hlasovací šablona',
'default count' => 'Výchozí počet',
'default driver' => 'Výchozí ovladač',
'default e-mail' => 'Výchozí e-mail',
'default vote' => 'Výchozí hlas',
freenetis/branches/subnets_assigning/application/i18n/cs_CZ/help.php
'add_new_bank_transfer_without_counteraccount' => 'Umožňuje přidat bankovní převod bez protiúčtu, jde typicky o vklad, úrok bance apod. V běžném provozu využívejte automatický import výpisů. Ruční přidávání je tu pouze z důvodu, že byla potřeba dát do systému staré platby, které již nebylo možné parsovat.',
'add_new_transfer' => 'Zobrazí formulář, který umožňuje hospodáři sdružení přidat libovolný převod mezi dvěma podvojnými účty. Účetní korektnost tohoto zásahu je ovšem v zodpovědnosti účetního.',
'add_from_account' => 'Umožňuje poslat peníze z účtu na jiný účet. Například člen může poslat peníze na projektový účet na podporu nějakého projektu nebo jinému členovi, např. zaplatit rodičům internet, pokud mají samostatnou přípojku.',
'allowed_subnets' => 'Jedná se o možnost omezovat provoz členů na určitý počet současně jedoucích přípojných míst. Předpokládá, že každé přípojné místo člena se nachází v jiné podsíti.',
'allowed_subnets_count' => 'Jedná se o maximální počet současně povolených podsítí člena. IP adresám mimo těchto podsítí bude blokován přístup na internet (formou přesměrování). Nula znamená neomezený počet.',
'allowed_subnets_default_count' => 'Jedná se o výchozí počet současně povolených podsítí člena. IP adresám mimo těchto podsítí bude blokován přístup na internet (formou přesměrování). Nula znamená neomezený počet.',
'allowed_subnets_update_interval' => 'Interval aktualizace povolených podsítí v sekundách. Po uplynutí této doby se IP adresám z nepovolených podsítí nastaví přesměrování typu Přerušené členství. Výchozí hodnota je 60 sekund (1 minuta).',
'application_password' => 'Aplikační heslo slouží uživateli pro přihlášení ke službám, které jsou závislé na Radius serveru, jako například VPN, aktivní prvky sítě atd. Toto heslo je v databázi uloženo v otevřené podobě.',
'approval_state' => 'Stav je ve formátu Pro / Proti / Zdrželi se.',
'bank_accounts' => 'Bankovní účty jsou primárně vytvářeny automaticky během importu bankovního výpisu. V případě úspěšného rozpoznání platby je rovnou tento bankovní účet svázán s rozpoznaným členem. V případě, že člen v budoucnu splete variabilní symbol, pak toto ukládání bankovních účtů usnadňuje identifikaci platby v případě, že opět platil ze stejného účtu. Ruční přidávání bankovních účtů je vyhrazeno pro nestandardní případy.',
freenetis/branches/subnets_assigning/application/models/ip_address.php
}
/**
* Clear redirect state of ip addresses
*
* @author Michal Kliment
*/
public function clear_disable_ips ()
{
$this->db->query("UPDATE ip_addresses SET redirect = redirect & ~1;");
}
/**
* Updates redirect state of ip_addresses
*
* @author Michal Kliment
......
*/
public function update_allowed_ips ()
{
return $this->db->query("UPDATE ip_addresses SET redirect = redirect & ~1;");
return $this->db->query("
$this->clear_disable_ips();
$this->db->query("
UPDATE ip_addresses ip,
(
SELECT ip_address_id FROM
freenetis/branches/subnets_assigning/application/models/subnets_owner.php
}
/**
* Clears state of redirect of ip addresses
*
* @author Michal Kliment
*/
public function clear_allowed_subnets ()
{
$this->db->query("UPDATE subnets_owners SET redirect = redirect & ~1;");
}
/**
* Updates state of redirect of subnet with set owner
*
* @author Michal Kliment
......
*/
public function update_allowed_subnets ()
{
return $this->db->query("UPDATE subnets_owners SET redirect = redirect & ~1;");
return $this->db->query("
$this->clear_allowed_subnets();
$this->db->query("
UPDATE subnets_owners so,
(
SELECT so.id FROM subnets_owners so
freenetis/branches/subnets_assigning/application/models/member.php
ORDER BY name
");
}
/**
* Returns doubleentry account of member by given account attribute id
*
* @author Michal Kliment
* @param integer $account_attribute_id
* @return MySQL Result object
*/
public function get_doubleentry_account ($account_attribute_id)
{
return $this->db->query("
SELECT * FROM accounts a
WHERE account_attribute_id = ? AND member_id = ?
", array($account_attribute_id, $this->id))->current();
}
}
?>
freenetis/branches/subnets_assigning/application/controllers/transfers.php
'query_string' => $query_string,
'filter' => $filter->view
));
// payment cash link
if ($this->acl_check_new('Accounts_Controller', 'transfers', $account->member_id))
{
$transfers_grid->add_new_button(url_lang::base().'transfers/add_member_fee_payment_by_cash/'.$account->member->id, url_lang::lang('texts.Payment by cash'));
$transfers_grid->add_new_button(url_lang::base().'transfers/add_from_account/'.$account_id, url_lang::lang('texts.Send money to other account'), array(), help::hint('add_from_account'));
$billing = new Billing();
$account= ORM::factory('account')->where('id', $account_id)->find();
......
}
else
{
$account = $member->get_doubleentry_account (Account_attribute_Model::$credit);
$breadcrumbs = array();
$breadcrumbs[] = html::anchor (url_lang::base().'members/show_all', url_lang::lang('texts.Members'));
$breadcrumbs[] = html::anchor(url_lang::base().'members/show/'.$member->id,"ID ".$member->id." - ".$member->name);
$breadcrumbs[] = html::anchor(url_lang::base().'transfers/show_by_account/'.$account->id, url_lang::lang('texts.Transfers'));
$breadcrumbs[] = url_lang::lang('texts.Add member fee payment by cash');
$headline = url_lang::lang('texts.Add member fee payment by cash');
$view = new View('main');
$view->breadcrumbs = implode(' » ', $breadcrumbs);
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form->html();
$links[] = html::anchor(url_lang::base().'members/show/'.$member_id, url_lang::lang('texts.Back to the member'));
$links[] = html::anchor(url_lang::base().'transfers/show_by_account/'.$credit->id, url_lang::lang('texts.Back to transfers of member'));
$view->content->link_back = implode(' | ', $links);
//$links[] = html::anchor(url_lang::base().'members/show/'.$member_id, url_lang::lang('texts.Back to the member'));
//$links[] = html::anchor(url_lang::base().'transfers/show_by_account/'.$credit->id, url_lang::lang('texts.Back to transfers of member'));
//$view->content->link_back = implode(' | ', $links);
$view->render(TRUE);
}
freenetis/branches/subnets_assigning/application/controllers/subnets.php
Allowed_subnets_Controller::update_enabled($form_data['owner_id'], array($subnet->id));
}
else
$subnet->subnets_owner->delete();
if ($subnet->subnets_owner->member->id && !ORM::factory('ip_address')->count_all_ip_addresses_by_member_and_subnet ($subnet->subnets_owner->member->id, $subnet->id))
Allowed_subnets_Controller::update_enabled($subnet->subnets_owner->member->id, NULL, NULL, array($subnet->id));
}
$subnet->name = $form_data['name'];
......
if ($subnet->save())
{
$this->session->set_flash('message', url_lang::lang('texts.Subnet has been successfully updated.'));
}
freenetis/branches/subnets_assigning/application/controllers/ip_addresses.php
{
$form_data[$key] = htmlspecialchars($value);
}
$ip = new ip_address_Model();
if ($form_data['iface_id'])
{
$iface = new Iface_Model($form_data['iface_id']);
$member_id = $iface->device->user->member->id;
$ip->iface_id = $form_data['iface_id'];
}
else
{
$vlan_iface = new Vlan_iface_Model($form_data['vlan_iface_id']);
$member_id = $vlan_iface->iface->device->user->member->id;
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
}
$ip = new ip_address_Model();
if (isset($form_data['iface_id']))
$ip->iface_id = $form_data['iface_id'];
if (isset($form_data['vlan_iface_id']))
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
$ip->ip_address = $form_data['ip_address'];
$ip->subnet_id = $form_data['subnet_id'];
$ip->gateway = $form_data['gateway'];
......
unset($form_data);
if ($ip->save())
{
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
Allowed_subnets_Controller::update_enabled($member_id, array($ip->subnet_id));
}
url::redirect($link_back_url);
}
......
if ($ip->save())
{
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
url::redirect(url_lang::base().'ifaces/show/'.$iface_id);
exit;
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
Allowed_subnets_Controller::update_enabled($iface->device->user->member_id, array($ip->subnet_id));
}
url::redirect(url_lang::base().'ifaces/show/'.$iface_id);
}
else
{
......
if ($ip->save())
{
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
url::redirect(url_lang::base().'vlan_ifaces/show/'.$vlan_iface_id);
exit;
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
Allowed_subnets_Controller::update_enabled($vlan_iface->iface->device->user->member_id, array($ip->subnet_id));
}
url::redirect(url_lang::base().'vlan_ifaces/show/'.$vlan_iface_id);
}
else
{
......
{
$form_data[$key] = htmlspecialchars($value);
}
$saved = TRUE;
$ip = new ip_address_Model($ip_address_id);
$old_subnet_id = $ip->subnet_id;
if (isset($form_data['iface_id']) && (int) $form_data['iface_id'])
{
......
$ip->iface_id = null;
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
}
$ip->ip_address = $form_data['ip_address'];
$ip->subnet_id = $form_data['subnet_id'];
$ip->gateway = $form_data['gateway'];
$ip->service = $form_data['service'];
$ip->whitelisted = $form_data['whitelisted'];
unset($form_data);
if ($ip->save()) {
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully updated.'));
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
/*
if (isset($this->session->get('ssIface_id')))
url::redirect(url_lang::base().'ifaces/show/'.$ip->iface_id);
else
url::redirect(url_lang::base().'vlan_ifaces/show/'.$ip->vlan_iface_id);
*/
}
$saved = $saved && $ip->save();
// subnet has been changed and ip address was the only one of this member from this subnet -> deletes subnet from allowed subnets of member
if ($old_subnet_id != $ip->subnet_id && !$ip->count_all_ip_addresses_by_member_and_subnet($member_id, $old_subnet_id))
Allowed_subnets_Controller::update_enabled($member_id, NULL, NULL, array($old_subnet_id));
Allowed_subnets_Controller::update_enabled($member_id, array($ip->subnet_id));
if ($saved)
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully updated.'));
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
}
if ($ip_address->vlan_iface_id)
......
if (!$this->acl_check_delete('Devices_Controller', 'ip_address', $member_id))
Controller::error(ACCESS);
$ip_address_string = $ip_address->ip_address;
$subnet_id = $ip_address->subnet_id;
// success
if ($ip_address->delete())
{
$this->session->set_flash('message', url_lang::lang('texts.IP address has been successfully deleted.'));
// delete is successful, let's delete redirections and static html redirection page, if exists
$db = new Database();
$db->delete('messages_ip_addresses', array('ip_address_id' => $ip_address_id));
unlink("static/$ip_address_string.html");
// ip address was the only one of this member from this subnet -> deletes subnet from allowed subnets of member
if (!$ip_address->count_all_ip_addresses_by_member_and_subnet($member_id, $subnet_id))
Allowed_subnets_Controller::update_enabled($member_id, NULL, NULL, array($subnet_id));
$this->session->set_flash('message', url_lang::lang('texts.IP address has been successfully deleted.'));
// delete is successful, let's delete redirections and static html redirection page, if exists
$db = new Database();
$db->delete('messages_ip_addresses', array('ip_address_id' => $ip_address_id));
@unlink("static/$ip_address_string.html");
}
else
$this->session->set_flash('message', url_lang::lang('texts.Error - cant delete ip address.'));
$this->session->set_flash('message', url_lang::lang('texts.Error - cant delete ip address.'));
url::redirect($link_back);
}
freenetis/branches/subnets_assigning/application/controllers/scheduler.php
self::update_ulogd();
// update allowed subnets
self::update_allowed_subnets();
if (Settings::get('allowed_subnets_enabled'))
self::update_allowed_subnets();
}
/**
......
*
* @author Michal Kliment
*/
function update_allowed_subnets ()
private function update_allowed_subnets ()
{
// it's time to update
if (Settings::get('allowed_subnets_enabled') && Settings::get('allowed_subnets_update_last') + Settings::get('allowed_subnets_update_interval') < time())
freenetis/branches/subnets_assigning/application/controllers/allowed_subnets.php
if (!$member->id || $member->id == 1)
Controller::error(RECORD);
// access control
if (!$this->acl_check_view('Devices_Controller', 'allowed_subnet', $member->id))
Controller::error(ACCESS);
// finds all allowed subnets of member
$allowed_subnet_model = new Allowed_subnet_Model();
$allowed_subnets = $allowed_subnet_model->get_all_allowed_subnets_by_member ($member->id);
......
$grid->add_new_button (url_lang::base().'allowed_subnets/add/'.$member->id, url_lang::lang('texts.Add new subnet'));
$grid->field('id')->label('ID');
$grid->callback_field('subnet_name')->label(url_lang::lang('texts.Subnet'))->callback('callback::subnet_field');
$grid->callback_field('enabled')->label(url_lang::lang('texts.Enabled'))->callback('callback::enabled_field', ($allowed_subnet_model->count_all_disabled_allowed_subnets_by_member($member->id) ? 'allowed_subnets/change/' : ''))->class('center');
$grid->action_field ('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'allowed_subnets/delete')->action(url_lang::lang('texts.Delete'))->class('delete_link');
......
if (!$member->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_new('Devices_Controller', 'allowed_subnet', $member->id))
Controller::error(ACCESS);
$subnet_model = new Subnet_Model();
// finds all subnets without allowed subnets of member
......
$member_id = $allowed_subnet->member_id;
// access control
if (!$this->acl_check_delete('Devices_Controller', 'allowed_subnet', $member_id))
Controller::error(ACCESS);
// success
if ($allowed_subnet->delete())
{
......
if (!$allowed_subnet->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_edit('Devices_Controller', 'allowed_subnet', $allowed_subnet->member->id))
Controller::error(ACCESS);
$allowed_subnet->enabled = !$allowed_subnet->enabled;
$allowed_subnet->save();
......
if (!$member->id)
return;
// access control
if (!Controller::instance()->acl_check_edit('Devices_Controller', 'allowed_subnet', $member->id))
return;
// to_enabled must be array
if (!is_array($to_enable))
$to_enable = array($to_enable);
freenetis/branches/subnets_assigning/application/controllers/members.php
{
if ($member->type != $former_type_id)
{
// payment cash link
//if ($this->acl_check_edit('Accounts_Controller', 'transfers', $member->id))
// $member_links[] = html::anchor(url_lang::base().'transfers/add_member_fee_payment_by_cash/'.$member->id, url_lang::lang('texts.Payment by cash'));
// allowed subnets are enabled
if (Settings::get('allowed_subnets_enabled') && $this->acl_check_view('Devices_Controller', 'allowed_subnet', $member->id))
$member_links[] = html::anchor (url_lang::base().'allowed_subnets/show_by_member/'.$member->id, url_lang::lang('texts.Show allowed subnets'));
$member_links[] = html::anchor (url_lang::base().'allowed_subnets/show_by_member/'.$member->id, url_lang::lang('texts.Show allowed subnets'));
// end membership link
if ($this->acl_check_edit(get_class($this), 'members'))
$member_links[] = html::anchor(url_lang::base().'members/end_membership/'.$member->id, url_lang::lang('texts.End membership'), array('onclick' => 'return potvrd(\''.url_lang::lang('texts.Do you want to end membership of this member').'\')'));
freenetis/branches/subnets_assigning/application/controllers/settings.php
'approval' => url_lang::lang('texts.Approval'),
'voip' => url_lang::lang('texts.VoIP'),
'sms' => url_lang::lang('texts.SMS'),
'gateway' => url_lang::lang('texts.Gateway'),
'redirection' => url_lang::lang('texts.Redirection'),
'logging' => url_lang::lang('texts.Logování'),
'map' => url_lang::lang('texts.Map'),
'registration_export' => url_lang::lang('texts.Export of registration')
......
}
function gateway()
function redirection()
{
// access control
if (!$this->acl_check_edit(get_class($this),'system'))
Controller::error(ACCESS);
// creating of new forge
$this->form = new Forge(url_lang::base()."settings/gateway", '', 'POST', array('id' => 'article_form'));
$this->form = new Forge(url_lang::base()."settings/redirection", '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$this->form->group('')->label(url_lang::lang('texts.Gateway'));
$this->form->input('gateway')->label(url_lang::lang('texts.Gateway IP address').':')->value($this->settings->get('gateway'));
......
$this->form->html_textarea('debtor')->label(url_lang::lang('texts.Debtor text').':')->rows(5)->cols(100)->value($this->settings->get('debtor'));
$this->form->html_textarea('payment_notice')->label(url_lang::lang('texts.Payment notice text').':')->rows(5)->cols(100)->value($this->settings->get('payment_notice'));
$this->form->html_textarea('optional_message')->label(url_lang::lang('texts.Optional message text').':')->rows(5)->cols(100)->value($this->settings->get('optional_message'));
$this->form->group('')->label(url_lang::lang('texts.Allowed subnets').' '.help::hint('allowed_subnets'));
$this->form->checkbox('allowed_subnets_enabled')->label(url_lang::lang('texts.Enabled'))->value(1)->checked(Settings::get('allowed_subnets_enabled'));
$this->form->input('allowed_subnets_update_interval')->label(url_lang::lang('texts.Interval of update').': '.help::hint('allowed_subnets_update_interval'))->value(Settings::get('allowed_subnets_update_interval'));
$this->form->input('allowed_subnets_default_count')->label(url_lang::lang('texts.Default count').': '.help::hint('allowed_subnets_default_count'))->value(Settings::get('allowed_subnets_default_count'));
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
// form validate
......
{
$form_data = $this->form->as_array();
$config_model = new Config_Model();
$allowed_subnets_enabled = (isset($form_data['allowed_subnets_enabled']) && $form_data['allowed_subnets_enabled'] == 1) ? '1' : '0';
$config_model->update_variable('allowed_subnets_enabled', $allowed_subnets_enabled);
// clears redirections after turning off
if (!$allowed_subnets_enabled)
{
ORM::factory('ip_address')->clear_disable_ips ();
ORM::factory('subnet')->clear_disable_subnets ();
}
$issaved = true;
foreach ($form_data as $name => $value)
{
if ($name == 'allowed_subnets_enabled') continue;
$value = addslashes($value);
// check if variable exists
if ($config_model->check_exist_variable($name))
......
// if not
$this->session->set_flash('message', url_lang::lang('texts.System variables havent been successfully updated').'.');
url::redirect(url_lang::base().'settings/gateway');
url::redirect(url_lang::base().'settings/redirection');
}
// create view for this template
$view = new View('main');
$view->title = url_lang::lang('texts.Settings').' - '.url_lang::lang('texts.Gateway');
$view->title = url_lang::lang('texts.Settings').' - '.url_lang::lang('texts.Redirection');
$view->content = new View('settings');
$view->content->current = 'gateway';
$view->content->current = 'redirection';
$view->content->content = $this->form->html();
$view->content->headline = url_lang::lang('texts.Gateway');
$view->content->headline = url_lang::lang('texts.Redirection');
$view->content->link_back = $this->links;
$message = $this->session->get_once('message');
if (!empty($message))
freenetis/branches/subnets_assigning/application/controllers/redirect.php
$continue = 0;
$device_engineers = array();
$device_admins = array();
// trying to find ip remote ip address in database
// trying to find remote ip address in database
$ip_address = ORM::factory('ip_address')->where('ip_address', server::remote_addr())->find();
// engineer of user's device, owner of ip address - if available
if ($ip_address->id != 0)
......
(
SELECT iface_id
FROM ip_addresses
WHERE ip_address = '".server::remote_addr()."'
WHERE ip_address = ?
)
)
)
UNION
SELECT member_id
FROM users
WHERE id =
(
SELECT user_id
FROM devices
WHERE id =
(
SELECT device_id
FROM ifaces
WHERE id =
(
SELECT iface_id
FROM vlan_ifaces
WHERE id =
(
SELECT vlan_iface_id
FROM ip_addresses
WHERE ip_address = ?
)
)
)
)
UNION
SELECT member_id
FROM subnets_owners
WHERE subnet_id =
(
SELECT id FROM subnets
WHERE inet_aton(?) & inet_aton(netmask) = inet_aton(network_address)
)
LIMIT 0,1
) q
SET m.redirect = m.redirect & ~$redir
SET m.redirect = m.redirect & ~?
WHERE q.member_id = m.id
");
", array(server::remote_addr(), server::remote_addr(), server::remote_addr(), $redir));
url::redirect(url_lang::base().'redirect');
}
else
freenetis/branches/subnets_assigning/application/controllers/devices.php
// has been everything saved successfully?
if ($device_saved && $device_engineer_saved && $iface_model_saved /*&& $wireless_model_saved*/ && $ip_address_saved)
{
$this->session->set_flash('message', url_lang::lang('texts.Device has been successfully saved.'));
url::redirect(url_lang::base().'devices/show/'.$device_model->id);
Allowed_subnets_Controller::update_enabled($user->member_id, array($ip_address_model->subnet_id));
$this->session->set_flash('message', url_lang::lang('texts.Device has been successfully saved.'));
}
url::redirect(url_lang::base().'devices/show/'.$device_model->id);
}
freenetis/branches/subnets_assigning/application/upgrade_sql/upgrade_sql.php
// array of sql queries that upgrade database
$upgrade_sql[get_SVN_rev()] = array(
"CREATE TABLE IF NOT EXISTS `allowed_subnets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`member_id` int(11) NOT NULL,
`subnet_id` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT '1',
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `member_id` (`member_id`,`subnet_id`,`enabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
"INSERT INTO `axo` (`id`, `section_value`, `value`, `order_value`, `name`, `hidden`) VALUES ('175', 'Devices_Controller', 'allowed_subnet', '0', 'Allowed subnet', '0');",
"CREATE TABLE IF NOT EXISTS `allowed_subnets_counts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`member_id` int(11) NOT NULL,
`count` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `member_id` (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
"INSERT INTO `axo_map` (`acl_id`, `section_value`, `value`) VALUES ('38', 'Devices_Controller', 'allowed_subnet');",
"INSERT INTO allowed_subnets
SELECT NULL, m.id AS member_id, IFNULL(ip1.subnet_id,ip2.subnet_id) AS subnet_id, 1 AS enabled, CURRENT_TIMESTAMP FROM members m
JOIN users u ON u.member_id = m.id
JOIN devices d ON d.user_id = u.id
JOIN ifaces i ON i.device_id = d.id
LEFT JOIN ip_addresses ip1 ON ip1.iface_id = i.id
LEFT JOIN vlan_ifaces vi ON vi.iface_id = i.id
LEFT JOIN ip_addresses ip2 ON ip2.vlan_iface_id = vi.id
WHERE m.id <> 1 AND IFNULL(ip1.subnet_id,ip2.subnet_id)
GROUP BY member_id, subnet_id",
"INSERT INTO `acl` (`id`, `section_value`, `allow`, `enabled`, `return_value`, `note`, `updated_date`) VALUES ('77', 'freenetis', '1', '1', NULL, 'All members can only edit their allowed subnets.', '0');",
"INSERT INTO allowed_subnets_counts
SELECT NULL, member_id, COUNT(a.subnet_id) AS count FROM allowed_subnets a
GROUP BY a.member_id",
"INSERT INTO `aco_map` (`acl_id`, `section_value`, `value`) VALUES ('77', 'freenetis', 'edit_own');",
"UPDATE segments s SET medium_id = medium_id - 55;",
"INSERT INTO `aro_groups_map` (`acl_id`, `group_id`) VALUES ('77', '22');",
"ALTER TABLE `ip_addresses` ADD `redirect` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `whitelisted` ,
ADD INDEX ( `redirect` )",
"INSERT INTO `axo_map` (`acl_id`, `section_value`, `value`) VALUES ('77', 'Devices_Controller', 'allowed_subnet');",
"CREATE TABLE IF NOT EXISTS `subnets_owners` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subnet_id` int(11) NOT NULL,
`member_id` int(11) NOT NULL,
`redirect` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `subnet_id` (`subnet_id`,`member_id`),
KEY `redirect` (`redirect`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
);
?>
freenetis/branches/subnets_assigning/application/upgrade_sql/upgrade_sql_952.php
<?php
// array of sql queries that upgrade database
$upgrade_sql[952] = array(
"CREATE TABLE IF NOT EXISTS `allowed_subnets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`member_id` int(11) NOT NULL,
`subnet_id` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT '1',
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `member_id` (`member_id`,`subnet_id`,`enabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
"CREATE TABLE IF NOT EXISTS `allowed_subnets_counts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`member_id` int(11) NOT NULL,
`count` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `member_id` (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
"INSERT INTO allowed_subnets
SELECT NULL, m.id AS member_id, IFNULL(ip1.subnet_id,ip2.subnet_id) AS subnet_id, 1 AS enabled, CURRENT_TIMESTAMP FROM members m
JOIN users u ON u.member_id = m.id
JOIN devices d ON d.user_id = u.id
JOIN ifaces i ON i.device_id = d.id
LEFT JOIN ip_addresses ip1 ON ip1.iface_id = i.id
LEFT JOIN vlan_ifaces vi ON vi.iface_id = i.id
LEFT JOIN ip_addresses ip2 ON ip2.vlan_iface_id = vi.id
WHERE m.id <> 1 AND IFNULL(ip1.subnet_id,ip2.subnet_id)
GROUP BY member_id, subnet_id",
"INSERT INTO allowed_subnets_counts
SELECT NULL, member_id, COUNT(a.subnet_id) AS count FROM allowed_subnets a
GROUP BY a.member_id",
"UPDATE segments s SET medium_id = medium_id - 55;",
"ALTER TABLE `ip_addresses` ADD `redirect` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `whitelisted` ,
ADD INDEX ( `redirect` )",
"CREATE TABLE IF NOT EXISTS `subnets_owners` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subnet_id` int(11) NOT NULL,
`member_id` int(11) NOT NULL,
`redirect` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `subnet_id` (`subnet_id`,`member_id`),
KEY `redirect` (`redirect`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
);
?>
freenetis/branches/subnets_assigning/application/libraries/MY_Controller.php
if (($ptr_record = dns::get_ptr_record(server::remote_addr())) != '')
$this->ip_address_span .= ' <i>('.$ptr_record.')</i>';
// toggle button between allowed subnets
$allowed_subnet_model = new Allowed_subnet_Model();
$allowed_subnet = $allowed_subnet_model->get_allowed_subnet_by_member_and_ip_address ($this->session->get('member_id'), server::remote_addr());
if ($allowed_subnet && $allowed_subnet->id)
// allowed subnets are enabled
if (Settings::get('allowed_subnets_enabled') && $this->acl_check_edit('Devices_Controller', 'allowed_subnet', $this->session->get('member_id')))
{
if ($allowed_subnet_model->count_all_disabled_allowed_subnets_by_member($this->session->get('member_id')))
$this->ip_address_span .= ' '.html::anchor (url_lang::base().'allowed_subnets/change/'.$allowed_subnet->id, html::image (array('src' => url::base().'media/images/'.(($allowed_subnet->enabled) ? 'active' : 'inactive').'.png')));
else
$this->ip_address_span .= ' '.html::image (array('src' => url::base().'media/images/'.(($allowed_subnet->enabled) ? 'active' : 'inactive').'.png'));
// toggle button between allowed subnets
$allowed_subnet_model = new Allowed_subnet_Model();
$allowed_subnet = $allowed_subnet_model->get_allowed_subnet_by_member_and_ip_address ($this->session->get('member_id'), server::remote_addr());
if ($allowed_subnet && $allowed_subnet->id)
{
if ($allowed_subnet_model->count_all_disabled_allowed_subnets_by_member($this->session->get('member_id')))
$this->ip_address_span .= ' '.html::anchor (url_lang::base().'allowed_subnets/change/'.$allowed_subnet->id, html::image (array('src' => url::base().'media/images/'.(($allowed_subnet->enabled) ? 'active' : 'inactive').'.png')));
else
$this->ip_address_span .= ' '.html::image (array('src' => url::base().'media/images/'.(($allowed_subnet->enabled) ? 'active' : 'inactive').'.png'));
}
}
// updates paths

Také k dispozici: Unified diff