From The Compiler, 6 Years ago, written in Bash.
Embed
  1. #!/bin/bash
  2. declare -A urls
  3.  
  4. urls['ziproxy']="username:password@localhost:9001"
  5. urls['ssh']='localhost:8123'
  6.  
  7. dwb_command() {
  8.         if [[ "$DWB_FIFO" ]]; then # running inside DWB
  9.                 echo "$@" >> "$DWB_FIFO"
  10.         else
  11.                 dwb -x "$@"
  12.         fi
  13. }
  14.  
  15. error() {
  16.         if [[ "$DWB_FIFO" ]]; then # running inside DWB
  17.                 echo "js window.alert('$@');" >> "$DWB_FIFO"
  18.         else
  19.                 echo "$@"
  20.         fi
  21.         exit 1
  22. }
  23.  
  24. set_proxy() {
  25.         proxy="${urls[$1]}"
  26.         if [[ -z "$proxy" ]]; then
  27.                 error "Proxy $1 is unknown!"
  28.         fi
  29.         dwb -x "local_set proxy true ;; local_set proxy-url $proxy"
  30. }
  31.  
  32. unset_proxy() {
  33.         dwb -x "local_set proxy false ;; local_set proxy-url NULL"
  34. }
  35.  
  36. if [[ "$DWB_FIFO" ]]; then
  37.         # fills $1 with the argument in dwb's command line.
  38.         set -- "$DWB_ARGUMENT" # quotes sic!
  39. fi
  40.  
  41. if (( $# != 1 )); then
  42.         error "Usage: $0 <proxyname>"
  43. fi
  44.  
  45. case $1 in
  46.         "off") unset_proxy ;;
  47.         *) set_proxy "$1" ;;
  48. esac
  49.