Skip to content

Commit

Permalink
Update with pfre changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonertari committed Jun 4, 2020
1 parent 7ed9283 commit 9242933
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 41 deletions.
10 changes: 4 additions & 6 deletions src/Controller/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ function IsDgSubCat($str)
* @param array $commands Available commands for the current model
* @param array $argv Argument vector
* @param string $cmd Method name, key to $commands
* @param int $actual Given arg count
* @param int $expected Expected arg count
* @param int $acceptable Acceptable arg count
* @param int $check Arg count used while validating
* @param int $actual Given arg count [out]
* @param int $expected Expected arg count [out]
* @param int $acceptable Acceptable arg count [out]
* @param int $check Arg count used while validating [out]
*/
function ComputeArgCounts($commands, $argv, $cmd, &$actual, &$expected, &$acceptable, &$check)
{
Expand Down Expand Up @@ -527,8 +527,6 @@ function ValidateArgs($commands, $command, $argv, $check)
*/
function ExpandArgs(&$ArgV, &$Locale, &$View, &$Command)
{
global $ModelFiles;

$valid= FALSE;

// Arg 0 contains all of the args as a json encoded string
Expand Down
3 changes: 3 additions & 0 deletions src/Model/lib/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function split()
* Generates anchor rule.
*
* Inline rules are always appended to the end.
*
* @return string String rule.
*/
function generate()
{
Expand Down Expand Up @@ -176,6 +178,7 @@ function genInline()
*
* @param string $str List of rule definitions in an array.
* @param bool $force If set, continues checking and validating even if there are errors or $MaxAnchorNesting is reached.
* @return bool TRUE if $str has inline anchor.
*/
function IsInlineAnchor($str, $force= FALSE)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Model/lib/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ function parseSourceHash()
}
}

/**
* Generates rule.
*
* The output of this function is returned to the View on the command line,
* so we return the generated rule string.
*
* @return string String rule.
*/
function generate()
{
$this->genAction();
Expand Down
18 changes: 9 additions & 9 deletions src/Model/lib/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ function validate($ruleArray, $force= FALSE)
* If a key in typedef is marked as 'require', it should exist in the rule array, otherwise is an error.
*
* @param array $arr Rule array.
* @param array $key Key to search in both rule array and typedef.
* @param string $key Key to search in both rule array and typedef.
* @param array $def Validation definition.
* @param array $parent If the value is an array within another array, this param represents the key of the parent array. Used in error reporting.
* @param string $parent If the value is an array within another array, this param represents the key of the parent array. Used in error reporting.
* @param bool $force Parameter to pass to validation function.
* @return bool TRUE if validated, FALSE if not.
*/
Expand Down Expand Up @@ -300,9 +300,9 @@ function validateKeyDef(&$arr, $key, $def, $parent, $force= FALSE)
* the rule element does not have 'multi' or 'values'.
*
* @param array $arr Rule array.
* @param array $key Key to search in both rule array and typedef.
* @param string $key Key to search in both rule array and typedef.
* @param array $def Validation definition.
* @param array $parent If the value is an array within another array, this param represents the key of the parent array. Used in error reporting.
* @param string $parent If the value is an array within another array, this param represents the key of the parent array. Used in error reporting.
* @param bool $force Parameter to pass to validation function.
* @return bool TRUE if validated, FALSE if not.
*/
Expand Down Expand Up @@ -350,10 +350,10 @@ function validateArrayValues(&$arr, $key, $def, $parent, $force= FALSE)
*
* Validation method should be defined as a regex or a function. Otherwise is an error.
*
* @param array $arr Rule array.
* @param array $key Key to search in both rule array and typedef.
* @param string $key Key to search in both rule array and typedef.
* @param mixed $value Value to validate, array or string.
* @param array $def Validation definition.
* @param array $parent If the value is an array within another array, this param represents the key of the parent array. Used in error reporting.
* @param string $parent If the value is an array within another array, this param represents the key of the parent array. Used in error reporting.
* @param bool $force Parameter to pass to validation function.
* @return bool TRUE if validated, FALSE if not.
*/
Expand Down Expand Up @@ -799,7 +799,7 @@ function genKey($key)
* Caller may supply a leading and/or a trailing string to print.
*
* @param string $key Key to print the value of.
* @param string $head Optional leading string.
* @param string $head Optional leading string, may be NULL.
* @param string $tail Optional trailing string.
*/
function genValue($key, $head= '', $tail= '')
Expand Down Expand Up @@ -829,7 +829,7 @@ function genItems($key, $head= '', $delimPre= '{', $delimPost= '}')
/**
* Prints the given values in delimiters.
*
* @param array $items Values to print.
* @param mixed $items Values to print, array or string.
* @param string $head Optional leading string.
* @param string $delimPre Opening delimiter.
* @param string $delimPost Closing delimiter.
Expand Down
4 changes: 4 additions & 0 deletions src/Model/lib/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class RuleSet
*
* @param array $rulesArray List of rule definitions in an array.
* @param bool $force Used to override validation or other types of errors, hence forces loading of rules.
* @return bool Load result.
*/
function load($rulesArray, $force= FALSE)
{
Expand Down Expand Up @@ -117,6 +118,7 @@ function deleteRules()
*
* @param string $text Rule set in string format to parse.
* @param bool $force Used to override validation or other types of errors, hence forces loading of rules.
* @return bool Validation result.
*/
function parse($text, $force= FALSE)
{
Expand Down Expand Up @@ -263,6 +265,7 @@ function parse($text, $force= FALSE)
* method validates the rules in the ruleset.
*
* @param bool $force Used to override validation or other types of errors, hence forces loading of rules.
* @return bool Validation result.
*/
function validate($force= FALSE)
{
Expand Down Expand Up @@ -356,6 +359,7 @@ function parseInlineRules($ruleLines, &$str, &$index, $force= FALSE)
* The default on the Display page is to print line numbers in front of each line.
*
* @param bool $printNumbers Print line numbers.
* @return string Generated rules.
*/
function generate($printNumbers= FALSE)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Model/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function SetLogLevel($level)
/**
* Enables or disables help boxes.
*
* @param bool $bool TRUE to enable, FALSE otherwise.
* @param string $bool 'TRUE' to enable, 'FALSE' otherwise.
* @return bool TRUE on success, FALSE on fail.
*/
function SetHelpBox($bool)
Expand Down Expand Up @@ -668,7 +668,7 @@ function SetDefaultLocale($locale)
/**
* Enables or disables HTTPs.
*
* @param bool $bool TRUE to enable, FALSE to disable HTTPs.
* @param string $bool 'TRUE' to enable, 'FALSE' otherwise.
* @return bool TRUE on success, FALSE on fail.
*/
function SetForceHTTPs($bool)
Expand All @@ -682,7 +682,7 @@ function SetForceHTTPs($bool)
/**
* Enables or disables SSH.
*
* @param bool $bool TRUE to enable, FALSE otherwise.
* @param string $bool 'TRUE' to enable, 'FALSE' otherwise.
* @return bool TRUE on success, FALSE on fail.
*/
function SetUseSSH($bool)
Expand Down Expand Up @@ -861,7 +861,7 @@ function PutFile($file, $contents)
*
* @param string $file Config file.
* @param string $name Name of NVP.
* @param mixed $newvalue New value to set.
* @param string $newvalue New value to set.
* @return bool TRUE on success, FALSE on fail.
*/
function SetNVP($file, $name, $newvalue)
Expand Down Expand Up @@ -899,7 +899,7 @@ function SetNVP($file, $name, $newvalue)
* @param string $name Name of NVP.
* @param int $set There may be multiple parentheses in $re, which one to return.
* @param string $trimchars Chars to trim in the results.
* @return mixed Value of NVP or NULL on failure.
* @return mixed Value of NVP or FALSE on failure.
*/
function GetNVP($file, $name, $set= 0, $trimchars= '')
{
Expand Down
8 changes: 4 additions & 4 deletions src/Model/pf.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ function GetPfRules($file, $tmp= FALSE, $force= FALSE)
*
* @todo Should we return success or fail status, instead of TRUE?
*
* @return string List of rule files.
* @return bool TRUE on success, FALSE on fail.
*/
function GetPfRuleFiles()
{
Expand Down Expand Up @@ -740,7 +740,7 @@ function InstallPfRules($json, $file= NULL, $load= TRUE, $force= FALSE)
*
* Strips the file path, because we work with files under $PF_CONFIG_PATH only.
*
* @param string $file File name to validate.
* @param string $file File name to validate [out].
* @return bool TRUE on success, FALSE on fail.
*/
function ValidateFilename(&$file)
Expand All @@ -761,7 +761,7 @@ function ValidateFilename(&$file)
* @param string $json JSON encoded rule array.
* @param int $ruleNumber Rule number.
* @param bool $force Used to override validation or other types of errors, hence forces loading of rules.
* @return string Generated rule.
* @return bool TRUE on success, FALSE on fail.
*/
function GeneratePfRule($json, $ruleNumber, $force= FALSE)
{
Expand All @@ -786,7 +786,7 @@ function GeneratePfRule($json, $ruleNumber, $force= FALSE)
* @param string $json JSON encoded rules array.
* @param bool $lines Whether to print line numbers in front of each line.
* @param bool $force Used to override validation or other types of errors, hence forces loading of rules.
* @return string Generated rules.
* @return bool TRUE on success, FALSE on fail.
*/
function GeneratePfRules($json, $lines= FALSE, $force= FALSE)
{
Expand Down
2 changes: 1 addition & 1 deletion src/View/lib/libwui.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function PrintHelpBox($msg= '', $width= 300)
* @warning $Width type should be string, because some functions use 'auto'.
*
* @param string $msg Message to display.
* @param int $width Box width, defaults to auto.
* @param mixed $width Box width, defaults to auto.
* @param string $type Image type to display.
*/
function PrintHelpWindow($msg, $width= 'auto', $type= 'INFO')
Expand Down
7 changes: 3 additions & 4 deletions src/View/pf/conf.write.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

require_once ('pf.php');

$printNumbers= TRUE;
$printNumbers= 1;
if (count($_POST) && !filter_has_var(INPUT_POST, 'numbers')) {
$printNumbers= FALSE;
$printNumbers= 0;
}

$testResult= $View->Controller($Output, 'TestPfRules', json_encode($View->RuleSet->rules));
Expand All @@ -45,8 +45,7 @@

$StrRules= array();
if ($testResult || $force) {
/// @todo Check why we cannot pass FALSE as numbers param
$generated= $View->Controller($StrRules, 'GeneratePfRules', json_encode($View->RuleSet->rules), $printNumbers ? 1 : 0, $force);
$generated= $View->Controller($StrRules, 'GeneratePfRules', json_encode($View->RuleSet->rules), $printNumbers, $force);
}

require_once($VIEW_PATH.'/header.php');
Expand Down
21 changes: 11 additions & 10 deletions src/View/pf/lib/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ function inputDelEmpty($flatten= TRUE)
*
* @param array $array Array to delete empty values from.
* @param bool $flatten Whether to flatten arrays with single values.
* @return array Converted array.
*/
function inputDelEmptyRecursive($array, $flatten)
{
Expand Down Expand Up @@ -683,7 +684,7 @@ function editCheckbox($key, $title)
* @param string $key Id and name of the checkbox.
* @param string $title Title for the key.
* @param string $help Anchor in the html file for the pf.conf(5) man page.
* @param int $size Size of the input.
* @param mixed $size Size of the input, int or NULL.
* @param string $hint Hint text.
*/
function editText($key, $title, $help= NULL, $size= 0, $hint= '')
Expand Down Expand Up @@ -715,7 +716,7 @@ function editText($key, $title, $help= NULL, $size= 0, $hint= '')
* @param string $addName Id of input box.
* @param string $hint Hint text.
* @param string $help Anchor in the html file for the pf.conf(5) man page.
* @param int $size Size of the input.
* @param mixed $size Size of the input, int or NULL.
* @param bool $disabled Condition to disable the input
*/
function editValues($key, $title, $delName, $addName, $hint, $help= NULL, $size= 0, $disabled= FALSE)
Expand Down Expand Up @@ -867,9 +868,9 @@ function editComment()
* Followed by add input box.
*
* @param mixed $value Value for delete link, array or string.
* @param string $name Get input var name, usually with a del prefix
* @param string $prefix Prefix to print
* @param string $postfix Postfix to print
* @param string $name Get input var name, usually with a del prefix.
* @param string $prefix Prefix to print.
* @param string $postfix Postfix to print.
*/
function editDeleteValueLinks($value, $name, $prefix= '', $postfix= '')
{
Expand Down Expand Up @@ -904,11 +905,11 @@ function editDeleteValueLinks($value, $name, $prefix= '', $postfix= '')
* Used for multi-value fields in rules.
*
* @param string $id Id of the input
* @param string $label Label
* @param string $hint Hint text
* @param string $value Value instead of hint
* @param int $size Size of the input
* @param bool $disabled Condition to disable the input
* @param mixed $label Label, string or NULL.
* @param string $hint Hint text.
* @param string $value Value instead of hint.
* @param mixed $size Size of the input, int or NULL.
* @param bool $disabled Condition to disable the input.
*/
function editAddValueBox($id, $label, $hint, $size= 0, $disabled= FALSE)
{
Expand Down
7 changes: 5 additions & 2 deletions src/View/pf/lib/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ function computeNewRuleNumber($ruleNumber= 0)
* Returns the number of a new rule to be appended to the end of the ruleset.
*
* This is simply the count of the rules in the ruleset, because the list is zero-based.
*
* @return int New rule number.
*/
function nextRuleNumber()
{
Expand Down Expand Up @@ -337,7 +339,7 @@ function setupEditSession($cat, &$action, &$ruleNumber)
* TRUE for $assoc param, to convert objects to arrays.
*
* @param int $ruleNumber The number of the rule to test.
* @param object $ruleObj The rule object to test.
* @param \View\Rule $ruleObj The rule object to test.
* @return bool Test result returned from the Model.
*/
function test($ruleNumber, $ruleObj)
Expand Down Expand Up @@ -437,7 +439,8 @@ function isModified($ruleNumber, $ruleObj)
*
* @return array List of queues.
*/
function getQueueNames() {
function getQueueNames()
{
$queues= array();
foreach ($this->rules as $ruleObj) {
if ($ruleObj->cat == 'Queue') {
Expand Down

0 comments on commit 9242933

Please sign in to comment.