mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 01:39:35 +02:00
ejabberdctl: Improve method to pass command arguments
This commit is contained in:
parent
46a64c0f68
commit
f789495c39
2 changed files with 13 additions and 13 deletions
|
@ -356,7 +356,14 @@ exec_other_command()
|
|||
|
||||
exec_ctl_over_http_socket()
|
||||
{
|
||||
CARGS='{"ctl-command-line": "'${*}'"}'
|
||||
COMMAND=${1}
|
||||
CARGS=""
|
||||
while [ $# -gt 0 ]; do
|
||||
[ -z "$CARGS" ] && CARGS="[" || CARGS="${CARGS}, "
|
||||
CARGS="${CARGS}\"$1\""
|
||||
shift
|
||||
done
|
||||
CARGS="${CARGS}]"
|
||||
TEMPHEADERS=temp-headers.log
|
||||
curl \
|
||||
--unix-socket ${CTL_OVER_HTTP} \
|
||||
|
@ -365,11 +372,11 @@ exec_ctl_over_http_socket()
|
|||
--data "${CARGS}" \
|
||||
--dump-header ${TEMPHEADERS} \
|
||||
--no-progress-meter \
|
||||
"http://localhost/ctl/${1}"
|
||||
"http://localhost/ctl/${COMMAND}"
|
||||
result=$(sed -n 's/.*status-code: \([0-9]*\).*/\1/p' < $TEMPHEADERS)
|
||||
rm ${TEMPHEADERS}
|
||||
case $result in
|
||||
2|3) exec_other_command help ${1};;
|
||||
2|3) exec_other_command help ${COMMAND};;
|
||||
*) :;;
|
||||
esac
|
||||
exit $result
|
||||
|
|
|
@ -121,10 +121,9 @@ code_change(_OldVsn, State, _Extra) ->
|
|||
|
||||
-spec process_http([binary()], tuple()) -> {non_neg_integer(), [{binary(), binary()}], string()}.
|
||||
|
||||
process_http([Call], #request{data = Data} = Request) when is_binary(Call) and is_record(Request, request) ->
|
||||
[{<<"ctl-command-line">>, LineBin}] = extract_args(Data),
|
||||
LineStrings = string:split(binary_to_list(LineBin), " ", all),
|
||||
process_http2(LineStrings, ?DEFAULT_VERSION).
|
||||
process_http([_Call], #request{data = Data, path = [<<"ctl">> | _]}) ->
|
||||
Args = [binary_to_list(E) || E <- misc:json_decode(Data)],
|
||||
process_http2(Args, ?DEFAULT_VERSION).
|
||||
|
||||
process_http2(["--version", Arg | Args], _) ->
|
||||
Version =
|
||||
|
@ -143,12 +142,6 @@ process_http2(Args, Version) ->
|
|||
end,
|
||||
{200, [{<<"status-code">>, integer_to_binary(Code)}], String2}.
|
||||
|
||||
%% Be tolerant to make API more easily usable from command-line pipe.
|
||||
extract_args(<<"\n">>) -> [];
|
||||
extract_args(Data) ->
|
||||
Maps = misc:json_decode(Data),
|
||||
maps:to_list(Maps).
|
||||
|
||||
%%-----------------------------
|
||||
%% Process command line
|
||||
%%-----------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue