-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
softflowd package cleanup, add privileges settings #309
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fc1fff6
Clean up descriptions, set required fields, split PHP code to softflo…
doktornotor 2fe7021
Split PHP code to softflowd.inc, improve input validations, clean up
doktornotor 4a0fd65
Add new file - split PHP code to softflowd.inc
doktornotor 79f2832
Split PHP code to softflowd.inc, add privileges settings
doktornotor 63f2a26
Add privileges settings
doktornotor 88e0d4a
Add privileges settings to softflowd
doktornotor 0cd58ec
Add enable/disable toggle to softflowd
doktornotor 61dfea7
Add enable/disable toggle to softflowd
doktornotor a8e2648
Rename so that is_service_enabled() works properly
doktornotor 60ab105
Use "off" for disabled service value
doktornotor 2bac4c4
Rename so that is_service_enabled() works properly
doktornotor 5a00e2d
Move conf_mount_rw() call
doktornotor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
net-mgmt/pfSense-pkg-softflowd/files/etc/inc/priv/softflowd.priv.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/* | ||
* softflowd.priv.inc | ||
* | ||
* part of pfSense (https://www.pfsense.org) | ||
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate) | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
global $priv_list; | ||
|
||
$priv_list['page-services-softflowd'] = array(); | ||
$priv_list['page-services-softflowd']['name'] = "WebCfg - Services: softflowd package"; | ||
$priv_list['page-services-softflowd']['descr'] = "Allow access to softflowd package GUI"; | ||
$priv_list['page-services-softflowd']['match'] = array(); | ||
|
||
$priv_list['page-services-softflowd']['match'][] = "pkg.php?xml=softflowd.xml*"; | ||
$priv_list['page-services-softflowd']['match'][] = "pkg_edit.php?xml=softflowd.xml*"; | ||
|
||
?> |
163 changes: 163 additions & 0 deletions
163
net-mgmt/pfSense-pkg-softflowd/files/usr/local/pkg/softflowd.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?php | ||
/* | ||
* softflowd.inc | ||
* | ||
* part of pfSense (https://www.pfsense.org) | ||
* Copyright (c) 2013-2017 Rubicon Communications, LLC (Netgate) | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
require_once("config.inc"); | ||
require_once("globals.inc"); | ||
require_once("interfaces.inc"); | ||
require_once("service-utils.inc"); | ||
require_once("util.inc"); | ||
|
||
function sync_package_softflowd() { | ||
global $config; | ||
|
||
if (is_array($config['installedpackages']['softflowd']['config'][0])) { | ||
$cf = $config['installedpackages']['softflowd']['config'][0]; | ||
} else { | ||
$cf = array(); | ||
} | ||
$interface_list = explode(",", $cf['interface']); | ||
if (!empty($cf['host']) && !empty($interface_list) && $cf['enable'] != "off") { | ||
conf_mount_rw(); | ||
$cf['host'] = is_ipaddrv6($cf['host']) ? "[{$cf['host']}]" : $cf['host']; | ||
$start = "/usr/bin/killall -9 softflowd"; | ||
foreach ($interface_list as $interface_friendly) { | ||
if (empty($interface_friendly)) { | ||
continue; | ||
} | ||
$interface = get_real_interface($interface_friendly); | ||
if (empty($interface)) { | ||
continue; | ||
} | ||
$start .= "\n\t/usr/local/sbin/softflowd "; | ||
$start .= " -i " . escapeshellarg($interface); | ||
$start .= " -n " . escapeshellarg("{$cf['host']}:{$cf['port']}"); | ||
if (is_numericint($cf['maxflows'])) { | ||
$start .= " -m " . escapeshellarg($cf['maxflows']); | ||
} | ||
if (is_numericint($cf['hoplimit'])) { | ||
$start .= " -L " . escapeshellarg($cf['hoplimit']); | ||
} | ||
if ($cf['version'] != "") { | ||
$start .= " -v " . escapeshellarg($cf['version']); | ||
} | ||
if ($cf['flowtracking'] != "") { | ||
$start .= " -T " . escapeshellarg($cf['flowtracking']); | ||
} | ||
if (is_numericint($cf['timeout-general'])) { | ||
$start .= " -t " . escapeshellarg("general={$cf['timeout-general']}"); | ||
} | ||
if (is_numericint($cf['timeout-maxlife'])) { | ||
$start .= " -t " . escapeshellarg("maxlife={$cf['timeout-maxlife']}"); | ||
} | ||
if (is_numericint($cf['timeout-expint'])) { | ||
$start .= " -t " . escapeshellarg("expint={$cf['timeout-expint']}"); | ||
} | ||
if (is_numericint($cf['timeout-tcp'])) { | ||
$start .= " -t " . escapeshellarg("tcp={$cf['timeout-tcp']}"); | ||
} | ||
if (is_numericint($cf['timeout-tcp-rst'])) { | ||
$start .= " -t " . escapeshellarg("tcp.rst={$cf['timeout-tcp-rst']}"); | ||
} | ||
if (is_numericint($cf['timeout-tcp-fin'])) { | ||
$start .= " -t " . escapeshellarg("tcp.fin={$cf['timeout-tcp-fin']}"); | ||
} | ||
if (is_numericint($cf['timeout-udp'])) { | ||
$start .= " -t " . escapeshellarg("udp={$cf['timeout-udp']}"); | ||
} | ||
$start .= " -p " . escapeshellarg("/var/run/softflowd.{$interface}.pid"); | ||
$start .= " -c " . escapeshellarg("/var/run/softflowd.{$interface}.ctl"); | ||
} | ||
write_rcfile(array( | ||
"file" => "softflowd.sh", | ||
"start" => $start, | ||
"stop" => "/usr/bin/killall -9 softflowd" | ||
) | ||
); | ||
/* Only try to restart if not booting */ | ||
if (!platform_booting()) { | ||
if (is_service_running("softflowd")) { | ||
restart_service("softflowd"); | ||
} else { | ||
start_service("softflowd"); | ||
} | ||
} | ||
} else { | ||
conf_mount_rw(); | ||
stop_service("softflowd"); | ||
unlink_if_exists("/usr/local/etc/rc.d/softflowd.sh"); | ||
} | ||
conf_mount_ro(); | ||
} | ||
|
||
function validate_form_softflowd($post, &$input_errors) { | ||
if (!is_ipaddr($post['host'])) { | ||
$input_errors[] = "You must specify a valid ip address in the 'Host' field"; | ||
} | ||
if (!is_port($post['port'])) { | ||
$input_errors[] = "You must specify a valid port number in the 'Port' field"; | ||
} | ||
if (!in_array($post['version'], array(1, 5, 9))) { | ||
$input_errors[] = 'You must specify a netflow version'; | ||
} | ||
if (!in_array($post['flowtracking'], array("full", "proto", "ip"))) { | ||
$input_errors[] = 'You must specify a valid flow tracking selection'; | ||
} | ||
if (!empty($post['hoplimit']) && (!is_numericint($post['hoplimit']) || ($post['hoplimit'] < 1) || ($post['hoplimit'] > 255))) { | ||
$input_errors[] = 'You must specify a valid hop limit'; | ||
} | ||
if (!empty($post['timeout-general']) && !is_numericint($post['timeout-general'])) { | ||
$input_errors[] = 'You must specify a valid General Timeout'; | ||
} | ||
if (!empty($post['timeout-maxlife']) && !is_numericint($post['timeout-maxlife'])) { | ||
$input_errors[] = 'You must specify a valid Maximum Lifetime Timeout'; | ||
} | ||
if (!empty($post['timeout-expint']) && !is_numericint($post['timeout-expint'])) { | ||
$input_errors[] = 'You must specify a valid Expire Interval'; | ||
} | ||
if (!empty($post['timeout-tcp']) && !is_numericint($post['timeout-tcp'])) { | ||
$input_errors[] = 'You must specify a valid TCP Timeout'; | ||
} | ||
if (!empty($post['timeout-tcp-rst']) && !is_numericint($post['timeout-tcp-rst'])) { | ||
$input_errors[] = 'You must specify a valid TCP RST Timeout'; | ||
} | ||
if (!empty($post['timeout-tcp-fin']) && !is_numericint($post['timeout-tcp-fin'])) { | ||
$input_errors[] = 'You must specify a valid TCP FIN Timeout'; | ||
} | ||
if (!empty($post['timeout-udp']) && !is_numericint($post['timeout-udp'])) { | ||
$input_errors[] = 'You must specify a valid UDP Timeout'; | ||
} | ||
} | ||
|
||
function cleanup_config_softflowd() { | ||
global $a_pkg; | ||
$pffconf = array(); | ||
if (is_array($a_pkg)) { | ||
foreach($a_pkg as $cf) { | ||
if ($cf['host'] != "") { | ||
$pffconf = $cf; | ||
} | ||
} | ||
} | ||
$a_pkg = array(); | ||
$a_pkg[0] = $pffconf; | ||
} | ||
|
||
?> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of call conf_mount_rw() inside if and else statements, just move it to a single call outside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved. The thing is completely no-op, why's it even still being used...