userV2ray.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/bash
  2. restart(){
  3. title "REINICIANDO V2RAY"
  4. if [[ "$(v2ray restart|awk '{printf $3}')" = "success" ]]; then
  5. print_center -verd "v2ray restart success !"
  6. msg -bar
  7. sleep 3
  8. else
  9. print_center -verm2 "v2ray restart fail !"
  10. msg -bar
  11. sleep 3
  12. return
  13. fi
  14. }
  15. list(){
  16. name=$(printf '%-25s' "$2")
  17. fecha=$(printf '%-10s' "$3")
  18. if [[ "$4" = "EXP" ]]; then
  19. dias=$(msg -verm2 "[$4]")
  20. else
  21. dias=$(msg -verd "[$4]")
  22. fi
  23. echo -e "$(msg -verd " [$1]") $(msg -verm2 ">") $(msg -azu "$name") $(msg -verm2 "$fecha") $dias"
  24. }
  25. userDat(){
  26. n=$(printf '%-5s' 'N°')
  27. u=$(printf '%-25s' 'Usuarios')
  28. f=$(printf '%-10s' 'fech exp')
  29. msg -azu " $n $u $f dias"
  30. msg -bar
  31. }
  32. list_user(){
  33. unset seg
  34. seg=$(date +%s)
  35. userDat
  36. users=$(jq '.inbounds[].settings.clients | length' $config)
  37. for (( i = 0; i < $users; i++ )); do
  38. user=$(jq -r --argjson a "$i" '.inbounds[].settings.clients[$a].email' < $config)
  39. fecha=$(jq -r --argjson a "$i" '.inbounds[].settings.clients[$a].date' < $config)
  40. [[ "$user" = "null" ]] && continue
  41. seg_exp=$(date +%s --date="$fecha")
  42. exp="$(($(($seg_exp - $seg)) / 86400))"
  43. [[ "$exp" -lt "0" ]] && exp="EXP"
  44. list "$i" "$user" "$fecha" "$exp"
  45. done
  46. }
  47. col2(){
  48. msg -ne "$1" && msg -ama " $2"
  49. }
  50. vmess(){
  51. ps=$(jq -r .inbounds[].settings.clients[$1].email $config) && [[ $ps = null ]] && ps="default"
  52. id=$(jq -r .inbounds[].settings.clients[$1].id $config)
  53. aid=$(jq .inbounds[].settings.clients[$1].alterId $config)
  54. add=$(jq -r .inbounds[].domain $config) && [[ $add = null ]] && add=$(wget -qO- ipv4.icanhazip.com)
  55. host=$(jq -r .inbounds[].streamSettings.wsSettings.headers.Host $config) && [[ $host = null ]] && host=''
  56. net=$(jq -r .inbounds[].streamSettings.network $config)
  57. path=$(jq -r .inbounds[].streamSettings.wsSettings.path $config) && [[ $path = null ]] && path=''
  58. port=$(jq .inbounds[].port $config)
  59. tls=$(jq -r .inbounds[].streamSettings.security $config)
  60. title "DATOS DE USUARIO: $ps"
  61. col2 "Remarks:" "$ps"
  62. col2 "Address:" "$add"
  63. col2 "Port:" "$port"
  64. col2 "id:" "$id"
  65. col2 "alterId:" "$aid"
  66. col2 "security:" "none"
  67. col2 "network:" "$net"
  68. col2 "Head Type:" "none"
  69. [[ ! $host = '' ]] && col2 "Host/SNI:" "$host"
  70. [[ ! $path = '' ]] && col2 "Path:" "$path"
  71. col2 "TLS:" "$tls"
  72. msg -bar
  73. var="{\"v\":\"2\",\"ps\":\"$ps\",\"add\":\"$add\",\"port\":$port,\"aid\":$aid,\"type\":\"none\",\"net\":\"$net\",\"path\":\"$path\",\"host\":\"$host\",\"id\":\"$id\",\"tls\":\"$tls\"}"
  74. msg -ama "vmess://$(echo "$var"|jq -r '.|@base64')"
  75. msg -bar
  76. read foo
  77. }
  78. newuser(){
  79. title "CREAR NUEVO USUARIO V2RAY"
  80. list_user
  81. back
  82. in_opcion "Nuevo Usuario"
  83. opcion=$(echo "$opcion" | tr -d '[[:space:]]')
  84. if [[ "$opcion" = "0" ]]; then
  85. return
  86. elif [[ -z "$opcion" ]]; then
  87. tput cuu1 && tput dl1
  88. msg -verm2 " no se puede ingresar campos vacios..."
  89. sleep 2
  90. return
  91. elif [[ ! "$opcion" =~ $tx_num ]]; then
  92. tput cuu1 && tput dl1
  93. msg -verm2 " ingrese solo letras y numeros..."
  94. sleep 2
  95. return
  96. elif [[ "${#opcion}" -lt "4" ]]; then
  97. tput cuu1 && tput dl1
  98. msg -verm2 " nombre demaciado corto!"
  99. sleep 2
  100. return
  101. elif [[ "$(jq -r '.inbounds[].settings.clients[].email' < $config|grep "$opcion")" ]]; then
  102. tput cuu1 && tput dl1
  103. msg -verm2 " este nombe de ususario ya existe..."
  104. sleep 2
  105. return
  106. fi
  107. email="$opcion"
  108. in_opcion "Dias de duracion"
  109. opcion=$(echo "$opcion" | tr -d '[[:space:]]')
  110. if [[ "$opcion" = "0" ]]; then
  111. return
  112. elif [[ ! "$opcion" =~ $numero ]]; then
  113. tput cuu1 && tput dl1
  114. msg -verm2 " ingresa solo numeros"
  115. sleep 2
  116. return
  117. fi
  118. dias=$(date '+%y-%m-%d' -d " +$opcion days")
  119. alterid=$(jq -r '.inbounds[].settings.clients[0].alterId' < $config)
  120. uuid=$(uuidgen)
  121. var="{\"alterId\":"$alterid",\"id\":\"$uuid\",\"email\":\"$email\",\"date\":\"$dias\"}"
  122. mv $config $temp
  123. jq --argjson a "$users" --argjson b "$var" '.inbounds[].settings.clients[$a] += $b' < $temp > $config
  124. chmod 777 $config
  125. rm -rf $temp
  126. restart
  127. vmess "$users"
  128. }
  129. deluser(){
  130. title "ELIMINAR USUARIOS"
  131. list_user
  132. back
  133. in_opcion "Opcion"
  134. opcion=$(echo "$opcion" | tr -d '[[:space:]]')
  135. if [[ "$opcion" = "0" ]]; then
  136. return
  137. elif [[ ! "$opcion" =~ $numero ]]; then
  138. tput cuu1 && tput dl1
  139. msg -verm2 " ingresa solo numeros"
  140. sleep 2
  141. return
  142. fi
  143. mv $config $temp
  144. jq --argjson a "$opcion" 'del(.inbounds[].settings.clients[$a])' < $temp > $config
  145. chmod 777 $config
  146. rm -rf $temp
  147. restart
  148. }
  149. datos(){
  150. title "DATOS DE USUARIOS"
  151. list_user
  152. back
  153. in_opcion "Opcion"
  154. vmess "$opcion"
  155. }
  156. respaldo(){
  157. title "COPIAS DE SEGURIDAD DE USUARIOS"
  158. menu_func "CREAR COPIA DE USUARIOS" "RESTAURAR COPIA DE USUARIO"
  159. back
  160. opcion=$(selection_fun 2)
  161. case $opcion in
  162. 1)rm -rf /root/User-V2ray.txt
  163. jq '.inbounds[].settings.clients' < $config > /root/User-V2ray.txt
  164. title "COPIA REALIZADO CON EXITO"
  165. msg -ne " Copia: " && msg -ama "/root/User-V2ray.txt"
  166. msg -bar
  167. read foo;;
  168. 2)[[ ! -e "/root/User-V2ray.txt" ]] && msg -verm2 " no hay copia de ususarios!" && sleep 3 && return
  169. var=$(cat /root/User-V2ray.txt)
  170. [[ -z "$var" ]] && msg -verm2 " copia de ususarios vacio!" && sleep 3 && return
  171. mv $config $temp
  172. jq --argjson a "$var" '.inbounds[].settings += {clients:$a}' < $temp > $config
  173. chmod 777 $config
  174. rm -rf $temp
  175. title "COPIA RESTAURADA CON EXITO"
  176. sleep 2
  177. restart;;
  178. 0)return;;
  179. esac
  180. }
  181. while :
  182. do
  183. title "GESTION DE USUARIOS V2RAY"
  184. menu_func "$(msg -verd "CREAR USUARIOS")" \
  185. "$(msg -verm2 "ELIMINAR USUARIOS")" \
  186. "BLOQUEAR USUARIOS $(msg -verm2 "(no diponible!)")" \
  187. "$(msg -ama "VMESS DE USUARIOS")" \
  188. "RESPALDO DE SEGURIDAD"
  189. back
  190. opcion=$(selection_fun 5)
  191. case $opcion in
  192. 1)newuser;;
  193. 2)deluser;;
  194. 3);;
  195. 4)datos;;
  196. 5)respaldo;;
  197. 0)break;;
  198. esac
  199. done