Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
d0206619
Commit
d0206619
authored
Nov 14, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mvc) extend JsonKeyValueStoreField to support configd calls for preloading options
parent
cdb0c667
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
3 deletions
+50
-3
JsonKeyValueStoreField.php
...odels/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php
+50
-3
No files found.
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php
View file @
d0206619
...
...
@@ -31,6 +31,7 @@ namespace OPNsense\Base\FieldTypes;
use
Phalcon\Validation\Validator\InclusionIn
;
use
OPNsense\Base\Validators\CsvListValidator
;
use
OPNsense\Core\Backend
;
/**
* Class JsonKeyValueStoreField, use a json encoded file as selection list
...
...
@@ -63,7 +64,6 @@ class JsonKeyValueStoreField extends BaseField
*/
private
$internalOptionList
=
array
();
/**
* @var null source field
*/
...
...
@@ -79,6 +79,16 @@ class JsonKeyValueStoreField extends BaseField
*/
private
$internalSelectAll
=
false
;
/**
* @var string action to send to configd to populate the provided source
*/
private
$internalConfigdPopulateAct
=
""
;
/**
* @var int execute configd command only when file is older then TTL (seconds)
*/
private
$internalConfigdPopulateTTL
=
3600
;
/**
* set descriptive text for empty value
* @param string $value description
...
...
@@ -116,13 +126,50 @@ class JsonKeyValueStoreField extends BaseField
}
}
/**
* @param string $value configd action to run
*/
public
function
setConfigdPopulateAct
(
$value
)
{
$this
->
internalConfigdPopulateAct
=
$value
;
}
/**
* @param string $value set TTL for config action
*/
public
function
setConfigdPopulateTTL
(
$value
)
{
if
(
is_numeric
(
$value
))
{
$this
->
internalConfigdPopulateTTL
=
$value
;
}
}
/**
* populate selection data
*/
protected
function
actionPostLoadingEvent
()
{
if
(
$this
->
internalSourceField
!=
null
&&
$this
->
internalSourceFile
!=
null
)
{
$sourcefile
=
sprintf
(
$this
->
internalSourceFile
,
$this
->
internalSourceField
);
if
(
$this
->
internalSourceFile
!=
null
)
{
if
(
$this
->
internalSourceField
!=
null
)
{
$sourcefile
=
sprintf
(
$this
->
internalSourceFile
,
$this
->
internalSourceField
);
}
else
{
$sourcefile
=
$this
->
internalSourceFile
;
}
if
(
!
empty
(
$this
->
internalConfigdPopulateAct
))
{
// execute configd action when provided
if
(
!
is_file
(
$sourcefile
))
{
$muttime
=
0
;
}
else
{
$stat
=
stat
(
$sourcefile
);
$muttime
=
$stat
[
'mtime'
];
}
if
(
time
()
-
$muttime
>
$this
->
internalConfigdPopulateTTL
)
{
$act
=
$this
->
internalConfigdPopulateAct
;
$backend
=
new
Backend
();
$response
=
$backend
->
configdRun
(
$act
,
false
,
20
);
file_put_contents
(
$sourcefile
,
$response
);
}
}
if
(
is_file
(
$sourcefile
))
{
$data
=
json_decode
(
file_get_contents
(
$sourcefile
),
true
);
if
(
$data
!=
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment