├── README.md ├── armv7_shadowsocks ├── ss-start ├── ss-nat └── shadowsocks └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # dd-wrt-shadowsocks 2 | 3 | Copyright (C) 2016 Jason Lin 4 | 5 | Version: V1.5-stable 6 | 7 | # Installation 8 | 9 | **See my [DD-WRT-ShadowSocks(armv7)](http://www.router008.com/2016/05/09/DD-WRT-ShadowSocks/)** 10 | 11 | # Usage wiki 12 | 13 | **[shadowsocks Scripting Guide](http://www.router008.com/2016/02/14/ShadowSocks-Scripting-Guide/)** 14 | 15 | # Support 16 | 17 | - NETGEAR: 18 | **R6300V2 R7000 R6700 AC1450 R6250** 19 | 20 | # NOTE 21 | 22 | **Script applications: These scripts are only apply to those [Firmware](http://entware.mirrors.ligux.com/DD-WRT/K3-AC-ARM/R29846/)** -------------------------------------------------------------------------------- /armv7_shadowsocks/ss-start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2016 DD-WRT 4 | # Copyright (C) 2016 Jason Lin 5 | # Main author: Jason Lin && wojiaolinmu008 6 | # This is free software, licensed under the GNU General Public License v3. 7 | # See /LICENSE for more information. 8 | # 9 | 10 | # debug 11 | #set -x 12 | 13 | if [ ! -d "/opt/etc/shadowsocks" ]; then 14 | mkdir -p /opt/etc/shadowsocks/WAN_AC_FW && \ 15 | mkdir -p /opt/etc/shadowsocks/WAN_AC_BP && \ 16 | mkdir -p /opt/etc/shadowsocks/LAN_AC_FW && \ 17 | mkdir -p /opt/etc/shadowsocks/LAN_AC_BP 18 | fi 19 | 20 | server_ip=`sed -n 's/.*ver": *"\(.*\)".*/\1/p' /opt/etc/shadowsocks.json` 21 | local_port=`sed -n 's/.*l_port": *\(.*\)/\1/p' /opt/etc/shadowsocks.json | sed 's/,//g'` 22 | ignore_list=/opt/etc/ignore.list 23 | wan_ac_list_fw=/opt/etc/shadowsocks/WAN_AC_FW/wan_ac.list 24 | wan_ac_list_bp=/opt/etc/shadowsocks/WAN_AC_BP/wan_ac.list 25 | lan_ac_list_fw=/opt/etc/shadowsocks/LAN_AC_FW/lan_ac.list 26 | lan_ac_list_bp=/opt/etc/shadowsocks/LAN_AC_BP/lan_ac.list 27 | 28 | [ ! -f "$wan_ac_list_fw" -o ! -f "$wan_ac_list_bp" ] && \ 29 | touch a $wan_ac_list_fw && \ 30 | touch a $wan_ac_list_bp 31 | 32 | [ ! -f "$lan_ac_list_in" -o ! -f "$lan_ac_list_out" ] && \ 33 | touch a $lan_ac_list_fw && \ 34 | touch a $lan_ac_list_bp 35 | 36 | WAN_AC_FW=`sort -t'.' -nk1,1 -nk2,3 -nk3,3 -nk4,4 $wan_ac_list_fw | xargs` 37 | WAN_AC_BP=`sort -t'.' -nk1,1 -nk2,3 -nk3,3 -nk4,4 $wan_ac_list_bp | xargs` 38 | 39 | LAN_AC_FW=`sort -t'.' -nk1,1 -nk2,3 -nk3,3 -nk4,4 $lan_ac_list_fw | xargs` 40 | LAN_AC_BP=`sort -t'.' -nk1,1 -nk2,3 -nk3,3 -nk4,4 $lan_ac_list_bp | xargs` 41 | 42 | PROCS=ss-nat 43 | BIN=/opt/bin 44 | START=$BIN/$PROCS 45 | IFNAME=`nvram get lan_ifname` 46 | 47 | chnroutes() { 48 | $START -s $server_ip -l $local_port -i $ignore_list -o -e "-m multiport --dports 22,80,443" \ 49 | -d SS_SPEC_WAN_AC \ 50 | -I $IFNAME \ 51 | -b "$WAN_AC_BP" \ 52 | -w "$WAN_AC_FW" \ 53 | -a "b,$LAN_AC_BP" \ 54 | -u 55 | 56 | exit 0 57 | } 58 | 59 | gfwlist() { 60 | $START -s $server_ip -l $local_port -i /dev/null -o -e "-m multiport --dports 22,80,443" \ 61 | -d SS_SPEC_WAN_AC \ 62 | -I $IFNAME \ 63 | -b "0.0.0.0/1 128.0.0.0/1" \ 64 | -u 65 | 66 | exit 0 67 | } 68 | 69 | [ -f /var/log/chnroutes.lock ] && chnroutes 70 | [ -f /var/log/gfwlist.lock ] && gfwlist || exit 0 -------------------------------------------------------------------------------- /armv7_shadowsocks/ss-nat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2016 DD-WRT 4 | # Copyright (C) 2016 Jian Chang && Jason Lin 5 | # Main author: Jian Chang && Jason Lin 6 | # This is free software, licensed under the GNU General Public License v3. 7 | # See /LICENSE for more information. 8 | # 9 | 10 | # debug 11 | #set -x 12 | 13 | IPT="/usr/iptables/iptables -t nat" 14 | IPT_M="/usr/iptables/iptables -t mangle" 15 | IPTS="/usr/sbin/iptables-restore" 16 | TAG="ss_spec" 17 | 18 | usage() { 19 | cat <<-EOF 20 | Usage: ss-nat [options] 21 | 22 | Valid options are: 23 | 24 | -s ip address of shadowsocks remote server 25 | -l port number of shadowsocks local server 26 | -i a file content is bypassed ip list 27 | -b wan ip of will be bypassed 28 | -w wan ip of will be forwarded 29 | -I proxy only for the given interface 30 | -d the default target of lan access control 31 | -a lan ip of access control, need a prefix to 32 | define access control mode 33 | -e extra options for iptables 34 | -o apply the rules to the OUTPUT chain 35 | -u enable udprelay mode, TPROXY is required 36 | -f flush the rules 37 | -h show this help message and exit 38 | EOF 39 | exit $1 40 | } 41 | 42 | loger() { 43 | # 1.alert 2.crit 3.err 4.warn 5.notice 6.info 7.debug 44 | logger -st ss-rules[$$] -p$1 $2 45 | } 46 | 47 | flush_rules() { 48 | $IPT -F 2>/dev/null 49 | $IPT_M -F 2>/dev/null 50 | $IPT -X SS_SPEC_WAN_AC 2>/dev/null 51 | $IPT -X SS_SPEC_WAN_FW 2>/dev/null 52 | $IPT -X SS_SPEC_LAN_DG 2>/dev/null 53 | $IPT -X SS_SPEC_LAN_AC 2>/dev/null 54 | $IPT_M -X SS_SPEC_LAN_DG 2>/dev/null 55 | $IPT_M -X SS_SPEC_LAN_AC 2>/dev/null 56 | $IPT_M -X SS_SPEC_WAN_AC 2>/dev/null 57 | $IPT_M -X SS_SPEC_WAN_FW 2>/dev/null 58 | ip rule del fwmark 0x01/0x01 table 100 2>/dev/null 59 | ip route del local 0.0.0.0/0 dev lo table 100 2>/dev/null 60 | for setname in $(ipset -n list | grep -i "$TAG"); do 61 | ipset destroy $setname 2>/dev/null 62 | done 63 | our_rule 64 | return 0 65 | } 66 | 67 | our_rule() { 68 | $IPTS /tmp/.ipt 69 | } 70 | 71 | ipset_init() { 72 | ipset -! restore <<-EOF || return 1 73 | create ss_spec_src_ac hash:ip hashsize 64 74 | create ss_spec_src_bp hash:ip hashsize 64 75 | create ss_spec_src_fw hash:ip hashsize 64 76 | create ss_spec_dst_sp hash:net hashsize 64 77 | create ss_spec_dst_bp hash:net hashsize 64 78 | create ss_spec_dst_fw hash:net hashsize 64 79 | $(gen_lan_host_ipset_entry) 80 | $(gen_special_purpose_ip | sed -e "s/^/add ss_spec_dst_sp /") 81 | $(sed -e "s/^/add ss_spec_dst_bp /" ${IGNORED:=/dev/null} 2>/dev/null) 82 | $(for ip in $WAN_BP_IP; do echo "add ss_spec_dst_bp $ip"; done) 83 | $(for ip in $WAN_FW_IP; do echo "add ss_spec_dst_fw $ip"; done) 84 | EOF 85 | return 0 86 | } 87 | 88 | ipt_nat() { 89 | include_ac_rules nat 90 | $IPT -A SS_SPEC_WAN_FW -p tcp \ 91 | -j REDIRECT --to-ports $local_port || return 1 92 | if [ "$OUTPUT" = 1 ]; then 93 | $IPT -N SS_SPEC_WAN_DG 94 | $IPT -A SS_SPEC_WAN_DG -m set --match-set ss_spec_dst_sp dst -j RETURN 95 | $IPT -A SS_SPEC_WAN_DG -p tcp $EXT_ARGS -j SS_SPEC_WAN_AC 96 | $IPT -I OUTPUT 1 -p tcp -j SS_SPEC_WAN_DG 97 | fi 98 | return $? 99 | } 100 | 101 | ipt_mangle() { 102 | [ -n "$TPROXY" ] || return 0 103 | if !(dmesg | grep -q TPROXY && command -v ip >/dev/null); then 104 | loger 4 "TPROXY or ip not found." 105 | return 0 106 | fi 107 | ip rule add fwmark 1 lookup 100 108 | ip route add local default dev lo table 100 109 | include_ac_rules mangle 110 | $IPT_M -A SS_SPEC_WAN_FW -p udp \ 111 | -j TPROXY --on-port $LOCAL_PORT --tproxy-mark 0x01/0x01 112 | return $? 113 | } 114 | 115 | gen_lan_host_ipset_entry() { 116 | for host in $LAN_HOSTS; do 117 | case "${host:0:1}" in 118 | n|N) 119 | echo add ss_spec_src_ac ${host:2} 120 | ;; 121 | b|B) 122 | echo add ss_spec_src_bp ${host:2} 123 | ;; 124 | g|G) 125 | echo add ss_spec_src_fw ${host:2} 126 | ;; 127 | esac 128 | done 129 | } 130 | 131 | gen_special_purpose_ip() { 132 | cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" 133 | 0.0.0.0/8 134 | 10.0.0.0/8 135 | 100.64.0.0/10 136 | 127.0.0.0/8 137 | 169.254.0.0/16 138 | 172.16.0.0/12 139 | 192.0.0.0/24 140 | 192.0.2.0/24 141 | 192.31.196.0/24 142 | 192.52.193.0/24 143 | 192.88.99.0/24 144 | 192.168.0.0/16 145 | 192.175.48.0/24 146 | 198.18.0.0/15 147 | 198.51.100.0/24 148 | 203.0.113.0/24 149 | 224.0.0.0/4 150 | 240.0.0.0/4 151 | 255.255.255.255 152 | $server 153 | EOF 154 | } 155 | 156 | include_ac_rules() { 157 | local protocol=$([ "$1" = "mangle" ] && echo udp || echo tcp) 158 | /usr/iptables/iptables-restore -n <<-EOF 159 | *$1 160 | :SS_SPEC_LAN_DG - [0:0] 161 | :SS_SPEC_LAN_AC - [0:0] 162 | :SS_SPEC_WAN_AC - [0:0] 163 | :SS_SPEC_WAN_FW - [0:0] 164 | -A SS_SPEC_LAN_DG -m set --match-set ss_spec_dst_sp dst -j RETURN 165 | -A SS_SPEC_LAN_DG -p $protocol $EXT_ARGS -j SS_SPEC_LAN_AC 166 | -A SS_SPEC_LAN_AC -m set --match-set ss_spec_src_bp src -j RETURN 167 | -A SS_SPEC_LAN_AC -m set --match-set ss_spec_src_fw src -j SS_SPEC_WAN_FW 168 | -A SS_SPEC_LAN_AC -m set --match-set ss_spec_src_ac src -j SS_SPEC_WAN_AC 169 | -A SS_SPEC_LAN_AC -j ${LAN_TARGET:=SS_SPEC_WAN_AC} 170 | -A SS_SPEC_WAN_AC -m set --match-set ss_spec_dst_fw dst -j SS_SPEC_WAN_FW 171 | -A SS_SPEC_WAN_AC -m set --match-set ss_spec_dst_bp dst -j RETURN 172 | -A SS_SPEC_WAN_AC -j SS_SPEC_WAN_FW 173 | $(gen_prerouting_rules $protocol) 174 | COMMIT 175 | EOF 176 | } 177 | 178 | gen_prerouting_rules() { 179 | [ -z "$IFNAMES" ] && echo -I PREROUTING 1 -p $1 -j SS_SPEC_LAN_DG 180 | for ifname in $IFNAMES; do 181 | echo -I PREROUTING 1 -i $ifname -p $1 -j SS_SPEC_LAN_DG 182 | done 183 | } 184 | 185 | while getopts ":s:l:i:b:w:I:d:a:e:oufh" arg; do 186 | case "$arg" in 187 | s) 188 | server=$(for ip in $OPTARG; do echo $ip; done) 189 | ;; 190 | l) 191 | local_port=$OPTARG 192 | ;; 193 | i) 194 | IGNORED=$OPTARG 195 | ;; 196 | b) 197 | WAN_BP_IP=$OPTARG 198 | ;; 199 | w) 200 | WAN_FW_IP=$OPTARG 201 | ;; 202 | I) 203 | IFNAMES=$OPTARG 204 | ;; 205 | d) 206 | LAN_TARGET=$OPTARG 207 | ;; 208 | a) 209 | LAN_HOSTS=$OPTARG 210 | ;; 211 | e) 212 | EXT_ARGS=$OPTARG 213 | ;; 214 | o) 215 | OUTPUT=1 216 | ;; 217 | u) 218 | TPROXY=1 219 | ;; 220 | f) 221 | flush_rules 222 | exit 0 223 | ;; 224 | h) 225 | usage 0 226 | ;; 227 | esac 228 | done 229 | 230 | if [ -z "$server" -o -z "$local_port" ]; then 231 | usage 2 232 | fi 233 | 234 | if [ "$TPROXY" = 1 ]; then 235 | SERVER=$server 236 | LOCAL_PORT=$local_port 237 | fi 238 | 239 | flush_rules && ipset_init && ipt_nat && ipt_mangle 240 | RET=$? 241 | [ "$?" = 0 ] && loger 3 "Load chnroutes successful" || loger 3 "Start failed!" 242 | exit $RET -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | -------------------------------------------------------------------------------- /armv7_shadowsocks/shadowsocks: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2015-2016 DD-WRT shadowsocks 4 | # Copyright (C) 2015-2016 Jason Lin 5 | # -------------------------------------------------------------------------------------------------------- 6 | # This is free software, licensed under the GNU General Public License v3. 7 | # See /LICENSE for more information. 8 | # -------------------------------------------------------------------------------------------------------- 9 | # 10 | 11 | # Debug 12 | #set -x 13 | 14 | # opkg source site 15 | OPKG_SITE="http://entware.mirrors.ligux.com/binaries" 16 | 17 | # Architecture 18 | ARCH="armv7" 19 | 20 | # SMTP server (EP:"smtp.gmail.com") 21 | SMTP="smtp.163.com" 22 | # Send E-mail Username 23 | username="" 24 | # Send E-mail password 25 | password="" 26 | # Sender E-mail 27 | FROM="" 28 | # E-mail Subject 29 | TITLE="ShadowSocks" 30 | # Content of E-mail 31 | CONTENT="Your tools running over the wall!" 32 | # Target E-mail address 33 | TO="" 34 | 35 | # Check DNS 36 | check_dns=0 37 | 38 | READ="\033[31;1m" 39 | BOLD="\033[42;1m" 40 | NORM="\033[0m" 41 | ansi_red="\033[1;31m"; 42 | ansi_white="\033[1;37m"; 43 | ansi_green="\033[1;32m"; 44 | ansi_yellow="\033[1;33m"; 45 | ansi_blue="\033[1;34m"; 46 | ansi_bell="\007"; 47 | ansi_blink="\033[5m"; 48 | ansi_std="\033[m"; 49 | ansi_rev="\033[7m"; 50 | ansi_ul="\033[4m"; 51 | INFO="$BOLD INFO: $NORM" 52 | WARNING="$READ WARNING: $NORM" 53 | MOUNT="$ansi_white MOUNT: " 54 | DEPENDENCE="$ansi_white DEPENDENCE: " 55 | PLATFORM="$ansi_white PLATFORM: " 56 | PACKAGES="$ansi_white PACKAGES: " 57 | SHADOWSOCKS="$ansi_white SHADOWSOCKS: " 58 | START_SCRIPT="$ansi_white START_SCRIPT: " 59 | ShadowSocks_Account="$ansi_white ShadowSocks_Account: " 60 | ss_switch="$ansi_white ss_switch: " 61 | update_scr="$ansi_white update_scr: " 62 | backup="$ansi_white backup: " 63 | 64 | # You can mount the partition path editing (EP:"/jffs" or "/tmp/mnt/sda1" ) 65 | PREFIX=/jffs 66 | SCRIPT_DIR=$(dirname ${0}) 67 | SCRIPT_DIR=$(cd ${SCRIPT_DIR} && pwd) 68 | 69 | # Time 70 | DATE=$(date "+%Y-%m-%d %H:%M:%S") 71 | 72 | # Schduler 73 | CHECK=/opt/etc 74 | 75 | # Link 76 | ops_list="http://entware.mirrors.ligux.com/opslist/opslist.conf" 77 | china_routing_list="http://entware.mirrors.ligux.com/apnic/delegated-apnic-latest" 78 | china_domain_list="http://entware.mirrors.ligux.com/dnsmasq-china-list/accelerated-domains.china.conf" 79 | china_google_list="http://entware.mirrors.ligux.com/dnsmasq-china-list/google.china.conf" 80 | 81 | # alias of iptables 82 | IPT="/usr/iptables/iptables -t nat" 83 | 84 | case ${1} in 85 | 86 | -su | --set_up) 87 | DECIVE=$(cat /proc/cpuinfo | grep "ARMv7" | grep -v "grep") 88 | if [ -z "$DECIVE" ]; then 89 | echo -e -n $PLATFORM 90 | sleep 1 91 | echo -e "$ansi_red ERROR. $ansi_std" 92 | echo -e $WARNING $BOLD This script is not suitable for the platform,can not continue.$NORM 93 | exit 0 94 | else 95 | if [ ! -d "$PREFIX/shadowsocks" ]; then 96 | echo -e $INFO "Creating in..." 97 | entware() { 98 | cd $PREFIX;wget $OPKG_SITE/$ARCH/backup/entware_backup.tar.gz 99 | sha1sum_entware="ffc285b0c4ded845c499508b365394ed77b682c1" 100 | checksum=`sha1sum $PREFIX/entware_backup.tar.gz | sed "s/ .*//"` 101 | if [ ! "$sha1sum_entware" == "$checksum" ]; then 102 | echo "$ansi_red entware-ng installation failed $ansi_std" 103 | exit 0 104 | fi 105 | tar -zxvf entware_backup.tar.gz 106 | [ -f $PREFIX/entware_backup.tar.gz ] && rm -rf $PREFIX/entware_backup.tar.gz 107 | } 108 | entware 109 | cd /tmp/root 110 | mkdir -p $PREFIX/shadowsocks 111 | cp $SCRIPT_DIR/shadowsocks $PREFIX/shadowsocks 112 | mount -o bind $PREFIX/opt /opt 113 | /opt/bin/opkg update 114 | if [ -e $SCRIPT_DIR/chinadns* -a -e $SCRIPT_DIR/diff* -a -e $SCRIPT_DIR/pcap_dns* -a -e $SCRIPT_DIR/pdns* -a -e $SCRIPT_DIR/shadowsocks-libe* -a -e $SCRIPT_DIR/dnscryp* ]; then 115 | cd $SCRIPT_DIR && opkg install --force-checksum china* pdnsd* pcap* shadowsocks-libe* diff* dnscry* 116 | echo -e "$ansi_green SHADOWSOCKS script installed successfully! $ansi_std" 117 | sleep 5 118 | ln -s $PREFIX/shadowsocks/shadowsocks /opt/bin 119 | else 120 | echo -e "$ansi_red You do not import the entire IPK! $ansi_std" 121 | exit 0 122 | fi 123 | else 124 | echo -e "$ansi_yellow SHADOWSOCKS already installed! $ansi_std" 125 | fi 126 | echo -e -n $PLATFORM 127 | sleep 1 128 | echo -e "$ansi_green PASS. $ansi_std" 129 | fi 130 | 131 | autorun=/opt/etc/init.d/auto.run 132 | if [ ! -f "$autorun" ]; then 133 | echo "#!/bin/sh" >> $autorun 134 | echo >> $autorun 135 | echo -e "mount -o bind $PREFIX/opt /opt" >> $autorun 136 | echo "/opt/bin/shadowsocks -m" >> $autorun 137 | echo "/opt/bin/shadowsocks -S" >> $autorun 138 | echo "sleep 1" >> $autorun 139 | echo "/opt/bin/shadowsocks -r" >> $autorun 140 | echo "stopservice cron && startservice cron" >> $autorun 141 | echo >> $autorun 142 | 143 | sleep 1 144 | chmod +x $autorun 145 | ln -s $autorun /opt/bin 146 | fi 147 | 148 | if [ -d "$PREFIX/shadowsocks" ]; then 149 | echo -e -n $SHADOWSOCKS 150 | sleep 1 151 | echo -e "$ansi_green PASS. $ansi_std" 152 | else 153 | echo -e -n $SHADOWSOCKS 154 | sleep 1 155 | echo -e "$ansi_red ERROR. $ansi_std" 156 | rm -rf $PREFIX/opt 157 | echo -e $WARNING $BOLD"Please install the SHADOWSOCKS script."$NORM 158 | exit 0 159 | fi 160 | 161 | if [ "`ls -A /opt`" = "" ]; then 162 | echo -e -n $MOUNT 163 | sleep 1 164 | echo -e "$ansi_red ERROR. $ansi_std" 165 | rm -rf $PREFIX/opt 166 | echo -e $WARNING $BOLD"OPT directory does not mount."$NORM 167 | exit 0 168 | else 169 | echo -e -n $MOUNT 170 | sleep 1 171 | echo -e "$ansi_green PASS. $ansi_std" 172 | fi 173 | 174 | BIN=/opt/bin 175 | SBIN=/opt/sbin 176 | echo -e "chinadns \ndiff \ndnscrypt-proxy \nPcap_DNSProxy \npdnsd-ctl \nss-redir" > /var/log/find.txt 177 | cd $BIN 178 | if [ ! -f chinadns -o ! -f Pcap_DNSProxy -o ! -f ss-redir -o ! -f pdnsd-ctl -o ! -f diff -o ! -f dnscrypt-proxy ]; then 179 | ls -1 chinadns Pcap_DNSProxy ss-redir pdnsd-ctl diff dnscrypt-proxy > /var/log/find_N.txt 180 | else 181 | ls -1 chinadns Pcap_DNSProxy ss-redir pdnsd-ctl diff dnscrypt-proxy > /var/log/find_N.txt 182 | fi 183 | cd / 184 | 185 | find $BIN/chinadns $BIN/Pcap_DNSProxy $BIN/ss-redir $BIN/pdnsd-ctl $BIN/diff $BIN/dnscrypt-proxy &> /dev/null;echo $? > /var/log/diff.txt 186 | DIFF=`sed -n '1p' /var/log/diff.txt` 187 | diff -w /var/log/find.txt /var/log/find_N.txt | grep \^\< > /var/log/diff_show.txt 188 | if [ "$DIFF" == "0" ]; then 189 | echo -e -n $DEPENDENCE 190 | sleep 1 191 | echo -e "$ansi_green PASS. $ansi_std" 192 | else 193 | if [ ! -e $BIN/chinadns -a ! -e $BIN/diff -a ! -e $BIN/Pcap_DNSProxy -a ! -e $BIN/pdnsd-ctl -a ! -e $BIN/ss-redir -a ! -e $BIN/dnscrypt-proxy ]; then 194 | echo -e $DEPENDENCE 195 | sleep 1 196 | echo -e "$ansi_red ERROR. $ansi_std" 197 | echo -e "$WARNING \n$BOLD Please install the following software:"$NORM 198 | rm -rf $PREFIX/opt 199 | echo -e $ansi_white"shadowsocks-libev \nchinadns \npdnsd \npcap-dnsproxy \ndiffutils \ndnscrypt-proxy"$ansi_std 200 | exit 0 201 | else 202 | echo -e $DEPENDENCE 203 | sleep 1 204 | echo -e "$ansi_red ERROR. $ansi_std" 205 | echo -e "$WARNING \n$BOLD Please install the following software:"$NORM 206 | rm -rf $PREFIX/opt 207 | cat /var/log/diff_show.txt 208 | exit 0 209 | fi 210 | fi 211 | 212 | if [ -f "$autorun" ]; then 213 | echo -e -n $START_SCRIPT 214 | sleep 1 215 | echo -e "$ansi_green PASS. $ansi_std" 216 | fi 217 | 218 | yes_or_no() { 219 | read -p "$1 ([y]es or [n]o): " 220 | case $(echo $REPLY | tr '[A-Z]' '[a-z]') in 221 | y|yes) echo "yes" ;; 222 | *) echo "no" ;; 223 | esac 224 | } 225 | 226 | echo "============================================" 227 | echo "Please input your shadowsocks account information:" 228 | read -p "(Your Server IP):" IP 229 | read -p "(Your Server Port):" port 230 | read -p "(Your Local Port):" PORT 231 | read -p "(Your Password):" password 232 | read -p "(Your Encryption Method):" method 233 | echo "============================================" 234 | echo "Please confirm your shadowsocks information:" 235 | echo -e "Your Server IP: \033[41;37m ${IP} \033[0m" 236 | echo -e "Your Server Port: \033[41;37m ${port} \033[0m" 237 | echo -e "Your Server Port: \033[41;37m ${PORT} \033[0m" 238 | echo -e "Your Password: \033[41;37m ${password} \033[0m" 239 | echo -e "Your Encryption Method: \033[41;37m ${method} \033[0m" 240 | echo "============================================" 241 | 242 | ping -q -w1 ${IP} | grep "PING" | sed -e "s;).*;;" -e "s;.*(;;" > /opt/var/log/resolvip_tmp.txt 243 | ping_ip() { 244 | ping -q -w1 ${IP} &> /dev/null 245 | return $? 246 | } 247 | 248 | ping_ip 249 | if [ ! "$?" = 0 ]; then 250 | echo -e "$WARNING You input an incorrect IP, please re-enter your: $ansi_white \nshadowsocks -su"$NORM 251 | exit 0 252 | fi 253 | 254 | server_ip=/opt/var/log/resolvip_tmp.txt 255 | 256 | get_server_ip() { 257 | cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" 258 | $(cat ${server_ip=:/dev/null} 2>/dev/null) 259 | EOF 260 | } 261 | echo $(get_server_ip) > /opt/var/log/resolvip.txt 262 | sed -i '/^$/d' /opt/var/log/resolvip.txt 263 | if [ -s "/opt/var/log/resolvip.txt" ]; then 264 | RIP=`sed -n '1p' /opt/var/log/resolvip.txt` 265 | echo -e $INFO Creating shadowsocks config file... 266 | rm -f $CHECK/shadowsocks.json 267 | cat > $CHECK/shadowsocks.json <<-end 268 | { 269 | "server":"$RIP", 270 | "server_port":${port}, 271 | "local_address":"0.0.0.0", 272 | "local_port":${PORT}, 273 | "password":"${password}", 274 | "timeout":60, 275 | "method":"${method}" 276 | } 277 | end 278 | sed -i '11d' $CHECK/shadowsocks.json 279 | else 280 | echo -e "$WARNING Can not write the configuration information, please re-enter your: $ansi_white \nshadowsocks set_up"$NORM 281 | exit 0 282 | fi 283 | 284 | echo -e "$ansi_white You confirm shadowsocks information you filled out correctly?(y/N)$ansi_std" 285 | if [ "no" == $(yes_or_no) ]; then 286 | echo -e $INFO Re-setting... 287 | echo -e $INFO Exiting... 288 | rm -f $CHECK/shadowsocks.json 289 | kill `ps | grep "shadowsocks" | grep -v "grep" | awk '{print $1}'` 290 | fi 291 | 292 | echo -e $INFO "Please select Please choose the following programs:\n\ 293 | $BOLD##programs_1##:$NORM (ss-redir+gfwlist+pdnsd)\n\ 294 | $BOLD##programs_2##:$NORM (ss-redir+chnroutes+chinadns+pdnsd)\n\ 295 | $BOLD##programs_3##:$NORM (ss-redir+chnroutes+chinadns+dnscrypt-proxy)\n\ 296 | $BOLD##programs_4##:$NORM (ss-redir+chnroutes+pcap_dnsproxy)\n\ 297 | $BOLD##programs_5##:$NORM (ss-tunnel+chnroutes+chinadns)\n\ 298 | Your Choice:" 299 | read programs 300 | if [ $programs == "1" ];then 301 | echo -e "$BOLD Set programs_1..." $NORM 302 | sed -e "s/shadowsocks.json\"/shadowsocks.json\"/" -e "s/PROCS=ss-local/PROCS=ss-redir/" -i $CHECK/init.d/S22shadowsocks 303 | sed -n 's/.*ver":"\(.*\)".*/\1/p' $CHECK/shadowsocks.json > $PREFIX/opt/var/log/server.txt 304 | 305 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S26pdnsd (start))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 306 | 307 | rm -f $CHECK/pdnsd.conf 308 | cat > $CHECK/pdnsd.conf <<-end 309 | global { 310 | perm_cache=2048; 311 | cache_dir="/var/pdnsd"; 312 | run_as="nobody"; 313 | server_port = 1054; 314 | server_ip = 127.0.0.1; 315 | status_ctl = on; 316 | query_method=tcp_only; 317 | min_ttl=6h; 318 | max_ttl=1w; 319 | timeout=10; 320 | } 321 | 322 | server { 323 | label= "google"; 324 | ip = 208.67.222.222; 325 | port = 443; 326 | root_server = on; 327 | uptest= none; 328 | } 329 | end 330 | 331 | $PREFIX/shadowsocks/shadowsocks -m 332 | $PREFIX/shadowsocks/shadowsocks -S 333 | $PREFIX/shadowsocks/shadowsocks -ug 334 | sleep 1 335 | touch /opt/var/log/gfwlist.lock 336 | $PREFIX/shadowsocks/shadowsocks -r 337 | 338 | nvram set time_zone="Asia/Shanghai" 339 | 340 | echo -e $INFO Configuring dnsmasq_custom... 341 | DNS_CUSTOM=`echo -e "min-cache-ttl=6000\ncache-size=10000\ 342 | \nconf-dir=$PREFIX$CHECK/dnsmasq.d" | \ 343 | sed -e 's/[\t]*//g' | \ 344 | sed -e ''` 345 | nvram set dnsmasq_options="$DNS_CUSTOM" 346 | 347 | echo -e $INFO Configuring turn startup items and guard the capital... 348 | echo -e "$PREFIX/opt/etc/init.d/auto.run" > /var/log/scr_c.txt 349 | SCR=`sed -e '' /var/log/scr_c.txt` 350 | nvram set rc_startup="$SCR" 351 | 352 | echo -e $INFO Configuring crontab_custom... 353 | CRON=`echo -e "*/1 * * * * root /opt/bin/shadowsocks -c\ 354 | \n*/30 * * * * root /opt/bin/clear" | \ 355 | sed -e 's/[\t]*//g' | \ 356 | sed -e ''` 357 | nvram set cron_jobs="$CRON" 358 | echo -e "#!/bin/sh\ 359 | \n\ 360 | \necho \"\" > /var/log/shadowsocks_watchdog.log\ 361 | \necho \"\" > /var/log/pdnsd_watchdog.log" \ 362 | > /opt/bin/clear 363 | sed -i 's/[\t]*//g' /opt/bin/clear && \ 364 | chmod -R 755 /opt/bin/clear 365 | nvram commit 366 | stopservice dnsmasq && \ 367 | startservice dnsmasq 368 | 369 | $PREFIX/shadowsocks/shadowsocks -b 370 | echo -e "$ansi_red Set successfully, please reboot the router. Found a Bug? Plea se report at https://github.com/houzi-/dd-wrt-shadowsocks/issues. $ansi_std" 371 | killall shadowsocks > /dev/null 372 | elif [ $programs == "2" ];then 373 | echo -e "$BOLD Set programs_2..." $NORM 374 | sed -e "s/shadowsocks.json\"/shadowsocks.json\"/" -e "s/PROCS=ss-local/PROCS=ss-redir/" -i $CHECK/init.d/S22shadowsocks 375 | sed '4c PROCS=chinadns' $CHECK/init.d/S22shadowsocks > $CHECK/init.d/S24cn 376 | sed '5c ARGS="-p 5353 -c /opt/etc/chnroute.txt -s 114.114.114.114,127.0.0.1:1054"' $CHECK/init.d/S24cn > $CHECK/init.d/S24chinadns 377 | 378 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S26pdnsd (start))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 379 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S24chinadns (start|restart))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 380 | 381 | if [ -n "`nvram get wan_get_dns | sed 's/ /,/'`" ]; then 382 | CHINADNS=`nvram get wan_get_dns | awk '/^.*/{print $1}'` 383 | sed -i "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$CHINADNS\2/" $CHECK/init.d/S24chinadns 384 | else 385 | CHINADNS=`cat /tmp/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 386 | sed -i "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$CHINADNS\2/" $CHECK/init.d/S24chinadns 387 | fi 388 | 389 | rm -f $CHECK/init.d/S24cn 390 | chmod +x $CHECK/init.d/S2* 391 | 392 | sleep 1 393 | echo -e $INFO Creating pdnsd.conf file... 394 | rm -f $CHECK/pdnsd.conf 395 | cat > $CHECK/pdnsd.conf <<-end 396 | global { 397 | perm_cache=2048; 398 | cache_dir="/var/pdnsd"; 399 | run_as="nobody"; 400 | server_port = 1054; 401 | server_ip = 127.0.0.1; 402 | status_ctl = on; 403 | query_method=tcp_only; 404 | min_ttl=6h; 405 | max_ttl=1w; 406 | timeout=10; 407 | } 408 | 409 | server { 410 | label= "google"; 411 | ip = 208.67.222.222,208.67.220.220; 412 | root_server = on; 413 | uptest= none; 414 | } 415 | end 416 | 417 | touch $PREFIX/shadowsocks/update.lock 418 | touch $PREFIX/shadowsocks/chnroutes.lock 419 | $PREFIX/shadowsocks/shadowsocks -m 420 | sleep 4 421 | $PREFIX/shadowsocks/shadowsocks -S 422 | sleep 2 423 | touch /opt/var/log/chnroutes.lock 424 | $PREFIX/shadowsocks/shadowsocks -r 425 | 426 | nvram set time_zone="Asia/Shanghai" 427 | 428 | echo -e $INFO Configuring dnsmasq_custom... 429 | DNS_CUSTOM=`echo -e "no-resolv\nno-poll\ 430 | \nserver=127.0.0.1#5353\ 431 | \nmin-cache-ttl=6000\ncache-size=10000\ 432 | \nconf-dir=$PREFIX$CHECK/dnsmasq.d" | \ 433 | sed -e 's/[\t]*//g' | \ 434 | sed -e ''` 435 | nvram set dnsmasq_options="$DNS_CUSTOM" 436 | stopservice dnsmasq && \ 437 | startservice dnsmasq 438 | 439 | echo -e $INFO Configuring turn startup items and guard the capital... 440 | echo -e "$PREFIX/opt/etc/init.d/auto.run" > /var/log/scr_c.txt 441 | SCR=`sed -e '' /var/log/scr_c.txt` 442 | nvram set rc_startup="$SCR" 443 | nvram commit 444 | 445 | echo -e $INFO Configuring crontab_custom... 446 | CRON=`echo -e "*/1 * * * * root /opt/bin/shadowsocks -c\ 447 | \n*/30 * * * * root /opt/bin/clear" | \ 448 | sed -e 's/[\t]*//g' | \ 449 | sed -e ''` 450 | nvram set cron_jobs="$CRON" 451 | echo -e "#!/bin/sh\ 452 | \n\ 453 | \necho \"\" > /var/log/shadowsocks_watchdog.log\ 454 | \necho \"\" > /var/log/chinadns_watchdog.log\ 455 | \necho \"\" > /var/log/pdnsd_watchdog.log" \ 456 | > /opt/bin/clear 457 | sed -i 's/[\t]*//g' /opt/bin/clear && \ 458 | chmod -R 755 /opt/bin/clear 459 | nvram commit 460 | 461 | rm -f $PREFIX/shadowsocks/update.lock 462 | rm -f $PREFIX/shadowsocks/chnroutes.lock 463 | $PREFIX/shadowsocks/shadowsocks -b 464 | echo -e "$ansi_red Set successfully, please reboot the router. Found a Bug? Plea se report at https://github.com/houzi-/dd-wrt-shadowsocks/issues. $ansi_std" 465 | killall shadowsocks > /dev/null 466 | elif [ $programs == "3" ];then 467 | echo -e "$BOLD Set programs_3..." $NORM 468 | sed -e "s/shadowsocks.json\"/shadowsocks.json\"/" -e "s/PROCS=ss-local/PROCS=ss-redir/" -i $CHECK/init.d/S22shadowsocks 469 | sed '4c PROCS=chinadns' $CHECK/init.d/S22shadowsocks > $CHECK/init.d/S24cn 470 | sed '5c ARGS="-p 5353 -c /opt/etc/chnroute.txt -s 114.114.114.114,127.0.0.1:1054,208.67.222.222:443"' $CHECK/init.d/S24cn > $CHECK/init.d/S24chinadns 471 | 472 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S29dnscrypt-proxy (start))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 473 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S24chinadns (start|restart))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 474 | 475 | if [ -n "`nvram get wan_get_dns | sed 's/ /,/'`" ]; then 476 | CHINADNS=`nvram get wan_get_dns | awk '/^.*/{print $1}'` 477 | sed -i "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$CHINADNS\2/" $CHECK/init.d/S24chinadns 478 | else 479 | CHINADNS=`cat /tmp/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 480 | sed -i "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$CHINADNS\2/" $CHECK/init.d/S24chinadns 481 | fi 482 | 483 | rm -f $CHECK/init.d/S24cn 484 | chmod +x $CHECK/init.d/S2* 485 | 486 | touch $PREFIX/shadowsocks/update.lock 487 | touch $PREFIX/shadowsocks/chnroutes.lock 488 | $PREFIX/shadowsocks/shadowsocks -m 489 | sleep 4 490 | $PREFIX/shadowsocks/shadowsocks -S 491 | sleep 2 492 | touch /opt/var/log/chnroutes.lock 493 | $PREFIX/shadowsocks/shadowsocks -r 494 | 495 | nvram set time_zone="Asia/Shanghai" 496 | 497 | echo -e $INFO Configuring dnsmasq_custom... 498 | DNS_CUSTOM=`echo -e "no-resolv\nno-poll\ 499 | \nserver=127.0.0.1#5353\ 500 | \nmin-cache-ttl=6000\ncache-size=10000\ 501 | \nconf-dir=$PREFIX$CHECK/dnsmasq.d" | \ 502 | sed -e 's/[\t]*//g' | \ 503 | sed -e ''` 504 | nvram set dnsmasq_options="$DNS_CUSTOM" 505 | stopservice dnsmasq && \ 506 | startservice dnsmasq 507 | 508 | echo -e $INFO Configuring turn startup items and guard the capital... 509 | echo -e "$PREFIX/opt/etc/init.d/auto.run" > /var/log/scr_c.txt 510 | SCR=`sed -e '' /var/log/scr_c.txt` 511 | nvram set rc_startup="$SCR" 512 | nvram commit 513 | 514 | echo -e $INFO Configuring crontab_custom... 515 | CRON=`echo -e "*/1 * * * * root /opt/bin/shadowsocks -c\ 516 | \n*/30 * * * * root /opt/bin/clear" | \ 517 | sed -e 's/[\t]*//g' | \ 518 | sed -e ''` 519 | nvram set cron_jobs="$CRON" 520 | echo -e "#!/bin/sh\ 521 | \n\ 522 | \necho \"\" > /var/log/shadowsocks_watchdog.log\ 523 | \necho \"\" > /var/log/dnscrypt-proxy_watchdog.log\ 524 | \necho \"\" > /var/log/chinadns_watchdog.log" \ 525 | > /opt/bin/clear 526 | sed -i 's/[\t]*//g' /opt/bin/clear && \ 527 | chmod -R 755 /opt/bin/clear 528 | nvram commit 529 | 530 | rm -f $PREFIX/shadowsocks/update.lock 531 | rm -f $PREFIX/shadowsocks/chnroutes.lock 532 | $PREFIX/shadowsocks/shadowsocks -b 533 | echo -e "$ansi_red Set successfully, please reboot the router. Found a Bug? Plea se report at https://github.com/houzi-/dd-wrt-shadowsocks/issues. $ansi_std" 534 | killall shadowsocks > /dev/null 535 | elif [ $programs == "4" ];then 536 | echo -e "$BOLD Set programs_4..." $NORM 537 | sed -e "s/shadowsocks.json\"/shadowsocks.json\"/" -e "s/PROCS=ss-local/PROCS=ss-redir/" -i $CHECK/init.d/S22shadowsocks 538 | 539 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S27pcap_dnsproxy (start))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 540 | 541 | local_dns=`cat /etc/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 542 | sed -i "s/ 114.114.115.115:53/ $local_dns:53/" $CHECK/pcap-dnsproxy/Config.conf 543 | 544 | touch $PREFIX/shadowsocks/update.lock 545 | touch $PREFIX/shadowsocks/chnroutes.lock 546 | touch /var/log/pcap_dnsproxy.lock 547 | $PREFIX/shadowsocks/shadowsocks -m 548 | sleep 4 549 | $PREFIX/shadowsocks/shadowsocks -S 550 | sleep 2 551 | touch /opt/var/log/chnroutes.lock 552 | $PREFIX/shadowsocks/shadowsocks -r 553 | 554 | nvram set time_zone="Asia/Shanghai" 555 | 556 | echo -e $INFO Configuring dnsmasq_custom... 557 | DNS_CUSTOM=`echo -e "no-resolv\nno-poll\ 558 | \nserver=127.0.0.1#5353\ 559 | \nmin-cache-ttl=6000\ncache-size=10000\ 560 | \nconf-dir=$PREFIX$CHECK/dnsmasq.d" | \ 561 | sed -e 's/[\t]*//g' | \ 562 | sed -e ''` 563 | nvram set dnsmasq_options="$DNS_CUSTOM" 564 | stopservice dnsmasq && \ 565 | startservice dnsmasq 566 | 567 | echo -e $INFO Configuring turn startup items and guard the capital... 568 | echo -e "$PREFIX/opt/etc/init.d/auto.run" > /var/log/scr_c.txt 569 | SCR=`sed -e '' /var/log/scr_c.txt` 570 | nvram set rc_startup="$SCR" 571 | nvram commit 572 | 573 | echo -e $INFO Configuring crontab_custom... 574 | CRON=`echo -e "*/1 * * * * root /opt/bin/shadowsocks -c\ 575 | \n*/30 * * * * root /opt/bin/clear" | \ 576 | sed -e 's/[\t]*//g' | \ 577 | sed -e ''` 578 | nvram set cron_jobs="$CRON" 579 | echo -e "#!/bin/sh\ 580 | \n\ 581 | \necho \"\" > /var/log/shadowsocks_watchdog.log\ 582 | \necho \"\" > /var/log/Pcap_DNSProxy_watchdog.log" \ 583 | > /opt/bin/clear 584 | sed -i 's/[\t]*//g' /opt/bin/clear && \ 585 | chmod -R 755 /opt/bin/clear 586 | nvram commit 587 | 588 | rm -f $PREFIX/shadowsocks/update.lock 589 | rm -f $PREFIX/shadowsocks/chnroutes.lock 590 | $PREFIX/shadowsocks/shadowsocks -b 591 | echo -e "$ansi_red Set successfully, please reboot the router. Found a Bug? Plea se report at https://github.com/houzi-/dd-wrt-shadowsocks/issues. $ansi_std" 592 | killall shadowsocks > /dev/null 593 | elif [ $programs == "5" ];then 594 | echo -e "$BOLD Set programs_5..." $NORM 595 | sed -e "s/shadowsocks.json\"/shadowsocks.json\"/" -e "s/PROCS=ss-local/PROCS=ss-redir/" -i $CHECK/init.d/S22shadowsocks 596 | sed -e "s/shadowsocks.json\"/shadowsocks.json -b 0.0.0.0 -l 5300 -L 8.8.8.8:53 -u\"/" -e "s/PROCS=ss-redir/PROCS=ss-tunnel/" $CHECK/init.d/S22shadowsocks > $CHECK/init.d/S23ss-tunnel 597 | sed '4c PROCS=chinadns' $CHECK/init.d/S22shadowsocks > $CHECK/init.d/S24cn 598 | sed '5c ARGS="-p 5353 -l /opt/etc/chinadns_iplist.txt -c /opt/etc/chnroute.txt -s 114.114.114.114,127.0.0.1:5300"' $CHECK/init.d/S24cn > $CHECK/init.d/S24chinadns 599 | 600 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S23ss-tunnel (start|restart))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 601 | sed -r 's/#(['$'\t'' ]*\/opt\/etc\/init.d\/S24chinadns (start|restart))/\1/' $PREFIX/shadowsocks/shadowsocks -i $PREFIX/shadowsocks/shadowsocks 602 | 603 | if [ -n "`nvram get wan_get_dns | sed 's/ /,/'`" ]; then 604 | CHINADNS=`nvram get wan_get_dns | awk '/^.*/{print $1}'` 605 | sed -i "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$CHINADNS\2/" $CHECK/init.d/S24chinadns 606 | else 607 | CHINADNS=`cat /tmp/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 608 | sed -i "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$CHINADNS\2/" $CHECK/init.d/S24chinadns 609 | fi 610 | 611 | rm -f $CHECK/init.d/S24cn 612 | chmod +x $CHECK/init.d/S2* 613 | 614 | touch $PREFIX/shadowsocks/update.lock 615 | touch $PREFIX/shadowsocks/chnroutes.lock 616 | $PREFIX/shadowsocks/shadowsocks -m 617 | sleep 4 618 | $PREFIX/shadowsocks/shadowsocks -S 619 | sleep 2 620 | touch /opt/var/log/chnroutes.lock 621 | $PREFIX/shadowsocks/shadowsocks -r 622 | 623 | nvram set time_zone="Asia/Shanghai" 624 | 625 | echo -e $INFO Configuring dnsmasq_custom... 626 | DNS_CUSTOM=`echo -e "no-resolv\nno-poll\ 627 | \nserver=127.0.0.1#5353\ 628 | \nmin-cache-ttl=6000\ncache-size=10000\ 629 | \nconf-dir=$PREFIX$CHECK/dnsmasq.d" | \ 630 | sed -e 's/[\t]*//g' | \ 631 | sed -e ''` 632 | nvram set dnsmasq_options="$DNS_CUSTOM" 633 | stopservice dnsmasq && \ 634 | startservice dnsmasq 635 | 636 | echo -e $INFO Configuring turn startup items and guard the capital... 637 | echo -e "$PREFIX/opt/etc/init.d/auto.run" > /var/log/scr_c.txt 638 | SCR=`sed -e '' /var/log/scr_c.txt` 639 | nvram set rc_startup="$SCR" 640 | nvram commit 641 | 642 | echo -e $INFO Configuring crontab_custom... 643 | CRON=`echo -e "*/1 * * * * root /opt/bin/shadowsocks -c\ 644 | \n*/30 * * * * root /opt/bin/clear" | \ 645 | sed -e 's/[\t]*//g' | \ 646 | sed -e ''` 647 | nvram set cron_jobs="$CRON" 648 | echo -e "#!/bin/sh\ 649 | \n\ 650 | \necho \"\" > /var/log/shadowsocks_watchdog.log\ 651 | \necho \"\" > /var/log/chinadns_watchdog.log" \ 652 | > /opt/bin/clear 653 | sed -i 's/[\t]*//g' /opt/bin/clear && \ 654 | chmod -R 755 /opt/bin/clear 655 | nvram commit 656 | 657 | rm -f $PREFIX/shadowsocks/update.lock 658 | rm -f $PREFIX/shadowsocks/chnroutes.lock 659 | $PREFIX/shadowsocks/shadowsocks -b 660 | echo -e "$ansi_red Set successfully, please reboot the router. Found a Bug? Plea se report at https://github.com/houzi-/dd-wrt-shadowsocks/issues. $ansi_std" 661 | killall shadowsocks > /dev/null 662 | fi 663 | ;; 664 | 665 | -m | --modules) 666 | echo -e -n "$ansi_white Load_Modules... " 667 | if [ ! "`lsmod | grep xt_set | wc -l`" -eq 1 ]; then 668 | if [ -f "/lib/modules/$(cat /proc/version | sed -e 's; (.*;;' -e 's;Linux version ;;')/xt_set.ko" ]; then 669 | modprobe xt_set 670 | if [ -f "/lib/modules/$(cat /proc/version | sed -e 's; (.*;;' -e 's;Linux version ;;')/xt_TPROXY.ko" ]; then 671 | modprobe xt_socket && \ 672 | modprobe xt_TPROXY 673 | fi 674 | else 675 | modprobe ipv6 676 | modprobe nf_conntrack_ipv6 677 | insmod /opt/lib/modules/xt_TPROXY.ko 678 | insmod /opt/lib/modules/xt_socket.ko 679 | insmod /opt/lib/modules/xt_set.ko 680 | fi 681 | fi 682 | echo -e " $ansi_green done. $ansi_std" 683 | ;; 684 | 685 | -S | --START) 686 | sed -n 's/.*ver": *"\(.*\)".*/\1/p' $CHECK/shadowsocks.json > /var/log/server.txt 687 | 688 | [ ! -f /tmp/resolv.dnsmasq ] && \ 689 | stopservice dnsmasq && \ 690 | startservice dnsmasq 691 | 692 | check_dns() { 693 | old_dns=`cat $PREFIX/opt/etc/init.d/S24chinadns | sed -n "5p" | awk '/^.*/{print $6}' | sed -e 's/,127.*//' -e 's/,.*//'` 694 | new_dns=`cat /tmp/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 695 | if [ "$old_dns" == "$new_dns" ]; then 696 | echo "DNS is same!" > /var/log/check_dns.log 697 | else 698 | if [ -n "`nvram get wan_get_dns | sed 's/ .*//'`" ]; then 699 | CHINADNS=`nvram get wan_get_dns | sed 's/ .*//'` 700 | sed -i "s/^ARGS=\(.*\)$old_dns\(.*\)$/ARGS=\1$CHINADNS\2/" $PREFIX/$CHECK/init.d/S24chinadns 701 | sed -i "s|^\(server.*\)/[^/]*$|\1/$new_dns|" $PREFIX/$CHECK/dnsmasq.d/accelerated-domains.china.conf 702 | else 703 | CHINADNS=`cat /tmp/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 704 | sed -i "s/^ARGS=\(.*\)$old_dns\(.*\)$/ARGS=\1$CHINADNS\2/" $PREFIX/$CHECK/init.d/S24chinadns 705 | sed -i "s|^\(server.*\)/[^/]*$|\1/$new_dns|" $PREFIX/$CHECK/dnsmasq.d/accelerated-domains.china.conf 706 | fi 707 | fi 708 | } 709 | 710 | sleep 2 711 | if [ -f "$PREFIX/shadowsocks/chnroutes.lock" ]; then 712 | $PREFIX/shadowsocks/shadowsocks -u 713 | else 714 | : 715 | fi 716 | 717 | [ "$check_dns" == "1" ] && check_dns 718 | 719 | PROCESS=$(ps | grep "ss-redir" | grep -v "grep") 720 | if [ -z "$PROCESS" ]; then 721 | /opt/etc/init.d/S22shadowsocks start && touch /var/log/shadowsocks.lock 722 | # /opt/etc/init.d/S23ss-tunnel start && touch /var/log/ss-tunnel.lock 723 | # /opt/etc/init.d/S26pdnsd start && touch /var/log/pdnsd.lock 724 | # /opt/etc/init.d/S24chinadns start && touch /var/log/chinadns.lock 725 | # /opt/etc/init.d/S27pcap_dnsproxy start && touch /var/log/pcap_dnsproxy.lock 726 | # /opt/etc/init.d/S29dnscrypt-proxy start && touch /var/log/dnscrypt-proxy.lock 727 | exit 0 728 | else 729 | for i in `cat /var/log/server.txt`;do 730 | for j in `cat $PREFIX/opt/var/log/server.txt`;do 731 | if [ $i == $j ]; then 732 | echo "$(date): OK" >> /var/log/account_switching.log 733 | else 734 | /opt/etc/init.d/S22shadowsocks restart 735 | # /opt/etc/init.d/S23ss-tunnel restart 736 | $PREFIX/shadowsocks/shadowsocks -f 737 | sleep 2 738 | $PREFIX/shadowsocks/shadowsocks -r 739 | fi 740 | done 741 | done 742 | fi 743 | ;; 744 | 745 | -r | --rules) 746 | nvram get wan_ipaddr > /var/log/wan_ipaddr.log 747 | sed -n 's/.*ver": *"\(.*\)".*/\1/p' $CHECK/shadowsocks.json > $PREFIX/opt/var/log/server.txt 748 | /opt/etc/init.d/S99ss-rules start 749 | echo -e -n "$ansi_white Loading iptables rules... " 750 | sleep 1 751 | echo -e " $ansi_green done. $ansi_std" 752 | ;; 753 | 754 | -g | --global) 755 | case ${2} in 756 | start) 757 | echo -e "$ansi_red **WARNING** USE AT YOUR OWN RISK! You want to ${2} global?(y/N) $ansi_std" 758 | read choice 759 | if [ "${choice}" == "y" ]; then 760 | touch $CHECK/global.list 761 | sed -i 's/\SS_SPEC_WAN_AC/SS_SPEC_WAN_FW/' /opt/bin/ss-start 762 | echo -e -n "$ansi_white ${2} Global... " 763 | sleep 1 764 | echo -e " $ansi_green done. $ansi_std" 765 | $PREFIX/shadowsocks/shadowsocks -f 766 | $PREFIX/shadowsocks/shadowsocks -r 767 | else 768 | : ${warning:?"You do not have any operations."} 769 | fi 770 | ;; 771 | 772 | stop) 773 | echo -e "$ansi_red **WARNING** USE AT YOUR OWN RISK! You want to ${2} global?(y/N) $ansi_std" 774 | read choice 775 | if [ "${choice}" == "y" ]; then 776 | touch $CHECK/global.list 777 | sed -i 's/\SS_SPEC_WAN_FW/SS_SPEC_WAN_AC/' /opt/bin/ss-start 778 | echo -e -n "$ansi_white ${2} Global... " 779 | sleep 1 780 | echo -e " $ansi_green done. $ansi_std" 781 | $PREFIX/shadowsocks/shadowsocks -f 782 | $PREFIX/shadowsocks/shadowsocks -r 783 | else 784 | : ${warning:?"You do not have any operations."} 785 | fi 786 | ;; 787 | esac 788 | ;; 789 | 790 | -f | --flush) 791 | ss-nat -f 792 | echo -e -n "$ansi_white Flush_iptables... " 793 | sleep 1 794 | echo -e " $ansi_green done. $ansi_std" 795 | ;; 796 | 797 | -u | --update) 798 | directory=$(cd $CHECK && ls | grep "dnsmasq.d" | grep -v "grep") 799 | if [ -z "$directory" ]; then 800 | cd $CHECK && mkdir dnsmasq.d 801 | fi 802 | 803 | if [ -f "$CHECK/ignore.list" ]; then 804 | rm -f $CHECK/ignore.list 805 | fi 806 | 807 | wget -t0 -O- $china_routing_list | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /var/log/ignore_tmp.txt 808 | 809 | IGNORE_TEMP_LIST=/var/log/ignore_tmp.txt 810 | IGNORE_LIST=$CHECK/ignore.list 811 | 812 | cat > $IGNORE_LIST <<-EOF 813 | 0.0.0.0/8 814 | 10.0.0.0/8 815 | 100.64.0.0/10 816 | 127.0.0.0/8 817 | 169.254.0.0/16 818 | 172.16.0.0/12 819 | 192.0.0.0/24 820 | 192.0.2.0/24 821 | 192.88.99.0/24 822 | 192.168.0.0/16 823 | 198.18.0.0/15 824 | 198.51.100.0/24 825 | 203.0.113.0/24 826 | 224.0.0.0/4 827 | 240.0.0.0/4 828 | 255.255.255.255 829 | $(cat ${IGNORE_TEMP_LIST:=/dev/null} 2>/dev/null) 830 | EOF 831 | 832 | if [ -f "/var/log/pcap_dnsproxy.lock" ]; then 833 | rm -f $CHECK/pcap-dnsproxy/Routing.txt $CHECK/pcap-dnsproxy/WhiteList.txt 834 | 835 | # Update Local Hosts 836 | cd /tmp;curl --insecure -O $china_domain_list;cd /tmp/root 837 | echo -e '[Local Hosts]' >> /tmp/WhiteList.txt 838 | echo -e '## China mainland domains' >> /tmp/WhiteList.txt 839 | echo -e '## Get the latest database: https://github.com/xinhugo/Free-List/blob/master/WhiteList.txt' >> /tmp/WhiteList.txt 840 | echo -e '## Report an issue: https://github.com/xinhugo/Free-List/issues' >> /tmp/WhiteList.txt 841 | echo -e "## Last update: $DATE\n" >> /tmp/WhiteList.txt 842 | sed 's|/114.114.114.114$||' /tmp/accelerated-domains.china.conf > /tmp/WhiteList_tmp.txt 843 | sed -i 's|\(\.\)|\\\1|g' /tmp/WhiteList_tmp.txt 844 | sed -i 's|server=/|.*\\\b|' /tmp/WhiteList_tmp.txt 845 | sed -i 's|b\(cn\)$|\.\1|' /tmp/WhiteList_tmp.txt 846 | cat /tmp/WhiteList_tmp.txt >> /tmp/WhiteList.txt 847 | 848 | cd /tmp;curl --insecure -O $china_google_list;cd /tmp/root 849 | sed 's|/114.114.114.114$||' /tmp/google.china.conf > /tmp/WhiteList_tmp.txt 850 | sed -i 's|\(\.\)|\\\1|g' /tmp/WhiteList_tmp.txt 851 | sed -i 's|server=/|.*\\\b|' /tmp/WhiteList_tmp.txt 852 | cat /tmp/WhiteList_tmp.txt >> /tmp/WhiteList.txt 853 | echo -e -n "$ansi_white Updating Local Hosts... " 854 | sleep 1 855 | echo -e " $ansi_green done. $ansi_std" 856 | 857 | cp /tmp/WhiteList.txt $CHECK/pcap-dnsproxy 858 | rm -f /tmp/WhiteList_tmp.txt /tmp/WhiteList.txt /tmp/accelerated-domains.china.conf /tmp/google.china.conf 859 | 860 | # Update Local Routing 861 | curl --insecure $china_routing_list | grep ipv4 | grep CN | awk -F\| '{printf("%s/%d\n", $4, 32-log($5)/log(2))}' > /tmp/Routing_IPv4.txt 862 | echo -e '[Local Routing]' >> /tmp/Routing_IPv4_tmp.txt 863 | echo -e '## China mainland routing blocks' >> /tmp/Routing_IPv4_tmp.txt 864 | echo -e "## Last update: $DATE\n\n" >> /tmp/Routing_IPv4_tmp.txt 865 | echo -e '## IPv4' >> /tmp/Routing_IPv4_tmp.txt 866 | echo -e '## Get the latest database from APNIC -> https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' >> /tmp/Routing_IPv4_tmp.txt 867 | cat /tmp/Routing_IPv4.txt >> /tmp/Routing_IPv4_tmp.txt 868 | 869 | curl --insecure $china_routing_list | grep ipv6 | grep CN | awk -F\| '{printf("%s/%d\n", $4, $5)}' > /tmp/Routing_IPv6.txt 870 | echo -e '## IPv6' >> /tmp/Routing_IPv6_tmp.txt 871 | echo -e '## Get the latest database from APNIC -> https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' >> /tmp/Routing_IPv6_tmp.txt 872 | cat /tmp/Routing_IPv6.txt >> /tmp/Routing_IPv6_tmp.txt 873 | 874 | cat /tmp/Routing_IPv6_tmp.txt >> /tmp/Routing_IPv4_tmp.txt 875 | touch /tmp/Routing.txt 876 | cat /tmp/Routing_IPv4_tmp.txt >> /tmp/Routing.txt 877 | echo -e -n "$ansi_white Updating Local Routing... " 878 | sleep 1 879 | echo -e " $ansi_green done. $ansi_std" 880 | 881 | cp /tmp/Routing.txt $CHECK/pcap-dnsproxy 882 | rm -f /tmp/Routing_IPv4.txt /tmp/Routing_IPv4_tmp.txt /tmp/Routing_IPv6.txt /tmp/Routing_IPv6_tmp.txt /tmp/Routing.txt 883 | else 884 | wget -t0 -O- $china_routing_list | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > $CHECK/chnroute.txt 885 | cd $CHECK/dnsmasq.d;curl -s --insecure -O $china_domain_list;cd /tmp/root 886 | DNS=`cat /tmp/resolv.dnsmasq | awk '/^nameserver/{print $2}' | sed -n '1p'` 887 | sed -i "s|^\(server.*\)/[^/]*$|\1/$DNS|" $CHECK/dnsmasq.d/accelerated-domains.china.conf 888 | fi 889 | 890 | rm -f $PREFIX/shadowsocks/dns.list 891 | rm -f $IGNORE_TEMP_LIST 892 | 893 | if [ -f "$PREFIX/shadowsocks/update.lock" ]; then 894 | echo '['$DATE'] Has loaded China route table.' > /var/log/chnroutes.log 895 | else 896 | if [ -f "/var/log/pcap_dnsproxy.lock" ]; then 897 | /opt/etc/init.d/S27pcap-dnsproxy restart 898 | $PREFIX/shadowsocks/shadowsocks -f 899 | sleep 1 900 | $PREFIX/shadowsocks/shadowsocks -r 901 | else 902 | /opt/etc/init.d/S24chinadns restart 903 | $PREFIX/shadowsocks/shadowsocks -f 904 | sleep 1 905 | $PREFIX/shadowsocks/shadowsocks -r 906 | fi 907 | fi 908 | stopservice dnsmasq && \ 909 | startservice dnsmasq 910 | echo -e -n "$ansi_white Updating chnroutes... " 911 | sleep 1 912 | echo -e " $ansi_green done. $ansi_std" 913 | ;; 914 | 915 | -ug | --update_gfwlist) 916 | echo -e -n "$ansi_white Updating gfwlist... " 917 | directory=$(cd $CHECK && ls | grep "dnsmasq.d" | grep -v "grep") 918 | if [ -z "$directory" ]; then 919 | cd $CHECK && mkdir dnsmasq.d 920 | fi 921 | 922 | DNS=127.0.0.1#1054 923 | 924 | cd $CHECK/dnsmasq.d;curl --insecure -O $ops_list;cd /tmp/root 925 | 926 | sed -i "s|^\(server.*\)/[^/]*$|\1/$DNS|" $CHECK/dnsmasq.d/opslist.conf 927 | sed -i "s|^\(ipset.*\)/[^/]*$|\1/gfw_black_list|" $CHECK/dnsmasq.d/opslist.conf 928 | sleep 1 929 | echo -e " $ansi_green done. $ansi_std" 930 | stopservice dnsmasq && \ 931 | startservice dnsmasq 932 | ;; 933 | 934 | -c | --check) 935 | SHADOWSOCKS=$(ps | grep "ss-redir" | grep -v "grep") 936 | if [ -f "/var/log/shadowsocks.lock" ]; then 937 | if [ -z "$SHADOWSOCKS" ]; then 938 | echo '['$DATE'] Shadowsoks abnormal operation, restarting shadowsocks.' >> /var/log/shadowsocks_watchdog.log 2>&1 939 | /opt/etc/init.d/S22shadowsocks start 940 | else 941 | echo '['$DATE'] No problem, the normal operation of shadowsoks.' >> /var/log/shadowsocks_watchdog.log 2>&1 942 | fi 943 | fi 944 | 945 | if [ -f "/var/log/chnroutes.lock" ]; then 946 | if [ "`$IPT -t nat -nvL | grep "SS_SPEC_WAN_AC" | wc -l`" -eq 4 ]; then 947 | : 948 | else 949 | /opt/bin/shadowsocks -r 950 | fi 951 | else 952 | if [ "`$IPT -nvL | grep "gfw_black_list" | wc -l`" -eq 2 ]; then 953 | : 954 | else 955 | /opt/bin/shadowsocks -r 956 | fi 957 | fi 958 | 959 | dnscrypt=$(ps | grep "dnscrypt-proxy" | grep -v "grep") 960 | if [ -f "/var/log/dnscrypt-proxy.lock" ]; then 961 | if [ -z "$dnscrypt" ]; then 962 | echo '['$DATE'] dnscrypt-proxy abnormal operation, restarting dnscrypt-proxy.' >> /var/log/dnscrypt-proxy_watchdog.log 2>&1 963 | # /opt/etc/init.d/S29dnscrypt-proxy start 964 | else 965 | echo '['$DATE'] No problem, the normal operation of dnscrypt-proxy.' >> /var/log/dnscrypt-proxy_watchdog.log 2>&1 966 | fi 967 | fi 968 | 969 | Pcap_DNSProxy=$(ps | grep "Pcap_DNSProxy" | grep -v "grep") 970 | if [ -f "/var/log/pcap_dnsproxy.lock" ]; then 971 | if [ -z "$Pcap_DNSProxy" ]; then 972 | echo '['$DATE'] Pcap_DNSProxy abnormal operation, restarting Pcap_DNSProxy.' >> /var/log/Pcap_DNSProxy_watchdog.log 2>&1 973 | # /opt/etc/init.d/S27pcap_dnsproxy start 974 | else 975 | echo '['$DATE'] No problem, the normal operation of Pcap_DNSProxy.' >> /var/log/Pcap_DNSProxy_watchdog.log 2>&1 976 | fi 977 | fi 978 | 979 | PDNSD=$(ps | grep "pdnsd" | grep -v "grep") 980 | if [ -f "/var/log/pdnsd.lock" ]; then 981 | if [ -z "$PDNSD" ]; then 982 | echo '['$DATE'] Pdnsd abnormal operation, restarting pdnsd.' >> /var/log/pdnsd_watchdog.log 2>&1 983 | # /opt/etc/init.d/S26pdnsd start 984 | else 985 | echo '['$DATE'] No problem, the normal operation of pdnsd.' >> /var/log/pdnsd_watchdog.log 2>&1 986 | fi 987 | fi 988 | 989 | judge=$(cd $CHECK && ls | grep "ignore.list" | grep -v "grep") 990 | if [ -z "$judge" ]; then 991 | exit 0 992 | else 993 | CHINADNS=$(ps | grep "chinadns" | grep -v "grep") 994 | if [ -f "/var/log/chinadns.lock" ]; then 995 | if [ -z "$CHINADNS" ]; then 996 | echo '['$DATE'] ChinaDNS is restarting.' >> /var/log/chinadns_watchdog.log 2>&1 997 | # /opt/etc/init.d/S24chinadns start 998 | else 999 | echo '['$DATE'] ChinaDNS no problem.' >> /var/log/chinadns_watchdog.log 2>&1 1000 | fi 1001 | fi 1002 | fi 1003 | ;; 1004 | 1005 | -sw | --ss_switch) 1006 | yes_or_no() { 1007 | read -p "$1 ([y]es or [n]o): " 1008 | case $(echo $REPLY | tr '[A-Z]' '[a-z]') in 1009 | y|yes) echo "yes" ;; 1010 | *) echo "no" ;; 1011 | esac 1012 | } 1013 | 1014 | echo -e "$ansi_white Do you want to edit json file?(y/N)$ansi_std" 1015 | if [ "yes" == $(yes_or_no) ]; then 1016 | echo -e $INFO Creating JSON file... 1017 | rm -f $CHECK/shadowsocks.json 1018 | 1019 | echo "============================================" 1020 | echo "Please input your shadowsocks account imformation:" 1021 | read -p "(Your Server IP):" IP 1022 | read -p "(Your Server Port):" port 1023 | read -p "(Your Local Port):" PORT 1024 | read -p "(Your Password):" password 1025 | read -p "(Your Encryption Method):" method 1026 | echo "============================================" 1027 | echo "Please confirm your shadowsocks imformation:" 1028 | echo -e "Your Server IP: \033[41;37m ${IP} \033[0m" 1029 | echo -e "Your Server Port: \033[41;37m ${port} \033[0m" 1030 | echo -e "Your Server Port: \033[41;37m ${PORT} \033[0m" 1031 | echo -e "Your Password: \033[41;37m ${password} \033[0m" 1032 | echo -e "Your Encryption Method: \033[41;37m ${method} \033[0m" 1033 | echo "============================================" 1034 | 1035 | ping -q -w1 ${IP} | grep "PING" | sed -e "s;).*;;" -e "s;.*(;;" > /opt/var/log/resolvip_tmp.txt 1036 | ping_ip() { 1037 | ping -q -w1 ${IP} &> /dev/null 1038 | return $? 1039 | } 1040 | 1041 | ping_ip 1042 | if [ ! "$?" = 0 ]; then 1043 | echo -e "$WARNING You input an incorrect IP, please re-enter your: $ansi_white \nshadowsocks ss_switch"$NORM 1044 | exit 0 1045 | fi 1046 | 1047 | server_ip=/opt/var/log/resolvip_tmp.txt 1048 | 1049 | get_server_ip() { 1050 | cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" 1051 | $(cat ${server_ip=:/dev/null} 2>/dev/null) 1052 | EOF 1053 | } 1054 | echo $(get_server_ip) > /opt/var/log/resolvip.txt 1055 | sed -i '/^$/d' /opt/var/log/resolvip.txt 1056 | if [ -s "/opt/var/log/resolvip.txt" ]; then 1057 | echo -e -n $ss_switch 1058 | RIP=`sed -n '1p' /opt/var/log/resolvip.txt` 1059 | cat > $CHECK/shadowsocks.json <<-end 1060 | { 1061 | "server":"$RIP", 1062 | "server_port":${port}, 1063 | "local_address":"0.0.0.0", 1064 | "local_port":${PORT}, 1065 | "password":"${password}", 1066 | "timeout":60, 1067 | "method":"${method}" 1068 | } 1069 | end 1070 | sed -i '11d' $CHECK/shadowsocks.json 1071 | sleep 1 1072 | echo -e "$ansi_green PASS. $ansi_std" 1073 | else 1074 | echo -e -n $ss_switch 1075 | sleep 1 1076 | echo -e "$ansi_red ERROR. $ansi_std" 1077 | echo -e "$WARNING Can not write the configuration information, please re-enter your: $ansi_white \nshadowsocks ss_switch"$NORM 1078 | exit 0 1079 | fi 1080 | else 1081 | echo -e $INFO Creating server file... 1082 | echo "============================================" 1083 | echo "Please input your shadowsocks account imformation:" 1084 | read -p "(Your Server IP):" IP 1085 | echo "============================================" 1086 | echo "Please confirm your shadowsocks imformation:" 1087 | echo -e "Your Server IP: \033[41;37m ${IP} \033[0m" 1088 | echo "============================================" 1089 | 1090 | ping -q -w1 ${IP} | grep "PING" | sed -e "s;).*;;" -e "s;.*(;;" > /opt/var/log/resolvip_tmp.txt 1091 | ping_ip() { 1092 | ping -q -w1 ${IP} &> /dev/null 1093 | return $? 1094 | } 1095 | 1096 | ping_ip 1097 | if [ ! "$?" = 0 ]; then 1098 | echo -e "$WARNING You input an incorrect IP, please re-enter your: $ansi_white \nshadowsocks ss_switch"$NORM 1099 | exit 0 1100 | fi 1101 | 1102 | server_ip=/opt/var/log/resolvip_tmp.txt 1103 | 1104 | get_server_ip() { 1105 | cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" 1106 | $(cat ${server_ip=:/dev/null} 2>/dev/null) 1107 | EOF 1108 | } 1109 | echo $(get_server_ip) > /opt/var/log/resolvip.txt 1110 | sed -i '/^$/d' /opt/var/log/resolvip.txt 1111 | if [ -s "/opt/var/log/resolvip.txt" ]; then 1112 | echo -e -n $ss_switch 1113 | RIP=`sed -n '1p' /opt/var/log/resolvip.txt` 1114 | sed -i 's/\("server":"\).*/\1'"$RIP"'",/g' $CHECK/shadowsocks.json 1115 | sleep 1 1116 | echo -e "$ansi_green PASS. $ansi_std" 1117 | else 1118 | echo -e -n $ss_switch 1119 | sleep 1 1120 | echo -e "$ansi_red ERROR. $ansi_std" 1121 | echo -e "$WARNING Can not write IP, please re-enter your: $ansi_white \nshadowsocks ss_switch"$NORM 1122 | exit 0 1123 | fi 1124 | fi 1125 | 1126 | $PREFIX/shadowsocks/shadowsocks -S 1127 | stopservice dnsmasq && \ 1128 | startservice dnsmasq 1129 | ;; 1130 | 1131 | -sa | --services_action) 1132 | case ${2} in 1133 | stop) 1134 | echo -e "$ansi_red **WARNING** USE AT YOUR OWN RISK! You want to ${2} all service under /opt/etc/init.d?(y/N) $ansi_std" 1135 | read choice 1136 | if [ "${choice}" == "y" ]; then 1137 | /opt/etc/init.d/rc.unslung ${2} 1138 | if [ "${2}" == "stop" ]; then 1139 | cron_clear() { 1140 | if [ ! -f /opt/etc/cron_jobs.bak ]; then 1141 | nvram get cron_jobs > /opt/etc/cron_jobs.bak 1142 | fi 1143 | nvram set cron_jobs="" 1144 | nvram commit 1145 | stopservice cron && startservice cron 1146 | } 1147 | 1148 | dnsmasq_clear() { 1149 | if [ ! -f /opt/etc/dnsmasq_options.bak ]; then 1150 | nvram get dnsmasq_options > /opt/etc/dnsmasq_options.bak 1151 | fi 1152 | nvram set dnsmasq_options="" 1153 | nvram commit 1154 | stopservice dnsmasq && startservice dnsmasq 1155 | } 1156 | 1157 | cron_clear 1158 | dnsmasq_clear 1159 | $PREFIX/shadowsocks/shadowsocks -f 1160 | fi 1161 | else 1162 | : ${warning:?"You do not have any operations."} 1163 | fi 1164 | ;; 1165 | 1166 | start) 1167 | echo -e "$ansi_red **WARNING** USE AT YOUR OWN RISK! You want to ${2} all service under /opt/etc/init.d?(y/N) $ansi_std" 1168 | read choice 1169 | if [ "${choice}" == "y" ]; then 1170 | if [ "${2}" == "start" ]; then 1171 | cron_restore() { 1172 | if [ -f /opt/etc/cron_jobs.bak ]; then 1173 | CRON=`cat /opt/etc/cron_jobs.bak | sed -e 's/[\t]*//g' | sed -e ''` 1174 | nvram set cron_jobs="$CRON" 1175 | nvram commit 1176 | stopservice cron && startservice cron 1177 | else 1178 | return 0 1179 | fi 1180 | } 1181 | 1182 | dnsmasq_restore() { 1183 | if [ -f /opt/etc/cron_jobs.bak ]; then 1184 | DNS_CUSTOM=`cat /opt/etc/dnsmasq_options.bak | sed -e 's/[\t]*//g' | sed -e ''` 1185 | nvram set dnsmasq_options="$DNS_CUSTOM" 1186 | nvram commit 1187 | stopservice dnsmasq && startservice dnsmasq 1188 | else 1189 | return 0 1190 | fi 1191 | } 1192 | 1193 | cron_restore 1194 | dnsmasq_restore 1195 | $PREFIX/shadowsocks/shadowsocks -f && \ 1196 | $PREFIX/shadowsocks/shadowsocks -S && \ 1197 | $PREFIX/shadowsocks/shadowsocks -r 1198 | fi 1199 | else 1200 | : ${warning:?"You do not have any operations."} 1201 | fi 1202 | ;; 1203 | 1204 | *) 1205 | echo -e "$ansi_white usage: [stop|start] $ansi_std" 1206 | esac 1207 | ;; 1208 | 1209 | -b | --backup) 1210 | echo -e "$ansi_white You want to backup entware?(y/N)$ansi_std" 1211 | read choice 1212 | if [ "${choice}" == "y" ]; then 1213 | tar -czf /tmp/entware_backup.tar.gz -C $PREFIX opt 1214 | [ ! -d "$PREFIX/shadowsocks/entware_backup" ] && mkdir -p $PREFIX/shadowsocks/entware_backup 1215 | cp /tmp/entware_backup.tar.gz $PREFIX/shadowsocks/entware_backup/ 1216 | fi 1217 | 1218 | echo -e -n $backup 1219 | sleep 1 1220 | echo -e "$ansi_green PASS. $ansi_std" 1221 | ;; 1222 | 1223 | -e | --email) 1224 | curl -s --connect-timeout 1 www.google.com &> /dev/null 1225 | 1226 | if [ "$?" == "0" ]; then 1227 | echo -e "From: $FROM\nContent-Type: text/plain;\nSubject: $TITLE\n\n$CONTENT\nAt: `date -R`" > /tmp/mail.txt 1228 | cat /tmp/mail.txt | sendmail -v -Ssmtp.163.com -f$FROM -au$username -ap$password $TO &> /dev/null 1229 | fi 1230 | ;; 1231 | 1232 | -h | --help) 1233 | shadowsocks 1234 | ;; 1235 | 1236 | *) 1237 | echo -e "$ansi_green # ------------------------------------------------------------------- $ansi_std" 1238 | echo -e "$ansi_green # Copyright (C) 2016 Jason Lin $ansi_std" 1239 | echo -e "$ansi_green # Last edited: 2016.9.16 $ansi_std" 1240 | echo -e "$ansi_green # Version: V1.6-beta (ARM version) $ansi_std" 1241 | echo -e "$ansi_green # Explain: This script can be used only for DD-WRT ARM firmware. $ansi_std" 1242 | echo -e "$ansi_green # Description: This is a science on ShadowSocks Internet automatic $ansi_std" 1243 | echo -e "$ansi_green # configuration script in DD-WRT under$ansi_std. " 1244 | echo -e "$ansi_green # This is free software, licensed under the GNU General Public License v3. $ansi_std" 1245 | echo -e "$ansi_green # See /LICENSE for more information. $ansi_std" 1246 | echo -e "$ansi_green # ------------------------------------------------------------------- $ansi_std" 1247 | echo -e "$ansi_white ===================================================================== $ansi_std" 1248 | echo -e "$ansi_blue WIKI: $ansi_std" 1249 | echo -e "$ansi_white [-su/--set_up] Set ShadowSocks and ChinaDNS $ansi_std" 1250 | echo -e "$ansi_white [-m/--modules] Loading module $ansi_std" 1251 | echo -e "$ansi_white [-S/--START] Running ShadowSocks and ChinaDNS $ansi_std" 1252 | echo -e "$ansi_white [-r/--rules] Application Firewall Policy $ansi_std" 1253 | echo -e "$ansi_white [-g/--global] Global Proxy $ansi_std" 1254 | echo -e "$ansi_white [-f/--flush] Clear firewall policy $ansi_std" 1255 | echo -e "$ansi_white [-u/--update] Update chnroutes Routing Host $ansi_std" 1256 | echo -e "$ansi_white [-ug/--update_gfwlist] Update GFWLIST domain $ansi_std" 1257 | echo -e "$ansi_white [-c/--check] Guardian ss-redir* $ansi_std" 1258 | echo -e "$ansi_white [-sw/--ss_switch] Account switching $ansi_std" 1259 | echo -e "$ansi_white [-sa/--services_action] Change all state services $ansi_std" 1260 | echo -e "$ansi_white [-b/--backup] Backup entware $ansi_std" 1261 | echo -e "$ansi_white [-e/--email] Send shadowsocks running information $ansi_std" 1262 | echo -e "$ansi_white [-h/--help] Script help $ansi_std" 1263 | echo -e "$ansi_white ===================================================================== $ansi_std" 1264 | exit 1265 | ;; 1266 | esac 1267 | --------------------------------------------------------------------------------