deathline94 / sing-REALITY-Box

One click REALITY installer on sing-box core
Apache License 2.0
246 stars 363 forks source link

Add new Feature: use some outstanding features of sb-server-configer in this project #5

Closed GhostOfSarina closed 1 year ago

GhostOfSarina commented 1 year ago

First of all this project is fantastic.

sb-server-configer is another project about the sing-box. We can bring some features here.

Telegram Channel Management sing-box : As you know, Telegram channels are widespread nowadays. We can send daily sing-box configurations into the channels. It means that sending a new configuration every day to the channel and the subscriber of the channel can use it, but the everyday configuration will be changed and the member can't share the config with other people easily. Admin channel only buys a small server and uses your configuration to increase their members. Or family members add configuration for their telegram family group.

Based on that requirement, I wanna add this new feature to your script :

  1. renew configuration ( make new UUID) 2. Send new configuration directly to the channel
  2. add cronjob for run renew configuration daily
GhostOfSarina commented 1 year ago

I added these two lines to store public_key in the installation part touch /root/public_key.txt echo $public_key > /root/public_key.txt

and the added part 4 ( renew)

   4)
      echo "Renew..."

      # Generate new uuid
      uuid=$(/root/sing-box generate uuid)
      # Generate necessary values
      short_id=$(jq -r '.inbounds[0].tls.reality.short_id[0]' /root/reality.json)

      # Modify reality.json with new settings
      jq --arg uuid "$uuid"  '.inbounds[0].users[0].uuid = $uuid' /root/reality.json > /root/reality_modified.json
      mv /root/reality_modified.json /root/reality.json

      listen_port=$(jq -r '.inbounds[0].listen_port' /root/reality.json)
        server_name=$(jq -r '.inbounds[0].tls.server_name' /root/reality.json)
      server_ip=$(curl -s https://api.ipify.org)

      public_key=`cat /root/public_key.txt`

      server_link="vless://$uuid@$server_ip:$listen_port?encryption=none&flow=xtls-rprx-vision&security=reality&sni=$server_name&fp=chrome&pbk=$public_key&sid=$short_id&type=tcp&headerType=none#SING-BOX-TCP"

      server_link_base64=$(printf $server_link | base64 -w0);

      echo "Send server link to telegram"
      BOT_TOKEN=XXXXXX:XXXXXXXX
      CHAT_ID=-100XXXXXX
      telegram_url="https://api.telegram.org/bot$BOT_TOKEN/sendMessage?chat_id=$CHAT_ID&text=$server_link_base64"

      curl $telegram_url

      # Restart sing-box service
      systemctl restart sing-box
      echo "DONE!"
      exit 0
        ;;

``

GhostOfSarina commented 1 year ago

Now I need to run printf 4 | bash sing-REALITY-box.sh on the special time with corn job

GhostOfSarina commented 1 year ago

add cronjob: daily send the new configuration to the telegram channel for members.


#!/bin/bash

croncmd="printf 4 | bash /root/sing-REALITY-box.sh > /root/cronjob.log 2>&1"
cronjob="0 10 * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
GhostOfSarina commented 1 year ago

I deploy a first version of my idea. base on this project.

sing-box-daily-telegram

I didn't test it but I will do that.

deathline94 commented 1 year ago

seems like a fantastic idea mate , but it kinda drifts away from my intial purpose that is to provide the most , simplistic script to achive the goal . trust me , all of these are amazing idea's but it just confuses people . im trying to avoid that . i was gonna ask you to fork it and implent it yourself , you got my blessing , but you already done it . again really nice job .

GhostOfSarina commented 1 year ago

I agree, this feature needs more knowledge about the telegram bot and Cronjob activity.

I forked it and make a separate project based on this idea.

https://github.com/GostOfSarina/sing-box-daily-telegram