Commit 817fbb60 authored by Ad Schellevis's avatar Ad Schellevis

(netflow) work in progress api and ui components

parent 8c35f297
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Diagnostics\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Diagnostics\Netflow;
use \OPNsense\Core\Config;
/**
* Class NetflowController
* @package OPNsense\Netflow
*/
class NetflowController extends ApiControllerBase
{
/**
* retrieve Netflow settings
* @return array
*/
public function getconfigAction()
{
$result = array();
if ($this->request->isGet()) {
$mdlNetflow = new Netflow();
$result['netflow'] = $mdlNetflow->getNodes();
}
return $result;
}
/**
* update netflow configuration fields
* @return array
* @throws \Phalcon\Validation\Exception
*/
public function setconfigAction()
{
$result = array("result"=>"failed");
if ($this->request->hasPost("netflow")) {
// load model and update with provided data
$mdlNetflow = new Netflow();
$mdlNetflow->setNodes($this->request->getPost("netflow"));
// perform validation
$validations = $mdlNetflow->validate();
if (count($validations)) {
$result['validations'] = array();
foreach ($validations as $valkey => $validation) {
$result['validations']['netflow.'.$valkey] = $validation;
}
} else {
// serialize model to config and save
$mdlNetflow->serializeToConfig();
Config::getInstance()->save();
$result["result"] = "saved";
}
}
return $result;
}
}
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Diagnostics;
use OPNsense\Base\IndexController;
/**
* Class NetflowController
* @package OPNsense\Diagnostics
*/
class NetflowController extends IndexController
{
public function indexAction()
{
$this->view->title = "Netflow";
$this->view->pick('OPNsense/Diagnostics/netflow');
$this->view->captureForm = $this->getForm("netflow_capture");
}
}
<form>
<field>
<id>netflow.capture.interfaces</id>
<label>Interfaces</label>
<type>select_multiple</type>
<style>tokenize</style>
<help><![CDATA[Select interface(s) to enable netflow on.]]></help>
<hint>Type or select interface.</hint>
</field>
<field>
<id>netflow.capture.version</id>
<label>Version</label>
<type>dropdown</type>
<help><![CDATA[Select netflow version to use.]]></help>
</field>
<field>
<id>netflow.capture.targets</id>
<label>Destinations</label>
<type>select_multiple</type>
<style>tokenize</style>
<help><![CDATA[Select destinations to send netflow data to (ip address:port, eg 192.168.0.1:2550).]]></help>
<hint>Type or select destinations.</hint>
<allownew>true</allownew>
</field>
</form>
\ No newline at end of file
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Diagnostics;
use OPNsense\Base\BaseModel;
/**
* Class Netflow
* @package OPNsense\Netflow
*/
class Netflow extends BaseModel
{
}
<model>
<mount>//OPNsense/Netflow</mount>
<description>
OPNsense Netflow
</description>
<items>
<capture>
<interfaces type="InterfaceField">
<Required>N</Required>
<default></default>
<multiple>Y</multiple>
<filters>
<enable>/^(?!0).*$/</enable>
</filters>
</interfaces>
<version type="OptionField">
<Required>Y</Required>
<default>5</default>
<OptionValues>
<v5>v5</v5>
<v9>v9</v9>
</OptionValues>
</version>
<targets type="CSVListField">
<Required>N</Required>
<mask>/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):(6553[0-5]|655[0-2][0-9]|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})([,]){0,1})*/u</mask>
<ValidationMessage>Please enter valid targets (e.g. 192.168.0.1:2055)</ValidationMessage>
</targets>
</capture>
</items>
</model>
{#
OPNsense® is Copyright © 2016 by Deciso B.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
#}
<script type="text/javascript">
$( document ).ready(function() {
var data_get_map = {'frm_CaptureSettings':"/api/diagnostics/netflow/getconfig"};
mapDataToFormUI(data_get_map).done(function(data){
// place actions to run after load, for example update form styles.
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
// link save button to API set action
$("#btn_save_capture").click(function(){
saveFormToEndpoint(url="/api/diagnostics/netflow/setconfig",formid='frm_CaptureSettings',callback_ok=function(){
});
});
});
</script>
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#capture">{{ lang._('Capture') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="capture" class="tab-pane fade in active">
<!-- tab page capture -->
{{ partial("layout_partials/base_form",['fields':captureForm,'id':'frm_CaptureSettings', 'apply_btn_id':'btn_save_capture'])}}
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment