mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
[Fixed]尝试修复PASS空指针问题
[Chore]调整workflows测试
This commit is contained in:
parent
7b4e06816f
commit
d66febb1a6
14
.github/workflows/Alpha.yml
vendored
14
.github/workflows/Alpha.yml
vendored
|
@ -34,10 +34,20 @@ jobs:
|
||||||
BINDIR: bin
|
BINDIR: bin
|
||||||
run: make -j releases
|
run: make -j releases
|
||||||
|
|
||||||
|
- uses: dev-drprasad/delete-tag-and-release@v0.2.0
|
||||||
|
with:
|
||||||
|
delete_release: true # default: false
|
||||||
|
tag_name: alpha # tag name to delete
|
||||||
|
repo: <owner>/<repoName> # target repo (optional). defaults to repo running this action
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Upload Alpha
|
- name: Upload Alpha
|
||||||
uses: softprops/action-gh-release@v1
|
uses: svenstaro/upload-release-action@v2
|
||||||
if: ${{ env.GIT_BRANCH != 'Meta' && success() }}
|
if: ${{ env.GIT_BRANCH != 'Meta' && success() }}
|
||||||
with:
|
with:
|
||||||
tag_name: alpha
|
tag: ${{ github.ref }}
|
||||||
|
asset_name: alpha
|
||||||
|
overwrite: true
|
||||||
files: bin/*
|
files: bin/*
|
||||||
prerelease: true
|
prerelease: true
|
|
@ -56,3 +56,13 @@ func NewCompatible() *Direct {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewPass() *Direct {
|
||||||
|
return &Direct{
|
||||||
|
Base: &Base{
|
||||||
|
name: "Pass",
|
||||||
|
tp: C.Pass,
|
||||||
|
udp: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package outbound
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"github.com/Dreamacro/clash/component/dialer"
|
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Pass struct {
|
|
||||||
*Base
|
|
||||||
}
|
|
||||||
|
|
||||||
// DialContext implements C.ProxyAdapter
|
|
||||||
func (r *Pass) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
|
|
||||||
return nil, errors.New("match Pass rule")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListenPacketContext implements C.ProxyAdapter
|
|
||||||
func (r *Pass) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) {
|
|
||||||
return nil, errors.New("match Pass rule")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPass() *Pass {
|
|
||||||
return &Pass{
|
|
||||||
Base: &Base{
|
|
||||||
name: "PASS",
|
|
||||||
tp: C.Pass,
|
|
||||||
udp: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -210,7 +209,6 @@ type RawConfig struct {
|
||||||
Proxy []map[string]any `yaml:"proxies"`
|
Proxy []map[string]any `yaml:"proxies"`
|
||||||
ProxyGroup []map[string]any `yaml:"proxy-groups"`
|
ProxyGroup []map[string]any `yaml:"proxy-groups"`
|
||||||
Rule []string `yaml:"rules"`
|
Rule []string `yaml:"rules"`
|
||||||
Script Script `yaml:"script"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse config
|
// Parse config
|
||||||
|
@ -280,10 +278,6 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||||
Profile: Profile{
|
Profile: Profile{
|
||||||
StoreSelected: true,
|
StoreSelected: true,
|
||||||
},
|
},
|
||||||
Script: Script{
|
|
||||||
MainCode: "",
|
|
||||||
ShortcutsCode: map[string]string{},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := yaml.Unmarshal(buf, rawCfg); err != nil {
|
if err := yaml.Unmarshal(buf, rawCfg); err != nil {
|
||||||
|
@ -322,11 +316,6 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||||
config.Proxies = proxies
|
config.Proxies = proxies
|
||||||
config.Providers = providers
|
config.Providers = providers
|
||||||
|
|
||||||
err = parseScript(rawCfg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
rules, ruleProviders, err := parseRules(rawCfg, proxies)
|
rules, ruleProviders, err := parseRules(rawCfg, proxies)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -494,49 +483,6 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
||||||
return proxies, providersMap, nil
|
return proxies, providersMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseScript(cfg *RawConfig) error {
|
|
||||||
mode := cfg.Mode
|
|
||||||
script := cfg.Script
|
|
||||||
mainCode := cleanPyKeywords(script.MainCode)
|
|
||||||
shortcutsCode := script.ShortcutsCode
|
|
||||||
|
|
||||||
if mode != T.Script && len(shortcutsCode) == 0 {
|
|
||||||
return nil
|
|
||||||
} else if mode == T.Script && len(mainCode) == 0 {
|
|
||||||
return fmt.Errorf("initialized script module failure, can't find script code in the config file")
|
|
||||||
}
|
|
||||||
|
|
||||||
content :=
|
|
||||||
`# -*- coding: UTF-8 -*-
|
|
||||||
|
|
||||||
from datetime import datetime as whatever
|
|
||||||
|
|
||||||
class ClashTime:
|
|
||||||
def now(self):
|
|
||||||
return whatever.now()
|
|
||||||
|
|
||||||
def unix(self):
|
|
||||||
return int(whatever.now().timestamp())
|
|
||||||
|
|
||||||
def unix_nano(self):
|
|
||||||
return int(round(whatever.now().timestamp() * 1000))
|
|
||||||
|
|
||||||
time = ClashTime()
|
|
||||||
|
|
||||||
`
|
|
||||||
for k, v := range shortcutsCode {
|
|
||||||
v = cleanPyKeywords(v)
|
|
||||||
v = strings.TrimSpace(v)
|
|
||||||
if len(v) == 0 {
|
|
||||||
return fmt.Errorf("initialized rule SCRIPT failure, shortcut [%s] code invalid syntax", k)
|
|
||||||
}
|
|
||||||
|
|
||||||
content += "def " + strings.ToLower(k) + "(ctx, network, process_name, host, src_ip, src_port, dst_ip, dst_port):\n return " + v + "\n\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) {
|
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) {
|
||||||
ruleProviders := map[string]*providerTypes.RuleProvider{}
|
ruleProviders := map[string]*providerTypes.RuleProvider{}
|
||||||
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
||||||
|
@ -887,7 +833,7 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie, rules []C.Rule) (*DNS,
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAuthentication(rawRecords []string) []auth.AuthUser {
|
func parseAuthentication(rawRecords []string) []auth.AuthUser {
|
||||||
users := []auth.AuthUser{}
|
var users []auth.AuthUser
|
||||||
for _, line := range rawRecords {
|
for _, line := range rawRecords {
|
||||||
if user, pass, found := strings.Cut(line, ":"); found {
|
if user, pass, found := strings.Cut(line, ":"); found {
|
||||||
users = append(users, auth.AuthUser{User: user, Pass: pass})
|
users = append(users, auth.AuthUser{User: user, Pass: pass})
|
||||||
|
@ -896,19 +842,6 @@ func parseAuthentication(rawRecords []string) []auth.AuthUser {
|
||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanPyKeywords(code string) string {
|
|
||||||
if len(code) == 0 {
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
keywords := []string{"import", "print"}
|
|
||||||
|
|
||||||
for _, kw := range keywords {
|
|
||||||
reg := regexp.MustCompile("(?m)[\r\n]+^.*" + kw + ".*$")
|
|
||||||
code = reg.ReplaceAllString(code, "")
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseTun(rawTun RawTun, general *General) (*Tun, error) {
|
func parseTun(rawTun RawTun, general *General) (*Tun, error) {
|
||||||
if (rawTun.Enable || general.TProxyPort != 0) && general.Interface == "" {
|
if (rawTun.Enable || general.TProxyPort != 0) && general.Interface == "" {
|
||||||
autoDetectInterfaceName, err := commons.GetAutoDetectInterface()
|
autoDetectInterfaceName, err := commons.GetAutoDetectInterface()
|
||||||
|
|
|
@ -369,6 +369,7 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if adapter.Type() == C.Pass || (adapter.Unwrap(metadata) != nil && adapter.Unwrap(metadata).Type() == C.Pass) {
|
if adapter.Type() == C.Pass || (adapter.Unwrap(metadata) != nil && adapter.Unwrap(metadata).Type() == C.Pass) {
|
||||||
|
log.Debugln("%s match Pass rule", adapter.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user