Skip to content

Commit

Permalink
0.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
frainzy1477 committed Jun 30, 2019
1 parent 394a97b commit 3a492ec
Show file tree
Hide file tree
Showing 51 changed files with 2,457 additions and 0 deletions.
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-clash
PKG_VERSION:=0.22.0
PKG_RELEASE:=1
PKG_MAINTAINER:=frainzy1477


include $(INCLUDE_DIR)/package.mk

define Package/luci-app-clash
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=2. Services
TITLE:=LuCI app for clash
DEPENDS:=+bash +coreutils-nohup +wget
PKGARCH:=all
MAINTAINER:=frainzy1477
endef

define Package/luci-app-clash/description
LuCI configuration for clash.
endef

define Package/$(PKG_NAME)/postinst
#!/bin/sh
rm -rf /tmp/luci*
/etc/init.d/clash disable
endef

define Build/Prepare
${CURDIR}/tools/po2lmo/src/po2lmo ${CURDIR}/po/zh-cn/clash.po ${CURDIR}/po/zh-cn/clash.zh-cn.lmo
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/clash
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/clash
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/clash
$(INSTALL_DIR) $(1)/www
$(INSTALL_DIR) $(1)/usr/share/clash
$(INSTALL_DIR) $(1)/usr/share/clash/web
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard/img
$(INSTALL_DIR) $(1)/usr/share/clash/dashboard/js

$(INSTALL_BIN) ./root/etc/init.d/clash $(1)/etc/init.d/clash
$(INSTALL_CONF) ./root/etc/config/clash $(1)/etc/config/clash
$(INSTALL_CONF) ./root/etc/clash/* $(1)/etc/clash/

$(INSTALL_BIN) ./root/usr/share/clash/clash-watchdog.sh $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/clash.sh $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/ipdb.sh $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/dns.yaml $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/clash_version $(1)/usr/share/clash/
$(INSTALL_BIN) ./root/usr/share/clash/check_version.sh $(1)/usr/share/clash/

$(INSTALL_BIN) ./root/usr/share/clash/web/* $(1)/usr/share/clash/web
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/index.html $(1)/usr/share/clash/dashboard/
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/main.5b2a02b81ea75793d649.css $(1)/usr/share/clash/dashboard/
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/img/33343e6117c37aaef8886179007ba6b5.png $(1)/usr/share/clash/dashboard/img/
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/img/logo.png $(1)/www/
$(INSTALL_BIN) ./root/usr/share/clash/dashboard/js/* $(1)/usr/share/clash/dashboard/js/

$(INSTALL_DATA) ./luasrc/controller/*.lua $(1)/usr/lib/lua/luci/controller/
$(INSTALL_DATA) ./luasrc/model/cbi/clash/*.lua $(1)/usr/lib/lua/luci/model/cbi/clash/
$(INSTALL_DATA) ./luasrc/view/clash/* $(1)/usr/lib/lua/luci/view/clash/
$(INSTALL_DATA) ./po/zh-cn/clash.zh-cn.lmo $(1)/usr/lib/lua/luci/i18n/

endef

$(eval $(call BuildPackage,luci-app-clash))
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<h1 align="center">
<img src="https://github.com/Dreamacro/clash/raw/master/docs/logo.png" alt="Clash" width="200">
<br>Clash for OpenWrt <br>

</h1>

<p align="center">
A rule based custom proxy for Openwrt based on <a href="https://github.com/Dreamacro/clash" target="_blank">Clash</a>.
</p>
<p align="center">
<a target="_blank" href="https://github.com/frainzy1477/clash/releases/tag/c0.15.0">
<img src="https://img.shields.io/badge/Clash-v0.15.0-orange.svg">
</a>
<a target="_blank" href="https://github.com/frainzy1477/luci-app-clash/releases/tag/v0.22.0">
<img src="https://img.shields.io/badge/luci%20for%20clash-v0.22.0-blue.svg">
</a>

</p>


## Usage

- Download and install clash ipk for openwrt [Download Clash ipk](https://github.com/frainzy1477/clash/releases/tag/c0.15.0) .

- Also Download and install luci for clash ipk [Download Luci for Clash ipk](https://github.com/frainzy1477/luci-app-clash/releases/tag/v0.22.0)


## Features
- Support sspanel Server subscription
- Support Manually config upload (config.yaml)
- GeoIP Database Update
- Iptables udp redirect
- IP Query / Website Access Check
- Proxy Lan IP(Client IP) that go through Proxy
- Bypass Lan IP(Client IP) that can't go through Proxy
- DNS Forwarding

## Dependency

- clash
- wget
- bash
- coreutils-nohup

## Clash on Other Platforms

- [Clash for Windows](https://github.com/Fndroid/clash_for_windows_pkg/releases) : A Windows GUI based on Clash
- [clashX](https://github.com/yichengchen/clashX) : A rule based custom proxy with GUI for Mac base on clash
- [ClashA](https://github.com/ccg2018/ClashA/tree/master) : An Android GUI for Clash
- [KoolClash OpenWrt/LEDE](https://github.com/SukkaW/Koolshare-Clash/tree/master) : A rule based custom proxy for Koolshare OpenWrt/LEDE based on Clash.

## License

Clash for OpenWrt is released under the MIT License - see detailed [LICENSE](https://github.com/frainzy1477/luci-app-clash/blob/rm/LICENSE) .

IP Query / Website Access Check based on knowledge from [MyIP](https://github.com/SukkaW/MyIP)

[Clash Dashboard](https://github.com/Dreamacro/clash-dashboard)

[Yet Another Clash Dashboard](https://github.com/haishanh/yacd)
74 changes: 74 additions & 0 deletions luasrc/controller/clash.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module("luci.controller.clash", package.seeall)

function index()
if not nixio.fs.access("/etc/config/clash") then
return
end


entry({"admin", "services", "clash"},alias("admin", "services", "clash", "overview"), _("Clash"), 60).dependent = true
entry({"admin", "services", "clash", "overview"},cbi("clash/overview"),_("Overview"), 10).leaf = true
entry({"admin", "services", "clash", "client"},cbi("clash/client"),_("Client"), 20).leaf = true
entry({"admin", "services", "clash", "settings"},cbi("clash/settings"),_("Settings"), 30).leaf = true
entry({"admin", "services", "clash", "config"},cbi("clash/config"),_("Config"), 40).leaf = true
entry({"admin","services","clash","status"},call("action_status")).leaf=true
entry({"admin", "services", "clash", "log"},cbi("clash/log"),_("Logs"), 50).leaf = true
entry({"admin","services","clash","check_status"},call("check_status")).leaf=true


end

local function dash_port()
return luci.sys.exec("uci get clash.config.dash_port 2>/dev/null")
end
local function dash_pass()
return luci.sys.exec("uci get clash.config.dash_pass 2>/dev/null")
end

local function is_running()
return luci.sys.call("pidof clash >/dev/null") == 0
end

local function is_web()
return luci.sys.call("pidof clash >/dev/null") == 0
end

local function localip()
return luci.sys.exec("uci get network.lan.ipaddr")
end

local function check_version()
return luci.sys.exec("sh /usr/share/clash/check_version.sh")
end

local function current_version()
return luci.sys.exec("sed -n 1p /usr/share/clash/clash_version")
end

local function new_version()
return luci.sys.exec("sed -n 1p /usr/share/clash/new_version")
end

function check_status()
luci.http.prepare_content("application/json")
luci.http.write_json({
check_version = check_version(),
current_version = current_version(),
new_version = new_version()

})
end
function action_status()
luci.http.prepare_content("application/json")
luci.http.write_json({
web = is_web(),
clash = is_running(),
localip = localip(),
dash_port = dash_port(),
current_version = current_version(),
new_version = new_version(),
dash_pass = dash_pass()

})
end

78 changes: 78 additions & 0 deletions luasrc/model/cbi/clash/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"


m = Map("clash")
s = m:section(TypedSection, "clash")
s.anonymous = true


o = s:option( Flag, "enable")
o.title = translate("Enable")
o.default = 0
o.rmempty = false
o.description = translate("After clash start running, wait a moment for servers to resolve")

o = s:option(Value, "proxy_port")
o.title = translate("Redir Port")
o.default = 7892
o.datatype = "port"
o.rmempty = false
o.description = translate("Redir Port")

o = s:option(Value, "dash_port")
o.title = translate("Dashboard Port")
o.default = 9090
o.datatype = "port"
o.rmempty = false
o.description = translate("Dashboard Port")

o = s:option(Value, "dash_pass")
o.title = translate("Dashboard Secret")
o.default = 123456
o.rmempty = false
o.description = translate("Dashboard Secret")


o = s:option(Flag, "auto_update", translate("Auto Update"))
o.rmempty = false
o.description = translate("Auto Update Server subscription")


o = s:option(ListValue, "auto_update_time", translate("Update time (every day)"))
for t = 0,23 do
o:value(t, t..":00")
end
o.default=0
o.rmempty = false
o.description = translate("Daily Server subscription update time")

o = s:option(Value, "subscribe_url")
o.title = translate("Subcription Url")
o.description = translate("Server Subscription Address")
o.rmempty = true

o = s:option(Button,"update")
o.title = translate("Update Subcription")
o.inputtitle = translate("Update Configuration")
o.inputstyle = "reload"
o.write = function()
os.execute("mv /etc/clash/config.yaml /etc/clash/config.bak")
SYS.call("bash /usr/share/clash/clash.sh >>/tmp/clash.log 2>&1 &")
HTTP.redirect(DISP.build_url("admin", "services", "clash", "client"))
end


local apply = luci.http.formvalue("cbi.apply")
if apply then
os.execute("/etc/init.d/clash restart >/dev/null 2>&1 &")
end


return m


80 changes: 80 additions & 0 deletions luasrc/model/cbi/clash/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"


local http = luci.http

ful = SimpleForm("upload", nil)
ful.reset = false
ful.submit = false

sul =ful:section(SimpleSection, "", translate(""))
o = sul:option(FileUpload, "")
o.title = translate("Upload Clash Configuration")
o.template = "clash/clash_upload"
o.description = translate("NB: Rename your config file to config.yaml before upload. file will save to /etc/clash")
um = sul:option(DummyValue, "", nil)
um.template = "clash/clash_dvalue"

local dir, fd
dir = "/etc/clash/"
http.setfilehandler(
function(meta, chunk, eof)
if not fd then
if not meta then return end

if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end

if not fd then
um.value = translate("upload file error.")
return
end
end
if chunk and fd then
fd:write(chunk)
end
if eof and fd then
fd:close()
fd = nil
um.value = translate("File saved to") .. ' "/etc/clash/' .. meta.file .. '"'
end
end
)

if luci.http.formvalue("upload") then


local f = luci.http.formvalue("ulfile")
if #f <= 0 then
um.value = translate("No specify upload file.")
end
end


m = Map("clash")
s = m:section(TypedSection, "clash")
s.anonymous = true
s.addremove=false


local conf = "/etc/clash/config.yaml"
sev = s:option(TextValue, "conf")
sev.readonly=true
update_time = SYS.exec("ls -l --full-time /etc/clash/config.yaml|awk '{print $6,$7;}'")
sev.description = update_time
--sev.description = translate("Changes to config file must be made from source")
sev.rows = 20
sev.wrap = "off"
sev.cfgvalue = function(self, section)
return NXFS.readfile(conf) or ""
end
sev.write = function(self, section, value)
end



return ful , m
Loading

0 comments on commit 3a492ec

Please sign in to comment.