尝试修复对2022的兼容性

This commit is contained in:
CN-JS-HuiBai
2026-04-15 00:20:34 +08:00
parent 5d5aefedfd
commit 17ed1bbe21
2 changed files with 34 additions and 21 deletions

View File

@@ -132,24 +132,15 @@ NODE_TYPE=${INPUT_TYPE:-${NODE_TYPE:-v2ray}}
read -p "Enter Panel Token (Node Key) [${PANEL_TOKEN}]: " INPUT_TOKEN read -p "Enter Panel Token (Node Key) [${PANEL_TOKEN}]: " INPUT_TOKEN
PANEL_TOKEN=${INPUT_TOKEN:-$PANEL_TOKEN} PANEL_TOKEN=${INPUT_TOKEN:-$PANEL_TOKEN}
# Optional Separate Config/User IDs and URLs # Consolidation
read -p "Use separate URL/ID for Config? (y/N): " USE_SEP_CONFIG CONFIG_PANEL_URL=$PANEL_URL
if [[ "$USE_SEP_CONFIG" =~ ^[Yy]$ ]]; then CONFIG_NODE_ID=$NODE_ID
read -p " Enter Config Panel URL [${CONFIG_PANEL_URL:-$PANEL_URL}]: " INPUT_CURL USER_PANEL_URL=$PANEL_URL
CONFIG_PANEL_URL=${INPUT_CURL:-$PANEL_URL} USER_NODE_ID=$NODE_ID
CONFIG_PANEL_URL="${CONFIG_PANEL_URL%/}"
read -p " Enter Config Node ID [${CONFIG_NODE_ID:-$NODE_ID}]: " INPUT_CID
CONFIG_NODE_ID=${INPUT_CID:-$NODE_ID}
fi
read -p "Use separate URL/ID for Users? (y/N): " USE_SEP_USER # Sync time (Critical for SS 2022)
if [[ "$USE_SEP_USER" =~ ^[Yy]$ ]]; then echo -e "${YELLOW}Syncing system time...${NC}"
read -p " Enter User Panel URL [${USER_PANEL_URL:-$PANEL_URL}]: " INPUT_UURL timedatectl set-ntp true || true
USER_PANEL_URL=${INPUT_UURL:-$PANEL_URL}
USER_PANEL_URL="${USER_PANEL_URL%/}"
read -p " Enter User Node ID [${USER_NODE_ID:-$NODE_ID}]: " INPUT_UID
USER_NODE_ID=${INPUT_UID:-$NODE_ID}
fi
if [[ -z "$PANEL_URL" || -z "$NODE_ID" || -z "$PANEL_TOKEN" ]]; then if [[ -z "$PANEL_URL" || -z "$NODE_ID" || -z "$PANEL_TOKEN" ]]; then
echo -e "${RED}All fields are required!${NC}" echo -e "${RED}All fields are required!${NC}"

View File

@@ -29,13 +29,24 @@ func fixSSKey(key string, length int) string {
if key == "" { if key == "" {
return "" return ""
} }
// Try to decode as-is first // If it's already a valid Base64 of the correct length, use it directly (as a B64 key)
if data, err := base64.StdEncoding.DecodeString(key); err == nil && len(data) == length { if data, err := base64.StdEncoding.DecodeString(key); err == nil && len(data) == length {
return key return key
} }
// Use SHA256 to derive a fixed-length key from the password
hash := sha256.Sum256([]byte(key)) // Legacy repetition/truncation logic for raw string keys (common in Xboard/V2board)
return base64.StdEncoding.EncodeToString(hash[:length]) password := key
if len(password) > length {
password = password[:length]
}
for len(password) < length {
password += password
}
// Re-truncate after repetition
password = password[:length]
// Convert to Base64 so sing-box treats it as a raw byte key
return base64.StdEncoding.EncodeToString([]byte(password))
} }
func RegisterService(registry *boxService.Registry) { func RegisterService(registry *boxService.Registry) {
@@ -407,6 +418,17 @@ func (s *Service) fetchConfig() (*XNodeConfig, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
// Check time drift
if dateStr := resp.Header.Get("Date"); dateStr != "" {
if panelTime, err := http.ParseTime(dateStr); err == nil {
drift := time.Since(panelTime)
if drift < 0 { drift = -drift }
if drift > 30*time.Second {
s.logger.Error("CRITICAL TIME DRIFT: ", drift, " off from Panel. SS 2022 WILL FAIL. Sync your time!")
}
}
}
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
respBody, _ := io.ReadAll(resp.Body) respBody, _ := io.ReadAll(resp.Body)
return nil, E.New("failed to fetch config, status: ", resp.Status, ", body: ", string(respBody)) return nil, E.New("failed to fetch config, status: ", resp.Status, ", body: ", string(respBody))