mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-20 03:16:12 +00:00
system: reconfigure routes via apply #1774
This commit is contained in:
parent
7e4bcda618
commit
e99ad4b4d0
2
plist
2
plist
@ -621,7 +621,7 @@
|
||||
/usr/local/opnsense/scripts/proxy/generate_cert.php
|
||||
/usr/local/opnsense/scripts/proxy/setup.sh
|
||||
/usr/local/opnsense/scripts/remote_backup.php
|
||||
/usr/local/opnsense/scripts/routes/routes_wrapper
|
||||
/usr/local/opnsense/scripts/routes/gateways.php
|
||||
/usr/local/opnsense/scripts/routes/show_routes.py
|
||||
/usr/local/opnsense/scripts/suricata/__init__.py
|
||||
/usr/local/opnsense/scripts/suricata/dropAlertLog.py
|
||||
|
||||
@ -1,32 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 Deciso B.V.
|
||||
* Copyright (C) 2017 Fabian Franz
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Deciso B.V.
|
||||
* Copyright (C) 2017 Fabian Franz
|
||||
* All rights reserved.
|
||||
*
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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\Routes\Api;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
@ -60,7 +60,6 @@ class RoutesController extends ApiControllerBase
|
||||
if ($uuid != null) {
|
||||
$node = $mdlRoute->getNodeByReference('route.'.$uuid);
|
||||
if ($node != null) {
|
||||
$this->backend_execute_route('delete', $node);
|
||||
$node->setNodes($this->request->getPost('route'));
|
||||
$validations = $mdlRoute->validate($node->__reference, 'route');
|
||||
if (count($validations)) {
|
||||
@ -68,9 +67,6 @@ class RoutesController extends ApiControllerBase
|
||||
} else {
|
||||
// serialize model to config and save
|
||||
$mdlRoute->serializeToConfig();
|
||||
if ((string)$node->disabled != '1') {
|
||||
$this->backend_execute_route('add', $node);
|
||||
}
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'saved';
|
||||
}
|
||||
@ -94,9 +90,6 @@ class RoutesController extends ApiControllerBase
|
||||
// serialize model to config and save
|
||||
$mdlRoute->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
if ((string)$node->disabled != '1') {
|
||||
$this->backend_execute_route('add', $node);
|
||||
}
|
||||
$result['result'] = 'saved';
|
||||
}
|
||||
}
|
||||
@ -131,9 +124,6 @@ class RoutesController extends ApiControllerBase
|
||||
$mdlRoute->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result['result'] = 'deleted';
|
||||
if ((string)$node->disabled != '1') {
|
||||
$this->backend_execute_route('delete', $node);
|
||||
}
|
||||
} else {
|
||||
$result['result'] = 'not found';
|
||||
}
|
||||
@ -152,10 +142,8 @@ class RoutesController extends ApiControllerBase
|
||||
$node->disabled = (string)$disabled;
|
||||
} elseif ($node->disabled->__toString() == '1') {
|
||||
$node->disabled = '0';
|
||||
$this->backend_execute_route('add', $node);
|
||||
} else {
|
||||
$node->disabled = '1';
|
||||
$this->backend_execute_route('delete', $node);
|
||||
}
|
||||
$result['result'] = (string)$node->disabled == '1' ? 'Disabled' : 'Enabled';
|
||||
// if item has toggled, serialize to config and save
|
||||
@ -165,10 +153,24 @@ class RoutesController extends ApiControllerBase
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
private function backend_execute_route($action, $node)
|
||||
|
||||
public function reconfigureAction()
|
||||
{
|
||||
$backend = new Backend();
|
||||
$command = "interface routes $action " . $node->network . ' ' . $node->gateway;
|
||||
$backend->configdRun($command, false);
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
|
||||
$backend = new Backend();
|
||||
$bckresult = trim($backend->configdRun('interface routes configure'));
|
||||
if ($bckresult == 'OK') {
|
||||
$status = 'ok';
|
||||
} else {
|
||||
$status = "error reloading routes ($bckresult)";
|
||||
}
|
||||
|
||||
return array('status' => $status);
|
||||
} else {
|
||||
return array('status' => 'failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,56 @@
|
||||
{#
|
||||
|
||||
Copyright (c) 2017 Fabian Franz
|
||||
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() {
|
||||
|
||||
$("#reconfigureAct").click(function(){
|
||||
$("#reconfigureAct_progress").addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(url="/api/routes/routes/reconfigure", sendData={}, callback=function(data,status) {
|
||||
// when done, disable progress animation.
|
||||
$("#reconfigureAct_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
|
||||
if (status != "success" || data['status'] != 'ok') {
|
||||
BootstrapDialog.show({
|
||||
type: BootstrapDialog.TYPE_WARNING,
|
||||
title: "{{ lang._('Error reconfiguring routes') }}",
|
||||
message: data['status'],
|
||||
draggable: true
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<div class="content-box">
|
||||
<table id="grid-routes" class="table table-responsive" data-editDialog="DialogRoute">
|
||||
<thead>
|
||||
@ -17,13 +70,15 @@
|
||||
<td colspan="5"></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
|
||||
<!-- <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> -->
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div>
|
||||
<p>{{ lang._('Do not enter static routes for networks assigned on any interface of this firewall. Static routes are only used for networks reachable via a different router, and not reachable via your default gateway.')}}</p>
|
||||
<div class="col-md-12">
|
||||
{{ lang._('Do not enter static routes for networks assigned on any interface of this firewall. Static routes are only used for networks reachable via a different router, and not reachable via your default gateway.')}}
|
||||
<hr/>
|
||||
<button class="btn btn-primary" id="reconfigureAct" type="button"><b>{{ lang._('Apply') }}</b> <i id="reconfigureAct_progress" class=""></i></button>
|
||||
<br/><br/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
42
src/opnsense/scripts/routes/gateways.php
Executable file
42
src/opnsense/scripts/routes/gateways.php
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Fabian Franz
|
||||
* 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.
|
||||
*/
|
||||
|
||||
require_once 'config.inc';
|
||||
require_once 'util.inc';
|
||||
require_once 'interfaces.inc';
|
||||
|
||||
$gateways = return_gateways_array(true, true, true);
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($gateways as $gateway) {
|
||||
$ret[$gateway['name']] = "{$gateway['name']} - {$gateway['gateway']}";
|
||||
}
|
||||
|
||||
echo json_encode($ret) . PHP_EOL;
|
||||
@ -1,56 +0,0 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
/*
|
||||
Copyright (C) 2017 Fabian Franz
|
||||
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.
|
||||
*/
|
||||
# require legacy services
|
||||
require_once("config.inc");
|
||||
require_once("util.inc");
|
||||
require_once("interfaces.inc");
|
||||
|
||||
|
||||
function extract_gateway_name($entry) {
|
||||
return $entry['name'];
|
||||
}
|
||||
|
||||
if ($_SERVER['argc'] == 0)
|
||||
die("You should not do that.");
|
||||
|
||||
switch ($_SERVER['argv'][1])
|
||||
{
|
||||
case 'list':
|
||||
$gateways = return_gateways_array(true, true, true);
|
||||
$gateways = array_map(extract_gateway_name, $gateways);
|
||||
print(json_encode($gateways));
|
||||
break;
|
||||
case 'add':
|
||||
case 'delete':
|
||||
$action = escapeshellarg($_SERVER['argv'][1]);
|
||||
$network = escapeshellarg($_SERVER['argv'][2]);
|
||||
$gateway = escapeshellarg(lookup_gateway_ip_by_name($_SERVER['argv'][3]));
|
||||
$version = stristr($network,':') ? '6' : '4';
|
||||
$command = "/sbin/route -$version $action -net $network $gateway";
|
||||
system($command);
|
||||
break;
|
||||
default:
|
||||
print_r($_SERVER);
|
||||
die("you should not do this");
|
||||
}
|
||||
@ -78,24 +78,12 @@ parameters:%s %s
|
||||
type:script_output
|
||||
message:show system routing table
|
||||
|
||||
[routes.add]
|
||||
command:/usr/local/opnsense/scripts/routes/routes_wrapper add
|
||||
parameters:%s %s
|
||||
type:script_output
|
||||
message:add static route %s on %s
|
||||
|
||||
[routes.delete]
|
||||
command:/usr/local/opnsense/scripts/routes/routes_wrapper delete
|
||||
parameters:%s %s
|
||||
type:script_output
|
||||
message:delete static route %s on %s
|
||||
|
||||
[routes.configure]
|
||||
command: /usr/local/etc/rc.routing_configure
|
||||
message: Reconfiguring routing
|
||||
type: script
|
||||
|
||||
[gateways.list]
|
||||
command:/usr/local/opnsense/scripts/routes/routes_wrapper list
|
||||
command:/usr/local/opnsense/scripts/routes/gateways.php
|
||||
type:script_output
|
||||
message:list gateways
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user