You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.5 KiB

  1. #!/bin/sh
  2. . /usr/share/libubox/jshn.sh
  3. . /lib/functions.sh
  4. log() {
  5. local msg="$1"
  6. logger -t ubnt-manager -s "$msg"
  7. }
  8. rexec() {
  9. local target="$1"
  10. local username="$2"
  11. local password="$3"
  12. local cmd="$4"
  13. raw=$(DROPBEAR_PASSWORD="$password" ssh -y $username@$target "$cmd" 2>/dev/null)
  14. ssh_result=$?
  15. }
  16. get_json_dump() {
  17. local cmd="/usr/www/status.cgi"
  18. rexec $* "$cmd"
  19. echo $raw
  20. }
  21. handle_device() {
  22. local device="${1//-/_}" # replace "-" with "_"
  23. config_load ubnt-manager
  24. config_get target "$device" target
  25. config_get username "$device" username
  26. config_get password "$device" password
  27. ssh_result=0
  28. }
  29. add_device_to_list() {
  30. local device="$1"
  31. device_list="$device_list $device"
  32. }
  33. list_devices() {
  34. device_list=""
  35. config_load ubnt-manager
  36. config_foreach add_device_to_list device device_list
  37. echo $device_list
  38. }
  39. usage() {
  40. cat <<EOF
  41. usage: ubnt-manager [command]
  42. -j | --json Dump json info
  43. -t | --target Target device
  44. -l | --list-devices List all devices
  45. -h | --help Brings up this menu
  46. EOF
  47. }
  48. while [ "$1" != "" ]; do
  49. case $1 in
  50. -t | --target)
  51. shift
  52. target=$1
  53. handle_device $target
  54. ;;
  55. -j | --json)
  56. json=1
  57. ;;
  58. -l | --list-devices)
  59. list_devices
  60. ;;
  61. -h | --help)
  62. usage
  63. ;;
  64. esac
  65. shift
  66. done
  67. if [ ! -z $json ]; then
  68. get_json_dump $target $username $password | sed 's/Content-Type:\ application\/json//'
  69. fi