StevenBlack / hosts

🔒 Consolidating and extending hosts files from several well-curated sources. Optionally pick extensions for porn, social media, and other categories.
MIT License
26.51k stars 2.2k forks source link

hosts file not copying/replacing file in /etc/hosts on Archlinux #2015

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, as stated when i do the following command in archlinux the hosts file does not get replaced with the generated one? Ive used the latest release of steven black hosts and press Y to replace hosts in /etc/hosts but nothing happens. It does generate a hosts file but it stays in the folder in PWD.

python3 updateHostsFile.py

welcome[bot] commented 2 years ago

Hello! Thank you for opening your first issue in this repo. It’s people like you who make these host files better!

StevenBlack commented 2 years ago

@stvnl2022 see this comment in code:

https://github.com/StevenBlack/hosts/blob/4ffbac63c2608204b164c72525d971365c61e1c0/updateHostsFile.py#L1273-L1275

Surely this is a permissions issue.

ghost commented 2 years ago

I have sudo permissions. I also have root permission on my machine. Here is the terminal output if it helps, im not sure why its doing printenv after Do you want to replace your existing hosts file with the newly generated file? [Y/n] Replacing /etc/hosts requires root privileges. You might need to enter your password. Is that normal?

stvnl@desktop1 ~/hosts-3.10.18 % python3 updateHostsFile.py
Do you want to update all data sources? [Y/n] 
Updating source data/stvnlnBlack from https://raw.githubusercontent.com/stvnlnBlack/hosts/master/data/stvnlnBlack/hosts
Updating source data/adaway.org from https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt
Updating source data/add.2o7Net from https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts
Updating source data/add.Dead from https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Dead/hosts
Updating source data/add.Risk from https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts
Updating source data/add.Spam from https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts
Updating source data/Adguard-cname from https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/combined_disguised_trackers_justdomains.txt
Updating source data/Badd-Boyz-Hosts from https://raw.githubusercontent.com/mitchellkrogza/Badd-Boyz-Hosts/master/hosts
Updating source data/hostsVN from https://raw.githubusercontent.com/bigdargon/hostsVN/master/option/hosts-VN
Updating source data/KADhosts from https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt
Updating source data/MetaMask from https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/hosts.txt
Updating source data/minecraft-hosts from https://raw.githubusercontent.com/jamiemansfield/minecraft-hosts/master/lists/tracking.txt
Updating source data/shady-hosts from https://raw.githubusercontent.com/shreyasminocha/shady-hosts/main/hosts
Updating source data/someonewhocares.org from https://someonewhocares.org/hosts/zero/hosts
Updating source data/tiuxo from https://raw.githubusercontent.com/tiuxo/hosts/master/ads
Updating source data/UncheckyAds from https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts
Updating source data/URLHaus from https://urlhaus.abuse.ch/downloads/hostfile/
Updating source extensions/fakenews from https://raw.githubusercontent.com/marktron/fakenews/master/fakenews
Updating source extensions/gambling from https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/gambling-hosts
Updating source extensions/porn/brijrajparmar27 from https://raw.githubusercontent.com/brijrajparmar27/host-sources/master/Porn/hosts
Updating source extensions/porn/clefspeare13 from https://raw.githubusercontent.com/stvnlnBlack/hosts/master/extensions/porn/clefspeare13/hosts
Updating source extensions/porn/sinfonietta from https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/pornography-hosts
Updating source extensions/porn/sinfonietta-snuff from https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/snuff-hosts
Updating source extensions/porn/tiuxo from https://raw.githubusercontent.com/tiuxo/hosts/master/porn
Updating source extensions/social/sinfonietta from https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/social-hosts
Updating source extensions/social/tiuxo from https://raw.githubusercontent.com/tiuxo/hosts/master/social
Do you want to exclude any domains?
For example, hulu.com video streaming must be able to access its tracking and ad servers in order to play video. [Y/n] n
OK, we'll only exclude domains in the whitelist.
Success! The hosts file has been saved in folder 
It contains 130,449 unique entries.
Do you want to replace your existing hosts file with the newly generated file? [Y/n] 
Replacing /etc/hosts requires root privileges. You might need to enter your password.
SHELL=/bin/zsh
SESSION_MANAGER=local/desktop1:@/tmp/.ICE-unix/1108,unix/desktop1:/tmp/.ICE-unix/1108
COLORTERM=truecolor
XDG_MENU_PREFIX=gnome-
LESS_TERMCAP_se=
LESS_TERMCAP_so=
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
DESKTOP_SESSION=gnome
EDITOR=nano
PWD=/home/stvnl/hosts-3.10.18
LOGNAME=stvnl
XDG_SESSION_DESKTOP=gnome
XDG_SESSION_TYPE=wayland
SYSTEMD_EXEC_PID=1122
_=/usr/bin/env
XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.UIMIP1
MOTD_SHOWN=pam
GDM_LANG=en_AU.UTF-8
HOME=/home/stvnl
USERNAME=stvnl
LANG=en_AU.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.swp=00;90:*.tmp=00;90:*.dpkg-dist=00;90:*.dpkg-old=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:
XDG_CURRENT_DESKTOP=GNOME
VTE_VERSION=6800
WAYLAND_DISPLAY=wayland-0
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/56987c06_950f_4626_8482_28b3a4f2c8f0
GNOME_SETUP_DISPLAY=:1
XDG_SESSION_CLASS=user
TERM=xterm-256color
LESS_TERMCAP_mb=
LESS_TERMCAP_me=
LESS_TERMCAP_md=
USER=stvnl
GNOME_TERMINAL_SERVICE=:1.90
DISPLAY=:0
LESS_TERMCAP_ue=
SHLVL=1
LESS_TERMCAP_us=
PAGER=less
XDG_RUNTIME_DIR=/run/user/1000
XDG_DATA_DIRS=/home/stvnl/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/
PATH=/home/stvnl/.local/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
GDMSESSION=gnome
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
MAIL=/var/spool/mail/stvnl
OLDPWD=/home/stvnl
Attempt to flush the DNS cache? [Y/n] 
Flushing the DNS cache to utilize new hosts file...
Flushing the DNS cache requires administrative privileges. You might need to enter your password.
[sudo] password for stvnl: 
Flushing the DNS cache by restarting NetworkManager.service succeeded
python3 updateHostsFile.py  6.75s user 0.25s system 13% cpu 52.243 total
StevenBlack commented 2 years ago

That's good @573V0.

Closing this now because this is a machine-local issue.

ghost commented 2 years ago

This also happens on another machine of mine using a debian based distro. It may be a machine-local issue but i think your python script could be the cause. I dont know python otherwise i would try to look into it. I wonder if other linux users are having this issue with latest release? Maybe i try an older release and get back to you.

EDIT: tried previous release hosts-3.10.17, no change in behaviour. Anyhow, ill try one more linux machine and forget this. Thanks

ghost commented 2 years ago

Last entry. This is also happening on alpine linux.

Take care.

StevenBlack commented 2 years ago

@573V0 there is only one reason why a file cannot be copied to a folder: permissions.

We can't really help you with that. The user (virtual or otherwise) doing the copy must have permissions to write to that folder.

ghost commented 2 years ago

@StevenBlack

I understand this, but if I am able to manually copy the generated hosts file to /etc/hosts using sudo then I should have the correct permissions, eg; sudo cp hosts /etc/hosts. Just to clarify, I don't use sudo to generate the host file, the only time sudo should be called is when overwriting the hosts file in /etc/hosts. So i do everything as my user until such time as updateHostfile.py asks me for my sudo password so it can have the correct permissions to overwrite the hosts file in /etc/hosts, to clarify even further I do not do sudo python3 updateHostfile.py that is not what your instructions indicate. If i need to manually copy over the generated hosts file to /etc/hosts im happy to do that, but your python script says it will do it but it does not.

EDIT: I have also used the replace flag but this does not work either.

Your active hosts file is not replaced unless you include the --replace flag

DPTJKKVH commented 2 years ago

Hey @StevenBlack I'm on Ubuntu 22.04 and I use your project for years via the same method of pulling and merging the code changes every Monday and having a daily script running via crontab with root permissions to pull list updates and replace the hosts file. July 17th (Sunday) is the last time the replacement of the hots file properly worked for me, no matter if I run the updateHostsFile.py manually or via crontab (both with root permissions). The issue coincided with the updateHostsFile.py producing a printenv, exactly how @573V0 explained it. So the issue must be in one of the code changes I pulled and merged on Monday, July 18th. This limits the window to any change made between July 11th and July 18th.

I can perfectly reproduce the issue with my second machine where I fortunately have a backup of the old code. Running the old code, I have no issues to update the lists and replace the hosts file. The moment I pull and merge the code changes from your project I experience the exact same issues I have on my main machine, which is identical to @573V0 issues.

So I implore you, this is not a single user having permission issues or not being knowledgeable enough to run your script properly. There must be a breaking change in the code somewhere between July 11th and July 18th.

DPTJKKVH commented 2 years ago

@StevenBlack I identified the change that causes the breakage for Linux! I marked the line with a comment here: https://github.com/StevenBlack/hosts/commit/6caf8a5244a75b9d7f7b679dc467bee0130162de#r79345315

Reverting the line back to subprocess.run(SUDO + ["cp", filename, target_file], check=True) results in no printenv being produced and the hosts file being replaced properly.

Since the change is titled now really fix windows but you are making a change to the Linux code in that line this might have been a simple mixup. You might want to check if you are missing a change to some Windows specific code.

DPTJKKVH commented 2 years ago

Pull request here for your convenience: https://github.com/StevenBlack/hosts/pull/2022

ghost commented 2 years ago

thanks for chiming in @DPTJKKVH I looked at that line of code too, i just didnt know what to do with it.

gprestes commented 2 years ago

Same issue happens for MacOS. Created this PR to fix it.