HTTPAuth.php
author Dan Fuhry <dan@enanocms.org>
Thu, 07 Apr 2016 12:29:38 +0000
changeset 0 29e93991703b
permissions -rw-r--r--
Initial commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     1
<?php
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     2
/**!info**
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     3
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     4
  "Plugin Name"  : "HTTP authentication",
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     5
  "Plugin URI"   : "http://enanocms.org/plugin/httpauth",
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     6
  "Description"  : "Allows authentication to Enano via HTTP authentication.",
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     7
  "Author"       : "Dan Fuhry",
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     8
  "Version"      : "1.0",
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     9
  "Author URI"   : "http://enanocms.org/",
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    10
  "Auth plugin"  : true
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    11
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    12
**!*/
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    13
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    14
/*
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    15
 * HTTP authentication plugin for Enano
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    16
 * (C) 2014 Dan Fuhry
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    17
 *
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    18
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    19
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    20
 *
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    21
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    22
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    23
 */
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    24
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    25
if ( getConfig('http_auth_enable', 0) == 1 )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    26
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    27
  $plugins->attachHook('compile_template', 'http_auth_attach_headers($this);');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    28
  $plugins->attachHook('login_form_html', 'http_auth_login_html();');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    29
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    30
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    31
function http_auth_attach_headers(&$template)
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    32
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    33
    global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    34
    
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    35
    $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/httpauth/login-hook.js"></script>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    36
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    37
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    38
function http_auth_login_html()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    39
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    40
	global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    41
	
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    42
	global $output;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    43
	
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    44
	ob_end_clean();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    45
	
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    46
	$return = ($goto = $paths->getAllParams()) !== '' ? $goto : get_main_page();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    47
	$qs = ( isset($_GET['level']) ) ? 'level=' . $_GET['level'] : '';
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    48
	
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    49
	$uri = makeUrlNS('Special', 'LoginHTTP/' . $return, $qs);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    50
	
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    51
	redirect($uri, '', '', 0);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    52
	exit;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    53
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    54
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    55
// Registration blocking hook
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    56
if ( getConfig('http_auth_disable_local', 0) == 1 )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    57
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    58
  $plugins->attachHook('ucp_register_validate', 'http_auth_reg_block($error);');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    59
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    60
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    61
function http_auth_reg_block(&$error)
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    62
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    63
  $error = 'Registration on this website is disabled because HTTP authentication is configured. Please log in using a valid username and password, and an account will be created for you automatically.';
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    64
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    65
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    66
$plugins->attachHook('session_started', 'http_auth_add_special();');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    67
 
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    68
function http_auth_add_special()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    69
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    70
  register_special_page('LoginHTTP', 'Login with HTTP Authentication', true);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    71
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    72
 
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    73
function page_Special_LoginHTTP()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    74
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    75
  global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    76
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    77
  global $output;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    78
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    79
  if ( isset($_GET['level']) ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    80
    $result = array('result' => 'error');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    81
    
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    82
    if ( !empty($_SERVER['REMOTE_USER']) ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    83
      $level = intval($_GET['level']);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    84
      if ( $level > USER_LEVEL_MEMBER ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    85
        $username = $db->escape(strtolower($_SERVER['REMOTE_USER']));
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    86
        
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    87
        $q = $db->sql_query("SELECT user_id, password, user_level FROM " . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) = '$username';");
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    88
        if ( !$q )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    89
          $db->_die();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    90
        
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    91
        if ( $db->numrows() == 1 ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    92
          $row = $db->fetchrow();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    93
          
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    94
          if ( $row['user_level'] < $level ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    95
            die_friendly('Access denied', '<p>Not permitted to authenticate at this level.</p>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    96
          }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    97
          
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    98
          $session->register_session($row['user_id'], $_SERVER['REMOTE_USER'], $row['password'], $level, $remember);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    99
          
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   100
          $result = array(
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   101
            'result' => 'success',
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   102
            'sid' => $session->sid_super
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   103
            );
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   104
        }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   105
        
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   106
        $db->free_result();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   107
      }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   108
    }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   109
    
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   110
    if ( isset($_GET['ajax']) ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   111
		$output = new Output_Naked;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   112
		header('Content-type: text/javascript');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   113
		echo json_encode($result);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   114
		
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   115
		return;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   116
	}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   117
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   118
  else
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   119
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   120
	  if ( empty($_SERVER['REMOTE_USER']) ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   121
		die_friendly('No HTTP authentication supplied', '<p>This site is configured for HTTP authentication, but none was supplied by the webserver software. Please verify your webserver configuration.</p>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   122
	  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   123
	  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   124
	  http_auth_do_login();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   125
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   126
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   127
  $return = ($goto = $paths->getAllParams()) !== '' ? $goto : get_main_page();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   128
  redirect(makeUrl($return), 'Logged in', 'You have successfully logged in using HTTP authentication. You will be momentarily taken to your destination.', 3);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   129
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   130
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   131
function http_auth_do_login()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   132
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   133
  global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   134
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   135
  $user = $_SERVER['REMOTE_USER'];
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   136
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   137
  $username = $db->escape(strtolower($user));
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   138
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   139
  $q = $db->sql_query("SELECT user_id, password FROM " . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) = '$username';");
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   140
  if ( !$q )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   141
    $db->_die();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   142
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   143
  if ( $db->numrows() < 1 )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   144
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   145
    // This user doesn't exist.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   146
    // Is creating it our job?
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   147
    if ( getConfig('http_auth_disable_local', 0) == 1 )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   148
    {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   149
      // Yep, register him
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   150
      $email = strtolower($user) . '@' . getConfig('http_auth_email_domain', 'localhost');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   151
      $random_pass = md5(microtime() . mt_rand());
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   152
      // load the language
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   153
      $session->register_guest_session();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   154
      $reg_result = $session->create_user($user, $random_pass, $email);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   155
      if ( $reg_result != 'success' )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   156
      {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   157
        // o_O
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   158
        // Registration failed.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   159
        die_friendly('HTTP authentication error', '<p>Your username and password were valid, but there was a problem instanciating your local user account: ' . $reg_result . '.</p>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   160
      }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   161
      // Get user ID
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   162
      $q = $db->sql_query("SELECT user_id, password FROM " . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) = '$username';");
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   163
      if ( !$q )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   164
        $db->_die();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   165
      if ( $db->numrows() < 1 ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   166
        die_friendly('HTTP authentication error', '<p>Your username and password were valid, but there was a problem getting your user ID.</p>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   167
      }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   168
      $row = $db->fetchrow();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   169
      $db->free_result();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   170
      // Quick - lock the account
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   171
      $q = $db->sql_query('UPDATE ' . table_prefix . "users SET password = 'Locked by HTTP auth plugin', password_salt = 'Locked by HTTP auth plugin' WHERE user_id = {$row['user_id']};");
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   172
      if ( !$q )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   173
        $db->_die();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   174
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   175
      $row['password'] = 'Locked by HTTP auth plugin';
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   176
    }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   177
    else
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   178
    {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   179
      // Nope. Just let Enano fail it properly.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   180
      die_friendly('User does not exist', '<p>You\'ve attempted to log in with an account that doesn\'t exist, and the HTTP Authentication plugin is not configured to auto-create new accounts.</p>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   181
    }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   182
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   183
  else
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   184
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   185
    $row = $db->fetchrow();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   186
    $db->free_result();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   187
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   188
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   189
  $session->register_session($row['user_id'], $user, $row['password'], $level, $remember);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   190
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   191
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   192
//
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   193
// ADMIN
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   194
//
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   195
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   196
$plugins->attachHook('session_started', 'http_auth_session_hook();');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   197
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   198
if ( getConfig('http_auth_disable_local', 0) == 1 )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   199
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   200
  $plugins->attachHook('common_post', 'http_auth_tou_hook();');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   201
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   202
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   203
function http_auth_session_hook()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   204
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   205
  global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   206
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   207
  // Register the admin page
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   208
  $paths->addAdminNode('adm_cat_security', 'HTTP Authentication', 'HTTPAuthConfig');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   209
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   210
  // Disable password change
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   211
  if ( getConfig('http_auth_disable_local', 0) == 1 && $session->user_level < USER_LEVEL_ADMIN )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   212
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   213
    $link_text = getConfig('http_auth_password_text', false);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   214
    if ( empty($link_text) )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   215
      $link_text = false;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   216
    $link_url = str_replace('%u', $session->username, getConfig('http_auth_password_url', ''));
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   217
    if ( empty($link_url) )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   218
      $link_url = false;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   219
    $session->disable_password_change($link_url, $link_text);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   220
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   221
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   222
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   223
function clean_server_redirect_vars()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   224
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   225
  foreach ( $_SERVER as $key => $value ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   226
    if ( preg_match($regexp = '/^(REDIRECT_)*/', $key) )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   227
    {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   228
      $newkey = preg_replace($regexp, '', $key);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   229
      if ( !isset($_SERVER[$newkey]) )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   230
      {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   231
        $_SERVER[$newkey] = $value;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   232
      }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   233
    }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   234
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   235
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   236
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   237
function http_auth_tou_hook()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   238
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   239
  global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   240
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   241
  // Are we supposed to fail if no authentication information is presented?
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   242
  // first strip REDIRECT_* from $_SERVER variables
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   243
  clean_server_redirect_vars();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   244
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   245
  if ( getConfig('http_auth_mode', 'guest') === 'noguest' && empty($_SERVER['REMOTE_USER']) )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   246
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   247
    die_friendly('No authentication provided', '<p>This Enano website is configured to require HTTP authentication for all pages, but none was provided by the webserver software. Please check your webserver configuration.</p>');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   248
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   249
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   250
  if ( !empty($_SERVER['REMOTE_USER']) && !$session->user_logged_in && !in_array($paths->page, array('Special:Login', 'Special:LoginHTTP', 'Special:Logout')) ) {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   251
    http_auth_do_login();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   252
    redirect($paths->page, '', '', 0);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   253
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   254
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   255
  // Are we pending TOU acceptance?
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   256
  if ( $session->user_logged_in && !$session->on_critical_page() && trim(getConfig('register_tou', '')) != '' )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   257
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   258
    $q = $db->sql_query('SELECT account_active FROM ' . table_prefix . "users WHERE user_id = {$session->user_id};");
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   259
    if ( !$q )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   260
      $db->_die();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   261
    
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   262
    list($active) = $db->fetchrow_num();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   263
    $db->free_result();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   264
    if ( $active == 1 )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   265
    {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   266
      // Pending TOU accept
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   267
      // Basically, what we do here is force the user to accept the TOU and record it by setting account_active to 2 instead of a 1
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   268
      // A bit of a hack, but hey, it works, at least in 1.1.8.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   269
      // In 1.1.7, it just breaks your whole account, and $session->on_critical_page() is broken in 1.1.7 so you won't even be able
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   270
      // to go the admin CP and re-activate yourself. Good times... erhm, sorry.
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   271
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   272
      if ( isset($_POST['tou_agreed']) && $_POST['tou_agreed'] === 'I accept the terms and conditions displayed on this site' )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   273
      {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   274
        // Accepted
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   275
        $q = $db->sql_query('UPDATE ' . table_prefix . "users SET account_active = 2 WHERE user_id = {$session->user_id};");
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   276
        if ( !$q )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   277
          $db->_die();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   278
        
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   279
        return true;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   280
      }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   281
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   282
      global $output, $lang;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   283
      $output->set_title('Terms of Use');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   284
      $output->header();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   285
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   286
      ?>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   287
      <p>Please read and accept the following terms:</p>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   288
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   289
      <div style="border: 1px solid #000000; height: 300px; width: 60%; clip: rect(0px,auto,auto,0px); overflow: auto; background-color: #FFF; margin: 0 auto; padding: 4px;">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   290
        <?php
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   291
        $terms = getConfig('register_tou', '');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   292
        echo RenderMan::render($terms);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   293
        ?>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   294
      </div>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   295
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   296
      <form method="post">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   297
        <p style="text-align: center;">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   298
          <label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   299
            <input tabindex="7" type="checkbox" name="tou_agreed" value="I accept the terms and conditions displayed on this site" />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   300
            <b><?php echo $lang->get('user_reg_lbl_field_tou'); ?></b>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   301
          </label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   302
        </p>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   303
        <p style="text-align: center;">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   304
          <input type="submit" value="Continue" />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   305
        </p>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   306
      </form>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   307
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   308
      <?php
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   309
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   310
      $output->footer();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   311
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   312
      $db->close();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   313
      exit;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   314
    }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   315
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   316
}
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   317
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   318
function page_Admin_HTTPAuthConfig()
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   319
{
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   320
  // Security check
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   321
  global $db, $session, $paths, $template, $plugins; // Common objects
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   322
  if ( $session->auth_level < USER_LEVEL_ADMIN )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   323
    return false;
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   324
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   325
  if ( isset($_POST['submit']) )
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   326
  {
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   327
    setConfig('http_auth_enable', isset($_POST['http_auth_enable']) ? '1' : '0');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   328
    setConfig('http_auth_disable_local', isset($_POST['http_auth_disable_local']) ? '1' : '0');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   329
    setConfig('http_auth_mode', isset($_POST['http_auth_mode']) && in_array($_POST['http_auth_mode'], array('guest', 'noguest')) ? $_POST['http_auth_mode'] : 'guest');
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   330
    setConfig('http_auth_password_text', $_POST['http_auth_password_text']);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   331
    setConfig('http_auth_password_url', $_POST['http_auth_password_url']);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   332
    setConfig('http_auth_email_domain', $_POST['http_auth_email_domain']);
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   333
    
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   334
    echo '<div class="info-box">Your changes have been saved.</div>';
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   335
  }
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   336
  
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   337
  acp_start_form();
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   338
  ?>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   339
  <div class="tblholder">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   340
    <table border="0" cellspacing="1" cellpadding="4">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   341
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   342
        <th colspan="2">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   343
          HTTP Authentication Configuration
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   344
        </th>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   345
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   346
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   347
      <!-- HTTP enable -->
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   348
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   349
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   350
        <td class="row2" style="width: 50%;">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   351
          Enable HTTP authentication:
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   352
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   353
        <td class="row1" style="width: 50%;">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   354
          <label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   355
            <input type="checkbox" name="http_auth_enable" <?php if ( getConfig('http_auth_enable', 0) ) echo 'checked="checked" '; ?>/>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   356
            Enabled
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   357
          </label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   358
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   359
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   360
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   361
      <!-- Block local auth -->
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   362
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   363
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   364
        <td class="row2">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   365
          Enforce HTTP for single-sign-on:<br />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   366
          <small>Use this option to force HTTP passwords and accounts to be used, regardless of local accounts, except for administrators.</small>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   367
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   368
        <td class="row1">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   369
          <label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   370
            <input type="checkbox" name="http_auth_disable_local" <?php if ( getConfig('http_auth_disable_local', 0) ) echo 'checked="checked" '; ?>/>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   371
            Enabled
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   372
          </label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   373
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   374
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   375
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   376
      <!-- Auth mode -->
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   377
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   378
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   379
        <td class="row2" rowspan="2">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   380
          Guest access mode:<br />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   381
          <small>You can allow guests to browse the site without logging in, and configure your webserver to require authentication only on the login page URL given below. Or, you can require authentication across the whole site. In the latter case, if the webserver fails to provide any authentication state, page loads will fail.</small>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   382
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   383
        <td class="row1">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   384
          <label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   385
            <input type="radio" name="http_auth_mode" value="guest" <?php if ( getConfig('http_auth_mode', 'guest') === 'guest' ) echo 'checked="checked" '; ?>/>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   386
            Guests allowed
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   387
          </label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   388
          
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   389
          <label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   390
            <input type="radio" name="http_auth_mode" value="noguest" <?php if ( getConfig('http_auth_mode', 'guest') === 'noguest' ) echo 'checked="checked" '; ?>/>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   391
            Fail without authentication
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   392
          </label>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   393
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   394
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   395
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   396
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   397
        <td class="row3">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   398
          Login page URL:
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   399
            <input size="45" type="text" readonly="readonly" value="<?php echo htmlspecialchars(preg_replace('/[?&]auth=[a-f0-9]+/', '', makeUrlComplete('Special', 'LoginHTTP'))); ?>" />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   400
          
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   401
          <br />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   402
          <small>Set this URL to require authentication in your webserver's configuration.</small>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   403
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   404
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   405
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   406
      <!-- E-mail domain -->
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   407
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   408
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   409
        <td class="row2">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   410
          E-mail address domain for autoregistered users:<br />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   411
          <small>When a user is automatically registered, this domain will be used as the domain for their e-mail address. This way, activation e-mails will
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   412
                 (ideally) reach the user.</small>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   413
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   414
        <td class="row1">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   415
          <input type="text" name="http_auth_email_domain" value="<?php echo htmlspecialchars(getConfig('http_auth_email_domain', '')); ?>" size="30" />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   416
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   417
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   418
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   419
      <!-- Site password change link -->
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   420
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   421
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   422
        <td class="row2">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   423
          External password management link:<br />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   424
          <small>Enter a URL here to link to from Enano's Change Password page. Leave blank to not display a link. The text "%u" will be replaced with the user's username.</small>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   425
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   426
        <td class="row1">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   427
          Link text: <input type="text" name="http_auth_password_text" value="<?php echo htmlspecialchars(getConfig('http_auth_password_text', '')); ?>" size="30" /><br />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   428
          Link URL:  <input type="text" name="http_auth_password_url" value="<?php echo htmlspecialchars(getConfig('http_auth_password_url', '')); ?>" size="30" />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   429
        </td>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   430
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   431
      
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   432
      <tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   433
        <th class="subhead" colspan="2">
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   434
          <input type="submit" name="submit" value="Save changes" />
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   435
        </th>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   436
      </tr>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   437
    </table>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   438
  </div>
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   439
  <?php
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   440
  echo '</form>';
29e93991703b Initial commit
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   441
}