|
发表于 2022-8-1 11:43:13
|
显示全部楼层
有俩个问题
一是脚本中缺少login操作
而是没有处理好json中的转义字符
现在已修正,修正后的脚本如下,API文档也已经同步修改
- #!/bin/sh
- host=$1
- username=$2
- password=$3
- which jq 2>&1 >/dev/null || {
- echo please install jq
- exit 1
- }
- ret="$(curl -k http://$host/rpc -d "{"jsonrpc":"3.0","method":"challenge","params":{"username":"${username}"},"id":1}" 2>/dev/null|jq -c)"
- salt="$(echo $ret|awk -F "salt" '{print $2}'|cut -d '"' -f 3)"
- nonce="$(echo $ret|awk -F "nonce" '{print $2}'|cut -d '"' -f 3)"
- alg="$(echo $ret|awk -F "alg" '{print $2}'|awk -F ":|," '{print $2}')"
- pw=$(openssl passwd -$alg -salt "$salt" "$password")
- hash=$(echo -n "$username:$pw:$nonce" | md5sum | cut -d' ' -f1)
- ret="$(curl -k http://$host/rpc -d "{"jsonrpc":"2.0","method":"login","params":{"username":"${username}","hash":"${hash}"},"id":1}" 2>/dev/null)"
- echo $ret
复制代码
|
|