v1.0.0beta15.2

~新增自定义http/sock5代理认证功能
~新增支持安装内置yacd面板
~增加自定义DNS配置功能
~优化安装脚本
~修复部分设备无法正常显示局域网连接ip/mac的bug
~修复iptables报错的bug
~同步最新版本Geoip数据库文件
This commit is contained in:
juewuy
2020-10-23 07:23:38 +08:00
parent 9e7799981b
commit a4b84dc55b
4 changed files with 679 additions and 627 deletions

BIN
bin/yacd.tar.gz Normal file

Binary file not shown.

View File

@@ -16,10 +16,13 @@ fi
ccfg=$clashdir/mark
yaml=$clashdir/config.yaml
#检查/读取标识文件
[ ! -f $ccfg ]&& echo '#标识clash运行状态的文件不明勿动' >> $ccfg
[ ! -f $ccfg ] && echo '#标识clash运行状态的文件不明勿动' > $ccfg
source $ccfg
#检查mac地址记录
[ ! -f $clashdir/mac ] && touch $clashdir/mac
#dashboard目录位置
[ -d /www/clash ] && dbdir=/www/clash && hostdir=/clash
[ -d $clashdir/ui ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui"
#开机自启相关
if [ -f /etc/rc.common ];then
if [ -n "$(find /etc/rc.d -name '*clash')" ];then
@@ -86,22 +89,6 @@ if [ -n "$PID" ];then
fi
echo -e "TG群\033[36;4mhttps://t.me/clashfm\033[0m"
echo -----------------------------------------------
#检查clash核心
if [ ! -f $clashdir/clash ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到核心文件请先下载clash核心\033[0m"
checkupdate
source $clashdir/getdate.sh
getcore
fi
#检查GeoIP数据库
if [ ! -f $clashdir/Country.mmdb ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到GeoIP数据库文件请下载数据库文件\033[0m"
checkupdate
source $clashdir/getdate.sh
getgeo
fi
#检查定时任务配置文件
if [ -z "$cronpath" ];then
[ -d /etc/crontabs/ ] && cronpath="/etc/crontabs/root"
@@ -110,14 +97,19 @@ if [ -z "$cronpath" ];then
[ -d /etc/storage/cron/crontabs ] && cronpath="/etc/storage/cron/crontabs/admin"
[ -n "$cronpath" ] && sed -i "1i\cronpath=\'$cronpath\'" $ccfg
fi
#检查新手引导
if [ -z "$userguide" ];then
read -p "检测到首次运行,是否启动新手引导?(1/0) > " res
echo -----------------------------------------------
sed -i "1i\userguide=1" $ccfg
[ "$res" = 1 ] && source $clashdir/getdate.sh && userguide
fi
}
start_over(){
[ $? -eq 1 ] && exit
echo -e "\033[32mclash服务已启动\033[0m"
if [ -d /www/clash ];then
echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则"
elif [ -d $clashdir/ui ];then
echo -e "请使用\033[30;47m http://$host:$db_port/ui \033[0m管理内置规则"
if [ -n "$dbdir" ];then
echo -e "请使用\033[30;47m http://$host$dbdir \033[0m管理内置规则"
else
echo -e "可使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m $db_port \033[0m"
@@ -293,6 +285,21 @@ checkport(){
done
}
clashstart(){
#检查clash核心
if [ ! -f $clashdir/clash ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到核心文件请先下载clash核心\033[0m"
checkupdate
source $clashdir/getdate.sh && getcore
fi
#检查GeoIP数据库
if [ ! -f $clashdir/Country.mmdb ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到GeoIP数据库文件请下载数据库文件\033[0m"
checkupdate
source $clashdir/getdate.sh && getgeo
fi
#检查yaml配置文件
if [ ! -f "$yaml" ];then
echo -----------------------------------------------
echo -e "\033[31m没有找到配置文件请先导入配置文件\033[0m"
@@ -631,7 +638,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read -p "是否配置自动代理PAC文件(1/0) > " res
if [ "$res" = 1 ]; then
source $clashdir/getdate.sh && catpac
source $clashdir/getdate.sh && setpac
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -758,7 +765,7 @@ echo -----------------------------------------------
echo -e " 1 使用自定义配置: \033[36m$modify_yaml\033[0m ————不使用内置规则修饰config.yaml"
echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定"
echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务"
echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————配置本机代理环境变量"
echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————使用环境变量或者PAC配置本机代理"
echo -e " 5 手动指定clash运行端口及秘钥"
echo -e " 6 手动配置内置DNS服务"
echo -----------------------------------------------
@@ -828,14 +835,14 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\local_proxy=已开启" $ccfg
local_proxy=已开启
$clashdir/start.sh set_proxy $mix_port
echo -e "\033[32m已经将代理参数写入环境变量~\033[0m"
$clashdir/start.sh set_proxy $mix_port $dbdir
echo -e "\033[32m已经成功配置本机代理~\033[0m"
echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m"
else
sed -i "1i\local_proxy=未开启" $ccfg
local_proxy=未开启
$clashdir/start.sh unset_proxy
echo -e "\033[33m已经将代理参数从环境变量移除\033[0m"
echo -e "\033[33m已经停用本机代理规则\033[0m"
fi
sleep 1
clashadv
@@ -924,7 +931,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 5 ]]; then
source $clashdir/getdate.sh
catpac
setpac
update
elif [[ $num == 7 ]]; then
@@ -1177,74 +1184,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
clashadv
elif [[ $num == 8 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m这里是测试命令菜单\033[0m"
echo -e "\033[33m如遇问题尽量运行相应命令后截图发群\033[0m"
echo -e "磁盘占用/所在目录:"
du -h $clashdir
echo -----------------------------------------------
echo " 1 查看clash运行时的报错信息"
echo " 2 查看系统DNS端口(:53)占用 "
echo " 3 测试ssl加密aes-128-gcm跑分"
echo " 4 查看iptables端口转发详情"
echo " 5 查看config.yaml前40行"
echo " 6 测试代理服务器连通性google.tw)"
echo -----------------------------------------------
echo " 0 返回上级目录!"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
elif [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
$clashdir/start.sh stop
echo -----------------------------------------------
$clashdir/clash -t -d $clashdir
echo -----------------------------------------------
echo -e "\033[31m如有报错请截图后到TG群询问\033[0m"
exit;
elif [[ $num == 2 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
netstat -ntulp |grep 53
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "可以使用\033[44m netstat -ntulp |grep xxx \033[0m来查询任意(xxx)端口"
exit;
elif [[ $num == 3 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
openssl speed -multi 4 -evp aes-128-gcm
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit;
elif [[ $num == 4 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iptables -t nat -L PREROUTING --line-numbers
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iptables -t nat -L clash --line-numbers
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iptables -t nat -L clash_dns --line-numbers
exit;
elif [[ $num == 5 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,40p' $yaml
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit;
elif [[ $num == 6 ]]; then
echo 注意:测试结果不保证一定准确!
delay=`curl -kx ${authentication}@127.0.0.1:$mix_port -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! & }` > /dev/null 2>&1
delay=`echo |awk "{print $delay*1000}"` > /dev/null 2>&1
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ `echo ${#delay}` -gt 1 ];then
echo -e "\033[32m连接成功响应时间为"$delay" ms\033[0m"
else
echo -e "\033[31m连接超时请重试或检查节点配置\033[0m"
fi
clashsh
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
fi
source $clashdir/getdate.sh && testcommand
elif [[ $num == 9 ]]; then
update

View File

@@ -422,8 +422,7 @@ else
sed -i "1i\clashv=$version" $ccfg
rm -rf /tmp/clashversion
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m$clashcore核心替换成功请手动启动clash服务\033[0m"
clashsh
echo -e "\033[32m$clashcore核心安装成功\033[0m"
fi
}
getgeo(){
@@ -448,14 +447,12 @@ if [ "$res" = '1' ]; then
sed -i '/Geo_v=*/'d $ccfg
sed -i "1i\Geo_v=$GeoIP_v" $ccfg
rm -rf /tmp/clashversion
clashsh
fi
else
clashsh
fi
}
getdb(){
#host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[36m安装本地版dashboard管理面板\033[0m"
echo -e "\033[32m打开管理面板的速度更快且更稳定\033[0m"
@@ -501,10 +498,10 @@ if [ -z "$num" ];then
update
elif [ "$num" = '1' ]; then
dbdir=$clashdir/ui
hostdir=":$db_port/ui\033[0;36m访问面板"
hostdir=":$db_port/ui"
elif [ "$num" = '2' ]; then
dbdir=/www/clash
hostdir='/clash\033[0;36m访问面板'
hostdir='/clash'
else
update
fi
@@ -546,26 +543,43 @@ fi
sed -i "s/7892/${db_port}/g" $dbdir/app*.js
fi
[ "$dbdir" != "/www/clash" ] && $clashdir/start.sh restart
#写入配置文件
sed -i '/dbdir*/'d $ccfg
sed -i "1i\dbdir=\'$hostdir\'" $ccfg
echo -----------------------------------------------
echo -e "\033[32m面板安装成功\033[0m"
echo -e "\033[36m请使用\033[32;4mhttp://$host$hostdir\033[0m"
echo -e "\033[36m请使用\033[32;4mhttp://$host$hostdir\033[0;36m访问面板\033[0m"
rm -rf /tmp/clashdb.tar.gz
sleep 1
update
fi
update
}
catpac(){
cat > $dbdir/pac <<EOF
function FindProxyForURL(url, host) {
if (
isInNet(host, "0.0.0.0", "255.0.0.0")||
isInNet(host, "10.0.0.0", "255.0.0.0")||
isInNet(host, "127.0.0.0", "255.0.0.0")||
isInNet(host, "224.0.0.0", "224.0.0.0")||
isInNet(host, "240.0.0.0", "240.0.0.0")||
isInNet(host, "172.16.0.0", "255.240.0.0")||
isInNet(host, "192.168.0.0", "255.255.0.0")||
isInNet(host, "169.254.0.0", "255.255.0.0")
)
return "DIRECT";
else
return "PROXY $host:$mix_port; DIRECT;"
}
EOF
}
setpac(){
#检测目录
[ -n "$authentication" ] && echo 检测到已经设置http代理密码pac不支持加密代理请先取消加密 && sleep 1 && clashadv
[ ! -d /www/clash -a ! -d $clashdir/ui ] && echo 未检测到本地Dashboard面板请先安装面板 && sleep 1 && getdb
#host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
[ -d /www/clash ]&&dir="/www/clash"&&pac=http://$host/clash/pac
[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:$db_port/ui/pac
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m生成用于设备WIFI或浏览器的自动PAC代理文件\033[0m"
echo -e "\033[33m纯净模式不推荐使用此功能\033[0m"
[ -f $dir/pac ]&&echo -e "PAC地址\033[32m$pac\033[0m"
echo -e "\033[33m适用于纯净模式或本机代理配置\033[0m"
[ -f $dbdir/pac ] && echo -e "PAC地址\033[32mhttp://$host$dbdir/pac\033[0m"
echo -----------------------------------------------
echo -e " 1 生成PAC文件"
echo -e " 2 清除PAC文件"
@@ -573,17 +587,13 @@ echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ "$num" = '1' ]; then
cat > $dir/pac <<EOF
function FindProxyForURL(url, host) {
return "PROXY $authentication@$host:$mix_port; DIRECT;"
}
EOF
catpac
echo -e "\033[33mPAC文件已生成\033[0m"
echo -e "PAC地址\033[32m$pac\033[0m"
echo -e "PAC地址\033[32mhttp://$host$dbdir/pac\033[0m"
echo "使用教程https://baike.baidu.com/item/PAC/16292100"
sleep 2
elif [[ $num == 2 ]]; then
rm -rf $dir/pac
rm -rf $dbdir/pac
echo -----------------------------------------------
echo -e "\033[33mPAC文件已清除\033[0m"
sleep 1
@@ -634,3 +644,85 @@ echo -e "\033[32m源地址更新成功\033[0m"
release_new=""
update
}
userguide(){
echo 欢迎使用ShellClash新手引导
checkupdate
getcore
getgeo
getdb
catpac
clashlink
}
testcommand(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m这里是测试命令菜单\033[0m"
echo -e "\033[33m如遇问题尽量运行相应命令后截图发群\033[0m"
echo -e "磁盘占用/所在目录:"
du -h $clashdir
echo -----------------------------------------------
echo " 1 查看clash运行时的报错信息"
echo " 2 查看系统DNS端口(:53)占用 "
echo " 3 测试ssl加密aes-128-gcm跑分"
echo " 4 查看iptables端口转发详情"
echo " 5 查看config.yaml前40行"
echo " 6 测试代理服务器连通性google.tw)"
echo " 7 重新进入新手引导"
echo -----------------------------------------------
echo " 0 返回上级目录!"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
elif [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
$clashdir/start.sh stop
echo -----------------------------------------------
$clashdir/clash -t -d $clashdir
echo -----------------------------------------------
echo -e "\033[31m如有报错请截图后到TG群询问\033[0m"
exit;
elif [[ $num == 2 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
netstat -ntulp |grep 53
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "可以使用\033[44m netstat -ntulp |grep xxx \033[0m来查询任意(xxx)端口"
exit;
elif [[ $num == 3 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
openssl speed -multi 4 -evp aes-128-gcm
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit;
elif [[ $num == 4 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iptables -t nat -L PREROUTING --line-numbers
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iptables -t nat -L clash --line-numbers
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iptables -t nat -L clash_dns --line-numbers
exit;
elif [[ $num == 5 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,40p' $yaml
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit;
elif [[ $num == 6 ]]; then
echo 注意:测试结果不保证一定准确!
delay=`curl -kx ${authentication}@127.0.0.1:$mix_port -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! & }` > /dev/null 2>&1
delay=`echo |awk "{print $delay*1000}"` > /dev/null 2>&1
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ `echo ${#delay}` -gt 1 ];then
echo -e "\033[32m连接成功响应时间为"$delay" ms\033[0m"
else
echo -e "\033[31m连接超时请重试或检查节点配置\033[0m"
fi
clashsh
elif [[ $num == 7 ]]; then
userguide
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
fi
}

View File

@@ -341,7 +341,7 @@ afstart(){
#标记启动时间
mark_time
#设置本机代理
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $dbdir
#启用面板配置自动保存
web_save_auto
#后台还原面板配置
@@ -406,12 +406,32 @@ web_save)
web_save
;;
set_proxy)
#GNOME配置
if gsettings --version >/dev/null 2>&1 ;then
gsettings set org.gnome.system.proxy autoconfig-url "http://127.0.0.1${3}/pac"
gsettings set org.gnome.system.proxy mode "auto"
#KDE配置
elif kwriteconfig5 -h >/dev/null 2>&1 ;then
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 2
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "Proxy Config Script" "http://127.0.0.1${3}/pac"
#环境变量方式
else
echo 'export all_proxy=http://127.0.0.1:'"$2" >> /etc/profile
echo 'export ALL_PROXY=$all_proxy' >> /etc/profile
fi
;;
unset_proxy)
#GNOME配置
if gsettings --version >/dev/null 2>&1 ;then
gsettings set org.gnome.system.proxy mode "none"
#KDE配置
elif kwriteconfig5 -h >/dev/null 2>&1 ;then
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 0
#环境变量方式
else
sed -i '/all_proxy/'d /etc/profile
sed -i '/ALL_PROXY/'d /etc/profile
fi
;;
esac