Heine

  • home
  • drupal
  • drupal core commits
  • about
Home › Drupal

Cache or PHP-info is none of your business

Heine — Sat, 24/02/2007 - 09:41

I've a few extra scripts in the webroot of several sites to provide me with server information when I need it. These scripts tend to provide too much information to just anyone. Here's how you can quickly limit access to the Drupal admin user (the first user created on the site).

Create a file restrict.php. The example assumes all files (restrict.php, info.php and apc.php) are in the Drupal root directory. You need to adapt the include paths if you save the files elsewhere. You can make the access criteria as baroque as you need; the example simply checks on user id.

// restrict.php
// Check whether the users is the Drupal admin user.  Display an access denied page and exit if not.
require_once("./includes/bootstrap.inc");
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if ($user->uid != 1) {
  drupal_maintenance_theme();
  drupal_set_title('Access denied');
  print theme('maintenance_page', '<p>Access denied. You are not authorized to access this page.</p>');
  exit();
}

You can, by simply including restrict.php, limit access to phpinfo ...

// Restrict access to info.php
require_once('./restrict.php');
phpinfo();

... or apc.php.

// ...
# Tie in to Drupal access control.
# Prevent non-uid 1 users from accessing this page.
require_once('./restrict.php');

$VERSION='$Id: apc.php,v 3.51 2005/04/02 02:07:41 rasmus Exp $';
//...

No votes yet
  • Drupal
  • PHP

I think

Anonymous (not verified) — Sun, 22/04/2007 - 00:32

don't you need global $user; at the beginning?

  • reply

Scope

Heine — Thu, 03/05/2007 - 14:58

No, as we're mucking in the global scope, $user is already available.

  • reply

changelog

bertboerland (not verified) — Sat, 05/04/2008 - 17:38

so we obfuscate HTTP headers on d.o (just apache and php, no version information) and we hide phpinfo. but having a CHANGELOG.txt in the docroot is no bad? I dont get it Heine, and yes this s one of the 100 things I dont agree with "the rest" but learned to deal with it :)

  • reply

Post new comment

I reserve the right to edit any comment submitted to the site. If your comment contains flaming, advertisements, or simply too many spelling errors (leet speak), it may never appear.
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <as>, <as3>, <csharp>, <diff>, <drupal5>, <drupal6>, <html>, <js>, <mysql>, <php>, <phpbrief>, <python>, <sql>, <plain>, <xml>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

Recent posts

  • Planet Drupal past and current
  • Help! - Cannot access a global variable.
  • Why is my module's update hook not listed on update.php's selection form?
  • How do I add a class to a link generated with l()
  • ZeroDayScan - Full path disclosure bug in Drupal 6.16 (0day)
more

Security reviews

  • Afraid custom code makes your site vulnerable?
  • You don't really trust that module you just downloaded from Drupal.org?

Sleep better after a security review.

Tags

Captcha CSRF Drupal embed Input Format modx OpenID Performance Planet Drupal rants Security Varnish
more tags
  • home
  • drupal
  • drupal core commits
  • about

Copyright © 2010 by Heine Deelstra. All rights reserved.