Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add clash api support #21

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions htdocs/luci-static/resources/view/homeproxy/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ return view.extend({
o.default = 'redirect_tproxy';
o.rmempty = false;

o = s.taboption('routing', form.Value, 'clashapi_port', _('Enable clash api'));
douglarek marked this conversation as resolved.
Show resolved Hide resolved
o.value('', _('Disable'));
o.value('9090', _('9090'));
o.validate = function(section_id, value) {
if (section_id && value && !stubValidator.apply('port', value)) {
return _('Expecting: %s').format(_('valid port value'));
}
return true;
}
douglarek marked this conversation as resolved.
Show resolved Hide resolved

o = s.taboption('routing', form.Flag, 'ipv6_support', _('IPv6 support'));
o.default = o.enabled;
o.rmempty = false;
Expand Down
1 change: 1 addition & 0 deletions root/etc/config/homeproxy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config homeproxy 'config'
option routing_port 'common'
option proxy_mode 'redirect_tproxy'
option ipv6_support '1'
option clashapi_port ''

config homeproxy 'control'
option lan_proxy_mode 'disabled'
Expand Down
18 changes: 17 additions & 1 deletion root/etc/homeproxy/scripts/generate_client.uc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const proxy_mode = uci.get(uciconfig, ucimain, 'proxy_mode') || 'redirect_tproxy
ipv6_support = uci.get(uciconfig, ucimain, 'ipv6_support') || '0',
default_interface = uci.get(uciconfig, ucicontrol, 'bind_interface');

const clashapi_port = uci.get(uciconfig, ucimain, 'clashapi_port') || '';
douglarek marked this conversation as resolved.
Show resolved Hide resolved

let self_mark, redirect_port, tproxy_port,
tun_name, tun_addr4, tun_addr6, tun_mtu,
tcpip_stack, endpoint_independent_nat;
Expand Down Expand Up @@ -550,5 +552,19 @@ if (!isEmpty(main_node)) {
}
/* Routing rules end */

system('mkdir -p ' + RUN_DIR);
/* Experimental start */
if (!isEmpty(clashapi_port)) {
config.experimental = {
clash_api: {
external_controller: '[::]:'+ clashapi_port,
external_ui: RUN_DIR + '/ui',
douglarek marked this conversation as resolved.
Show resolved Hide resolved
store_selected: true,
cache_file: RUN_DIR + '/cache.db'
douglarek marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
/* Experimental end */

system('mkdir -p ' + RUN_DIR + '/ui');
system('touch ' + RUN_DIR + '/cache.db');
douglarek marked this conversation as resolved.
Show resolved Hide resolved
writefile(RUN_DIR + '/sing-box-c.json', sprintf('%.J\n', removeBlankAttrs(config)));
6 changes: 6 additions & 0 deletions root/etc/init.d/homeproxy
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ start_service() {
procd_add_jail "sing-box-c" log procfs
procd_add_jail_mount "$RUN_DIR/sing-box-c.json"
procd_add_jail_mount_rw "$RUN_DIR/sing-box-c.log"
procd_add_jail_mount "$RUN_DIR/ui/"
douglarek marked this conversation as resolved.
Show resolved Hide resolved
procd_add_jail_mount_rw "$RUN_DIR/ui/"
procd_add_jail_mount "$RUN_DIR/cache.db"
procd_add_jail_mount_rw "$RUN_DIR/cache.db"
procd_add_jail_mount "$HP_DIR/certs/"
procd_add_jail_mount "/etc/ssl/"
procd_add_jail_mount "/etc/localtime"
Expand Down Expand Up @@ -263,6 +267,8 @@ start_service() {
echo > "$RUN_DIR/sing-box-c.log"
chown sing-box:sing-box "$RUN_DIR/sing-box-c.log"
chown sing-box:sing-box "$RUN_DIR/sing-box-c.json"
chown -R sing-box:sing-box "$RUN_DIR/ui"
chown sing-box:sing-box "$RUN_DIR/cache.db"
chmod 0644 "$HP_DIR/resources/gfw_list.txt"
fi
if [ "$server_enabled" = "1" ]; then
Expand Down