add-ws.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. source /var/lib/premium-script/ipvps.conf
  3. if [[ "$IP" = "" ]]; then
  4. domain=$(cat /etc/v2ray/domain)
  5. else
  6. domain=$IP
  7. fi
  8. tls="$(cat ~/log-install.txt | grep -w "Vmess TLS" | cut -d: -f2|sed 's/ //g')"
  9. none="$(cat ~/log-install.txt | grep -w "Vmess None TLS" | cut -d: -f2|sed 's/ //g')"
  10. mkcp="$(cat ~/log-install.txt | grep -w "V2RAY VMESS KCP" | cut -d: -f2|sed 's/ //g')"
  11. until [[ $user =~ ^[a-zA-Z0-9_]+$ && ${CLIENT_EXISTS} == '0' ]]; do
  12. read -rp "User: " -e user
  13. CLIENT_EXISTS=$(grep -w $user /etc/v2ray/config.json | wc -l)
  14. if [[ ${CLIENT_EXISTS} == '1' ]]; then
  15. echo ""
  16. echo "A client with the specified name was already created, please choose another name."
  17. exit 1
  18. fi
  19. done
  20. uuid=$(cat /proc/sys/kernel/random/uuid)
  21. read -p "Expired (days): " masaaktif
  22. exp=`date -d "$masaaktif days" +"%Y-%m-%d"`
  23. sed -i '/#tls$/a\### '"$user $exp"'\
  24. },{"id": "'""$uuid""'","alterId": '"2"',"email": "'""$user""'"' /etc/v2ray/config.json
  25. sed -i '/#none$/a\### '"$user $exp"'\
  26. },{"id": "'""$uuid""'","alterId": '"2"',"email": "'""$user""'"' /etc/v2ray/none.json
  27. sed -i '/#mkcp$/a\### '"$user $exp"'\
  28. },{"id": "'""$uuid""'","alterId": '"2"',"email": "'""$user""'"' /etc/v2ray/mkcp.json
  29. cat>/etc/v2ray/$user-tls.json<<EOF
  30. {
  31. "v": "2",
  32. "ps": "${user}",
  33. "add": "${domain}",
  34. "port": "${tls}",
  35. "id": "${uuid}",
  36. "aid": "2",
  37. "net": "ws",
  38. "path": "/v2ray",
  39. "type": "none",
  40. "host": "",
  41. "tls": "tls"
  42. }
  43. EOF
  44. cat>/etc/v2ray/$user-none.json<<EOF
  45. {
  46. "v": "2",
  47. "ps": "${user}",
  48. "add": "${domain}",
  49. "port": "${none}",
  50. "id": "${uuid}",
  51. "aid": "2",
  52. "net": "ws",
  53. "path": "/v2ray",
  54. "type": "none",
  55. "host": "",
  56. "tls": "none"
  57. }
  58. EOF
  59. cat>/etc/v2ray/$user-mkcp.json<<EOF
  60. {
  61. "v": "2",
  62. "ps": "${user}",
  63. "add": "${domain}",
  64. "port": "${mkcp}",
  65. "id": "${uuid}",
  66. "aid": "2",
  67. "net": "kcp",
  68. "path": "/v2ray",
  69. "type": "dtls",
  70. "host": "",
  71. "tls": "none"
  72. }
  73. EOF
  74. vmess_base641=$( base64 -w 0 <<< $vmess_json1)
  75. vmess_base642=$( base64 -w 0 <<< $vmess_json2)
  76. vmess_base643=$( base64 -w 0 <<< $vmess_json3)
  77. vmesslink1="vmess://$(base64 -w 0 /etc/v2ray/$user-tls.json)"
  78. vmesslink2="vmess://$(base64 -w 0 /etc/v2ray/$user-none.json)"
  79. vmesslink3="vmess://$(base64 -w 0 /etc/v2ray/$user-mkcp.json)"
  80. systemctl restart v2ray
  81. systemctl restart v2ray@none
  82. systemctl restart v2ray@mkcp
  83. service cron restart
  84. clear
  85. echo -e ""
  86. echo -e "==========-V2RAY/VMESS-=========="
  87. echo -e "Remarks : ${user}"
  88. echo -e "Domain : ${domain}"
  89. echo -e "port TLS : ${tls}"
  90. echo -e "port none TLS : ${none}"
  91. echo -e "port KCP : ${mkcp}"
  92. echo -e "id : ${uuid}"
  93. echo -e "alterId : 2"
  94. echo -e "Security : auto"
  95. echo -e "network : ws"
  96. echo -e "path : /v2ray"
  97. echo -e "================================="
  98. echo -e "link TLS : ${vmesslink1}"
  99. echo -e "================================="
  100. echo -e "link none TLS : ${vmesslink2}"
  101. echo -e "================================="
  102. echo -e "link KCP : ${vmesslink3}"
  103. echo -e "================================="
  104. echo -e "Expired On : $exp"