Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1705

Přidáno uživatelem Michal Kliment před asi 12 roky(ů)

Novinky:

- MAC adresa a typ zarizeni na seznamu IP adres podsite (fixes #327)

Opravy:

- export zarizeni typu mikrotik (fixes #320)

Upravy:

- pokroceny prace na generovani zaznamu DHCP serveru zarizeni (#312)

Zobrazit rozdíly:

freenetis/branches/1.1/application/i18n/cs_CZ/texts.php
'delete all records' => 'Smazat všechny záznamy',
'delete all unsended e-mails' => 'Smazat všechny neodeslané emaily',
'delete device' => 'Smazat zařízení',
'delete ip address' => 'Smazat IP adresu',
'delete own records' => 'Smazat vlastní záznamy',
'delete selection' => 'Smazat výběr',
'delete selected messages' => 'Smazat vybrané zprávy',
......
'show interface' => 'Zobrazit rozhraní',
'show invoice' => 'Zobrazit fakturu',
'show invoice item' => 'Zobrazit položku faktury',
'show ip address' => 'Zobrazit IP adresu',
'show login logs' => 'Zobrazit logy přihlášení',
'show logins of user' => 'Zobrazit uživatelovi přihlášení',
'show logs' => 'Zobrazit logy',
freenetis/branches/1.1/application/helpers/arr.php
* @param array array to convert
* @return object
*/
public static function to_object(array $array, $class = 'stdClass')
public static function to_object(array $array, $class = 'stdClass', $recursively = TRUE)
{
$object = new $class;
foreach ($array as $key => $value)
{
if (is_array($value))
if ($recursively && is_array($value))
{
// Convert the array to an object
$value = arr::to_object($value, $class);
$value = arr::to_object($value, $class, $recursively);
}
// Add the value to the object
freenetis/branches/1.1/application/models/device.php
", $device_id, Iface_Model::TYPE_PORT)->current()->pnumber;
}
/**
* Returns full export of device as object
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $device_id
* @return type
*/
public function get_export($device_id = NULL)
{
if (!$device_id && $this->id)
$device = $this;
else
$device = new Device_Model($device_id);
// interfaces of device
$interfaces = array();
// IP addresses of device
$addresses = array();
// gateways of device, probably only one
$gateways = array();
// DHCP servers of device
$dhcp_servers = array();
// all device's interfaces
foreach ($device->ifaces as $iface)
{
// for all type of interface
$interface = arr::to_object(array
(
'name' => $iface->name,
'type' => $iface->type,
'mac' => $iface->mac,
'number' => $iface->number,
'link_name' => $iface->link->name,
'comment' => '{link_name}'
), 'stdClass', FALSE);
// only for wireless type of interface
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$interface->wireless = arr::to_object(array
(
'mode' => $iface->wireless_mode,
'ssid' => $iface->link->wireless_ssid,
'norm' => $iface->link->wireless_norm,
'frequency' => $iface->link->wireless_norm,
'channel' => $iface->link->wireless_norm,
'channel_width' => $iface->link->wireless_norm,
'polarization' => $iface->link->wireless_norm,
'bitrate' => $iface->link->bitrate
), 'stdClass', FALSE);
// only for mode AP of wireless type of interface
if ($iface->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$interface->wireless->clients = array();
// find all connected client
foreach ($iface->link->ifaces as $link_iface)
{
// not device itself
if ($link_iface->id == $iface->id)
continue;
$interface->wireless->clients[] = arr::to_object(array
(
'name' => $link_iface->name,
'mac' => $link_iface->mac,
'device_name' => $link_iface->device->name,
'device_type' => $link_iface->device->type,
'member_id' => $link_iface->device->user->member->id,
'member_name' => $link_iface->device->user->member->name,
'member_type' => $link_iface->device->user->member->type,
'comment' => 'ID {member_id} - {member_name} - {device_name}'
), 'stdClass', FALSE);
}
}
}
// only for VLAN type of interface
else if ($iface->type == Iface_Model::TYPE_VLAN)
{
$interface->vlan = arr::to_object(array
(
'name' => $iface->ifaces_vlans->current()->vlan->name,
'parent_interface' => $iface->ifaces_relationships->current()->parent_iface->name,
'tag_802_1q' => $iface->ifaces_vlans->current()->vlan->tag_802_1q
), 'stdClass', FALSE);
}
// only for port type of interface
else if ($iface->type == Iface_Model::TYPE_PORT)
{
// default port vlan of port is default VLAN
$port_vlan = 1;
$vlans = array();
// for all port's vlans
foreach ($iface->ifaces_vlans as $iface_vlan)
{
// tagged or untagged
$vlans[$iface_vlan->vlan->tag_802_1q] = $iface_vlan->tagged;
// vlan is port vlan
if ($iface_vlan->port_vlan)
$port_vlan = $iface_vlan->vlan->tag_802_1q;
}
$interface['port'] = array
(
'mode' => $iface->port_mode,
'port_vlan' => $port_vlan,
'vlans' => $vlans
);
}
$interface->ip_addresses = array();
// interface's IP addresses
foreach ($iface->ip_addresses as $ip_address)
{
// create CIDR format
$cidr = $ip_address->subnet->network_address.'/'.network::netmask2cidr($ip_address->subnet->netmask);
// find broadcast address
$broadcast = long2ip(ip2long($ip_address->subnet->network_address) | ~ip2long($ip_address->subnet->netmask));
$address = arr::to_object(array
(
'address' => $ip_address->ip_address,
'netmask' => $ip_address->subnet->netmask,
'network' => $ip_address->subnet->network_address,
'broadcast' => $broadcast,
'cidr' => $cidr,
'interface' => $iface->name,
'subnet_name' => $ip_address->subnet->name,
'comment' => '{subnet_name}'
), 'stdClass', FALSE);
// device is gateway
if ($ip_address->gateway)
{
// DHCP server on subnet is running
if ($ip_address->subnet->dhcp)
{
$dhcp_server = arr::to_object(array
(
'name' => text::cs_utf2ascii($ip_address->subnet->name),
'network' => $ip_address->subnet->network_address,
'netmask' => $ip_address->subnet->netmask,
'gateway' => $ip_address->ip_address,
'broadcast' => $broadcast,
'cidr' => $cidr,
'interface' => $iface->name,
'range_start' => long2ip(ip2long($ip_address->ip_address)+1),
'range_end' => long2ip(ip2long($broadcast)-1),
'hosts' => array(),
'comment' => '{name}'
), 'stdClass', FALSE);
// find all hosts in subnets
foreach ($ip_address->subnet->ip_addresses as $dhcp_ip_address)
{
// not device itself
if ($dhcp_ip_address->ip_address == $ip_address->ip_address ||
!$dhcp_ip_address->iface_id)
{
continue;
}
// for VLAN interface get MAC from parent interface
if ($dhcp_ip_address->iface->type == Iface_Model::TYPE_VLAN)
$mac = $dhcp_ip_address->iface->ifaces_relationships->current()->parent_iface->mac;
else
$mac = $dhcp_ip_address->iface->mac;
$dhcp_server->hosts[] = arr::to_object(array
(
'id' => $dhcp_ip_address->id,
'server' => $dhcp_server->name,
'ip_address' => $dhcp_ip_address->ip_address,
'mac' => $mac,
'device_name' => $dhcp_ip_address->iface->device->name,
'device_type' => $dhcp_ip_address->iface->device->type,
'member_id' => $dhcp_ip_address->iface->device->user->member->id,
'member_name' => $dhcp_ip_address->iface->device->user->member->name,
'member_type' => $dhcp_ip_address->iface->device->user->member->type,
'comment' => 'ID {member_id} - {member_name} - {device_name}'
), 'stdClass', FALSE);
}
$dhcp_servers[] = $dhcp_server;
}
}
else
{
// find gateway of subnet
$gateway = $ip_address->subnet->get_gateway();
if ($gateway && $gateway->ip_address)
{
$gateways[] = $gateway->ip_address;
$address->gateway = $gateway->ip_address;
}
}
$addresses[] = $address;
$interface->ip_addresses[] = $address;
}
$interfaces[$iface->type][] = $interface;
}
// finally return result
return arr::to_object(array
(
'name' => $device->name,
'type' => $device->type,
'interfaces' => $interfaces,
'ip_addresses' => $addresses,
'dhcp_servers' => $dhcp_servers,
'gateways' => array_unique($gateways)
), 'stdClass', FALSE);
}
}
freenetis/branches/1.1/application/models/iface.php
protected $has_many = array
(
'ifaces_vlans', 'ip_addresses',
'parents' => 'ifaces_relationships',
'childrens' => 'ifaces_relationships'
'ifaces_relationships',
);
/** Wireless type of iface */
freenetis/branches/1.1/application/controllers/subnets.php
Controller::error(ACCESS);
}
// laod model
// load model
$subnet = new Subnet_Model($subnet_id);
// correct data?
......
$clouds = $subnet->get_clouds_of_subnet($subnet_id);
// ip addresses of subnet
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_of_subnet($subnet_id);
$ips = $subnet->ip_addresses;
$total_available = (~ip2long($subnet->netmask) & 0xffffffff)-1;
......
for ($i=1; $i <= $total_available; $i++)
{
$ip_addresses[$i] = new stdClass();
$ip_addresses[$i]->ip_address_id = NULL;
$ip_addresses[$i]->device_id = NULL;
$ip_addresses[$i]->device_name = NULL;
$ip_addresses[$i]->member_id = NULL;
$ip_addresses[$i]->ip_address = long2ip($network+$i);
$ip_addresses[$i] = arr::to_object(array
(
'ip_address_id' => NULL,
'id' => NULL,
'device_id' => NULL,
'device_name' => NULL,
'device_type' => NULL,
'member_id' => NULL,
'member_name' => NULL,
'ip_address' => long2ip($network+$i),
'mac' => NULL,
'iface_id' => NULL,
'iface_name' => NULL,
));
}
$enum_type_model = new Enum_type_Model();
foreach ($ips as $ip)
{
$ip_addresses[ip2long($ip->ip_address)-$network] = $ip;
if ($ip->iface_id)
{
$member_id = $ip->iface->device->user->member_id;
$member_name = $ip->iface->device->user->member->name;
}
else
{
$member_id = $ip->member_id;
$member_name = $ip->member->name;
}
$ip_addresses[ip2long($ip->ip_address)-$network] = arr::to_object(array
(
'id' => $ip->id,
'device_id' => $ip->iface->device_id,
'device_name' => $ip->iface->device->name,
'device_type' => $enum_type_model->get_value($ip->iface->device->type),
'member_id' => $member_id,
'member_name' => $member_name,
'ip_address' => $ip->ip_address,
'mac' => ($ip->iface->mac != '') ? $ip->iface->mac : '-',
'iface_id' => $ip->iface_id,
'iface_name' => $ip->iface->name
));
}
// grid
......
'use_selector' => false
));
$grid->field('ip_address_id')
->label(__('ID'));
$grid->field('ip_address')
->label('IP address');
$grid->callback_field('ip_address')
->label(__('IP address'))
->callback('callback::ip_address_field');
$grid->link_field('iface_id')
->link('ifaces/show', 'mac', 'iface_name')
->label('MAC');
$grid->callback_field('device_name')
->label(__('Device'))
->callback('callback::device_field');
$grid->link_field('device_id')
->link('devices/show', 'device_name')
->label(__('Device'));
$callback_link = '';
$grid->field('device_type')
->label(__('Type'));
if ($subnet->subnets_owner->member->id)
{
$callback_link = html::anchor(
'members/show/'.$subnet->subnets_owner->member->id,
$subnet->subnets_owner->member->name
);
}
$grid->link_field('member_id')
->link('members/show', 'member_name');
$grid->callback_field('member_name')
->label(__('Member'))
->callback('callback::member_field', $callback_link);
$actions = $grid->grouped_action_field();
$actions->add_action()
->icon_action('show')
->label('Show IP address')
->url('ip_addresses/show')
->class('popup_link');
$actions->add_action()
->icon_action('edit')
->label('Edit IP address')
->url('ip_addresses/edit')
->class('popup_link');
$actions->add_action()
->icon_action('delete')
->label('Delete IP address')
->url('ip_addresses/delete')
->class('delete_link');
// load datasource
$grid->datasource($ip_addresses);
freenetis/branches/1.1/application/controllers/devices.php
* @author Michal Kliment
* @param type $device_id
*/
public function export($device_id = NULL)
public function export($device_id = NULL, $format = '', $output = '')
{
// bad parameter
if (!$device_id || !is_numeric($device_id))
......
$device = new Device_Model($device_id);
// device doesn't exist
if (!$device->id)
Controller::error(RECORD);
// interfaces of device
$interfaces = array();
// IP addresses of device
$addresses = array();
// gateways of device, probably only one
$gateways = array();
foreach ($device->ifaces as $iface)
// user is not logged
if (!$this->user_id)
{
$interface = array
(
'name' => $iface->name,
'type' => $iface->type,
'mac' => $iface->mac,
'number' => $iface->number,
);
if ($iface->type == Iface_Model::TYPE_WIRELESS)
// device doesn't exist
if (!$device->id)
{
$interface['wireless'] = array
(
'mode' => $iface->wireless_mode,
'ssid' => $iface->link->wireless_ssid,
'norm' => $iface->link->wireless_norm,
'frequency' => $iface->link->wireless_norm,
'channel' => $iface->link->wireless_norm,
'channel_width' => $iface->link->wireless_norm,
'polarization' => $iface->link->wireless_norm,
'bitrate' => $iface->link->bitrate
);
if ($iface->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$interface['wireless']['clients'] = array();
foreach ($iface->link->ifaces as $link_iface)
{
if ($link_iface->id == $iface->id)
continue;
$interface['wireless']['clients'][] = array
(
'name' => $link_iface->name,
'mac' => $link_iface->mac,
'device_name' => $link_iface->device->name,
'device_type' => $link_iface->device->type,
'member_id' => $link_iface->device->user->member->id,
'member_name' => $link_iface->device->user->member->name,
'member_type' => $link_iface->device->user->member->type,
);
}
}
@header('HTTP/1.0 404 Not found');
die();
}
$interfaces[] = $interface;
foreach ($iface->ip_addresses as $ip_address)
$ip_addresses = array();
foreach ($device->ifaces as $iface)
{
// create CIDR format
$cidr = $ip_address->subnet->network_address.'/'.network::netmask2cidr($ip_address->subnet->netmask);
// find broadcast address
$broadcast = long2ip(ip2long($ip_address->subnet->network_address) | ~ip2long($ip_address->subnet->netmask));
$address = array
(
'address' => $ip_address->ip_address,
'netmask' => $ip_address->subnet->netmask,
'network' => $ip_address->subnet->network_address,
'broadcast' => $broadcast,
'cidr' => $cidr,
'interface' => $iface->name
);
if ($ip_address->gateway)
foreach ($iface->ip_addresses as $ip_address)
{
$ip_addresses[] = $ip_address->ip_address;
}
else
{
// find gateway of subnet
$gateway = $ip_address->subnet->get_gateway();
if ($gateway && $gateway->ip_address)
{
$gateways[] = $gateway->ip_address;
$address['gateway'] = $gateway->ip_address;
}
}
$addresses[] = $address;
}
// is it device itself?
if (!in_array(server::remote_addr(), $ip_addresses))
{
@header('HTTP/1.0 403 Forbidden');
die();
}
}
else
{
// device doesn't exist
if (!$device->id)
Controller::error(RECORD);
if (!$this->acl_check_view(get_class($this), 'devices', $device->user->member_id))
Controller::error(ACCESS);
}
$result = array
// definition of formats of export
$formats = array
(
'name' => $device->name,
'type' => $device->type,
'interfaces' => $interfaces,
'ip' => array
(
'addresses' => $addresses,
'gateways' => array_unique($gateways)
)
'debian-etc-dhcp-dhcpd' => 'Debian /etc/dhcp/dhcpd.conf',
'debian-etc-network-interfaces' => 'Debian /etc/network/interfaces',
'mikrotik-all' => 'Mikrotik',
'mikrotik-ip-dhcp-server-lease' => 'Mikrotik /ip dhcp-server lease',
);
debug::printr($result);
die();
// definition of models
$subnet_model = new Subnet_Model();
$ip_address_model = new Ip_address_Model();
$iface_model = new Iface_Model();
$device_model = new Device_Model();
// definition of array for data
$device_ifaces = array
// type of outputs
$outputs = array
(
Iface_Model::TYPE_WIRELESS => array(),
Iface_Model::TYPE_ETHERNET => array(),
Iface_Model::TYPE_PORT => array(),
Iface_Model::TYPE_BRIDGE => array(),
Iface_Model::TYPE_VLAN => array(),
Iface_Model::TYPE_INTERNAL => array(),
Iface_Model::TYPE_VIRTUAL_AP => array()
'text' => __('Text'),
'file' => __('File')
);
$device_wireless_iface_devices = array();
$device_ip_addresses = array();
$device_subnets = array();
$device_gateways = array();
$device_members = array();
$dhcp_subnets = array();
$dhcp_ip_addresses = array();
$qos_subnets = array();
$qos_ip_addresses = array();
// devices's interfaces
$ifaces = $iface_model->get_all_ifaces_of_device($device->id);
foreach ($ifaces as $iface)
// format and output is set
if ($format != '' && $output != '')
{
$device_ifaces[$iface->type][$iface->name] = $iface;
// bad format or output
if (!isset($formats[$format]) || !isset($outputs[$output]))
Controller::error(RECORD);
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$link_devices = $device_model->get_all_devices_of_link($iface->link_id);
$device_wireless_iface_devices[$iface->id] = array();
foreach ($link_devices as $link_device)
{
if ($link_device->id != $device->id)
$device_wireless_iface_devices[$iface->id][] = $link_device;
}
}
}
// device's ip addresses
$ip_addresses = $ip_address_model->get_ip_addresses_of_device($device->id);
foreach ($ip_addresses as $ip_address)
$device_ip_addresses[] = $ip_address;
// device's subnets
$subnets = $subnet_model->get_all_subnets_by_device($device->id);
$subnets_options = array();
$subnets_selected = array();
foreach ($subnets as $subnet)
{
$subnets_options[$subnet->id] = $subnet->name.' ('.$subnet->network_address.'/'.$subnet->subnet_range.')';
if ($subnet->gateway)
$subnets_selected[] = $subnet->id;
else
{
$gateway = $ip_address_model->get_gateway_of_subnet($subnet->id);
if ($gateway)
$device_gateways[$gateway->subnet_id] = $gateway->ip_address;
}
$device_subnets[$subnet->id] = $subnet;
// there is dhcp server on this subnet
if ($subnet->gateway && $subnet->dhcp)
$dhcp_subnets[$subnet->id] = $subnet;
// there is a qos on this subnet
if ($subnet->gateway && $subnet->qos)
$qos_subnets[$subnet->id] = $subnet;
$mac_addresses = array();
$dhcp_ip_addresses[$subnet->id] = array();
$ip_addresses = $ip_address_model->get_ip_addresses_of_subnet($subnet->id);
foreach ($ip_addresses as $ip_address)
{
if ($ip_address->ip_address != $subnet->ip_address)
{
if (!in_array($ip_address->mac, $mac_addresses))
{
$mac_addresses[] = $ip_address->mac;
// get full export of device
$device_export = $device->get_export();
if (!isset($device_members[$ip_address->member_id]))
$device_members[$ip_address->member_id] = $ip_address->member_name;
if ($subnet->dhcp)
$dhcp_ip_addresses[$subnet->id][$ip_address->id] = $ip_address;
if ($subnet->qos)
$qos_ip_addresses[$subnet->id][$ip_address->member_id][] = $ip_address->ip_address;
}
}
}
}
$title = __('Export of device');
$form = new Forge();
// format of export
$form->dropdown('format')
->options(array
(
'debian-etc-dhcp-dhcpd' => 'Debian /etc/dhcp/dhcpd.conf',
'debian-etc-network-interfaces' => 'Debian /etc/network/interfaces',
'mikrotik' => 'Mikrotik',
));
// result format - text or file
$form->dropdown('download_as')
->options(array
(
'text' => __('Text'),
'file' => __('File')
));
$form->submit('Export');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
if ($form_data['download_as'] == 'file')
if ($output == 'file')
{
switch ($form_data["format"])
switch ($format)
{
case "mikrotik":
$ext = '.rsc';
break;
default:
$ext = '';
break;
}
header ("Content-disposition: attachment; filename=".url::title($device->name)."-".$form_data['format']."-export".$ext);
header ("Content-disposition: attachment; filename=".url::title($device->name)."-".$format."-export".$ext);
}
else
echo "<pre>";
$view = new View('device_templates/'.$form_data['format']);
$view->name = $device->name;
$view->dhcp_subnets = $dhcp_subnets;
$view->dhcp_ip_addresses = $dhcp_ip_addresses;
$view->qos_subnets = $qos_subnets;
$view->qos_ip_addresses = $qos_ip_addresses;
$view->device_members = $device_members;
$view->device_ifaces = $device_ifaces;
$view->device_ip_addresses = $device_ip_addresses;
$view->device_gateways = $device_gateways;
$view->device_wireless_iface_devices = $device_wireless_iface_devices;
$view = new View('device_templates/'.$format);
$view->result = $device_export;
$view->dns_servers = explode("\n", Settings::get('dns_servers'));
$view->render(TRUE);
}
// form to choose format and output
else
{
$title = __('Export of device');
$form = new Forge();
// format of export
$form->dropdown('format')
->rules('required')
->options(array
(
NULL => '----- '.__('Choose format of export').' -----'
) + $formats);
// result format - text or file
$form->dropdown('output')
->rules('required')
->label('Download as')
->options(array
(
NULL => '----- '.__('Choose').' -----'
) + $outputs);
$form->submit('Export');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
$this->redirect('devices/export/'.$device_id.'/'.$form_data['format'].'/'.$form_data['output']);
}
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
freenetis/branches/1.1/application/libraries/grid/Link_field.php
public $data_name = 'id';
/**
* Title of data column
*
* @var string
*/
public $data_title = '';
/**
* URL to action
*
* @var string
......
* @param string $url
* @param string $data_name Name of data field, if empty name is set as data name
*/
public function link($url, $data_name = NULL)
public function link($url, $data_name = NULL, $data_title = NULL)
{
if (!text::starts_with($url, url::base()))
{
......
$this->data_name = $data_name;
if (empty($data_title))
{
$data_title = $data_name;
}
$this->data_title = $data_title;
if (!empty($data_name))
{
$this->label = __(utf8::ucfirst(inflector::humanize($data_name)));
freenetis/branches/1.1/application/libraries/MY_Controller.php
{
// init sessions
$this->session = Session::instance();
// store user ID from session
$this->user_id = $this->session->get('user_id', 0);
// store member ID from session
$this->member_id = $this->session->get('member_id', 0);
// test if visitor is logged in, or he accesses public
// controllers like registration, redirect, installation, etc.
if (!in_array(url_lang::current(), self::$login_not_required) &&
strpos(url_lang::current(), 'web_interface') === false &&
url_lang::current(true) != 'web_interface' &&
!$this->session->get('user_id', 0))
!text::starts_with(url_lang::current(), 'devices/export') &&
!$this->user_id)
{
// Not logged in - redirect to login page
$this->session->set_flash('err_message', __('Must be logged in'));
......
}
// load these variables only for logged user
if ($this->session->get('user_id', 0))
if ($this->user_id)
{
// for preprocessing some variable
try
......
// helper class
$member = new Member_Model();
// store user ID from session
$this->user_id = $this->session->get('user_id');
// store member ID from session
$this->member_id = $this->session->get('member_id');
// boolean variable if user has any phone invoices (for menu rendering)
$phone_invoice_user = new Phone_invoice_user_Model();
freenetis/branches/1.1/application/views/device_export_templates/mikrotik-all.php
<?php
if (isset($result->interfaces[Iface_Model::TYPE_WIRELESS]))
{
?>
/interface wireless
<?php
foreach ($result->interfaces[Iface_Model::TYPE_WIRELESS] as $id => $iface)
{
if ($iface->wireless->norm)
{
$norm = $iface->wireless->norm;
if ($iface->wireless->frequency !="")
$frequency = " frequency=".$iface->wireless->frequency;
}
else
{
$norm = Link_Model::NORM_802_11_A;
$frequency = "";
}
?>
set <?php echo $id ?> arp=enabled disabled=no mac-address=<?php echo $iface->mac ?> name="<?php echo $iface->name ?>" comment="<?php echo text::cs_utf2ascii(text::object_format($iface, $iface->comment)) ?>" <?php
switch ($iface->wireless->mode)
{
case Iface_Model::WIRELESS_MODE_AP:
echo "mode=ap-bridge ";
break;
case Iface_Model::WIRELESS_MODE_CLIENT:
echo "mode=station ";
break;
}
switch ($norm)
{
case Link_Model::NORM_802_11_B:
echo " band=2ghz-b ";
break;
case Link_Model::NORM_802_11_G:
echo " band=2ghz-onlyg ";
break;
case Link_Model::NORM_802_11_B_G:
echo " band=2ghz-b/g ";
break;
case Link_Model::NORM_802_11_A:
case Link_Model::NORM_802_11_N:
echo " band=5ghz-a ";
break;
}
if ($iface->wireless->channel_width != "")
echo "channel-width=".$iface->wireless->channel_width."mhz ";
?>country="czech republic" default-authentication=yes<?php echo $frequency ?> ssid="<?php echo $iface->wireless->ssid ?>"
<?php } ?>
<?php if (isset($result->interfaces[Iface_Model::TYPE_VIRTUAL_AP])): ?>
<?php foreach ($result->interfaces[Iface_Model::TYPE_VIRTUAL_AP] as $iface): ?>
add arp=enabled disabled=no mac-address=<?php echo $iface->mac ?> master-interface="<?php echo $iface->parent_name ?>" name="<?php echo $iface->name ?>" ssid="<?php echo $iface->wireless_ssid ?>"
<?php endforeach ?>
<?php endif ?>
/interface wireless access-list
<?php
foreach ($result->interfaces[Iface_Model::TYPE_WIRELESS] as $id => $iface)
{
foreach ($iface->wireless->clients as $client)
{
?>
add disabled=no interface="<?php echo $iface->name ?>" forwarding=no mac-address=<?php echo $client->mac ?> comment="<?php echo text::cs_utf2ascii(text::object_format($client, $client->comment)) ?>"
<?php
}
}
}
?>
/interface ethernet
<?php
if (isset($result->interfaces[Iface_Model::TYPE_ETHERNET]))
{
foreach ($result->interfaces[Iface_Model::TYPE_ETHERNET] as $id => $iface)
{
?>
set <?php echo $id ?> arp=enabled auto-negotiation=yes disabled=no full-duplex=yes mac-address=<?php echo $iface->mac ?> name="<?php echo $iface->name ?>" comment="<?php echo text::cs_utf2ascii(text::object_format($iface, $iface->comment)) ?>"
<?php
}
}
?>
<?php if (isset($result->interfaces[Iface_Model::TYPE_VLAN])): ?>
/interface vlan
<?php foreach ($result->interfaces[Iface_Model::TYPE_VLAN] as $id => $iface): ?>
add arp=enabled disabled=no interface="<?php echo $iface->vlan->parent_interface ?>" name="<?php echo $iface->name ?>" vlan-id=<?php echo $iface->vlan->tag_802_1q ?> comment="<?php echo text::cs_utf2ascii($iface->vlan->name) ?>"
<?php endforeach ?>
<?php endif ?>
/ip address
<?php foreach ($result->ip_addresses as $address): ?>
add address=<?php echo $address->address ?>/<?php echo network::netmask2cidr($address->netmask) ?> disabled=no interface="<?php echo $address->interface ?>" network=<?php echo $address->network ?> comment="<?php echo text::cs_utf2ascii(text::object_format($address, $address->comment)) ?>"
<?php endforeach ?>
/ip dns
set allow-remote-requests=yes servers=<?php echo implode(", ",$dns_servers) ?>
/ip pool
<?php foreach ($result->dhcp_servers as $dhcp_server): ?>
add name="<?php echo text::cs_utf2ascii($dhcp_server->name) ?>" ranges=<?php echo $dhcp_server->range_start ?>-<?php echo $dhcp_server->range_end ?>
<?php endforeach ?>
/ip dhcp-server
<?php foreach ($result->dhcp_servers as $dhcp_server): ?>
add name="<?php echo text::cs_utf2ascii($dhcp_server->name) ?>" address-pool="<?php echo text::cs_utf2ascii($dhcp_server->name) ?>" authoritative=after-2sec-delay bootp-support=static disabled=no interface="<?php echo $dhcp_server->interface ?>" lease-time=3d
<?php endforeach ?>
/ip dhcp-server config
set store-leases-disk=5m
/ip dhcp-server network
<?php foreach ($result->dhcp_servers as $dhcp_server): ?>
add address=<?php echo $dhcp_server->cidr ?> dhcp-option="" dns-server="" gateway=<?php echo $dhcp_server->gateway ?> ntp-server="" wins-server="" comment="<?php echo text::cs_utf2ascii(text::object_format($dhcp_server, $dhcp_server->comment)) ?>"
<?php endforeach ?>
/ip dhcp-server lease
<?php foreach ($result->dhcp_servers as $dhcp_server): ?>
<?php foreach ($dhcp_server->hosts as $host): ?>
add address=<?php echo $host->ip_address ?> disabled=no mac-address=<?php echo $host->mac ?> server="<?php echo $host->server ?>" comment="<?php echo text::cs_utf2ascii(text::object_format($host, $host->comment)) ?>"
<?php endforeach ?>
<?php endforeach ?>
/ip route
<?php foreach ($result->gateways as $gateway): ?>
add disabled=no dst-address=0.0.0.0/0 gateway=<?php echo $gateway ?>
<?php endforeach ?>
/system identify set name="<?php echo text::cs_utf2ascii($result->name) ?>"
<?php if (isset($gateway)): ?>
/system watchdog set watchdog-timer=yes watch-address=<?php echo $gateway ?>
<?php endif ?>
freenetis/branches/1.1/application/views/device_export_templates/debian-etc-network-interfaces.php
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
<?php
foreach ($result->interfaces as $interfaces)
{
foreach ($interfaces as $interface)
{
foreach ($interface->ip_addresses as $i => $ip_address)
{
$name = ($i > 0) ? $interface->name.':'.$i : $interface->name;
?>
auto <?php echo $name ?>
iface <?php echo $name ?> inet static
address <?php echo $ip_address->address ?>
netmask <?php echo $ip_address->netmask ?>
<?php if (isset($ip_address->gateway)): ?>
gateway <?php echo $ip_address->gateway ?>
<?php endif ?>
<?php
}
}
}
?>
freenetis/branches/1.1/application/views/device_export_templates/mikrotik-ip-dhcp-server-lease.php
/ip dhcp-server lease
remove [find]
<?php foreach ($result->dhcp_servers as $dhcp_server): ?>
<?php foreach ($dhcp_server->hosts as $host): ?>
add address=<?php echo $host->ip_address ?> disabled=no mac-address=<?php echo $host->mac ?> server="<?php echo $host->server ?>" comment="<?php echo text::cs_utf2ascii(text::object_format($host, $host->comment)) ?>"
<?php endforeach ?>
<?php endforeach ?>
freenetis/branches/1.1/application/views/device_export_templates/debian-etc-dhcp-dhcpd.php
#
# Sample configuration file for ISC dhcpd for Debian
#
#
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;
# option definitions common to all supported networks...
option domain-name-servers <?php echo implode(", ",$dns_servers) ?>;
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
<?php foreach ($result->dhcp_servers as $dhcp_server): ?>
# <?php echo $dhcp_server->name ?>
subnet <?php echo $dhcp_server->network ?> netmask <?php echo $dhcp_server->netmask ?>
{
range <?php echo $dhcp_server->range_start ?> <?php echo $dhcp_server->range_end ?>;
option subnet-mask <?php echo $dhcp_server->netmask ?>;
option broadcast-address <?php echo $dhcp_server->broadcast ?>;
option routers <?php echo $dhcp_server->gateway ?>;
<?php foreach ($dhcp_server->hosts as $host): ?>
# <?php echo text::cs_utf2ascii(text::object_format($host, $host->comment)) ?>
host host_<?php echo $host->id ?>
{
hardware ethernet <?php echo $host->mac ?>;
fixed-address <?php echo $host->ip_address ?>;
}
<?php endforeach ?>
}
<?php endforeach ?>
freenetis/branches/1.1/application/views/grid_template.php
}
$property = $action_field->name;
// do not display row with empty property
if (!$item->$property)
continue;
$class = array();
if (!empty($action_field->class))
......
$href = $item->$property;
$property = $field->data_name;
$text = $item->$property;
$property = $field->data_title;
$title = ($property) ? $item->$property : '';
echo '<td class="noprint">';
......
echo html::anchor($field->url.'/'.$href, $text, array
(
'script' => $field->script,
'class' => $field->class
'class' => $field->class,
'title' => $title
));
}
else
......
if ($field instanceof Callback_Field || $field instanceof Order_Callback_Field)
{
if (isset($field->callback))
{
if (!is_callable($field->callback))
$field->callback = 'callback::'.$field->callback;
call_user_func($field->callback, $item, $field->name, $field->args['callback']);
}
else
echo $item->$field;
}
freenetis/branches/1.1/application/views/device_templates/mikrotik.php
<?php if(count($device_ifaces[Iface_Model::TYPE_WIRELESS])): ?>
/interface wireless
<?php foreach ($device_ifaces[Iface_Model::TYPE_WIRELESS] as $iface_id => $iface)
{
if ($iface->wireless_norm)
{
$norm = $iface->wireless_norm;
if ($iface->wireless_frequency !="")
$frequency = " frequency=".$iface->wireless_frequency;
}
else
{
$norm = Link_Model::NORM_802_11_A;
$frequency = "";
}
?>
set <?php echo $iface_id ?> arp=enabled disabled=no mac-address=<?php echo $iface->mac ?> name="<?php echo $iface->name ?>" <?php
switch ($iface->wireless_mode)
{
case Iface_Model::WIRELESS_MODE_AP:
echo "mode=ap-bridge ";
break;
case Iface_Model::WIRELESS_MODE_CLIENT:
echo "mode=station ";
break;
}
switch ($norm)
{
case Link_Model::NORM_802_11_B:
echo " band=2ghz-b ";
break;
case Link_Model::NORM_802_11_G:
echo " band=2ghz-onlyg ";
break;
case Link_Model::NORM_802_11_B_G:
echo " band=2ghz-b/g ";
break;
case Link_Model::NORM_802_11_A:
case Link_Model::NORM_802_11_N:
echo " band=5ghz-a ";
break;
}
if ($iface->wireless_channel_width != "")
echo "channel-width=".$iface->wireless_channel_width."mhz ";
?>country="czech republic" default-authentication=yes<?php echo $frequency ?> ssid="<?php echo $iface->wireless_ssid ?>"
<?php } ?>
<?php foreach ($device_ifaces[Iface_Model::TYPE_VIRTUAL_AP] as $iface): ?>
add arp=enabled disabled=no mac-address=<?php echo $iface->mac ?> master-interface="<?php echo $iface->parent_name ?>" name="<?php echo $iface->name ?>" ssid="<?php echo $iface->wireless_ssid ?>"
<?php endforeach ?>
/interface wireless access-list
<?php foreach ($device_ifaces[Iface_Model::TYPE_WIRELESS] as $iface_id => $iface): ?>
<?php foreach ($device_wireless_iface_devices[$iface->id] as $device_wireless_iface_device): ?>
add disabled=no interface="<?php echo $iface->name ?>" forwarding=no mac-address=<?php echo $device_wireless_iface_device->mac ?> comment="<?php echo text::cs_utf2ascii(text::object_format($device_wireless_iface_device, "ID {member_id} - {member_name} - {name} (IP {ip_address})")) ?>"
<?php endforeach ?>
<?php endforeach ?>
<?php endif ?>
/interface ethernet
<?php foreach ($device_ifaces[Iface_Model::TYPE_ETHERNET] as $iface_id => $iface): ?>
set <?php echo $iface_id ?> arp=enabled auto-negotiation=yes disabled=no full-duplex=yes mac-address=<?php echo $iface->mac ?> name="<?php echo $iface->name ?>"
<?php endforeach ?>
/interface vlan
<?php foreach ($device_ifaces[Iface_Model::TYPE_VLAN] as $iface_id => $iface): ?>
add arp=enabled disabled=no interface="<?php echo $iface->parent_name ?>" name="<?php echo $iface->name ?>" vlan-id=<?php echo $iface->tag_802_1q ?>
<?php endforeach ?>
/ip address
<?php foreach ($device_ip_addresses as $device_ip_address): ?>
add address=<?php echo $device_ip_address->ip_address ?>/<?php echo $device_ip_address->subnet_range ?> disabled=no interface="<?php echo $device_ip_address->iface_name !='' ? $device_ip_address->iface_name : $device_ip_address->vlan_iface_name ?>" network=<?php echo $device_ip_address->subnet_network ?>
<?php endforeach ?>
/ip dns
set allow-remote-requests=yes servers=<?php echo implode(", ",$dns_servers) ?>
/ip pool
<?php foreach ($dhcp_subnets as $dhcp_subnet): ?>
add name="<?php echo $dhcp_subnet->iface ?>" ranges=<?php echo $dhcp_subnet->subnet_range_start ?>-<?php echo $dhcp_subnet->subnet_range_end ?>
<?php endforeach ?>
/ip dhcp-server
<?php foreach ($dhcp_subnets as $dhcp_subnet): ?>
add address-pool="<?php echo $dhcp_subnet->iface ?>" authoritative=after-2sec-delay bootp-support=static disabled=no interface="<?php echo $dhcp_subnet->iface ?>" lease-time=3d name="<?php echo $dhcp_subnet->iface ?>"
<?php endforeach ?>
/ip dhcp-server config
set store-leases-disk=5m
/ip dhcp-server network
<?php foreach ($dhcp_subnets as $dhcp_subnet): ?>
add address=<?php echo $dhcp_subnet->network_address ?>/<?php echo $dhcp_subnet->subnet_range ?> dhcp-option="" dns-server="" gateway=<?php echo $dhcp_subnet->ip_address ?> ntp-server="" wins-server=""
<?php endforeach ?>
/ip dhcp-server lease
<?php foreach ($dhcp_subnets as $subnet_id => $dhcp_subnet): ?>
<?php foreach ($dhcp_ip_addresses[$subnet_id] as $dhcp_ip_address): ?>
add address=<?php echo $dhcp_ip_address->ip_address ?> disabled=no mac-address=<?php echo $dhcp_ip_address->mac ?> server="<?php echo $dhcp_subnet->iface !='' ? $dhcp_subnet->iface : $dhcp_subnet->vlan_iface ?>" comment="ID <?php echo $dhcp_ip_address->member_id ?> - <?php echo text::cs_utf2ascii($dhcp_ip_address->member_name) ?> - <?php echo text::cs_utf2ascii($dhcp_ip_address->device_name) ?>"
<?php endforeach ?>
<?php endforeach ?>
/ip route
<?php foreach ($device_gateways as $device_gateway): ?>
add disabled=no dst-address=0.0.0.0/0 gateway=<?php echo $device_gateway ?>
<?php endforeach ?>
/queue simple
add disabled=no target-addresses=0.0.0.0/0 interface=all name="Parent queue" parent=none priority=1
<?php foreach ($qos_subnets as $qos_subnet): ?>
add disabled=no target-addresses=<?php echo $qos_subnet->network_address ?>/<?php echo $qos_subnet->subnet_range ?> interface="<?php echo $qos_subnet->iface !='' ? $qos_subnet->iface : $qos_subnet->vlan_iface ?>" name="<?php echo text::cs_utf2ascii($qos_subnet->name) ?>" priority=2 parent="Parent queue"
<?php endforeach ?>
<?php foreach ($qos_subnets as $subnet_id => $qos_subnet)
{
$names[] = array();
foreach ($qos_ip_addresses[$subnet_id] as $member_id => $qos_member_ip_addresses)
{
if ($member_id != 1)
$qos_name = "ID $member_id - ".text::cs_utf2ascii($device_members[$member_id]);
else
$qos_name = "ID $member_id - ".text::cs_utf2ascii($qos_subnet->name);
if (in_array($qos_name, $names))
$qos_name .= " (".text::cs_utf2ascii($qos_subnet->name).")";
$names[] = $qos_name;
?>add disabled=no interface=all target-addresses=<?php echo implode(",",$qos_member_ip_addresses) ?> name="<?php echo $qos_name ?>" parent="<?php echo text::cs_utf2ascii($qos_subnet->name) ?>" priority=8
<?php
}
} ?>
<?php foreach ($qos_subnets as $qos_subnet): ?>
add disabled=no target-addresses=<?php echo $qos_subnet->network_address ?>/<?php echo $qos_subnet->subnet_range ?> interface="<?php echo $qos_subnet->iface !='' ? $qos_subnet->iface : $qos_subnet->vlan_iface ?>" name="others on <?php echo text::cs_utf2ascii($qos_subnet->name) ?>" parent="<?php echo text::cs_utf2ascii($qos_subnet->name) ?>" priority=8
<?php endforeach ?>
/system identify set name="<?php echo text::cs_utf2ascii($name) ?>"
<?php if (isset($device_gateway)): ?>
/system watchdog set watchdog-timer=yes watch-address=<?php echo $device_gateway ?>
<?php endif ?>

Také k dispozici: Unified diff