├── bin ├── .ufw-autowhitelist.version ├── .ufw-autowhitelist.config.clear ├── .ufw-autowhitelist.config.sample ├── ufw-autowhitelist-update └── ufw-autowhitelist ├── .gitignore ├── etc └── not-z.png ├── README.md ├── install_ufw-autowhitelist.sh └── LICENSE /bin/.ufw-autowhitelist.version: -------------------------------------------------------------------------------- 1 | v1.0.0 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.config 3 | etc/previous_ips 4 | -------------------------------------------------------------------------------- /etc/not-z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyX-Community/ufw-autowhitelist/master/etc/not-z.png -------------------------------------------------------------------------------- /bin/.ufw-autowhitelist.config.clear: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | declare -a HOSTNAMES=() 4 | declare -a HOSTNAMESIPS=() 5 | declare -a CURRENTIPS=() 6 | -------------------------------------------------------------------------------- /bin/.ufw-autowhitelist.config.sample: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Add or remove as many lines as you need 4 | declare -a HOSTNAMES+=("host-1.example.com") 5 | declare -a HOSTNAMES+=("host-2.example.com") 6 | declare -a HOSTNAMES+=("host-3.example.com") 7 | declare -a HOSTNAMES+=("host-4.example.com") 8 | -------------------------------------------------------------------------------- /bin/ufw-autowhitelist-update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | cd ${SCRIPT_DIR} 5 | 6 | # Autofilled Variables (do not change) 7 | export vPWD=$(pwd) 8 | export vPATH=$(echo $PATH) 9 | export vVER=$(cat .ufw-autowhitelist.version) 10 | 11 | timestamp() { 12 | echo -n "[$(date +"%Y-%m-%d %H-%M-%S")] " 13 | } 14 | 15 | if [[ -f ".ufw-autowhitelist.config" ]]; then 16 | 17 | source .ufw-autowhitelist.config 18 | 19 | timestamp ; echo "" 20 | timestamp ; echo "ufw-autowhitelist-update ${vVER}" 21 | timestamp ; echo "" 22 | timestamp ; echo "pwd [$vPWD]" 23 | timestamp ; echo "path [$vPATH]" 24 | timestamp ; echo "" 25 | 26 | else 27 | 28 | echo ".ufw-autowhitelist.config does not exist.\nPlease read the README.md and run the installer!" 29 | echo "" 30 | exit 31 | 32 | fi 33 | 34 | cd .. 35 | git pull ; ./install_ufw-autowhitelist.sh ; 36 | cd ${SCRIPT_DIR} 37 | 38 | # Clear ENV vars for security 39 | source .ufw-autowhitelist.config.clear 40 | -------------------------------------------------------------------------------- /bin/ufw-autowhitelist: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | cd ${SCRIPT_DIR} 5 | 6 | vFORCEOPT=$1 7 | if [[ ! -z "${vFORCEOPT}" ]] ; then vFORCEOPT=true ; fi 8 | 9 | # Autofilled Variables (do not change) 10 | export vPWD=$(pwd) 11 | export vPATH=$(echo $PATH) 12 | export vVER=$(cat ${SCRIPT_DIR}/.crypto-autosend.version) 13 | 14 | # Init array of hostnames 15 | declare -a HOSTNAMES 16 | declare -a HOSTNAMESIPS 17 | declare -a PREVIOUSIPS 18 | 19 | timestamp() { 20 | echo -n "[$(date +"%Y-%m-%d %H-%M-%S")] " 21 | } 22 | 23 | timestamp ; echo "" 24 | timestamp ; echo "ufw-autowhitelist ${vVER}" 25 | timestamp ; echo "" 26 | timestamp ; echo "pwd [$vPWD]" 27 | timestamp ; echo "path [$vPATH]" 28 | timestamp ; echo "" 29 | 30 | if test -f ".ufw-autowhitelist.config"; then 31 | source .ufw-autowhitelist.config 32 | else 33 | timestamp ; echo ".ufw-autowhitelist.config does not exist, please read the README.md!" 34 | timestamp ; echo "" 35 | exit 36 | fi 37 | 38 | # Read old hostnames from previous_ips file 39 | while read var; do 40 | var=$(echo "${var}" | xargs) 41 | declare -a PREVIOUSIPS+=("${var}") 42 | done < ../etc/previous_ips 43 | 44 | vHOSTNAMESLEN=${#HOSTNAMES[@]} 45 | for (( j=0; j=0 && NR<=1 { print $1 }' | xargs)) 49 | timestamp ; echo "Host ${j}: [${HOSTNAMES[$j]}] Curr. IP: [${HOSTNAMESIPS[$j]}] Prev. IP: [${PREVIOUSIPS[$j]}]" 50 | 51 | if [[ "${HOSTNAMESIPS[$j]}" == "${PREVIOUSIPS[$j]}" ]] && [[ ! $vFORCEOPT ]] ; then 52 | timestamp ; echo "Host ${HOSTNAMES[$j]} IP's are same, not updating..." 53 | else 54 | timestamp ; echo "Host ${HOSTNAMES[$j]} IP's are different, updating..." 55 | timestamp ; ufw delete allow from ${PREVIOUSIPS[$j]} 56 | timestamp ; ufw allow from ${HOSTNAMESIPS[$j]} 57 | timestamp ; echo "" 58 | fi 59 | 60 | done 61 | 62 | echo "" 63 | ufw status 64 | echo "" 65 | 66 | # Write old hostnames to previous_ips file 67 | echo -n "" > ../etc/previous_ips 68 | for i in "${HOSTNAMESIPS[@]}" 69 | do 70 | i=$(echo "${i}" | xargs) 71 | echo "$i" 72 | done >> ../etc/previous_ips 73 | 74 | # Clear ENV vars for security 75 | source .ufw-autowhitelist.config.clear 76 | 77 | exit 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ufw-autowhitelist v1.0.0 2 | 3 | Auto Whitelist for UFW to be used with dynamic IP address. Featuring a new installer. Linux only. 4 | 5 | Force update with `ufw-autowhitelist --force` 6 | 7 | All three domains will be resolved and then whitelisted in UFW. The old IP address will be removed each update. 8 | 9 | ### Disclaimer: 10 | **I am not liable in any way for damages to your computer due to bugs, being hacked, exploited, or any other malfunction of the scripts. Having a script that automatically whitelist's ip addresses is possibly dangerous and can be exploited for malicious purposes. Please be advised of the risks and ensure the domains/webservices are hosted at a registrar/host with 2fa enabled and secure passwords. This source code is open, it is your responsibility to audit the code.** 11 | 12 | #### Notes: 13 | - It is important the instructions are completed in order 14 | - Read the notes about [cronjobs](#cronjobs) before installing 15 | - Do not delete the git repository directory, it installs in it's place 16 | 17 | #### Setup: 18 | 1. change to the directory where you want ufw-autowhitelist installed 19 | 2. `git clone https://gogs.easyx.cc/EasyX-Community/ufw-autowhitelist.git` 20 | 3. `cd ufw-autowhitelist` 21 | 4. `./install_ufw-autowhitelist.sh` 22 | 5. enter domains one at a time (do not put https:// or trailing / - leave blank when finished) 23 | 6. `source ~/.bashrc` 24 | 25 | #### Updating (manual): 26 | 1. `ufw-autowhitelist` 27 | 28 | #### Cronjobs: 29 | The installer will ask if you want it to install cronjob for you. It will also ask if you want it to install a weekly update cronjob for you. 30 | 31 | It is advised you select **'yes'** and then if you want to change it you can use `crontab -e` later. 32 | 33 | If you are unsure about crontab times, this calculator will come in handy [https://crontab.guru/](https://crontab.guru/) 34 | 35 | #### Coming features: 36 | - Can't think of any at the moment, but please create GitHub or Gogs issue ticket if you have any suggestions. 37 | 38 | 39 | #### Donations: 40 | **XMR:** 84wwa7EKo8uasZAHijHKtBTuBaMPuNjCJgnfGJrsLFo4aZcfrzGvUX33sSeFNdno8fPiTDGnz4h1bCvsdFQYWRuR2619FzS
41 | **ETH(ERC-20):** 0xc89eEa9b5C0cfa7f583dc1A6405a7d5730ADB603
42 | **BNB(BSC)** 0xc89eEa9b5C0cfa7f583dc1A6405a7d5730ADB603
43 | **RTM:** RDg5KstHYvxip77EiGhPKYNL3TZQr6456T
44 | **AVN:** R9zSPpKjo6tCutMT5FyyGNr2vRaAssEtrm
45 | **PHL:** F7XaUosKYEXPP62o31DdpDoADo3VcxoFP4
46 | **PEXA:** XBghzGLdeUzspUcJpeggPFLs3mAyTRHpPH
47 | -------------------------------------------------------------------------------- /install_ufw-autowhitelist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | cd ${SCRIPT_DIR} 5 | 6 | # Autofilled Variables (do not change) 7 | export vPWD=$(pwd) 8 | export vPATH=$(echo $PATH) 9 | export vVER=$(cat bin/.ufw-autowhitelist.version) 10 | 11 | # Init array of hostnames 12 | declare -a HOSTNAMES 13 | declare -a HOSTNAMESIPS 14 | declare -a PREVIOUSIPS 15 | 16 | if [ -f "bin/.ufw-autowhitelist.config" ] ; then 17 | 18 | source bin/.ufw-autowhitelist.config 19 | 20 | echo "" 21 | echo "ufw-autowhitelist ${vVER}" 22 | echo "" 23 | echo "pwd [$vPWD]" 24 | echo "path [$vPATH]" 25 | echo "" 26 | 27 | else 28 | 29 | echo "apt updating..." 30 | apt update 31 | echo "" 32 | 33 | vDIALOG=$(dpkg-query -l dialog) 34 | if [[ "no packages found matching" == *"${vDIALOG}"* ]]; then 35 | echo "installing dialog" 36 | echo "" 37 | apt install -y dialog 38 | echo "" 39 | fi 40 | 41 | vUFW=$(dpkg-query -l ufw) 42 | if [[ "no packages found matching" == *"${vUFW}"* ]]; then 43 | echo "installing ufw" 44 | echo "" 45 | apt install -y ufw 46 | echo "" 47 | fi 48 | 49 | export vHOSTCTR=0 50 | export vCONTINUEVAR=1 51 | export vHOST="thiscanbeanythingtostart" 52 | while [ "$vCONTINUEVAR" == "1" ] 53 | do 54 | 55 | dialog --stdout --title "Configuration" \ 56 | --backtitle "ufw-autowhitelist ${vVER} setup" \ 57 | --inputbox "Enter hostnames, enter blank when finished" 8 60 58 | 59 | while : ; do 60 | 61 | vHOST=$(dialog --stdout --title "Configuration" \ 62 | --backtitle "ufw-autowhitelist ${vVER} setup" \ 63 | --inputbox "Host $vHOSTCTR (blank to finish): \n" 8 60) 64 | 65 | # Add host to arrays 66 | declare -a HOSTNAMES+=(${vHOST}) 67 | 68 | if [[ ! -z "${vHOST}" ]] ; then 69 | ((vHOSTCTR+=1)) 70 | else 71 | break; 72 | fi 73 | 74 | done 75 | 76 | 77 | 78 | dialog --stdout --title "Configuration" \ 79 | --backtitle "ufw-autowhitelist ${vVER} setup" \ 80 | --yesno "Should I install cronjob to run every 5 min?" 10 60 \ 81 | 3>&1 1>&2 2>&3 3>&- 82 | vCRONJOB=$? 83 | 84 | dialog --stdout --title "Configuration" \ 85 | --backtitle "ufw-autowhitelist ${vVER} setup" \ 86 | --yesno "Should I install cronjob to update ufw-autowhitelist weekly?" 10 60 \ 87 | 3>&1 1>&2 2>&3 3>&- 88 | vCRONJOBUPDATE=$? 89 | 90 | if [ $vCRONJOB -eq 0 ] ; then 91 | vCRONJOBENG="yes" 92 | else 93 | vCRONJOBENG="no" 94 | fi 95 | 96 | if [ $vCRONJOBUPDATE -eq 0 ] ; then 97 | vCRONJOBUPDATEENG="yes" 98 | else 99 | vCRONJOBUPDATEENG="no" 100 | fi 101 | 102 | export vHOSTNAMESLEN=${#HOSTNAMES[@]} 103 | export vYESNOLEN=11 104 | 105 | export vYESNOCONFIRM="Is this information correct?\n\n" 106 | if [ $vHOSTCTR -gt 11 ] ; then 107 | vYESNOLEN=$vHOSTNAMESLEN+11 108 | fi 109 | for (( j=0; j&1 1>&2 2>&3 3>&- 119 | vCONTINUEVAR=$? 120 | 121 | if [ "$vCONTINUEVAR" == "1" ] ; then 122 | export vHOSTCTR=0 123 | export vHOST="thiscanbeanythingtostart" 124 | declare -a HOSTNAMES=() 125 | else 126 | break 127 | fi 128 | 129 | done 130 | 131 | echo "" | tee bin/.ufw-autowhitelist.config > /dev/null 2>&1 132 | echo "#!/usr/bin/env bash" | tee -a bin/.ufw-autowhitelist.config > /dev/null 2>&1 133 | echo "" | tee -a bin/.ufw-autowhitelist.config > /dev/null 2>&1 134 | echo "# Add or remove as many lines as you need" | tee -a bin/.ufw-autowhitelist.config > /dev/null 2>&1 135 | 136 | for (( j=0; j /dev/null 2>&1 139 | done 140 | 141 | echo "" | tee -a bin/.ufw-autowhitelist.config > /dev/null 2>&1 142 | 143 | fi 144 | 145 | source bin/.ufw-autowhitelist.config 146 | 147 | # CHMOD the ufw-autowhitelist scripts 148 | chmod +x bin/ufw-autowhitelist* 149 | 150 | # Check if vPWD/bin is added to $PATH 151 | if [[ "${vPATH}" == *"${vPWD}/bin"* ]]; then 152 | echo "ufw-autowhitelist directory already in path [${vPATH}]" 153 | echo "" 154 | else 155 | echo "Adding ufw-autowhitelist directory to \$PATH" 156 | echo "export PATH=${vPWD}/bin:\$PATH" | tee -a ${HOME}/.bashrc 157 | echo "" 158 | fi 159 | 160 | # ADD CRYPTO-AUTOSEND CRONJOB 161 | if [[ $vCRONJOB -eq 0 ]] ; then 162 | vCRONJOBENG="yes" 163 | vCRONENTRIES=$(crontab -l) 164 | if [[ "$vCRONENTRIES" != *"${vPWD}/bin/ufw-autowhitelist ;"* ]] ; then 165 | echo "installing ufw-autowhitelist cronjob" 166 | echo -e "$(crontab -l)\n\n# ufw-autowhitelist cronjob" | crontab - 167 | echo -e "$(crontab -l)\n*/5 * * * * ${vPWD}/bin/ufw-autowhitelist ;" | crontab - 168 | else 169 | echo "refusing to install ufw-autowhitelist cron, cron already exists!" 170 | fi 171 | else 172 | vCRONJOBENG="no" 173 | echo "skipping ufw-autowhitelist cronjob install" 174 | fi 175 | 176 | # ADD CRYPTO-AUTOSEND-UPDATE CRONJOB 177 | if [[ $vCRONJOBUPDATE -eq 0 ]] ; then 178 | vCRONJOBUPDATEENG="yes" 179 | vCRONENTRIES=$(crontab -l) 180 | if [[ "$vCRONENTRIES" != *"@weekly ${vPWD}/bin/ufw-autowhitelist-update ;"* ]] ; then 181 | echo "installing ufw-autowhitelist-update cronjob" 182 | echo -e "$(crontab -l)\n\n# ufw-autowhitelist-update cronjob" | crontab - 183 | echo -e "$(crontab -l)\n@weekly ${vPWD}/bin/ufw-autowhitelist-update ;" | crontab - 184 | else 185 | echo "refusing to install ufw-autowhitelist-update cron, cron already exists!" 186 | fi 187 | else 188 | vCRONJOBUPDATEENG="no" 189 | echo "skipping ufw-autowhitelist-update cronjob install" 190 | fi 191 | 192 | echo "" 193 | echo "Please execute 'source ${HOME}/.bashrc' or log out and back in again" 194 | echo "" 195 | echo "ufw-autowhitelist installation is complete!" 196 | echo "" 197 | 198 | # Clear ENV vars for security 199 | source bin/.ufw-autowhitelist.config.clear 200 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | Copyright (C) 2007 Free Software Foundation, Inc. 4 | 5 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 6 | 7 | This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 8 | 9 | 0. Additional Definitions. 10 | 11 | As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. 12 | 13 | "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. 14 | 15 | An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. 16 | 17 | A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". 18 | 19 | The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. 20 | 21 | The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 22 | 23 | 1. Exception to Section 3 of the GNU GPL. 24 | You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 25 | 26 | 2. Conveying Modified Versions. 27 | If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: 28 | 29 | a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or 30 | 31 | b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 32 | 33 | 3. Object Code Incorporating Material from Library Header Files. 34 | The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: 35 | 36 | a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. 37 | 38 | b) Accompany the object code with a copy of the GNU GPL and this license document. 39 | 40 | 4. Combined Works. 41 | You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: 42 | 43 | a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. 44 | 45 | b) Accompany the Combined Work with a copy of the GNU GPL and this license document. 46 | 47 | c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. 48 | 49 | d) Do one of the following: 50 | 51 | 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 52 | 53 | 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. 54 | 55 | e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 56 | 57 | 5. Combined Libraries. 58 | You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: 59 | 60 | a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. 61 | 62 | b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 63 | 64 | 6. Revised Versions of the GNU Lesser General Public License. 65 | The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 66 | 67 | Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. 68 | 69 | If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall 70 | apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. 71 | --------------------------------------------------------------------------------