Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
frainzy1477 committed Jan 17, 2020
1 parent a77cd7c commit ca021e4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion luasrc/model/cbi/clash/groups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ o:depends("type", "fallback")
o:depends("type", "load-balance")

o = s:option(DynamicList, "other_group", translate("Other Group"))
o.rmempty = false
o.rmempty = true
o.description = translate("Proxy Groups Must Exist In Rule")
o:value("ALL", translate("All Servers"))
uci:foreach("clash", "servers",
Expand Down
2 changes: 1 addition & 1 deletion luasrc/model/cbi/clash/provider-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ for t,f in ipairs(fss.glob("/etc/clash/provider/*"))do
end
end
end
o.rmempty = true
o.rmempty = false
o:depends("type", "file")


Expand Down
84 changes: 50 additions & 34 deletions root/usr/share/clash/proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REAL_LOG="/usr/share/clash/clash_real.txt"
lang=$(uci get luci.main.lang 2>/dev/null)
config_type=$(uci get clash.config.config_type 2>/dev/null)
create=$(uci get clash.config.create 2>/dev/null)
load_from=$(uci get clash.config.loadfrom 2>/dev/null)
load_from=$(uci get clash.config.loadfrom 2>/dev/null)


if [ "$load_from" == "sub" ];then
Expand All @@ -16,7 +16,6 @@ elif [ "$load_from" == "upl" ];then
load="/usr/share/clash/config/upload/config.yaml"
fi


if [ "${create}" -eq 1 ];then

if [ $lang == "en" ] || [ $lang == "auto" ];then
Expand All @@ -39,6 +38,8 @@ DNS_FILE="/usr/share/clash/dns.yaml"
PROVIDER_FILE="/tmp/yaml_provider.yaml"

gcount=$( grep -c "config groups" $CFG_FILE 2>/dev/null)
scount=$( grep -c "config servers" $CFG_FILE 2>/dev/null)
pcount=$( grep -c "config provider" $CFG_FILE 2>/dev/null)
if [ $gcount -eq 0 ];then
if [ $lang == "en" ] || [ $lang == "auto" ];then
echo "No policy group found. Aborting Operation .." >$REAL_LOG
Expand All @@ -51,7 +52,7 @@ PROVIDER_FILE="/tmp/yaml_provider.yaml"
fi
exit 0
fi
sleep 2
sleep 2



Expand Down Expand Up @@ -112,6 +113,19 @@ EOF

}

if [ $pcount -gt 0 ];then
config_load "clash"
config_foreach yml_proxy_provider_set "provider"
fi

if [ -f $PROVIDER_FILE ];then
sed -i "1i\ " $PROVIDER_FILE 2>/dev/null
sed -i "2i\proxy-provider:" $PROVIDER_FILE 2>/dev/null
#echo "proxy-provider:" >$PROVIDER_FILE
rm -rf /tmp/Proxy_Provider

fi


servers_set()
{
Expand Down Expand Up @@ -352,32 +366,32 @@ EOF
}



config_load "clash"
config_foreach yml_proxy_provider_set "provider"

if [ -f $PROVIDER_FILE ];then
sed -i "1i\ " $PROVIDER_FILE 2>/dev/null
sed -i "2i\proxy-provider:" $PROVIDER_FILE 2>/dev/null
#echo "proxy-provider:" >$PROVIDER_FILE
rm -rf /tmp/Proxy_Provider

fi


if [ $scount -gt 0 ];then
config_load clash
config_foreach servers_set "servers"
fi

if [ -z "${scount}" ] || [ "${scount}" -eq 0 ];then
cat >> "$SERVER_FILE" <<-EOF
- name: Shadowsocks
type: ss
server: 127.0.0.1
port: 1080
cipher: aes-256-gcm
password: "12345"
EOF
fi

if [ "$(ls -l $SERVER_FILE|awk '{print $5}')" -ne 0 ]; then

sed -i "1i\ " $SERVER_FILE 2>/dev/null
sed -i "2i\Proxy:" $SERVER_FILE 2>/dev/null

egrep '^ {0,}-' $SERVER_FILE |grep name: |awk -F 'name: ' '{print $2}' |sed 's/,.*//' >$Proxy_Group 2>&1

sed -i "s/^ \{0,\}/ - /" $Proxy_Group 2>/dev/null



yml_servers_add()
{

Expand Down Expand Up @@ -481,21 +495,21 @@ yml_groups_set()

if [ "$( grep -c "config provider" $CFG_FILE )" -ne 0 ];then

echo " use: $group_name" >>$GROUP_FILE

config_foreach set_proxy_provider "provider" "$group_name"

if [ "$set_group" -eq 1 ]; then
sed -i "/^ \{0,\}proxies: ${group_name}/c\ proxies:" $GROUP_FILE
else
sed -i "/proxies: ${group_name}/d" $GROUP_FILE 2>/dev/null
fi

if [ "$set_proxy_provider" -eq 1 ]; then
sed -i "/^ \{0,\}use: ${group_name}/c\ use:" $GROUP_FILE
else
sed -i "/use: ${group_name}/d" $GROUP_FILE 2>/dev/null
fi
echo " use: $group_name" >>$GROUP_FILE
config_foreach set_proxy_provider "provider" "$group_name"

if [ "$set_group" -eq 1 ]; then
sed -i "/^ \{0,\}proxies: ${group_name}/c\ proxies:" $GROUP_FILE
else
sed -i "/proxies: ${group_name}/d" $GROUP_FILE 2>/dev/null
fi

if [ "$set_proxy_provider" -eq 1 ]; then
sed -i "/^ \{0,\}use: ${group_name}/c\ use:" $GROUP_FILE
else
sed -i "/use: ${group_name}/d" $GROUP_FILE 2>/dev/null
fi

fi

Expand Down Expand Up @@ -561,7 +575,9 @@ EOF

cat $DNS_FILE >> $TEMP_FILE 2>/dev/null

if [ -f $SERVER_FILE ];then
cat $SERVER_FILE >> $TEMP_FILE 2>/dev/null
fi

cat $GROUP_FILE >> $TEMP_FILE 2>/dev/null

Expand Down Expand Up @@ -598,9 +614,9 @@ if pidof clash >/dev/null; then
fi
fi

fi
rm -rf $SERVER_FILE

rm -rf $SERVER_FILE
fi

}
create_config >/dev/null 2>&1

0 comments on commit ca021e4

Please sign in to comment.