mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +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()
|
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
|
TEMPHEADERS=temp-headers.log
|
||||||
curl \
|
curl \
|
||||||
--unix-socket ${CTL_OVER_HTTP} \
|
--unix-socket ${CTL_OVER_HTTP} \
|
||||||
|
@ -365,11 +372,11 @@ exec_ctl_over_http_socket()
|
||||||
--data "${CARGS}" \
|
--data "${CARGS}" \
|
||||||
--dump-header ${TEMPHEADERS} \
|
--dump-header ${TEMPHEADERS} \
|
||||||
--no-progress-meter \
|
--no-progress-meter \
|
||||||
"http://localhost/ctl/${1}"
|
"http://localhost/ctl/${COMMAND}"
|
||||||
result=$(sed -n 's/.*status-code: \([0-9]*\).*/\1/p' < $TEMPHEADERS)
|
result=$(sed -n 's/.*status-code: \([0-9]*\).*/\1/p' < $TEMPHEADERS)
|
||||||
rm ${TEMPHEADERS}
|
rm ${TEMPHEADERS}
|
||||||
case $result in
|
case $result in
|
||||||
2|3) exec_other_command help ${1};;
|
2|3) exec_other_command help ${COMMAND};;
|
||||||
*) :;;
|
*) :;;
|
||||||
esac
|
esac
|
||||||
exit $result
|
exit $result
|
||||||
|
|
|
@ -121,10 +121,9 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
||||||
-spec process_http([binary()], tuple()) -> {non_neg_integer(), [{binary(), binary()}], string()}.
|
-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) ->
|
process_http([_Call], #request{data = Data, path = [<<"ctl">> | _]}) ->
|
||||||
[{<<"ctl-command-line">>, LineBin}] = extract_args(Data),
|
Args = [binary_to_list(E) || E <- misc:json_decode(Data)],
|
||||||
LineStrings = string:split(binary_to_list(LineBin), " ", all),
|
process_http2(Args, ?DEFAULT_VERSION).
|
||||||
process_http2(LineStrings, ?DEFAULT_VERSION).
|
|
||||||
|
|
||||||
process_http2(["--version", Arg | Args], _) ->
|
process_http2(["--version", Arg | Args], _) ->
|
||||||
Version =
|
Version =
|
||||||
|
@ -143,12 +142,6 @@ process_http2(Args, Version) ->
|
||||||
end,
|
end,
|
||||||
{200, [{<<"status-code">>, integer_to_binary(Code)}], String2}.
|
{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
|
%% Process command line
|
||||||
%%-----------------------------
|
%%-----------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue