Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update add.php #1360

Closed
wants to merge 3 commits into from
Closed

Update add.php #1360

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 23, 2020

Added removal from blacklist if adding to whitelist
Added removal from whitelist if we add to the blacklist
Added removal option from both lists black & white option "none"

Added removal from blacklist if adding to whitelist
Added removal from whitelist if we add to the blacklist
Added removal option from both lists option "none"
scripts/pi-hole/php/add.php Outdated Show resolved Hide resolved
scripts/pi-hole/php/add.php Outdated Show resolved Hide resolved
Code readability has been improved
@PromoFaux
Copy link
Member

I was looking over this PR on saturday, then life kind of got in the way. I am not sure if the change is a necessary one, at least in the case of removing from one list when adding to the other.

We already made a change in database.php which does REPLACE INTO the list, so it will automatically switch it from one to the other:

https://github.com/pi-hole/AdminLTE/blob/devel/scripts/pi-hole/php/database.php#L139

@ghost
Copy link
Author

ghost commented May 25, 2020

If this has been implemented at the database level, that's fine. Have you tested it on sample requests?

@PromoFaux
Copy link
Member

It's implemented in the method add_to_table (on the dev branch at least, not master currently).

All I'm saying is that a call to remove_from_table before calling add_to_table is redundant because of the REPLACE INTO. Say you want to whitelist domain.com, and it is already on the blacklist, what REPLACE INTO is effectively saying is:

Insert domain.com to whitelist, and if domain.com is already there as a blacklist item, change the list type so that it is on the whitelist now.

This has been tested from the web interface:

blackwhitelist

@ghost
Copy link
Author

ghost commented May 25, 2020

I understand it makes sense. In that case, it could be useful to reset (cleaning the domain from all lists). I tried to solve this by adding "none"

@PromoFaux
Copy link
Member

Yeah, removing from probably makes sense. I believe add.php and database.php have only stayed around for interaction with the query log, as most other functionality (including removing from lists) has been created in groups.php (@DL6ER would know better here, he did this part)

@ghost
Copy link
Author

ghost commented May 25, 2020

I think api is really needed. However, there is probably a need to rewrite.

@PromoFaux
Copy link
Member

For sure. I think for the purposes of this PR, you should be able to get away with only having the case for none, and remove the two remove_from_table lines.

Although, can you test that removing those two lines still has the desired effects for the extension this is for?

@ghost
Copy link
Author

ghost commented May 25, 2020

You mean remove changes for case white and black? Because this is implemented with datebase query?

@PromoFaux
Copy link
Member

Sorry, I wasn't clear! Yes, those two are redundant

@ghost
Copy link
Author

ghost commented May 25, 2020

I can delete but I have no way to check on dev branch (I'm using a docker instance)

@badsgahhl
Copy link

badsgahhl commented May 26, 2020

Hello,

i checked out the dev branch currently. And actually the replace feature which is done in the database.php is doing exactly the correct thing. Adding a domain to the whitelist/blacklist that is already on a list gets replaced. Perfect! But i think the none option is also nice to have, removing a domain from any list.

Duplicate functionality has been removed
@PromoFaux
Copy link
Member

Closing in favour of #1387

Thank you, nonetheless, for your contribution!

@PromoFaux PromoFaux closed this May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants