Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Add basic support for generating sing-box configs.
Use cpp-httplib as web server.
Optimize codes.
  • Loading branch information
tindy2013 committed Nov 7, 2023
1 parent f99748b commit bbcb643
Show file tree
Hide file tree
Showing 32 changed files with 10,288 additions and 236 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
- uses: msys2/setup-msys2@v2
with:
update: true
install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-libevent mingw-w64-x86_64-pcre2 patch
install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-pcre2 patch
msystem: MINGW64
path-type: inherit
- name: Add commit id into version
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
- uses: msys2/setup-msys2@v2
with:
update: true
install: base-devel git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-libevent mingw-w64-i686-pcre2 patch
install: base-devel git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-pcre2 patch
msystem: MINGW32
path-type: inherit
- name: Add commit id into version
Expand Down
19 changes: 10 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ ADD_EXECUTABLE(${BUILD_TARGET_NAME}
src/parser/subparser.cpp
src/script/cron.cpp
src/script/script_quickjs.cpp
src/server/webserver_libevent.cpp
# src/server/webserver_libevent.cpp
src/server/webserver_httplib.cpp
src/utils/base64/base64.cpp
src/utils/codepage.cpp
src/utils/file.cpp
Expand All @@ -66,12 +67,12 @@ SET(THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE(Threads REQUIRED)
TARGET_LINK_LIBRARIES(${BUILD_TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})

PKG_CHECK_MODULES(LIBEVENT libevent>=2.1.10 REQUIRED)
FIND_PATH(LIBEVENT_INCLUDE_DIR NAMES event.h PATHS ${LIBEVENT_INCLUDE_DIRS})
FIND_LIBRARY(LIBEVENT_LIBRARY NAMES event PATHS ${LIBEVENT_LIBRARY_DIRS})
TARGET_LINK_DIRECTORIES(${BUILD_TARGET_NAME} PRIVATE ${LIBEVENT_LIBRARY_DIRS})
TARGET_INCLUDE_DIRECTORIES(${BUILD_TARGET_NAME} PRIVATE ${LIBEVENT_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${BUILD_TARGET_NAME} ${LIBEVENT_LIBRARY})
#PKG_CHECK_MODULES(LIBEVENT libevent>=2.1.10 REQUIRED)
#FIND_PATH(LIBEVENT_INCLUDE_DIR NAMES event.h PATHS ${LIBEVENT_INCLUDE_DIRS})
#FIND_LIBRARY(LIBEVENT_LIBRARY NAMES event PATHS ${LIBEVENT_LIBRARY_DIRS})
#TARGET_LINK_DIRECTORIES(${BUILD_TARGET_NAME} PRIVATE ${LIBEVENT_LIBRARY_DIRS})
#TARGET_INCLUDE_DIRECTORIES(${BUILD_TARGET_NAME} PRIVATE ${LIBEVENT_INCLUDE_DIR})
#TARGET_LINK_LIBRARIES(${BUILD_TARGET_NAME} ${LIBEVENT_LIBRARY})

FIND_PACKAGE(CURL 7.54.0 REQUIRED)
TARGET_LINK_DIRECTORIES(${BUILD_TARGET_NAME} PRIVATE ${CURL_LIBRARY_DIRS})
Expand Down Expand Up @@ -113,7 +114,7 @@ ELSE()
INSTALL(DIRECTORY base/ DESTINATION ${CMAKE_INSTALL_BINDIR}/${BUILD_TARGET_NAME} FILES_MATCHING PATTERN "*")
ENDIF()

ELSE()
ELSE() #BUILD_STATIC_LIBRARY

ADD_LIBRARY(${BUILD_TARGET_NAME} STATIC
src/generator/config/ruleconvert.cpp
Expand Down Expand Up @@ -154,7 +155,7 @@ IF(WIN32)
TARGET_LINK_LIBRARIES(${BUILD_TARGET_NAME} PRIVATE ws2_32)
ENDIF()

ENDIF()
ENDIF() #BUILD_STATIC_LIBRARY

IF(HAVE_TO_STRING)
TARGET_COMPILE_DEFINITIONS(${BUILD_TARGET_NAME} PRIVATE -DHAVE_TO_STRING)
Expand Down
30 changes: 30 additions & 0 deletions base/base/all_base.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,33 @@ enhanced-mode-by-rule = true
}

{% endif %}
{% if request.target == "singbox" %}

{
"log": {
"disabled": false,
"level": "info",
"output": "box.log",
"timestamp": true
},
"dns": {},
"ntp": {
"enabled": false,
"server": "time.apple.com",
"server_port": 123,
"interval": "30m"
},
"inbounds": [
{
"type": "socks",
"tag": "socks-in",
"listen": "127.0.0.1",
"listen_port": 2080
}
],
"outbounds": [],
"route": {},
"experimental": {}
}

{% endif %}
26 changes: 26 additions & 0 deletions base/base/singbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"log": {
"disabled": false,
"level": "info",
"output": "box.log",
"timestamp": true
},
"dns": {},
"ntp": {
"enabled": false,
"server": "time.apple.com",
"server_port": 123,
"interval": "30m"
},
"inbounds": [
{
"type": "socks",
"tag": "socks-in",
"listen": "127.0.0.1",
"listen_port": 2080
}
],
"outbounds": [],
"route": {},
"experimental": {}
}
3 changes: 3 additions & 0 deletions base/config/example_external_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ clash_rule_base=base/forcerule.yml
;mellow_rule_base=base/mellow.conf
;quan_rule_base=base/quan.conf
;quanx_rule_base=base/quanx.conf
;loon_rule_base=base/loon.conf
;sssub_rule_base=base/shadowsocks_base.json
;singbox_rule_base=base/singbox.json

;Options for renaming nodes
;rename=Test-(.*?)-(.*?)-(.*?)\((.*?)\)@\1\4x测试线路_自\2到\3
Expand Down
3 changes: 3 additions & 0 deletions base/config/example_external_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ clash_rule_base = "base/forcerule.yml"
#mellow_rule_base = "base/mellow.conf"
#quan_rule_base = "base/quan.conf"
#quanx_rule_base = "base/quanx.conf"
#loon_rule_base = "base/loon.conf"
#sssub_rule_base = "base/shadowsocks_base.json"
#singbox_rule_base = "base/singbox.json"

# Options for adding emojis
#add_emoji = true
Expand Down
3 changes: 3 additions & 0 deletions base/config/example_external_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ custom:
# mellow_rule_base: base/mellow.conf
# quan_rule_base: base/quan.conf
# quanx_rule_base: base/quanx.conf
# loon_rule_base: base/loon.conf
# sssub_rule_base: base/shadowsocks_base.json
# singbox_rule_base: base/singbox.json

# rename_node:
# - {import: snippet/rename.txt}
Expand Down
6 changes: 5 additions & 1 deletion base/pref.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exclude_remarks=(到期|剩余流量|时间|官网|产品|平台)
enable_filter=false
;Script used for filtering nodes. Supports inline script and script path. A "filter" function with 1 argument which is a node should be defined in the script.
;Example: Inline script: Set value to content of script. Replace all line break with "\n".
; Script path: Set value to "path:/path/to/script.js".
; Script path: set value to "path:/path/to/script.js".
;filter_script=function filter(node) {\n const info = JSON.parse(node.ProxyInfo);\n if(info.EncryptMethod.includes('chacha20'))\n return true;\n return false;\n}

;Setting an external config file as default when none is specified, supports local files/URL
Expand Down Expand Up @@ -59,6 +59,9 @@ loon_rule_base=base/all_base.tpl
;Shadowsocks Android config base used by the generator, supports local files/URL
sssub_rule_base=base/all_base.tpl

;sing-box config base used by the generator, supports local files/URL
singbox_rule_base=base/all_base.tpl

;Proxy used to download configs, rulesets or subscriptions, set to NONE or empty to disable it, set to SYSTEM to use system proxy.
;Accept cURL-supported proxies (http:// https:// socks4a:// socks5://)
;Additional support for CORS proxy ( https://github.com/Rob--W/cors-anywhere https://github.com/Zibri/cloudflare-cors-anywhere etc.), prefix the address with "cors:" to recognize the address as CORS proxy.
Expand Down Expand Up @@ -237,6 +240,7 @@ clash.log_level=info
/mellow=/sub?target=mellow
/surfboard=/sub?target=surfboard
/loon=/sub?target=loon
/singbox=/sub?target=singbox
/ss=/sub?target=ss
/ssd=/sub?target=ssd
/sssub=/sub?target=sssub
Expand Down
11 changes: 9 additions & 2 deletions base/pref.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ exclude_remarks = ["(到期|剩余流量|时间|官网|产品)"]
# Enable script support for filtering nodes
enable_filter = false
# Script used for filtering nodes. Supports inline script and script path. A "filter" function with 1 argument which is a node should be defined in the script.
# Example: Inline script: Set value to content of script.
# Script path: Set value to "path:/path/to/script.js".
# Example: Inline script: set value to content of script.
# Script path: set value to "path:/path/to/script.js".
#filter_script = '''
#function filter(node) {
# const info = JSON.parse(node.ProxyInfo);
Expand Down Expand Up @@ -66,6 +66,9 @@ loon_rule_base = "base/all_base.tpl"
# Shadowsocks Android config base used by the generator, supports local files/URL
sssub_rule_base = "base/all_base.tpl"

# sing-box config base used by the generator, supports local files/URL
singbox_rule_base = "base/all_base.tpl"

# Proxy used to download rulesets or subscriptions, set to NONE or empty to disable it, set to SYSTEM to use system proxy.
# Accept cURL-supported proxies (http:// https:// socks4a:// socks5://)

Expand Down Expand Up @@ -266,6 +269,10 @@ target = "/sub?target=surfboard"
uri = "/loon"
target = "/sub?target=loon"

[[aliases]]
uri = "/singbox"
target = "/sub?target=singbox"

[[aliases]]
uri = "/ss"
target = "/sub?target=ss"
Expand Down
2 changes: 2 additions & 0 deletions base/pref.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ common:
quanx_rule_base: base/all_base.tpl
loon_rule_base: base/all_base.tpl
sssub_rule_base: base/all_base.tpl
singbox_rule_base: base/all_base.tpl
proxy_config: SYSTEM
proxy_ruleset: SYSTEM
proxy_subscription: NONE
Expand Down Expand Up @@ -116,6 +117,7 @@ aliases:
- {uri: /mellow, target: "/sub?target=mellow"}
- {uri: /surfboard, target: "/sub?target=surfboard"}
- {uri: /loon, target: "/sub?target=loon"}
- {uri: /singbox, target: "/sub?target=singbox"}
- {uri: /ss, target: "/sub?target=ss"}
- {uri: /ssd, target: "/sub?target=ssd"}
- {uri: /sssub, target: "/sub?target=sssub"}
Expand Down
Loading

0 comments on commit bbcb643

Please sign in to comment.