Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 934

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

Merge z testingu do trunku: Velka sada zmen - prepsano zobrazeni zarizeni a zobrazeni zarizeni uzivatele. Snad konecne odladen vypocet platnosti kreditu clena. Do ORM pridana nova metoda check_permission, ktera testuje MySQL prava - vyuzito u instalatoru u vytvareni SQL funkci pro ulogd => pokud uzivatel, pod kterym freenetis bezi, nema prava na vytvareni funkci, tak se tyto funkce vubec nevytvari a ulogd se nepovoli. Vylepseno vypinani/zapinani ulogd. Nyni se pri vypnuti nezobrazuje odkaz v menu, ani info na profilu clena. Do ORM dopsana funkce function_exists, ktera testuje jestli MySQL funkce existuje. Oprava mensi chyby na profilu clena. Zobrazovani aplikacniho hesla na profilu clena a uzivatele az na vyzadani (do te doby skryte za hvezdicky).

Zobrazit rozdíly:

freenetis/trunk/kohana/media/css/style.css
.right {
text-align: right;
}
#show_application_password_link {
float: right;
margin-right: 40px;
}
freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'add new invoice' => 'Přidat novou fakturu',
'add new invoice item' => 'Přidat novou položku faktury',
'add new ip address' => 'Přidat novou IP adresu',
'add new ip address to device' => 'Přidat novou IP adresu k zařízení',
'add new items' => 'Přidat nové položky',
'add new member' => 'Přidat nového člena',
'add new message' => 'Přidat novou zprávu',
......
'add new translation' => 'Přidat nový překlad',
'add new user' => 'Přidat nového uživatele',
'add new vlan interface' => 'Přidat nové VLAN rozhraní',
'add new vlan interface to device' => 'Přidat nové VLAN rozhraní k zařízení',
'add new vlan interface to interface' => 'Přidat nové VLAN rozhraní k rozhraní',
'add new vlan' => 'Přidat nový VLAN',
'add new voip transfer' => 'Přidat nový VoIP převod',
'add new whole device' => 'Přidat nové celé zařízení',
......
'agree' => 'Souhlas',
'all' => 'Všichni',
'all accounts now have correct balances, %d accounts had incorrect balances, list of ids of corrected accounts: %s' => 'Všechny účty teď mají správné zůstatky, %d účtů mělo chybné zůstatky, seznam ID opravených účtů: %s',
'all devices' => 'Všechna zařízení',
'all ip addresses of member' => 'všem IP adresám člena',
'all redirected' => 'Všichni přesměrovaní',
'all transfers' => 'Všechny převody',
......
'are you sure you want to recount entrance fees of this member' => 'Jste si jistí, že chcete přepočítat vstupní příspěvky tohoto člena',
'area' => 'Oblast',
'arrival' => 'Příchozí',
'ascending' => 'Vzestupně',
'assign' => 'Přiřadit',
'assign free subnet' => 'Přiřaď volnou podsíť',
'assign free subnet to cloud' => 'Přiřaď volnou podsíť',
......
'back to the approval template' => 'Zpátky k hlasovací šabloně',
'back to the approval type' => 'Zpátky k hlasovacímu typu',
'back to the cloud list' => 'Zpět na seznam oblastí',
'back to the device' => 'Zpět na zařízení',
'back to the double-entry accounts' => 'Zpět na podvojné účty',
'back to the form' => 'Zpátky k formuláři',
'back to the interface' => 'Zpět na rozhraní',
'back to the invoice' => 'Zpět na fakturu',
'back to the invoice item' => 'Zpět na položku faktury',
'back to the list of routerboard backups' => 'Zpět na zálohu routerboardů',
......
'deny' => 'Odepřít',
'dependent transfer' => 'Závislý převod',
'deposit' => 'Vklad',
'descending' => 'Sestupně',
'description' => 'Popis',
'describe what you have been doing, when the error came out' => 'Popište jakou akci jste prováděl(a), když se objevila tato chyba',
'deselect all' => 'Zrušit výběr',
......
'device repayments' => 'Splátky zařízení',
'device still has at least one interface' => 'Zařízení má ještě nejméně jedno rozhraní.',
'device still has at least one port' => 'Zařízení má ještě nejméně jeden port.',
'device type' => 'Typ zařízení',
'device_name' => 'Název zařízení',
'device_type' => 'Typ zařízení',
'devices list' => 'Seznam zařízení',
'devices' => 'Zařízení',
'dhcp configuration' => 'Konfigurace DHCP',
'dhcp configuration file was successfully generated' => 'Konfigurační soubor pro DHCP byl úspěšně vygenerován',
'direction' => 'Směr',
'directory "static" is not writable, change access rights' => 'Adresář "static" není zapisovatelný, změňte přístupová práva.',
'directory "upload" is not writable, change access rights' => 'Adresář "upload" není zapisovatelný, změňte přístupová práva.',
'disabled' => 'Vypnuto',
......
'edit cloud' => 'Upravit oblast',
'edit contact' => 'Upravit kontakt',
'edit device' => 'Upravit zařízení',
'edit device admin' => 'Upravit správce zařízení',
'edit device admins' => 'Upravit správce zařízení',
'edit enum type' => 'Upravit výčet',
'edit fee' => 'Upravit poplatek',
'edit group' => 'Upravit skupinu',
......
'e-mail variables' => 'Proměnné e-mailu',
'e-mail variables have been successfully updated' => 'Proměnné e-mailu byly úspěšně aktualizovány.',
'e-mail variables havent been successfully updated' => 'Proměnné e-mailu nebyly úspěšně aktualizovány.',
'enable action logs' => 'Zapnout logy akcí',
'enable integrity test (all numbers in invoice has to be in extended statement)' => 'Povolit test na celistvost (každé číslo ve faktuře musí být v podrobném výpisu)',
'enable mysql event scheduler' => 'Povolit MySQL plánovač akcí',
'enable ulogd' => 'Zapnout ulogd',
'enabled' => 'Zapnuto',
'end membership' => 'Ukončit členství',
'end of month' => 'Konec měsíce',
......
'help' => 'Nápověda',
'help register' => 'Registr nápovědy',
'help text not found' => 'Text nápovědy nenalezen.',
'hide' => 'Skrýt',
'hide this table' => 'Schovat tuto tabulku',
'history' => 'Historie',
'history of phone services between' => 'Historie telefonních služeb mezi',
'history of phone services between user and phone' => 'Historie telefonních služeb mezi uživatelem a číslem',
......
'it is not possible vote this way about work on work report' => 'Není možné hlasovat tímto způsobem o práci na pracovním výkaze.',
'it is not possible vote about locked work' => 'Není možné hlasovat o zamčené práci.',
'it is possible to deduct fees only in one year' => 'Členské příspěvky je možné strhávat jen v rámci jednoho roku.',
'it requires already created functions for ulogd or mysql permission create routine for create them' => 'vyžaduje již vytvořené funkce pro ulogd nebo MySQL oprávnění CREATE ROUTINE pro jejich vytvoření',
'it\'s not possible to write your htacess file for clean urls' => 'Není možné zapsat váš soubor .htacess pro čistá URL.',
'item' => 'Položka',
'item number' => 'Položka č.',
......
'or' => 'nebo',
'or enter correct variable symbol' => 'Nebo vložte správný variabilní symbol',
'order' => 'Pořadí',
'order by' => 'Řadit podle',
'order number' => 'Číslo objednávky',
'organization identifier' => 'IČ',
'organization_identifier' => 'IČ',
......
'request for membership' => 'Žádost o členství',
'reguest is invalid or expired' => 'Žádost je neplatná nebo expirovala',
'requests' => 'Požadavky',
'require mysql %s and higher' => 'potřebuje MySQL ve verzi %s nebo vyšší',
'resize' => 'Změnit velikost',
'restore membership' => 'Obnovit členství',
'reverse dns' => 'Zpětné DNS',
......
'show calls of whole member' => 'Zobrazit hovory celého člena',
'show clouds' => 'Zobrazit oblasti',
'show details' => 'Zobrazit detaily',
'show device' => 'Zobrazit zařízení',
'show devices' => 'Zobrazit zařízení',
'show help' => 'Zobrazit nápovědu',
'show interface' => 'Zobrazit rozhraní',
'show invoice' => 'Zobrazit fakturu',
'show invoice item' => 'Zobrazit položku faktury',
'show mail message' => 'Zobrazit poštovní zprávu',
......
'show sms message' => 'Zobrazit SMS zprávu',
'show statements' => 'Zobrazit výpisy',
'show tariffs' => 'Zobrazit tarify',
'show this table' => 'Zobrazit tuto tabulku',
'show transfer' => 'ukaž transakci',
'show transfers' => 'Zobrazit převody',
'show transfers on this account' => 'Ukaž převody tohoto účtu',
'show unread messages' => 'Zobrazit nepřečtené zprávy',
'show user' => 'Ukaž uživatele',
'show user actions' => 'Zobraz uživatelovi akce',
'show vlan' => 'Zobrazit VLAN',
'show vlan interface' => 'Zobrazit VLAN rozhraní',
'show voip account' => 'Zobrazit VoIP účet',
'show work' => 'Zobrazit práci',
'show work report' => 'Zobrazit pracovní výkaz',
......
'viewing of all records' => 'Prohlížení všech záznamů',
'viewing of own records' => 'Prohlížení vlastních záznamů',
'virus' => 'Počítačový vir',
'vlan count' => 'Počet VLANů',
'vlan detail' => 'Detail VLANu',
'vlan interface' => 'VLAN rozhraní',
'vlan interface detail' => 'Detail VLAN rozhraní',
freenetis/trunk/kohana/application/i18n/cs_CZ/help.php
(
'access_to_system' => 'Určuje, zda-li má uživatel možnost přihlásit se do systému Freenetis a zda má možnost využívat služeb Radius serveru napojeného na Freenetis, tedy například VPN, aktivní prvky sítě, volání z VoIP účtu atd.',
'accounting_system' => 'Účetní osnova je hlavní pomocník pro účetního sdružení. Zobrazuje sumu peněz na účtu z pohledu účetní osnovy. Ve výchozím stavu je to částka za celou dobu fungování sdružení, lze ovšem vyfiltrovat převody za zvolené období, např. od data 2009-01-01 do data 2009-12-31.',
'action_logs_active' => 'Logy akcí je nástroj pro detekci akcí koncových uživatelů na data v systému.',
'actual_traffic %s' => 'Jedná se o provoz člena získaný z poslední aktualizace ulogd (%s). Viz Nastavení - Logování - Ulogd - Interval aktualizace.',
'add_new_bank_transfer' => 'Umožňuje přidat ručně nový bankovní převod, který ma zdrojový i cílový účet. Typicky jde o fakturu nebo členský příspěvek. 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ž byly jen v textovém formátu a nebylo možné je parsovat.',
'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.',
freenetis/trunk/kohana/application/i18n/en_US/help.php
$lang = array
(
'action_logs_active' => 'Actions log is tool for detectins end user actions on data in system.',
'approval_state' => 'State is in format Agree / Disagree / Abstain.',
'gps_coordinates' => 'GPS can be in shape of real number, or: hours°minutes\'seconds&quot.',
'price_tax' => 'Price with tax',
freenetis/trunk/kohana/application/helpers/callback.php
* @param unknown_type $item
* @param unknown_type $name
*/
static function ip_address_field($item, $name)
static function ip_address_field($item, $name, $args = array())
{
$ip_address = (isset($args[0]) && $args[0]) ? $item->ip_address.'/'.$item->subnet_range : $item->ip_address;
if ($item->ip_address_id)
echo html::anchor(url_lang::base()."ip_addresses/show/$item->ip_address_id", $item->ip_address);
echo html::anchor(url_lang::base()."ip_addresses/show/$item->ip_address_id", $ip_address);
else if ($item->ip_address != '')
echo '<span style="color: green">'.$item->ip_address.'</span>';
echo '<span style="color: green">'.$ip_address.'</span>';
else
echo '&nbsp';
}
......
echo ($color != '') ? '<span style="color: '.$color.'">'.$item->used.' %</span>' : $item->used.' %';
}
/**
* Callback to print Iface or VLAN iface to which belong ip address
*
* @author Michal Kliment
* @param <type> $item
* @param <type> $name
*/
public function iface_vlan_iface_field ($item, $name)
{
if ($item->iface_id)
echo html::anchor (url_lang::base().'ifaces/show/'.$item->iface_id, $item->iface_name, array('title' => url_lang::lang('texts.Show interface')));
else
echo html::anchor (url_lang::base().'vlan_ifaces/show/'.$item->vlan_iface_id, $item->vlan_iface_name, array('title' => url_lang::lang('texts.Show VLAN interface')));
}
/**
* Callback to print vlan
*
* @author Michal Kliment
* @param <type> $item
* @param <type> $name
*/
public function vlan_field ($item, $name)
{
echo html::anchor (url_lang::base().'vlans/show/'.$item->vlan_id, $item->vlan_name, array('title' => url_lang::lang('texts.Show VLAN')));
}
/**
* Callback to print VLAN interface
*
* @author Michal Kliment
* @param <type> $item
* @param <type> $name
*/
public function vlan_iface_field ($item, $name)
{
echo html::anchor (url_lang::base().'vlan_ifaces/show/'.$item->vlan_iface_id, $item->vlan_iface_name, array('title' => url_lang::lang('texts.Show VLAN interface')));
}
/**
* Callback to print port
*
* @author Michal Kliment
* @param <type> $item
* @param <type> $name
*/
public function port_field ($item, $name)
{
echo html::anchor (url_lang::base().'ports/show/'.$item->port_id, $item->port_name, array('title' => url_lang::lang('texts.Show port')));
}
/**
* Callback to print ID of interface
*
* @author MIchal Kliment
* @param <type> $item
* @param <type> $name
*/
public function iface_id_field ($item, $name)
{
echo html::anchor (url_lang::base().'ifaces/show/'.$item->iface_id, $item->iface_id, array('title' => url_lang::lang('texts.Show interface')));
}
}
freenetis/trunk/kohana/application/helpers/arr.php
return $object;
}
/**
* Creates array from object
*
* @author Michal Kliment
* @param mixed $object
* @return array
*/
public static function from_object ($object)
{
$arr = array();
foreach ($object as $key => $value)
$arr[$key] = $value;
return $arr;
}
/**
* Transforms array to lower
*
* @author Michal Kliment
* @param array $array
* @return array
*/
public static function tolower ($array = array())
{
foreach ($array as $key => $value)
$array[$key] = strtolower ($value);
return $array;
}
/**
* @author Michal Kliment
* Converts array of objects to classic array in format: key = id of object, value = attributte
freenetis/trunk/kohana/application/models/device.php
);
} // end of get_all_devices
/**
* Function gets all devices of user.
* @param $limit_from
* @param $limit_results
* @param $order_by
* @param $order_by_direction
* @param $user_id
* @return unknown_type
* Returns all devices of user
*
* @author Michal Kliment
* @param int $user_id
* @param int $limit_from
* @param int $limit_results
* @param string $order_by
* @param string $order_by_direction
* @return MySQL Iterator object
*/
public function get_devices_of_user($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'ASC', $user_id = null)
public function get_devices_of_user ($user_id, $limit_from, $limit_results, $order_by, $order_by_direction)
{
if ($order_by == 'id')
$order_by = 'device_id';
if ($order_by == 'ip_address')
$order_by = 'inet_aton(ip_address)';
else if ($order_by == 'ip_address')
$order_by = 'inet_aton(ip_address)';
return $this->db->query("SELECT
d.id AS device_id,
IFNULL(f.translated_term,e.value) as type,
d.name AS device_name, d.price,
CONCAT(u.name, ' ', u.surname) AS u_name,
i.mac, i.id AS iface_id, se.name AS segment_name, ip.ip_address, ip.id AS ip_address_id,
su.name AS subnet_name, su.id AS subnet_id,
SUM(IFNULL(t.amount, 0)) AS total_amount
FROM devices d
JOIN users u ON d.user_id = u.id
LEFT JOIN enum_types e ON d.type = e.id
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::get('lang')."') f ON e.value = f.original_term
LEFT JOIN ifaces i ON d.id = i.device_id
LEFT JOIN segments se ON se.id = i.segment_id
LEFT JOIN ip_addresses ip ON i.id = ip.iface_id
LEFT JOIN subnets su ON su.id = ip.subnet_id
LEFT JOIN accounts a ON a.member_id = u.member_id AND u.member_id <> 1
LEFT JOIN transfers t ON t.type = ".Transfer_Model::$deduct_device_fee." AND t.origin_id = a.id
WHERE u.id = $user_id
GROUP BY d.id
ORDER BY $order_by $order_by_direction
LIMIT $limit_from, $limit_results
");
return $this->db->query("
SELECT * FROM
(
SELECT * FROM
(
SELECT d.id, d.name, IFNULL(t.translated_term,e.value) AS type, i.mac, IFNULL(ip1.ip_address,ip2.ip_address) AS ip_address FROM devices d
LEFT JOIN enum_types e ON d.type = e.id
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = '". Config::get('lang') ."'
LEFT JOIN ifaces i ON d.id = i.device_id
LEFT JOIN vlan_ifaces vi ON i.id = vi.iface_id
LEFT JOIN ip_addresses ip1 ON ip1.iface_id = i.id
LEFT JOIN ip_addresses ip2 ON ip2.vlan_iface_id = vi.id
WHERE user_id = ?
) AS d
ORDER BY $order_by $order_by_direction
) AS d
GROUP BY d.id
ORDER BY $order_by $order_by_direction
LIMIT $limit_from, $limit_results
", array($user_id));
}
/**
freenetis/trunk/kohana/application/models/iface.php
WHERE device_id = $device_id
");
}
/**
* Returns all interfaces of device
*
* @author Michal Kliment
* @param int $device_id
* @return MySQL iterator object
*/
public function get_all_ifaces_of_device ($device_id)
{
return $this->db->query("
SELECT i.id, i.id AS iface_id, i.segment_id, sg.name AS segment_name, i.mac, i.name, i.comment, ip.subnet_id, sb.name as subnet_name, ip.id AS ip_address_id, ip.ip_address, 32-log2((~inet_aton(sb.netmask) & 0xffffffff) + 1) AS subnet_range
FROM ifaces i
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
LEFT JOIN segments sg ON i.segment_id = sg.id
LEFT JOIN subnets sb ON ip.subnet_id = sb.id
WHERE i.device_id = ?
ORDER BY inet_aton (ip.ip_address)
", array($device_id));
}
public function count_ws_of_iface($iface_id)
{
freenetis/trunk/kohana/application/models/vlan_iface.php
{
return $this->db->count_records('vlan_ifaces');
}
/**
* Returns all VLAN interfaces which belong to device
*
* @author Michal Kliment
* @param <type> $device_id
* @return <type>
*/
public function get_all_vlan_ifaces_by_device_id ($device_id)
{
return $this->db->query(
"SELECT vi.*, vi.id AS vlan_iface_id, vi.name AS vlan_iface_name, v.id AS vlan_id, v.name AS vlan_name, v.tag_802_1q, i.id AS iface_id, i.name AS iface_name
FROM vlan_ifaces vi
LEFT JOIN vlans v ON vi.vlan_id = v.id
LEFT JOIN ifaces i ON vi.iface_id = i.id
WHERE i.device_id = ?
", array($device_id));
}
/**
* Returns all VLAN interface of device
*
* @author Michal Kliment
* @param int $device_id
* @return MySQL iterator object
*/
public function get_all_vlan_ifaces_with_ip_addresses_by_device_id ($device_id)
{
return $this->db->query("
SELECT
vi.*,
vi.id AS vlan_iface_id,
vi.name AS vlan_iface_name,
v.id AS vlan_id,
v.name AS vlan_name,
v.tag_802_1q,
i.id AS iface_id,
i.name AS iface_name,
ip.id AS ip_address_id,
ip.ip_address,
32-log2((~inet_aton(s.netmask) & 0xffffffff) + 1) AS subnet_range
FROM vlan_ifaces vi
LEFT JOIN vlans v ON vi.vlan_id = v.id
LEFT JOIN ifaces i ON vi.iface_id = i.id
LEFT JOIN ip_addresses ip ON vi.id = ip.vlan_iface_id
LEFT JOIN subnets s ON ip.subnet_id = s.id
WHERE i.device_id = ?
ORDER BY inet_aton (ip.ip_address)
", array ($device_id));
}
}
?>
freenetis/trunk/kohana/application/models/ip_address.php
public function get_ip_addresses_of_device($device_id)
{
return $this->db->query("
SELECT ip.*, s.name AS subnet_name
SELECT
ip.*,
ip.id AS ip_address_id,
s.name AS subnet_name,
32-log2((~inet_aton(netmask) & 0xffffffff) + 1) AS subnet_range,
i1.name AS iface_name,
vi.id AS vlan_iface_id,
vi.name AS vlan_iface_name
FROM ip_addresses ip
LEFT JOIN subnets s ON s.id = ip.subnet_id
LEFT JOIN ifaces i1 ON i1.id = ip.iface_id
freenetis/trunk/kohana/application/models/members_traffic.php
IFNULL(SUM(download),0) AS download,
IFNULL(active,0) AS active
FROM members_traffics t WHERE t.member_id = ?
GROUP BY t.member_id
", array($member_id))->current();
}
freenetis/trunk/kohana/application/models/log.php
}
/**
* Creates table for logs
* @author Ondřej Fibich
*/
public static function create_table()
{
$db = new Database();
$db->query("
CREATE TABLE IF NOT EXISTS `logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`table_name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
`values` text COLLATE utf8_czech_ci,
`time` datetime NOT NULL,
`action` tinyint(2) NOT NULL DEFAULT '1',
`object_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci
PARTITION BY RANGE (TO_DAYS(`time`))
(PARTITION p_first VALUES LESS THAN (TO_DAYS('1970-01-01')) ENGINE = InnoDB);
");
}
/**
* Add new partition for logs
* @author Ondřej Fibich
* @see Scheduler_Controller::logs_partitions_daily()
freenetis/trunk/kohana/application/models/config.php
<?php defined('SYSPATH') or die('No direct script access.');
class Config_Model extends Model
{
public function __construct()
......
{
try // try if query return exception, for example config table doesn't exist
{
$result = $this->db->query('select value from config where name = "'.$name.'"');
$result = $this->db->query('select value from config where name = ?', $name);
}
catch (Kohana_Database_Exception $e)
{
{
$result = NULL;
}
}
return (count($result)) ? $result[0]->value : '';
}
public function get_all_values()
{
return $this->db->query('select name, value from config order by name');
}
public function check_exist_variable($name = '')
{
return count ($result = $this->db->query('select value from config where name = "'.$name.'"'));
return count($result = $this->db->query('select value from config where name = ?', $name));
}
public function update_variable($name,$value)
public function update_variable($name, $value)
{
return $this->db->query('update config set value = "'.$value.'" where name = "'.$name.'"');
return $this->db->query('update config set value = ? where name = ?', $value, $name);
}
public function insert_variable($name,$value)
public function insert_variable($name, $value)
{
return $this->db->query('insert into config (name,value) values("'.$name.'","'.$value.'")');
return $this->db->query('insert into config (name,value) values(?,?)', $name, $value);
}
public function set_db_schema_version($revision = NULL)
{
if ($revision)
{
$this->db->query('update config set value = '.$revision.' where name = "db_schema_version"');
$this->db->query('update config set value = ? where name = "db_schema_version"', $revision);
}
}
}
freenetis/trunk/kohana/application/models/ulog2_ct.php
<?php
/**
*
* @author Michal Kliment
* @copyright (c) 2011 Kliment Michal
* @license GNU GPLv3
* @license http://www.gnu.org/licenses/gpl.txt
*/
class Ulog2_ct_Model extends Model
{
/**
* Creates function to ulogd
* @author Michal Kliment
*/
public static function create_functions ()
{
$db = new Database();
$db->query("DROP FUNCTION IF EXISTS `INSERT_CT`");
$db->query("
CREATE FUNCTION `INSERT_CT`(
`_orig_ip_saddr` int unsigned,
`_orig_ip_daddr` int unsigned,
`_orig_ip_protocol` tinyint(3) unsigned,
`_orig_l4_sport` int(5),
`_orig_l4_dport` int(5),
`_orig_raw_pktlen` bigint,
`_orig_raw_pktcount` bigint,
`_reply_ip_daddr` int unsigned,
`_reply_l4_dport` int(5),
`_reply_raw_pktlen` bigint,
`_reply_raw_pktcount` bigint,
`_icmp_code` tinyint(3),
`_icmp_type` tinyint(3),
`_flow_start_sec` int(10),
`_flow_end_sec` int(10)
) RETURNS bigint(20) unsigned
READS SQL DATA
BEGIN
INSERT INTO ulog2_ct
(orig_ip_saddr, orig_ip_daddr, orig_ip_protocol,
orig_l4_sport, orig_l4_dport, orig_raw_pktlen, orig_raw_pktcount,
reply_ip_daddr,
reply_l4_dport, reply_raw_pktlen, reply_raw_pktcount,
icmp_code, icmp_type,
flow_start_sec,
flow_end_sec
)
VALUES (_orig_ip_saddr, _orig_ip_daddr, _orig_ip_protocol,
_orig_l4_sport, _orig_l4_dport, _orig_raw_pktlen, _orig_raw_pktcount,
_reply_ip_daddr,
_reply_l4_dport, _reply_raw_pktlen, _reply_raw_pktcount,
_icmp_code, _icmp_type,
_flow_start_sec,
_flow_end_sec
);
RETURN LAST_INSERT_ID();
END
");
$db->query("DROP FUNCTION IF EXISTS `insert_rand`");
$db->query("
CREATE FUNCTION `insert_rand`() RETURNS bigint(20) unsigned
READS SQL DATA
BEGIN
SET @tnow=now();
INSERT INTO ulog2_ct
(orig_ip_daddr,
orig_l4_dport,
reply_l4_dport,
flow_start_sec,
flow_end_sec
)
VALUES (
rand()*4294967295,
rand()*80,
rand()*65535,
unix_timestamp(@tnow - interval (rand()*60) second),
unix_timestamp(@tnow)
);
RETURN LAST_INSERT_ID();
END
");
$db->query("DROP FUNCTION IF EXISTS `ip2str`");
$db->query("
CREATE FUNCTION `ip2str`(ip INT UNSIGNED) RETURNS varchar(15) CHARSET latin1
DETERMINISTIC
RETURN concat(ip & 255, \".\", ip>>8 & 255, \".\", ip>>16 & 255, \".\", ip>>24)
");
$db->query("DROP FUNCTION IF EXISTS `swap_endian`");
$db->query("
CREATE FUNCTION `swap_endian`(ip INT UNSIGNED) RETURNS int(10) unsigned
DETERMINISTIC
RETURN ((ip & 255)<<24 | (ip & 65280)<<8 | (ip>>8 & 65280) | ip>>24)
");
}
/**
* Checks pre requirements for ulogd
*
* @author Michal Kliment
* @return <type>
*/
public function check_pre_requirements()
{
$user_model = new User_Model();
return ($user_model->function_exists('INSERT_CT') && $user_model->function_exists('insert_rand') && $user_model->function_exists('ip2str') && $user_model->function_exists('swap_endian'));
}
}
?>
freenetis/trunk/kohana/application/models/port.php
public function get_ports_of_device($device_id)
{
return $this->db->query('SELECT devices.name as device_name,segments.name as segment_name,
return $this->db->query('SELECT ports.id AS port_id, ports.name AS port_name, devices.name as device_name,ports.segment_id, segments.name as segment_name,
IFNULL(ports_vlans.vlan_count,0) AS vlan_count, ports.id,ports.name
FROM ports
LEFT JOIN devices ON devices.id = ports.device_id
freenetis/trunk/kohana/application/controllers/vlan_ifaces.php
* Function adds vlan interface.
* @param $iface_id
*/
function add($iface_id = NULL)
function add($iface_id = NULL, $device_id = NULL)
{
$arr_ifaces = array();
if ($iface_id && $iface_id != 0)
{
if (!is_numeric($iface_id))
Controller::warning(PARAMETER);
$iface = new Iface_Model($iface_id);
if (!$iface->id)
Controller::error(RECORD);
$arr_ifaces[$iface->id] = $iface->name;
$title = url_lang::lang('texts.Add new VLAN interface to interface').' '.$iface->name.' ('.$iface->device->name.')';
$link_back = html::anchor (url_lang::base().'ifaces/show/'.$iface->id, url_lang::lang('texts.Back to the interface'));
}
else if ($device_id)
{
if (!is_numeric($device_id))
Controller::warning(PARAMETER);
$device = new Device_Model ($device_id);
if (!$device->id)
Controller::error(RECORD);
foreach ($device->ifaces as $iface)
$arr_ifaces[$iface->id] = $iface->name;
$title = url_lang::lang('texts.Add new VLAN interface to device').' '.$device->name;
$link_back = html::anchor (url_lang::base().'devices/show/'.$device->id.'#vlan_interfaces', url_lang::lang('texts.Back to the device'));
}
else
{
$iface_model = new Iface_Model();
$ifaces = $iface_model->find_all();
foreach ($ifaces as $iface)
$arr_ifaces[$iface->id] = $iface->device->name.' - '.$iface->name;
$title = url_lang::lang('texts.Add new VLAN interface');
}
$form = new Forge(url_lang::base()."vlan_ifaces/add/$iface_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('name')->label(url_lang::lang('texts.VLAN interface name').':')->rules('required|length[3,250]');
$member_id = NULL;
if ($iface_id)
{
$iface = new Iface_Model($iface_id);
if (!$iface->id)
Controller::error(RECORD);
$member_id = $iface->device->user->member_id;
$form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name'))->options(array($iface->id => $iface->name))->rules('required');
}
else
{
$iface_model = new Iface_Model();
$ifaces = $iface_model->select(array('id','name'))->orderby('name')->find_all();
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
foreach ($ifaces as $iface) {
$arr_ifaces[$iface->id] = $iface->name;
}
$form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name'))->options($arr_ifaces)->rules('required');
}
$form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name'))->options($arr_ifaces)->rules('required');
if (!$this->acl_check_new('Devices_Controller','vlan_iface',$member_id))
Controller::error(1);
$vlan_model = new Vlan_Model();
......
}
}
if ($iface_id) $link_back = html::anchor(url_lang::base().'ifaces/show/'.$iface_id, url_lang::lang('texts.Back to interface parameters'));
else $link_back = html::anchor(url_lang::base().'vlan_ifaces/show_all/', url_lang::lang('texts.Back to VLAN interfaces list'));
$view = new View('main');
$view->title = url_lang::lang('texts.Add new VLAN interface');
$view->title = $title;
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->link_back = $link_back;
$view->content->headline = url_lang::lang('texts.Add new VLAN interface');
$view->content->headline = $title;
$view->render(TRUE);
} // end of add
freenetis/trunk/kohana/application/controllers/device_admins.php
$remove_button = form::submit('remove', '◄ '.url_lang::lang('texts.Remove'), 'style="width:80px;"');
$headline = url_lang::lang('texts.Edit device admin').': '.url_lang::lang('texts.'.$device->name);
$headline = url_lang::lang('texts.Edit device admins').': '.url_lang::lang('texts.'.$device->name);
$view = new View('main');
$view->title = $headline;
$view->content = new View('device_admins/edit_device_admins');
freenetis/trunk/kohana/application/controllers/ip_addresses.php
* Adds new ip address to current interface.
* @return unknown_type
*/
function add()
{
$this->form = new Forge(url_lang::base()."ip_addresses/add", '', 'POST', array('id' => 'article_form'));
function add($device_id = NULL)
{
if (!$this->acl_check_new('Devices_Controller', 'ip_address'))
Controller::error(ACCESS);
$vlan_iface_model = new Vlan_iface_Model();
if ($device_id)
{
if (!is_numeric($device_id))
Controller::warning(PARAMETER);
$device = new Device_Model($device_id);
if (!$device->id)
Controller::error(RECORD);
$ifaces = $device->ifaces;
$vlan_ifaces = $vlan_iface_model->get_all_vlan_ifaces_by_device_id($device->id);
$title = url_lang::lang('texts.Add new IP address to device').' '.$device->name;
$link_back_url = url_lang::base().'devices/show/'.$device->id;
$link_back = html::anchor($link_back_url, url_lang::lang('texts.Back to the device'));
}
else
{
$iface_model = new Iface_Model();
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
$vlan_ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all();
$title = url_lang::lang('texts.Add new IP address');
$link_back_url = url_lang::base().'ip_addresses/show_all';
$link_back = html::anchor($link_back_url, url_lang::lang('texts.Back to IP addresses list'));
}
$this->form = new Forge(url::base().url::current(TRUE), '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$iface_model = new Iface_Model();
$vlan_iface_model = new Vlan_iface_Model();
$arr_ifaces = array();
$arr_vlan_ifaces = array();
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
$vlan_ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all();
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
$arr_vlan_ifaces[0] = '----- '.url_lang::lang('texts.select vlan interface').' -----';
if (!$this->acl_check_new('Devices_Controller', 'ip_address')) Controller::error(1);
foreach ($ifaces as $iface) {
$arr_ifaces[$iface->id] = $iface->name;
}
......
if ($ip->save())
{
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
url::redirect(url_lang::base().'ip_addresses/show_all');
}
url::redirect($link_back_url);
}
else
{
//$form->ip_address->value("ahoj"); //demo of how to fill a field after validation error
}
$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.Add new IP address');
$view->title = $title;;
$view->content = new View('form');
$view->content->form = $this->form->html();
$view->content->link_back = $link_back;
$view->content->headline = url_lang::lang('texts.Add new IP address');
$view->content->headline = $title;
$view->render(TRUE);
} // end of add function
......
if ($iface_id && $vlan_iface_id)
$input->add_error('required', url_lang::lang('texts.Select only one type of iface.'));
else if (!$iface_id && !$vlan_iface_id)
$input->add_error('required', url_lang::lang('texts.Iface has not been selected.'));
$input->add_error('required', url_lang::lang('texts.Interface has not been selected.'));
}
/**
freenetis/trunk/kohana/application/controllers/scheduler.php
// manage logs
if ((date('H:i') == '00:00'))
{
self::logs_partitions_daily();
if (Settings::get('action_logs_active') == '1')
{
self::logs_partitions_daily();
}
}
//send quened SMS
freenetis/trunk/kohana/application/controllers/members.php
// user edit link
if ($member->type != $former_type_id && $this->acl_check_edit('Users_Controller','users', $member->id))
$user_links[] = html::anchor(url_lang::base().'users/edit/'.$member->id, url_lang::lang('texts.Edit'));
$user_links[] = html::anchor(url_lang::base().'users/edit/'.$user->id, url_lang::lang('texts.Edit'));
// user's devices link
if ($this->acl_check_view('Devices_Controller', 'devices', $member->id))
......
$year = date('Y');
// rounds date down
date::round_down($day, $month, $year);
date::round_up($day, $month, $year);
// balance is in positive, we will go to the future
if ($balance > 0)
......
}
}
$month--;
if ($month == 0)
{
$month = 12;
$year--;
}
return '<span style="color: '.$color.'">'.date::create (date::days_of_month($month), $month, $year).'</span>';
}
freenetis/trunk/kohana/application/controllers/settings.php
if (!$this->acl_check_edit(get_class($this),'system'))
Controller::error(ACCESS);
// time of next update of ulogd
$ulogd_update_next = Settings::get('ulogd_update_last')+Settings::get('ulogd_update_interval');
if (Settings::get('ulogd_enabled'))
{
// time of next update of ulogd
$ulogd_update_next = Settings::get('ulogd_update_last')+Settings::get('ulogd_update_interval');
// remaining time to next update of ulogd
$remaining_time = $ulogd_update_next - time();
// remaining time to next update of ulogd
$remaining_time = $ulogd_update_next - time();
$additional_info = '<b>ulogd</b> - '.url_lang::lang('texts.info').':<br />';
$additional_info .= url_lang::lang('texts.last update').': <b>'.date('Y-m-d H:i:s',Settings::get('ulogd_update_last')).'</b>,<br />';
$additional_info .= '<span';
$additional_info = '<b>ulogd</b> - '.url_lang::lang('texts.info').':<br />';
$additional_info .= url_lang::lang('texts.last update').': <b>'.date('Y-m-d H:i:s',Settings::get('ulogd_update_last')).'</b>,<br />';
$additional_info .= '<span';
// remaining time is in past, print it red
if ($remaining_time < 0)
$additional_info .= ' style="color:red"';
// remaining time is in past, print it red
if ($remaining_time < 0)
$additional_info .= ' style="color:red"';
$additional_info .= '>'.url_lang::lang('texts.next update').': <b>'.date('Y-m-d H:i:s',$ulogd_update_next).'</b> ('.url_lang::lang('texts.Remaining time').': <b><span id="rest">'.date::counter($remaining_time).'</span></b>)</span>';
$additional_info .= '>'.url_lang::lang('texts.next update').': <b>'.date('Y-m-d H:i:s',$ulogd_update_next).'</b> ('.url_lang::lang('texts.Remaining time').': <b><span id="rest">'.date::counter($remaining_time).'</span></b>)</span>';
}
else
$additional_info = '';
// creating of new forge
$this->form = new Forge(NULL, '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$this->form->group('')->label(url_lang::lang('texts.Centralized logging'));
$this->form->group('')->label('ulogd '.help::hint('ulogd'))->message();
$this->form->checkbox('ulogd_enabled')->value('1')->label(url_lang::lang('texts.Enable ulogd'));
$this->form->input('ulogd_update_interval')->label(url_lang::lang('texts.Interval of update').':')->rules('required|valid_numeric')->value($this->settings->get('ulogd_update_interval'))->help(help::hint('ulogd_update_interval'));
$this->form->group('')->label(url_lang::lang('texts.Active members').' '.help::hint('ulogd_active'));
$this->form->input('ulogd_active_count')->label(url_lang::lang('texts.Count of active members').':')->rules('required|valid_ulogd_active_count')->value($this->settings->get('ulogd_active_count'))->help(help::hint('ulogd_active_count'));
$this->form->dropdown('ulogd_active_type')->label(url_lang::lang('texts.Type of traffic').':')->rules('required')->options(array(0 => '----- '.url_lang::lang('texts.Select type').' -----', 'upload' => url_lang::lang('texts.upload'), 'download' => url_lang::lang('texts.download'),'total' => url_lang::lang('texts.both').' ('.url_lang::lang('texts.upload').' + '.url_lang::lang('texts.download').')'))->selected($this->settings->get('ulogd_active_type'))->help(help::hint('ulogd_active_type'));
$this->form->group('')->label(url_lang::lang('texts.Action logs') . ' ' . help::hint('action_logs_active'));
$this->form->checkbox('action_logs_active')->value('1')->label(url_lang::lang('texts.Enable action logs'));
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
$user_model = new User_Model();
if (version_compare($user_model->get_mysql_version(), '5.1.0', '<'))
{
$this->form->action_logs_active->label(url_lang::lang('texts.Enable action logs').' - <span class="error">' . url_lang::lang('texts.require MySQL %s and higher', array('5.1')) . '</span>');
$this->form->action_logs_active->disabled('disabled');
}
else if ($this->settings->get('action_logs_active') == 1)
{
$this->form->action_logs_active->checked('checked');
}
$ulog2_ct_model = new Ulog2_ct_Model();
if (!$ulog2_ct_model->check_pre_requirements() && !$user_model->check_permission('CREATE ROUTINE'))
{
$this->form->ulogd_enabled->label(url_lang::lang('texts.Enable ulogd').' - <span class="error">' . url_lang::lang('texts.it requires already created functions for ulogd or MySQL permission CREATE ROUTINE for create them') . '</span>');
$this->form->ulogd_enabled->disabled('disabled');
}
else if ($this->settings->get('ulogd_enabled') == 1)
{
$this->form->ulogd_enabled->checked('checked');
}
// form validate
if ($this->form->validate())
{
$form_data = $this->form->as_array();
$config_model = new Config_Model();
// action logs value
$action_logs_active = (isset($form_data['action_logs_active']) && $form_data['action_logs_active'] == 1) ? '1' : '0';
// action logs value
$ulogd_enabled = (isset($form_data['ulogd_enabled']) && $form_data['ulogd_enabled'] == 1) ? '1' : '0';
// set logs checkbox value to db
$config_model->update_variable('action_logs_active', $action_logs_active);
$config_model->update_variable('ulogd_enabled', $ulogd_enabled);
// try to create log table if not exists
if ($action_logs_active == '1')
{
Log_Model::create_table();
}
// try to create ulogd function if not exists
if ($ulogd_enabled == '1' && $user_model->check_permission('CREATE ROUTINE'))
{
Ulog2_ct_Model::create_functions();
}
$issaved = true;
foreach ($form_data as $name => $value)
{
$value = addslashes($value);
if ($name == 'action_logs_active' OR $name == 'ulogd_enabled') continue;
// check if variable exists
if ($config_model->check_exist_variable($name))
// update of variable
freenetis/trunk/kohana/application/controllers/devices.php
* Function shows all devices of user.
* @return unknown_type
*/
function show_by_user($user_id = null, $limit_results = 500, $order_by = 'ip_address', $order_by_direction = 'asc', $page_word = null, $page = 1)
function show_by_user($user_id = null, $limit_results = 10, $order_by = 'id', $order_by_direction = 'asc', $page_word = 'page', $page = 1)
{
if (!isset($user_id))
// bad parameter
if (!$user_id || !is_numeric ($user_id))
Controller::warning(PARAMETER);
$user = new User_Model($user_id);
if ($user->id == 0)
Controller::error(RECORD);
// user doesn't exist
if (!$user->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_view(get_class($this),'devices',$user->member_id))
Controller::error(ACCESS);
$device_model = new Device_Model;
$this->session->set('ssUser_id',$user->id);
$device_model = new Device_Model();
$enum_type_model = new Enum_type_Model();
$port_model = new Port_Model();
$iface_model = new Iface_Model();
$vlan_iface_model = new Vlan_iface_Model();
$total_devices = $device_model->count_devices_of_user($user->id);
$allowed_order_by = array(
'id' => url_lang::lang('texts.Device ID'),
'name' => url_lang::lang('texts.Device name') ,
'type' => url_lang::lang('texts.Device type'),
'mac' => url_lang::lang('texts.MAC address'),
'ip_address' => url_lang::lang('texts.IP address')
);
$allowed_order_by_direction = array(
'asc' => url_lang::lang('texts.Ascending'),
'desc' => url_lang::lang('texts.Descending'),
);
if (!in_array($order_by, array_keys($allowed_order_by)))
$order_by = 'id';
if (!in_array(strtolower($order_by_direction), array_keys($allowed_order_by_direction)))
$order_by_direction = 'asc';
// get new selector
if (is_numeric($this->input->get('record_per_page')))
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
$total_devices = $device_model->count_devices_of_user($user_id);
if (($sql_offset = ($page - 1) * $limit_results) > $total_devices)
$sql_offset = 0;
$query = $device_model->get_devices_of_user($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $user_id);
$headline = url_lang::lang('texts.Device list of user').' '.$user->name.' '.$user->surname.' ('.url_lang::lang('texts.Member').' '.$user->member_id.' '.$user->member->name.')';
$sql_offset = 0;
$order_form = new Forge(url::base().url::current(TRUE),'', 'POST', array('id' => 'article_form'));
$order_form->set_attr('class', 'form_class')->set_attr('method', 'post');
$order_form->dropdown('order_by')->label(url_lang::lang('texts.Order by').':')->options($allowed_order_by)->rules('required')->selected($order_by);
$order_form->dropdown('order_by_direction')->label(url_lang::lang('texts.Direction').':')->options($allowed_order_by_direction)->rules('required')->selected($order_by_direction);
$order_form->submit('submit')->value(url_lang::lang('texts.Send'));
if ($order_form->validate())
{
$form_data = $order_form->as_array();
url::redirect(url_lang::base()."devices/show_by_user/$user_id/$limit_results/".$form_data['order_by']."/".$form_data['order_by_direction']."/$page_word/$page");
}
$grid = new Grid(url_lang::base().'devices/show_by_user', null,array(
//'separator' => '&nbsp;&nbsp;-&nbsp;&nbsp;',
//'use_paginator' => false,
//'use_selector' => false,
'current' => $limit_results, // current selected 'records_per_page' value
'selector_increace' => 500, // increace
'selector_min' => 500, // minimum where selector start
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang').'/devices/show_by_user/'.$user->id.'/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality
'total_items' => $total_devices, // 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,
'variables' => $user->id.'/',
'url_array_ofset' => 1
));
$devices = $device_model->get_devices_of_user($user_id, $sql_offset, $limit_results, $order_by, $order_by_direction);
$grid->add_new_button(url_lang::base().'members/show/'.$user->member_id, url_lang::lang('texts.Back to the member'));
$grid->add_new_button(url_lang::base().'users/show/'.$user->id, url_lang::lang('texts.Back to the user'));
if ($this->acl_check_new(get_class($this),'devices',$user->member_id))
$grid->add_new_button(url_lang::base().'devices/add_whole/'.$user->id, url_lang::lang('texts.Add new whole device'));
if ($this->acl_check_new(get_class($this),'devices',$user->member_id))
$grid->add_new_button(url_lang::base().'devices/add/'.$user->id, url_lang::lang('texts.Add new device'));
$grid->order_field('device_id')->label('ID')->class('center');
// name of the user's device is shown only, if user is the first user, so by this are shown association's devices
if ($user_id == 1)
$grid->order_callback_field('device_name')->label(url_lang::lang('texts.Name'))->callback('callback::device_field');
$grid->order_callback_field('type')->label(url_lang::lang('texts.Type'))->callback('callback::device_type_field');
//$grid->order_callback_field('price')->label(url_lang::lang('texts.Price'))->callback('callback::device_price_field');
//$grid->order_field('u_name')->label(url_lang::lang('texts.User'));
$grid->order_callback_field('mac')->label(url_lang::lang('texts.MAC address'))->callback('callback::iface_field');
//$grid->order_field('segment_name')->label(url_lang::lang('texts.Segment'));
$grid->order_callback_field('ip_address')->label(url_lang::lang('texts.IP address'))->callback('callback::ip_address_field');
$grid->order_callback_field('subnet_name')->label(url_lang::lang('texts.Subnet'))->callback('callback::subnet_field');
if ($this->acl_check_view(get_class($this),'devices',$user->member_id))
$grid->action_field('device_id')->label(url_lang::lang('texts.Device'))->url(url_lang::base().'devices/show')->action(url_lang::lang('texts.Show'))->class('center');
//if ($this->acl_check_edit(get_class($this),'devices',$user->member_id))
// $grid->action_field('id')->label(url_lang::lang('texts.Device'))->url(url_lang::base().'devices/edit')->action(url_lang::lang('texts.Edit'))->class('center');
if ($this->acl_check_delete('Devices_Controller', 'devices', $user->member_id))
$grid->action_field('device_id')->label(url_lang::lang('texts.Device'))->url(url_lang::base().'devices/delete')->action(url_lang::lang('texts.Delete'))->class('center')->script('onclick="return potvrd(\''.url_lang::lang('texts.Do you want to delete this device').'\');"');
if ($this->acl_check_delete('Devices_Controller', 'devices', $user->member_id))
$grid->action_field('device_id')->label(url_lang::lang('texts.Whole d.'))->url(url_lang::base().'devices/delete_whole')->action(url_lang::lang('texts.Delete'))->class('center')->script('onclick="return potvrd(\''.url_lang::lang('texts.Do you want to delete this device including all its interfaces and IP adresses').'\');"');
$grid->datasource($query);
$this->selector = new Selector (array(
'selector_max_multiplier' => 20,
'current' => $limit_results
));
$this->pagination = new Pagination (array(
'base_url' => Config::get('lang').'/devices/show_by_user/'.$user->id.'/'.$limit_results.'/'.$order_by.'/'.$order_by_direction,
'total_items' => $total_devices,
'items_per_page' => $limit_results,
'uri_segment' => 'page'
));
$arr_devices = array();
foreach ($devices as $device)
{
$arr_devices[$device->id] = array(
'type' => $device->type,
'name' => $device->name,
'grids' => array()
);
$ifaces = $iface_model->get_all_ifaces_of_device($device->id);
$grid = new Grid(url_lang::base().'devices', null,array(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($ifaces)
));
$grid->callback_field('id')->label('ID')->class('center')->callback('callback::iface_id_field');
$grid->field('name')->label(url_lang::lang('texts.Name'));;
$grid->field('mac')->label(url_lang::lang('texts.MAC'));;
$grid->callback_field('segment_id')->label(url_lang::lang('texts.Segment'))->callback('callback::segment_field');
$grid->callback_field('ip_address')->label(url_lang::lang('texts.IP address'))->callback('callback::ip_address_field', TRUE);
$grid->callback_field('subnet_id')->label(url_lang::lang('texts.Subnet'))->callback('callback::subnet_field');
if ($this->acl_check_edit(get_class($this),'iface',$user->member_id))
$grid->action_field('id')->label(url_lang::lang('texts.Interface')) ->url(url_lang::base().'ifaces/edit')->action(url_lang::lang('texts.Edit'))->class('center');
if ($this->acl_check_delete(get_class($this), 'iface', $user->member_id))
$grid->action_field('id')->label(url_lang::lang('texts.Interface')) ->url(url_lang::base().'ifaces/delete')->action(url_lang::lang('texts.Delete'))->class('center delete_link');
$grid->datasource($ifaces);
$arr_devices[$device->id]['grids']['interfaces'] = $grid;
$ports = $port_model->get_ports_of_device($device->id);
if (count($ports) > 0)
{
$grid = new Grid(url_lang::base().'devices', null,array(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($ports)
));
$grid->field('id')->label('ID')->class('center');
$grid->callback_field('name')->label(url_lang::lang('texts.Name'))->class('center')->callback('callback::port_field');
$grid->callback_field('segment_id')->label(url_lang::lang('texts.Segment'))->callback('callback::segment_field');
$grid->field('vlan_count')->label(url_lang::lang('texts.VLAN count'))->class('center');
if ($this->acl_check_edit(get_class($this),'port',$user->member_id))
$grid->action_field('id')->label(url_lang::lang('texts.Port')) ->url(url_lang::base().'ports/edit')->action(url_lang::lang('texts.Edit'))->class('center');
if ($this->acl_check_delete(get_class($this), 'port', $user->member_id))
$grid->action_field('id')->label(url_lang::lang('texts.Port')) ->url(url_lang::base().'ports/delete')->action(url_lang::lang('texts.Delete'))->class('center delete_link');
$grid->datasource($ports);
$arr_devices[$device->id]['grids']['ports'] = $grid;
}
$vlan_ifaces = $vlan_iface_model->get_all_vlan_ifaces_with_ip_addresses_by_device_id($device->id);
if (count($vlan_ifaces))
{
$grid = new Grid(url_lang::base().'devices', null,array(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($vlan_ifaces)
));
$grid->field('id')->label('ID')->class('center');
$grid->callback_field('vlan_iface_id')->label(url_lang::lang('texts.Name'))->callback('callback::vlan_iface_field');
$grid->callback_field('vlan_id')->label(url_lang::lang('texts.VLAN name'))->callback('callback::vlan_field');
$grid->field('tag_802_1q')->label(url_lang::lang('texts.tag_802_1q'));
$grid->field('iface_name')->label(url_lang::lang('texts.Interface'));
$grid->callback_field('ip_address')->label(url_lang::lang('texts.IP address'))->callback('callback::ip_address_field', TRUE);
if ($this->acl_check_edit(get_class($this),'vlan_iface',$user->member_id))
$grid->action_field('id')->label(url_lang::lang('texts.VLAN interface')) ->url(url_lang::base().'vlan_ifaces/edit')->action(url_lang::lang('texts.Edit'))->class('center');
if ($this->acl_check_delete(get_class($this), 'vlan_iface', $user->member_id))
$grid->action_field('id')->label(url_lang::lang('texts.VLAN interface')) ->url(url_lang::base().'vlan_ifaces/delete')->action(url_lang::lang('texts.Delete'))->class('center delete_link');
$grid->datasource($vlan_ifaces);
$arr_devices[$device->id]['grids']['vlan interfaces'] = $grid;
}
}
$headline = url_lang::lang('texts.Device list of user').' '.$user->name.' '.$user->surname.' ('.url_lang::lang('texts.Member').' '.$user->member_id.' '.$user->member->name.')';
$view = new View('main');
$view->extra_scripts = ' $(document).ready(function(){
$("#device_button_plus, #device_button_minus").click(function (){
if (this.id == "device_button_plus")
{
$(".device").removeClass("dispNone");
$(".device_button").attr("src", "'.url::base().'media/images/ico_minus.gif");
$(".device_button").attr("title", "'.url_lang::lang('texts.Hide this table').'");
}
else
{
$(".device").addClass("dispNone");
$(".device_button").attr("src", "'.url::base().'media/images/ico_plus.gif");
$(".device_button").attr("title", "'.url_lang::lang('texts.Show this table').'");
}
});
$(".device_button").click(function (){
var name = substr(this.id,0,strrpos(this.id,"button")-1);
if ($("#"+name).hasClass("dispNone"))
{
$("#"+name+"_button").attr("src", "'.url::base().'media/images/ico_minus.gif");
$("#"+name+"_button").attr("title", "'.url_lang::lang('texts.Hide this table').'");
$("#"+name).removeClass("dispNone");
}
else
{
$("#"+name+"_button").attr("src", "'.url::base().'media/images/ico_plus.gif");
$("#"+name+"_button").attr("title", "'.url_lang::lang('texts.Show this table').'");
$("#"+name).addClass("dispNone");
}
});
});';
$view->title = $headline;
$view->content = new View('show_all');
$view->content = new View('devices_show_by_user');
$view->content->user_id = $user->id;
$view->content->member_id = $user->member_id;
$view->content->total_devices = $total_devices;
$view->content->order_form = $order_form->html();
$view->content->headline = $headline;
$view->content->table = $grid;
$view->content->devices = $arr_devices;
$view->render(TRUE);
}
......
$de = $device_engineer_model->get_device_engineers($device_id);
$grid_device_engineers = new Grid(url_lang::base().'devices', null, array(
'use_paginator' => false,
'use_selector' => false
'use_selector' => false,
'total_items' => count($de)
));
if ($this->acl_check_new('Devices_Controller', 'engineer', $member_id))
$grid_device_engineers->add_new_button(url_lang::base()."device_engineers/add/$device_id", url_lang::lang('texts.Add new device engineer'));
......
$grid_device_engineers->field('surname')->label(url_lang::lang('texts.Surname'));
$grid_device_engineers->field('login')->label(url_lang::lang('texts.Username'));
if ($this->acl_check_delete('Devices_Controller', 'engineer', $member_id))
$grid_device_engineers->action_field('id')->label(url_lang::lang('texts.Remove')) ->url(url_lang::base().'device_engineers/remove')->action(url_lang::lang('texts.Remove'))->class('center');
$grid_device_engineers->action_field('id')->label(url_lang::lang('texts.Remove')) ->url(url_lang::base().'device_engineers/remove')->action(url_lang::lang('texts.Remove'))->class('center delete_link');
$grid_device_engineers->datasource($de);
// device admins
......
$da = $device_admin_model->get_device_admins($device_id);
$grid_device_admins = new Grid(url_lang::base().'devices', null, array(
'use_paginator' => false,
'use_selector' => false
'use_selector' => false,
'total_items' => count($da)
));
if ($this->acl_check_new(get_class($this), 'admin', $member_id))
$grid_device_admins->add_new_button(url_lang::base()."device_admins/edit/$device_id", url_lang::lang('texts.Add new device admin'));
if ($this->acl_check_edit(get_class($this), 'admin', $member_id))
$grid_device_admins->add_new_button(url_lang::base()."device_admins/edit/$device_id", url_lang::lang('texts.Edit device admins'));
$grid_device_admins->field('name')->label(url_lang::lang('texts.name'));
$grid_device_admins->field('surname')->label(url_lang::lang('texts.surname'));
$grid_device_admins->field('login')->label(url_lang::lang('texts.username'));
if ($this->acl_check_delete('Devices_Controller', 'admin', $member_id))
$grid_device_admins->action_field('id')->label(url_lang::lang('texts.Remove')) ->url(url_lang::base().'device_admins/remove')->action(url_lang::lang('texts.Remove'))->class('center');
$grid_device_admins->datasource($da);
// interfaces of device
......
->find_all();
$grid_ifaces = new Grid(url_lang::base().'devices', null,array(
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff