Spaces:
Paused
Paused
Commit ·
31194ec
1
Parent(s): d0cd93b
Feat: Add core application files
Browse files- Dockerfile +55 -0
- start.sh +60 -0
- sync.sh +73 -0
- warp_proxy.sh +58 -0
Dockerfile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM debian:bullseye-slim
|
| 2 |
+
|
| 3 |
+
# Install prerequisites
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
curl \
|
| 6 |
+
gnupg \
|
| 7 |
+
ca-certificates \
|
| 8 |
+
dos2unix \
|
| 9 |
+
wget \
|
| 10 |
+
tar \
|
| 11 |
+
bash \
|
| 12 |
+
--no-install-recommends && \
|
| 13 |
+
rm -rf /var/lib/apt/lists/*
|
| 14 |
+
|
| 15 |
+
SHELL ["/bin/bash", "-c"]
|
| 16 |
+
|
| 17 |
+
# Set a safe working directory
|
| 18 |
+
WORKDIR /opt/app
|
| 19 |
+
|
| 20 |
+
# Install tools
|
| 21 |
+
ARG SINGBOX_VERSION=1.12.8
|
| 22 |
+
RUN wget -O /tmp/sing-box.tar.gz "https://github.com/SagerNet/sing-box/releases/download/v${SINGBOX_VERSION}/sing-box-${SINGBOX_VERSION}-linux-amd64.tar.gz" && \
|
| 23 |
+
tar -zxvf /tmp/sing-box.tar.gz -C /tmp && \
|
| 24 |
+
mv /tmp/sing-box-${SINGBOX_VERSION}-linux-amd64/sing-box /usr/local/bin/sing-box && \
|
| 25 |
+
chmod +x /usr/local/bin/sing-box && \
|
| 26 |
+
rm -rf /tmp/sing-box*
|
| 27 |
+
ARG CHISEL_VERSION=1.10.1
|
| 28 |
+
RUN wget https://github.com/jpillora/chisel/releases/download/v${CHISEL_VERSION}/chisel_${CHISEL_VERSION}_linux_amd64.gz -O /tmp/chisel.gz && \
|
| 29 |
+
gunzip /tmp/chisel.gz && \
|
| 30 |
+
mv /tmp/chisel /usr/local/bin/chisel && \
|
| 31 |
+
chmod +x /usr/local/bin/chisel
|
| 32 |
+
RUN ARCH=$(uname -m) && \
|
| 33 |
+
if [ "$ARCH" = "x86_64" ]; then ARCH="amd64"; fi && \
|
| 34 |
+
if [ "$ARCH" = "aarch64" ]; then ARCH="arm64"; fi && \
|
| 35 |
+
wget -O /usr/local/x-ui-linux-${ARCH}.tar.gz \
|
| 36 |
+
"https://github.com/MHSanaei/3x-ui/releases/latest/download/x-ui-linux-${ARCH}.tar.gz" && \
|
| 37 |
+
mkdir -p /usr/local/x-ui/ && \
|
| 38 |
+
tar -zxvf /usr/local/x-ui-linux-*.tar.gz -C /usr/local/x-ui/ --strip-components=1 && \
|
| 39 |
+
rm /usr/local/x-ui-linux-*.tar.gz && \
|
| 40 |
+
chmod +x /usr/local/x-ui/x-ui && \
|
| 41 |
+
cp /usr/local/x-ui/x-ui.sh /usr/bin/x-ui
|
| 42 |
+
|
| 43 |
+
# Copy all files from the build context (huggingface-x-ui-final) into the work directory
|
| 44 |
+
COPY . .
|
| 45 |
+
|
| 46 |
+
# Make scripts executable
|
| 47 |
+
RUN chmod +x /opt/app/warp_proxy.sh && \
|
| 48 |
+
chmod +x /opt/app/start.sh
|
| 49 |
+
|
| 50 |
+
# Expose the x-ui port
|
| 51 |
+
EXPOSE 2023
|
| 52 |
+
|
| 53 |
+
# Set the entrypoint to our startup script
|
| 54 |
+
RUN chmod -R 777 /usr/local/x-ui/
|
| 55 |
+
ENTRYPOINT ["/bin/bash", "-c", "/opt/app/start.sh"]
|
start.sh
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
echo "Architecture: $(uname -m)"
|
| 3 |
+
|
| 4 |
+
# --- Restore Configs from baked-in repo files ---
|
| 5 |
+
CONFIG_DIR_IN_REPO="/opt/app/x-ui-configs"
|
| 6 |
+
LIVE_XUI_DB_PATH="/tmp/x-ui.db"
|
| 7 |
+
LIVE_XRAY_CONFIG_PATH="/usr/local/x-ui/bin/config.json"
|
| 8 |
+
|
| 9 |
+
echo "Restoring configs from baked-in files..."
|
| 10 |
+
if [ -f "${CONFIG_DIR_IN_REPO}/config.json" ]; then
|
| 11 |
+
cp -f "${CONFIG_DIR_IN_REPO}/config.json" "${LIVE_XRAY_CONFIG_PATH}"
|
| 12 |
+
echo "Restored config.json"
|
| 13 |
+
fi
|
| 14 |
+
if [ -f "${CONFIG_DIR_IN_REPO}/x-ui.db" ]; then
|
| 15 |
+
cp -f "${CONFIG_DIR_IN_REPO}/x-ui.db" "${LIVE_XUI_DB_PATH}"
|
| 16 |
+
echo "Restored x-ui.db"
|
| 17 |
+
fi
|
| 18 |
+
# --- End Restore ---
|
| 19 |
+
|
| 20 |
+
# --- WARP SOCKS Proxy Setup ---
|
| 21 |
+
echo "Starting WARP SOCKS5 proxy via sing-box..."
|
| 22 |
+
nohup /opt/app/warp_proxy.sh > /tmp/warp.log 2>&1 &
|
| 23 |
+
echo "WARP SOCKS5 proxy started in background. Log at /tmp/warp.log"
|
| 24 |
+
# --- End WARP SOCKS Proxy Setup ---
|
| 25 |
+
|
| 26 |
+
# Set a writable directory for the x-ui database
|
| 27 |
+
export XUI_DB_FOLDER=/tmp
|
| 28 |
+
|
| 29 |
+
# Function to run chisel client in a loop
|
| 30 |
+
run_chisel() {
|
| 31 |
+
while true; do
|
| 32 |
+
echo "Starting chisel client..."
|
| 33 |
+
# This is the line from the user's last instruction
|
| 34 |
+
/usr/local/bin/chisel client -v --auth "cloud:2025" --keepalive 25s "https://vds1.iri1968.dpdns.org/chisel-ws" R:8080:127.0.0.1:2023
|
| 35 |
+
echo "Chisel client exited. Restarting in 5 seconds..."
|
| 36 |
+
sleep 5
|
| 37 |
+
done
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Start chisel in the background
|
| 41 |
+
run_chisel &
|
| 42 |
+
|
| 43 |
+
# Wait a moment for the background process to start
|
| 44 |
+
sleep 2
|
| 45 |
+
|
| 46 |
+
# --- ADDED USER SETTINGS ---
|
| 47 |
+
echo "Configuring x-ui web base path..."
|
| 48 |
+
/usr/local/x-ui/x-ui setting -webBasePath /
|
| 49 |
+
|
| 50 |
+
echo "Resetting x-ui admin credentials..."
|
| 51 |
+
/usr/local/x-ui/x-ui setting -username prog10 -password 04091968
|
| 52 |
+
|
| 53 |
+
# This command is from a previous step, it is needed for the port
|
| 54 |
+
/usr/local/x-ui/x-ui setting -port 2023
|
| 55 |
+
# --- END ADDED SETTINGS ---
|
| 56 |
+
|
| 57 |
+
# Start x-ui in the foreground
|
| 58 |
+
echo "Starting x-ui panel..."
|
| 59 |
+
cd /usr/local/x-ui
|
| 60 |
+
./x-ui
|
sync.sh
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# This script assumes that start.sh has already cloned the repo and set up SSH.
|
| 4 |
+
|
| 5 |
+
# --- Paths ---
|
| 6 |
+
# The git repo is cloned into /tmp/repo by start.sh
|
| 7 |
+
GIT_REPO_DIR="/tmp/repo"
|
| 8 |
+
LOG_FILE="/tmp/sync.log"
|
| 9 |
+
|
| 10 |
+
# Live files to be backed up
|
| 11 |
+
XUI_DB_PATH="/tmp/x-ui.db"
|
| 12 |
+
XRAY_CONFIG_PATH="/usr/local/x-ui/bin/config.json"
|
| 13 |
+
|
| 14 |
+
# Destination for the backed up files inside the git repo
|
| 15 |
+
TARGET_DIR="${GIT_REPO_DIR}/x-ui-configs"
|
| 16 |
+
|
| 17 |
+
# Git commit message
|
| 18 |
+
COMMIT_MESSAGE="Automatic sync of x-ui configs"
|
| 19 |
+
|
| 20 |
+
# --- Functions ---
|
| 21 |
+
|
| 22 |
+
log() {
|
| 23 |
+
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# --- Main ---
|
| 27 |
+
|
| 28 |
+
log "--- Starting Hourly Sync ---"
|
| 29 |
+
|
| 30 |
+
# Navigate to the Git repository
|
| 31 |
+
if [ ! -d "$GIT_REPO_DIR/.git" ]; then
|
| 32 |
+
log "Error: Git repository not found at $GIT_REPO_DIR. Exiting sync."
|
| 33 |
+
exit 1
|
| 34 |
+
fi
|
| 35 |
+
cd "$GIT_REPO_DIR" || exit 1
|
| 36 |
+
|
| 37 |
+
# Configure git user for this operation
|
| 38 |
+
git config user.email "igor04091968@gmail.com"
|
| 39 |
+
git config user.name "igor04091968"
|
| 40 |
+
|
| 41 |
+
# Pull latest changes first to avoid conflicts
|
| 42 |
+
log "Pulling latest changes from remote..."
|
| 43 |
+
git pull --rebase
|
| 44 |
+
|
| 45 |
+
# Ensure the target directory for configs exists
|
| 46 |
+
mkdir -p "$TARGET_DIR"
|
| 47 |
+
|
| 48 |
+
# Copy live files into the git repo
|
| 49 |
+
log "Copying live db from ${XUI_DB_PATH} and config from ${XRAY_CONFIG_PATH} into git repo..."
|
| 50 |
+
cp -f "${XUI_DB_PATH}" "${TARGET_DIR}/x-ui.db"
|
| 51 |
+
cp -f "${XRAY_CONFIG_PATH}" "${TARGET_DIR}/config.json"
|
| 52 |
+
|
| 53 |
+
# Add, commit, and push
|
| 54 |
+
log "Adding changes to git..."
|
| 55 |
+
git add "$TARGET_DIR/x-ui.db" "$TARGET_DIR/config.json"
|
| 56 |
+
|
| 57 |
+
# Commit only if there are changes
|
| 58 |
+
if ! git diff-index --quiet HEAD; then
|
| 59 |
+
log "Found changes, committing..."
|
| 60 |
+
git commit -m "$COMMIT_MESSAGE"
|
| 61 |
+
log "Committed changes."
|
| 62 |
+
|
| 63 |
+
log "Pushing changes to remote..."
|
| 64 |
+
if git push; then
|
| 65 |
+
log "Successfully pushed changes to the remote repository."
|
| 66 |
+
else
|
| 67 |
+
log "Error: Failed to push changes."
|
| 68 |
+
fi
|
| 69 |
+
else
|
| 70 |
+
log "No changes to commit."
|
| 71 |
+
fi
|
| 72 |
+
|
| 73 |
+
log "--- Hourly Sync Finished ---"
|
warp_proxy.sh
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Based on the entrypoint from Mon-ius/Docker-Warp-Socks v5
|
| 3 |
+
|
| 4 |
+
set -e
|
| 5 |
+
sleep 3
|
| 6 |
+
|
| 7 |
+
# Get WARP configuration
|
| 8 |
+
RESPONSE=$(curl -fsSL bit.ly/create-cloudflare-warp | sh -s)
|
| 9 |
+
|
| 10 |
+
# Extract variables
|
| 11 |
+
CF_CLIENT_ID=$(echo "$RESPONSE" | grep -oP '(?<=CLIENT_ID = ).*$')
|
| 12 |
+
CF_PRIVATE_KEY=$(echo "$RESPONSE" | grep -oP '(?<=PRIVATE_KEY = ).*$')
|
| 13 |
+
CF_ADDR_V4=$(echo "$RESPONSE" | grep -oP '(?<=V4 = ).*$')
|
| 14 |
+
CF_ADDR_V6=$(echo "$RESPONSE" | grep -oP '(?<=V6 = ).*$')
|
| 15 |
+
|
| 16 |
+
# Generate sing-box config
|
| 17 |
+
cat > /tmp/sing-box-config.json <<EOF
|
| 18 |
+
{
|
| 19 |
+
"log": {
|
| 20 |
+
"level": "info",
|
| 21 |
+
"timestamp": true
|
| 22 |
+
},
|
| 23 |
+
"inbounds": [
|
| 24 |
+
{
|
| 25 |
+
"type": "socks",
|
| 26 |
+
"tag": "socks-in",
|
| 27 |
+
"listen": "0.0.0.0",
|
| 28 |
+
"listen_port": 1080
|
| 29 |
+
}
|
| 30 |
+
],
|
| 31 |
+
"outbounds": [
|
| 32 |
+
{
|
| 33 |
+
"type": "wireguard",
|
| 34 |
+
"tag": "warp-out",
|
| 35 |
+
"server": "engage.cloudflareclient.com",
|
| 36 |
+
"server_port": 2408,
|
| 37 |
+
"local_address": [
|
| 38 |
+
"${CF_ADDR_V4}/32",
|
| 39 |
+
"${CF_ADDR_V6}/128"
|
| 40 |
+
],
|
| 41 |
+
"private_key": "${CF_PRIVATE_KEY}",
|
| 42 |
+
"peer_public_key": "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=",
|
| 43 |
+
"reserved": [${reserved_bytes}],
|
| 44 |
+
"mtu": 1280
|
| 45 |
+
}
|
| 46 |
+
]
|
| 47 |
+
}
|
| 48 |
+
EOF
|
| 49 |
+
|
| 50 |
+
# Replace reserved_bytes placeholder
|
| 51 |
+
# od -An -t u1 formats the bytes as unsigned decimal integers
|
| 52 |
+
reserved_bytes=$(echo "$CF_CLIENT_ID" | base64 -d | od -An -t u1 | awk
|
| 53 |
+
'{print $1", "$2", "$3}')
|
| 54 |
+
sed -i "s/\[${reserved_bytes}\]/\[${reserved_bytes}\]/" /tmp/sing-box-config.json
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
echo "Starting sing-box WARP proxy..."
|
| 58 |
+
exec /usr/local/bin/sing-box run -c /tmp/sing-box-config.json
|