├── .gitattributes ├── .gitignore ├── Changelog.md ├── Install_From_Scratch.sh ├── LICENCE.md ├── P2Partisan └── p2partisan.sh ├── README.md ├── ci ├── .gitlab-ci.yml └── scripts │ ├── 00-libs.sh │ ├── 10-check_versions.sh │ ├── 30-check_bash.sh │ ├── 40-check_project.sh │ └── 99-end_script.sh ├── root ├── .bash_aliases ├── .bashrc ├── .inputrc ├── .profile ├── .screenrc ├── ConfigOverload │ └── .gitkeep ├── ISP │ └── Orange │ │ └── Orange_ISP.sh ├── OpenVPN │ ├── client1 │ │ └── .gitkeep │ ├── client2 │ │ └── .gitkeep │ ├── client3 │ │ └── .gitkeep │ ├── server1 │ │ └── .gitkeep │ └── server2 │ │ └── .gitkeep ├── SCRIPTs │ ├── Environment_Config.sh │ ├── Load_ArmExtras.sh │ ├── Services_Start.sh │ ├── Services_Stop.sh │ ├── USB_AfterMounting.sh │ ├── USB_BeforeUnmounting.sh │ ├── Upgrade.sh │ └── inc │ │ ├── funcs │ │ └── vars └── TEMPLATEs │ ├── .autorun.tmpl │ ├── dnscrypt │ ├── blacklists.txt.tmpl │ ├── cloaking-rules.txt.tmpl │ ├── dnscrypt-proxy.toml.tmpl │ ├── forwarding-rules.txt.tmpl │ ├── generate-domains-blacklists │ │ ├── domains-blacklist-local-additions.txt.tmpl │ │ ├── domains-blacklist.conf.tmpl │ │ ├── domains-time-restricted.txt.tmpl │ │ └── domains-whitelist.txt.tmpl │ ├── ip_blacklist.txt.tmpl │ └── whitelist.txt.tmpl │ ├── init │ ├── S01fake-hwclock.tmpl │ ├── S02syslog.tmpl │ ├── S03dnsmasq.tmpl │ ├── S09dnscrypt-proxy2.tmpl │ ├── S19rpcbind.tmpl │ ├── S57nfs-kernel-server.tmpl │ ├── S71openvpn-client1.tmpl │ ├── S72openvpn-client2.tmpl │ ├── S73openvpn-client3.tmpl │ ├── S74openvpn-server1.tmpl │ ├── S75openvpn-server2.tmpl │ ├── S76openvpn-server3.tmpl │ ├── S77ntpd.tmpl │ ├── S80cstats.tmpl │ ├── S81rstats.tmpl │ ├── S83samba.tmpl │ ├── rc.func.tmpl │ └── rc.unslung.tmpl │ ├── p2partisan │ ├── blacklist-custom.txt.tmpl │ ├── blacklists.txt.tmpl │ ├── greylist.txt.tmpl │ └── whitelist.txt.tmpl │ └── vars.tmpl └── version /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text eol=lf 3 | # Custom for Visual Studio 4 | *.cs diff=csharp 5 | *.sln merge=union 6 | *.csproj merge=union 7 | *.vbproj merge=union 8 | *.fsproj merge=union 9 | *.dbproj merge=union 10 | # Standard to msysgit 11 | *.doc diff=astextplain 12 | *.DOC diff=astextplain 13 | *.docx diff=astextplain 14 | *.DOCX diff=astextplain 15 | *.dot diff=astextplain 16 | *.DOT diff=astextplain 17 | *.pdf diff=astextplain 18 | *.PDF diff=astextplain 19 | *.rtf diff=astextplain 20 | *.RTF diff=astextplain 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.custom 2 | .vscode/ 3 | bin/ 4 | bash.exe.stackdump 5 | 6 | P2Partisan/* 7 | !P2Partisan/p2partisan.sh 8 | 9 | root/.ash_history 10 | root/.bash_history 11 | root/.config/ 12 | root/.uuid 13 | root/BACKUPs/ 14 | root/ConfigOverload/* 15 | 16 | ARM-Extras/ 17 | 18 | client1.log 19 | client2.log 20 | client3.log 21 | server1.log 22 | server2.log 23 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v1.0.14 - _2021/06/27_ 4 | 5 | - fix `.gitignore` 6 | - Shellcheck fix 7 | - code format 8 | - force scripts permissions 9 | - remove unused empty log files 10 | - fix `Upgrade.sh` about OPKG packages listing 11 | - `p2partisan.sh` 12 | - nslookup DNS 13 | - Shellcheck review 14 | - `deaggregate.sh` review 15 | - clean 16 | - force source of overloaded vars 17 | - force Quad9 DNS for internal scripts 18 | - fix shebang 19 | 20 | ## v1.0.13 - _2021/06/21_ 21 | 22 | - disable **Ext4 Metadata Checksums** for USB disk setup from documentation _(#2)_ 23 | - remove OPKG Python2 package to avoid `opkg_install_cmd: Cannot install package python` error 24 | 25 | ## v1.0.12 - _2020/03/26_ 26 | 27 | - typo fix 28 | - CI review 29 | 30 | ## v1.0.11 - _2019/09/22_ 31 | 32 | - DNScrypt-proxy v2 33 | - add 'gsExternalDns' variable for use external DNS server like PiHole 34 | - Minor code review 35 | 36 | ## v1.0.10 - _2019/04/13_ 37 | 38 | - DNScrypt-proxy v2 39 | - update dnscrypt-proxy.toml.tmpl 40 | - update generate-domains-blacklists/domains-blacklist.conf.tmpl 41 | - set doh_servers to false _(DoH is not available with OPKG binary)_ 42 | - disable empty public DNS in inti script 43 | 44 | ## v1.0.9 - _2019/03/04_ 45 | 46 | - funcs, bug fix 47 | - DNScrypt-proxy v2 48 | - active tls_cipher_suite for default config 49 | - clean blacklists.txt 50 | - update default entries for cloaking-rules.txt 51 | - update default entries for ip_blacklist.txt 52 | - activate and add default file for query.log _(Query logging)_ 53 | - activate and add default file for nx.log _(Suspicious queries logging)_ 54 | - add defaults generate-domains-blacklists config files 55 | 56 | ## v1.0.8 - _2019/02/24_ 57 | 58 | - code review of ci/31-check_bash.sh 59 | - remove all variable declaration 60 | - add Youtube to DNScrypt whitelist 61 | - update P2Partisan blacklists _(block more countries)_ 62 | 63 | ## v1.0.7 - _2019/01/31_ 64 | 65 | - mount /tmp to /opt/tmp to avoid overloading NVRAM 66 | - increase /tmp to 256MB 67 | - update DNScrypt-proxy blacklists.txt 68 | - P2Partisan disable upgrade & autorun functions 69 | - P2Partisan disable tutor on firewall script, add it to custom schedule 1 at 05:00 70 | - bug fix Install_From_Scratch.sh 71 | - code review for .autorun script 72 | - add lock file for USB_AfterMounting.sh & USB_BeforeUnmounting.sh 73 | - P2Partisan update blocklists 74 | 75 | ## v1.0.6 - _2019/01/29_ 76 | 77 | - add .autorun to /opt _(permit to restore last NVRAM config file after a reset)_ 78 | - add more NVRAM save _(after mounting, before unmounting, during upgrade)_ 79 | - add Python 2 & 3 packages 80 | - update DNScrypt-proxy blacklists.txt from [Public Blacklists](https://github.com/jedisct1/dnscrypt-proxy/wiki/Public-blacklists) 81 | - add [DNScrypt-proxy utils](https://github.com/jedisct1/dnscrypt-proxy/tree/master/utils/generate-domains-blacklists) 82 | - included DNScrypt-proxy repo update _(get latest DNScrypt-proxy utils)_ 83 | - add comment in README about DNScrypt-proxy utils 84 | - add loading custom config files directly into S09dnscrypt-proxy2.tmpl 85 | - P2Partisan, remove native autorun 86 | - disable Upgrade.sh after USB mounting 87 | 88 | ## v1.0.5 - _2019/01/28_ 89 | 90 | - p2partisan.sh 91 | - dynamic addition of all ports of system services _(nvram show 2>/dev/null | grep 'port=')_ 92 | - add gsP2Partisan_UdpPorts & gsP2Partisan_TcpPorts to vars files 93 | - update blocklists 94 | 95 | ## v1.0.4 - _2019/01/26_ 96 | 97 | - remove Orange ISP patch 98 | - change the location of custom configuration files for DNScrypt-proxy and P2Partisan 99 | - p2partisan.sh version code review 100 | - DNScrypt-proxy detect AIO firmware 101 | 102 | ## v1.0.3 - _2019/01/25_ 103 | 104 | - remove backup of DNScrypt-config.toml by date 105 | - add auto restore NVRAM configuration file after mount /opt 106 | - change the location of custom configuration files for DNScrypt-proxy and P2Partisan 107 | - bug fix for Orange_ISP.sh 108 | - create method for /sbin/udhcpc 109 | - nvram set script_init 110 | - orange_ack_script_fire.sh 111 | - variables backslashes 112 | - some mistakes - p2partisan.sh, correct some shellcheck errors codes _(SC2164, SC2034, SC2046, SC2154, SC2181, SC2162, SC2116, SC2016)_ 113 | 114 | ## v1.0.2 - _2019/01/22_ 115 | 116 | - disable DNScrypt v2 install for AIO firmware version _(nvram get os_version)_ 117 | - add port 52 to p2partisan whitelist 118 | - update README 119 | - add chmod after an Upgrade for p2partisan.sh 120 | 121 | ## v1.0.1 - _2019/01/22_ 122 | 123 | - add /opt/etc/init.d/ to .bashrc 124 | - add p2partisan.sh alias to .bash_aliases 125 | - code review for gfnP2pArtisanStartStop function to add/remove start on boot 126 | - add whiteports_tcp=43,80,443 and whiteports_udp=53,123,1194:1196 to p2partisan.sh 127 | 128 | ## v1.0.0 - _2019/01/19_ 129 | 130 | - First release 131 | -------------------------------------------------------------------------------- /Install_From_Scratch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # https://github.com/toulousain79/MyTomato 4 | 5 | #### Variables declaration 6 | gsDirLogs="" 7 | gsDirBackups="" 8 | gsDirArmExtras="" 9 | gsDirOverLoad="" 10 | gsWan1_DNS="" 11 | [ -n "${1}" ] && FILESYSTEM="${1}" || FILESYSTEM="ext4" 12 | 13 | #### Check if OPKG already exist 14 | (type opkg >/dev/null) && echo "ERROR: 'opkg' already exist" && exit 1 15 | 16 | #### Mount /opt 17 | (df -h | grep -q '/tmp/mnt/ENTWARE') && umount /tmp/mnt/ENTWARE 18 | echo "LABEL=ENTWARE /opt ${FILESYSTEM} defaults,data=writeback,noatime,nodiratime 0 0" >/etc/fstab 19 | mount -a 20 | (! df -h | grep -q '/opt') && echo "ERROR: '/opt' not mounting" && exit 1 21 | 22 | #### Install ENTWARE 23 | wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh 24 | 25 | ### Export 26 | (! echo "$PATH" | grep -q '/opt/bin') && PATH=$PATH:/opt/bin 27 | (! echo "$PATH" | grep -q '/opt/sbin') && PATH=$PATH:/opt/sbin 28 | export PATH 29 | 30 | wget -O - http://pkg.entware.net/sources/i18n_glib223.tar.gz | tar zx -C /tmp/ 31 | mv -v /tmp/i18n/locales/* /opt/usr/share/i18n/locales/ 32 | mv -v /tmp/i18n/charmaps/* /opt/usr/share/i18n/charmaps/ 33 | rm -rf /tmp/i18n 34 | 35 | opkg update 36 | opkg install \ 37 | bash \ 38 | wget \ 39 | curl \ 40 | bzip2 \ 41 | less \ 42 | lsof \ 43 | perl \ 44 | tar \ 45 | unzip \ 46 | sed \ 47 | vim \ 48 | vim-runtime \ 49 | tcpdump \ 50 | htop \ 51 | gawk \ 52 | bind-dig \ 53 | file \ 54 | strace \ 55 | whereis \ 56 | mlocate \ 57 | git \ 58 | jq \ 59 | xxd \ 60 | logrotate \ 61 | mount-utils \ 62 | coreutils-ln \ 63 | coreutils-uniq \ 64 | coreutils-kill \ 65 | coreutils-dircolors \ 66 | coreutils-dirname \ 67 | coreutils-cp \ 68 | coreutils-mv \ 69 | coreutils-chown \ 70 | coreutils-chmod \ 71 | coreutils-cat \ 72 | coreutils-basename \ 73 | coreutils-install \ 74 | coreutils-df \ 75 | procps-ng-ps \ 76 | procps-ng-pgrep \ 77 | ca-certificates \ 78 | ca-bundle \ 79 | fake-hwclock \ 80 | ntpdate \ 81 | ntpd \ 82 | rsync \ 83 | openssh-sftp-server \ 84 | nfs-kernel-server \ 85 | nfs-kernel-server-utils \ 86 | python3 87 | 88 | #### NTP 89 | ntpdate -4 -p 1 -u 0.fr.pool.ntp.org 90 | 91 | #### Clone GitHub repoistory 92 | if [ ! -d /opt/MyTomato ]; then 93 | git clone git://github.com/toulousain79/MyTomato.git /opt/MyTomato 94 | else 95 | cd /opt/MyTomato || exit 1 96 | git fetch origin 97 | git reset --hard origin/master 98 | git pull origin master 99 | fi 100 | 101 | #### DNScrypt-proxy v2 102 | if (! nvram get os_version | grep -q 'AIO'); then 103 | if [ ! -d /opt/usr/local/dnscrypt-proxy ]; then 104 | git clone git://github.com/jedisct1/dnscrypt-proxy.git /opt/usr/local/dnscrypt-proxy 105 | else 106 | cd /opt/usr/local/dnscrypt-proxy || exit 1 107 | git fetch origin 108 | git reset --hard origin/master 109 | git pull origin master 110 | fi 111 | if [ -f /opt/usr/local/dnscrypt-proxy/utils/generate-domains-blacklists/generate-domains-blacklist.py ]; then 112 | cd /opt/usr/local/dnscrypt-proxy/utils/generate-domains-blacklists/ || exit 113 | chmod +x generate-domains-blacklist.py 114 | # python generate-domains-blacklist.py >list.txt.tmp && mv -f list.txt.tmp blacklists.txt 115 | fi 116 | fi 117 | 118 | # Add /opt UUID to "/opt/MyTomato/root/ConfigOverload/vars" 119 | cp -v /opt/MyTomato/root/TEMPLATEs/vars.tmpl /opt/MyTomato/root/ConfigOverload/vars 120 | gsUsbOptUuid="$(blkid | grep 'ENTWARE' | awk '{ print $3 }' | cut -d '"' -f 2)" 121 | if [ -f /opt/MyTomato/root/ConfigOverload/vars ]; then 122 | nNumLine=$(grep 'gsUsbOptUuid' -n -m 1 >/opt/MyTomato/root/ConfigOverload/vars 134 | fi 135 | 136 | #### Loading vars 137 | [ ! -f /opt/MyTomato/root/SCRIPTs/inc/vars ] && { 138 | echo "Error, '/opt/MyTomato/root/SCRIPTs/inc/vars' file does not exist, aborting !" 139 | exit 1 140 | } 141 | # shellcheck source=root/SCRIPTs/inc/vars 142 | . /opt/MyTomato/root/SCRIPTs/inc/vars 143 | # shellcheck source=root/SCRIPTs/inc/vars 144 | . /opt/MyTomato/root/ConfigOverload/vars 145 | export PATH=/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin:/bin:/sbin:/mmc/bin:/mmc/sbin:/mmc/usr/bin:/mmc/usr/sbin:/usr/bin:/usr/sbin:/home/root 146 | echo "Firmware Version: ${gsFirmwareVersion}" 147 | echo "Firmware Year: ${gsFirmwareYear}" 148 | echo "URL Arm-Extras: ${gsUrlArmExtras}" 149 | echo "Locales: ${gsLocales}" 150 | echo "Timezone: ${gsTimezone}" 151 | echo "USB filesystem: ${gsUsbFileSystem}" 152 | echo "USB UUID: ${gsUsbOptUuid}" 153 | echo "Enable P2Partisan: ${gbP2Partisan_Enable}" 154 | echo "Enable DSNcrypt: ${gbDNScrypt_Enable}" 155 | echo "Default DNS (Quad 9): ${gsWan1_DNS}" 156 | echo "Enable repo auto upgrade: ${gbRepoUpgrade_Enable}" 157 | 158 | #### Add /opt/bin/bash to /opt/etc/shells 159 | (! grep -q '/opt/bin/bash' /opt/etc/shells) && echo "/opt/bin/bash" >>/opt/etc/shells 160 | cat /opt/etc/shells 161 | 162 | #### Locales 163 | [ -n "${gsLocales}" ] && /opt/bin/localedef.new -c -f UTF-8 -i "${gsLocales}" "${gsLocales}.UTF-8" 164 | [ -n "${gsTimezone}" ] && ln -sfv /opt/share/zoneinfo/${gsTimezone} /opt/etc/localtime 165 | 166 | #### TAG '/opt' and '/opt/var/log' with UUID to avoid deleting 167 | if [ -n "${gsUsbOptUuid}" ]; then 168 | if [ ! -f /opt/.uuid ] || [ "$(cat /opt/.uuid)" != "${gsUsbOptUuid}" ]; then 169 | echo "${gsUsbOptUuid}" >/opt/.uuid 170 | fi 171 | if [ ! -f /opt/root/.uuid ] || [ "$(cat /opt/root/.uuid)" != "${gsUsbOptUuid}" ]; then 172 | echo "${gsUsbOptUuid}" >/opt/root/.uuid 173 | fi 174 | if [ ! -f /opt/var/log/.uuid ] || [ "$(cat /opt/var/log/.uuid)" != "${gsUsbOptUuid}" ]; then 175 | echo "${gsUsbOptUuid}" >/opt/var/log/.uuid 176 | fi 177 | fi 178 | 179 | #### Prepare some files and directories #### 180 | # /opt/tmp 181 | if (! mount -l | grep -q '/tmp'); then 182 | mount -t tmpfs -o size=256M,mode=0755 tmpfs /opt/tmp/ 183 | cp -af /tmp/* /opt/tmp/ 184 | rm -rRf /tmp/* && rm -rRf /tmp/.??* 185 | mount -v --bind /opt/tmp /tmp 186 | fi 187 | 188 | # /opt/var/log 189 | if (! mount -l | grep -q '/tmp/var/log'); then 190 | if [ -f /tmp/var/log/messages ]; then 191 | cat /tmp/var/log/messages >>/opt/var/log/messages 192 | if [ ! -f /tmp/var/log/.uuid ]; then 193 | rm -rRfv /tmp/var/log/* && rm -rRf /tmp/var/log/.??* 194 | fi 195 | /opt/bin/mount -v --bind /opt/var/log /tmp/var/log 196 | fi 197 | fi 198 | 199 | # /opt/root 200 | if (! mount -l | grep -q '/tmp/home/root'); then 201 | if [ ! -f /tmp/home/root/.uuid ]; then 202 | rm -rRf /tmp/home/root/* && rm -rRf /tmp/home/root/.??* 203 | rm -rf /opt/root 204 | fi 205 | /opt/bin/mount -v --bind /opt/MyTomato/root /tmp/home/root 206 | fi 207 | [ ! -h /opt/root ] && ln -s /opt/MyTomato/root/ /opt/root 208 | 209 | # Rights 210 | chmod +x ${gsDirScripts}/* 211 | 212 | # Creating directories 213 | mkdir -pv "${gsDirBackups}" 214 | mkdir -pv "${gsDirArmExtras}" 215 | mkdir -pv "${gsDirOverLoad}/p2partisan" 216 | mkdir -pv "${gsDirOverLoad}/dnscrypt" 217 | 218 | # Copy back all existing init files 219 | /opt/bin/find /opt/etc/init.d/ -type f -name "*" -exec bash -c 'i="$1"; cp -v "${i}" "${gsDirBackups}/$(basename ${i}).original"' _ {} \; 220 | 221 | # Copy all init files 222 | /opt/bin/find "${gsDirTemplates}/init/" -name "*.tmpl" -exec bash -c 'i="$1"; cp -v "${i}" /opt/etc/init.d/$(basename $(echo "${i}" | sed "s/.tmpl//g;"))' _ {} \; 223 | chmod +x /opt/etc/init.d/* 224 | 225 | # Create empty file 226 | touch /etc/dnsmasq-custom.conf 227 | touch ${gsDirOverLoad}/.bash_aliases 228 | /opt/bin/find "${gsDirTemplates}/p2partisan/" -name "*.txt.tmpl" -exec bash -c 'i="$1"; cp -v "${i}" ${gsDirOverLoad}/p2partisan/$(basename $(echo "$1" | sed "s/p2partisan.//g;s/.txt.tmpl//g;"))' _ {} \; 229 | /opt/bin/find "${gsDirTemplates}/dnscrypt/" -name "*.txt.tmpl" -exec bash -c 'i="$1"; cp -v "${i}" ${gsDirOverLoad}/dnscrypt/$(basename $(echo "$1" | sed "s/.tmpl//g;"))' _ {} \; 230 | 231 | #### NVRAM settings 232 | # Administration > Scripts > Init 233 | nvram set script_init="echo \"LABEL=SWAP none swap sw 0 0\" > /etc/fstab 234 | echo \"LABEL=ENTWARE /opt ${FILESYSTEM} defaults,data=writeback,noatime,nodiratime 0 0\" >> /etc/fstab 235 | touch /etc/dnsmasq-custom.conf" 236 | 237 | # USB and NAS > USB Support>Run after mounting 238 | nvram set script_usbmount="{ [ \"\$1\" == \"/opt\" ]; [ -f \"\$1/MyTomato/root/SCRIPTs/USB_AfterMounting.sh\" ]; } && bash \"\$1/MyTomato/root/SCRIPTs/USB_AfterMounting.sh\"" 239 | # USB and NAS > USB Support>Run before unmounting 240 | { 241 | echo "{ [ \"\$1\" == \"/opt\" ]; [ -f \"\$1/MyTomato/root/SCRIPTs/USB_BeforeUnmounting.sh\" ]; } && bash \"\$1/MyTomato/root/SCRIPTs/USB_BeforeUnmounting.sh\"" 242 | echo "sleep 2; service dnsmasq restart" 243 | } >/tmp/script_usbumount 244 | nvram set script_usbumount="$(cat /tmp/script_usbumount)" 245 | # Administration > Scheduler > Custom 1 246 | nvram set sch_c1=1,300,127 # Everyday at 5:00 am 247 | nvram set sch_c1_cmd="bash ${gsDirScripts}/Upgrade.sh" 248 | # Administration > Script > Shutdown 249 | nvram set script_shut="[ -f ${gsDirScripts}/USB_BeforeUnmounting.sh ] && bash ${gsDirScripts}/USB_BeforeUnmounting.sh" 250 | #### Administration > Logging > Syslog 251 | nvram set log_file=1 252 | nvram set log_events="acre,crond,dhcpc,ntp,sched" 253 | nvram set log_file_custom=1 254 | nvram set log_file_path="/var/log/messages" 255 | nvram set log_file_keep=30 256 | nvram set log_file_size=10240 257 | nvram set log_limit=0 258 | nvram set log_mark=30 259 | ### Administration > Logging > IP Traffic Monitoring 260 | nvram set cstats_enable=0 261 | nvram set cstats_path="${gsDirLogs}/" 262 | nvram set cstats_offset=1 263 | nvram set cstats_stime=1 264 | nvram set cstats_include= 265 | nvram set cstats_exclude= 266 | nvram set cstats_sshut=1 267 | nvram set cstats_bak=1 268 | ### Administration > Logging > Bandwidth Monitoring 269 | nvram set rstats_enable=0 270 | nvram set rstats_path="${gsDirLogs}/" 271 | nvram set rstats_offset=1 272 | nvram set rstats_stime=1 273 | nvram set rstats_exclude= 274 | nvram set rstats_sshut=1 275 | nvram set rstats_bak=1 276 | ## Basic > Identification > Hostname 277 | nvram set wan_hostname="MyTomato" 278 | ## Basic > Network > WAN Settings > WAN 1 279 | nvram set wan_dns="${gsWan1_DNS}" 280 | ## Basic > Time 281 | nvram set ntp_tdod=1 282 | ## VPN Tunneling > OpenVPN Client > Client 1 > Advanced 283 | { 284 | echo "ca /opt/MyTomato/root/OpenVPN/client1/ca_example.crt" 285 | echo "cert /opt/MyTomato/root/OpenVPN/client1/demo_example.crt" 286 | echo "key /opt/MyTomato/root/OpenVPN/client1/demo_example.key" 287 | echo "tls-auth /opt/MyTomato/root/OpenVPN/client1/ta_example.key 1" 288 | echo "log /opt/MyTomato/root/OpenVPN/client1/client1.log" 289 | echo "verb 3" 290 | } >>/tmp/openvpn_client1 291 | nvram set vpn_client1_custom="$(cat /tmp/openvpn_client1)" 292 | 293 | #### Cleaning 294 | rm -fv /tmp/script_init 295 | rm -fv /tmp/script_fire 296 | rm -fv /tmp/script_usbumount 297 | rm -fv /tmp/openvpn_client1 298 | rm -fv /opt/etc/init.d/S77ntpdate 299 | rm -fv /opt/etc/*.1 300 | if (nvram get os_version | grep -q 'AIO'); then 301 | rm -fv /opt/etc/dnscrypt-proxy.toml 302 | rm -fv ${gsDirBackups}/dnscrypt-proxy* 303 | rm -fv /opt/etc/init.d/S09dnscrypt-proxy2 304 | rm -fv ${gsDirOverLoad}/dnscrypt* 305 | rm -fv ${gsDirOverLoad}/*.md 306 | rm -fv ${gsDirOverLoad}/*.minisig 307 | 308 | nNumLine=$(grep 'gbDNScrypt_Enable' -n -m 1 >/opt/etc/group 333 | cat /opt/etc/group 334 | updatedb 335 | 336 | #### NVRAM config save 337 | nvram set mytomato_config_save="${gdDateTime}" 338 | nvram commit 339 | nvram save "${gsDirBackups}/MyTomato_${gdDateTime}.cfg" >/dev/null 2>&1 340 | 341 | #### Reboot needed 342 | echo 343 | echo 344 | echo "Please, adapt '${gsDirOverLoad}/vars' as you want..." 345 | echo 346 | echo "And, reboot your router..." 347 | echo "The reboot can take a while, so please be patient." 348 | echo 349 | echo "Maybe adapt your LAN IP address... ;-)" 350 | echo 351 | echo 352 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 toulousain79 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MyTomato _(ARMv7 only)_ 2 | 3 | TomatoUSB environment for Shibby or FreshTomato **ARM v7** firmwares VPN version _(kernel v2.6.36)_. 4 | 5 | 11 | 12 |
15 | 16 | 22 | 23 | ## Features 24 | 25 | - Install latest [Entware](https://github.com/Entware/Entware) version _(Merge of Entware-ng-3x and Entware-ng)_ 26 | - Use of [standard](https://github.com/Entware/Entware/wiki/Alternative-install-vs-standard) installation version _(generic for kernel v2.6.36)_ 27 | - Prepare an environment for root user 28 | - bash _(prompt, locale, colors, readline, bash on login, ...)_ 29 | - aliases for all Entware binaries installed _(dynamically)_ 30 | - admin tools 31 | - PATH updated to prioritize binaries in /opt 32 | - code review of rc.unslung 33 | - add locales & timezone 34 | - auto restore the last NVRAM config saved on /opt 35 | - Project auto upgrade _(Entware & GitHub)_ 36 | - get patch 37 | - new features 38 | - ARM-Extras modules downloaded automatically 39 | - [P2Partisan v6.08](https://www.linksysinfo.org/index.php?threads/p2partisan-v5-14-v6-08-mass-ip-blocking-peerblock-peerguardian-for-tomato.69128/) 40 | - countries blocklists 41 | - usual blocklists 42 | - known addresses of TMG 43 | - code review 44 | - [DNScrypt-proxy v2](https://github.com/jedisct1/dnscrypt-proxy/blob/master/README.md) _(no DoH)_ _(disabled for AIO firmwares)_ 45 | - DNS query monitoring, with separate log files for regular and suspicious queries 46 | - Filtering: **block ads**, **malware**, and other unwanted content. Compatible with all DNS services 47 | - Time-based filtering, with a flexible weekly schedule 48 | - Compatible with DNSSEC 49 | - ... 50 | - NVram sets 51 | - init script 52 | - shutdown script 53 | - USB mount/unmount for /opt 54 | - ... 55 | 56 | ### Test on 57 | 58 | - Netgear R7000 _(FreshTomato)_ 59 | 60 | ## Install 61 | 62 | ### Prepare your USB disk _(mine is a 60Go SSD on USB 3.0)_ 63 | 64 | You must create partitions before _(fdisk /dev/xxx ?)_ ;-) 65 | 66 | Replace **/dev/xxxx** by your device _(ex: /dev/sda2)_ 67 | 68 | For an USB key, you can use _ext2_, because this filesystem limits disk access in read and write _(Journaling & Directory Indexing)_. 69 | 70 | Seas personally, I prefer to use _ext4_, as long as I disable the journaling. 71 | 72 | This allows faster read/write access, and increases the life of your USB device ;-) 73 | 74 | 1. Prepare your SWAP and ext4 partitions 75 | 76 | 2. Format the **SWAP** partition with the label **SWAP** _(for size, 128M is sufficient)_ 77 | 78 | ```bash 79 | mkswap -L SWAP /dev/xxxx 80 | ``` 81 | 82 | 3. Format **/opt** partition as EXT4 with the label **ENTWARE** _(minimum of 4Go)_ 83 | 84 | ```bash 85 | mkfs.ext4 -L ENTWARE /dev/xxxx 86 | ``` 87 | 88 | 4. Tuning the Ext4 filesystem _(disable Journal, disable Directory Indexing, disable Ext4 Metadata Checksums, reduce 5% to 2% Reserved Blocks)_ 89 | 90 | ```bash 91 | tune2fs -o ^journal_data_writeback -O ^has_journal,dir_index,^metadata_csum /dev/xxxx 92 | tune2fs -m 2 /dev/xxxx 93 | e2fsck -Df /dev/xxxx 94 | ``` 95 | 96 | ### Install MyTomato 97 | 98 | **It is best to before perform an _Erase all data in NVRAM memory thorough_.** 99 | 100 | 1. Plug your disk on router 101 | 102 | 2. Login in SSH 103 | 104 | 3. Make sure you have a working Internet connection on your router 105 | 106 | 4. Execute the installation 107 | 108 | Where FILESYSTEM can be **ext2**, **ext3** or **ext4** _(default)_ 109 | 110 | ```bash 111 | export FILESYSTEM="ext4" 112 | wget -O - https://raw.githubusercontent.com/toulousain79/MyTomato/master/Install_From_Scratch.sh | sh 113 | ``` 114 | 115 | 5. At the end, you will get the following message: 116 | 117 | ```bash 118 | Please, adapt '/opt/MyTomato/root/ConfigOverload/vars' as you want... 119 | 120 | And, reboot your router... 121 | The reboot can take a while, so please be patient. 122 | 123 | Maybe adapt your LAN IP address... ;-) 124 | ``` 125 | 126 | _**NB:** Default IP address is **192.168.1.1**_ 127 | 128 | 6. It's time to fill in your variables 129 | 130 | ```bash 131 | vim /opt/MyTomato/root/ConfigOverload/vars 132 | ``` 133 | 134 | 7. Reboot 135 | 136 | ## Availables commands 137 | 138 | All the scripts present in /opt/MyTomato/root/SCRIPTs/ are accessible directly via the PATH. 139 | 140 | - **USB_AfterMounting.sh** 141 | - executed after USB /opt mounting 142 | - **Services_Start.sh** 143 | - executed by USB_AfterMounting.sh 144 | - start all services using _/opt/etc/init.d/rc.unslung_ script 145 | - **USB_BeforeUnmounting.sh** 146 | - executed after USB /opt UNmounting 147 | - **Services_Stop.sh** 148 | - executed by USB_BeforeUnmounting.sh 149 | - stop all services using _/opt/etc/init.d/rc.unslung_ script 150 | - **Upgrade.sh** 151 | - executed periodically every day 152 | - upgrade /opt/MyTomato/ via GitHub 153 | - update & upgrade OPKG packages 154 | 155 | ## Personalization 156 | 157 | To allow the update of MyTomato, some files _(ex: config)_, are overchargeable. 158 | 159 | If you modify the original files, you will **lose** your changes during an update of MyTomato. 160 | 161 | Editable files are: 162 | 163 | - System 164 | - /opt/MyTomato/root/ConfigOverload/vars 165 | - /opt/MyTomato/root/ConfigOverload/.bash_aliases 166 | - /opt/MyTomato/root/ConfigOverload/.bashrc 167 | 168 | - DNScrypt-proxy v2 _(default files)_ 169 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/dnscrypt-proxy.toml _(DNScrypt config file)_ 170 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/blacklists.txt 171 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/ip_blacklist.txt 172 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/whitelist.txt 173 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/cloaking-rules.txt 174 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/forwarding-rules.txt 175 | 176 | - DNScrypt-proxy v2 _(generate-domains-blacklists)_ 177 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/domains-blacklist.conf 178 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/domains-blacklist-local-additions.txt 179 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/domains-time-restricted.txt 180 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/domains-whitelist.txt 181 | 182 | - P2Partisan 183 | - /opt/MyTomato/root/ConfigOverload/p2partisan/blacklists 184 | - /opt/MyTomato/root/ConfigOverload/p2partisan/blacklists-custom 185 | - /opt/MyTomato/root/ConfigOverload/p2partisan/greylist 186 | - /opt/MyTomato/root/ConfigOverload/p2partisan/whitelist 187 | 188 | ## Additional services 189 | 190 | ### P2Partisan _(mass IP blocking like peerblock/peerguardian for tomato)_ 191 | 192 | All ports of system services are dynamicly added to whitelist. _(nvram show 2>/dev/null | grep 'port=')_ 193 | 194 | And you can add more into **/opt/MyTomato/root/ConfigOverload/vars**. 195 | 196 | #### P2Partisan - Config file 197 | 198 | ```bash 199 | vim /opt/MyTomato/P2Partisan/p2partisan.sh 200 | ``` 201 | 202 | _**NB:** Default values are acceptable_ 203 | 204 | #### Blocklists 205 | 206 | - /opt/MyTomato/root/ConfigOverload/p2partisan/whitelist 207 | - /opt/MyTomato/root/ConfigOverload/p2partisan/greylist 208 | - /opt/MyTomato/root/ConfigOverload/p2partisan/blacklists 209 | - /opt/MyTomato/root/ConfigOverload/p2partisan/blacklist-custom 210 | 211 | _**NB:** Default values are acceptable_ 212 | 213 | ### DNScrypt-proxy v2 214 | 215 | #### DNScrypt-proxy - Config file 216 | 217 | ```bash 218 | vim /opt/MyTomato/root/ConfigOverload/dnscrypt/dnscrypt-proxy.toml 219 | ``` 220 | 221 | You can generate your own **blacklist.txt** with in **/opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/**. 222 | 223 | Please, check [Public Blacklists](https://github.com/jedisct1/dnscrypt-proxy/wiki/Public-blacklists) 224 | 225 | Edit following files like you want to generate your final **blocklist.txt**: 226 | 227 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/**domains-blacklist.conf** 228 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/**domains-whitelist.txt** 229 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/**domains-time-restricted.txt** 230 | - /opt/MyTomato/root/ConfigOverload/dnscrypt/generate-domains-blacklists/**domains-blacklist-local-additions.txt** 231 | 232 | And, simply execute this: 233 | 234 | ```bash 235 | Upgrade.sh 236 | . /opt/MyTomato/root/SCRIPTs/inc/vars 237 | cp -f "${gsDirOverLoad}/dnscrypt/generate-domains-blacklists/blacklists.txt" "${gsDirOverLoad}/dnscrypt/blacklists.txt" 238 | /opt/etc/init.d/S09dnscrypt-proxy2 restart 239 | ``` 240 | 241 | _**NB:** Default values are acceptable_ 242 | 243 | ## Links 244 | 245 | - [FreshTomato](http://freshtomato.org/) _(active development from Shibby work)_ 246 | - [Tomato by Shibby](http://tomato.groov.pl/) 247 | - [Entware - WiKi](https://github.com/Entware/Entware/wiki) 248 | - [DNScrypt - WiKi](https://github.com/jedisct1/dnscrypt-proxy/wiki) 249 | - [DNScrypt - Public Blacklists](https://github.com/jedisct1/dnscrypt-proxy/wiki/Public-blacklists) 250 | - [P2Partisan](https://www.linksysinfo.org/index.php?threads/p2partisan-v5-14-v6-08-mass-ip-blocking-peerblock-peerguardian-for-tomato.69128/) 251 | - [armv7sf-k3.2 - installer](http://bin.entware.net/armv7sf-k3.2/installer/) 252 | -------------------------------------------------------------------------------- /ci/.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | stages: 3 | - scheduled_check_develop 4 | - scheduled_check_master 5 | - check_develop_before_merge 6 | - check_master_after_merge 7 | 8 | # #### Templates - BoF 9 | .tmpl_check: &tmpl_check 10 | image: ${REGISTRY_IMAGES} 11 | script: 12 | - | 13 | for script in $(echo ${CI_PROJECT_DIR}/ci/scripts/[0-9][0-9]-*.sh); do 14 | echo ${script} "${CI_PROJECT_DIR}" 15 | done 16 | for script in $(echo ${CI_PROJECT_DIR}/ci/scripts/[0-9][0-9]-*.sh); do 17 | . ${script} "${CI_PROJECT_DIR}" 18 | done 19 | # #### Templates - EoF 20 | 21 | # #### Project check scheduled - BoF 22 | Scheduled Develop: 23 | stage: scheduled_check_develop 24 | only: 25 | refs: 26 | - schedules 27 | variables: 28 | - $RELEASE == "develop" 29 | <<: *tmpl_check 30 | 31 | Scheduled Prod: 32 | stage: scheduled_check_master 33 | only: 34 | refs: 35 | - schedules 36 | variables: 37 | - $RELEASE == "prod" 38 | <<: *tmpl_check 39 | # #### Project check scheduled - EoF 40 | 41 | # #### Project check before merge - BoF 42 | Develop: 43 | stage: check_develop_before_merge 44 | only: 45 | refs: 46 | - merge_requests 47 | <<: *tmpl_check 48 | 49 | Prod: 50 | stage: check_master_after_merge 51 | <<: *tmpl_check 52 | only: 53 | - master 54 | except: 55 | - schedules 56 | when: on_success 57 | # #### Project check before merge - EoF 58 | -------------------------------------------------------------------------------- /ci/scripts/00-libs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #### 0 - Base 4 | sPwd=$(pwd) 5 | nReturn=0 6 | [ -n "${CI_PROJECT_PATH}" ] && sProjectDir="/builds/${CI_PROJECT_PATH}" || sProjectDir="$(pwd)" 7 | sDirToScan="/tmp/shellcheck_scan" 8 | 9 | #### 1 - Colors 10 | CEND="\033[0m" 11 | CRED="\033[1;31m" 12 | CGREEN="\033[1;32m" 13 | CYELLOW="\033[1;33m" 14 | CBLUE="\033[1;34m" 15 | 16 | #### 2 - Functions 17 | function gfnCopyProject() { 18 | [ -d "${sDirToScan}" ] && rm -rf "${sDirToScan}" 19 | 20 | if [ -n "${sProjectDir}" ] && [ -d "${sProjectDir}" ]; then 21 | rsync -a --exclude '.git' "${sProjectDir}/" "${sDirToScan}/" 22 | else 23 | echo -e "${CYELLOW}You are not in 'project_validation' images:${CEND} ${CRED}Failed${CEND}" 24 | exit 1 25 | fi 26 | } 27 | 28 | #### Export 29 | export gbLoaded sPwd nReturn CEND CRED CGREEN CYELLOW CBLUE 30 | -------------------------------------------------------------------------------- /ci/scripts/10-check_versions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo && echo -e "${CBLUE}*** Current branch ***${CEND}" 4 | if [ -n "${CI_COMMIT_REF_NAME}" ]; then 5 | echo "${CI_COMMIT_REF_NAME}" 6 | else 7 | git branch | grep "^* " 8 | fi 9 | 10 | echo && echo -e "${CBLUE}*** Check bash version ***${CEND}" 11 | if (! bash --version); then 12 | echo -e "${CYELLOW}bash version:${CEND} ${CRED}Failed${CEND}" 13 | nReturn=$((nReturn + 1)) 14 | fi 15 | 16 | echo && echo -e "${CBLUE}*** Check shellcheck version ***${CEND}" 17 | if (! shellcheck --version); then 18 | echo -e "${CYELLOW}shellcheck version:${CEND} ${CRED}Failed${CEND}" 19 | nReturn=$((nReturn + 1)) 20 | fi 21 | 22 | echo && echo -e "${CBLUE}*** Check dos2unix version ***${CEND}" 23 | if (! dos2unix --version); then 24 | echo -e "${CYELLOW}dos2unix version:${CEND} ${CRED}Failed${CEND}" 25 | nReturn=$((nReturn + 1)) 26 | fi 27 | 28 | echo && echo -e "${CBLUE}*** Check xz version ***${CEND}" 29 | if (! xz --version); then 30 | echo -e "${CYELLOW}xz version:${CEND} ${CRED}Failed${CEND}" 31 | nReturn=$((nReturn + 1)) 32 | fi 33 | 34 | echo && echo -e "${CBLUE}*** Check rsync version ***${CEND}" 35 | if (! rsync --version); then 36 | echo -e "${CYELLOW}rsync version:${CEND} ${CRED}Failed${CEND}" 37 | nReturn=$((nReturn + 1)) 38 | fi 39 | 40 | echo && echo -e "${CBLUE}*** Check pylint version ***${CEND}" 41 | if (! pylint --version); then 42 | echo -e "${CYELLOW}pylint version:${CEND} ${CRED}Failed${CEND}" 43 | nReturn=$((nReturn + 1)) 44 | fi 45 | 46 | echo && echo -e "${CBLUE}*** Check pylint3 version ***${CEND}" 47 | if (! pylint3 --version); then 48 | echo -e "${CYELLOW}pylint3 version:${CEND} ${CRED}Failed${CEND}" 49 | nReturn=$((nReturn + 1)) 50 | fi 51 | 52 | export nReturn 53 | -------------------------------------------------------------------------------- /ci/scripts/30-check_bash.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ###################################################################### 3 | # https://github.com/koalaman/shellcheck/wiki/Recursiveness 4 | ##################### FIRST LINE ##################################### 5 | 6 | if [ -z "${vars}" ] || [ "${vars}" -eq 0 ]; then 7 | # shellcheck source=/dev/null 8 | . "/builds/${CI_PROJECT_PATH}/ci/scripts/00-libs.sh" 9 | else 10 | nReturn=$((nReturn + 1)) 11 | fi 12 | 13 | gfnCopyProject 14 | 15 | sFilesListSh="$(grep -IRl "\(#\!/bin/\|shell\=\)sh" --exclude-dir ".git" --exclude-dir ".vscode" --exclude "funcs_*" "${sDirToScan}/")" 16 | if [ -n "${sFilesListSh}" ]; then 17 | echo && echo -e "${CBLUE}*** Check Syntax with Shellcheck (sh) ***${CEND}" 18 | for sFile in ${sFilesListSh}; do 19 | if ! shellcheck -s sh -f tty -S error -S warning -e SC2154 "${sFile}"; then 20 | echo -e "${CYELLOW}${sFile}:${CEND} ${CRED}Failed${CEND}" 21 | nReturn=$((nReturn + 1)) 22 | else 23 | echo -e "${CYELLOW}${sFile}:${CEND} ${CGREEN}Passed${CEND}" 24 | fi 25 | done 26 | fi 27 | 28 | sFilesListBash="$(grep -IRl "\(#\!/bin/\|shell\=\)bash" --exclude-dir ".git" --exclude-dir ".vscode" --exclude-dir ".vscode" "${sDirToScan}/")" 29 | if [ -n "${sFilesListBash}" ]; then 30 | echo && echo -e "${CBLUE}*** Check Syntax with Shellcheck (bash) ***${CEND}" 31 | for sFile in ${sFilesListBash}; do 32 | if ! shellcheck -s bash -f tty -S error -S warning -e SC2154 "${sFile}"; then 33 | echo -e "${CYELLOW}${sFile}:${CEND} ${CRED}Failed${CEND}" 34 | nReturn=$((nReturn + 1)) 35 | else 36 | echo -e "${CYELLOW}${sFile}:${CEND} ${CGREEN}Passed${CEND}" 37 | fi 38 | done 39 | fi 40 | 41 | sFuncsList="$(grep -R -h -E "^[A-Za-z]+[A-Za-z0-9]*(\(\)\ \{)" "${sDirToScan}/root/SCRIPTs/inc/" | cut -d '(' -f 1 | sort)" 42 | if [ -n "${sFuncsList}" ]; then 43 | echo && echo -e "${CBLUE}*** Check for orphan functions ***${CEND}" 44 | for func in ${sFuncsList}; do 45 | nCount=$(grep -R "${func}" "${sDirToScan}/" | wc -l) 46 | case "${nCount}" in 47 | 1) 48 | echo -e "${CYELLOW}${func}:${CEND} ${CRED}Failed${CEND}" 49 | nReturn=$((nReturn + 1)) 50 | ;; 51 | *) 52 | echo -e "${CYELLOW}${func}:${CEND} ${CGREEN}Passed${CEND}" 53 | ;; 54 | esac 55 | done 56 | fi 57 | 58 | sFilesListSh="$(grep -IRl "\(#\!/bin/\|shell\=\)sh" --exclude-dir ".git" --exclude-dir ".vscode" --exclude-dir "ci" "${sDirToScan}/")" 59 | sFilesListBash="$(grep -IRl "\(#\!/bin/\|shell\=\)bash" --exclude-dir ".git" --exclude-dir ".vscode" --exclude-dir "ci" "${sDirToScan}/")" 60 | sFilesList="${sFilesListSh} ${sFilesListBash}" 61 | if [ -n "${sFilesList}" ]; then 62 | echo && echo -e "${CBLUE}*** Check scripts with 'set -n' ***${CEND}" 63 | for file in ${sFilesList}; do 64 | sed -i '/includes_before/d' "${file}" 65 | sed -i '/includes_after/d' "${file}" 66 | sed -i '/#!\/bin\/bash/d' "${file}" 67 | sed -i '1iset -n' "${file}" 68 | echo "set +n" >>"${file}" 69 | dos2unix "${file}" &>/dev/null 70 | if (bash "${file}"); then 71 | echo -e "${CYELLOW}${file}:${CEND} ${CGREEN}Passed${CEND}" 72 | else 73 | echo -e "${CYELLOW}${file}:${CEND} ${CRED}Failed${CEND}" 74 | nReturn=$((nReturn + 1)) 75 | fi 76 | done 77 | fi 78 | -------------------------------------------------------------------------------- /ci/scripts/40-check_project.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 1/ lister tous les fichiers .tmpl 4 | # 2/ pour chaque fichier trouvé, rechercher si il est appelé 5 | # SI trouvé ALORS OK 6 | # SI trouvé ET commenté ALORS WARNING 7 | # SINON KO 8 | 9 | if [ -z "${vars}" ] || [ "${vars}" -eq 0 ]; then 10 | # shellcheck source=/dev/null 11 | . "/builds/${CI_PROJECT_PATH}/ci/scripts/00-libs.sh" 12 | else 13 | nReturn=$((nReturn + 1)) 14 | fi 15 | 16 | gfnCopyProject 17 | 18 | # Templates files used 19 | sFilesListTmpl="$(find "${sDirToScan}"/root/TEMPLATEs/ -type f -name "*.tmpl" -printf "%f\n" | sort -z | xargs -r0)" 20 | if [ -n "${sFilesListTmpl}" ]; then 21 | echo && echo -e "${CBLUE}*** Check for unused templates ***${CEND}" 22 | for sFile in ${sFilesListTmpl}; do 23 | case "${sFile}" in 24 | *fake-hwclock* | *rpcbind* | *samba* | *openvpn-client* | *openvpn-server* | *ntpd* | *rstats* | *syslog* | *dnsmasq* | *cstats* | *ip_blacklist* | *domains-* | *-rules*) 25 | continue 26 | ;; 27 | *) 28 | if (! grep -qR --exclude-dir=.git "${sFile}" "${sDirToScan}"/); then 29 | echo -e "${CYELLOW}${sDirToScan}/${sFile}:${CEND} ${CRED}Failed${CEND}" 30 | nReturn=$((nReturn + 1)) 31 | else 32 | echo -e "${CYELLOW}${sFile}:${CEND} ${CGREEN}Passed${CEND}" 33 | fi 34 | ;; 35 | esac 36 | done 37 | fi 38 | 39 | # Templates files called 40 | sLine="$(grep -rh --exclude-dir=ci --exclude-dir=.git "TEMPLATEs\|\${gsDirTemplates}" "${sDirToScan}"/ | grep -v 'shellcheck')" 41 | if [ -n "${sLine}" ]; then 42 | echo && echo -e "${CBLUE}*** Check for missing templates ***${CEND}" 43 | for sColumn in ${sLine}; do 44 | sColumn="$(echo "${sColumn}" | sed "s/\"//g;s/'//g;s/)//g;s/;//g;")" 45 | if [ -n "${sColumn}" ]; then 46 | if (grep -q '.tmpl' <<<"${sColumn}"); then 47 | if (grep -q 'TEMPLATEs' <<<"${sColumn}"); then 48 | sTemplate="$(echo "${sColumn}" | cut -d '/' -f 6)" 49 | if [ -n "${sTemplate}" ]; then 50 | sFile="$(find "${sDirToScan}"/root/TEMPLATEs/ -type f -name "${sTemplate}")" 51 | for FILE in ${sFiles}; do 52 | if [ -n "${FILE}" ] && [ -f "${FILE}" ]; then 53 | echo -e "${CYELLOW}${sTemplate}:${CEND} ${CGREEN}Passed${CEND}" 54 | else 55 | echo -e "${CYELLOW}${sTemplate}:${CEND} ${CRED}Failed${CEND}" 56 | nReturn=$((nReturn + 1)) 57 | fi 58 | done 59 | fi 60 | elif (grep -q "\${gsDirTemplates}" <<<"${sColumn}"); then 61 | sTemplate="$(echo "${sColumn}" | cut -d '/' -f 3)" 62 | if [ -n "${sTemplate}" ]; then 63 | sFiles="$(find "${sDirToScan}"/root/TEMPLATEs/ -type f -name "${sTemplate}")" 64 | for FILE in ${sFiles}; do 65 | if [ -n "${FILE}" ] && [ -f "${FILE}" ]; then 66 | echo -e "${CYELLOW}${sTemplate}:${CEND} ${CGREEN}Passed${CEND}" 67 | else 68 | echo -e "${CYELLOW}${sTemplate}:${CEND} ${CRED}Failed${CEND}" 69 | nReturn=$((nReturn + 1)) 70 | fi 71 | done 72 | fi 73 | fi 74 | fi 75 | fi 76 | done 77 | fi 78 | 79 | export nReturn 80 | -------------------------------------------------------------------------------- /ci/scripts/99-end_script.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -z "${gbLoaded}" ] || [ "${gbLoaded}" -eq 0 ]; then 4 | # shellcheck source=ci/scripts/00-libs.sh 5 | . "/builds/${CI_PROJECT_PATH}/ci/scripts/00-libs.sh" 6 | fi 7 | 8 | if [ -n "${nReturn}" ]; then 9 | if [[ -f /.dockerenv ]]; then 10 | exit "${nReturn}" 11 | else 12 | return "${nReturn}" 13 | fi 14 | fi 15 | -------------------------------------------------------------------------------- /root/.bash_aliases: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | 3 | #### MyTomato 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | [ -f /opt/MyTomato/root/SCRIPTs/inc/vars ] && . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | 7 | # enable color support of ls and also add handy aliases 8 | if [ -x /opt/bin/dircolors ]; then 9 | if test -r ~/.dircolors; then 10 | eval "$(dircolors -b ~/.dircolors)" 11 | else 12 | eval "$(dircolors -b)" 13 | fi 14 | alias ls='ls --color=auto' 15 | alias dir='dir --color=auto' 16 | alias vdir='vdir --color=auto' 17 | 18 | alias grep='grep --color=auto' 19 | alias fgrep='fgrep --color=auto' 20 | alias egrep='egrep --color=auto' 21 | fi 22 | 23 | # Commands 24 | alias ll='ls $LS_OPTIONS -l' 25 | alias l='ls $LS_OPTIONS -lA' 26 | alias l='ls -CF' 27 | alias ..='cd ..' 28 | alias ...='cd ../..' 29 | alias s='ssh -l root' 30 | 31 | # P2Partisan 32 | { 33 | [ "${gbP2Partisan_Enable}" -eq 1 ] 34 | [ -f /opt/MyTomato/P2Partisan/p2partisan.sh ] 35 | } && alias p2partisan='bash /opt/MyTomato/P2Partisan/p2partisan.sh' 36 | -------------------------------------------------------------------------------- /root/.bashrc: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | 3 | # ~/.bashrc: executed by bash(1) for non-login shells. 4 | # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) 5 | # for examples 6 | 7 | # If not running interactively, don't do anything 8 | case $- in 9 | *i*) ;; 10 | *) return ;; 11 | esac 12 | 13 | # don't put duplicate lines or lines starting with space in the history. 14 | # See bash(1) for more options 15 | HISTCONTROL=ignoreboth 16 | 17 | # append to the history file, don't overwrite it 18 | shopt -s histappend 19 | 20 | # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) 21 | HISTFILESIZE=4096 22 | HISTSIZE=4096 23 | 24 | # check the window size after each command and, if necessary, 25 | # update the values of LINES and COLUMNS. 26 | shopt -s checkwinsize 27 | 28 | # If set, the pattern "**" used in a pathname expansion context will 29 | # match all files and zero or more directories and subdirectories. 30 | shopt -s globstar 31 | 32 | # set a fancy prompt (non-color, unless we know we "want" color) 33 | case "$TERM" in 34 | xterm-color) color_prompt=yes ;; 35 | esac 36 | 37 | if [ "$color_prompt" = yes ]; then 38 | PS1='\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]' 39 | else 40 | PS1='\u@\h:\w\$ ' 41 | fi 42 | unset color_prompt 43 | 44 | # If this is an xterm set the title to user@host:dir 45 | case "$TERM" in 46 | xterm* | rxvt*) 47 | PS1="\[\e]0;\u@\h: \w\a\]$PS1" 48 | ;; 49 | *) ;; 50 | 51 | esac 52 | 53 | # colored GCC warnings and errors 54 | export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' 55 | 56 | #### MyTomato 57 | # shellcheck source=root/SCRIPTs/inc/vars 58 | [ -f /opt/MyTomato/root/SCRIPTs/inc/vars ] && . /opt/MyTomato/root/SCRIPTs/inc/vars 59 | 60 | # PATH 61 | export PATH=/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin:/bin:/sbin:/mmc/bin:/mmc/sbin:/mmc/usr/bin:/mmc/usr/sbin:/usr/bin:/usr/sbin:/home/root:/opt/etc/init.d/:${gsDirScripts} 62 | 63 | # Alias definitions. 64 | # You may want to put all your additions into a separate file like 65 | # ~/.bash_aliases, instead of adding them here directly. 66 | # See /usr/share/doc/bash-doc/examples in the bash-doc package. 67 | # shellcheck source=root/.bash_aliases 68 | [ -f ~/.bash_aliases ] && . ~/.bash_aliases 69 | 70 | # Define localization 71 | export LANG="${gsLocales}.UTF-8" 72 | export LC_ALL="${gsLocales}.UTF-8" 73 | 74 | # .bash_aliases custom 75 | # shellcheck source=root/.bash_aliases 76 | [ -f "${gsDirOverLoad}/.bash_aliases" ] && . "${gsDirOverLoad}/.bash_aliases" 77 | 78 | # .bashrc custom 79 | # shellcheck source=root/.bash_aliases 80 | [ -f "${gsDirOverLoad}/.bashrc" ] && . "${gsDirOverLoad}/.bashrc" 81 | 82 | /usr/sbin/mymotd 83 | -------------------------------------------------------------------------------- /root/.inputrc: -------------------------------------------------------------------------------- 1 | # https://wiki.archlinux.org/index.php/Readline 2 | set meta-flag on 3 | set convert-meta off 4 | set output-meta on 5 | # Faster completion 6 | set show-all-if-unmodified off 7 | set show-all-if-ambiguous off 8 | # Color files by types 9 | set colored-stats On 10 | # Append char to indicate type 11 | set visible-stats On 12 | # Mark symlinked directories 13 | set mark-symlinked-directories On 14 | # Color the common prefix 15 | set colored-completion-prefix On 16 | # Color the common prefix in menu-complete 17 | set menu-complete-display-prefix On 18 | 19 | "\e[1;5D": backward-word 20 | "\e[1;5C": forward-word 21 | "\e[1~": beginning-of-line 22 | "\e[4~": end-of-line 23 | "\e[7~": beginning-of-line 24 | "\e[8~": end-of-line 25 | "\eOH": beginning-of-line 26 | "\eOF": end-of-line 27 | "\e[H": beginning-of-line 28 | "\e[F": end-of-line 29 | -------------------------------------------------------------------------------- /root/.profile: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | # shellcheck disable=SC1091 3 | 4 | [ -f /opt/etc/profile ] && . /opt/etc/profile 5 | BASH_VERSION="$(bash --version 2>/dev/null | head -n 1)" 6 | 7 | export BASH_VERSION 8 | export TERM=xterm-color 9 | 10 | if [ -n "$BASH_VERSION" ]; then 11 | bash 12 | fi 13 | 14 | exit 15 | -------------------------------------------------------------------------------- /root/.screenrc: -------------------------------------------------------------------------------- 1 | # $Id: screenrc,v 1.15 2003/10/08 11:39:03 zal Exp $ 2 | # 3 | # This is the system wide screenrc. 4 | # 5 | # You can use this file to change the default behavior of screen system wide 6 | # or copy it to ~/.screenrc and use it as a starting point for your own 7 | # settings. 8 | # 9 | # Commands in this file are used to set options, bind screen functions to 10 | # keys, redefine terminal capabilities, and to automatically establish one or 11 | # more windows at the beginning of your screen session. 12 | # 13 | # This is not a comprehensive list of options, look at the screen manual for 14 | # details on everything that you can put in this file. 15 | # 16 | 17 | # ------------------------------------------------------------------------------ 18 | # SCREEN SETTINGS 19 | # ------------------------------------------------------------------------------ 20 | 21 | # Turn off the welcome message 22 | startup_message off 23 | #nethack on 24 | 25 | #defflow on # will force screen to process ^S/^Q 26 | deflogin on 27 | #autodetach off 28 | 29 | # turn visual bell on 30 | vbell off 31 | vbell_msg " Wuff ---- Wuff!! " 32 | 33 | # Set scrollback buffer to 10000 34 | defscrollback 10000 35 | 36 | # ------------------------------------------------------------------------------ 37 | # SCREEN KEYBINDINGS 38 | # ------------------------------------------------------------------------------ 39 | 40 | # Remove some stupid / dangerous key bindings 41 | bind ^k 42 | #bind L 43 | bind ^\ 44 | # Make them better 45 | bind \\ quit 46 | bind K kill 47 | bind I login on 48 | bind O login off 49 | bind } history 50 | 51 | # An example of a "screen scraper" which will launch urlview on the current 52 | # screen window 53 | # 54 | #bind ^B eval "hardcopy_append off" "hardcopy -h $HOME/.screen-urlview" "screen urlview $HOME/.screen-urlview" 55 | 56 | # ------------------------------------------------------------------------------ 57 | # TERMINAL SETTINGS 58 | # ------------------------------------------------------------------------------ 59 | 60 | # The vt100 description does not mention "dl". *sigh* 61 | termcapinfo vt100 dl=5\E[M 62 | 63 | # Customize the status line 64 | # turn sending of screen messages to hardstatus off 65 | hardstatus alwayslastline 66 | # Set the hardstatus prop on gui terms to set the titlebar/icon title 67 | termcapinfo xterm*|rxvt*|kterm*|Eterm* hs:ts=\E]0;:fs=\007:ds=\E]0;\007 68 | # use this for the hard status string 69 | #hardstatus string "%h%? users: %u%?" 70 | hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]' 71 | 72 | # An alternative hardstatus to display a bar at the bottom listing the 73 | # windownames and highlighting the current windowname in blue. (This is only 74 | # enabled if there is no hardstatus setting for your terminal) 75 | # 76 | #hardstatus lastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<" 77 | 78 | # set these terminals up to be 'optimal' instead of vt100 79 | termcapinfo xterm*|linux*|rxvt*|Eterm* OP 80 | 81 | # Change the xterm initialization string from is2=\E[!p\E[?3;4l\E[4l\E> 82 | # (This fixes the "Aborted because of window size change" konsole symptoms found 83 | # in bug #134198) 84 | termcapinfo xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l' 85 | 86 | # To get screen to add lines to xterm's scrollback buffer, uncomment the 87 | # following termcapinfo line which tells xterm to use the normal screen buffer 88 | # (which has scrollback), not the alternate screen buffer. 89 | # 90 | #termcapinfo xterm|xterms|xs|rxvt ti@:te@ 91 | 92 | # Enable non-blocking mode to better cope with flaky ssh connections. 93 | defnonblock 5 94 | 95 | # ------------------------------------------------------------------------------ 96 | # STARTUP SCREENS 97 | # ------------------------------------------------------------------------------ 98 | 99 | # Example of automatically running some programs in windows on screen startup. 100 | # 101 | # The following will open top in the first window, an ssh session to monkey 102 | # in the next window, and then open mutt and tail in windows 8 and 9 103 | # respectively. 104 | # 105 | # screen top 106 | # screen -t monkey ssh monkey 107 | # screen -t mail 8 mutt 108 | # screen -t daemon 9 tail -f /var/log/daemon.log 109 | -------------------------------------------------------------------------------- /root/ConfigOverload/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/ConfigOverload/.gitkeep -------------------------------------------------------------------------------- /root/ISP/Orange/Orange_ISP.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | [ -z "${gsOrange_FTI}" ] && { 14 | echo 15 | echo "'gsOrange_FTI' variable is not defined in '\"${gsDirOverLoad}/vars\"', aborting !" 16 | exit 1 17 | } 18 | 19 | (! df -h | grep -q '/opt') && { 20 | echo "ERROR: '/opt' not mounting" 21 | exit 1 22 | } 23 | 24 | #### Orange - DHCP Mode 25 | # https://lafibre.info/remplacer-livebox/tuto-mode-dhcp-sur-firmware-tomato/12/ 26 | 27 | ## Install neeeded tools 28 | # convert string to hexa 29 | if (opkg list-installed | grep -q 'xxd'); then 30 | opkg update 31 | opkg install xxd 32 | HEXA="$(xxd -p -u <<<"$(echo "${gsOrange_FTI}" | cut -d '/' -f 2)" | sed 's/0A$//')" 33 | else 34 | echo 35 | echo "'xxd' package is missing, aborting !" 36 | exit 1 37 | fi 38 | 39 | ## Basic > Network > WAN Settings 40 | nvram set wan_ppp_username="${gsOrange_FTI}" 41 | nvram set wan_proto=dhcp 42 | 43 | ## Advanced > Network > WAN Settings 44 | nvram set wan_iface=vlan832 45 | nvram set wan_ifname=vlan832 46 | nvram set wan_ifnameX=vlan2 47 | nvram set wan_ifnames=vlan832 48 | nvram set wandevs=vlan2 49 | nvram set vlan2vid=832 50 | nvram set vlan2tag=1 51 | 52 | ## Advanced -> DHCP/DNS -> DHCP Client (WAN) 53 | #nvram set dhcpc_custom="~u2014retries=2 ~u2014timeout=5 ~u2014tryagain=310" 54 | 55 | ## Adminsitration > Script > Init 56 | nvram get script_init >/tmp/script_init 57 | sed -i '/# Orange DHCP Mode/d' /tmp/script_init 58 | sed -i '/\/tmp\/sbin/d' /tmp/script_init 59 | sed -i '/udhcpc/d' /tmp/script_init 60 | { 61 | echo "# Orange DHCP Mode" 62 | echo "cp -R /sbin/ /tmp/sbin" 63 | echo "rm /tmp/sbin/udhcpc" 64 | echo "echo 'exec busybox udhcpc -O 0x4d -O 0x5a -x 0x4d:2b46535644534c5f6c697665626f782e496e7465726e65742e736f66746174686f6d652e4c697665626f7834 -x 0x5a:00000000000000000000001a0900000558010341010d6674692f${HEXA} \"\$*\"' >/tmp/sbin/udhcpc" 65 | echo "chmod +x /tmp/sbin/udhcpc" 66 | echo "mount --bind /tmp/sbin/ /sbin" 67 | } >>/tmp/script_init 68 | nvram set script_init="$(cat /tmp/script_init)" 69 | rm -f /tmp/script_init 70 | 71 | ## Adminsitration > Script > Firewall 72 | echo "### Version 17 20190117 73 | ### https://lafibre.info/remplacer-livebox/tuto-remplacer-la-livebox-par-un-routeur-dd-wrt-internet-tv/ 74 | 75 | ### Priorite / CoS pour Internet 76 | # File 0 (par defaut) pour le DHCP (raw-socket), file 1 pour le reste du trafic 77 | vconfig set_egress_map vlan832 0 6 78 | vconfig set_egress_map vlan832 1 0 79 | 80 | ### Support TV, priorite / CoS pour l'ensemble des files 81 | if ( nvram show |sort |grep 'vlan' |grep -q '840' ); then 82 | for i in \$(seq 0 7); do 83 | vconfig set_egress_map vlan840 \"\$i\" 5 84 | done 85 | fi 86 | 87 | ### On classe le trafic Internet dans les bonnes files 88 | # Tout le trafic priorite 1 (CoS 0) 89 | iptables -t mangle -A POSTROUTING -j CLASSIFY --set-class 0000:0001 90 | # Client DHCP non raw-socket (pas le cas de udhcpc) mais sert aussi pour le renew 91 | iptables -t mangle -A POSTROUTING -o vlan832 -p udp --dport 67 -j CLASSIFY --set-class 0000:0000" >/opt/etc/orange_ack_script_fire.sh 92 | 93 | nvram get script_fire >/tmp/script_fire 94 | sed -i '/orange_ack_script_fire/d' /tmp/script_fire 95 | echo "sh /opt/etc/orange_ack_script_fire.sh" >>/tmp/script_fire 96 | nvram set script_fire="$(cat /tmp/script_fire)" 97 | rm -f /tmp/script_fire 98 | 99 | ## Commit 100 | nvram commit 101 | 102 | ### Reboot needed 103 | echo 104 | echo 105 | echo "Please, reboot your router..." 106 | echo 107 | echo 108 | 109 | exit 0 110 | -------------------------------------------------------------------------------- /root/OpenVPN/client1/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/OpenVPN/client1/.gitkeep -------------------------------------------------------------------------------- /root/OpenVPN/client2/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/OpenVPN/client2/.gitkeep -------------------------------------------------------------------------------- /root/OpenVPN/client3/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/OpenVPN/client3/.gitkeep -------------------------------------------------------------------------------- /root/OpenVPN/server1/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/OpenVPN/server1/.gitkeep -------------------------------------------------------------------------------- /root/OpenVPN/server2/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/OpenVPN/server2/.gitkeep -------------------------------------------------------------------------------- /root/SCRIPTs/Environment_Config.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | #### TAG '/opt' and '/opt/var/log' with UUID to avoid deleting 14 | if [ -n "${gsUsbOptUuid}" ]; then 15 | if [ ! -f /opt/.uuid ] || [ "$(cat /opt/.uuid)" != "${gsUsbOptUuid}" ]; then 16 | echo "${gsUsbOptUuid}" >/opt/.uuid 17 | fi 18 | if [ ! -f /opt/root/.uuid ] || [ "$(cat /opt/root/.uuid)" != "${gsUsbOptUuid}" ]; then 19 | echo "${gsUsbOptUuid}" >/opt/root/.uuid 20 | fi 21 | if [ ! -f /opt/var/log/.uuid ] || [ "$(cat /opt/var/log/.uuid)" != "${gsUsbOptUuid}" ]; then 22 | echo "${gsUsbOptUuid}" >/opt/var/log/.uuid 23 | fi 24 | fi 25 | 26 | #### Prepare some files and directories #### 27 | # /opt/tmp 28 | if (! /opt/bin/mount -l | grep -q '/opt/tmp'); then 29 | mount -t tmpfs -o size=256M,mode=0755 tmpfs /opt/tmp/ 30 | cp -af /tmp/* /opt/tmp/ 31 | rm -rRf /tmp/* && rm -rRf /tmp/.??* 32 | /opt/bin/mount --bind /opt/tmp /tmp 33 | fi 34 | 35 | # /opt/var/log 36 | if (! /opt/bin/mount -l | grep -q '/tmp/var/log'); then 37 | if [ -f /tmp/var/log/messages ]; then 38 | gfnStartStopSyslogd 'stop' 39 | echo "$(/bin/date '+%a %b %d %T %Y') $(nvram get lan_hostname) user.notice | ${gsScriptName} | Copy /tmp/var/log/messages to /opt/var/log/messages" >>/opt/var/log/messages 40 | cat /tmp/var/log/messages >>/opt/var/log/messages 41 | if [ ! -f /tmp/var/log/.uuid ]; then 42 | echo "$(/bin/date '+%a %b %d %T %Y') $(nvram get lan_hostname) user.notice | ${gsScriptName} | Clean /tmp/var/log/" >>/opt/var/log/messages 43 | rm -rRf /tmp/var/log/* && rm -rRf /tmp/var/log/.??* 44 | fi 45 | echo "$(/bin/date '+%a %b %d %T %Y') $(nvram get lan_hostname) user.notice | ${gsScriptName} | Mount /opt/var/log to /tmp/var/log" >>/opt/var/log/messages 46 | /opt/bin/mount --bind /opt/var/log /tmp/var/log 47 | gfnStartStopSyslogd 'start' 48 | fi 49 | fi 50 | 51 | # /opt/root 52 | if (! /opt/bin/mount -l | grep -q '/tmp/home/root'); then 53 | if [ ! -f /tmp/home/root/.uuid ]; then 54 | logger -p user.notice "| ${gsScriptName} | Clean /tmp/home/root/" 55 | rm -rRf /tmp/home/root/* && rm -rRf /tmp/home/root/.??* 56 | fi 57 | if [ ! -f /opt/root/.uuid ]; then 58 | logger -p user.notice "| ${gsScriptName} | Clean /opt/root/" 59 | rm -rRf /opt/root/* && rm -rRf /opt/root/.??* 60 | fi 61 | logger -p user.notice "| ${gsScriptName} | Mount /opt/MyTomato/root to /tmp/home/root" 62 | /opt/bin/mount --bind /opt/MyTomato/root /tmp/home/root 63 | fi 64 | 65 | #### Create /opt/.autorun script 66 | cp -v "${gsDirTemplates}"/.autorun.tmpl /opt/.autorun 67 | chmod +x /opt/.autorun 68 | 69 | #### rc.unslung / rc.func 70 | # Create a backup of original files 71 | { [ -f /opt/etc/init.d/rc.unslung ] && [ ! -f "${gsDirBackups}/rc.unslung.original" ]; } && 72 | cp /opt/etc/init.d/rc.unslung "${gsDirBackups}/rc.unslung.original" 73 | { [ -f /opt/etc/init.d/rc.func ] && [ ! -f "${gsDirBackups}/rc.func.original" ]; } && 74 | cp /opt/etc/init.d/rc.func "${gsDirBackups}/rc.func.original" 75 | # Replace original scripts by the templates 76 | [ -f "${gsDirTemplates}/init/rc.unslung.tmpl" ] && cp "${gsDirTemplates}/init/rc.unslung.tmpl" /opt/etc/init.d/rc.unslung 77 | [ -f "${gsDirTemplates}/init/rc.func.tmpl" ] && cp "${gsDirTemplates}/init/rc.func.tmpl" /opt/etc/init.d/rc.func 78 | chmod +x /opt/etc/init.d/* 79 | 80 | #### /opt/etc/init/SXX 81 | /opt/bin/find "${gsDirTemplates}/init/" -name "*.tmpl" -exec bash -c 'i="$1"; cp -v "${i}" /opt/etc/init.d/$(basename $(echo "${i}" | sed "s/.tmpl//g;"))' _ {} \; 82 | chmod +x /opt/etc/init.d/* 83 | 84 | #### Replace binaries with aliases 85 | if [ -d /opt/bin/ ]; then 86 | # Create an empty file if needed 87 | [ ! -f "${gsDirOverLoad}/.bash_aliases" ] && touch "${gsDirOverLoad}/.bash_aliases" 88 | 89 | # Add some aliases manualy 90 | (! grep -q 'vi=' "${gsDirOverLoad}/.bash_aliases") && 91 | { 92 | echo "alias vi='/opt/bin/vim'" 93 | } >"${gsDirOverLoad}/.bash_aliases" 94 | 95 | # Generate aliases list 96 | for bin in $(/opt/bin/find /opt/bin/ /opt/sbin/ -type f ! -type d -perm '-u+x' | grep -v '[0-9*]\.' | sort); do 97 | # Ignore links 98 | [ -h "${bin}" ] && continue 99 | [ "$(whereis "${bin}" | awk '{ print $2 }')" == "${bin}" ] || continue 100 | 101 | (! grep -q "${bin}" "${gsDirOverLoad}/.bash_aliases") && 102 | echo "alias $(echo "${bin}" | cut -d '/' -f 4)='${bin}'" >>"${gsDirOverLoad}/.bash_aliases" 103 | done 104 | cat "${gsDirOverLoad}/.bash_aliases" >>/tmp/to_syslog 105 | fi 106 | 107 | #### Add bash to shells 108 | (! grep -q '/bin/bash' /opt/etc/shells) && echo "/bin/bash" >>/opt/etc/shells 109 | (! grep -q '/opt/bin/bash' /opt/etc/shells) && echo "/opt/bin/bash" >>/opt/etc/shells 110 | cat /opt/etc/shells >>/tmp/to_syslog 111 | 112 | #### /etc/group 113 | [ ! -f /opt/etc/group ] && cp -fv /etc/group /opt/etc/group 114 | [ -f /opt/etc/group ] && (! grep -q 'mlocate' /opt/etc/group) && echo "mlocate:x:111:" >>/opt/etc/group 115 | cat /opt/etc/group >>/tmp/to_syslog 116 | 117 | #### Purge LOGs files (internal use) 118 | [ -n "${gsDirLogs}" ] && /opt/bin/find "${gsDirLogs}/" -type f -mtime +30 -exec rm -vf {} \; >>/tmp/to_syslog 119 | [ -n "${gsDirBackups}" ] && /opt/bin/find "${gsDirBackups}/" -type f -mtime +30 -exec rm -vf {} \; >>/tmp/to_syslog 120 | 121 | #### Copy back local logs to Syslog 122 | gfnCopyToSyslog 123 | 124 | #### Locales 125 | if [ -n "${gsLocales}" ]; then 126 | logger -p user.notice "| ${gsScriptName} | Add locales '${gsLocales}'" 127 | /opt/bin/localedef.new -c -f UTF-8 -i "${gsLocales}" "${gsLocales}.UTF-8" 128 | fi 129 | if [ -n "${gsTimezone}" ]; then 130 | logger -p user.notice "| ${gsScriptName} | Add timezone '${gsTimezone}'" 131 | ln -sf /opt/share/zoneinfo/"${gsTimezone}" /opt/etc/localtime 132 | fi 133 | 134 | exit 0 135 | -------------------------------------------------------------------------------- /root/SCRIPTs/Load_ArmExtras.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | if [ -n "${gsUrlArmExtras}" ]; then 14 | logger -p user.notice "| ${gsScriptName} | Get ${gsUrlArmExtras}" 15 | ${binCurl} "${gsUrlArmExtras}" -o "/tmp/arm-extras.tar.gz" 16 | fi 17 | 18 | if [ -f "/tmp/arm-extras.tar.gz" ]; then 19 | logger -p user.notice "| ${gsScriptName} | Untar /tmp/arm-extras.tar.gz" 20 | if [ -f "/tmp/arm-extras.tar.gz" ]; then 21 | sSubDir="$(tar -ztf "/tmp/arm-extras.tar.gz" | cut -d '/' -f 1 | head -n 1)" 22 | tar -zxf "/tmp/arm-extras.tar.gz" -C "/tmp/" 23 | rm -rf "${gsDirArmExtras}" 24 | mv "/tmp/${sSubDir}" "${gsDirArmExtras}" 25 | rm -f "/tmp/arm-extras.tar.gz" 26 | fi 27 | fi 28 | 29 | gfnLoadModules 'usb' 30 | gfnLoadModules 'nfs' 31 | 32 | exit 0 33 | -------------------------------------------------------------------------------- /root/SCRIPTs/Services_Start.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | #### STOP all services #### 14 | bash "${gsDirScripts}/Services_Stop.sh" 15 | 16 | #### SysLog #### 17 | gfnStartStopSyslogd 'start' 18 | 19 | #### EntWare Services #### 20 | gfnEntwareServices "start" 21 | 22 | #### P2Partisan 23 | gfnP2pArtisanStartStop 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /root/SCRIPTs/Services_Stop.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | #### EntWare Services 14 | gfnEntwareServices "stop" 15 | 16 | #### P2Partisan 17 | [ -f /opt/MyTomato/P2Partisan/p2partisan.sh ] && /opt/MyTomato/P2Partisan/p2partisan.sh stop 18 | 19 | #### SFTP 20 | [ -n "$(pidof sftp-server)" ] && killall sftp-server >/dev/null 21 | 22 | exit 0 23 | -------------------------------------------------------------------------------- /root/SCRIPTs/USB_AfterMounting.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Restore last date time 4 | fake-hwclock load force 5 | 6 | #### Includes 7 | # shellcheck source=root/SCRIPTs/inc/vars 8 | . /opt/MyTomato/root/SCRIPTs/inc/vars 9 | # shellcheck source=root/SCRIPTs/inc/vars 10 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 11 | # shellcheck source=root/SCRIPTs/inc/funcs 12 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 13 | 14 | ############################## 15 | 16 | #### Lock file 17 | [ ! -f /tmp/"${gsScriptName}".lock ] && touch /tmp/"${gsScriptName}".lock || exit 0 18 | 19 | #### Sync time 20 | gfnNtpUpdate 21 | 22 | #### Creating directories 23 | [ ! -d "${gsDirLogs}" ] && mkdir -pv "${gsDirLogs}" 24 | [ ! -d "${gsDirBackups}" ] && mkdir -pv "$gsDirBackups" 25 | [ ! -d "${gsDirArmExtras}" ] && mkdir -pv "${gsDirArmExtras}" 26 | 27 | #### SCRIPTs 28 | chmod +x "${gsDirScripts}"/* 29 | 30 | #### Restore config if needed 31 | if [ -z "$(nvram get mytomato_config_save)" ]; then 32 | sLastConfig="$(find "${gsDirBackups}"/ -type f -name "MyTomato_*.cfg" -exec ls -A1t {} + | head -1)" 33 | if [ -n "${sLastConfig}" ] && [ -f "${sLastConfig}" ]; then 34 | (nvram restore "${sLastConfig}") && reboot 35 | fi 36 | fi 37 | 38 | #### NVRAM settings 39 | gfnNvramUpdate 'fstab' 40 | gfnNvramUpdate 'dnsmasq' 41 | gfnNvramUpdate 'dns_wan1' 42 | 43 | #### Environment Config (/opt/root, /opt/var/log, ...) 44 | bash "${gsDirScripts}/Environment_Config.sh" 45 | 46 | #### P2Partisan install 47 | if [ ! -f /opt/MyTomato/P2Partisan/p2partisan.sh ] && [ "${gbP2Partisan_Enable}" -eq 1 ]; then 48 | logger -p user.notice "| ${gsScriptName} | Start P2Partisan installation" 49 | gfnP2pArtisanStartStop 50 | logger -p user.notice "| ${gsScriptName} | End of P2Partisan installation" 51 | fi 52 | 53 | #### DNScrypt install 54 | gfnInstallDnscryptProxy 55 | 56 | #### Loading Additional modules 57 | bash "${gsDirScripts}/Load_ArmExtras.sh" 58 | 59 | #### Services 60 | bash "${gsDirScripts}/Services_Start.sh" 61 | 62 | #### NVRAM config save 63 | gfnNvramSave 64 | 65 | #### Lock file 66 | [ -f /tmp/"${gsScriptName}".lock ] && rm /tmp/"${gsScriptName}".lock 67 | 68 | exit 0 69 | -------------------------------------------------------------------------------- /root/SCRIPTs/USB_BeforeUnmounting.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | #### Lock file 14 | [ ! -f /tmp/"${gsScriptName}".lock ] && touch "${gsScriptName}".lock || exit 0 15 | 16 | #### NVRAM settings 17 | gfnNvramUpdate 'dns_wan1' 'get' 18 | 19 | #### Stop all services 20 | bash "${gsDirScripts}/Services_Stop.sh" 21 | 22 | #### Keep date time 23 | fake-hwclock save 24 | 25 | #### NVRAM save 26 | gfnNvramSave 27 | 28 | #### Umount if possible 29 | # /tmp/var/log 30 | (/opt/bin/mount -l | grep -q '/tmp/var/log') && /opt/bin/umount -v /tmp/var/log 31 | (/opt/bin/mount -l | grep -q '/tmp/var/log') && /opt/bin/umount -vf /tmp/var/log 32 | (/opt/bin/mount -l | grep -q '/tmp/var/log') && /opt/bin/umount -vl /tmp/var/log 33 | # /tmp/home/root 34 | (/opt/bin/mount -l | grep -q '/tmp/home/root') && /opt/bin/umount -v /tmp/home/root 35 | (/opt/bin/mount -l | grep -q '/tmp/home/root') && /opt/bin/umount -vf /tmp/home/root 36 | (/opt/bin/mount -l | grep -q '/tmp/home/root') && /opt/bin/umount -vl /tmp/home/root 37 | # /opt/tmp 38 | if (/opt/bin/mount -l | grep -q '/opt/tmp'); then 39 | [ ! -d /opt/temp ] && mkdir /opt/temp 40 | cp -af /tmp/* /opt/temp/ 41 | /opt/bin/umount -v /tmp 42 | /opt/bin/umount -vf /tmp 43 | /opt/bin/umount -vl /tmp 44 | cp -af /opt/temp/* /tmp/ 45 | [ -d /opt/temp ] && rm -rf /opt/temp 46 | fi 47 | # /opt 48 | (/opt/bin/mount -l | grep -q '/opt') && /opt/bin/umount -v /opt 49 | (/opt/bin/mount -l | grep -q '/opt') && /opt/bin/umount -vf /opt 50 | (/opt/bin/mount -l | grep -q '/opt') && /opt/bin/umount -vl /opt 51 | 52 | #### Lock file 53 | [ -f /tmp/"${gsScriptName}".lock ] && rm "${gsScriptName}".lock 54 | 55 | #### Kill bash sessions 56 | for sPid in $(pidof bash); do kill -9 "${sPid}"; done 57 | 58 | ############################## 59 | -------------------------------------------------------------------------------- /root/SCRIPTs/Upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### Includes 4 | # shellcheck source=root/SCRIPTs/inc/vars 5 | . /opt/MyTomato/root/SCRIPTs/inc/vars 6 | # shellcheck source=root/SCRIPTs/inc/vars 7 | [ -f "${gsDirOverLoad}/vars" ] && . "${gsDirOverLoad}/vars" 8 | # shellcheck source=root/SCRIPTs/inc/funcs 9 | . /opt/MyTomato/root/SCRIPTs/inc/funcs 10 | 11 | ############################## 12 | 13 | #### OPKG 14 | opkg update 15 | opkg upgrade 16 | 17 | logger -p user.notice "| ${gsScriptName} | EntWare generate pakages installed list" 18 | gsOpkgPackagesList="${gsDirLogs}/opkg_list-installed_${gdDateTime}.txt" 19 | opkg list-installed | awk '{ print $1 }' >"${gsOpkgPackagesList}" 20 | 21 | if [ -f "${gsOpkgPackagesList}" ]; then 22 | while read -r line; do 23 | sPackage="$(echo "${line}" | awk '{ print $1 }')" 24 | (! opkg list-installed | grep -q "${sPackage}") && opkg install "${sPackage}" \ 25 | logger -p user.notice "| ${gsScriptName} | EntWare install package '${sPackage}'" 26 | done <"${gsOpkgPackagesList}" 27 | fi 28 | 29 | #### MyTomato repo 30 | if [ "${gbRepoUpgrade_Enable:?}" -eq 1 ]; then 31 | [ -d "/opt/MyTomato" ] && cd "/opt/MyTomato" || exit 1 32 | logger -p user.notice "| ${gsScriptName} | Update /opt/MyTomato via GitHub" 33 | git fetch origin 34 | git reset --hard origin/master 35 | git config pull.rebase false 36 | git pull origin master 37 | fi 38 | 39 | #### DNScrypt-proxy v2 40 | if [ ! -d /opt/usr/local/dnscrypt-proxy ]; then 41 | logger -p user.notice "| ${gsScriptName} | Git clone https://github.com/jedisct1/dnscrypt-proxy.git" 42 | git clone git://github.com/jedisct1/dnscrypt-proxy.git "${gsDirDnscrypt:?}" 43 | else 44 | cd "${gsDirDnscrypt:?}" || exit 1 45 | logger -p user.notice "| ${gsScriptName} | Update ${gsDirDnscrypt} via GitHub" 46 | git fetch origin 47 | git reset --hard origin/master 48 | # git pull origin master 49 | [ -f "${gsDirDnscryptGen}"/generate-domains-blacklist.py ] && { 50 | mkdir -p "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists 51 | cp -v "${gsDirDnscryptGen}"/generate-domains-blacklist.py "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/generate-domains-blacklist.py 52 | chmod +x "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/generate-domains-blacklist.py 53 | } 54 | fi 55 | if [ -f "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/generate-domains-blacklist.py ] && [ -f "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/domains-blacklist.conf ]; then 56 | cd "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/ || exit 1 57 | logger -p user.notice "| ${gsScriptName} | Generate 'blacklists.txt' with 'generate-domains-blacklist.py'" 58 | python generate-domains-blacklist.py -c domains-blacklist.conf >list.txt.tmp && mv -f list.txt.tmp blacklists.txt 59 | fi 60 | 61 | #### SCRIPTs 62 | logger -p user.notice "| ${gsScriptName} | Chmod +x to ${gsDirScripts}/*" 63 | chmod +x "${gsDirScripts}"/* 64 | logger -p user.notice "| ${gsScriptName} | Chmod +x to /opt/MyTomato/P2Partisan/p2partisan.sh" 65 | [ -f /opt/MyTomato/P2Partisan/p2partisan.sh ] && chmod +x /opt/MyTomato/P2Partisan/p2partisan.sh 66 | 67 | #### NVRAM save 68 | gfnNvramSave 69 | 70 | exit 0 71 | -------------------------------------------------------------------------------- /root/SCRIPTs/inc/funcs: -------------------------------------------------------------------------------- 1 | #!/opt/bin/bash 2 | 3 | #### NTP Update 4 | gfnNtpUpdate() { 5 | ntpdate -4 -p 1 -u 0.fr.pool.ntp.org 6 | } 7 | 8 | #### NVRAM save 9 | gfnNvramSave() { 10 | logger -p user.notice "| ${gsScriptName} | NVRAM config save to ${gsDirBackups}/MyTomato_${gdDateTime}.cfg" 11 | nvram set mytomato_config_save="${gdDateTime}" 12 | nvram commit 13 | nvram save "${gsDirBackups}/MyTomato_${gdDateTime}.cfg" >/dev/null 2>&1 14 | } 15 | 16 | #### NVRAM update 17 | gfnNvramUpdate() { 18 | local sValue sSwith nCommit 19 | nCommit=0 20 | 21 | [ -n "${1}" ] && sValue="${1}" || return 1 22 | sSwith="${2}" 23 | 24 | case "${sValue}" in 25 | 'fstab') 26 | nvram get script_init >/tmp/script_init 27 | (! grep -q 'LABEL=ENTWARE' /tmp/script_init) && { 28 | echo "echo \"LABEL=ENTWARE /opt ${FILESYSTEM} defaults,data=writeback,noatime,nodiratime 0 0\" >> /etc/fstab" >>/tmp/script_init 29 | nCommit=1 30 | } 31 | (! grep -q 'LABEL=SWAP' /tmp/script_init) && { 32 | echo 'echo "LABEL=SWAP none swap sw 0 0" > /etc/fstab' >>/tmp/script_init 33 | nCommit=1 34 | } 35 | (! grep -q 'dnsmasq-custom.conf' /tmp/script_init) && { 36 | echo "touch /etc/dnsmasq-custom.conf" >>/tmp/script_init 37 | nCommit=1 38 | } 39 | [ "${nCommit}" -eq 1 ] && nvram set script_init="$(cat /tmp/script_init)" 40 | rm -f /tmp/script_init 41 | ;; 42 | 'dnsmasq') 43 | nvram get dnsmasq_custom >/tmp/dnsmasq_custom 44 | (! grep -q 'log-async' /tmp/dnsmasq_custom) && { 45 | echo "log-async=20" >>/tmp/dnsmasq_custom 46 | nCommit=1 47 | } 48 | (! grep -q '/etc/dnsmasq-custom.conf' /tmp/dnsmasq_custom) && { 49 | echo "conf-file=/etc/dnsmasq-custom.conf" >>/tmp/dnsmasq_custom 50 | nCommit=1 51 | } 52 | if [ "${nCommit}" -eq 1 ]; then 53 | logger -p user.notice "| ${gsScriptName} | Set NVram dnsmasq_custom=\"$(cat /tmp/dnsmasq_custom)\"" 54 | nvram set dnsmasq_custom="$(cat /tmp/dnsmasq_custom)" 55 | service dnsmasq restart 56 | fi 57 | rm -f /tmp/dnsmasq_custom 58 | ;; 59 | 'dns_wan1') 60 | case "${sSwith}" in 61 | 'get') 62 | # WAN 1 DNS 63 | sWan1Dns="$(nvram get wan_dns)" 64 | if [ -n "${sWan1Dns}" ] && [ "${sWan1Dns}" != "${gsWan1_DNS}" ]; then 65 | # Backup custom vars file 66 | [ -f "${gsDirOverLoad}/vars" ] && cp "${gsDirOverLoad}/vars" "${gsDirBackups}/vars.${gdDateTime}" 67 | # Replace value in vars file 68 | logger -p user.notice "| ${gsScriptName} | Replace gsWan1_DNS FROM \"${gsWan1_DNS}\" to \"${sWan1Dns}\" in \"${gsDirOverLoad}/vars\"" 69 | nNumLine=$(grep 'gsWan1_DNS' -n -m 1 <"${gsDirOverLoad}/vars" | cut -d ':' -f 1) 70 | sed -i "${nNumLine}"s/.*/gsWan1_DNS=\""${sWan1Dns}"\"/ "${gsDirOverLoad}/vars" 71 | fi 72 | ;; 73 | *) 74 | sWan1Dns="$(nvram get wan_dns)" 75 | if [ "${sWan1Dns}" != "${gsWan1_DNS}" ]; then 76 | logger -p user.notice "| ${gsScriptName} | Set NVram wan_dns=\"${gsWan1_DNS}\"" 77 | nCommit=1 78 | nvram set wan_dns="${gsWan1_DNS}" 79 | fi 80 | ;; 81 | esac 82 | ;; 83 | esac 84 | 85 | [ "${nCommit}" -eq 1 ] && nvram commit 86 | } 87 | 88 | #### Start all Optware services 89 | gfnEntwareServices() { 90 | local sAction 91 | [ -n "${1}" ] && sAction="$(echo "${1}" | sed 's/^ //g;s/\s+$//g;')" 92 | 93 | # NFS 94 | # gfnInstallNfsServer 95 | # if [ -f /opt/etc/init.d/S57nfs-kernel-server ]; then 96 | # nNumLine=$(grep 'ENABLED' -n -m 1 >/opt/var/log/messages 159 | syslogd -L -s "$(nvram get log_file_size)" -O "$(nvram get log_file_path)" -b "$(nvram get log_file_keep)" 160 | fi 161 | ;; 162 | 'stop') 163 | if [ -n "$(pidof syslogd)" ]; then 164 | killall syslogd >/dev/null | echo "$(/bin/date '+%a %b %d %T %Y') $(nvram get lan_hostname) user.notice | Stop SysLog process" >>/opt/var/log/messages 165 | fi 166 | ;; 167 | *) return 1 ;; 168 | esac 169 | } 170 | 171 | #### Install DNScrypt-proxy 172 | gfnInstallDnscryptProxy() { 173 | #### AIO version 174 | if (nvram get os_version | grep -q 'AIO'); then 175 | nNumLine=$(grep 'gbDNScrypt_Enable' -n -m 1 <"${gsDirOverLoad}/vars" | cut -d ':' -f 1) 176 | sed -i "${nNumLine}"s/.*/gbDNScrypt_Enable=0/ "${gsDirOverLoad}/vars" 177 | if [ -f /opt/etc/init.d/S09dnscrypt-proxy2 ]; then 178 | nNumLine=$(grep 'ENABLED' -n -m 1 /dev/null); then 217 | # logger -p user.notice "| ${gsScriptName} | Start DNScrypt-proxy installation" 218 | # # Download latest release 219 | # sUrl="https://api.github.com/repos/jedisct1/dnscrypt-proxy/releases/latest" 220 | # for sFile in $(${binCurl} ${sUrl} |jq -r ".assets[] | select(.name | contains(\"linux_arm-\")) | .browser_download_url"); do 221 | # if (! grep -q 'minisig' <<< "${sFile}"); then 222 | # sTarGz="$(basename "${gsDirBackups}/${sFile##*/}")" 223 | # ${binCurl} "${sFile}" -o "${gsDirBackups}/${sTarGz}" 224 | # fi 225 | # done 226 | # # Extract it 227 | # sSubDir="$(tar -ztf "${gsDirBackups}/${sTarGz}" | cut -d '/' -f 1 | uniq)" 228 | # tar -zxf "${gsDirBackups}/${sTarGz}" -C /tmp/ 229 | # mv -v "/tmp/$sSubDir/dnscrypt-proxy" /opt/sbin/dnscrypt-proxy 230 | # chmod +x /opt/sbin/dnscrypt-proxy 231 | # # Copy back examples files in conf overload dir 232 | # find "/tmp/$sSubDir/" -name "example*.toml" -exec bash -c 'i="$1"; mv -v "$i" ${gsDirBackups}/$(basename $(echo "$1" | sed "s/example-//g;"))' _ {} \; 233 | # find "/tmp/$sSubDir/" -name "example*.txt" -exec bash -c 'i="$1"; mv -v "$i" ${gsDirBackups}/$(basename $(echo "$1" | sed "s/example-/dnscrypt./g;"))' _ {} \; 234 | # logger -p user.notice "| ${gsScriptName} | End of DNScrypt-proxy installation" 235 | # fi 236 | 237 | #### Files 238 | # Create logs directory 239 | [ ! -d /opt/var/log/dnscrypt ] && mkdir -p /opt/var/log/dnscrypt 240 | # Create custom config directory 241 | [ ! -d "${gsDirOverLoad}/dnscrypt/" ] && mkdir -p "${gsDirOverLoad}/dnscrypt/" 242 | 243 | # Create a backup of original file: /opt/etc/init.d/S09dnscrypt-proxy2 244 | { [ -f /opt/etc/init.d/S09dnscrypt-proxy2 ] && [ ! -f "${gsDirBackups}/S09dnscrypt-proxy2.original" ]; } && 245 | cp /opt/etc/init.d/S09dnscrypt-proxy2 "${gsDirBackups}/S09dnscrypt-proxy2.original" 246 | 247 | # Replace original init script by the template 248 | [ -f "${gsDirTemplates}/init/S09dnscrypt-proxy2.tmpl" ] && cp "${gsDirTemplates}/init/S09dnscrypt-proxy2.tmpl" /opt/etc/init.d/S09dnscrypt-proxy2 249 | 250 | # If exist, replace actual init script by cutom 251 | [ -f "${gsDirOverLoad}/S09dnscrypt-proxy2" ] && cp "${gsDirOverLoad}/S09dnscrypt-proxy2" /opt/etc/init.d/S09dnscrypt-proxy2 252 | chmod +x /opt/etc/init.d/S09dnscrypt-proxy2 253 | 254 | # Create a custom config file: dnscrypt-proxy.toml 255 | { [ -f "${gsDirTemplates}/dnscrypt/dnscrypt-proxy.toml.tmpl" ] && [ ! -f "${gsDirOverLoad}/dnscrypt/dnscrypt-proxy.toml" ]; } && 256 | cp "${gsDirTemplates}/dnscrypt/dnscrypt-proxy.toml.tmpl" "${gsDirOverLoad}/dnscrypt/dnscrypt-proxy.toml" 257 | 258 | # Create a backup of original file: /opt/etc/dnscrypt-proxy.toml 259 | { [ -f /opt/etc/dnscrypt-proxy.toml ] && [ ! -f "${gsDirBackups}/dnscrypt-proxy.toml.original" ]; } && 260 | cp /opt/etc/dnscrypt-proxy.toml "${gsDirBackups}/dnscrypt-proxy.toml.original" 261 | 262 | # Copy dnscrypt-proxy.toml from templates for next start 263 | [ -f "${gsDirTemplates}/dnscrypt/dnscrypt-proxy.toml.tmpl" ] && cp "${gsDirTemplates}/dnscrypt/dnscrypt-proxy.toml.tmpl" /opt/etc/dnscrypt-proxy.toml 264 | # If exist, use a custom dnscrypt-proxy.toml 265 | [ -f "${gsDirOverLoad}/dnscrypt/dnscrypt-proxy.toml" ] && cp "${gsDirOverLoad}/dnscrypt/dnscrypt-proxy.toml" /opt/etc/dnscrypt-proxy.toml 266 | 267 | # Blocklists 268 | if (! find "${gsDirOverLoad}/dnscrypt/"*.txt &>/dev/null); then 269 | find "${gsDirTemplates}/dnscrypt/" -name "*.txt.tmpl" -exec bash -c 'i="$1"; mv "$i" ${gsDirOverLoad}/dnscrypt/$(basename $(echo "$1" | sed "s/.tmpl//g;"))' _ {} \; 270 | fi 271 | # Blocklists - generate-domains-blacklists 272 | mkdir -p "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists 273 | if (! find "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/*.txt &>/dev/null); then 274 | find "${gsDirTemplates}/dnscrypt/generate-domains-blacklists/" -name "*.txt.tmpl" -exec bash -c 'i="$1"; mv "$i" ${gsDirOverLoad}/dnscrypt/generate-domains-blacklists/$(basename $(echo "$1" | sed "s/.tmpl//g;"))' _ {} \; 275 | fi 276 | if (! find "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/*.conf &>/dev/null); then 277 | find "${gsDirTemplates}/dnscrypt/generate-domains-blacklists/" -name "*.conf.tmpl" -exec bash -c 'i="$1"; mv "$i" ${gsDirOverLoad}/dnscrypt/generate-domains-blacklists/$(basename $(echo "$1" | sed "s/.tmpl//g;"))' _ {} \; 278 | fi 279 | # Blocklists - generate-domains-blacklists 280 | mkdir -p "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists 281 | if (! find "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/*.txt &>/dev/null); then 282 | find "${gsDirTemplates}/dnscrypt/generate-domains-blacklists/" -name "*.txt.tmpl" -exec bash -c 'i="$1"; mv -v "$i" ${gsDirOverLoad}/dnscrypt/generate-domains-blacklists/$(basename $(echo "$1" | sed "s/.tmpl//g;"))' _ {} \; 283 | fi 284 | if (! find "${gsDirOverLoad}"/dnscrypt/generate-domains-blacklists/*.conf &>/dev/null); then 285 | find "${gsDirTemplates}/dnscrypt/generate-domains-blacklists/" -name "*.conf.tmpl" -exec bash -c 'i="$1"; mv -v "$i" ${gsDirOverLoad}/dnscrypt/generate-domains-blacklists/$(basename $(echo "$1" | sed "s/.tmpl//g;"))' _ {} \; 286 | fi 287 | } 288 | 289 | #### Install P2Partisan 290 | gfnP2pArtisanStartStop() { 291 | 292 | if [ "${gbP2Partisan_Enable}" -eq 1 ] && [ -f /opt/MyTomato/P2Partisan/p2partisan.sh ]; then 293 | #### Files 294 | # Create custom config directory 295 | [ ! -d "${gsDirOverLoad}/p2partisan/" ] && mkdir -p "${gsDirOverLoad}/p2partisan/" 296 | 297 | # Copy templates 298 | { [ -f "${gsDirTemplates}/p2partisan/blacklists.txt.tmpl" ] && [ ! -f /opt/MyTomato/P2Partisan/blacklists ]; } && 299 | cp "${gsDirTemplates}/p2partisan/blacklists.txt.tmpl" /opt/MyTomato/P2Partisan/blacklists 300 | { [ -f "${gsDirTemplates}/p2partisan/blacklist-custom.txt.tmpl" ] && [ ! -f /opt/MyTomato/P2Partisan/blacklist-custom ]; } && 301 | cp "${gsDirTemplates}/p2partisan/blacklist-custom.txt.tmpl" /opt/MyTomato/P2Partisan/blacklist-custom 302 | { [ -f "${gsDirTemplates}/p2partisan/greylist.txt.tmpl" ] && [ ! -f /opt/MyTomato/P2Partisan/greylist ]; } && 303 | cp "${gsDirTemplates}/p2partisan/greylist.txt.tmpl" /opt/MyTomato/P2Partisan/greylist 304 | { [ -f "${gsDirTemplates}/p2partisan/whitelist.txt.tmpl" ] && [ ! -f /opt/MyTomato/P2Partisan/whitelist ]; } && 305 | cp "${gsDirTemplates}/p2partisan/whitelist.txt.tmpl" /opt/MyTomato/P2Partisan/whitelist 306 | 307 | # Create custom lists 308 | { [ -f "${gsDirTemplates}/p2partisan/blacklists.txt.tmpl" ] && [ ! -f "${gsDirOverLoad}/p2partisan/blacklists" ]; } && 309 | cp "${gsDirTemplates}/p2partisan/blacklists.txt.tmpl" "${gsDirOverLoad}/p2partisan/blacklists" 310 | { [ -f "${gsDirTemplates}/p2partisan/blacklist-custom.txt.tmpl" ] && [ ! -f "${gsDirOverLoad}/p2partisan/blacklist-custom" ]; } && 311 | cp "${gsDirTemplates}/p2partisan/blacklist-custom.txt.tmpl" "${gsDirOverLoad}/p2partisan/blacklist-custom" 312 | { [ -f "${gsDirTemplates}/p2partisan/greylist.txt.tmpl" ] && [ ! -f "${gsDirOverLoad}/p2partisan/greylist" ]; } && 313 | cp "${gsDirTemplates}/p2partisan/greylist.txt.tmpl" "${gsDirOverLoad}/p2partisan/greylist" 314 | { [ -f "${gsDirTemplates}/p2partisan/whitelist.txt.tmpl" ] && [ ! -f "${gsDirOverLoad}/p2partisan/whitelist" ]; } && 315 | cp -v "${gsDirTemplates}/p2partisan/whitelist.txt.tmpl" "${gsDirOverLoad}/p2partisan/whitelist" 316 | 317 | # If exist, replace actual list by cutom 318 | [ -f "${gsDirOverLoad}/p2partisan/blacklists" ] && cp "${gsDirOverLoad}/p2partisan/blacklists" /opt/MyTomato/P2Partisan/blacklists 319 | [ -f "${gsDirOverLoad}/p2partisan/blacklist-custom" ] && cp "${gsDirOverLoad}/p2partisan/blacklist-custom" /opt/MyTomato/P2Partisan/blacklist-custom 320 | [ -f "${gsDirOverLoad}/p2partisan/greylist" ] && cp "${gsDirOverLoad}/p2partisan/greylist" /opt/MyTomato/P2Partisan/greylist 321 | [ -f "${gsDirOverLoad}/p2partisan/whitelist" ] && cp "${gsDirOverLoad}/p2partisan/whitelist" /opt/MyTomato/P2Partisan/whitelist 322 | 323 | # Create a symlink to /opt/usr/bin 324 | [ ! -h /opt/sbin/p2partisan.sh ] && ln -s /opt/MyTomato/P2Partisan/p2partisan.sh /opt/sbin/p2partisan.sh 325 | 326 | chmod +x /opt/MyTomato/P2Partisan/p2partisan.sh 327 | /opt/MyTomato/P2Partisan/p2partisan.sh restart 328 | elif [ "${gbP2Partisan_Enable}" -ne 1 ] && [ -f /opt/MyTomato/P2Partisan/p2partisan.sh ]; then 329 | chmod +x /opt/MyTomato/P2Partisan/p2partisan.sh 330 | /opt/MyTomato/P2Partisan/p2partisan.sh stop 331 | fi 332 | } 333 | 334 | #### Install NFS server 335 | gfnInstallNfsServer() { 336 | #### Install 337 | if (! opkg list-installed | grep -q 'nfs-kernel-server'); then 338 | if (opkg list | grep -q 'nfs-kernel-server'); then 339 | logger -p user.notice "| ${gsScriptName} | Start NFS Server installation" 340 | opkg install nfs-kernel-server nfs-kernel-server-utils 341 | logger -p user.notice "| ${gsScriptName} | End of NFS Server installation" 342 | fi 343 | fi 344 | 345 | #### Load modules 346 | gfnLoadModules 'nfs' 347 | 348 | #### Files 349 | # Replace original init script by the template 350 | [ -f "${gsDirTemplates}/init/S57nfs-kernel-server.tmpl" ] && cp "${gsDirTemplates}/init/S57nfs-kernel-server.tmpl" /opt/etc/init.d/S57nfs-kernel-server 351 | 352 | # /etc/services 353 | sed -i '/nfsd/d' /etc/services 354 | if (! grep -q 'nfs 2049/tcp' /etc/services); then 355 | nNumLine=$(grep 'upnp 1900/udp' -n -m 1 /dev/null | grep 'port=') 75 | gsP2Partisan_UdpPorts="" # Whitelist UDP ports separated by commas 76 | gsP2Partisan_TcpPorts="" # Whitelist TCP ports separated by commas 77 | 78 | # DNScrypt-proxy 79 | gbDNScrypt_Enable=1 # Off = 0 / On = 1 80 | gsWan1_DNS="84.200.69.80 84.200.70.40" # Quad 9 DNS; Add 1 or 2 IP address comma seperated. 81 | gsExternalDns="" # External DNS server like PiHole instead of local DNScrypt 82 | 83 | # Upgrade MyTomato from GitHub repository 84 | gbRepoUpgrade_Enable=1 # Off = 0 / On = 1 85 | 86 | #### Export 87 | export binCurl gsDirArmExtras gsUrlArmExtras gsLocales gsTimezone 88 | export gsScriptName gsDirRoot gsDirScripts gsDirOpenVpn gsDirBackups gsDirLogs gsDirTemplates gsDirOverLoad gsDirDnscrypt gsDirDnscryptGen 89 | export gsUsbFileSystem gsUsbOptUuid gsWan1_DNS gsExternalDns gsP2Partisan_UdpPorts gsP2Partisan_TcpPorts 90 | export gdDateTime 91 | export gbP2Partisan_Enable gbDNScrypt_Enable gbRepoUpgrade_Enable gbSyslog_Enable 92 | 93 | # shellcheck disable=SC1091 94 | [ -f "${gsDirOverLoad}"/vars ] && . "${gsDirOverLoad}"/vars 95 | -------------------------------------------------------------------------------- /root/TEMPLATEs/.autorun.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gdDateTime="$(date +%Y%m%d_%H%M)" 4 | 5 | #### Restore config if needed 6 | if [ -z "$(nvram get mytomato_config_save)" ]; then 7 | sLastConfig="$(find /mnt/ -name "MyTomato_*.cfg" -exec ls -A1t {} + | head -1)" 8 | if [ -n "${sLastConfig}" ] && [ -f "${sLastConfig}" ]; then 9 | nvram restore "${sLastConfig}" 10 | sleep 2 11 | nvram set mytomato_config_save="${gdDateTime:?}" 12 | nvram commit 13 | reboot 14 | fi 15 | fi 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /root/TEMPLATEs/dnscrypt/blacklists.txt.tmpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toulousain79/MyTomato/957c871a7d282fa569ee124ab227575c029ccc09/root/TEMPLATEs/dnscrypt/blacklists.txt.tmpl -------------------------------------------------------------------------------- /root/TEMPLATEs/dnscrypt/dnscrypt-proxy.toml.tmpl: -------------------------------------------------------------------------------- 1 | # shellcheck disable=SC1073,SC1072,SC1020,SC1035 2 | ############################################## 3 | # # 4 | # dnscrypt-proxy configuration # 5 | # # 6 | ############################################## 7 | 8 | ## This is an example configuration file. 9 | ## You should adjust it to your needs, and save it as "dnscrypt-proxy.toml" 10 | ## 11 | ## Online documentation is available here: https://dnscrypt.info/doc 12 | 13 | ################################## 14 | # Global settings # 15 | ################################## 16 | 17 | ## List of servers to use 18 | ## 19 | ## Servers from the "public-resolvers" source (see down below) can 20 | ## be viewed here: https://dnscrypt.info/public-servers 21 | ## 22 | ## If this line is commented, all registered servers matching the require_* filters 23 | ## will be used. 24 | ## 25 | ## The proxy will automatically pick the fastest, working servers from the list. 26 | ## Remove the leading # first to enable this; lines starting with # are ignored. 27 | 28 | # server_names = ['scaleway-fr', 'google', 'yandex', 'cloudflare'] 29 | 30 | ## List of local addresses and ports to listen to. Can be IPv4 and/or IPv6. 31 | ## Note: When using systemd socket activation, choose an empty set (i.e. [] ). 32 | 33 | listen_addresses = ['127.0.0.1:52', '[::1]:52'] 34 | 35 | ## Maximum number of simultaneous client connections to accept 36 | 37 | max_clients = 250 38 | 39 | ## Switch to a different system user after listening sockets have been created. 40 | ## Note (1): this feature is currently unsupported on Windows. 41 | ## Note (2): this feature is not compatible with systemd socket activation. 42 | ## Note (3): when using -pidfile, the PID file directory must be writable by the new user 43 | 44 | # user_name = 'nobody' 45 | 46 | ## Require servers (from static + remote sources) to satisfy specific properties 47 | 48 | # Use servers reachable over IPv4 49 | 50 | ipv4_servers = true 51 | 52 | # Use servers reachable over IPv6 -- Do not enable if you don't have IPv6 connectivity 53 | 54 | ipv6_servers = false 55 | 56 | # Use servers implementing the DNSCrypt protocol 57 | 58 | dnscrypt_servers = true 59 | 60 | # Use servers implementing the DNS-over-HTTPS protocol (not available with OPKG binary) 61 | 62 | doh_servers = false 63 | 64 | ## Require servers defined by remote sources to satisfy specific properties 65 | 66 | # Server must support DNS security extensions (DNSSEC) 67 | 68 | require_dnssec = false 69 | 70 | # Server must not log user queries (declarative) 71 | 72 | require_nolog = true 73 | 74 | # Server must not enforce its own blacklist (for parental control, ads blocking...) 75 | 76 | require_nofilter = true 77 | 78 | # Server names to avoid even if they match all criteria 79 | 80 | disabled_server_names = [] 81 | 82 | ## Always use TCP to connect to upstream servers. 83 | ## This can be useful if you need to route everything through Tor. 84 | ## Otherwise, leave this to `false`, as it doesn't improve security 85 | ## (dnscrypt-proxy will always encrypt everything even using UDP), and can 86 | ## only increase latency. 87 | 88 | force_tcp = false 89 | 90 | ## SOCKS proxy 91 | ## Uncomment the following line to route all TCP connections to a local Tor node 92 | ## Tor doesn't support UDP, so set `force_tcp` to `true` as well. 93 | 94 | # proxy = "socks5://127.0.0.1:9050" 95 | 96 | ## HTTP/HTTPS proxy 97 | ## Only for DoH servers 98 | 99 | # http_proxy = "http://127.0.0.1:8888" 100 | 101 | ## How long a DNS query will wait for a response, in milliseconds 102 | 103 | timeout = 2500 104 | 105 | ## Keepalive for HTTP (HTTPS, HTTP/2) queries, in seconds 106 | 107 | keepalive = 30 108 | 109 | ## Use the REFUSED return code for blocked responses 110 | ## Setting this to `false` means that some responses will be lies. 111 | ## Unfortunately, `false` appears to be required for Android 8+ 112 | 113 | refused_code_in_responses = true 114 | 115 | ## Load-balancing strategy: 'p2' (default), 'ph', 'fastest' or 'random' 116 | 117 | lb_strategy = 'p2' 118 | 119 | ## Log level (0-6, default: 2 - 0 is very verbose, 6 only contains fatal errors) 120 | 121 | log_level = 2 122 | 123 | ## log file for the application 124 | 125 | log_file = '/opt/var/log/dnscrypt/dnscrypt-proxy.log' 126 | 127 | ## Use the system logger (syslog on Unix, Event Log on Windows) 128 | 129 | use_syslog = true 130 | 131 | ## Delay, in minutes, after which certificates are reloaded 132 | 133 | cert_refresh_delay = 240 134 | 135 | ## DNSCrypt: Create a new, unique key for every single DNS query 136 | ## This may improve privacy but can also have a significant impact on CPU usage 137 | ## Only enable if you don't have a lot of network load 138 | 139 | # dnscrypt_ephemeral_keys = false 140 | 141 | ## DoH: Disable TLS session tickets - increases privacy but also latency 142 | 143 | tls_disable_session_tickets = false 144 | 145 | ## DoH: Use a specific cipher suite instead of the server preference 146 | ## 49199 = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 147 | ## 49195 = TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 148 | ## 52392 = TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 149 | ## 52393 = TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 150 | ## 151 | ## On non-Intel CPUs such as MIPS routers and ARM systems (Android, Raspberry Pi...), 152 | ## the following suite improves performance. 153 | ## This may also help on Intel CPUs running 32-bit operating systems. 154 | ## 155 | ## Keep tls_cipher_suite empty if you have issues fetching sources or 156 | ## connecting to some DoH servers. Google and Cloudflare are fine with it. 157 | 158 | tls_cipher_suite = [52392, 49199] 159 | 160 | ## Fallback resolver 161 | ## This is a normal, non-encrypted DNS resolver, that will be only used 162 | ## for one-shot queries when retrieving the initial resolvers list, and 163 | ## only if the system DNS configuration doesn't work. 164 | ## No user application queries will ever be leaked through this resolver, 165 | ## and it will not be used after IP addresses of resolvers URLs have been found. 166 | ## It will never be used if lists have already been cached, and if stamps 167 | ## don't include host names without IP addresses. 168 | ## It will not be used if the configured system DNS works. 169 | ## A resolver supporting DNSSEC is recommended. This may become mandatory. 170 | ## 171 | ## People in China may need to use 114.114.114.114:53 here. 172 | ## Other popular options include 8.8.8.8 and 1.1.1.1. 173 | 174 | fallback_resolvers = '84.200.69.80:53' 175 | 176 | ## Never let dnscrypt-proxy try to use the system DNS settings; 177 | ## unconditionally use the fallback resolver. 178 | 179 | ignore_system_dns = false 180 | 181 | ## Maximum time (in seconds) to wait for network connectivity before 182 | ## initializing the proxy. 183 | ## Useful if the proxy is automatically started at boot, and network 184 | ## connectivity is not guaranteed to be immediately available. 185 | ## Use 0 to disable. 186 | 187 | netprobe_timeout = 60 188 | 189 | ## Offline mode - Do not use any remote encrypted servers. 190 | ## The proxy will remain fully functional to respond to queries that 191 | ## plugins can handle directly (forwarding, cloaking, ...) 192 | 193 | # offline_mode = false 194 | 195 | ## Automatic log files rotation 196 | 197 | # Maximum log files size in MB 198 | log_files_max_size = 10 199 | 200 | # How long to keep backup files, in days 201 | log_files_max_age = 7 202 | 203 | # Maximum log files backups to keep (or 0 to keep all backups) 204 | log_files_max_backups = 1 205 | 206 | ######################### 207 | # Filters # 208 | ######################### 209 | 210 | ## Immediately respond to IPv6-related queries with an empty response 211 | ## This makes things faster when there is no IPv6 connectivity, but can 212 | ## also cause reliability issues with some stub resolvers. 213 | ## Do not enable if you added a validating resolver such as dnsmasq in front 214 | ## of the proxy. 215 | 216 | block_ipv6 = false 217 | 218 | ################################################################################## 219 | # Route queries for specific domains to a dedicated set of servers # 220 | ################################################################################## 221 | 222 | ## Example map entries (one entry per line): 223 | ## example.com 9.9.9.9 224 | ## example.net 9.9.9.9,8.8.8.8,1.1.1.1 225 | 226 | # forwarding_rules = '/opt/MyTomato/root/ConfigOverload/dnscrypt/forwarding-rules.txt' 227 | 228 | ############################### 229 | # Cloaking rules # 230 | ############################### 231 | 232 | ## Cloaking returns a predefined address for a specific name. 233 | ## In addition to acting as a HOSTS file, it can also return the IP address 234 | ## of a different name. It will also do CNAME flattening. 235 | ## 236 | ## Example map entries (one entry per line) 237 | ## example.com 10.1.1.1 238 | ## www.google.com forcesafesearch.google.com 239 | 240 | # cloaking_rules = '/opt/MyTomato/root/ConfigOverload/dnscrypt/cloaking-rules.txt' 241 | 242 | ########################### 243 | # DNS cache # 244 | ########################### 245 | 246 | ## Enable a DNS cache to reduce latency and outgoing traffic 247 | 248 | cache = true 249 | 250 | ## Cache size 251 | 252 | cache_size = 512 253 | 254 | ## Minimum TTL for cached entries 255 | 256 | cache_min_ttl = 600 257 | 258 | ## Maximum TTL for cached entries 259 | 260 | cache_max_ttl = 86400 261 | 262 | ## Minimum TTL for negatively cached entries 263 | 264 | cache_neg_min_ttl = 60 265 | 266 | ## Maximum TTL for negatively cached entries 267 | 268 | cache_neg_max_ttl = 600 269 | 270 | ############################### 271 | # Query logging # 272 | ############################### 273 | 274 | ## Log client queries to a file 275 | 276 | [query_log] 277 | 278 | ## Path to the query log file (absolute, or relative to the same directory as the executable file) 279 | 280 | file = '/opt/var/log/dnscrypt/query.log' 281 | 282 | ## Query log format (currently supported: tsv and ltsv) 283 | 284 | format = 'tsv' 285 | 286 | ## Do not log these query types, to reduce verbosity. Keep empty to log everything. 287 | 288 | ignored_qtypes = ['DNSKEY', 'NS'] 289 | 290 | ############################################ 291 | # Suspicious queries logging # 292 | ############################################ 293 | 294 | ## Log queries for nonexistent zones 295 | ## These queries can reveal the presence of malware, broken/obsolete applications, 296 | ## and devices signaling their presence to 3rd parties. 297 | 298 | [nx_log] 299 | 300 | ## Path to the query log file (absolute, or relative to the same directory as the executable file) 301 | 302 | file = '/opt/var/log/dnscrypt/nx.log' 303 | 304 | ## Query log format (currently supported: tsv and ltsv) 305 | 306 | format = 'tsv' 307 | 308 | ###################################################### 309 | # Pattern-based blocking (blacklists) # 310 | ###################################################### 311 | 312 | ## Blacklists are made of one pattern per line. Example of valid patterns: 313 | ## 314 | ## example.com 315 | ## =example.com 316 | ## *sex* 317 | ## ads.* 318 | ## ads*.example.* 319 | ## ads*.example[0-9]*.com 320 | ## 321 | ## Example blacklist files can be found at https://download.dnscrypt.info/blacklists/ 322 | ## A script to build blacklists from public feeds can be found in the 323 | ## `utils/generate-domains-blacklists` directory of the dnscrypt-proxy source code. 324 | 325 | [blacklist] 326 | 327 | ## Path to the file of blocking rules (absolute, or relative to the same directory as the executable file) 328 | 329 | # blacklist_file = '/opt/MyTomato/root/ConfigOverload/dnscrypt/blacklists.txt' 330 | 331 | ## Optional path to a file logging blocked queries 332 | 333 | log_file = '/opt/var/log/dnscrypt/blocked.log' 334 | 335 | ## Optional log format: tsv or ltsv (default: tsv) 336 | 337 | log_format = 'tsv' 338 | 339 | ########################################################### 340 | # Pattern-based IP blocking (IP blacklists) # 341 | ########################################################### 342 | 343 | ## IP blacklists are made of one pattern per line. Example of valid patterns: 344 | ## 345 | ## 127.* 346 | ## fe80:abcd:* 347 | ## 192.168.1.4 348 | 349 | [ip_blacklist] 350 | 351 | ## Path to the file of blocking rules (absolute, or relative to the same directory as the executable file) 352 | 353 | # blacklist_file = '/opt/MyTomato/root/ConfigOverload/dnscrypt/ip_blacklist.txt' 354 | 355 | ## Optional path to a file logging blocked queries 356 | 357 | log_file = '/opt/var/log/dnscrypt/ip_blocked.log' 358 | 359 | ## Optional log format: tsv or ltsv (default: tsv) 360 | 361 | log_format = 'tsv' 362 | 363 | ###################################################### 364 | # Pattern-based whitelisting (blacklists bypass) # 365 | ###################################################### 366 | 367 | ## Whitelists support the same patterns as blacklists 368 | ## If a name matches a whitelist entry, the corresponding session 369 | ## will bypass names and IP filters. 370 | ## 371 | ## Time-based rules are also supported to make some websites only accessible at specific times of the day. 372 | 373 | [whitelist] 374 | 375 | ## Path to the file of whitelisting rules (absolute, or relative to the same directory as the executable file) 376 | 377 | # whitelist_file = '/opt/MyTomato/root/ConfigOverload/dnscrypt/whitelist.txt' 378 | 379 | ## Optional path to a file logging whitelisted queries 380 | 381 | log_file = '/opt/var/log/dnscrypt/whitelisted.log' 382 | 383 | ## Optional log format: tsv or ltsv (default: tsv) 384 | 385 | log_format = 'tsv' 386 | 387 | ########################################## 388 | # Time access restrictions # 389 | ########################################## 390 | 391 | ## One or more weekly schedules can be defined here. 392 | ## Patterns in the name-based blocklist can optionally be followed with @schedule_name 393 | ## to apply the pattern 'schedule_name' only when it matches a time range of that schedule. 394 | ## 395 | ## For example, the following rule in a blacklist file: 396 | ## *.youtube.* @time-to-sleep 397 | ## would block access to YouTube only during the days, and period of the days 398 | ## define by the 'time-to-sleep' schedule. 399 | ## 400 | ## {after='21:00', before= '7:00'} matches 0:00-7:00 and 21:00-0:00 401 | ## {after= '9:00', before='18:00'} matches 9:00-18:00 402 | 403 | [schedules] 404 | 405 | # [schedules.'time-to-sleep'] 406 | # mon = [{after='21:00', before='7:00'}] 407 | # tue = [{after='21:00', before='7:00'}] 408 | # wed = [{after='21:00', before='7:00'}] 409 | # thu = [{after='21:00', before='7:00'}] 410 | # fri = [{after='23:00', before='7:00'}] 411 | # sat = [{after='23:00', before='7:00'}] 412 | # sun = [{after='21:00', before='7:00'}] 413 | 414 | # [schedules.'work'] 415 | # mon = [{after='9:00', before='18:00'}] 416 | # tue = [{after='9:00', before='18:00'}] 417 | # wed = [{after='9:00', before='18:00'}] 418 | # thu = [{after='9:00', before='18:00'}] 419 | # fri = [{after='9:00', before='17:00'}] 420 | 421 | ######################### 422 | # Servers # 423 | ######################### 424 | 425 | ## Remote lists of available servers 426 | ## Multiple sources can be used simultaneously, but every source 427 | ## requires a dedicated cache file. 428 | ## 429 | ## Refer to the documentation for URLs of public sources. 430 | ## 431 | ## A prefix can be prepended to server names in order to 432 | ## avoid collisions if different sources share the same for 433 | ## different servers. In that case, names listed in `server_names` 434 | ## must include the prefixes. 435 | ## 436 | ## If the `urls` property is missing, cache files and valid signatures 437 | ## must be already present; This doesn't prevent these cache files from 438 | ## expiring after `refresh_delay` hours. 439 | 440 | [sources] 441 | 442 | ## An example of a remote source from https://github.com/DNSCrypt/dnscrypt-resolvers 443 | 444 | [sources.'public-resolvers'] 445 | urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/public-resolvers.md', 'https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md'] 446 | cache_file = 'public-resolvers.md' 447 | minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3' 448 | refresh_delay = 72 449 | prefix = 'public-' 450 | 451 | ## Quad9 over DNSCrypt - https://quad9.net/ 452 | 453 | [sources.quad9-resolvers] 454 | urls = ["https://www.quad9.net/quad9-resolvers.md"] 455 | minisign_key = "RWQBphd2+f6eiAqBsvDZEBXBGHQBJfeG6G+wJPPKxCZMoEQYpmoysKUN" 456 | cache_file = "quad9-resolvers.md" 457 | refresh_delay = 72 458 | prefix = "quad9-" 459 | 460 | ## OpenNIC - https://download.dnscrypt.info/dnscrypt-resolvers/v2/opennic.md 461 | 462 | [sources.'opennic'] 463 | urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/opennic.md', 'https://download.dnscrypt.info/resolvers-list/v2/opennic.md'] 464 | minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3' 465 | cache_file = 'opennic.md' 466 | refresh_delay = 72 467 | prefix = "opennic-" 468 | 469 | ## Another example source, with resolvers censoring some websites not appropriate for children 470 | ## This is a subset of the `public-resolvers` list, so enabling both is useless 471 | 472 | # [sources.'parental-control'] 473 | # urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/parental-control.md', 'https://download.dnscrypt.info/resolvers-list/v2/parental-control.md'] 474 | # cache_file = 'parental-control.md' 475 | # minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3' 476 | 477 | ## Optional, local, static list of additional servers 478 | ## Mostly useful for testing your own servers. 479 | 480 | [static] 481 | 482 | # [static.'google'] 483 | # stamp = 'sdns://AgUAAAAAAAAAAAAOZG5zLmdvb2dsZS5jb20NL2V4cGVyaW1lbnRhbA' 484 | -------------------------------------------------------------------------------- /root/TEMPLATEs/dnscrypt/forwarding-rules.txt.tmpl: -------------------------------------------------------------------------------- 1 | ################################## 2 | # Forwarding rules # 3 | ################################## 4 | 5 | ## This is used to route specific domain names to specific servers. 6 | ## The general format is: 7 | ##