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
fc753b5a
Commit
fc753b5a
authored
Apr 06, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add message tracking to configd
parent
8e107684
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
+23
-13
processhandler.py
src/opnsense/service/modules/processhandler.py
+23
-13
No files found.
src/opnsense/service/modules/processhandler.py
View file @
fc753b5a
...
@@ -126,7 +126,6 @@ class HandlerClient(threading.Thread):
...
@@ -126,7 +126,6 @@ class HandlerClient(threading.Thread):
"""
"""
def
__init__
(
self
,
connection
,
client_address
,
action_handler
,
simulation_mode
=
False
):
def
__init__
(
self
,
connection
,
client_address
,
action_handler
,
simulation_mode
=
False
):
"""
"""
:param connection: socket connection object
:param connection: socket connection object
:param client_address: client address ( from socket accept )
:param client_address: client address ( from socket accept )
:param action_handler: action handler object
:param action_handler: action handler object
...
@@ -181,10 +180,10 @@ class HandlerClient(threading.Thread):
...
@@ -181,10 +180,10 @@ class HandlerClient(threading.Thread):
# execute requested action
# execute requested action
if
self
.
simulation_mode
:
if
self
.
simulation_mode
:
self
.
action_handler
.
showAction
(
exec_command
,
exec_action
,
exec_params
)
self
.
action_handler
.
showAction
(
exec_command
,
exec_action
,
exec_params
,
self
.
message_uuid
)
result
=
'OK'
result
=
'OK'
else
:
else
:
result
=
self
.
action_handler
.
execute
(
exec_command
,
exec_action
,
exec_params
)
result
=
self
.
action_handler
.
execute
(
exec_command
,
exec_action
,
exec_params
,
self
.
message_uuid
)
if
not
exec_in_background
:
if
not
exec_in_background
:
# send response back to client( including trailing enter )
# send response back to client( including trailing enter )
...
@@ -285,12 +284,13 @@ class ActionHandler(object):
...
@@ -285,12 +284,13 @@ class ActionHandler(object):
return
action_obj
return
action_obj
def
execute
(
self
,
command
,
action
,
parameters
):
def
execute
(
self
,
command
,
action
,
parameters
,
message_uuid
):
""" execute configuration defined action
""" execute configuration defined action
:param command: command/topic for example interface
:param command: command/topic for example interface
:param action: action to run ( for example linkup )
:param action: action to run ( for example linkup )
:param parameters: the parameters to supply
:param parameters: the parameters to supply
:param message_uuid: message unique id
:return: OK on success, else error code
:return: OK on success, else error code
"""
"""
action_params
=
[]
action_params
=
[]
...
@@ -300,13 +300,17 @@ class ActionHandler(object):
...
@@ -300,13 +300,17 @@ class ActionHandler(object):
if
parameters
is
not
None
and
len
(
parameters
)
>
action_obj
.
getParameterStartPos
():
if
parameters
is
not
None
and
len
(
parameters
)
>
action_obj
.
getParameterStartPos
():
action_params
=
parameters
[
action_obj
.
getParameterStartPos
():]
action_params
=
parameters
[
action_obj
.
getParameterStartPos
():]
return
'
%
s
\n
'
%
action_obj
.
execute
(
action_params
)
return
'
%
s
\n
'
%
action_obj
.
execute
(
action_params
,
message_uuid
)
return
'Action not found
\n
'
return
'Action not found
\n
'
def
showAction
(
self
,
command
,
action
,
parameters
):
def
showAction
(
self
,
command
,
action
,
parameters
,
message_uuid
):
""" debug/simulation mode: show action information
""" debug/simulation mode: show action information
:return:
:param command: command/topic for example interface
:param action: action to run ( for example linkup )
:param parameters: the parameters to supply
:param message_uuid: message unique id
:return: None
"""
"""
action_obj
=
self
.
findAction
(
command
,
action
,
parameters
)
action_obj
=
self
.
findAction
(
command
,
action
,
parameters
)
print
(
'---------------------------------------------------------------------'
)
print
(
'---------------------------------------------------------------------'
)
...
@@ -344,18 +348,21 @@ class Action(object):
...
@@ -344,18 +348,21 @@ class Action(object):
"""
"""
return
self
.
_parameter_start_pos
return
self
.
_parameter_start_pos
def
execute
(
self
,
parameters
):
def
execute
(
self
,
parameters
,
message_uuid
):
""" execute an action
""" execute an action
:param parameters: list of parameters
:param parameters: list of parameters
:param message_uuid: unique message id
:return:
:return:
"""
"""
# send-out syslog message
# send-out syslog message
if
self
.
message
is
not
None
:
if
self
.
message
is
not
None
:
log_message
=
'[
%
s] '
%
message_uuid
if
self
.
message
.
count
(
'
%
s'
)
>
0
and
parameters
is
not
None
and
len
(
parameters
)
>
0
:
if
self
.
message
.
count
(
'
%
s'
)
>
0
and
parameters
is
not
None
and
len
(
parameters
)
>
0
:
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
self
.
message
%
tuple
(
parameters
[
0
:
self
.
message
.
count
(
'
%
s'
)])
)
log_message
=
log_message
+
self
.
message
%
tuple
(
parameters
[
0
:
self
.
message
.
count
(
'
%
s'
)]
)
else
:
else
:
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
self
.
message
)
log_message
=
log_message
+
self
.
message
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
log_message
)
# validate input
# validate input
if
self
.
type
is
None
:
if
self
.
type
is
None
:
...
@@ -387,14 +394,16 @@ class Action(object):
...
@@ -387,14 +394,16 @@ class Action(object):
else
:
else
:
return
'Error (
%
d)'
%
exit_status
return
'Error (
%
d)'
%
exit_status
except
:
except
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'Script action failed at
%
s'
%
traceback
.
format_exc
())
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'[
%
s] Script action failed at
%
s'
%
(
message_uuid
,
traceback
.
format_exc
()))
return
'Execute error'
return
'Execute error'
elif
self
.
type
.
lower
()
==
'script_output'
:
elif
self
.
type
.
lower
()
==
'script_output'
:
try
:
try
:
script_output
=
subprocess
.
check_output
(
script_command
,
shell
=
True
)
script_output
=
subprocess
.
check_output
(
script_command
,
shell
=
True
)
return
script_output
return
script_output
except
:
except
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'Script action failed at
%
s'
%
traceback
.
format_exc
())
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'[
%
s] Script action failed at
%
s'
%
(
message_uuid
,
traceback
.
format_exc
()))
return
'Execute error'
return
'Execute error'
# fallback should never get here
# fallback should never get here
...
@@ -411,7 +420,8 @@ class Action(object):
...
@@ -411,7 +420,8 @@ class Action(object):
return
ph_inline_actions
.
execute
(
self
,
inline_act_parameters
)
return
ph_inline_actions
.
execute
(
self
,
inline_act_parameters
)
except
:
except
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'Inline action failed at
%
s'
%
traceback
.
format_exc
())
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'[
%
s] Inline action failed at
%
s'
%
(
message_uuid
,
traceback
.
format_exc
()))
return
'Execute error'
return
'Execute error'
return
'Unknown action type'
return
'Unknown action type'
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