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
e4cd84cb
Commit
e4cd84cb
authored
Jun 08, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(configd) make client tool more verbose and add -m option to execute multiple commands at once.
parent
9e04b808
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
20 deletions
+61
-20
configd_ctl.py
src/opnsense/service/configd_ctl.py
+61
-20
No files found.
src/opnsense/service/configd_ctl.py
View file @
e4cd84cb
...
...
@@ -34,23 +34,30 @@
"""
import
socket
import
os.path
import
traceback
import
syslog
import
sys
__author__
=
'Ad Schellevis'
configd_socket_name
=
'/var/run/configd.socket'
# set a timeout to the socket
socket
.
setdefaulttimeout
(
120
)
if
len
(
sys
.
argv
)
<=
1
:
print
'usage :
%
s <command>'
%
sys
.
argv
[
0
]
sys
.
exit
(
0
)
else
:
for
exec_command
in
sys
.
argv
[
1
:]:
def
exec_config_cmd
(
exec_command
)
:
""" execute command using configd socket
:param exec_command: command string
:return: string
"""
# Create and open unix domain socket
try
:
sock
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
sock
.
connect
(
configd_socket_name
)
except
socket
.
error
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'unable to connect to configd socket (@
%
s)'
%
configd_socket_name
)
print
(
'unable to connect to configd socket (@
%
s)'
%
configd_socket_name
)
return
None
try
:
sock
.
send
(
exec_command
)
data
=
""
...
...
@@ -63,6 +70,40 @@ else:
if
data
.
find
(
"
%
c
%
c
%
c"
%
(
chr
(
0
),
chr
(
0
),
chr
(
0
)))
>
-
1
:
break
print
(
data
[:
-
3
])
return
(
data
[:
-
3
])
except
:
print
(
'error in configd communication
%
s, see syslog for details'
)
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'error in configd communication
\n
%
s'
%
traceback
.
format_exc
())
finally
:
sock
.
close
()
# set a timeout to the socket
socket
.
setdefaulttimeout
(
120
)
# validate parameters
if
len
(
sys
.
argv
)
<=
1
:
print
(
'usage :
%
s [-m] <command>'
%
sys
.
argv
[
0
])
sys
.
exit
(
0
)
# check if configd socket exists
if
not
os
.
path
.
exists
(
configd_socket_name
):
print
(
'configd socket missing (@
%
s)'
%
configd_socket_name
)
sys
.
exit
(
-
1
)
if
sys
.
argv
[
1
]
==
'-m'
:
# execute multiple commands at once ( -m "action1 param .." "action2 param .." )
for
exec_command
in
sys
.
argv
[
2
:]:
result
=
exec_config_cmd
(
exec_command
=
exec_command
)
if
result
is
None
:
sys
.
exit
(
-
1
)
print
(
'
%
s'
%
(
result
))
else
:
# execute single command sequence
exec_command
=
' '
.
join
(
sys
.
argv
[
1
:])
result
=
exec_config_cmd
(
exec_command
=
exec_command
)
if
result
is
None
:
sys
.
exit
(
-
1
)
print
(
'
%
s'
%
(
result
))
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