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

Add Clash support #47

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions htdocs/luci-static/resources/view/homeproxy/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,30 @@ return view.extend({
/* Direct domain list end */
/* ACL settings end */

/* Clash start */
s.tab('clash', _('Clash'));
o = s.taboption('clash', form.SectionValue, '_clash', form.NamedSection, 'clash', 'homeproxy');

ss = o.subsection;
so = ss.option(form.Flag, 'enabled', _('Enable Clash API'));
so.default = so.disabled;

so = ss.option(form.Value, 'external_controller', _('Clash API URL'));
so.default = '0.0.0.0:9090'
so.rmempty = false;
so.depends('enabled', '1');

so = ss.option(form.Value, 'external_ui', _('UI Folder'));
so.default = '/etc/homeproxy/ui'
so.rmempty = false;
so.depends('enabled', '1');

so = ss.option(form.Value, 'secret', _('Secret'));
so.default = ''
so.rmempty = true;
so.depends('enabled', '1');
/* Clash end */

return m.render();
}
});
16 changes: 16 additions & 0 deletions po/templates/homeproxy.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2360,3 +2360,19 @@ msgstr ""
#: htdocs/luci-static/resources/homeproxy.js:268
msgid "valid uuid"
msgstr ""

#: htdocs/luci-static/resources/view/homeproxy/client.js:981
msgid "Enable Clash API"
msgstr ""

#: htdocs/luci-static/resources/view/homeproxy/client.js:984
msgid "Clash API URL"
msgstr ""

#: htdocs/luci-static/resources/view/homeproxy/client.js:989
msgid "UI Folder"
msgstr ""

#: htdocs/luci-static/resources/view/homeproxy/client.js:989
msgid "Secret"
msgstr ""
16 changes: 16 additions & 0 deletions po/zh_Hans/homeproxy.po
Original file line number Diff line number Diff line change
Expand Up @@ -2415,3 +2415,19 @@ msgstr "有效端口值"
#: htdocs/luci-static/resources/homeproxy.js:268
msgid "valid uuid"
msgstr "有效 uuid"

#: htdocs/luci-static/resources/view/homeproxy/client.js:981
msgid "Enable Clash API"
msgstr "启用Clash API"

#: htdocs/luci-static/resources/view/homeproxy/client.js:984
msgid "Clash API URL"
msgstr "Chash API URL"

#: htdocs/luci-static/resources/view/homeproxy/client.js:989
msgid "UI Folder"
msgstr "UI文件夹"

#: htdocs/luci-static/resources/view/homeproxy/client.js:989
msgid "Secret"
msgstr "访问密码"
2 changes: 2 additions & 0 deletions root/etc/config/homeproxy
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ config homeproxy 'server'
option enabled '0'
option auto_firewall '0'

config homeproxy 'clash'
option enabled '0'
21 changes: 20 additions & 1 deletion root/etc/homeproxy/scripts/generate_client.uc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ uci.load(uciconfig);

const uciinfra = 'infra',
ucimain = 'config',
ucicontrol = 'control';
ucicontrol = 'control',
uciclash = 'clash';

const ucidnssetting = 'dns',
ucidnsserver = 'dns_server',
Expand Down Expand Up @@ -566,5 +567,23 @@ if (!isEmpty(main_node)) {
}
/* Routing rules end */

/* Clash start */
if (uci.get(uciconfig, uciclash, 'enabled') == '1')
{
config.experimental = {
clash_api: {
external_controller: uci.get(uciconfig, uciclash, 'external_controller'),
external_ui: uci.get(uciconfig, uciclash, 'external_ui')

}
};

if (uci.get(uciconfig, uciclash, 'secret') != '')
{
config.experimental.clash_api.secret = uci.get(uciconfig, uciclash, 'secret');
}
}
/* Clash end */

system('mkdir -p ' + RUN_DIR);
writefile(RUN_DIR + '/sing-box-c.json', sprintf('%.J\n', removeBlankAttrs(config)));