Pārlūkot izejas kodu

Tidying of firewall

Bob Mottram 8 gadus atpakaļ
vecāks
revīzija
80ed13fba0

+ 4
- 10
src/freedombone-app-dlna Parādīt failu

87
         # docker does its own firewalling
87
         # docker does its own firewalling
88
         return
88
         return
89
     fi
89
     fi
90
-    iptables -A INPUT -p udp --dport 1900 -j ACCEPT
91
-    iptables -A INPUT -p tcp --dport 8200 -j ACCEPT
92
-    function_check save_firewall_settings
93
-    save_firewall_settings
94
 
90
 
95
-    OPEN_PORTS+=('DLNA     1900')
96
-    OPEN_PORTS+=('DLNA     8200')
91
+    firewall_add DLNA 1900 udp
92
+    firewall_add DLNA 8200 tcp
97
     mark_completed $FUNCNAME
93
     mark_completed $FUNCNAME
98
 }
94
 }
99
 
95
 
162
     if [ -f /etc/minidlna.conf ]; then
158
     if [ -f /etc/minidlna.conf ]; then
163
         rm /etc/minidlna.conf
159
         rm /etc/minidlna.conf
164
     fi
160
     fi
165
-    iptables -D INPUT -p udp --dport 1900 -j ACCEPT
166
-    iptables -D INPUT -p tcp --dport 8200 -j ACCEPT
167
-    function_check save_firewall_settings
168
-    save_firewall_settings
169
     remove_completion_param install_dlna
161
     remove_completion_param install_dlna
162
+    firewall_remove 1900 udp
163
+    firewall_remove 8200 tcp
170
 }
164
 }
171
 
165
 
172
 function install_dlna_main {
166
 function install_dlna_main {

+ 3
- 10
src/freedombone-app-ipfs Parādīt failu

164
     systemctl daemon-reload
164
     systemctl daemon-reload
165
     rm /etc/systemd/system/ipfs.service
165
     rm /etc/systemd/system/ipfs.service
166
     rm -rf $GOPATH/src/github.com/ipfs
166
     rm -rf $GOPATH/src/github.com/ipfs
167
-    iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
168
-    function_check save_firewall_settings
169
-    save_firewall_settings
167
+    firewall_remove $IPFS_PORT tcp
170
     remove_completion_param install_ipfs
168
     remove_completion_param install_ipfs
171
     remove_completion_param configure_firewall_for_ipfs
169
     remove_completion_param configure_firewall_for_ipfs
172
     sed -i '/ipfs/d' $COMPLETION_FILE
170
     sed -i '/ipfs/d' $COMPLETION_FILE
181
     npm uninstall ipfs --global
179
     npm uninstall ipfs --global
182
     npm uninstall ronin --global
180
     npm uninstall ronin --global
183
 
181
 
184
-    iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
185
-    function_check save_firewall_settings
186
-    save_firewall_settings
182
+    firewall_remove $IPFS_PORT tcp
187
     sed -i '/install_ipfs/d' $COMPLETION_FILE
183
     sed -i '/install_ipfs/d' $COMPLETION_FILE
188
     sed -i '/ipfs/d' $COMPLETION_FILE
184
     sed -i '/ipfs/d' $COMPLETION_FILE
189
     sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
185
     sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
201
     if [[ $ONION_ONLY != "no" ]]; then
197
     if [[ $ONION_ONLY != "no" ]]; then
202
         return
198
         return
203
     fi
199
     fi
204
-    iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
205
-    function_check save_firewall_settings
206
-    save_firewall_settings
207
 
200
 
208
-    OPEN_PORTS+=("IPFS     $IPFS_PORT")
201
+    firewall_add IPFS $IPFS_PORT tcp
209
     mark_completed $FUNCNAME
202
     mark_completed $FUNCNAME
210
 }
203
 }
211
 
204
 

+ 4
- 3
src/freedombone-app-irc Parādīt failu

244
     if [ -d /etc/ngircd ]; then
244
     if [ -d /etc/ngircd ]; then
245
         rm -rf /etc/ngircd
245
         rm -rf /etc/ngircd
246
     fi
246
     fi
247
-    iptables -D INPUT -p tcp --dport ${IRC_PORT}  -j ACCEPT
247
+
248
     iptables -D INPUT -p tcp --dport 1024:65535 --sport ${IRC_PORT} -j ACCEPT
248
     iptables -D INPUT -p tcp --dport 1024:65535 --sport ${IRC_PORT} -j ACCEPT
249
     function_check save_firewall_settings
249
     function_check save_firewall_settings
250
     save_firewall_settings
250
     save_firewall_settings
251
+    firewall_remove ${IRC_PORT} tcp
252
+
251
     function_check remove_onion_service
253
     function_check remove_onion_service
252
     remove_onion_service irc ${IRC_ONION_PORT}
254
     remove_onion_service irc ${IRC_ONION_PORT}
253
     remove_completion_param install_irc
255
     remove_completion_param install_irc
269
     if [[ ${ONION_ONLY} != "no" ]]; then
271
     if [[ ${ONION_ONLY} != "no" ]]; then
270
         return
272
         return
271
     fi
273
     fi
272
-    iptables -A INPUT -p tcp --dport ${IRC_PORT}  -j ACCEPT
273
     iptables -I INPUT -p tcp --dport 1024:65535 --sport ${IRC_PORT} -j ACCEPT
274
     iptables -I INPUT -p tcp --dport 1024:65535 --sport ${IRC_PORT} -j ACCEPT
274
     function_check save_firewall_settings
275
     function_check save_firewall_settings
275
     save_firewall_settings
276
     save_firewall_settings
276
 
277
 
277
-    OPEN_PORTS+=("IRC      $IRC_PORT")
278
+    firewall_add IRC ${IRC_PORT} tcp
278
     echo 'configure_firewall_for_irc' >> ${COMPLETION_FILE}
279
     echo 'configure_firewall_for_irc' >> ${COMPLETION_FILE}
279
 }
280
 }
280
 
281
 

+ 2
- 10
src/freedombone-app-librevault Parādīt failu

109
 }
109
 }
110
 
110
 
111
 function remove_librevault {
111
 function remove_librevault {
112
-    iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
113
-    iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
114
-    function_check save_firewall_settings
115
-    save_firewall_settings
116
-
112
+    firewall_remove ${LIBREVAULT_PORT}
117
     systemctl stop librevault
113
     systemctl stop librevault
118
     systemctl disable librevault
114
     systemctl disable librevault
119
     rm /etc/systemd/system/librevault.service
115
     rm /etc/systemd/system/librevault.service
125
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
121
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
126
         return
122
         return
127
     fi
123
     fi
128
-    iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
129
-    iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
130
-    function_check save_firewall_settings
131
-    save_firewall_settings
132
-    OPEN_PORTS+=("Librevault $LIBREVAULT_PORT")
124
+    firewall_add Librevault ${LIBREVAULT_PORT}
133
     mark_completed $FUNCNAME
125
     mark_completed $FUNCNAME
134
 }
126
 }
135
 
127
 

+ 2
- 10
src/freedombone-app-mumble Parādīt failu

158
 function remove_mumble {
158
 function remove_mumble {
159
     apt-get -y remove --purge mumble-server
159
     apt-get -y remove --purge mumble-server
160
     if [[ $ONION_ONLY == "no" ]]; then
160
     if [[ $ONION_ONLY == "no" ]]; then
161
-        iptables -D INPUT -p udp --dport $MUMBLE_PORT -j ACCEPT
162
-        iptables -D INPUT -p tcp --dport $MUMBLE_PORT -j ACCEPT
163
-        function_check save_firewall_settings
164
-        save_firewall_settings
161
+        firewall_remove ${MUMBLE_PORT}
165
     fi
162
     fi
166
     if [ -f /etc/mumble-server.ini ]; then
163
     if [ -f /etc/mumble-server.ini ]; then
167
         rm /etc/mumble-server.ini
164
         rm /etc/mumble-server.ini
189
     if [[ $ONION_ONLY != "no" ]]; then
186
     if [[ $ONION_ONLY != "no" ]]; then
190
         return
187
         return
191
     fi
188
     fi
192
-    iptables -A INPUT -p udp --dport $MUMBLE_PORT -j ACCEPT
193
-    iptables -A INPUT -p tcp --dport $MUMBLE_PORT -j ACCEPT
194
-    function_check save_firewall_settings
195
-    save_firewall_settings
196
-
197
-    OPEN_PORTS+=("Mumble   $MUMBLE_PORT")
189
+    firewall_add Mumble ${MUMBLE_PORT}
198
     mark_completed $FUNCNAME
190
     mark_completed $FUNCNAME
199
 }
191
 }
200
 
192
 

+ 2
- 7
src/freedombone-app-pihole Parādīt failu

207
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
207
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
208
         return
208
         return
209
     fi
209
     fi
210
-    #iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
211
-    iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
212
-    iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
213
-    function_check save_firewall_settings
214
-    save_firewall_settings
215
-
216
-    OPEN_PORTS+=('DNS      53')
210
+    firewall_add DNS 53
217
     mark_completed $FUNCNAME
211
     mark_completed $FUNCNAME
218
 }
212
 }
219
 
213
 
324
         rm /etc/cron.d/pihole
318
         rm /etc/cron.d/pihole
325
     fi
319
     fi
326
 
320
 
321
+    firewall_remove 53
327
     userdel -r pihole
322
     userdel -r pihole
328
 }
323
 }
329
 
324
 

+ 8
- 27
src/freedombone-app-sip Parādīt failu

158
 }
158
 }
159
 
159
 
160
 function remove_sip {
160
 function remove_sip {
161
-    iptables -D INPUT -p udp --dport $TURN_PORT -j ACCEPT
162
-    iptables -D INPUT -p tcp --dport $TURN_PORT -j ACCEPT
163
-    iptables -D INPUT -p tcp --dport $TURN_TLS_PORT -j ACCEPT
164
-
165
-    iptables -D INPUT -p udp --dport $SIP_PORT -j ACCEPT
166
-    iptables -D INPUT -p tcp --dport $SIP_PORT -j ACCEPT
167
-    iptables -D INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
168
-    iptables -D INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
169
-    function_check save_firewall_settings
170
-    save_firewall_settings
161
+    firewall_remove ${TURN_PORT}
162
+    firewall_remove ${TURN_TLS_PORT} tcp
163
+    firewall_remove ${SIP_PORT}
164
+    firewall_remove ${SIP_TLS_PORT}
171
 
165
 
172
     function_check remove_onion_service
166
     function_check remove_onion_service
173
     remove_onion_service sip ${SIP_PORT}
167
     remove_onion_service sip ${SIP_PORT}
192
     if [[ $ONION_ONLY != "no" ]]; then
186
     if [[ $ONION_ONLY != "no" ]]; then
193
         return
187
         return
194
     fi
188
     fi
195
-    iptables -A INPUT -p udp --dport $TURN_PORT -j ACCEPT
196
-    iptables -A INPUT -p tcp --dport $TURN_PORT -j ACCEPT
197
-    iptables -A INPUT -p tcp --dport $TURN_TLS_PORT -j ACCEPT
198
-    function_check save_firewall_settings
199
-    save_firewall_settings
200
-
201
-    OPEN_PORTS+=("TURN     $TURN_PORT")
202
-    OPEN_PORTS+=("TURN TLS $TURN_TLS_PORT")
189
+    firewall_add TURN ${TURN_PORT}
190
+    firewall_add "TURN TLS" ${TURN_TLS_PORT} tcp
203
     mark_completed $FUNCNAME
191
     mark_completed $FUNCNAME
204
 }
192
 }
205
 
193
 
211
     if [[ $ONION_ONLY != "no" ]]; then
199
     if [[ $ONION_ONLY != "no" ]]; then
212
         return
200
         return
213
     fi
201
     fi
214
-    iptables -A INPUT -p udp --dport $SIP_PORT -j ACCEPT
215
-    iptables -A INPUT -p tcp --dport $SIP_PORT -j ACCEPT
216
-    iptables -A INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
217
-    iptables -A INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
218
-    function_check save_firewall_settings
219
-    save_firewall_settings
220
-
221
-    OPEN_PORTS+=("SIP      $SIP_PORT")
222
-    OPEN_PORTS+=("SIP TLS  $SIP_TLS_PORT")
202
+    firewall_add SIP ${SIP_PORT}
203
+    firewall_add "SIP TLS" ${SIP_TLS_PORT}
223
     mark_completed $FUNCNAME
204
     mark_completed $FUNCNAME
224
 }
205
 }
225
 
206
 

+ 2
- 11
src/freedombone-app-syncthing Parādīt failu

462
 }
462
 }
463
 
463
 
464
 function remove_syncthing {
464
 function remove_syncthing {
465
-    iptables -D INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
466
-    iptables -D INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
467
-    function_check save_firewall_settings
468
-    save_firewall_settings
469
-
465
+    firewall_remove ${SYNCTHING_PORT}
470
     systemctl stop syncthing
466
     systemctl stop syncthing
471
     systemctl disable syncthing
467
     systemctl disable syncthing
472
     apt-get -y remove --purge syncthing
468
     apt-get -y remove --purge syncthing
482
         return
478
         return
483
     fi
479
     fi
484
 
480
 
485
-    iptables -A INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
486
-    iptables -A INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
487
-    function_check save_firewall_settings
488
-    save_firewall_settings
489
-
490
-    OPEN_PORTS+=("Syncthing $SYNCTHING_PORT")
481
+    firewall_add Syncthing ${SYNCTHING_PORT}
491
     mark_completed $FUNCNAME
482
     mark_completed $FUNCNAME
492
 }
483
 }
493
 
484
 

+ 2
- 9
src/freedombone-app-tahoelafs Parādīt failu

186
 }
186
 }
187
 
187
 
188
 function remove_tahoelafs {
188
 function remove_tahoelafs {
189
-    iptables -D INPUT -p udp --dport $TAHOELAFS_PORT -j ACCEPT
190
-    iptables -D INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
191
-    function_check save_firewall_settings
192
-    save_firewall_settings
189
+    firewall_remove ${TAHOELAFS_PORT}
193
 
190
 
194
     for d in /home/*/ ; do
191
     for d in /home/*/ ; do
195
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
192
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
209
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
206
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
210
         return
207
         return
211
     fi
208
     fi
212
-    iptables -A INPUT -p udp --dport $TAHOELAFS_PORT -j ACCEPT
213
-    iptables -A INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
214
-    function_check save_firewall_settings
215
-    save_firewall_settings
216
-    OPEN_PORTS+=("Tahoe-LAFS $TAHOELAFS_PORT")
209
+    firewall_add Tahoe-LAFS ${TAHOELAFS_PORT}
217
     mark_completed $FUNCNAME
210
     mark_completed $FUNCNAME
218
 }
211
 }
219
 
212
 

+ 2
- 10
src/freedombone-app-tox Parādīt failu

242
 }
242
 }
243
 
243
 
244
 function remove_tox_node {
244
 function remove_tox_node {
245
-    iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
246
-    iptables -D INPUT -p udp --dport $TOX_PORT -j ACCEPT
247
-    function_check save_firewall_settings
248
-    save_firewall_settings
245
+    firewall_remove ${TOX_PORT}
249
 
246
 
250
     function_check remove_onion_service
247
     function_check remove_onion_service
251
     remove_onion_service tox ${TOX_PORT}
248
     remove_onion_service tox ${TOX_PORT}
307
         exit 32856
304
         exit 32856
308
     fi
305
     fi
309
 
306
 
310
-    iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
311
-    iptables -A INPUT -p udp --dport $TOX_PORT -j ACCEPT
312
-    function_check save_firewall_settings
313
-    save_firewall_settings
314
-
315
-    OPEN_PORTS+=("Tox      $TOX_PORT")
307
+    firewall_add Tox ${TOX_PORT}
316
     mark_completed $FUNCNAME
308
     mark_completed $FUNCNAME
317
 }
309
 }
318
 
310
 

+ 10
- 14
src/freedombone-app-xmpp Parādīt failu

251
     if [[ $ONION_ONLY != "no" ]]; then
251
     if [[ $ONION_ONLY != "no" ]]; then
252
         return
252
         return
253
     fi
253
     fi
254
-    iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
255
-    iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
256
-    iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
257
-    function_check save_firewall_settings
258
-    save_firewall_settings
259
-
260
-    OPEN_PORTS+=('XMPP     5222-5223')
261
-    OPEN_PORTS+=('XMPP     5269')
262
-    OPEN_PORTS+=('XMPP     5280-5281')
254
+    firewall_add XMPP 5222 tcp
255
+    firewall_add XMPP 5223 tcp
256
+    firewall_add XMPP 5269 tcp
257
+    firewall_add XMPP 5280 tcp
258
+    firewall_add XMPP 5281 tcp
263
     mark_completed $FUNCNAME
259
     mark_completed $FUNCNAME
264
 }
260
 }
265
 
261
 
271
 
267
 
272
 function remove_xmpp {
268
 function remove_xmpp {
273
     remove_xmpp_client
269
     remove_xmpp_client
274
-    iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
275
-    iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
276
-    iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
277
-    function_check save_firewall_settings
278
-    save_firewall_settings
270
+    firewall_remove 5222 tcp
271
+    firewall_remove 5223 tcp
272
+    firewall_remove 5269 tcp
273
+    firewall_remove 5280 tcp
274
+    firewall_remove 5281 tcp
279
 
275
 
280
     function_check remove_onion_service
276
     function_check remove_onion_service
281
     remove_onion_service xmpp 5222 5223 5269
277
     remove_onion_service xmpp 5222 5223 5269

+ 8
- 17
src/freedombone-app-zeronet Parādīt failu

126
     remove_zeronet_blog
126
     remove_zeronet_blog
127
     remove_zeronet_mail
127
     remove_zeronet_mail
128
     remove_zeronet_forum
128
     remove_zeronet_forum
129
-    iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT
130
-    iptables -D INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT
131
-    iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT
132
-    iptables -D INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT
133
-    iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT
134
-    function_check save_firewall_settings
135
-    save_firewall_settings
129
+
130
+    firewall_remove ${ZERONET_PORT}
131
+    firewall_remove ${TRACKER_PORT}
132
+    firewall_remove 1900 udp
133
+
136
     ${PROJECT_NAME}-mesh-install -f zeronet --remove yes
134
     ${PROJECT_NAME}-mesh-install -f zeronet --remove yes
137
     remove_completion_param install_zeronet
135
     remove_completion_param install_zeronet
138
     remove_completion_param configure_firewall_for_zeronet
136
     remove_completion_param configure_firewall_for_zeronet
143
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
141
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
144
         return
142
         return
145
     fi
143
     fi
146
-    iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT
147
-    iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT
148
-    iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT
149
-    iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT
150
-    iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT
151
-    function_check save_firewall_settings
152
-    save_firewall_settings
153
-
154
-    OPEN_PORTS+=("ZeroNet  $ZERONET_PORT")
155
-    OPEN_PORTS+=("Tracker  $TRACKER_PORT")
144
+    firewall_add ZeroNet ${ZERONET_PORT}
145
+    firewall_add Tracker ${TRACKER_PORT}
146
+    firewall_add Tracker 1900 udp
156
     mark_completed $FUNCNAME
147
     mark_completed $FUNCNAME
157
 }
148
 }
158
 
149
 

+ 5
- 11
src/freedombone-base-email Parādīt failu

93
     if [[ $ONION_ONLY != "no" ]]; then
93
     if [[ $ONION_ONLY != "no" ]]; then
94
         return
94
         return
95
     fi
95
     fi
96
-    iptables -A INPUT -p tcp --dport 25 -j ACCEPT
97
-    iptables -A INPUT -p tcp --dport 587 -j ACCEPT
98
-    iptables -A INPUT -p tcp --dport 465 -j ACCEPT
99
-    iptables -A INPUT -p tcp --dport 993 -j ACCEPT
100
-    function_check save_firewall_settings
101
-    save_firewall_settings
102
-
103
-    OPEN_PORTS+=('Email    25')
104
-    OPEN_PORTS+=('Email    587')
105
-    OPEN_PORTS+=('Email    465')
106
-    OPEN_PORTS+=('Email    993')
96
+
97
+    firewall_add Email 25 tcp
98
+    firewall_add Email 587 tcp
99
+    firewall_add Email 465 tcp
100
+    firewall_add Imap 993 tcp
107
     mark_completed $FUNCNAME
101
     mark_completed $FUNCNAME
108
 }
102
 }
109
 
103
 

+ 0
- 6
src/freedombone-utils-final Parādīt failu

28
 # You should have received a copy of the GNU Affero General Public License
28
 # You should have received a copy of the GNU Affero General Public License
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
 
30
 
31
-OPEN_PORTS=()
32
-
33
 function install_final {
31
 function install_final {
34
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
32
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
35
         return
33
         return
50
 
48
 
51
     Ensure that these ports are forwarded from your internet router
49
     Ensure that these ports are forwarded from your internet router
52
 "
50
 "
53
-    for p in "${OPEN_PORTS[@]}"
54
-    do
55
-        echo "  $p"
56
-    done
57
     echo ''
51
     echo ''
58
 
52
 
59
     if [ -f "/home/$MY_USERNAME/README" ]; then
53
     if [ -f "/home/$MY_USERNAME/README" ]; then

+ 58
- 20
src/freedombone-utils-firewall Parādīt failu

28
 # You should have received a copy of the GNU Affero General Public License
28
 # You should have received a copy of the GNU Affero General Public License
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
 
30
 
31
+FIREWALL_CONFIG=$HOME/firewall.cfg
32
+
31
 function save_firewall_settings {
33
 function save_firewall_settings {
32
     iptables-save > /etc/firewall.conf
34
     iptables-save > /etc/firewall.conf
33
     ip6tables-save > /etc/firewall6.conf
35
     ip6tables-save > /etc/firewall6.conf
156
     if [[ $ONION_ONLY != "no" ]]; then
158
     if [[ $ONION_ONLY != "no" ]]; then
157
         return
159
         return
158
     fi
160
     fi
159
-    iptables -A INPUT -p tcp --dport 32768:61000 --sport 80 -j ACCEPT
160
-    iptables -A INPUT -p tcp --dport 32768:61000 --sport 443 -j ACCEPT
161
-    function_check save_firewall_settings
162
-    save_firewall_settings
163
-
161
+    firewall_remove 80 tcp
162
+    firewall_remove 443 tcp
164
     mark_completed $FUNCNAME
163
     mark_completed $FUNCNAME
165
 }
164
 }
166
 
165
 
175
     if [[ $ONION_ONLY != "no" ]]; then
174
     if [[ $ONION_ONLY != "no" ]]; then
176
         return
175
         return
177
     fi
176
     fi
178
-    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
179
-    iptables -A INPUT -p tcp --dport 443 -j ACCEPT
180
-    function_check save_firewall_settings
181
-    save_firewall_settings
182
 
177
 
183
-    OPEN_PORTS+=('HTTP     80')
184
-    OPEN_PORTS+=('HTTPS    443')
178
+    firewall_add HTTP 80 tcp
179
+    firewall_add HTTPS 443 tcp
185
     mark_completed $FUNCNAME
180
     mark_completed $FUNCNAME
186
 }
181
 }
187
 
182
 
193
         # docker does its own firewalling
188
         # docker does its own firewalling
194
         return
189
         return
195
     fi
190
     fi
196
-    iptables -A INPUT -p tcp --dport 22 -j ACCEPT
197
-    iptables -A INPUT -p tcp --dport $SSH_PORT -j ACCEPT
198
-    function_check save_firewall_settings
199
-    save_firewall_settings
200
 
191
 
201
-    OPEN_PORTS+=("SSH      $SSH_PORT")
192
+    firewall_add SSH 22 tcp
193
+    firewall_add SSH ${SSH_PORT} tcp
202
     mark_completed $FUNCNAME
194
     mark_completed $FUNCNAME
203
 }
195
 }
204
 
196
 
213
     if [[ $ONION_ONLY != "no" ]]; then
205
     if [[ $ONION_ONLY != "no" ]]; then
214
         return
206
         return
215
     fi
207
     fi
216
-    iptables -A INPUT -p tcp --dport 9418 -j ACCEPT
217
-    function_check save_firewall_settings
218
-    save_firewall_settings
219
 
208
 
220
-    OPEN_PORTS+=("Git      9418")
209
+    firewall_add Git 9418 tcp
221
     mark_completed $FUNCNAME
210
     mark_completed $FUNCNAME
222
 }
211
 }
223
 
212
 
314
     echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
303
     echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
315
     chroot "$rootdir" systemctl enable meshfirewall
304
     chroot "$rootdir" systemctl enable meshfirewall
316
 }
305
 }
306
+
307
+function firewall_add {
308
+    firewall_name="$1"
309
+    firewall_port=$2
310
+    firewall_protocol="$3"
311
+
312
+    if ! grep -q "${firewall_name}=${firewall_port}" $FIREWALL_CONFIG; then
313
+        echo "${firewall_name}=${firewall_port}" >> $FIREWALL_CONFIG
314
+        if [ ! ${firewall_protocol} ]; then
315
+            iptables -A INPUT -p udp --dport ${firewall_port} -j ACCEPT
316
+            iptables -A INPUT -p tcp --dport ${firewall_port} -j ACCEPT
317
+        else
318
+            if [[ "${firewall_protocol}" == *"udp"* ]]; then
319
+                iptables -A INPUT -p udp --dport ${firewall_port} -j ACCEPT
320
+            fi
321
+            if [[ "${firewall_protocol}" == *"tcp"* ]]; then
322
+                iptables -A INPUT -p tcp --dport ${firewall_port} -j ACCEPT
323
+            fi
324
+        fi
325
+        save_firewall_settings
326
+    fi
327
+}
328
+
329
+function firewall_remove {
330
+    firewall_port=$1
331
+    firewall_protocol="$2"
332
+
333
+    if [ ! -f $FIREWALL_CONFIG ]; then
334
+        return
335
+    fi
336
+
337
+    if grep -q "=${firewall_port}" $FIREWALL_CONFIG; then
338
+        if [ ! ${firewall_protocol} ]; then
339
+            iptables -D INPUT -p udp --dport ${firewall_port} -j ACCEPT
340
+            iptables -D INPUT -p tcp --dport ${firewall_port} -j ACCEPT
341
+        else
342
+            if [[ "${firewall_protocol}" == *"udp"* ]]; then
343
+                iptables -D INPUT -p udp --dport ${firewall_port} -j ACCEPT
344
+            fi
345
+            if [[ "${firewall_protocol}" == *"tcp"* ]]; then
346
+                iptables -D INPUT -p tcp --dport ${firewall_port} -j ACCEPT
347
+            fi
348
+        fi
349
+        sed -i "/=${firewall_port}/d" $FIREWALL_CONFIG
350
+        save_firewall_settings
351
+    fi
352
+}
353
+
354
+# NOTE: deliberately no exit 0