Problem/Motivation
In some cases, there are situations where you want to exclude looking up some IP address to reduce load or prevent excessive requests. Such IPs can be A monitoring service that pings the site. An internal IP of a company
Proposed resolution
It would be nice to add some a configuration text area in Smart IP config page, to list IPs to exclude.
Those IPs will then be skipped from being queried.
User interface changes
Add configuration text area in /admin/config/people/smart_ip configuration page.
API changes
TBD, but probably minimal or none.
We only need to add an if statement in geolocateUser() function to skip looking up those IPs.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | provide-config-to-exclude-looking-up-specific-ips-3107344-8.patch | 2.33 KB | omar alahmed |
| #4 | provide-config-to-exclude-looking-up-specific-ips-3107344-4.patch | 3.47 KB | milosr |
Comments
Comment #2
mohammed j. razemComment #3
arpeggio commentedI'll work on this feature on my free time. Of course, patches are always welcome. Thank you for the suggestion.
Comment #4
milosr commentedComment #5
mohammed j. razemHere's another patch (based on what @MilosR did.
It includes minor naming changes, and some missing methods such as actually saving the form config.
I also moved the check of excluded IPs to
query(). However, I do not think this is the right way. But hoping this can give someone a head start to get the feature finalized.Comment #6
omar alahmedReplace array_search with in_array in #5 as array_search returns the index of the found IP so if it was the first index will be 0 which means FALSE and won't match the condition! But in_array returns TRUE if IP is found in the array, FALSE otherwise.
Comment #7
mohammed j. razemIn some cases, $data array is not set. For example when IP detection is removed from certain roles.
This will result in a PHP Notice: Undefined variable: data in Drupal\smart_ip\SmartIp::query() (line 36 of smart_ip/src/SmartIp.php)
This needs an isset() check on the $data variable before even querying the $excluded_ips config.
Comment #8
omar alahmedThe following patch fixes the notice.
Comment #11
arpeggio commentedI have improved the checking of excluded IPs logic and changed the comma delimiter to new line (this is to be consistent with the allowed_pages form). Thanks to all.