arendruni / homebridge-pihole

Pi-hole switch for Homebridge
https://www.npmjs.com/package/homebridge-pihole
MIT License
159 stars 10 forks source link

Ability to toggle a block rule #33

Open jacklawry opened 3 years ago

jacklawry commented 3 years ago

Is there any way to allow a switch to toggle a block url or ideally a group of rules?

It would be so useful to be able to block a set list of urls via a toggle (that could then be set via a timer if required) so I could easily block say Netflix, prime, YouTube etc while the kids should be doing homeschooling/homework etc.

arendruni commented 3 years ago

Hi @jacklawry!

This could be a real extension of this plugin functionality which is now limited to only disable/enable the entire Pi-hole. I tried to look which requests the admin page makes when disabling a list and I couldn’t find a hint on where to add timer as a param in the request, though there should be an internal timeout inside the plugin to handle this.

I don’t have so much time to go any further in this feature now so if you want to try and integrate it, PR are always welcome!

wawoodwa commented 3 years ago

I am looking for the same thing! I manage mine based on groups that are enabled or disabled. I currently do it via a crontab. However, in looking at the code, the api.php and api_FTL.php doesn't appear to expose the more functional parts of the Pi-hole. Those files, if you wish to look at them, are in /var/www/html/admin. There is an api_db.php there, but it isn't included in the api.php, so you have to call it specifically to access any of its features.

But in looking in /var/www/html/admin/scripts/pi-hole/php/groups.php, it isn't a simple edit_group call. It requires all of the information on it (id, name, description, and enabled). It also requires a login token, unless $api is set.

I am going to look at it some more.

wawoodwa commented 3 years ago

Ok, so I wrote some code for Pi-hole to be able to control groups via the API. I am going to submit a PR for it to see if they would add it in the next rev. I guess now I need to look at this code and see if I can add in a switch for it to be controlled via the plug-in.

jacklawry commented 3 years ago

At the moment I am able to control all the blocks I need (mainly YouTube) via ssh rules that I can enable and disable via some saved logic in the Shortcuts app on my phone but this would be loads better if it can be done.

wawoodwa commented 3 years ago

I think I am still going to look at this. I did submit the API change to Pi-hole FTL. Will see if it gets incorporated. In the mean time I will work on a fork of this to see if I can extend it based on the assumption they will accept it.

wawoodwa commented 3 years ago

@arendruni I am thinking of extending your plug-in to include multiple switches to control groups. I will fork it and see what I can come up with.

arendruni commented 3 years ago

Do you already know what needs to be changed to add this new feature?

wawoodwa commented 3 years ago

I have an idea, but nothing in stone. I am thinking that the plugin becomes a platform plugin, instead of multiple accessories that have to be independently configured. The main accessory can be turned on or off (enable / disable) and then other accessories representing groups that can be independently controlled.

wawoodwa commented 3 years ago

Ok, quick update. Pi-hole revved and didn't include my code. They forgot to review it before the update. I reached out to them and they apologized. However, they believe they are very close to 6.0, which has the functionality we need to make this concept work.

So, going to put this on the back burner momentarily until they get 6.0 out.