<?php
 
class NP_BasicAuth extends NucleusPlugin {
 
   function getName() {
      return 'Basic Auth';
   }
 
   function getAuthor()  {
      return 'Andy';
   }
 
   function getURL()
   {
      return 'http://www.matsubarafamily.com/blog/';
   }
 
   function getVersion() {
      return '0.1';
   }
 
   function getDescription() {
      return 'restrict viewing item page using BASIC authentication.';
   }
 
   function supportsFeature($what) {
      switch($what){
         case 'SqlTablePrefix':
            return 1;
         default:
            return 0;
      }
   }
 
   function getMinNucleusVersion() {
      return 320;
   }
 
   function getEventList() { return array('PreSkinParse'); }
 
   function install() {
      $this->createItemOption('auth_needed','Authentication Needed','yesno','no');
      $this->createItemOption('username','User Name','text','');
      $this->createItemOption('password', 'Password','password','');
      $this->createOption('defaultname', 'Default User Name', 'text', 'user');
      $this->createOption('defaultpass', 'Default Password', 'password', 'pass');
   }
 
 
   function event_PreSkinParse(&$data) {
      global $itemid;
      if ($data['type'] != 'item') return;
      if ($this->getItemOption($itemid, 'auth_needed') == "no") return;
      if (!($user = $this->getItemOption($itemid, 'username'))) {
         $user = $this->getOption('defaultname');
      }
      if (!($pass = $this->getItemOption($itemid, 'password'))) {
         $pass = $this->getOption('defaultpass');
      }
      while (($_SERVER['PHP_AUTH_USER'] != $user) || ($_SERVER['PHP_AUTH_PW'] != $pass)) {
         header('WWW-Authenticate: Basic realm="auth"');
         header('HTTP/1.0 401 Unauthorized');
         echo "To view this item, you need correct ID/Password\n";
         exit;
      }
   }
 
}
?>
np_basicauth_code.txt · Last modified: 2006/07/05 13:03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki