diff --git a/README.md b/README.md index 17715b3..b0ca46b 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,69 @@ ![飞天面条教保佑你的代码](https://cdn.rawgit.com/LunaGao/BlessYourCodeTag/master/tags/ramen.svg) -## 由于portal升级,queryString等参数发生变化,脚本暂时失效 - ### Openwrt路由器自动安装 在命令行中使用root权限运行以下代码即可 +不自动安装curl +````shell +wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/autoinstallNoUpdate.sh && chmod +x autoinstallNoUpdate.sh && sh autoinstallNoUpdate.sh ```` -wget --no-check-certificate https://raw.githubusercontent.com/EndangeredF1sh/UPCNet/bash/autoinstall.sh && chmod +x autoinstall.sh && sh autoinstall.sh +自动安装curl +````shell +wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/autoinstall.sh && chmod +x autoinstall.sh && sh autoinstall.sh ```` +### Openwrt路由器配置IPV6中继Relay +> 引用自[Yumao's Blog](https://www.yumao.name/read/openwrt-ipv6-bridge-or-nat6/) + +LUCI界面中LAN接口设置: +``` +路由通告服务:中继 +DHCPv6服务:中继 +NDP代理:中继 +``` +检查/etc/config/dhcp文件中,lan的相关参数 +``` +config dhcp 'lan' + option ra "relay" + option dhcp "relay" + option ndp "relay" +``` +修改 /etc/config/dhcp文件中,wan的相关参数 +``` +config dhcp 'wan' + option interface 'wan' + option dhcpv6 'relay' + option ra 'relay' + option ndp 'relay' + option master '1' + +``` +添加计划任务 +```shell +* * * * * /root/ipv6-bridge.sh +``` +/root/ipv6-bridge.sh如下: +```shell +#!/bin/sh +if [ -n "`ip -6 route show default|grep from -m 1`" ];then + logger -t "IPV6" change default gateway without from source + DEFAULT=`ip -6 route show default|grep from -m 1` + #刪除默認路由 + ip -6 route del ${DEFAULT} + #添加無from source路由 + ip -6 route add `echo ${DEFAULT}|sed -e 's/from [^ ]* //'` + #添加子網内設備通過br-lan訪問 + ip -6 route add `echo ${DEFAULT}|grep from|awk '{printf $3}'` dev br-lan metric 128 +fi +#刪除之前自動添加的錯誤路由 +ip -6 route list|grep -v default|grep -v br-lan|grep static|while read -r s; do ip -6 route del $s; done +#可選:可以根據需求自定義SUBNETEX的值,UPC校园网为240c +SUBNETEX="240c:" +ip -6 route list|grep -v default|grep -v br-lan|grep ${SUBNETEX}|while read -r s; do ip -6 route del $s; done +``` +```shell +chmod +x /root/ipv6-bridge.sh +``` ### 手动安装方法(其他Linux发行版,暂不支持pandavan) 在UPCNet.sh文件下输入学号(username)、密码(password)和运营商编号(service),然后运行 ``` diff --git a/UPCNet.sh b/UPCNet.sh index 8378812..87b4d8d 100644 --- a/UPCNet.sh +++ b/UPCNet.sh @@ -1,23 +1,40 @@ +cat="" +back="" username="" password="" service="" +usernameB="" +passwordB="" +serviceB="" + DATE=`date +%Y-%m-%d-%H:%M:%S` -tries=0 -echo --- my_watchdog start --- -while [[ $tries -lt 3 ]] +echo "Start detecting network connection status......" +ip_list="47.104.38.82,218.30.118.6,61.241.129.110" +ips=$(echo "$ip_list" | tr ',' ' ') +for ip in $ips do - if /bin/ping -c 1 114.114.114.114 >/dev/null + if /bin/ping -c 1 "$ip" >/dev/null then - echo --- exit --- + echo "The network connection is normal, enjoy~" + echo "---close script---" exit 0 fi - tries=$((tries+1)) - sleep 1 done +sleep 1 +echo "!!!ERROR: Network connection exception!!!" +echo "Start writing to the log and execute the login script..." +echo $DATE network offline and try to restart... ... >>my_watchdog.log +# /etc/init.d/network restart +# 重启网卡需要吗? +# sleep 3 -echo $DATE network restart >>my_watchdog.log -/etc/init.d/network restart -sleep 10 +if [ $cat == 2 ] +then + uci set openclash.config.enable='0' + uci commit openclash + /etc/init.d/openclash stop + sleep 10 +fi parameter='userId='${username}'&password='${password}'&service='${service}'&queryString=' location='http://121.251.251.207/eportal/InterFace.do?method=login' url=`curl -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" -o /dev/null -w %{url_effective} http://121.251.251.217` @@ -27,5 +44,60 @@ url=${url//&/%2526} url=${url//:/%253A} url=${url//\//%252F} parameter=${parameter}${url}'&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false' -echo $parameter +# echo $parameter +echo -e "Try to log in using the primary account\n" curl -X POST -d $parameter $location +sleep 8 +if [ $back == 2 ] +then +for ip in $ips +do + if /bin/ping -c 1 "$ip" >/dev/null + then + echo -e "\n" + echo "Log in with your primary account, the network is back to normal, enjoy~" + echo "---close script---" + if [ $cat == 2 ] + then + uci set openclash.config.enable='1' + uci commit openclash + reboot + fi + sleep 15 + exit 0 + fi +done +for ip in $ips +do + if /bin/ping -c 1 "$ip" >/dev/null + then + echo "The network connection is normal, enjoy~" + echo "---close script---" + exit 0 + fi +done +echo -e "FAILED, Start trying to log in with an alternate account\n" +parameterB='userId='${usernameB}'&password='${passwordB}'&service='${serviceB}'&queryString=' +parameterB=${parameterB}${url}'&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false' +# echo $parameterB +curl -X POST -d $parameterB $location +for ip in $ips +do + if /bin/ping -c 1 "$ip" >/dev/null + then + echo -e "\n" + echo "Log in with your alternate account, the network is back to normal, enjoy~" + echo "---close script---" + if [ $cat == 2 ] + then + uci set openclash.config.enable='1' + uci commit openclash + reboot + fi + sleep 15 + exit 0 + + fi +done +echo "You can't sign in with your existing account. Please check your configuration and other network settings and close script" +fi diff --git a/autoinstall.sh b/autoinstall.sh index 1a5b017..071641f 100644 --- a/autoinstall.sh +++ b/autoinstall.sh @@ -19,7 +19,13 @@ fi echo "Auto install start ..." opkg update opkg install curl -wget --no-check-certificate https://raw.githubusercontent.com/EndangeredF1sh/UPCNet/bash/UPCNet.sh && chmod +x UPCNet.sh +wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/UPCNet.sh && chmod +x UPCNet.sh +echo -n "If you have openclash? (1 for no, 2 for yes, default:1) -> " +read cat +cat=${cat:-1} +echo -n "If Backup? (1 for no,2 for yes, default:1) -> " +read bk +bk=${bk:-1} echo -n "input stuID -> " read stuID echo -n "input password -> " @@ -56,14 +62,65 @@ read -p "Enter selection [1-5] -> " num if [[ $num == 5 ]]; then service="local" fi +if [ $bk == 2 ] +then +echo -n "input stuID -> " +read stuIDB +echo -n "input password -> " +read passwdB +echo "Select your back service: +1. Campus Network Service +2. China Unicom Network Service +3. China Mobile Network Service +4. China Telecom Network Service +5. Campus Intranet +" +read -p "Enter selection [1-5] -> " num + if [ $num -lt 1 ] || [ $num -gt 5 ];then + echo "invalid selection, exit."; + exit; + fi + + if [[ $num == 1 ]]; then + serviceB="default" + fi + + if [[ $num == 2 ]]; then + serviceB="unicom" + fi + + if [[ $num == 3 ]]; then + serviceB="cmcc" + fi + + if [[ $num == 4 ]]; then + serviceB="ctcc" + fi + if [[ $num == 5 ]]; then + serviceB="local" + fi +fi -sed -i '1,3d' UPCNet.sh +if [ $bk == 2 ] +then +sed -i '1,8d' UPCNet.sh +sed -i "1i cat=\"$cat\"" UPCNet.sh +sed -i "1i back=\"$bk\"" UPCNet.sh sed -i "1i service=\"$service\"" UPCNet.sh sed -i "1i password=\"$passwd\"" UPCNet.sh sed -i "1i username=\"$stuID\"" UPCNet.sh - - +sed -i "1i serviceB=\"$serviceB\"" UPCNet.sh +sed -i "1i passwordB=\"$passwdB\"" UPCNet.sh +sed -i "1i usernameB=\"$stuIDB\"" UPCNet.sh +else +sed -i '1,5d' UPCNet.sh +sed -i "1i cat=\"$cat\"" UPCNet.sh +sed -i "1i back=\"$bk\"" UPCNet.sh +sed -i "1i service=\"$service\"" UPCNet.sh +sed -i "1i password=\"$passwd\"" UPCNet.sh +sed -i "1i username=\"$stuID\"" UPCNet.sh +fi croncmd="sh ${SHELL_FOLDER}"/UPCNet.sh"" cronjob="*/1 * * * * $croncmd" ( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab - diff --git a/autoinstallNoUpdate.sh b/autoinstallNoUpdate.sh new file mode 100644 index 0000000..27551cb --- /dev/null +++ b/autoinstallNoUpdate.sh @@ -0,0 +1,129 @@ +os_release_path="/etc/os-release" +openwrt_release_path="/etc/openwrt_release" +SHELL_FOLDER=$(dirname $(readlink -f "$0")) +if [ -f "$os_release_path" ];then + source /etc/os-release +else + if [ -f "$openwrt_release_path" ];then + ID="openwrt" + fi +fi + +if [[ $ID != "openwrt" ]];then + read -r -p "Mismatch Operation System Detected, Are you sure to install? [Y/n] " response + if [[ $response != "y" && $response != "Y" ]];then + exit 0 + fi +fi + +echo "Auto install start ..." +wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/UPCNet.sh && chmod +x UPCNet.sh +echo -n "If you have openclash? (1 for no, 2 for yes, default:1) -> " +read cat +cat=${cat:-1} +echo -n "If Backup? (1 for no,2 for yes, default:1) -> " +read bk +bk=${bk:-1} +echo -n "input stuID -> " +read stuID +echo -n "input password -> " +read passwd +echo "Select your service: +1. Campus Network Service +2. China Unicom Network Service +3. China Mobile Network Service +4. China Telecom Network Service +5. Campus Intranet +" +read -p "Enter selection [1-5] -> " num + if [ $num -lt 1 ] || [ $num -gt 5 ];then + echo "invalid selection, exit."; + exit; + fi + + if [[ $num == 1 ]]; then + service="default" + fi + + if [[ $num == 2 ]]; then + service="unicom" + fi + + if [[ $num == 3 ]]; then + service="cmcc" + fi + + if [[ $num == 4 ]]; then + service="ctcc" + fi + + if [[ $num == 5 ]]; then + service="local" + fi +if [ $bk == 2 ] +then +echo -n "input stuID -> " +read stuIDB +echo -n "input password -> " +read passwdB +echo "Select your back service: +1. Campus Network Service +2. China Unicom Network Service +3. China Mobile Network Service +4. China Telecom Network Service +5. Campus Intranet +" +read -p "Enter selection [1-5] -> " num + if [ $num -lt 1 ] || [ $num -gt 5 ];then + echo "invalid selection, exit."; + exit; + fi + + if [[ $num == 1 ]]; then + serviceB="default" + fi + + if [[ $num == 2 ]]; then + serviceB="unicom" + fi + + if [[ $num == 3 ]]; then + serviceB="cmcc" + fi + + if [[ $num == 4 ]]; then + serviceB="ctcc" + fi + + if [[ $num == 5 ]]; then + serviceB="local" + fi +fi + +if [ $bk == 2 ] +then +sed -i '1,8d' UPCNet.sh +sed -i "1i cat=\"$cat\"" UPCNet.sh +sed -i "1i back=\"$bk\"" UPCNet.sh +sed -i "1i service=\"$service\"" UPCNet.sh +sed -i "1i password=\"$passwd\"" UPCNet.sh +sed -i "1i username=\"$stuID\"" UPCNet.sh +sed -i "1i serviceB=\"$serviceB\"" UPCNet.sh +sed -i "1i passwordB=\"$passwdB\"" UPCNet.sh +sed -i "1i usernameB=\"$stuIDB\"" UPCNet.sh +else +sed -i '1,5d' UPCNet.sh +sed -i "1i cat=\"$cat\"" UPCNet.sh +sed -i "1i back=\"$bk\"" UPCNet.sh +sed -i "1i service=\"$service\"" UPCNet.sh +sed -i "1i password=\"$passwd\"" UPCNet.sh +sed -i "1i username=\"$stuID\"" UPCNet.sh +fi +croncmd="sh ${SHELL_FOLDER}"/UPCNet.sh"" +cronjob="*/1 * * * * $croncmd" +( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab - + +sed -i "2a ${croncmd}" /etc/rc.local + +echo "Auto Install Finished. Enjoy." +rm -- "$0"