.bash_profile 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # ============================== DATAD / DATADD ==============================
  2. # [DATAD] Quick source shortcuts for NetScaler data scripts | Usage: datad / datadd / ddd | Example: datad
  3. alias ddd="source /home/CITRITE/manjeshn/manscript/datad.sh"
  4. alias datad="source /home/CITRITE/manjeshn/manscript/datad.sh"
  5. alias datadd="source /home/CITRITE/manjeshn/manscript/datadd.sh"
  6. # ============================== CONFETCH TOOLING =============================
  7. # [CONFETCH] Wrapper + viewers for config fetch tooling | Usage: conFetch / show / showd | Example: conFetch <args>
  8. alias show="python /home/CITRITE/manjeshn/manscript/show.py"
  9. alias showd="python /home/CITRITE/manjeshn/manscript/showd.py"
  10. alias conFetch="python /home/CITRITE/manjeshn/manscript/conFetch_Wrapper.py"
  11. # ============================== BIGCAP ==============================
  12. # [BIGCAP] Run bigcap helper script (packet/capture helper) | Usage: bigcap <args> | Example: bigcap -h
  13. alias bigcap="python /home/CITRITE/manjeshn/manscript/bigcap.py"
  14. # ============================== DISPOSABLE TOYS (dT) ==============================
  15. # [DT] Run disposableToys dt utility | Usage: dt <args> | Example: dt --help
  16. alias dt="python /home/CITRITE/manjeshn/manscript/disposableToys/Project_dT/dt.py"
  17. # ============================== PARV TSHOOT STYLE ==============================
  18. # [LS OVERRIDE] List files in long + reverse + all + human readable | Usage: ls <path> | Example: ls /var/log
  19. alias ls="ls -lrha"
  20. # ============================== ALLNEWNSLOG ==============================
  21. # [ALLNEWNSLOG] Iterate collector*/var/nslog/newnslog* and run nsconmsg | Usage: allnewnslog <duration> | Example: allnewnslog 300
  22. alias allnewnslog='function _allnewnslog() { base_dir="$(pwd | sed '\''s|\(.*collector[^/]*\)/.*|\1|'\'')"; find "$base_dir/var/nslog/" -maxdepth 1 -type d -name "newnslog*" -print0 | while IFS= read -r -d "" i; do echo -e "\033[1;33m------------------------ $i ------------------------\033[0m"; nsconmsg -K "$i" -d "$1" -s disptime=1; done; }; _allnewnslog'
  23. # ============================== DIRECTORY SHORTCUTS ==============================
  24. # [CD SHORTCUTS] Faster directory traversal | Usage: .. / ... / .2 etc | Example: ... (go up 2 levels)
  25. alias ..="cd .."
  26. alias ...="cd ../../"
  27. alias ....="cd ../../../"
  28. alias .....="cd ../../.././"
  29. alias .1="cd .."
  30. alias .2="cd ../../"
  31. alias .3="cd ../../../"
  32. alias .4="cd ../../../../"
  33. # ============================== HISTORY / CLEAR ==============================
  34. # [HISTORY] Quick shell history shortcuts | Usage: h / gh <pattern> | Example: gh nslog
  35. alias h='history'
  36. alias gh="history | grep "
  37. alias c="clear"
  38. # ============================== COLORIZED GREP / LESS ==============================
  39. # [GREP COLOR] Case-insensitive grep with persistent color | Usage: zzgrep <pattern> <file> | Example: zzgrep error ns.log
  40. alias zzgrep='grep -i --color=always'
  41. # [LESS COLOR] View ANSI-colored output safely in less | Usage: <cmd> | zzless | Example: cat out.txt | zzless
  42. alias zzless='less -R'
  43. # ============================== CSV COLUMN COUNTER ==============================
  44. # [COUNTCOL] Print column index and first row values from CSV | Usage: countcol < file.csv | Example: head -1 a.csv | countcol
  45. alias countcol="awk -F, '{for(i=1;i<=NF;i++) { print i, \$i } exit}'"
  46. # ============================== FASTFIND FUNCTION ==============================
  47. # [FASTFIND] Case-insensitive filename search under current dir | Usage: fastfind <token> | Example: fastfind nslog
  48. fastfind () {
  49. find . -iname "*$1*" 2>/dev/null
  50. }
  51. # [LASTOOL] LAS Your Netscaler VPX
  52. alias lastool="python /home/CITRITE/pashwani/NSTools/las_tool.py"
  53. #[Grafana View]
  54. alias grafanaview='ns 2ts -tprof var/nslog/newnslog* ; ns 2ts -conlb var/nslog/newnslog*'
  55. # =============== APPENDED SECTION: PCAP SSLKEYS INJECTOR ===============
  56. # [PCAP TLS INJECTOR] Inject TLS secrets into captures using editcap | Usage: pcap-inject <ssl_keys> <pcap> [out.pcapng] | Example: pcap-inject sslkeys.log in.pcap out.pcapng
  57. # [PCAP-SSL] Convenience alias for editcap TLS secret injection mode | Usage: pcap-ssl ... | Example: pcap-ssl "tls,sslkeys.log" in.pcap out.pcapng
  58. alias pcap-ssl='editcap --inject-secrets tls'
  59. # [PCAP-INJECT] Safe wrapper: validates inputs + prevents overwrite + creates .pcapng | Usage: pcap-inject <ssl_keys_file> <input_pcap> [output_pcapng] | Example: pcap-inject keys.log trace.pcap
  60. pcap-inject() {
  61. if [ $# -ne 2 ] && [ $# -ne 3 ]; then
  62. echo "Usage: pcap-inject <ssl_keys_file> <input_pcap> [output_pcapng]"
  63. echo "If output_pcapng is omitted, uses input name with .pcapng extension"
  64. return 1
  65. fi
  66. local ssl_keys="$1"
  67. local input_pcap="$2"
  68. local output_pcapng="${3:-}"
  69. # [VALIDATION] Ensure SSL keys + PCAP exist before running editcap | Usage: automatic | Example: missing file => error
  70. if [ ! -f "$ssl_keys" ]; then
  71. echo -e "\033[31m? ERROR: SSL keys file not found: $ssl_keys\033[0m"
  72. return 1
  73. fi
  74. if [ ! -f "$input_pcap" ]; then
  75. echo -e "\033[31m? ERROR: Input PCAP not found: $input_pcap\033[0m"
  76. return 1
  77. fi
  78. # [OUTPUT NAME] Default output is input basename + .pcapng | Usage: omit 3rd arg | Example: foo.pcap => foo.pcapng
  79. if [ -z "$output_pcapng" ]; then
  80. if [[ "$input_pcap" == *.* ]]; then
  81. output_pcapng="${input_pcap%.*}.pcapng"
  82. else
  83. output_pcapng="${input_pcap}.pcapng"
  84. fi
  85. fi
  86. # [OVERWRITE GUARD] Prompt if output exists to avoid clobbering | Usage: automatic | Example: choose 'n' to abort
  87. if [ -f "$output_pcapng" ]; then
  88. read -rp "$(echo -e "\033[33m?? Output file '$output_pcapng' exists. Overwrite? (y/n) \033[0m")" confirm
  89. if [[ ! "$confirm" =~ [yY] ]]; then
  90. echo -e "\033[33mAborted by user\033[0m"
  91. return 1
  92. fi
  93. fi
  94. # [EXECUTION] Inject secrets and write output (pcap/pcapng supported) | Usage: automatic | Example: editcap --inject-secrets "tls,keys.log" in.pcap out.pcapng
  95. editcap --inject-secrets "tls,$ssl_keys" "$input_pcap" "$output_pcapng"
  96. # [RESULT] Print success/failure + basic output metadata | Usage: automatic | Example: shows size on success
  97. if [ $? -eq 0 ]; then
  98. echo -e "\n\033[32m? SUCCESS: Created $output_pcapng\033[0m"
  99. echo " Input PCAP: $input_pcap"
  100. echo " SSL Keys: $ssl_keys"
  101. echo " Output Size: $(du -h "$output_pcapng" 2>/dev/null | awk '{print $1}')"
  102. else
  103. echo -e "\n\033[31m? FAILED: editcap returned error status\033[0m"
  104. echo " Command: editcap --inject-secrets tls,$ssl_keys $input_pcap $output_pcapng"
  105. return 1
  106. fi
  107. }
  108. # ============================== PCAP-INJECT AUTO-COMPLETION ==============================
  109. # [AUTOCOMPLETE] Tab-complete keys/pcap/output args for pcap-inject | Usage: type 'pcap-inject <TAB>' | Example: pcap-inject ssl<TAB>
  110. _pcap-inject-completion() {
  111. local cur prev
  112. COMPREPLY=()
  113. cur="${COMP_WORDS[COMP_CWORD]}"
  114. prev="${COMP_WORDS[COMP_CWORD-1]}"
  115. case $COMP_CWORD in
  116. 1) # [COMPLETE ARG1] SSL keys file completion | Matches: *.sslkeys/*.keys/*.log | Example: keys<TAB>
  117. COMPREPLY=( $(compgen -f -X '!*@(sslkeys|keys|log)' -- "$cur") )
  118. ;;
  119. 2) # [COMPLETE ARG2] Input capture completion | Matches: *.pcap/*.cap/*.pcapng/*.trace | Example: in.p<TAB>
  120. COMPREPLY=( $(compgen -f -X '!*@(pcap|cap|pcapng|trace)' -- "$cur") )
  121. ;;
  122. 3) # [COMPLETE ARG3] Output file completion | Any filename | Example: out.pcapng<TAB>
  123. COMPREPLY=( $(compgen -f -- "$cur") )
  124. ;;
  125. esac
  126. }
  127. # [SHELL OPT] Enable extended glob needed for the completion filters | Usage: automatic | Example: older shells ignore safely
  128. shopt -s extglob 2>/dev/null
  129. # [REGISTER] Bind completion function to pcap-inject | Usage: automatic | Example: completion works in bash
  130. complete -F _pcap-inject-completion pcap-inject 2>/dev/null
  131. # [LOAD BANNER] Friendly message showing injector loaded | Usage: automatic on shell load | Example: appears on new terminal
  132. echo -e "\033[36m>> PCAP TLS Injector loaded. Use 'pcap-inject' <<\033[0m"
  133. # ============================== AUTO-UPDATE BASH_PROFILE ==============================
  134. # [AUTO-UPDATE] Pull the latest .bash_profile from git | Usage: automatic on shell load
  135. _auto_update_profile() {
  136. # [LOCAL TESTING GUARD] Bypass update if DISABLE_PROFILE_UPDATE=1
  137. if [ "$DISABLE_PROFILE_UPDATE" = "1" ]; then
  138. echo -e "\033[1;33m>> Auto-update skipped (DISABLE_PROFILE_UPDATE=1) <<\033[0m"
  139. return 0
  140. fi
  141. local remote_url="https://git.4parv.in/parv.ashwani/.bash_profile/raw/main/.bash_profile"
  142. local local_file="$HOME/.bash_profile"
  143. local tmp_file="/tmp/.bash_profile_new"
  144. # [GUARD] Prevent infinite loops if the new profile sources itself
  145. if [ "$_PROFILE_UPDATE_RUN" = "1" ]; then
  146. return 0
  147. fi
  148. export _PROFILE_UPDATE_RUN="1"
  149. # [FETCH] Download quietly with a 2-second timeout to avoid shell hangs
  150. if curl -sL --connect-timeout 2 -m 2 "$remote_url" -o "$tmp_file" 2>/dev/null; then
  151. # [CHECK] If file has content and differs from the local version
  152. if [ -s "$tmp_file" ] && ! cmp -s "$local_file" "$tmp_file" 2>/dev/null; then
  153. echo -e "\033[1;35m>> New .bash_profile detected on Git! Updating... <<\033[0m"
  154. # Backup current profile and overwrite with new
  155. cp "$local_file" "${local_file}.bak" 2>/dev/null
  156. cp "$tmp_file" "$local_file"
  157. # Clean up temp file before sourcing to keep environment clean
  158. rm -f "$tmp_file" 2>/dev/null
  159. # Apply the newly downloaded profile immediately
  160. source "$local_file"
  161. return 0
  162. fi
  163. fi
  164. # Clean up if no update was needed or curl failed
  165. rm -f "$tmp_file" 2>/dev/null
  166. }
  167. # Run the update check
  168. _auto_update_profile