ak1001 Posted June 21, 2021 Share Posted June 21, 2021 Is it possible to restrict access to /admin page to only specific ip addresses? like in apache conf for example : <Location /> Require ip 192.168.0.0/24 </Location> ? Link to comment Share on other sites More sharing options...
Robin S Posted June 23, 2021 Share Posted June 23, 2021 You could edit /site/templates/admin.php so that it looks something like this: // Get the user's IP address $ip = $session->getIP(); // Define the allowed IP addresses $allowed_ips = ['111.111.111.111', '222.222.222.222']; // Check user's IP is allowed if(!in_array($ip, $allowed_ips)) { return 'Access denied'; } require($config->paths->adminTemplates . 'controller.php'); 2 Link to comment Share on other sites More sharing options...
howdytom Posted December 2, 2023 Share Posted December 2, 2023 @Robin S Thanks for sharing. Using the code above throws an unknown error when I login into ProcessWire. Is it still valid for ProcessWire 3.0.229? Fatal Error: Cannot redeclare _hookSessionRedirectModal() (previously declared in wire/core/admin.php:36) (line 36 of wire/core/admin.php) Link to comment Share on other sites More sharing options...
Robin S Posted December 2, 2023 Share Posted December 2, 2023 On 12/2/2023 at 9:05 PM, howdytom said: Using the code above throws an unknown error when I login into ProcessWire. Is it still valid for ProcessWire 3.0.229? Expand There isn't anything in that code that should cause an error in any version of PW. Just a guess, but given that the error message originates from /wire/core/admin.php make sure you have edited /site/templates/admin.php and not /wire/core/admin.php by mistake. 1 Link to comment Share on other sites More sharing options...
howdytom Posted December 2, 2023 Share Posted December 2, 2023 Yeah, this is what I had in mind too. I never touched /wire/core/admin.php. I have edited /site/templates/admin.php. When I open the ProcessWire Admin url a Internal Error shows up below the input fields. It is happening with PHP 7 and PHP 8.2 Link to comment Share on other sites More sharing options...
Robin S Posted December 2, 2023 Share Posted December 2, 2023 @howdytom, I think I see where the confusion comes in. In more recent PW versions the require() line in /site/templates/admin.php is... require($config->paths->core . "admin.php"); ...whereas in earlier versions it is... require($config->paths->adminTemplates . 'controller.php'); These both end up doing the same thing so you should only have one require() in the file. The functional part of my code is this bit: // Get the user's IP address $ip = $session->getIP(); // Define the allowed IP addresses $allowed_ips = ['111.111.111.111', '222.222.222.222']; // Check user's IP is allowed if(!in_array($ip, $allowed_ips)) { return 'Access denied'; } I only include the require() line to indicate that my code needs to be inserted above the existing contents of /site/templates/admin.php 1 Link to comment Share on other sites More sharing options...
howdytom Posted December 3, 2023 Share Posted December 3, 2023 Indeed, you are right. FANTASTIC, it is working now. Thank you so much! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now