<?php

namespace app\models\mikrotik\capsman;

use yii\base\Model;
use Yii;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Interfaces extends Model {

    public $id;
    public $name;
    public $mtu;
    public $l2mtu;
    public $mac_address;
    public $arp;
    public $radio_mac;
    public $master_interface;
    public $configuration;
    public $configurationmode;
    public $configurationssid;
    public $configurationhide_ssid;
    public $configurationmax_sta_count;
    public $configurationmulticast_helper;
    public $configurationtx_chains;
    public $configurationrx_chains;
    public $configurationguard_interval;
    public $configurationcountry;
    public $configurationload_balancing_group;
    public $security;
    public $securityauthentication_types;
    public $securityencryption;
    public $securitygroup_encryption;
    public $securitypassphrase;
    public $securityeap_methods;
    public $securitytls_mode;
    public $securitytls_certificate;
    public $datapath;
    public $datapathclient_to_client_forwarding;
    public $datapathbridge;
    public $datapathbridge_cost;
    public $datapathbridge_horizon;
    public $datapathlocal_forwarding;
    public $datapathvlan_mode;
    public $datapathvlan_id;
    public $channel;
    public $channelfrequency;
    public $channelwidth;
    public $channelband;
    public $channelextension_channel;
    public $channeltx_power;
    public $master;
    public $bound;
    public $inactive;
    public $running;
    public $disabled;

    public function rules() {
        return [
            ['id', 'string'],
            ['name', 'string'],
            ['mtu', 'string'],
            ['l2mtu', 'string'],
            ['mac_address', 'string'],
            ['arp', 'string'],
            ['radio_mac', 'string'],
            ['master_interface', 'string'],
            ['configuration', 'string'],
            ['configurationmode', 'string'],
            ['configurationssid', 'string'],
            ['configurationhide_ssid', 'string'],
            ['configurationmax_sta_count', 'string'],
            ['configurationmulticast_helper', 'string'],
            ['configurationguard_interval', 'string'],
            ['configurationcountry', 'string'],
            ['configurationload_balancing_group', 'string'],
            ['security', 'string'],
            ['securitygroup_encryption', 'string'],
            ['securitypassphrase', 'string'],
            ['securitytls_mode', 'string'],
            ['securitytls_certificate', 'string'],
            ['datapath', 'string'],
            ['datapathclient_to_client_forwarding', 'string'],
            ['datapathbridge', 'string'],
            ['datapathbridge_cost', 'string'],
            ['datapathbridge_horizon', 'string'],
            ['datapathlocal_forwarding', 'string'],
            ['datapathvlan_mode', 'string'],
            ['datapathvlan_id', 'string'],
            ['channel', 'string'],
            ['channelfrequency', 'string'],
            ['channelwidth', 'string'],
            ['channelband', 'string'],
            ['channelextension_channel', 'string'],
            ['channeltx_power', 'string'],
            ['master', 'string'],
            ['bound', 'string'],
            ['inactive', 'string'],
            ['running', 'string'],
            ['disabled', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/interface/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Interfaces();
                $c->id = $response->getProperty('.id');
                $c->name = $response->getProperty('name');
                $c->mtu = $response->getProperty('mtu');
                $c->l2mtu = $response->getProperty('l2mtu');
                $c->mac_address = $response->getProperty('mac-address');
                $c->arp = $response->getProperty('arp');
                $c->radio_mac = $response->getProperty('radio-mac');
                $c->master_interface = $response->getProperty('master-interface');
                $c->configuration = $response->getProperty('configuration');
                $c->configurationmode = $response->getProperty('configuration.mode');
                $c->configurationssid = $response->getProperty('configuration.ssid');
                $c->configurationhide_ssid = $response->getProperty('configuration.hide-ssid');
                $c->configurationmax_sta_count = $response->getProperty('configuration.max-sta-count');
                $c->configurationmulticast_helper = $response->getProperty('configuration.multicast-helper');
                $c->configurationtx_chains = $response->getProperty('configuration.tx-chains');
                $c->configurationrx_chains = $response->getProperty('configuration.rx-chains');
                $c->configurationguard_interval = $response->getProperty('configuration.guard-interval');
                $c->configurationcountry = $response->getProperty('configuration.country');
                $c->configurationload_balancing_group = $response->getProperty('configuration.load-balancing-group');
                $c->security = $response->getProperty('security');
                $c->securityauthentication_types = $response->getProperty('security.authentication-types');
                $c->securityencryption = $response->getProperty('security.encryption');
                $c->securitygroup_encryption = $response->getProperty('security.group-encryption');
                $c->securitypassphrase = $response->getProperty('security.passphrase');
                $c->securityeap_methods = $response->getProperty('security.eap-methods');
                $c->securitytls_mode = $response->getProperty('security.tls-mode');
                $c->securitytls_certificate = $response->getProperty('security.tls-certificate');
                $c->datapath = $response->getProperty('datapath');
                $c->datapathclient_to_client_forwarding = $response->getProperty('datapath.client-to-client-forwarding');
                $c->datapathbridge = $response->getProperty('datapath.bridge');
                $c->datapathbridge_cost = $response->getProperty('datapath.bridge-cost');
                $c->datapathbridge_horizon = $response->getProperty('datapath.bridge-horizon');
                $c->datapathlocal_forwarding = $response->getProperty('datapath.local-forwarding');
                $c->datapathvlan_mode = $response->getProperty('datapath.vlan-mode');
                $c->datapathvlan_id = $response->getProperty('datapath.vlan-id');
                $c->channel = $response->getProperty('channel');
                $c->channelfrequency = $response->getProperty('channel.frequency');
                $c->channelwidth = $response->getProperty('channel.width');
                $c->channelband = $response->getProperty('channel.band');
                $c->channelextension_channel = $response->getProperty('channel.extension-channel');
                $c->channeltx_power = $response->getProperty('channel.tx-power');
                $c->master = $response->getProperty('master');
                $c->bound = $response->getProperty('bound');
                $c->inactive = $response->getProperty('inactive');
                $c->running = $response->getProperty('running');
                $c->disabled = $response->getProperty('disabled');
                $return[] = $c;
            }
        }
        return $return;
    }

    public function get($id) {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/interface/print');
        $getRequest->setQuery(RouterOS\Query::where('.id', $id));
        $responses = $connect->getConnection()->sendSync($getRequest);
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $this->id = $response->getProperty('.id');
                $this->name = $response->getProperty('name');
                $this->mtu = $response->getProperty('mtu');
                $this->l2mtu = $response->getProperty('l2mtu');
                $this->mac_address = $response->getProperty('mac-address');
                $this->arp = $response->getProperty('arp');
                $this->radio_mac = $response->getProperty('radio-mac');
                $this->master_interface = $response->getProperty('master-interface');
                $this->configuration = $response->getProperty('configuration');
                $this->configurationmode = $response->getProperty('configuration.mode');
                $this->configurationssid = $response->getProperty('configuration.ssid');
                $this->configurationhide_ssid = (($response->getProperty('configuration.hide-ssid') == 'true') ? true : false);
                $this->configurationmax_sta_count = $response->getProperty('configuration.max-sta-count');
                $this->configurationmulticast_helper = $response->getProperty('configuration.multicast-helper');
                $this->configurationtx_chains = $response->getProperty('configuration.tx-chains');
                $this->configurationrx_chains = $response->getProperty('configuration.rx-chains');
                $this->configurationguard_interval = $response->getProperty('configuration.guard-interval');
                $this->configurationcountry = $response->getProperty('configuration.country');
                $this->configurationload_balancing_group = $response->getProperty('configuration.load-balancing-group');
                $this->security = $response->getProperty('security');
                $this->securityauthentication_types = $response->getProperty('security.authentication-types');
                $this->securityencryption = $response->getProperty('security.encryption');
                $this->securitygroup_encryption = $response->getProperty('security.group-encryption');
                $this->securitypassphrase = $response->getProperty('security.passphrase');
                $this->securityeap_methods = $response->getProperty('security.eap-methods');
                $this->securitytls_mode = $response->getProperty('security.tls-mode');
                $this->securitytls_certificate = $response->getProperty('security.tls-certificate');
                $this->datapath = $response->getProperty('datapath');
                $this->datapathclient_to_client_forwarding = (($response->getProperty('datapath.client-to-client-forwarding') == 'true') ? true : false);
                $this->datapathbridge = $response->getProperty('datapath.bridge');
                $this->datapathbridge_cost = $response->getProperty('datapath.bridge-cost');
                $this->datapathbridge_horizon = $response->getProperty('datapath.bridge-horizon');
                $this->datapathlocal_forwarding = (($response->getProperty('datapath.local-forwarding') == 'true') ? true : false);
                $this->datapathvlan_mode = $response->getProperty('datapath.vlan-mode');
                $this->datapathvlan_id = $response->getProperty('datapath.vlan-id');
                $this->channel = $response->getProperty('channel');
                $this->channelfrequency = $response->getProperty('channel.frequency');
                $this->channelwidth = $response->getProperty('channel.width');
                $this->channelband = $response->getProperty('channel.band');
                $this->channelextension_channel = $response->getProperty('channel.extension-channel');
                $this->channeltx_power = $response->getProperty('channel.tx-power');
                $this->master = (($response->getProperty('master') == 'true') ? true : false);
                $this->bound = (($response->getProperty('bound') == 'true') ? true : false);
                $this->inactive = (($response->getProperty('inactive') == 'true') ? true : false);
                $this->running = (($response->getProperty('running') == 'true') ? true : false);
                $this->disabled = (($response->getProperty('disabled') == 'true') ? true : false);
            }
        }
        return;
    }

    public function update($id) {
        $c = new Interfaces();
        $c->get($id);
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/caps-man/interface/set');
        $setRequest->setargument('.id', $id);
        if ($this->name != $c->name) {
            $setRequest->setargument('name', $this->name);
        }
        if ($this->mtu != $c->mtu) {
            $setRequest->setargument('mtu', $this->mtu);
        }
        if ($this->l2mtu != $c->l2mtu) {
            $setRequest->setargument('l2mtu', $this->l2mtu);
        }
        if ($this->mac_address != $c->mac_address) {
            $setRequest->setargument('mac-address', $this->mac_address);
        }
        if ($this->arp != $c->arp) {
            $setRequest->setargument('arp', $this->arp);
        }
        if ($this->radio_mac != $c->radio_mac) {
            $setRequest->setargument('radio-mac', $this->radio_mac);
        }
        if ($this->master_interface != $c->master_interface) {
            $setRequest->setargument('master-interface', $this->master_interface);
        }
        if ($this->configuration != $c->configuration) {
            if ($this->configuration == '') {
                $unset[] = 'configuration';
            } else {
                $setRequest->setargument('configuration', $this->configuration);
            }
        }
        if ($this->configurationmode != $c->configurationmode) {
            if ($this->configurationmode == '') {
                $unset[] = 'configuration.mode';
            } else {
                $setRequest->setargument('configuration.mode', $this->configurationmode);
            }
        }
        if ($this->configurationssid != $c->configurationssid) {
            if ($this->configurationssid == '') {
                $unset[] = 'configuration.ssid';
            } else {
                $setRequest->setargument('configuration.ssid', $this->configurationssid);
            }
        }
        $setRequest->setargument('configuration.hide-ssid', (($this->configurationhide_ssid == true) ? "true" : "false"));
        if ($this->configurationmax_sta_count != $c->configurationmax_sta_count) {
            if ($this->configurationmax_sta_count == '') {
                $unset[] = 'configuration.max-sta-count';
            } else {
                $setRequest->setargument('configuration.max-sta-count', $this->configurationmax_sta_count);
            }
        }
        if ($this->configurationmulticast_helper != $c->configurationmulticast_helper) {
            if ($this->configurationmulticast_helper == '') {
                $unset[] = 'configuration.multicast-helper';
            } else {
                $setRequest->setargument('configuration.multicast-helper', $this->configurationmulticast_helper);
            }
        }
        if ($this->configurationtx_chains != $c->configurationtx_chains) {
            if ($this->configurationtx_chains == '') {
                $unset[] = 'configuration.tx-chains';
            } else {
                $setRequest->setargument('configuration.tx-chains', $this->configurationtx_chains);
            }
        }
        if ($this->configurationrx_chains != $c->configurationrx_chains) {
            if ($this->configurationrx_chains == '') {
                $unset[] = 'configuration.rx-chains';
            } else {
                $setRequest->setargument('configuration.rx-chains', $this->configurationrx_chains);
            }
        }
        if ($this->configurationguard_interval != $c->configurationguard_interval) {
            if ($this->configurationguard_interval == '') {
                $unset[] = 'configuration.guard-interval';
            } else {
                $setRequest->setargument('configuration.guard-interval', $this->configurationguard_interval);
            }
        }
        if ($this->configurationcountry != $c->configurationcountry) {
            if ($this->configurationcountry == '') {
                $unset[] = 'configuration.country';
            } else {
                $setRequest->setargument('configuration.country', $this->configurationcountry);
            }
        }
        if ($this->configurationload_balancing_group != $c->configurationload_balancing_group) {
            if ($this->configurationload_balancing_group == '') {
                $unset[] = 'configuration.load-balancing-group';
            } else {
                $setRequest->setargument('configuration.load-balancing-group', $this->configurationload_balancing_group);
            }
        }
        if ($this->security != $c->security) {
            if ($this->security == '') {
                $unset[] = 'security';
            } else {
                $setRequest->setargument('security', $this->security);
            }
        }
        if ($this->securityauthentication_types != $c->securityauthentication_types) {
            if ($this->securityauthentication_types == '') {
                $unset[] = 'security.authentication-types';
            } else {
                $setRequest->setargument('security.authentication-types', $this->securityauthentication_types);
            }
        }
        if ($this->securityencryption != $c->securityencryption) {
            if ($this->securityencryption == '') {
                $unset[] = 'security.encryption';
            } else {
                $setRequest->setargument('security.encryption', $this->securityencryption);
            }
        }
        if ($this->securitygroup_encryption != $c->securitygroup_encryption) {
            if ($this->securitygroup_encryption == '') {
                $unset[] = 'security.group-encryption';
            } else {
                $setRequest->setargument('security.group-encryption', $this->securitygroup_encryption);
            }
        }
        if ($this->securitypassphrase != $c->securitypassphrase) {
            if ($this->securitypassphrase == '') {
                $unset[] = 'security.passphrase';
            } else {
                $setRequest->setargument('security.passphrase', $this->securitypassphrase);
            }
        }
        if ($this->securityeap_methods != $c->securityeap_methods) {
            if ($this->securityeap_methods == '') {
                $unset[] = 'security.eap-methods';
            } else {
                $setRequest->setargument('security.eap-methods', $this->securityeap_methods);
            }
        }
        if ($this->securitytls_mode != $c->securitytls_mode) {
            $setRequest->setargument('security.tls-mode', $this->securitytls_mode);
        }
        if ($this->securitytls_certificate != $c->securitytls_certificate) {
            if ($this->securitytls_certificate == '') {
                $unset[] = 'security.tls-certificate';
            } else {
                $setRequest->setargument('security.tls-certificate', $this->securitytls_certificate);
            }
        }
        if ($this->datapath != $c->datapath) {
            if ($this->datapath == '') {
                $unset[] = 'datapath';
            } else {
                $setRequest->setargument('datapath', $this->datapath);
            }
        }
        $setRequest->setargument('datapath.client-to-client-forwarding', (($this->datapathclient_to_client_forwarding == true) ? "true" : "false"));
        if ($this->datapathbridge != $c->datapathbridge) {
            if ($this->datapathbridge == '') {
                $unset[] = 'datapath.bridge';
            } else {
                $setRequest->setargument('datapath.bridge', $this->datapathbridge);
            }
        }
        if ($this->datapathbridge_cost != $c->datapathbridge_cost) {
            if ($this->datapathbridge_cost == '') {
                $unset[] = 'datapath.bridge-cost';
            } else {
                $setRequest->setargument('datapath.bridge-cost', $this->datapathbridge_cost);
            }
        }
        if ($this->datapathbridge_horizon != $c->datapathbridge_horizon) {
            if ($this->datapathbridge_horizon == '') {
                $unset[] = 'datapath.bridge-horizon';
            } else {
                $setRequest->setargument('datapath.bridge-horizon', $this->datapathbridge_horizon);
            }
        }
        $setRequest->setargument('datapath.local-forwarding', (($this->datapathlocal_forwarding == true) ? "true" : "false"));
        if ($this->datapathvlan_mode != $c->datapathvlan_mode) {
            if ($this->datapathvlan_mode == '') {
                $unset[] = 'datapath.vlan-mode';
            } else {
                $setRequest->setargument('datapath.vlan-mode', $this->datapathvlan_mode);
            }
        }
        if ($this->datapathvlan_id != $c->datapathvlan_id) {
            if ($this->datapathvlan_id == '') {
                $unset[] = 'datapath.vlan-id';
            } else {
                $setRequest->setargument('datapath.vlan-id', $this->datapathvlan_id);
            }
        }
        if ($this->channel != $c->channel) {
            if ($this->channel == '') {
                $unset[] = 'channel';
            } else {
                $setRequest->setargument('channel', $this->channel);
            }
        }
        if ($this->channelfrequency != $c->channelfrequency) {
            if ($this->channelfrequency == '') {
                $unset[] = 'channel.frequency';
            } else {
                $setRequest->setargument('channel.frequency', $this->channelfrequency);
            }
        }
        if ($this->channelwidth != $c->channelwidth) {
            if ($this->channelwidth == '') {
                $unset[] = 'channel.width';
            } else {
                $setRequest->setargument('channel.width', $this->channelwidth);
            }
        }
        if ($this->channelband != $c->channelband) {
            $setRequest->setargument('channel.band', $this->channelband);
        }
        if ($this->channelextension_channel != $c->channelextension_channel) {
            if ($this->channelextension_channel == '') {
                $unset[] = 'channel.extension-channel';
            } else {
                $setRequest->setargument('channel.extension-channel', $this->channelextension_channel);
            }
        }
        if ($this->channeltx_power != $c->channeltx_power) {
            if ($this->channeltx_power == '') {
                $unset[] = 'channel.tx-power';
            } else {
                $setRequest->setargument('channel.tx-power', $this->channeltx_power);
            }
        }
        $setRequest->setargument('master', (($this->master == true) ? "true" : "false"));
        $setRequest->setargument('bound', (($this->bound == true) ? "true" : "false"));
        $setRequest->setargument('inactive', (($this->inactive == true) ? "true" : "false"));
        if (isset($unset)) {
            $unsetRequest = new RouterOS\Request('/caps-man/interface/unset');
            foreach ($unset as $value) {
                $unsetRequest->setArgument('.id', $id);
                $unsetRequest->setArgument('value-name', $value);
                $resp = $connect->getConnection()->sendSync($unsetRequest);
                if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
                    if (!isset($re)) {
                        $re = '';
                    } $re.= ' ' . $resp->getProperty('message');
                }
            }
        } $resp = $connect->getConnection()->sendSync($setRequest);
        if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
            if (isset($re)) {
                $re.= ' ' . $resp->getProperty('message');
            } else {
                $re = $resp->getProperty('message');
            }
        } if (isset($re)) {
            return $re;
        } else {
            return '1';
        }
    }

    public function disable($id) {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/caps-man/interface/disable');
        $setRequest->setArgument('.id', $id);
        $connect->getConnection()->sendSync($setRequest);
        return;
    }

    public function enable($id) {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/caps-man/interface/enable');
        $setRequest->setArgument('.id', $id);
        $connect->getConnection()->sendSync($setRequest);
        return;
    }

    public function create() {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/caps-man/interface/add');
        if ($this->name != "") {
            $setRequest->setargument('name', $this->name);
        }
        if ($this->mtu != "") {
            $setRequest->setargument('mtu', $this->mtu);
        }
        if ($this->l2mtu != "") {
            $setRequest->setargument('l2mtu', $this->l2mtu);
        }
        if ($this->mac_address != "") {
            $setRequest->setargument('mac-address', $this->mac_address);
        }
        if ($this->arp != "") {
            $setRequest->setargument('arp', $this->arp);
        }
        if ($this->radio_mac != "") {
            $setRequest->setargument('radio-mac', $this->radio_mac);
        }
        if ($this->master_interface != "") {
            $setRequest->setargument('master-interface', $this->master_interface);
        }
        if ($this->configuration != "") {
            $setRequest->setargument('configuration', $this->configuration);
        }
        if ($this->configurationmode != "") {
            $setRequest->setargument('configuration.mode', $this->configurationmode);
        }
        if ($this->configurationssid != "") {
            $setRequest->setargument('configuration.ssid', $this->configurationssid);
        }
        if ($this->configurationhide_ssid != "") {
            $setRequest->setargument('configuration.hide-ssid', (($this->configurationhide_ssid == true) ? "true" : "false"));
        }
        if ($this->configurationmax_sta_count != "") {
            $setRequest->setargument('configuration.max-sta-count', $this->configurationmax_sta_count);
        }
        if ($this->configurationmulticast_helper != "") {
            $setRequest->setargument('configuration.multicast-helper', $this->configurationmulticast_helper);
        }
        if ($this->configurationtx_chains != "") {
            $setRequest->setargument('configuration.tx-chains', $this->configurationtx_chains);
        }
        if ($this->configurationrx_chains != "") {
            $setRequest->setargument('configuration.rx-chains', $this->configurationrx_chains);
        }
        if ($this->configurationguard_interval != "") {
            $setRequest->setargument('configuration.guard-interval', $this->configurationguard_interval);
        }
        if ($this->configurationcountry != "") {
            $setRequest->setargument('configuration.country', $this->configurationcountry);
        }
        if ($this->configurationload_balancing_group != "") {
            $setRequest->setargument('configuration.load-balancing-group', $this->configurationload_balancing_group);
        }
        if ($this->security != "") {
            $setRequest->setargument('security', $this->security);
        }
        if ($this->securityauthentication_types != "") {
            $setRequest->setargument('security.authentication-types', $this->securityauthentication_types);
        }
        if ($this->securityencryption != "") {
            $setRequest->setargument('security.encryption', $this->securityencryption);
        }
        if ($this->securitygroup_encryption != "") {
            $setRequest->setargument('security.group-encryption', $this->securitygroup_encryption);
        }
        if ($this->securitypassphrase != "") {
            $setRequest->setargument('security.passphrase', $this->securitypassphrase);
        }
        if ($this->securityeap_methods != "") {
            $setRequest->setargument('security.eap-methods', $this->securityeap_methods);
        }
        if ($this->securitytls_mode != "") {
            $setRequest->setargument('security.tls-mode', $this->securitytls_mode);
        }
        if ($this->securitytls_certificate != "") {
            $setRequest->setargument('security.tls-certificate', $this->securitytls_certificate);
        }
        if ($this->datapath != "") {
            $setRequest->setargument('datapath', $this->datapath);
        }
        if ($this->datapathclient_to_client_forwarding != "") {
            $setRequest->setargument('datapath.client-to-client-forwarding', (($this->datapathclient_to_client_forwarding == true) ? "true" : "false"));
        }
        if ($this->datapathbridge != "") {
            $setRequest->setargument('datapath.bridge', $this->datapathbridge);
        }
        if ($this->datapathbridge_cost != "") {
            $setRequest->setargument('datapath.bridge-cost', $this->datapathbridge_cost);
        }
        if ($this->datapathbridge_horizon != "") {
            $setRequest->setargument('datapath.bridge-horizon', $this->datapathbridge_horizon);
        }
        if ($this->datapathlocal_forwarding != "") {
            $setRequest->setargument('datapath.local-forwarding', (($this->datapathlocal_forwarding == true) ? "true" : "false"));
        }
        if ($this->datapathvlan_mode != "") {
            $setRequest->setargument('datapath.vlan-mode', $this->datapathvlan_mode);
        }
        if ($this->datapathvlan_id != "") {
            $setRequest->setargument('datapath.vlan-id', $this->datapathvlan_id);
        }
        if ($this->channel != "") {
            $setRequest->setargument('channel', $this->channel);
        }
        if ($this->channelfrequency != "") {
            $setRequest->setargument('channel.frequency', $this->channelfrequency);
        }
        if ($this->channelwidth != "") {
            $setRequest->setargument('channel.width', $this->channelwidth);
        }
        if ($this->channelband != "") {
            $setRequest->setargument('channel.band', $this->channelband);
        }
        if ($this->channelextension_channel != "") {
            $setRequest->setargument('channel.extension-channel', $this->channelextension_channel);
        }
        if ($this->channeltx_power != "") {
            $setRequest->setargument('channel.tx-power', $this->channeltx_power);
        }
        if ($this->master != "") {
            $setRequest->setargument('master', (($this->master == true) ? "true" : "false"));
        }
        if ($this->bound != "") {
            $setRequest->setargument('bound', (($this->bound == true) ? "true" : "false"));
        }
        if ($this->inactive != "") {
            $setRequest->setargument('inactive', (($this->inactive == true) ? "true" : "false"));
        }
        $resp = $connect->getConnection()->sendSync($setRequest);
        if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
            return $resp->getProperty('message');
        } else {
            return '1';
        }
    }

    public function delete($id) {
        $connect = MikrotikConnect::Instance();
        $util = new RouterOS\Util($connect->getConnection());
        $util->setMenu('/caps-man/interface');
        $util->remove(RouterOS\Query::where('.id', $id));
        return;
    }

    public function getChannel() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/channel/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getSecurity() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/security/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getCert() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/certificate/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {

                if ($response->getProperty('private-key') == 'true') {
                    $return[$response->getProperty('name')] = $response->getProperty('name');
                }
            }
        }
        return $return;
    }

    public function getDatapath() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/datapath/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getBridge() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/bridge/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getMaster() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/interface/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getConf() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/configuration/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

}
