New Entity AI



dugout-> proxy_env_wn.dugout



Define, start, and stop temporary or full-time system proxies


            
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
###############################################################################
## COPYRIGHT (C) 2020-2026 NEW ENTITY OPERATIONS INC. and Various contributing
## INSTANCE: proxy_env_wn.dugout
## MODIFIED: 2026/04/20
## OVERVIEW: Define, start, and stop temporary or full-time system proxies
##
## program_env_wn sets traditional proxy routines that can be made available to 
## the operator with short-commands to abstract away complex behavior
###############################################################################
## Use: Configure the Proxy methods
## Assign a system proxy with the defined environment variables
###############################################################################
## Generic Values
###############################################################################

## Generic Instance Values Proxy (GIVP)
export PROXYUSER="${CONFIGURATION_PROXYUSER}"
export PROXYPASS="${CONFIGURATION_PROXYPASS}"
export PROXY_SPECIAL_IP="${CONFIGURATION_PROXY_SPECIAL_IP}"
export PROXY_SPECIAL_IP_ADDRESS="${CONFIGURATION_PROXY_SPECIAL_IP_ADDRESS}"
export PROXY_SPECIAL_PORT="${CONFIGURATION_PROXY_SPECIAL_PORT}"

## Generic Instance Values Environment (GIVE)
export PROXY_ENV="http_proxy ftp_proxy https_proxy all_proxy rsync_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY RSYNC_PROXY"
export PROXY_ENV_NONE="no_proxy NO_PROXY"
## defaults
export proxy_value="http://${PROXYUSER}:${PROXYPASS}@${PROXY_SPECIAL_IP}:${PROXY_SPECIAL_PORT}"
export no_proxy_value='localhost,127.0.0.1'

## Generic Instance Values Wrapper (GIVW)
assignProxy(){
 ## If no arguments (IP/PORT) are passed, assign the proxy values individually
 if [ "${1}" = "${proxy_value}" ] && [ "${2}" = "${no_proxy_value}" ]; then
  export PROXY_VALUE="${1}"
  export PROXY_VALUE_NONE="${2}"
 elif [ -z "${1}" ]; then
  alert_proxy_instructions
 ## If no no_proxy_value is provided, use the default
 elif [ -z "$2" ]; then
  alert_proxy_no_proxy_value
  export PROXY_VALUE="${1}"
  export PROXY_VALUE_NONE="${no_proxy_value}"
  alert_proxy_is "${PROXY_VALUE}" "${PROXY_VALUE_NONE}"
 ## If a base PROXY is overloaded, use it for all of the values
 else
  export PROXY_VALUE="${1}"
  export PROXY_VALUE_NONE="${2}"
  alert_proxy_is "${PROXY_VALUE}" "${PROXY_VALUE_NONE}"
 fi
 for i in $PROXY_ENV
 do
  export "${i}"="${PROXY_VALUE}"
  alert_proxy_value "${i}" "${PROXY_VALUE}"
 done
 for i in $PROXY_ENV_NONE
 do
  export "${i}"="${PROXY_VALUE_NONE}"
  alert_proxy_value "${i}" "${PROXY_VALUE_NONE}"
 done
}

## Teardown the assigned Proxy
clrProxy(){
 for PROXY_TYPE in $PROXY_ENV
 do
  unset "${PROXY_VALUE}"
  unset "${PROXY_VALUE_NONE}"
 done
}

## Standard Proxy Bridge: No password, generic local system proxy
## v*NUMBER*Proxy() -> Assign each additional as needed
vStandardProxy(){
 if [ -z "${1}" ]; then
  export user_proxy_vStandardProxy="${USER}"
 else
  export user_proxy_vStandardProxy="${1}"
 fi
 alert_proxy_asign_standard "${PROXY_SPECIAL_IP_ADDRESS}" "${PROXY_SPECIAL_PORT}" "${no_proxy_value}"
 assignProxy "http://${PROXY_SPECIAL_IP_ADDRESS}:${PROXY_SPECIAL_PORT}" "${no_proxy_value}"
}

## v*NUMBER*Proxy() -> Assign each additional as needed, assumes password for a provided or generic
voneProxy(){
 if [ -z "${1}" ]; then
  export user_proxy_voneProxy="${USER}"
 else
  export user_proxy_voneProxy="${1}"
 fi
 stty -echo
 alert_proxy_password
 read password
 stty echo
 alert_proxy_password_masked
 ## If you need a password echo, uncomment this
 #alert_proxy_password_plain "${password}"
 alert_proxy_asign_complex "${user_proxy_voneProxy}" "${PROXY_SPECIAL_IP_ADDRESS}" "${PROXY_SPECIAL_PORT}" "${no_proxy_value}"
 assignProxy "http://${user_proxy_voneProxy}:${password}@${PROXY_SPECIAL_IP_ADDRESS}:${PROXY_SPECIAL_PORT}" "${no_proxy_value}"
}

## Provide a generic overloadable wrapper
vXProxy(){
 if [ -z "${3}" ]; then
  export user_proxy_vXProxy="${PROXYUSER}"
 else
  export user_proxy_vXProxy="${3}"
 fi
 assign_proxy_credentials(){
  if [ -z "${4}" ]; then
   stty -echo
   alert_proxy_password
   read password
   stty echo
   alert_proxy_password_masked
   ## If you need a password echo, uncomment this
   #alert_proxy_password_plain "${password}"
   alert_proxy_asign_simple "${3}" "${1}" "${2}"
   assignProxy "http://${3}:${password}@${1}" "${2}"
  else
   password="${4}"
   ## If you need a password echo, uncomment this
   #alert_proxy_password_plain "${4}"
   alert_proxy_asign_simple "${3}" "${1}" "${2}"
   assignProxy "http://${3}:${4}@${1}" "${2}"
  fi
 }

 if [ -z "${1}" ]; then
  alert_proxy_asign_failure_empty
 elif [ -z "${3}" ]; then
  alert_proxy_no_proxy_value
  proxy_value="${1}"
  proxy_value_default="${no_proxy_value}"
  alert_proxy_asign_simple "${user_proxy_vXProxy}" "${proxy_value}" "${no_proxy_value}"
  assignProxy "${user_proxy_vXProxy}:${PROXYPASS}@${proxy_value}" "${proxy_value_default}"
 else
  proxy_value="${1}"
  no_proxy_value="${2}"
  assign_proxy_credentials "${1}" "${2}" "${3}" "${4}"
 fi
}