-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhostflash
More file actions
executable file
·2313 lines (1797 loc) · 64.6 KB
/
Copy pathhostflash
File metadata and controls
executable file
·2313 lines (1797 loc) · 64.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# set -euo pipefail
# set -x
IFS=$'\n\t'
###
# Host Flash™ 4.0.3
#
# Downloads hosts file rules from various sources.
# Installs hosts file rules into /etc/hosts
# Integrates Host Flash™ hosts file rules with rules that already exist in /etc/hosts
#
# For OS: Linux (Debian)
# Tested With: Ubuntu flavours
#
# Lead Author: Lee Hodson<https://github.com/vr51//>
# Contributor: skeletonkey<https://github.com/skeletonkey/>
# Donate: https://paypal.me/vr51
# Website: https://host-flash.com<https://host-flash.com>
# This Release: 23rd April 2025
# First Written: 18th Oct. 2015
# First Release: 2nd Nov. 2015
#
# Copyright Host Flash™ https://host-flash.com<https://host-flash.com>
# License: GPL3
#
# Programmer: Lee Hodson<journalxtra.com>, VR51<vr51.com>
#
# Use of this program is at your own risk
#
# INSTALLS OR UPDATES
#
# Use Host Flash™ to block access to websites (hosts), ad servers, malicious websites and time wasting websites.
# Use Host Flash™ to manage your hosts file
#
# TO RUN:
#
# Ensure the script is executable:
#
# Right-click > properties > Executable
#
# OR
#
# chmod u+x hostflash
#
# Launch by clicking the script file or by typing `bash ./hostflash` at the command line.
#
# Host Flash™ will attempt to preserve existing host rules.
#
###
##
# TO DO / DEV NOTES
# Please feel free to work through this list if you wish to help the project.
#
#
#
#
# line 1583 fix restore. should point to backup directory and unzip into tmp directory then test for hosts before moving it to /etc/hosts
##
#
# Modularisation
# Host Flash is meant to be a single file downloadable script.
# I (Lee) might convert the script to an installer that chops itself up to extract modules.
# This would enable Host Flash to accept plugins, facilitate user customizations and facilitate HF's future development.
# TBC...
#
# Use one file per list.
# Download Free Mode. Place source files into directory. HF builds from source files.
# Rebuild source file process method
#
# If internet is available (Check exit status of latest Git commit check: $networked should = 0 if the net is available)
# Download DOCs
# Offer HF script updates
# Show error if internet is unavailable
#
# versions: add deb installer
#
# En/disable Automatic list update
# En/disable Automatic script update
#
# CLI: disable HF, enable HF, add rule, remove rule, update lists, set options
#
# List Build Options
# Build pure list. No whitelisting
# Check whitelists (extracted, found, not found) # To be integrated from standalone file.
# Rebuild whitelists after check
# Build filtered list. Whitelisting done
# Install after build
# Do not install after build
# Compact local whitelists and local blacklists (all lower, sort -u)
# View/Edit local lists (nano, pico, cat)
#
# Feature: search hosts file for a domain or list of domains (grep without regex)
# Offer to disable if found
# Offer to add to custom whitelist
#
# Switchlist
# Temporarily disable and enable whitelist hosts
# Options
# Check .hfremoved list # Script written and tested ready for insertion
# Move items from .hfremoved to post processing blacklist
# Move items from .hfremoved to Switch List
#
# Move more actions into functions.
# Tidy up
# Add input checking/sanitisation
# Make messages and menus clearer
# Menu + View all HF configs
#
# Summary info on main screen / maybe footer for all screens
# Add more useful info
# Include link to host-flash.com
#
# Info about each list
# Last update time
#
# Go through functions to state the output format
#
# Rebuild menu system based on SaLi text mode only
###
##
# NOTES
#
# Hosts File Build Process
#
# The host file work is done in $HOME/src/hostflash/tmp. This eventually builds hosts.txt
# The final build of hosts.txt is moved to $HOME/src/hostflash/
# __enable looks for $HOME/src/hostflash/hosts.txt which it moves to /etc/hosts
#
# Whitelist Processing
#
# Whitelist wild is processed twice:
# As a normal whitelist
# As a wild whitelist
# A period is added before the first character of each host name processed
##
##
# CONFIGS ARE BELOW HERE - should be no reason to manually change these
#
# Any of these can be overruled by adding each variable along with its new value into $HOME/.config/hostflash/.hfrc
# Adding config changes to $HOME/.config/hostflash/.hfrc will protect changes from script version updates.
##
##
# Raw URLs for those who want them
# wget https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt
# wget https://adaway.org/hosts.txt
# wget https://pgl.yoyo.org/as/serverlist.php?showintro=0;hostformat=hosts
# wget https://raw.githubusercontent.com/azet12/KADhosts/master/KADhosts.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/ad_servers.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/emd.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/exp.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/fsa.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/grm.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/hfs.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/hjk.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/mmt.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/pha.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/psh.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/pup.txt
# wget https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master/wrz.txt
# wget https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt
# wget https://www.github.developerdan.com/hosts/lists/tracking-aggressive-extended.txt
# wget https://www.hostsfile.org/Downloads/hosts.txt
# wget https://www.malwaredomainlist.com/hostslist/hosts.txt
#
# wget http://rlwpx.free.fr/WPFF/hmis.7z
# wget http://rlwpx.free.fr/WPFF/hpub.7z
# wget http://rlwpx.free.fr/WPFF/hrsk.7z
# wget http://rlwpx.free.fr/WPFF/hsex.7z
# wget http://rlwpx.free.fr/WPFF/htrc.7z
# wget https://winhelp2002.mvps.org/hosts.zip
#
# wget https://raw.githubusercontent.com/mitchellkrogza/Badd-Boyz-Hosts/master/hosts
# wget https://someonewhocares.org/hosts/hosts
# IMPORTANT: Do not Use trailing slashes in URLs, URIs or directory paths
package='Host Flash™' # Name of software installed by this installer
version='4.0.3 - 23rd April 2025' # Updated version with optimizations and fixes
debug='0'
## Clear screen
__clear() {
if [ "$debug" -eq 0 ]; then
clear
fi
}
## Source loader
# Load source files
# This facilitates modularisation
__flying_sourcer() {
local SourcerSection="$1"
# Try to source the file using 'source' command, fallback to '.' if it fails
# Note: The duplicate source command was removed as it was redundant
if ! source "${SourcerSection}" 2>/dev/null; then
. "${SourcerSection}"
fi
}
# Clear arrays
unset app conf dir file in list log message rem menu select mode essentialpackages credits flush listc listcc listsc
# Declare associative arrays
declare -A app conf dir file list log message rem
# Declare regular arrays and types
declare -a menu # Menu options are set within __menu_main()
declare -a select # Menu options count
declare -a mode # Used for notices
declare -a essentialpackages # Packages to install to help the build process
declare -a credits # Hosts file credits
declare -a flush # DNS cache flush commands
declare -i listc listcc listsc # For list repository counts
# Remote Hosts
rem[gith]='https://github.com/VR51/host-flash' # Github home URL for this package.
rem[gitp]='https://github.com/VR51/host-flash.git' # Software source package git address
rem[tld]='https://data.iana.org/TLD/tlds-alpha-by-domain.txt' # Official list of valid TLDs
# Directories
# These directories are created by dir[@] dump. Be careful when adding directories to this list
#
# Top level directories
dir[hfh]="$HOME/hostflash" # Host Flash Home directory
dir[src]="$HOME/src/hostflash" # Directory where source hosts files are stored locally
dir[conf]="$HOME/.config/hostflash" # Location of custom configuration files.
# Sub level directories
## These are permanent doc and log directories
dir[docs]="${dir[hfh]}/DOC" # Location of program documents. # To be written
dir[logs]="${dir[hfh]}/logs" # Location of host file logs.
dir[bck]="${dir[hfh]}/backups" # Location of host file backups.
## These are config directories
dir[lists]="${dir[conf]}/lists" # Modular lists
dir[menus]="${dir[conf]}/menus" # Modular menus
dir[plugs]="${dir[conf]}/plugins" # Modular plugins
## These are wiped each time a hosts file is built unless DEBUG is set to '1'.
dir[tmp]="${dir[src]}/tmp" # Directory where temporary files are stored locally
dir[tmpd]="${dir[tmp]}/downloads" # Directory where source hosts files downloaded and unpacked before being moved
dir[tmpu]="${dir[tmp]}/unprocessed" # Directory where unprocessed source hosts files are stored
dir[tmpp]="${dir[tmp]}/processed" # Directory where processed source hosts files are stored. This allows us to check events.
# Files
file[hosts]=''
# System hosts file location. Where it is copied from and where it is installed to.
# See next code block, it replaces this current section. This section is here for reference or in case there is need to manually set the path.
#
# file[hosts]='/etc/hosts' # Location of system hosts file in Unix, Unix-like and POSIX systems.
# file[hosts]='/private/etc/hosts' # iOS, Apple Mac
# file[hosts]='/system/etc/hosts' # Android
# file[hosts]='%SystemRoot%\System32\drivers\etc\hosts' # Windows NT, 2000, XP,[5] 2003, Vista, 2008, 7, 2012, 8, 10
# Custom Hosts File location
# file[hosts]='/enter/path/to/file/called/hosts' # Add the path to your system's hosts file then uncomment (remove the #) and save to activate.
__clear
if [ -z "${file[hosts]}" ]; then
if [ -f "/system/etc/hosts" ]; then
file[hosts]='/system/etc/hosts'
elif [ -f "/private/etc/hosts" ]; then
file[hosts]='/private/etc/hosts'
elif [ -f "/etc/hosts" ]; then
file[hosts]='/etc/hosts'
else
echo "Unable to detect the location of this system's hosts file."
echo "Please edit the hostflash program at around line 175 to set a custom value for ${bold}file[hosts]${normal} to point to your system's hosts file"
echo "and uncomment the line edited."
echo "Alternatively, add ${bold}file[hosts]='/path/to/your/hosts'${normal} to ${bold}$HOME/.config/hostflash/.hfrc${normal} if the change should survive script updates."
echo "Visit ${bold}${rem[gith]}${normal} if you want us to add your host file's location to the automatic detection list."
echo "Press any key to exit $package"
read a
exit 1
fi
fi
# HF Config Files
# These are created by file[@] dump. Be careful when adding files to this list
file[conf]="${dir[conf]}/.hfrc" # Location of user's custom settings for Host Flash™.
file[confwl]="${dir[conf]}/.hfwlrc" # Location of the user's custom whitelist.
file[confwlw]="${dir[conf]}/.hfwlwrc" # Location of the user's custom whitelist-wild.
file[confbl]="${dir[conf]}/.hfblrc" # Location of the user's custom blacklist.
file[confcl]="${dir[conf]}/.hfclrc" # Location of the user's custom hosts lists.
file[confr]="${dir[conf]}/.hfremoved" # Hosts removed from hosts list during hosts build/update.
file[conftld]="${dir[conf]}/.hftld" # Location of valid TLD list.
# Log files
file[hist]="${dir[logs]}/history.txt" # Location of update history.
file[log]="${dir[logs]}/log.txt" # Location of the general process log file.
file[debug]="${dir[logs]}/debug.txt" # Location of debug logging file.
# Next files to be used in a later version of HF
file[confpost]="${dir[conf]}/.hfpost" # Location of the post processing blacklist (block hosts that are wild needlessly whitelisted)
file[confsl]="${dir[conf]}/.hfslrc" # Location of the user's hosts switch list.
# App Launcher Settings
# These are specific to the application/task manager installer (yet to be implemented)
app[icon]="${dir[src]}/data" # Directory where the application icon will be located.
app[bin]='/usr/bin' # Binary installation path. Where should the compiled binary be installed to? Exact path. # Not required for this installer.
app[icon]="hostflash.svg" # Icon name
app[type]='Application' #
app[cats]='Utilities' # Application launcher categories
app[binary]="hostflash" # Name of the binary file that is this program.
# Detected settings
user="$(whoami)" # Current User
group="$(id -g -n "$user")" # Current user's primary group
###
# DECLARE LIST ARRAYS
###
# Declare custom list associative arrays. If they are not declared we cannot use them.
# Count Lists
listc=$(grep -E '\[status[[:digit:]]+]=' "$0" | wc -l) # Count lists in hostflash script
if grep -Eq '\[status[[:digit:]]+]=' "${file[confcl]}" 2>/dev/null; then
listcc=$(grep -E '\[status[[:digit:]]+]=' "${file[confcl]}" | wc -l) # Count custom lists in .hfclrc
else
listcc=0
fi
listsc=$((listc + listcc)) # Use arithmetic expansion instead of let
##
# LISTS
#
# These are set with
#
# list[status]='Enabled / Disabled' # + or - for TRUE or FALSE
# list[info]='List Domain' # The name of the list
# list[src]='Download URL' # From where the package will be retrieved
# list[file]='Download Package' # Name of package retrieved
# list[target]='Package Target' # Name of usable file in a retrieved zip package / Name of file created on retrieval if FLAG is raw
# list[ip]='0' # 0 or 1 for false or true. Add loopback IP address to downloaded list. This is required when a hosts list consists of domain names with no IP prefix. Not required for whitelists, in fact should never be set to '1' for whitelists.
#
# Changes to list[status] are stored in .hfrc
# Custom lists will be added to .hfclrc
# Framework in place: conf etc... Needs menu section to be added.
##
# TO DO: Change to list[NUM TYPE]
# https://hosts-file.net/?s=Download <-- DEAD. This is now a Malwarebytes browser addon.
# Files from here now mirrored and updated at https://github.com/fredprod/host-file.net-backup
# & https://github.com/blackskye-sx/host-file.net-backup
list[status1]='+'
list[info1]='hosts-file.net - Ad Servers (Liberal)'
list[src1]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file1]='ad_servers.txt'
list[target1]='ad_servers.txt'
list[ip1]='0'
list[status2]='+'
list[info2]='hosts-file.net - EMD (Liberal)'
list[src2]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file2]='emd.txt'
list[target2]='emd.txt'
list[ip2]='0'
list[status3]='+'
list[info3]='hosts-file.net - EXP (Liberal)'
list[src3]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file3]='exp.txt'
list[target3]='exp.txt'
list[ip3]='0'
list[status4]='+'
list[info4]='hosts-file.net - FSA (Liberal)'
list[src4]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file4]='fsa.txt'
list[target4]='fsa.txt'
list[ip4]='0'
list[status5]='+'
list[info5]='hosts-file.net - GRM (Liberal)'
list[src5]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file5]='grm.txt'
list[target5]='grm.txt'
list[ip5]='0'
list[status6]='+'
list[info6]='hosts-file.net - HFS (Liberal)'
list[src6]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file6]='hfs.txt'
list[target6]='hfs.txt'
list[ip6]='0'
list[status7]='+'
list[info7]='hosts-file.net - HJK (Liberal)'
list[src7]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file7]='hjk.txt'
list[target7]='hjk.txt'
list[ip7]='0'
list[status8]='+'
list[info8]='hosts-file.net - MMT (Liberal)'
list[src8]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file8]='mmt.txt'
list[target8]='mmt.txt'
list[ip8]='0'
list[status9]='+'
list[info9]='hosts-file.net - PHA (Liberal)'
list[src9]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file9]='pha.txt'
list[target9]='pha.txt'
list[ip9]='0'
list[status10]='+'
list[info10]='hosts-file.net - PSH (Liberal)'
list[src10]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file10]='psh.txt'
list[target10]='psh.txt'
list[ip10]='0'
list[status11]='+'
list[info11]='hosts-file.net - PUP (Liberal)'
list[src11]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file11]='pup.txt'
list[target11]='pup.txt'
list[ip11]='0'
list[status12]='+'
list[info12]='hosts-file.net - WRZ (Liberal)'
list[src12]='https://raw.githubusercontent.com/blackskye-sx/host-file.net-backup/master'
list[file12]='wrz.txt'
list[target12]='wrz.txt'
list[ip12]='0'
list[status13]='+'
list[info13]='mvps.org (Liberal: Blocks mostly adware, spyware, malware and trackers. Big list)'
list[src13]='https://winhelp2002.mvps.org'
list[file13]='hosts.zip'
list[target13]='HOSTS'
list[ip13]='0'
list[status14]='+'
list[info14]='free.fr-Trackers (Moderate: Blocks trackers)'
list[src14]='http://rlwpx.free.fr/WPFF'
list[file14]='htrc.7z'
list[target14]='Hosts.trc'
list[ip14]='0'
list[status15]='+'
list[info15]='free.fr-Ad-Servers (Moderate: Blocks ad servers)'
list[src15]='http://rlwpx.free.fr/WPFF'
list[file15]='hpub.7z'
list[target15]='Hosts.pub'
list[ip15]='0'
list[status16]='+'
list[info16]='free.fr-Malware (Moderate: Blocks malware domains)'
list[src16]='http://rlwpx.free.fr/WPFF'
list[file16]='hrsk.7z'
list[target16]='Hosts.rsk'
list[ip16]='0'
list[status17]='+'
list[info17]='free.fr-Adult (Moderate: Blocks adult domains. Coincidentally blocks forums and some social sites)'
list[src17]='http://rlwpx.free.fr/WPFF'
list[file17]='hsex.7z'
list[target17]='Hosts.sex'
list[ip17]='0'
list[status18]='+'
list[info18]='free.fr-Misc (Moderate: Blocks miscellaneous domains)'
list[src18]='http://rlwpx.free.fr/WPFF'
list[file18]='hmis.7z'
list[target18]='Hosts.mis'
list[ip18]='0'
list[status19]='+'
list[info19]='someonewhocares.org (Liberal: Blocks mostly adware, spyware, malware and trackers. Small list)'
list[src19]='https://someonewhocares.org/hosts'
list[file19]='hosts'
list[target19]='hosts.txt'
list[ip19]='0'
list[status20]='-'
list[info20]='Removed - No longer accessible'
list[src20]=''
list[file20]=''
list[target20]=''
list[ip20]='0'
list[status21]='+'
list[info21]='KADhosts (Liberal: Blocks malware hosts)'
list[src21]='https://raw.githubusercontent.com/azet12/KADhosts/master/KADhosts.txt'
list[file21]=''
list[target21]='hosts.txt'
list[ip21]='0'
list[status22]='+'
list[info22]='yoyo.org (Liberal: Blocks adservers)'
list[src22]='https://pgl.yoyo.org/as/serverlist.php?showintro=0;hostformat=hosts'
list[file22]=''
list[target22]='hosts.txt'
list[ip22]='0'
list[status23]='+'
list[info23]='Mitchell Krog (Liberal: Blocks spam bot hosts)'
list[src23]='https://raw.githubusercontent.com/mitchellkrogza/Badd-Boyz-Hosts/master/hosts'
list[file23]=''
list[target23]='hosts.txt'
list[ip23]='0'
list[status24]='-'
list[info24]='Removed - No longer accessible'
list[src24]=''
list[file24]=''
list[target24]=''
list[ip24]='0'
list[status25]='+'
list[info25]='Developer Dan Ads and Trackers Safe List (Liberal: Blocks ads and trackers)'
list[src25]='https://www.github.developerdan.com/hosts/lists'
list[file25]='ads-and-tracking-extended.txt'
list[target25]='hosts.txt'
list[ip25]='0'
list[status26]='+'
list[info26]='Developer Dan Ads and Trackers Aggressive List (Moderate: Could cause browsing issues)'
list[src26]='https://www.github.developerdan.com/hosts/lists'
list[file26]='tracking-aggressive-extended.txt'
list[target26]='hosts.txt'
list[ip26]='0'
# Alternative address: https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt
list[status27]='+'
list[info27]='AdAway (Liberal: Blocks ad networks)'
list[src27]='https://adaway.org'
list[file27]='hosts.txt'
list[target27]='hosts.txt'
list[ip27]='0'
list[status28]='+'
list[info28]='hostsfile.org (Very Strict: Regular blocks + porn, gambling and gaming sites)\n'
list[src28]='https://www.hostsfile.org/Downloads'
list[file28]='hosts.txt'
list[target28]='hosts.txt'
list[ip28]='0'
# Others
list[status29]='+'
list[info29]='Community Whitelist (Host Flash™ whitelist. Unblocks a limited set of sites blocked by the other blacklists)'
list[src29]='https://gist.githubusercontent.com/VR51/7eaace2b6778ea508996/raw/'
list[file29]='remw'
list[target29]='whitelist.txt'
list[ip29]='0'
list[status30]='+'
list[info30]='Community Whitelist Wild (Host Flash™ wild whitelist. Unblocks a limited set of sites blocked by the other blacklists)'
list[src30]='https://gist.githubusercontent.com/VR51/9798c78337fe2f7ad589/raw/'
list[file30]='remww'
list[target30]='whitelist-wild.txt'
list[ip30]='0'
list[status31]='+'
list[info31]='Community Blacklist (Host Flash™ blacklist. Blocks a limited set of sites not blocked by other lists)'
list[src31]='https://gist.githubusercontent.com/VR51/ef3b90b1be2693a44f27/raw/'
list[file31]='remb'
list[target31]='hosts.txt'
list[ip31]='1'
list[status32]='+'
list[info32]='Local Whitelist (Your own custom whitelist)'
list[src32]='localhost'
list[file32]="${file[confwl]}"
list[target32]='whitelist.txt'
list[ip32]='0'
list[status33]='+'
list[info33]='Local Whitelist Wild (Your own custom wild whitelist)'
list[src33]='localhost'
list[file33]="${file[confwlw]}"
list[target33]='whitelist-wild.txt'
list[ip33]='0'
list[status34]='+'
list[info34]='Local blacklist (Your own custom blacklist)'
list[src34]='localhost'
list[file34]="${file[confbl]}"
list[target34]='hosts.txt'
list[ip34]='1'
# GENERAL
essentialpackages=( zip unzip 7z curl sed git )
conf[ess]=0 # Essentials # Install build essential software. 0 = Not done, 1 = Done
conf[upv]=0 # Update Host Flash™ program.
#conf[locv]=$($binary -v) # Installed package version
conf[inst]=$( ls -l "$0" | cut -d' ' -f 6-8) # $package installation date
conf[locv]="$version installed ${conf[inst]}"
# Use a timeout to prevent hanging if network is unavailable
conf[gitv]=$(curl -v --silent "${rem[gith]}/commit/master" --stderr - --connect-timeout 5 | grep '<relative-time datetime' | sed -E 's#.+">(.+)<.+#\1#')
networked=$? # Are we connected to the net? We are if $networked = 0
conf[hosts]=$( ls -l "${file[hosts]}" | cut -d' ' -f5 ) # Hosts file size
conf[hostt]=$( ls -l "${file[hosts]}" | cut -d' ' -f 6-8 ) # Hosts file timestamp
conf[hostc]=$( wc -l "${file[hosts]}" | cut -d' ' -f1 ) # Hosts file line count
conf[ip]='0.0.0.0' # Redirect IP address
conf[mode]='1' # Build Only or Build and Install 0 or 1
timestamp="$(date +"%Y-%m-%d-%H-%M-%S")"
# LOGS
# Log host file history, general log messages and debug messages
__log() {
# @1 = File to store log (hist, log, or debug)
# @2 = Message to store with log
local log_file=$1
local message=$2
local now
# Get current timestamp
now="$(date +"%Y-%m-%d %H:%M:%S")"
case "$log_file" in
hist)
# Only append message if it's not empty
[ -n "$message" ] && echo "$message" >> "${file[hist]}"
echo "$now: Line Count: ${conf[hostc]} | Bytes: ${conf[hosts]} | Timestamp: ${conf[hostt]} | Location: ${file[hosts]}" >> "${file[hist]}"
;;
log)
echo "$now: $message" >> "${file[log]}"
;;
debug)
echo "$now: $message" >> "${file[debug]}"
;;
esac
}
## END CONFIGS
## BEGIN
# Other settings
bold=$(tput bold)
normal=$(tput sgr0)
# Locate where we are
filepath="$( echo $PWD )"
# A Little precaution
cd "$filepath"
# Make/Remove directories and files
__download_tlds() {
# Download TLD list if it doesn't exist or is older than 24 hours (1440 minutes)
if [ ! -f "${file[conftld]}" ] || [ -n "$(find "${file[conftld]}" -mmin +1440 2>/dev/null)" ]; then
# Download TLD list, convert to lowercase, and remove comments
curl -s -L "${rem[tld]}" -o "${file[conftld]}.tmp"
if [ $? -eq 0 ]; then
# Convert to lowercase and remove comments
sed -e 's/\(.*\)/\L\1/' "${file[conftld]}.tmp" | grep -vE '^#' > "${file[conftld]}"
rm -f "${file[conftld]}.tmp"
else
__log "log" "Failed to download TLD list from ${rem[tld]}"
fi
fi
}
# __download_tlds # Get TLD list # Not yet used.
case "${debug}" in
0)
if test -d "${dir[tmp]}"; then
rm -r "${dir[tmp]}" # Clean the tmp directory but not if we are debugging.
fi
;;
esac
# Make directories and files that do not yet exist
mkdir -p "${dir[@]}" # Make directories
touch -a "${file[@]}" # Make config files
# INSTALL RC SETTINGS
__repaint() {
# Loads configs then clears the screen
# Whatever calls this should reload the screen for the new configs to be reflected on the screen
# @1 = type: soft, hard, conf, ret
# soft just refreshes the screen
# hard reloads the script in the current shell
# conf must be followed by a config file to load. Loads default conf then extra conf.
# 'no argument' loads the default config file represented by ${file[conf]}
# @2..@n = config file(s) to reload
#
# ret executes the function stated in $2
__clear
# Create array from arguments with proper quoting
local in=( "$@" )
case "${in[0]}" in
soft) # Reset variables
unset
__repaint
;;
hard) # Restart this script
exec bash "$0"
;;
conf) # Include basic conf and any extras listed in $@
# Process additional config files
for i in "${in[@]:1}"; do
[ -f "$i" ] && __flying_sourcer "$i"
done
# Always load the main config file
[ -f "${file[conf]}" ] && __flying_sourcer "${file[conf]}"
;;
ret) # Execute a function
# Only execute if the function exists
if [ -n "${in[1]}" ] && declare -F "${in[1]}" >/dev/null; then
"${in[1]}"
fi
;;
*) # Include basic conf only
[ -f "${file[conf]}" ] && __flying_sourcer "${file[conf]}"
;;
esac
}
# Include custom lists
__repaint conf "${file[confcl]}"
##
# Actions
##
__run() {
# Check if running in a terminal, if not launch terminal
# Otherwise run the main menu
if ! tty -s; then
__launch
else
__menu_main "${1:-}" # This will be changed when CLI added
fi
}
__hosts_update() {
# Read the file of hosts and remove any line listed in the input whitelist file
# The results are logged in a file in the config directory.
# @1 = type: (file) norm or wild, or (string) linen or linew
# @2 = file to remove data from
# @3 = file containing lines of data to remove from @2 or single line of text to remove from @2
# Validate inputs
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
__log "log" "Error: Missing parameters in __hosts_update"
return 1
fi
# Use local variables for clarity and safety
local input_type="$1"
local target_file="$2"
local filter_source="$3"
local temp_file
local line
local escaped_ip
# Check if target file exists
if [ ! -f "$target_file" ]; then
__log "log" "Error: Target file '$target_file' not found"
return 1
fi
# Escape IP for grep pattern (convert periods to character classes)
escaped_ip=$(echo "${conf[ip]}" | sed 's/\./[.]/g')
# Process according to input type
case "$input_type" in
norm)
# Log header for non-wild whitelist processing
echo -ne "\n###\n# NON-WILD WHITELIST\n###\n\n" >> "${file[confr]}"
# Process each line in the filter file
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and comments
[ -z "$line" ] || [[ "$line" =~ ^[[:space:]]*# ]] && continue
# Escape dots in the line for grep pattern
escaped_line=$(echo "$line" | sed 's/\./[.]/g')
# Log the line being processed
echo -ne "\n# $line\n\n" >> "${file[confr]}"
# Log removed entries
grep -i "^${escaped_ip}[[:blank:]]${escaped_line}$" "$target_file" >> "${file[confr]}" || true
# Remove entries from target file
temp_file="$(mktemp)"
grep -vi "^${escaped_ip}[[:blank:]]${escaped_line}$" "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
done < "$filter_source"
;;
wild)
# Log header for wild whitelist processing
echo -ne "\n###\n# WILD WHITELIST PASS 2 - WILD\n###\n\n" >> "${file[confr]}"
# Process each line in the filter file
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and comments
[ -z "$line" ] || [[ "$line" =~ ^[[:space:]]*# ]] && continue
# Escape dots in the line for grep pattern
escaped_line=$(echo "$line" | sed 's/\./[.]/g')
# Log the line being processed
echo -ne "\n# $line\n\n" >> "${file[confr]}"
# Log removed entries
grep -i "^${escaped_ip}[[:blank:]].*[.]${escaped_line}" "$target_file" >> "${file[confr]}" || true
# Remove entries from target file
temp_file="$(mktemp)"
grep -vi "^${escaped_ip}[[:blank:]].*[.]${escaped_line}" "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
done < "$filter_source"
;;
linen) # Single line exact match
# Escape dots in the data for grep pattern
local data=$(echo "$filter_source" | sed 's/\./[.]/g')
# Log removed entries
grep -i "^${escaped_ip}[[:blank:]]${data}$" "$target_file" >> "${file[confr]}" || true
# Remove entries from target file
temp_file="$(mktemp)"
grep -vi "^${escaped_ip}[[:blank:]]${data}$" "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
;;
linew) # Single line wildcard match
# Escape dots in the data for grep pattern
local data=$(echo "$filter_source" | sed 's/\./[.]/g')
# Log removed entries
grep -i "^${escaped_ip}[[:blank:]].*[.]${data}" "$target_file" >> "${file[confr]}" || true
# Remove entries from target file
temp_file="$(mktemp)"
grep -vi "^${escaped_ip}[[:blank:]].*[.]${data}" "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
;;
*)
__log "log" "Error: Unknown input type '$input_type' in __hosts_update"
return 1
;;
esac
return 0
}
__conf_update() {
# Add or remove a single host from the .hf*rc config files
# ! Considered merging this function with __hosts_update. Opted to keep the two separate. It simplifies input sanitization.
# @1 = type: add, rem, remw, or remn (remove by line number)
# @2 = data to add/remove
# @3 = file to add/remove @1 to/from
# Validate inputs
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
__log "log" "Error: Missing parameters in __conf_update"
return 1
fi
# Use local variables for clarity and safety
local action="$1"
local data="$2"
local target_file="$3"
local temp_file
# Check if target file exists
if [ ! -f "$target_file" ]; then
__log "log" "Warning: Target file '$target_file' not found in __conf_update"
touch "$target_file" # Create the file if it doesn't exist
fi
case "$action" in
add)
# Only add the entry if it doesn't already exist
if ! grep -qF "$data" "$target_file"; then
echo "$data" >> "$target_file"
__log "log" "Added entry '$data' to $target_file"
return 0
fi
;;
rem)
# Use grep to safely remove exact matches
temp_file="$(mktemp)"
grep -v "^${data}$" "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
__log "log" "Removed exact match entries for '$data' from $target_file"
;;
remw)
# Use grep to safely remove wildcard matches
temp_file="$(mktemp)"
grep -v "${data}" "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
__log "log" "Removed wildcard match entries for '$data' from $target_file"
;;
remn)
# Remove by line number if data is a valid number
if [[ "$data" =~ ^[0-9]+$ ]]; then
temp_file="$(mktemp)"
sed "${data}d" "$target_file" > "$temp_file"
mv -f "$temp_file" "$target_file"
__log "log" "Removed line $data from $target_file"
else
__log "log" "Error: Invalid line number '$data' in __conf_update"
return 1
fi
;;
*)
__log "log" "Error: Unknown action '$action' in __conf_update"
return 1
;;
esac
# Remove empty lines from the file
temp_file="$(mktemp)"
grep -v '^$' "$target_file" > "$temp_file" || true
mv -f "$temp_file" "$target_file"
return 0
}
__conf_delete() {
__repaint conf "${file[confcl]}"
# Delete specified file
# @1 = File to delete
# @2 = File's friendly name
# Validate inputs
if [ -z "$1" ] || [ -z "$2" ]; then
__log "log" "Error: Missing parameters in __conf_delete"
return 1
fi
# Use local variables for clarity and safety
local target_file="$1"
local friendly_name="$2"
local choice
printf "${bold}DELETE CONFIG FILES${normal}"
printf "\n\nReset chosen configuration file\n\n"
# Display menu
unset menu
menu[1]="Proceed: Reset ${friendly_name} by deleting file ${target_file}"
menu[2]="Return: Do not reset ${friendly_name}"
local m=1
while [ $m -le ${#menu[@]} ]; do
printf "%d) %s\n" "$m" "${menu[$m]}"
((m++))
done
printf "\nChoose an option then press Enter:\n"
read -r choice
while true; do
case "$choice" in
1)
if [ -f "$target_file" ]; then
rm -f "$target_file"
__log "log" "Deleted configuration file: $target_file"
printf "%s reset.\n" "$friendly_name"
printf "\nPress any key to continue\n"
touch "$target_file"
read -r something
__repaint conf "${file[confcl]}"
__menu_reset_confs
else
printf "%s not found.\n" "$friendly_name"
printf "Custom settings not yet created. Nothing to do. Nothing done.\n"
printf "\nPress any key to continue\n"