Changeset 2095 in ExiteCMS


Ignore:
Timestamp:
12/07/08 01:22:46 (3 years ago)
Author:
WanWizard
Message:

updated the authentication system to allow new authentication methods to be 'plugged in'

Location:
trunk
Files:
6 added
16 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/administration/db_backups/index.php

    • Property svn:keywords set to Date Revision Author Id
  • trunk/administration/settings_security.php

    r2033 r2095  
    2929$variables['this_module'] = FUSION_SELF; 
    3030 
     31if (!isset($action)) $action = ""; 
     32 
    3133// check for the proper admin access rights 
    3234if (!checkrights("S4") || !defined("iAUTH") || $aid != iAUTH) fallback(BASEDIR."index.php"); 
     
    4446    } 
    4547    if ($variables['errormessage'] == "") { 
    46         // authentication method check 
    47         $auth_method = $_POST['auth_method']{0}; 
    48         $auth_local = (isset($_POST['auth_method']{1}) && $_POST['auth_method']{1} == "+") ? "1" : "0"; 
    49         switch ($auth_method) { 
    50             case "0":   // Local only 
    51                 $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'local' WHERE cfg_name = 'auth_type'"); 
    52                 break; 
    53             case "1":   // LDAP 
    54                 if ($auth_local) { 
    55                     $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'ldap,local' WHERE cfg_name = 'auth_type'"); 
    56                 } else { 
    57                     $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'ldap' WHERE cfg_name = 'auth_type'"); 
    58                 } 
    59                 break; 
    60             case "2":   // AD 
    61                 if ($auth_local) { 
    62                     $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'ad,local' WHERE cfg_name = 'auth_type'"); 
    63                 } else { 
    64                     $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'ad' WHERE cfg_name = 'auth_type'"); 
    65                 } 
    66                 break; 
    67             case "3":   // OpenID 
    68                 if ($auth_local) { 
    69                     $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'local,openid' WHERE cfg_name = 'auth_type'"); 
    70                 } else { 
    71                     $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = 'openid' WHERE cfg_name = 'auth_type'"); 
    72                 } 
    73                 break; 
    74             default: 
    75                 $variables['errormessage'] = "Invalid authentication method. This may never happen!"; 
    76         } 
    7748        if ($variables['errormessage'] == "") { 
    7849            $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".(isNum($_POST['enable_registration']) ? $_POST['enable_registration'] : "1")."' WHERE cfg_name = 'enable_registration'"); 
     
    11485} 
    11586 
    116 // check if the PHP installation supports the OpenID class 
    117 $variables['has_curl'] = function_exists('curl_exec'); 
     87// load the defined authentication methods 
     88$methods = unserialize($settings2['authentication_methods']); 
     89$selected = explode(",", $settings2['authentication_selected']); 
     90foreach ($methods as $name => $method) { 
     91    $methods[$name]['status'] = 'old'; 
     92} 
    11893 
    119 // determine the auth_method defined 
    120 $auth_methods = explode(",",$settings2['auth_type']); 
    121 $auth_method = 0; 
    122 $auth_local = false; 
    123 foreach($auth_methods as $this_method) { 
    124     switch($this_method) { 
    125         case "ldap": 
    126             $auth_method = 1; 
    127             break; 
    128         case "ad": 
    129             $auth_method = 2; 
    130             break; 
    131         case "openid": 
    132             // OpenID requires CURL to be installed 
    133             if ($variables['has_curl']) { 
    134                 $auth_method = 3; 
    135             } 
    136         case "local": 
    137             $auth_local = true; 
    138             break; 
    139         default: 
    140             $auth_method = 0; 
     94// status update request? 
     95if ($action == "setstatus") { 
     96    if ($status == 1 && array_search($authmethod,$selected) == false) { 
     97        // add the method to the selected array and update the configuration 
     98        $selected[] = $authmethod; 
     99    } elseif ($status == 0 && array_search($authmethod,$selected) !== false) { 
     100        // remove the method from the selected array and update the configuration 
     101        unset($selected[array_search($authmethod,$selected)]); 
     102    } 
     103    // write the update back 
     104    $settings2['authentication_selected'] = ""; 
     105    foreach($selected as $sel) { 
     106        $settings2['authentication_selected'] .= ($settings2['authentication_selected'] == "" ? "" : ",").$sel; 
     107    } 
     108    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$settings2['authentication_selected']."' WHERE cfg_name = 'authentication_selected'"); 
     109} 
     110 
     111// move up requested? 
     112if ($action == "up") { 
     113    // swap the selected method with the previous in the list 
     114    $sel = $selected[$method_id-1]; 
     115    $selected[$method_id-1] = $selected[$method_id]; 
     116    $selected[$method_id] = $sel; 
     117    // write the update back 
     118    $settings2['authentication_selected'] = ""; 
     119    foreach($selected as $sel) { 
     120        $settings2['authentication_selected'] .= ($settings2['authentication_selected'] == "" ? "" : ",").$sel; 
     121    } 
     122    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$settings2['authentication_selected']."' WHERE cfg_name = 'authentication_selected'"); 
     123} 
     124 
     125// move down requested? 
     126if ($action == "down") { 
     127    // swap the selected method with the previous in the list 
     128    $sel = $selected[$method_id+1]; 
     129    $selected[$method_id+1] = $selected[$method_id]; 
     130    $selected[$method_id] = $sel; 
     131    // write the update back 
     132    $settings2['authentication_selected'] = ""; 
     133    foreach($selected as $sel) { 
     134        $settings2['authentication_selected'] .= ($settings2['authentication_selected'] == "" ? "" : ",").$sel; 
     135    } 
     136    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$settings2['authentication_selected']."' WHERE cfg_name = 'authentication_selected'"); 
     137} 
     138 
     139// check if new authentication methods have been installed 
     140$files = makefilelist(PATH_INCLUDES."authentication", ".|..", $sort=true, $type="files", $hidden=false); 
     141foreach($files as $file) { 
     142    if (substr($file,0,5) == "auth_" && strrchr($file,".") == ".php") { 
     143        $class = substr($file, 0, strrpos($file, ".")); 
     144        $method = substr($class, strrpos($file, "_")+1); 
     145        if (!isset($methods[$method])) { 
     146            $methods[$method] = array('class' => $class, 'status' => "new"); 
     147        } else { 
     148            $methods[$method]['status'] = "found"; 
     149        } 
    141150    } 
    142151} 
    143152 
    144 // check if a local fallback is defined 
    145 $variables['auth_method'] = $auth_method . ($auth_local ? "+" : " "); 
     153// delete old ones, add the others to the sortlist, and update the config 
     154$sortlist = array(); 
     155foreach ($methods as $name => $method) { 
     156    if ($method['status'] == "old") { 
     157        unset($methods[$name]); 
     158    } else { 
     159        // add to the sortlist 
     160        if (in_array($name, $selected)) { 
     161            $sortlist[] = substr('000'.array_search($name, $selected),-3).".".$name; 
     162        } else { 
     163            $sortlist[] = "zzz.".$name; 
     164        } 
     165    } 
     166} 
     167$result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".mysql_real_escape_string(serialize($methods))."' WHERE cfg_name = 'authentication_methods'"); 
     168 
     169// create the list of available methods, in the correct order 
     170sort($sortlist); 
     171$variables['methods'] = array(); 
     172$c = count($selected);$i=1; 
     173foreach($sortlist as $entry) { 
     174    $listentry = explode(".", $entry); 
     175    $variables['methods'][] = array('name' => $listentry[1], 'class' => $methods[$listentry[1]]['class'], 'status' => $listentry[0] == 'zzz' ? 0 :1, 'last' => ($i++ == $c ? 1 : 0)); 
     176} 
    146177 
    147178// define the admin body panel 
  • trunk/administration/tools/language_pack_English.php

    r2092 r2095  
    11011101        $localestrings['575'] = "Login requires HTTPS:"; 
    11021102        $localestrings['576'] = "Site access requires login:"; 
     1103        $localestrings['577'] = "Installed authentication methods"; 
     1104        $localestrings['578'] = "Method"; 
     1105        $localestrings['579'] = "Class"; 
     1106        $localestrings['580'] = "Order"; 
     1107        $localestrings['581'] = "Status"; 
     1108        $localestrings['582'] = "Options"; 
     1109        $localestrings['583'] = "Move up"; 
     1110        $localestrings['584'] = "Move down"; 
     1111        $localestrings['585'] = "Enable"; 
     1112        $localestrings['586'] = "Enabled"; 
     1113        $localestrings['587'] = "Disable"; 
     1114        $localestrings['588'] = "Disabled"; 
    11031115        $localestrings['600'] = "Albums"; 
    11041116        $localestrings['601'] = "Thumbnail width:"; 
     
    37693781if (!defined('LP_COUNTRIES')) define('LP_COUNTRIES', "us|gb|ca|au|nz|in|za|ir|mt|hk|pr"); 
    37703782if (!defined('LP_VERSION')) define('LP_VERSION', "7.20"); 
    3771 if (!defined('LP_DATE')) define('LP_DATE', "1228492311"); 
     3783if (!defined('LP_DATE')) define('LP_DATE', "1228608894"); 
    37723784$lp_date = LP_DATE; 
    37733785 
  • trunk/administration/tools/language_pack_Nederlands.php

    r2092 r2095  
    11011101        $localestrings['575'] = "Login vereist HTTPS:"; 
    11021102        $localestrings['576'] = "Login verplicht voor site toegang:"; 
     1103        $localestrings['577'] = "Geinstalleerde authenticatie methoden"; 
     1104        $localestrings['578'] = "Methode"; 
     1105        $localestrings['579'] = "Class"; 
     1106        $localestrings['580'] = "Volgorde"; 
     1107        $localestrings['581'] = "Status"; 
     1108        $localestrings['582'] = "Opties"; 
     1109        $localestrings['583'] = "Naar omhoog"; 
     1110        $localestrings['584'] = "Naar beneden"; 
     1111        $localestrings['585'] = "Activeren"; 
     1112        $localestrings['586'] = "Geactiveerd"; 
     1113        $localestrings['587'] = "Uitschakelen"; 
     1114        $localestrings['588'] = "Uitgeschakeld"; 
    11031115        $localestrings['600'] = "Albums"; 
    11041116        $localestrings['601'] = "Breedte miniatuur:"; 
     
    37693781if (!defined('LP_COUNTRIES')) define('LP_COUNTRIES', "nl|be|sr|aw|an"); 
    37703782if (!defined('LP_VERSION')) define('LP_VERSION', "7.20"); 
    3771 if (!defined('LP_DATE')) define('LP_DATE', "1228492315"); 
     3783if (!defined('LP_DATE')) define('LP_DATE', "1228608898"); 
    37723784$lp_date = LP_DATE; 
    37733785 
  • trunk/edit_profile.php

    r2087 r2095  
    3131// load the OpenID class (if cURL is present) 
    3232if (function_exists('curl_exec')) { 
    33     require_once PATH_INCLUDES."class.openid.php"; 
     33    require_once PATH_INCLUDES."authentication/class.openid.php"; 
    3434    $openid = new SimpleOpenID; 
    3535} 
  • trunk/files/locales/en.main.global.php

    r2092 r2095  
    33// locale       : English 
    44// locale name  : main.global 
    5 // generated on : Fri Dec 5 2008, 16:52:09 CET 
     5// generated on : Sun Dec 7 2008, 1:15:00 CET 
    66// translators  : ExiteCMS team,WanWizard 
    77// ---------------------------------------------------------- 
  • trunk/files/locales/en.main.setup.php

    r2092 r2095  
    33// locale       : English 
    44// locale name  : main.setup 
    5 // generated on : Thu Dec 4 2008, 15:56:51 CET 
     5// generated on : Sun Dec 7 2008, 1:14:54 CET 
    66// translators  : ExiteCMS team,WanWizard 
    77// ---------------------------------------------------------- 
  • trunk/files/locales/nl.main.global.php

    r2092 r2095  
    33// locale       : English 
    44// locale name  : main.global 
    5 // generated on : Thu Dec 4 2008, 15:56:55 CET 
     5// generated on : Sun Dec 7 2008, 1:14:58 CET 
    66// translators  : ExiteCMS team,WanWizard 
    77// ---------------------------------------------------------- 
  • trunk/files/locales/nl.main.setup.php

    r2092 r2095  
    33// locale       : English 
    44// locale name  : main.setup 
    5 // generated on : Thu Dec 4 2008, 15:56:55 CET 
     5// generated on : Sun Dec 7 2008, 1:14:58 CET 
    66// translators  : ExiteCMS team,WanWizard 
    77// ---------------------------------------------------------- 
  • trunk/includes/templates/admin.settings_image.tpl

    r2033 r2095  
    2121{include file="admin.settings_links.tpl} 
    2222<form name='settingsform' method='post' action='{$smarty.const.FUSION_SELF}{$aidlink}'> 
    23     <table align='center' cellpadding='0' cellspacing='0' width='500'> 
     23    <table align='center' cellpadding='0' cellspacing='0' width='100%'> 
    2424        <tr> 
    2525            <td class='tbl' width='50%'> 
  • trunk/includes/templates/admin.settings_security.tpl

    r2035 r2095  
    9191        <tr> 
    9292            <td width='50%' class='tbl'> 
    93                 {$locale.537} 
    94             </td> 
    95             <td width='50%' class='tbl'> 
    96                 <select name='auth_method' class='textbox'> 
    97                     <option value='0'{if $auth_method == "0"} selected="selected"{/if}>{$locale.538}</option> 
    98                     <option value='1'{if $auth_method == "1"} selected="selected"{/if}>{$locale.539}</option> 
    99                     <option value='1+'{if $auth_method == "1+"} selected="selected"{/if}>{$locale.539}{$locale.541}{$locale.538}</option> 
    100                     <option value='2'{if $auth_method == "2"} selected="selected"{/if}>{$locale.540}</option> 
    101                     <option value='2+'{if $auth_method == "2+"} selected="selected"{/if}>{$locale.540}{$locale.541}{$locale.538}</option> 
    102                     {if $has_curl} 
    103                     <option value='3+'{if $auth_method == "3+"} selected="selected"{/if}>{$locale.538}{$locale.542}</option> 
    104                     {/if} 
    105                 </select> 
    106             </td> 
    107         </tr> 
    108         <tr> 
    109             <td width='50%' class='tbl'> 
    11093                {$locale.575} 
    11194            </td> 
     
    129112        </tr> 
    130113        <tr> 
    131             <td align='center' colspan='2' class='tbl'> 
    132                 <hr /> 
     114            <td width='50%' class='tbl'> 
     115                {$locale.529} 
     116            </td> 
     117            <td width='50%' class='tbl'> 
     118                <select name='login_expire' class='textbox'> 
     119                {section name=min start=0 loop=721 step=15} 
     120                <option value='{$smarty.section.min.index}' {if $smarty.section.min.index == $login_expire|default:0}selected='selected'{/if}>{if $smarty.section.min.index == 0}{$locale.714}{else}{$smarty.section.min.index} {$locale.531}{/if}</option> 
     121                {/section} 
     122                </select> 
     123            </td> 
     124        </tr> 
     125        <tr> 
     126            <td width='50%' class='tbl'> 
     127                {$locale.530} 
     128            </td> 
     129            <td width='50%' class='tbl'> 
     130                <select name='login_extended_expire' class='textbox'> 
     131                {section name=days start=0 loop=1441 step=1} 
     132                <option value='{$smarty.section.days.index}' {if $smarty.section.days.index == $login_extended_expire|default:0}selected='selected'{/if}>{if $smarty.section.days.index == 0}{$locale.714}{elseif $smarty.section.days.index == 1}1 {$locale.527}{else}{$smarty.section.days.index} {$locale.518}{/if}</option> 
     133                {/section} 
     134                </select> 
    133135            </td> 
    134136        </tr> 
     
    150152        </tr> 
    151153        <tr> 
    152             <td width='50%' class='tbl'> 
    153                 {$locale.529} 
    154             </td> 
    155             <td width='50%' class='tbl'> 
    156                 <select name='login_expire' class='textbox'> 
    157                 {section name=min start=0 loop=721 step=15} 
    158                 <option value='{$smarty.section.min.index}' {if $smarty.section.min.index == $login_expire|default:0}selected='selected'{/if}>{if $smarty.section.min.index == 0}{$locale.714}{else}{$smarty.section.min.index} {$locale.531}{/if}</option> 
    159                 {/section} 
    160                 </select> 
    161             </td> 
    162         </tr> 
    163         <tr> 
    164             <td width='50%' class='tbl'> 
    165                 {$locale.530} 
    166             </td> 
    167             <td width='50%' class='tbl'> 
    168                 <select name='login_extended_expire' class='textbox'> 
    169                 {section name=days start=0 loop=1441 step=1} 
    170                 <option value='{$smarty.section.days.index}' {if $smarty.section.days.index == $login_extended_expire|default:0}selected='selected'{/if}>{if $smarty.section.days.index == 0}{$locale.714}{elseif $smarty.section.days.index == 1}1 {$locale.527}{else}{$smarty.section.days.index} {$locale.518}{/if}</option> 
    171                 {/section} 
    172                 </select> 
    173             </td> 
    174         </tr> 
    175         <tr> 
    176154            <td align='center' colspan='2' class='tbl'> 
    177155                <br /> 
     
    182160</form> 
    183161{include file="_closetable.tpl"} 
     162{include file="_opentable.tpl" name=$_name title=$locale.577 state=$_state style=$_style} 
     163<table align='center' cellpadding='0' cellspacing='1' width='80%' class='tbl-border'> 
     164    <tr> 
     165        <td align='center' width='1%' class='tbl2' style='white-space:nowrap'> 
     166            <b>{$locale.578}</b> 
     167        </td> 
     168        <td align='center' width='1%' class='tbl2' style='white-space:nowrap'> 
     169            <b>{$locale.579}</b> 
     170        </td> 
     171        <td align='center' width='1%' class='tbl2' style='white-space:nowrap'> 
     172            <b>{$locale.580}</b> 
     173        </td> 
     174        <td align='center' width='1%' class='tbl2' style='white-space:nowrap'> 
     175            <b>{$locale.581}</b> 
     176        </td> 
     177        <td align='center' width='1%' class='tbl2' style='white-space:nowrap'> 
     178            <b>{$locale.582}</b> 
     179        </td> 
     180    </tr> 
     181    <br /> 
     182    {section name=id loop=$methods} 
     183        <tr> 
     184            <td align='center' width='1%' class='tbl1' style='white-space:nowrap'> 
     185                {$methods[id].name} 
     186            </td> 
     187            <td align='center' width='1%' class='tbl1' style='white-space:nowrap'> 
     188                {$methods[id].class} 
     189            </td> 
     190            <td align='center' width='1%' class='tbl1' style='white-space:nowrap'> 
     191                {if $methods[id].status == 1} 
     192                    {if !$smarty.section.id.first} 
     193                        {imagelink link=$smarty.const.FUSION_SELF|cat:$aidlink|cat:"&amp;action=up&amp;method_id="|cat:$smarty.section.id.index image="up.gif" alt=$locale.583 title=$locale.583} 
     194                    {/if} 
     195                    {if !$methods[id].last} 
     196                        {imagelink link=$smarty.const.FUSION_SELF|cat:$aidlink|cat:"&amp;action=down&amp;method_id="|cat:$smarty.section.id.index image="down.gif" alt=$locale.584 title=$locale.584} 
     197                    {/if} 
     198                {/if} 
     199            </td> 
     200            <td align='center' width='1%' class='tbl1' style='white-space:nowrap'> 
     201                {if $methods[id].status == 1} 
     202                    {$locale.586} 
     203                {else} 
     204                    {$locale.588} 
     205                {/if} 
     206            </td> 
     207            <td align='center' width='1%' class='tbl1' style='white-space:nowrap'> 
     208                {if $methods[id].status == 1} 
     209                    {imagelink link=$smarty.const.FUSION_SELF|cat:$aidlink|cat:"&amp;action=setstatus&amp;status=0&amp;authmethod="|cat:$methods[id].name image="page_red.gif" alt=$locale.587 title=$locale.587} 
     210                {else} 
     211                    {imagelink link=$smarty.const.FUSION_SELF|cat:$aidlink|cat:"&amp;action=setstatus&amp;status=1&amp;authmethod="|cat:$methods[id].name image="page_green.gif" alt=$locale.585 title=$locale.585} 
     212                {/if} 
     213            </td> 
     214        </tr> 
     215    {/section} 
     216</table> 
     217<br /> 
     218{include file="_closetable.tpl"} 
    184219{***************************************************************************} 
    185220{* End of template                                                         *} 
  • trunk/includes/templates/main.login.tpl

    r2013 r2095  
    2727    <body class='body'> 
    2828        <div class='splashscreen-h'> 
    29             <div class='splashscreen-v' style='height:250px;vertical-align:center;'> 
     29            <div class='splashscreen-v' style='height:325px;vertical-align:center;'> 
    3030                <table align='center' cellpadding='0' cellspacing='1' width='500'> 
    3131                    <tr> 
  • trunk/includes/user_functions.php

    r2078 r2095  
    1919if (eregi("user_functions.php", $_SERVER['PHP_SELF']) || !defined('INIT_CMS_OK')) die(); 
    2020 
     21// load and instantiate the authentication class 
     22require_once "authentication/authentication.php"; 
     23$cms_authentication =& new authentication(); 
     24 
    2125// need the GeoIP functions to determine the users country of origin 
    2226require_once "geoip_include.php"; 
     
    5862        if ($_COOKIE['site_visited'] == "yes") { 
    5963            $site_visited = md5(uniqid(rand(), true)); 
    60             setcookie("site_visited", $site_visited, time() + 31536000, "/", "", "0"); 
    61         } else { 
     64        } else { 
     65            // get the cookie value 
    6266            $site_visited = $_COOKIE['site_visited']; 
    6367        } 
     68        // refresh the cookie 
     69        setcookie("site_visited", $site_visited, time() + 31536000, "/", "", "0"); 
    6470    } 
    6571} 
     
    6773// if not in the process of posting a form, did the login session expire? 
    6874if (count($_POST)==0 && !empty($_SESSION['login_expire']) && $_SESSION['login_expire'] < time()) { 
    69     // clear the login info from the session 
    70     unset($_SESSION['user']); 
    71     unset($_SESSION['userinfo']); 
    72     unset($_SESSION['login_expire']); 
     75    $cms_authentication->logoff(); 
    7376} 
    7477 
    7578// Are we logged in? 
    76 if (isset($_SESSION['userinfo'])) { 
    77     $userinfo_vars = explode(".", $_SESSION['userinfo']); 
    78     $userinfo_1 = isNum($userinfo_vars['0']) ? $userinfo_vars['0'] : "0"; 
    79     $userinfo_2 = (preg_match("/^[0-9a-z]{32}$/", $userinfo_vars['1']) ? $userinfo_vars['1'] : ""); 
    80     $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_id='$userinfo_1' AND user_password='$userinfo_2'"); 
    81     unset($userinfo_vars,$userinfo_1,$userinfo_2); 
    82     if (dbrows($result) != 0) { 
    83         $userdata = dbarray($result); 
    84         if ($userdata['user_status'] == 0) { 
    85             // set the user's theme 
    86             if (isset($_SESSION['set_theme']) && file_exists(PATH_THEMES.$_SESSION['set_theme']."/theme.php")) { 
    87                 $userdata['user_theme'] = $_SESSION['set_theme']; 
    88                 unset($_SESSION['set_theme']); 
    89                 $result2 = dbquery("UPDATE ".$db_prefix."users SET user_theme = '".$userdata['user_theme']."' WHERE user_id='$userinfo_1' AND user_password='$userinfo_2'"); 
    90                 define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
    91                 define("THEME", THEMES.$userdata['user_theme']."/"); 
    92             } elseif ($userdata['user_theme'] != "Default" && file_exists(PATH_THEMES.$userdata['user_theme']."/theme.php")) { 
    93                 define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
    94                 define("THEME", THEMES.$userdata['user_theme']."/"); 
    95             } else { 
    96                 define("PATH_THEME", PATH_THEMES.$settings['theme']."/"); 
    97                 define("THEME", THEMES.$settings['theme']."/"); 
    98                 // make sure the default theme exists! 
    99                 if (!file_exists(PATH_THEMES.$settings['theme']."/theme.php")) { 
    100                     die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>FATAL ERROR: Unable to load the default theme</b></div>"); 
    101                 } 
    102             } 
    103             if ($userdata['user_offset'] <> 0) { 
    104                 $settings['timeoffset'] = $settings['timeoffset'] + $userdata['user_offset']; 
    105             } 
    106             if (empty($_SESSION['lastvisit'])) { 
    107                 $_SESSION['lastvisit'] = $userdata['user_lastvisit']; 
    108                 $lastvisited = $userdata['user_lastvisit']; 
    109             } else { 
    110                 $lastvisited = $_SESSION['lastvisit']; 
    111             } 
    112         } else { 
    113             header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    114             // make sure the user info is erased from the session 
    115             unset($_SESSION['user']); 
    116             unset($_SESSION['userinfo']); 
    117             unset($_SESSION['login_expire']); 
    118             redirect(BASEDIR."index.php", "script"); 
    119             exit; 
    120         } 
    121         // update the login expiration timestamp 
    122         if ($settings['login_expire']) { 
    123             if (isset($_SESSION['remember_me']) && $_SESSION['remember_me'] == "yes") { 
    124                 $_SESSION['login_expire'] = time() + $settings['login_extended_expire']; 
    125             } else { 
    126                 $_SESSION['login_expire'] = time() + $settings['login_expire']; 
    127             } 
    128         } else { 
    129             $_SESSION['login_expire'] = mktime(0,0,0,1,1,2038); // do not expire 
    130         } 
    131     } else { 
    132         header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    133         // make sure the user info is erased from the session 
    134         unset($_SESSION['user']); 
    135         unset($_SESSION['userinfo']); 
    136         unset($_SESSION['login_expire']); 
    137         redirect(BASEDIR."index.php", "script"); 
    138         exit; 
     79if ($cms_authentication->logged_on()) { 
     80 
     81    $userdata = $cms_authentication->get_userinfo(); 
     82    // set the user's theme 
     83    if (isset($_SESSION['set_theme']) && file_exists(PATH_THEMES.$_SESSION['set_theme']."/theme.php")) { 
     84        $userdata['user_theme'] = $_SESSION['set_theme']; 
     85        unset($_SESSION['set_theme']); 
     86        $result2 = dbquery("UPDATE ".$db_prefix."users SET user_theme = '".$userdata['user_theme']."' WHERE user_id='$userinfo_1' AND user_password='$userinfo_2'"); 
     87        define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
     88        define("THEME", THEMES.$userdata['user_theme']."/"); 
     89    } elseif ($userdata['user_theme'] != "Default" && file_exists(PATH_THEMES.$userdata['user_theme']."/theme.php")) { 
     90        define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
     91        define("THEME", THEMES.$userdata['user_theme']."/"); 
     92    } else { 
     93        define("PATH_THEME", PATH_THEMES.$settings['theme']."/"); 
     94        define("THEME", THEMES.$settings['theme']."/"); 
     95        // make sure the default theme exists! 
     96        if (!file_exists(PATH_THEMES.$settings['theme']."/theme.php")) { 
     97            die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>FATAL ERROR: Unable to load the default theme</b></div>"); 
     98        } 
     99    } 
     100    if ($userdata['user_offset'] <> 0) { 
     101        $settings['timeoffset'] = $settings['timeoffset'] + $userdata['user_offset']; 
     102    } 
     103    if (empty($_SESSION['lastvisit'])) { 
     104        $_SESSION['lastvisit'] = $userdata['user_lastvisit']; 
     105        $lastvisited = $userdata['user_lastvisit']; 
     106    } else { 
     107        $lastvisited = $_SESSION['lastvisit']; 
     108    } 
     109    // update the login expiration timestamp 
     110    if ($settings['login_expire']) { 
     111        if (isset($_SESSION['remember_me']) && $_SESSION['remember_me'] == "yes") { 
     112            $_SESSION['login_expire'] = time() + $settings['login_extended_expire']; 
     113        } else { 
     114            $_SESSION['login_expire'] = time() + $settings['login_expire']; 
     115        } 
     116    } else { 
     117        $_SESSION['login_expire'] = mktime(0,0,0,1,1,2038); // do not expire 
    139118    } 
    140119} else { 
  • trunk/login.php

    r1936 r2095  
    4040 
    4141// get which authentication to show 
    42 $variables['auth_methods'] = explode(",",$settings['auth_type']); 
     42$variables['auth_methods'] = explode(",",$settings['authentication_selected']); 
    4343$variables['method_count'] = count($variables['auth_methods']); 
    4444$variables['auth_state'] = array(); 
  • trunk/modules/user_info_panel/user_info_panel.php

    r2079 r2095  
    8080 
    8181// get which authentication to show 
    82 $variables['auth_methods'] = explode(",",$settings['auth_type']); 
     82$variables['auth_methods'] = $GLOBALS['cms_authentication']->selected; 
    8383$variables['method_count'] = count($variables['auth_methods']); 
    8484$variables['auth_state'] = array(); 
  • trunk/setuser.php

    r2084 r2095  
    2020require_once PATH_INCLUDES."theme_functions.php"; 
    2121 
    22 // used by the auth functions to store the retrieved local user_id 
    23 // this value is needed in some of the error handling code 
    24 $user_id = 0; 
    25  
    26 /*---------------------------------------------------+ 
    27 | User authentication functions                      | 
    28 +----------------------------------------------------*/ 
    29  
    30 // authentication against the local user database 
    31 function auth_local($userid, $password) { 
    32     global $db_prefix, $user_id; 
    33      
    34     // check and validate the given userid and pasword 
    35     $user_pass = md5(md5($password)); 
    36     $user_name = preg_replace(array("/\=/","/\#/","/\sOR\s/"), "", stripinput($userid)); 
    37  
    38     // check if we have a user record for this userid and password 
    39     $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_name='$user_name' AND user_password='".$user_pass."'"); 
    40     if (dbrows($result) == 0) { 
    41         // not found, display an error message 
    42         return 3; 
    43     } else { 
    44         // retrieve the record 
    45         $data = dbarray($result); 
    46         // store the global user_id for reference outside this function 
    47         $user_id = $data['user_id']; 
    48         // found, get the record and do some more validation 
    49         $ret = auth_user_validate($data); 
    50         return $ret; 
    51     } 
    52 } 
    53  
    54 // authentication against an LDAP server 
    55 function auth_ldap($userid, $password) { 
    56     terminate('auth_ldap not defined yet!'); 
    57 } 
    58  
    59 // authentication against an Active Directory server 
    60 function auth_ad($userid, $password) { 
    61     terminate('auth_ad not defined yet!'); 
    62 } 
    63  
    64 // authentication using an OpenID 
    65 function auth_openid($openid_url) { 
    66     global $settings; 
    67  
    68     // check if the URL is valid 
    69     if (isURL($openid_url)) { 
    70         require_once(PATH_INCLUDES."class.openid.php"); 
    71         $openid = new SimpleOpenID; 
    72         $openid->SetIdentity($openid_url); 
    73         $openid->SetApprovedURL($settings['siteurl']."setuser.php"); 
    74         $openid->SetTrustRoot($settings['siteurl']); 
    75         $server_url = $openid->GetOpenIDServer(); 
    76         if ($server_url) { 
    77             redirect($openid->GetRedirectURL() , "script"); 
    78             exit; 
    79         } 
    80     } else { 
    81         // for now... 
    82         return 0; 
    83     } 
    84 } 
    85  
    86 // further validation on the userid found 
    87 function auth_user_validate($userrecord) { 
    88     global $settings; 
    89  
    90     // if the account is suspended, check for an expiry date 
    91     if ($userrecord['user_status'] == 1 && $userrecord['user_ban_expire'] > 0 && $userrecord['user_ban_expire'] < time() ) { 
    92         // if this user's email address is marked as bad, reset the countdown counter 
    93         $userrecord['user_bad_email'] = $userrecord['user_bad_email'] == 0 ? 0 : time(); 
    94         // reset the user status and the expiry date 
    95         $result = dbquery("UPDATE ".$db_prefix."users SET user_status='0', user_ban_expire='0', user_bad_email = '".$userrecord['user_bad_email']."' WHERE user_id='".$userrecord['user_id']."'"); 
    96         $userrecord['user_status'] = 0; 
    97     } 
    98     if ($userrecord['user_status'] == 0) {   
    99         header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    100         // set the 'remember me' status value  
    101         $_SESSION['remember_me'] = isset($_POST['remember_me']) ? "yes" : "no"; 
    102         $_SESSION['userinfo'] = $userrecord['user_id'].".".$userrecord['user_password']; 
    103         // login expiry defined? 
    104         if ($settings['login_expire']) { 
    105             if (isset($_POST['remember_me']) && $_POST['remember_me'] == "yes") { 
    106                 $_SESSION['login_expire'] = time() + $settings['login_extended_expire']; 
    107             } else { 
    108                 $_SESSION['login_expire'] = time() + $settings['login_expire']; 
    109             } 
    110         } else { 
    111             $_SESSION['login_expire'] = mktime(0,0,0,1,1,2038); // do not expire 
    112         } 
    113         return 4; 
    114     } elseif ($userrecord['user_status'] == 1) { 
    115         return 1; 
    116     } elseif ($userrecord['user_status'] == 2) { 
    117         return 2; 
    118     } else { 
    119         return 0; 
    120     } 
    121 } 
    122  
    123  
    124 /*---------------------------------------------------+ 
    125 | Main code                                          | 
    126 +----------------------------------------------------*/ 
    127  
    12822// temp storage for template variables 
    12923$variables = array(); 
     
    13125// array to store the lines of the setuser message 
    13226$message = array(); 
     27 
     28// set the P3P header                
     29header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    13330 
    13431// make sure the error variable has a value 
     
    14845 
    14946    // process the logout request 
     47    $cms_authentication->logoff(); 
    15048 
    151     header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    15249    // make sure the user info is erased from the session 
    153     unset($_SESSION['user']); 
    154     unset($_SESSION['userinfo']); 
    155     unset($_SESSION['login_expire']); 
    156     $result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_ip='".USER_IP."'"); 
    15750    if (isset($userdata['user_name'])) { 
    15851        $message['line2'] =  "<b>".$locale['192'].$userdata['user_name']."</b>"; 
     
    16154} elseif (isset($_GET['login']) && $_GET['login'] == "yes") { 
    16255 
    163     // process the login request 
    164     $auth_methods = isset($settings['auth_type']) ? explode(",",$settings['auth_type'].",") : array('local'); 
    165     foreach($auth_methods as $auth_method) { 
    166         switch($auth_method) { 
    167             case "local": 
    168                 // authentication against the local user database 
    169                 if (!empty($_POST['user_name']) && !empty($_POST['user_pass'])) { 
    170                     $error = auth_local($_POST['user_name'], $_POST['user_pass']); 
    171                 } 
    172                 break; 
    173             case "ldap": 
    174                 break; 
    175             case "ad": 
    176                 break; 
    177             case "openid": 
    178                 // authentication against an openid provider 
    179                 if (!empty($_POST['user_openid_url'])) { 
    180                     $error = auth_openid($_POST['user_openid_url']); 
    181                 } 
    182                 break; 
    183             case "default": 
    184                 // empty or unknown entry, ignore 
    185                 break; 
    186         } 
     56    // store any login parameters to be passed 
     57    $params = array(); 
     58    if (!empty($_POST['user_name'])) { 
     59        $params['username'] = stripinput($_POST['user_name']); 
     60    } 
     61    if (!empty($_POST['user_pass'])) { 
     62        $params['password'] = stripinput($_POST['user_pass']); 
     63    } 
     64    if (!empty($_POST['user_openid_url']) && isURL($_POST['user_openid_url'])) { 
     65        $params['openid_url'] = stripinput($_POST['user_openid_url']); 
    18766    } 
    18867 
    189 } else { 
     68    // process the logon request 
     69    if ($cms_authentication->logon($params)) { 
     70        // get the logon status 
     71        $error = $cms_authentication->status; 
     72    } else { 
     73        $error = 3; // // credentials not correct 
     74    } 
    19075 
    191     if (isset($_GET['openid_mode'])) { 
    192         // handle openid login 
    193         require_once(PATH_INCLUDES."class.openid.php"); 
    194         $openid = new SimpleOpenID; 
    195         $openid->SetIdentity(urldecode($_GET['openid_identity'])); 
    196         if ($openid->ValidateWithServer()) { 
    197             $openid_url = strtolower($openid->OpenID_Standarize($_GET['openid_identity'])); 
    198             $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_openid_url='".$openid_url."'"); 
    199             if (dbrows($result) != 0) { 
    200                 // found, get the record and do some more validation 
    201                 $error = auth_user_validate(dbarray($result)); 
    202             } else { 
    203                 $message['line2'] =  "<b>".$locale['196']."</b>"; 
    204             } 
    205         } else { 
    206             trigger_error($openid->GetError()); 
    207             exit; 
    208         } 
     76} elseif (isset($_GET['openid_mode'])) { 
     77 
     78    // store any login parameters to be passed 
     79    $params = array(); 
     80 
     81    if (!empty($_GET['openid_mode'])) { 
     82        $params['openid_mode'] = stripinput($_GET['openid_mode']); 
     83    } 
     84 
     85    // process the openid logon request 
     86    if ($cms_authentication->logon($params)) { 
     87        $error = $cms_authentication->status; 
     88    } else { 
     89        $error = 3; // credentials not correct 
    20990    } 
    21091 
     
    21394// check the result of the authentication attempt, and process it 
    21495switch($error) { 
    215     case 0: 
     96    case 0: // no errors 
    21697        //  
    21798        $refresh = 1; 
    21899        break; 
    219     case 1: 
     100    case 1: // account is suspended 
    220101        $message['line1'] = "<b>".$locale['194']."</b>"; 
    221102        $data = dbarray(dbquery("SELECT user_ban_reason, user_ban_expire FROM ".$db_prefix."users WHERE user_id='".$user_id."'")); 
     
    226107        $refresh = 10; 
    227108        break; 
    228     case 2: 
     109    case 2: // account not activated (yet) 
    229110        $message['line2'] =  "<b>".$locale['195']."</b>"; 
    230111        $refresh = 10; 
    231112        break; 
    232     case 3: 
     113    case 3: // credentials not correct 
    233114        $message['line2'] =  "<b>".$locale['196']."</b>"; 
    234115        $refresh = 10; 
    235116        break; 
    236     case 4: 
     117    case 4: // successful logon 
    237118        if (isset($_SESSION['userinfo'])) { 
    238119            // now that we have user info, finish the login validation 
     
    257138        } 
    258139        break; 
    259     case 5: 
     140    case 5: // logon requires https 
    260141        $message['line2'] =  "<b>".$locale['https']."</b>"; 
    261142        $refresh = 99999; 
    262143        break; 
    263     case 6: 
     144    case 6: // user is banned 
    264145        $message['line2'] =  "<font style='color:red;font-weight:bold'>".($locale['banned'])."</font>"; 
    265146        // get the reason for this ban 
Note: See TracChangeset for help on using the changeset viewer.