all: create $confdir if it does not exist
zmapi, cam: refactor, use main() so that bash finds trap_error/trap_clean
This commit is contained in:
parent
858b168b05
commit
5bb1b8cef2
3 changed files with 267 additions and 258 deletions
237
cam
237
cam
|
@ -2,41 +2,43 @@
|
|||
|
||||
shopt -s extglob
|
||||
|
||||
version="1.0.2"
|
||||
version="1.0.3"
|
||||
release="20221001"
|
||||
|
||||
declare -A camera
|
||||
main () {
|
||||
declare -A camera
|
||||
|
||||
username="admin"
|
||||
password=""
|
||||
viewer="display"
|
||||
player="mpv"
|
||||
username="admin"
|
||||
password=""
|
||||
viewer="display"
|
||||
player="mpv"
|
||||
|
||||
confdir="${XDG_CONFIG_HOME:-$HOME/.config}/zmapi"
|
||||
config="cam.conf"
|
||||
confdir="${XDG_CONFIG_HOME:-$HOME/.config}/zmapi"
|
||||
config="cam.conf"
|
||||
|
||||
if [ -f "$confdir/$config" ]; then
|
||||
if [ -f "$confdir/$config" ]; then
|
||||
source "$confdir/$config"
|
||||
else
|
||||
else
|
||||
echo "configuration file ($confdir/$config) missing"
|
||||
echo "new file created, edit it and restart program"
|
||||
mkdir "$confdir"
|
||||
cat <<-EOT > "$confdir/$config"
|
||||
camera=()
|
||||
username=
|
||||
password=
|
||||
viewer=
|
||||
player=
|
||||
EOT
|
||||
EOT
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
auth=$(echo -n "$username:$password"|base64)
|
||||
headers="-H 'Authorization: Basic $auth'"
|
||||
# headers="-H 'Authorization: Basic $auth' -H 'Cookie: juanipcam_lang=en; login=${username}%2C${password}; sync_time=true; usr=$username; pwd=$password'"
|
||||
auth=$(echo -n "$username:$password"|base64)
|
||||
headers="-H 'Authorization: Basic $auth'"
|
||||
# headers="-H 'Authorization: Basic $auth' -H 'Cookie: juanipcam_lang=en; login=${username}%2C${password}; sync_time=true; usr=$username; pwd=$password'"
|
||||
|
||||
camlst=$(echo -n "${!camera[@]}"|tr ' ' '|')
|
||||
camlst=$(echo -n "${!camera[@]}"|tr ' ' '|')
|
||||
|
||||
declare -A SDK=(
|
||||
declare -A SDK=(
|
||||
[audio_encode]=/NetSDK/Audio/encode/channel/101
|
||||
[audio_input]=/NetSDK/Audio/input/channel/1
|
||||
[image]=/NetSDK/Image
|
||||
|
@ -89,39 +91,106 @@ declare -A SDK=(
|
|||
[view_sub]="/ch0_1.264"
|
||||
[snapshot]=/snapshot
|
||||
[user_list]="/user/user_list.xml?username=$username&password=$password"
|
||||
)
|
||||
)
|
||||
|
||||
declare -A audio_encode=(e enabled:b i audioInputChannelID:i c codecType:s)
|
||||
declare -A audio_input=(w workMode:s m microphoneType:s:auto,activePickup,passiveMic r sampleRate:i w sampleBitWidth:i i inputVolume:i o outputVolume:i)
|
||||
declare -A image_ircut=(c irCutControlMode:s:hardware,software m irCutMode:s:auto,daylight,night)
|
||||
declare -A image_denoise3d=(e enabled:b s denoise3dStrength:i)
|
||||
declare -A image_sharpness=(e enabled:b -s sharpnessLevel:i)
|
||||
declare -A image_wdr=(e enabled:b -s WDRStrength:i)
|
||||
declare -A image=(s imageStyle:i:1,2,3 l lowlightMode:s:close,day-night,only-night,auto c sceneMode:s:auto,indoor,outdoor e exposureMode:s:auto,bright,dark a awbMode:s:auto,indoor,outdoor b BLcompensationMode:s)
|
||||
declare -A image_videomode=(s imageStyle:i:1,2,3 l lowlightMode:s:close,day-night,only-night,auto c sceneMode:s:auto,indoor,outdoor e exposureMode:s:auto,bright,dark a awbMode:s:auto,indoor,outdoor b BLcompensationMode:s)
|
||||
declare -A network_dns=(p preferredDns:s a staticAlternateDns:s)
|
||||
declare -A network_esee=(e enabled:b)
|
||||
declare -A network_lan1=(v ipVersion:s i staticIP:s n staticNetmask:s g staticGateway:s t addressingType:s o OnvifAutoAdapt:b d dhcp:b)
|
||||
declare -A network_lan4=(v ipVersion:s i staticIP:s n staticNetmask:s g staticGateway:s t addressingType:s o OnvifAutoAdapt:b d dhcp:b)
|
||||
declare -A network_wifi=(m wirelessMode:s s stationMode.wirelessStaMode:s b stationMode.wirelessApBssId:s a stationMode.wirelessApEssId:s p stationMode.wirelessApPsk:s)
|
||||
declare -A network_port=(n portname:s p value:i)
|
||||
declare -A reboot=()
|
||||
declare -A time_ntp=(e enabled:b s ntpServerDomain:s)
|
||||
declare -A time_zone=()
|
||||
declare -A time=()
|
||||
declare -A vencode_main=(e enabled:b r resolution:s c codecType:s b constantBitrate:i f frameRate:i t bitRateControlType:s p h264Profile:s k keyFrameInterval:i n channelName:s F freeResolution:b )
|
||||
declare -A vencode_sub=(e enabled:b r resolution:s c codecType:s b constantBitrate:i f frameRate:i t bitRateControlType:s p h264Profile:s k keyFrameInterval:i n channelName:s F freeResolution:b )
|
||||
declare -A video_timeoverlay=(e enabled:b x regionX:i y regionY:i d dateFormat:s t timeFormat:i w displayWeek:b c displayChinese:b)
|
||||
declare -A video_channeloverlay=(e enabled:b x regionX:i y regionY:i)
|
||||
declare -A video_extraoverlay=(e expandChannelNameOverlay[0].enabled:b t expandChannelNameOverlay[0].expandChannelName:s)
|
||||
declare -A video_input=(e enabled:b l powerLineFrequencyMode:i:50,60,100,120 b brightnessLevel:i:0-100 c contrastLevel:i:0-100 s sharpnessLevel:i:0-100 a saturationLevel:i:0-100 h hueLevel:i:0-100 f flipEnabled:b m mirrorEnabled:b p privacyMask)
|
||||
declare -A video_flip=()
|
||||
declare -A video_mirror=()
|
||||
declare -A video_brightness=()
|
||||
declare -A video_contrast=()
|
||||
declare -A video_saturation=()
|
||||
declare -A video_hue=()
|
||||
declare -A video_sharpness=()
|
||||
declare -A audio_encode=(e enabled:b i audioInputChannelID:i c codecType:s)
|
||||
declare -A audio_input=(w workMode:s m microphoneType:s:auto,activePickup,passiveMic r sampleRate:i w sampleBitWidth:i i inputVolume:i o outputVolume:i)
|
||||
declare -A image_ircut=(c irCutControlMode:s:hardware,software m irCutMode:s:auto,daylight,night)
|
||||
declare -A image_denoise3d=(e enabled:b s denoise3dStrength:i)
|
||||
declare -A image_sharpness=(e enabled:b -s sharpnessLevel:i)
|
||||
declare -A image_wdr=(e enabled:b -s WDRStrength:i)
|
||||
declare -A image=(s imageStyle:i:1,2,3 l lowlightMode:s:close,day-night,only-night,auto c sceneMode:s:auto,indoor,outdoor e exposureMode:s:auto,bright,dark a awbMode:s:auto,indoor,outdoor b BLcompensationMode:s)
|
||||
declare -A image_videomode=(s imageStyle:i:1,2,3 l lowlightMode:s:close,day-night,only-night,auto c sceneMode:s:auto,indoor,outdoor e exposureMode:s:auto,bright,dark a awbMode:s:auto,indoor,outdoor b BLcompensationMode:s)
|
||||
declare -A network_dns=(p preferredDns:s a staticAlternateDns:s)
|
||||
declare -A network_esee=(e enabled:b)
|
||||
declare -A network_lan1=(v ipVersion:s i staticIP:s n staticNetmask:s g staticGateway:s t addressingType:s o OnvifAutoAdapt:b d dhcp:b)
|
||||
declare -A network_lan4=(v ipVersion:s i staticIP:s n staticNetmask:s g staticGateway:s t addressingType:s o OnvifAutoAdapt:b d dhcp:b)
|
||||
declare -A network_wifi=(m wirelessMode:s s stationMode.wirelessStaMode:s b stationMode.wirelessApBssId:s a stationMode.wirelessApEssId:s p stationMode.wirelessApPsk:s)
|
||||
declare -A network_port=(n portname:s p value:i)
|
||||
declare -A reboot=()
|
||||
declare -A time_ntp=(e enabled:b s ntpServerDomain:s)
|
||||
declare -A time_zone=()
|
||||
declare -A time=()
|
||||
declare -A vencode_main=(e enabled:b r resolution:s c codecType:s b constantBitrate:i f frameRate:i t bitRateControlType:s p h264Profile:s k keyFrameInterval:i n channelName:s F freeResolution:b )
|
||||
declare -A vencode_sub=(e enabled:b r resolution:s c codecType:s b constantBitrate:i f frameRate:i t bitRateControlType:s p h264Profile:s k keyFrameInterval:i n channelName:s F freeResolution:b )
|
||||
declare -A video_timeoverlay=(e enabled:b x regionX:i y regionY:i d dateFormat:s t timeFormat:i w displayWeek:b c displayChinese:b)
|
||||
declare -A video_channeloverlay=(e enabled:b x regionX:i y regionY:i)
|
||||
declare -A video_extraoverlay=(e expandChannelNameOverlay[0].enabled:b t expandChannelNameOverlay[0].expandChannelName:s)
|
||||
declare -A video_input=(e enabled:b l powerLineFrequencyMode:i:50,60,100,120 b brightnessLevel:i:0-100 c contrastLevel:i:0-100 s sharpnessLevel:i:0-100 a saturationLevel:i:0-100 h hueLevel:i:0-100 f flipEnabled:b m mirrorEnabled:b p privacyMask)
|
||||
declare -A video_flip=()
|
||||
declare -A video_mirror=()
|
||||
declare -A video_brightness=()
|
||||
declare -A video_contrast=()
|
||||
declare -A video_saturation=()
|
||||
declare -A video_hue=()
|
||||
declare -A video_sharpness=()
|
||||
|
||||
if is_ip "$1"; then
|
||||
cam=$(cam_for_ip "$1")
|
||||
parameters=( "$@" )
|
||||
parameters[0]=$cam
|
||||
set -- "${parameters[@]}"
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
|
||||
@($camlst))
|
||||
cam_s=$1
|
||||
cam_f=$1
|
||||
shift
|
||||
;;
|
||||
all)
|
||||
cam_s=1
|
||||
cam_f=8
|
||||
shift
|
||||
;;
|
||||
help)
|
||||
help
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
exit_with_error "camera number, IP address or 'all' missing"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -z $1 ]]; then
|
||||
help
|
||||
else
|
||||
command="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if ! test ${SDK[$command]+_}; then
|
||||
printf "unknown command $command\n\n"
|
||||
help
|
||||
fi
|
||||
|
||||
for cam in $(seq "$cam_s" "$cam_f");do
|
||||
case "$command" in
|
||||
load)
|
||||
get_json "$cam" "$command" ".CPU.Usage"
|
||||
;;
|
||||
health|config|log)
|
||||
get_text "$cam"
|
||||
;;
|
||||
reboot)
|
||||
put_json "$cam" "$command" '{true}'
|
||||
;;
|
||||
snapshot)
|
||||
view "$cam" "$command"
|
||||
;;
|
||||
view_main|view_sub)
|
||||
watch "$cam" "$command"
|
||||
;;
|
||||
help)
|
||||
help
|
||||
;;
|
||||
*)
|
||||
config "$cam" "$command" "$@"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
is_json () {
|
||||
jq -e . >/dev/null 2>&1 <<<"$@"
|
||||
|
@ -468,76 +537,10 @@ exit_with_error () {
|
|||
exit 1
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
# ---------------------------------------------------
|
||||
|
||||
if is_ip "$1"; then
|
||||
cam=$(cam_for_ip "$1")
|
||||
parameters=( "$@" )
|
||||
parameters[0]=$cam
|
||||
set -- "${parameters[@]}"
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
|
||||
@($camlst))
|
||||
cam_s=$1
|
||||
cam_f=$1
|
||||
shift
|
||||
;;
|
||||
all)
|
||||
cam_s=1
|
||||
cam_f=8
|
||||
shift
|
||||
;;
|
||||
help)
|
||||
help
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
exit_with_error "camera number, IP address or 'all' missing"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -z $1 ]]; then
|
||||
help
|
||||
else
|
||||
command="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if ! test ${SDK[$command]+_}; then
|
||||
printf "unknown command $command\n\n"
|
||||
help
|
||||
fi
|
||||
|
||||
for cam in $(seq "$cam_s" "$cam_f");do
|
||||
case "$command" in
|
||||
load)
|
||||
get_json "$cam" "$command" ".CPU.Usage"
|
||||
;;
|
||||
health|config|log)
|
||||
get_text "$cam"
|
||||
;;
|
||||
reboot)
|
||||
put_json "$cam" "$command" '{true}'
|
||||
;;
|
||||
snapshot)
|
||||
view "$cam" "$command"
|
||||
;;
|
||||
view_main|view_sub)
|
||||
watch "$cam" "$command"
|
||||
;;
|
||||
help)
|
||||
help
|
||||
;;
|
||||
*)
|
||||
config "$cam" "$command" "$@"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
exit
|
||||
|
||||
# based on strings pulled from firmware dump, these represent api endpoints
|
||||
# used with GET or PUT requests as defined in NK_N1Device_InitV2()
|
||||
#
|
||||
|
|
3
camwatch
3
camwatch
|
@ -16,11 +16,12 @@ if [ -f "$confdir/$config" ]; then
|
|||
else
|
||||
echo "configuration file ($confdir/$config) missing"
|
||||
echo "new file created, edit it and restart program"
|
||||
mkdir -p "$confdir"
|
||||
cat <<-EOT > "$confdir/$config"
|
||||
monitors=()
|
||||
threshold=3
|
||||
mon_stat_store="$confdir/mon_stat_store"
|
||||
EOT
|
||||
EOT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
95
zmapi
95
zmapi
|
@ -4,21 +4,22 @@ trap "trap_error" TERM
|
|||
trap "trap_clean" EXIT
|
||||
export TOP_PID=$$
|
||||
|
||||
version="1.1.2"
|
||||
version="1.1.3"
|
||||
release="20221001"
|
||||
|
||||
username=""
|
||||
password=""
|
||||
server=""
|
||||
main () {
|
||||
username=""
|
||||
password=""
|
||||
server=""
|
||||
|
||||
confdir="${XDG_CONFIG_HOME:-$HOME/.config}/zmapi"
|
||||
config="zmapi.conf"
|
||||
access_token="access.json"
|
||||
refresh_token="refresh.json"
|
||||
opt_netrc="--netrc-optional"
|
||||
netrc=""
|
||||
confdir="${XDG_CONFIG_HOME:-$HOME/.config}/zmapi"
|
||||
config="zmapi.conf"
|
||||
access_token="access.json"
|
||||
refresh_token="refresh.json"
|
||||
opt_netrc="--netrc-optional"
|
||||
netrc=""
|
||||
|
||||
if [ -f "$confdir/$config" ]; then
|
||||
if [ -f "$confdir/$config" ]; then
|
||||
source "$confdir/$config"
|
||||
if [ -n "$proxy_username" -a -n "$proxy_password" ]; then
|
||||
machine="${server##http*://}"
|
||||
|
@ -27,10 +28,11 @@ if [ -f "$confdir/$config" ]; then
|
|||
echo "machine $machine login $proxy_username password $proxy_password" > "$netrc"
|
||||
opt_netrc="--netrc-file $netrc"
|
||||
fi
|
||||
else
|
||||
else
|
||||
echo "configuration file ($confdir/$config) missing"
|
||||
echo "new file created, edit it and restart program"
|
||||
echo <<-EOT > "$confdir/$config"
|
||||
mkdir -p "$confdir"
|
||||
cat <<-EOT > "$confdir/$config"
|
||||
# ZoneMinder username, password and server:
|
||||
username=
|
||||
password=
|
||||
|
@ -38,11 +40,11 @@ else
|
|||
# Reverse proxy credentials:
|
||||
# proxy_username=
|
||||
# proxy_password=
|
||||
EOT
|
||||
EOT
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
declare -A API=(
|
||||
declare -A API=(
|
||||
[monitors]='monitors.json|G'
|
||||
[sourcetypes]='monitors/sourceTypes.json|G'
|
||||
[monitor]='monitors/${1}.json|G'
|
||||
|
@ -64,7 +66,37 @@ declare -A API=(
|
|||
[storage]='storage.json|G'
|
||||
[servers]='servers.json|G'
|
||||
[configs]='configs.json|G'
|
||||
)
|
||||
)
|
||||
|
||||
token=$(get_token)
|
||||
|
||||
cmd="$1"
|
||||
shift
|
||||
|
||||
if [ -z "$cmd" -o "$cmd" == "help" ]; then
|
||||
help
|
||||
exit
|
||||
fi
|
||||
|
||||
if ! test ${API[$cmd]+_}; then
|
||||
printf "zmapi: unknown command '$cmd'\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
method=$(echo "${API[$cmd]}"|cut -d '|' -f 2)
|
||||
|
||||
case "$method" in
|
||||
G)
|
||||
get "$cmd" "$token" "$@"
|
||||
;;
|
||||
P)
|
||||
post "$cmd" "$token" "$@"
|
||||
;;
|
||||
*)
|
||||
printf "unknown method $method for command $1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
get () {
|
||||
cmd="$1"
|
||||
|
@ -234,31 +266,4 @@ EOF
|
|||
exit
|
||||
}
|
||||
|
||||
token=$(get_token)
|
||||
|
||||
cmd="$1"
|
||||
shift
|
||||
|
||||
if [ -z "$cmd" -o "$cmd" == "help" ]; then
|
||||
help
|
||||
exit
|
||||
fi
|
||||
|
||||
if ! test ${API[$cmd]+_}; then
|
||||
printf "zmapi: unknown command '$cmd'\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
method=$(echo "${API[$cmd]}"|cut -d '|' -f 2)
|
||||
|
||||
case "$method" in
|
||||
G)
|
||||
get "$cmd" "$token" "$@"
|
||||
;;
|
||||
P)
|
||||
post "$cmd" "$token" "$@"
|
||||
;;
|
||||
*)
|
||||
printf "unknown method $method for command $1"
|
||||
;;
|
||||
esac
|
||||
main "$@"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue