Giter VIP home page Giter VIP logo

hostctl's Introduction

Tests GitHub Release Go Report Card License All Contributors Coverage Mentioned in Awesome Go

hostctl

Your dev tool to manage /etc/hosts like a pro!

This tool gives you more control over the use of your hosts file. You can have multiple profiles and switch them on/off as you need.

Why?

It is a tedious task to handle the hosts file by editing manually. With this tool you can automate some aspects to do it cleaner and quick.

Features

  • Manage groups of host names by profile.
  • Enable/disable complete profiles.
  • Add/remove groups of host names.
  • Add profiles directly from a text file that you can add to your git repo or any VCS.
  • Sync a profile with Docker or Docker Compose containers.

Documentation

You can read about how to use this tool here:

Or you can start directly on the Docs homepage.

Sample Usage

sample usage

Installation

Go to release page and download the binary you prefer.

Or read about other installation methods on different systems here

Linux/Mac/Windows and permissions

The tool recognize your system and use the right hosts file, it will use /etc/hosts on Linux/Mac and C:/Windows/System32/Drivers/etc/hosts on Windows.

SUDO/ADMIN: You will need permissions for any action that modify hosts file, add sudo to the commands below when needed. If you are on windows, make sure you run it as administrator.

WARNING: it should work on any system. It's tested on Ubuntu and Windows 10. If you can confirm it works on other system, please let me know here.

Contributing

Be sure to read CONTRIBUTING and CODE_OF_CONDUCT.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


George Kontridze

πŸ’»

Pacodes

⚠️ πŸ’»

BarbUk

πŸ’» πŸ€”

Brett Mack

πŸ’»

Peter Thaleikis

πŸ’» πŸ“–

simohamed

πŸ€” πŸ’»

Fabian Grutschus

πŸ€”

Pablo Caderno

πŸ’»

Josh Brown

πŸ›

Lukas M

πŸ› πŸ€”

This project follows the all-contributors specification. Contributions of any kind welcome!

Author(s)

If you like this tool and think is worth it, you can invite me a coffee:

paypal.me/guumaster ko-fi.com/guumaster

LICENSE

MIT license

hostctl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hostctl's Issues

Remove domains command

Proposing add subcommands:

  • remove domains [-p profile] [-all] - will remove by name in profile (-p) or hosts file (-all)
  • remove ip [-p profile] [-all] - will remove by IP in profile (-p) or hosts file (-all)

fix aur-publish step

Something change on aur publish step and it is broken.

Check how to fix it. Here are the logs from the latest build:
https://github.com/guumaster/hostctl/runs/891503728?check_suite_focus=true

"
---------------- AUR Package version hostctl/1.0.12 ----------------
# aur.archlinux.org:22 SSH-2.0-OpenSSH_8.3
---------------- ssh://[email protected]/hostctl.git ----------------
Cloning into 'hostctl'...
Warning: Permanently added the ED25519 host key for IP address '5.9.250.164' to the list of known hosts.
------------- BUILDING PKG hostctl ----------------
==> Making package: hostctl 1.0.12-2 (Mon 20 Jul 2020 08:15:26 PM UTC)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Found v1.0.12.tar.gz
==> Validating source files with sha256sums...

Error on enable command

version: 0.10.0 (I think. Hence #42)

I tried status, toggle, set, and disable, they all work fine, except enable that outputs error on use (still works though).

$ sudo hc enable -p hn --raw
PROFILE STATUS  IP              DOMAIN
hn      on      127.0.0.1       news.ycombinator.com
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5631518b9ac8]

goroutine 1 [running]:
github.com/spf13/cobra.(*Command).Name(0x0, 0xa, 0xc0005adcf8)
        github.com/spf13/cobra@v0.0.7/command.go:1251 +0x28
github.com/guumaster/hostctl/cmd.glob..func11(0xc00011ab00, 0xc0003445d0, 0x0, 0x3, 0x0, 0x563151ad80da, 0x7fff953509de)
        github.com/guumaster/hostctl/cmd/post_action.go:35 +0x1e0
github.com/guumaster/hostctl/cmd.init.3.func3(0xc00011ab00, 0xc0003445d0, 0x0, 0x3, 0x0, 0x0)
        github.com/guumaster/hostctl/cmd/enable.go:50 +0x5e
github.com/spf13/cobra.(*Command).execute(0xc00011ab00, 0xc000344540, 0x3, 0x3, 0xc00011ab00, 0xc000344540)
        github.com/spf13/cobra@v0.0.7/command.go:845 +0x3ef
github.com/spf13/cobra.(*Command).ExecuteC(0x563151f01100, 0x0, 0x0, 0x563100000000)
        github.com/spf13/cobra@v0.0.7/command.go:943 +0x319
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v0.0.7/command.go:883
github.com/guumaster/hostctl/cmd.Execute()
        github.com/guumaster/hostctl/cmd/root.go:42 +0x2f
main.main()
        github.com/guumaster/hostctl/main.go:10 +0x22

Wait Flag

Is your feature request related to a problem? Please describe.
blocking websites to work, I sometimes need to use a website for a limited amount of time to not sidetrack. Do you think it would be useful to add a time flag?

Describe the solution you'd like

$ hostctl enable -p youtube -t 15 # enable youtube profile for 15 minutes

Describe alternatives you've considered

$ hostcl enable -p youtube && sleep 900 && hostctl disable -p youtube

`--only` for `disable`

for my use case, I find myself wanting to enable all profiles except one.
Could we have a hostctl disable awesome --only?

Installation via brew

Hi, to remain in line with other projects that provide a brew tap might I suggest creating another repo called homebrew-tap. This would allow you a central point for all your homebrew formulae (I hope you go on to create more projects, this one is great) as well as allowing users to install hostctl as well as subscribe to your tap with a single command brew install guumaster/tap/hostctl. This is the same way goreleaser does it (Gotta love a tool that "eats its own dogfood").

more render targets

Maybe is useful to render output as different targets like json, yaml, html and markdown.

Changing tablewriter to go-pretty could help.

Add an UI

I'm thinking on adding a simple UI. Maybe some Vue frontend and a web server to perform the updates.

Or maybe something more like k9s

Not sure if this should be splitted to a separate binary and keep it separate from core functionality.

Add `--watch` flag

Add --watch flag to sync commands to monitor and react to changes on the origin system (docker, kubernetes, etc).

panic when adding from a file that doesn't exists

Describe the bug
If you try to add a profile from a file that doesn't exists, it panic.

Expected behavior

Check for the source file and fail more gracefully on missing file.

Additional context
Error:

hostctl add -p test --from .etchosts
Using hosts file: /etc/hosts
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x556854311397]

goroutine 1 [running]:
github.com/guumaster/hostctl/pkg/host.add(0x0, 0xc000133ca0, 0x0, 0x5568543c8ae0)
	github.com/guumaster/hostctl/pkg/host/add.go:75 +0xb7
github.com/guumaster/hostctl/pkg/host.AddFromFile(0xc000133d50, 0x55685431bb29, 0x7)
	github.com/guumaster/hostctl/pkg/host/add.go:39 +0xc3
github.com/guumaster/hostctl/cmd.glob..func1(0x5568544f7cc0, 0xc000068300, 0x0, 0x4, 0x0, 0x0)
	github.com/guumaster/hostctl/cmd/add.go:21 +0x17c
github.com/spf13/cobra.(*Command).execute(0x5568544f7cc0, 0xc0000682c0, 0x4, 0x4, 0x5568544f7cc0, 0xc0000682c0)
	github.com/spf13/[email protected]/command.go:840 +0x455
github.com/spf13/cobra.(*Command).ExecuteC(0x5568544f99a0, 0x0, 0x0, 0x556800000000)
	github.com/spf13/[email protected]/command.go:945 +0x319
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:885
github.com/guumaster/hostctl/cmd.Execute()
	github.com/guumaster/hostctl/cmd/root.go:35 +0x2f
main.main()
	github.com/guumaster/hostctl/main.go:10 +0x22

v1.1.1 - Access Denied on Windows 10 while running as administrator

Running a command prompt as admin and getting access denied error.

Using latest v1.1.1

My local account is in the Administrators group.

This is due to running your utility from a non-C drive; which fails. If I run it from the c:\ drive it succeeds. This is long standing bug in the GO language related to paths that is causing this. I posted about this a long time ago on another open source project. If I can find that post I'll add it here.

image

Adding a new profile: Error: unknown profile name

Describe the bug

Using the last version (binary or compiled), I can no longer add a new profile.

To Reproduce

With no profile named test

$ sudo hostctl add domains test test.com
Error: unknown profile name

Expected behavior

Domain test.com is added in a newly created test profile

System (please complete the following information):

  • OS: Linux
  • Version:
$ hostctl --version
hostctl version 1.0.5

simple logo

tools with logo are better than tools without it. I have less than zero skills to do it.

If anyone have some idea of a minimal and simple logo that can match with the features of this CLI tool, is welcome to create a PR and add ideas, images or designs.

Docker integration

Any ideas how to integrate this with Docker?

I need something that recognizes when a container starts and add then a hostname to the hosts file with the ip of the container (maybe the project name from docker-compose). Would be fantastic to automate, so I don’t have to remember all the service names and there port redirections.

hostctl adds entries for the same domain + ip

Describe the bug
hostctl appears to not be idempotent when it adds entries for the same domain + ip when run multiple times.

To Reproduce
Run this command multiple times (--uniq doesn't seem to make a difference)

touch /tmp/test-hosts; hostctl add domains test domain1 --ip 127.0.0.1 --host-file /tmp/test-hosts

Current behavior

##################################################################
# Content under this line is handled by hostctl. DO NOT EDIT.
##################################################################

# profile.on test
127.0.0.1 domain1
127.0.0.1 domain1
127.0.0.1 domain1
127.0.0.1 domain1
# end

Expected behavior
When running the command above, /tmp/test-hosts should only contain one uniq entry.

Example of what it should look like

##################################################################
# Content under this line is handled by hostctl. DO NOT EDIT.
##################################################################

# profile.on test
127.0.0.1 domain1
# end

System (please complete the following information):

  • OS: Mac
  • Version: 10.15.7 (19H15)

Additional context

hostctl --version
hostctl version 1.0.14

Comments turn into entries

Describe the bug

In this hosts file you can find the following line:

# 0.0.0.0  www.youtube-nocookie.com #[affects various videos]

When you add the file with hostctl, it becomes:

0.0.0.0 www.youtube-nocookie.com
0.0.0.0 #[affects
0.0.0.0 various
0.0.0.0 videos]

To Reproduce

Download the list and add it via hostctl add

Expected behavior
Comments should not turn into entries.
They should be either stripped altogether or preserved.

System (please complete the following information):

  • OS: archlinux
  • hostctl version 1.0.14 from AUR

New features

Thinks I'd like to add:

  • hostctl sync k8s -n namespace -p profile
  • hostctl sync minikube -p profile
  • hostctl sync docker -p profile
  • hostctl sync docker-compose -f docker-compose.yml -p profile

Also with a --watch flag to monitor and react to changes

Alphabetic sorting of profiles

hostctl status gives a different sorting each time it's invoked. Could you enforce an alphabetic sorting?

This would also make names with prefixes somewhat useful if you have a good number of profiles.

Acces denied as admin on win10

hostctl set -p mdserver --from c:\script\hostctl\mdserver_hosts.txt
Using hosts file: C:\Windows\System32\Drivers\etc\hosts
Error: truncate C:\Windows\System32\Drivers\etc\hosts: Access is denied.

Profile Groups

Is your feature request related to a problem? Please describe.
I use /etc/hosts to block websites during work. for example, I block youtube, twitter, ycombinator, etc. I would love to have profiles for individual websites (e.g., sudo hostctl enable -p youtube) but at the same time have a group of profiles that I can manipulate all at once (e.g., sudo hostctl disable -p socialmedia).

Describe the solution you'd like

$ hostctl group socialmedia -p youtube twitter linkedin
$ hostctl disable -p socialmedia # disable all social media
$ hostcl enable -p youtube          # except for youtube

Split binary into plugins

Maybe it's a good idea to split the program in smaller components, example:

  • hostctl (core)
  • hostctl-docker
  • hostctl-k8s
  • hostctl-ui (or web)

A kind of plugin system or so. Not sure if there is any example on Go to checkout.

i really want to use this by yum or dnf.

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

i really want to use this by yum or dnf ( Centos )
may i ask this package manager repo. i wish that. my god~

Profiles as default argument in commands

Why not just have profiles the default argument in commands?
Instead of hostctl toggle -p awesome you'd have hostctl toggle awesome? (with -p still working for backward compatibility)

I get that the add command, for instance, can be convoluted and a flag (-p) to clearly define profile name is a healthy pattern. But profile as a default argument is straightforward for most other commands.

image

What do you think?

Version flag

$ hostctl -v || hostctl --version
hostctl 0.10.0

or add it to the output of the help command?

CLI autocompletion

Create commands and subcommands to enable autocompletion:

hostctl completion bash
hostctl completion zsh

Minimal Output

Is your feature request related to a problem? Please describe.
I use /etc/hosts to block websites during work and it exceeds 20,000 lines. When listing profiles, it all gets outputted.

Describe the solution you'd like
I would love there to be a minified output flag (through persistent configuration? hostctl config minimal)

Describe alternatives you've considered
outputting to /dev/null, but I want to see enabled/disabled profiles.

Unable to handle big profile files

Describe the bug
I have a profile file with 23,000 lines that used to work just fine. With 1.0.0 (and now 1.0.2), hostctl no longer works.
hostctl status didn't work. I removed all profiles to start fresh and the big file would not be added --from.

To Reproduce
Steps to reproduce the behavior:

  1. sudo hostctl add nsfw --from https://github.com/smhmd/dotfiles/blob/master/.config/hosts/nsfw -q
    (there's an idea. Profile files --from URLs.)

Expected behavior
hostctl to load the profile

System
OS: Linux

Additional context
Loading that profile worked in 0.10.x.

Improve documentation guides

In order to have a very thorough documentation, here you have an explanation on how the docs are automatically generated and published, and how you can contribute to improve it.

Where to create/modify guides?

Markdown docs can be found on the Hugo site folder on the docs branch.

The path for the guides is: docs/content/docs/guides, there you can modify or add new content.

Automatic CLI usage docs

On the same branch there is a directory where all content is generated automatically with a cobra feature to inspect and generate markdown.
So everything inside docs/content/docs/cli-usage is auto generated and will be overwritten on each run of the workflow.

Don't manually edit content there.

What to add?

  • Anything that you consider useful for other users.

  • Things you struggled with and found out how to solve.

  • asciinema records that show how to use any feature. see how to below.

  • Whatever you think is missing to better learn to use hostctl.

How to add content?

  • First open a new issue to show your intentions about what would you like to write, that way the community can add to the discussion and help.

  • Then fork it and checkout the docs branch.

  • Create/add/modify any content you like.

  • And finally open a PR to the docs branch

  • (optional pro tip) If you add the text "Closes #999" on one of your commits with issue number you opened on the first step, it would be automatically closed when the PR is merged.

How to add asciinema casts

  • Check asciinema Getting started if you don't know how to record.
  • Once you have a cast file, ex: my_record.cast, add it to docs/static/my_record.cast directory on your PR.
  • Modify a markdown file to include the player and your cast as the following example:
---
title: Some guide with a player
description: A great guide with an asciinema player
+asciinema: true
---

Some content... 

+{{<asciinema key="my_record.cast" >}}

...More content... 

Discussion: Interactive selection

Does the framework you're using support interactivity of this sort?

interactive

I could imagine a heavy use of hostctl profiles would call for such an interface.

Add the ability to manage entries added from other applications

Is your feature request related to a problem? Please describe.
This is a great tool, as the hosts file can be a b**ch to organize! The issue I am having is that I use tools to add entries to the hosts file and (maybe I simply do not understand the tool) would like to somehow manage these entries easily. I use tools like Spybot Anti-Beacon which automatically add entries specifically to the default "hosts" file.

Describe the solution you'd like
Would like to somehow combine files into one hosts file. As stated, maybe I don't fully understand how it works. If I were to divide my hosts file into profiles, then use Anti-Beacon to update its entries, I would like to be able to add all of those new entries to the "Anti-Beacon" profile basically. If this is possible already, then disregard this.

Describe alternatives you've considered
What I've considered, as hostctl (to my knowledge) can target other hosts files easily, is to have several files for each tool and use hostctl to combine these into a "master" hosts file. This is cumbersome as it involves the swapping of hosts files (e.g if I have all Anti-Beacon entries in a 'hosts.beacon' file, when I want to update these entries I have to rename it to "hosts" and then use the tool to update the entries, rename it again to 'hosts.beacon' and use hostctl to import the new entries).

Additional context
The documentation for this tool seems (to me) inadequate as I am not entirely sure how to exactly import entries to the hosts file. I just now found how to add profiles, as the set command is not part of the "CLI Usage" documentation for some reason...

Batch profile managment

hostctl enable -p awesome amazing sublime would only enable awesome. Is there a way to batch manage profiles?

Multiple "DO NOT EDIT" comments in etc/hosts

Describe the bug
Every time when run add/replace commands hostctl is adding 1 more header

##################################################################
# Content under this line is handled by hostctl. DO NOT EDIT.
##################################################################

To Reproduce
Steps to reproduce the behavior:
just run hostctl replace -f /path/of/some/project/repo/.etchosts few times

Expected behavior
don't add header if it's already exists

Test different installations

There is a Github Action workflow that automatically generates packages for different systems. I can only test on Linux and Windows, so I need help to test all options:

  • Linux/Mac/Window binary
  • deb package
  • AUR package
  • scoop
  • Brew tap
  • snap (pending add feature to work properly)

Please add comments if you have tested it any version of this list. Thanks!

UPDATE: Finally the snap build is approved to have proper permissions πŸš€ !

Roadmap to v1.0

The current state of the CLI and module is kind of beta(ish), is subject to small/big changes as I or the community finds it uses, requests features and I learn better ways of implementing the CLI with cobra.

Here are things that should be finished before reaching an stable version tag v1.0.0:

  • Add a decent amount code coverage of all files in pkg directory. #48
  • Refactor pkg code to expose a better API to use as module. #48
  • Change semantics to have profiles as arguments instead of flag. #37 #48
  • Allow to manage multiple profiles at once. Ex: hostctl disable profile1 profile2... #48
  • Add mutex to save file to avoid concurrency issues. #48

NOTE: The issue is locked just to keep better track of the features that would be added. In anyways this mean you can't participate on deciding new features.
I encourage you to open new issues with any idea you have.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.