summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorColin Smith <colin@pfsense.org>2005-04-28 02:17:49 +0000
committerColin Smith <colin@pfsense.org>2005-04-28 02:17:49 +0000
commit775433e7f3863681f784899f7e6607d3c551e246 (patch)
treef79e396569a96409ede0da61ed5b573f8bb6a880 /etc
parentfc01e4144b3a147fdff47243a97c6727aa06288e (diff)
downloadpfsense-775433e7f3863681f784899f7e6607d3c551e246.zip
pfsense-775433e7f3863681f784899f7e6607d3c551e246.tar.gz
* Document more functions.
* Rework return_filename_as_array. * Use PHP's file instead of reading the file by hand. * Use preg_grep to match only the beginning of the line. * Allow more than one comment "tostrip" character to be defined.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/pfsense-utils.inc60
1 files changed, 35 insertions, 25 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 85e2746..7d3591c 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -52,12 +52,12 @@ function log_error($error) {
* INPUTS
* $dir - string containing the path to the desired directory.
* RESULT
- * $dir_array - array containing the directory's contents. This array will be empty in the event of an array.
+ * $dir_array - array containing the directory's contents. This array will be empty if the path specified is invalid.
******/
function return_dir_as_array($dir) {
$dir_array = array();
if (is_dir($dir)) {
- If ($dh = opendir($dir)) {
+ if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$canadd = 0;
if($file == ".") $canadd = 1;
@@ -71,36 +71,46 @@ function return_dir_as_array($dir) {
return $dir_array;
}
-/*
- * enable_hardware_offloading() enables hardware features of nics if they are supported
- */
+/****f* pfsense-utils/enable_hardware_offloading
+ * NAME
+ * enable_hardware_offloading - Enable a NIC's supported hardware features.
+ * INPUTS
+ * $interface - string containing the physical interface to work on.
+ * RESULT
+ * null
+ * NOTES
+ * This function only supports the fxp driver's loadable microcode.
+ ******/
function enable_hardware_offloading($interface) {
global $config;
global $g;
if($g['booting']) {
- $supported_ints = array('fxp');
- foreach($supported_ints as $int) {
- if(stristr($interface,$int) != false) {
- mwexec("/sbin/ifconfig $interface link0");
- }
- }
+ $supported_ints = array('fxp');
+ foreach($supported_ints as $int) {
+ if(stristr($interface,$int) != false) {
+ mwexec("/sbin/ifconfig $interface link0");
+ }
+ }
}
+ return;
}
-/*
- * return_filename_as_array($filename): returns $filename contents as a string
- */
-function return_filename_as_array($filename) {
- $file = array();
- if(file_exists($filename)) {
- $text = return_filename_as_string($filename);
- $text_split = split("\n", $text);
-
- /* Strip out comments */
- while (($line = array_shift($text_split)) != NULL) {
- if(strpos($line, "#") !== 0)
- array_push($file, $line);
- }
+/****f* pfsense-utils/return_filename_as_array
+ * NAME
+ * return_filename_as_array - Return a file's contents as an array.
+ * INPUTS
+ * $filename - string containing the path to the desired file.
+ * $strip - array of characters to strip - default is '#'.
+ * RESULT
+ * $file - array containing the file's contents.
+ * NOTES
+ * This function strips lines starting with '#' and leading/trailing whitespace by default.
+ ******/
+function return_filename_as_array($filename, $strip = array('#')) {
+ if(file_exists($filename)) $file = file($filename);
+ if(is_array($file)) {
+ foreach($file as $line) $line = trim($line);
+ foreach($strip as $tostrip) $file = preg_grep("/^{$tostrip}/", $file, PREG_GREP_INVERT);
}
return $file;
}
OpenPOWER on IntegriCloud