Ignore:
Timestamp:
May 25, 2014, 6:52:42 PM (10 years ago)
Author:
22decembre
Message:

add function to sync ldap and piwigo groups
ldap groups correspond to webmasters and admin roles

Location:
extensions/Ldap_Login/admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/Ldap_Login/admin/configuration.php

    r27284 r28534  
    1212$me = new Ldap();
    1313$me->load_config();
     14$me->ldap_conn();
    1415//$me = get_plugin_data($plugin_id);
    1516
    1617$template->assign('HOST',       $me->config['host']);
    1718$template->assign('BASEDN',     $me->config['basedn']); // racine !
     19$template->assign('USERSBRANCH',$me->config['usersbranch']);
     20$template->assign('GROUPBRANCH',$me->config['groupbranch']);
     21$template->assign('LD_SEARCH_USERS',$me->config['ld_search_users']);
     22$template->assign('LD_SEARCH_GROUPS',$me->config['ld_search_groups']);
    1823$template->assign('PORT',       $me->config['port']);
    1924$template->assign('LD_ATTR',    $me->config['ld_attr']);
     25$template->assign('LD_GROUP',   $me->config['ld_group']);
    2026$template->assign('LD_USE_SSL', $me->config['ld_use_ssl']);
    2127$template->assign('LD_BINDPW',  $me->config['ld_bindpw']);
    2228$template->assign('LD_BINDDN',  $me->config['ld_binddn']);
     29$template->assign('WEBMASTERS_GROUP',   $me->config['webmasters_group']);
     30$template->assign('ADMINS_GROUP',       $me->config['admins_group']);
    2331
    2432if (isset($_POST['save'])){
    2533        $me->config['host']      = $_POST['HOST'];
    2634        $me->config['basedn']    = $_POST['BASEDN'];
     35        $me->config['usersbranch']    = $_POST['USERSBRANCH'];
     36        $me->config['groupbranch']    = $_POST['GROUPBRANCH'];
    2737        $me->config['port']      = $_POST['PORT'];
    2838        $me->config['ld_attr']   = $_POST['LD_ATTR'];
     39        $me->config['ld_group']   = $_POST['LD_GROUP'];
    2940        $me->config['ld_binddn'] = $_POST['LD_BINDDN'];
    3041        $me->config['ld_bindpw'] = $_POST['LD_BINDPW'];
     42       
     43        $me->config['webmasters_group'] = $_POST['WEBMASTERS_GROUP'];
     44        $me->config['admins_group'] = $_POST['ADMINS_GROUP'];
    3145
    3246        if (isset($_POST['LD_USE_SSL'])){
     
    3448        } else {
    3549                $me->config['ld_use_ssl'] = False;
     50        }
     51       
     52        if (isset($_POST['LD_SEARCH_GROUPS'])){
     53                $me->config['ld_search_groups'] = True;
     54        } else {
     55                $me->config['ld_search_groups'] = False;
     56        }
     57       
     58        if (isset($_POST['LD_SEARCH_USERS'])){
     59                $me->config['ld_search_users'] = True;
     60        } else {
     61                $me->config['ld_search_users'] = False;
    3662        }
    3763}
     
    4470// Check LDAP configuration
    4571if (isset($_POST['check_ldap'])){
    46 $check = $me->ldap_name($_POST['USERNAME']);
    47 $error = $me->check_ldap();
     72#$check = $me->ldap_name($_POST['USERNAME']);
     73#$error = $me->check_ldap();
    4874
    49         if ($me->ldap_bind_as($_POST['USERNAME'],$_POST['PASSWORD'])){
    50         $template->assign('LD_CHECK_LDAP','<p style="color:green;">Configuration LDAP OK : '.$check.'</p>');
     75        if ($me->config['users_group']) {
     76                if ($me->user_membership($_POST['USERNAME'],$me->ldap_group($me->config['users_group']))) {
     77                        if ($me->ldap_bind_as($_POST['USERNAME'],$_POST['PASSWORD'])){
     78                                // search groups
     79                                $group_query = 'SELECT name, id FROM '.GROUPS_TABLE.';';
     80                                $groups = pwg_query($group_query);
     81                                $sentence = '';
     82       
     83                                foreach($groups as $group) {
     84                                        if($me->user_membership($_POST['USERNAME'], $me->ldap_group($group['name']))) {
     85                                                $sentence = $sentence . ', '.$group['name'];
     86                                        }
     87                                }
     88                                $template->assign('LD_CHECK_LDAP','<p style="color:green;">Configuration LDAP OK : '.$_POST['USERNAME'].' is in users'.$sentence.' group(s) and can auth. He is a '.$me->ldap_status($_POST['USERNAME']).' user according to the plugin.</p>');
     89                        }
     90                        else {
     91                                $template->assign('LD_CHECK_LDAP','<p style="color:red;">Error : test '.$me->config['uri'].' '.$me->ldap_name($_POST['USERNAME']).'</p>');
     92                        }
     93                }
    5194        }
    5295        else {
    53         $template->assign('LD_CHECK_LDAP','<p style="color:red;">Error :'.$error.' test '.$me->config['uri'].' '.$check.'</p>');
     96                if ($me->ldap_bind_as($_POST['USERNAME'],$_POST['PASSWORD'])){
     97                        // search groups
     98                        $group_query = 'SELECT name, id FROM '.GROUPS_TABLE.';';
     99                        $groups = pwg_query($group_query);
     100                        $sentence = '';
     101       
     102                        foreach($groups as $group) {
     103                                if($me->user_membership($_POST['USERNAME'], $me->ldap_group($group['name']))) {
     104                                        $sentence = $sentence . ', '.$group['name'];
     105                                }
     106                        }
     107                        $template->assign('LD_CHECK_LDAP','<p style="color:green;">Configuration LDAP OK : '.$_POST['USERNAME'].' is in group(s) '.$sentence.' and can auth. He is a '.$me->ldap_status($_POST['USERNAME']).' user according to the plugin.</p>');
     108                }
     109                else {
     110                        $template->assign('LD_CHECK_LDAP','<p style="color:red;">Error : test '.$me->config['uri'].' '.$me->ldap_name($_POST['USERNAME']).'</p>');
     111                }
    54112        }
    55113}
  • extensions/Ldap_Login/admin/configuration.tpl

    r27036 r28534  
    3737                        <input type="text" id="port" name="PORT" value="{$PORT}" />
    3838                </li>
    39         </ul>
     39               
    4040        <i>{'If empty, localhost and standard protocol ports will be used in configuration.'|@translate}</i>
    41     </fieldset>
    42    
    43     <fieldset class="mainConf">
    44         <legend>{'Ldap attributes'|@translate}</legend>
    45         <ul>
     41               
    4642                <li>
    4743                        <label for="basedn">{'Base DN'|@translate}</label>
     
    4945                        <input size="70" type="text" id="basedn" name="BASEDN" value="{$BASEDN}" />
    5046                </li>
     47        </ul>
    5148       
     49    </fieldset>
     50   
     51    <fieldset class="mainConf">
     52        <legend>{'Ldap users'|@translate}</legend>
     53        <ul>
     54                <li>
     55                        <label for="usersbranch">{'Users Branch'|@translate}</label>
     56                        <br>
     57                        <input size="70" type="text" id="usersbranch" name="USERSBRANCH" value="{$USERSBRANCH}" />
     58                </li>
     59               
     60                <li>
     61                        <label for="ld_search_users">
     62                        {if $LD_SEARCH_USERS }
     63                                <input type="checkbox" id="ld_search_users" name="LD_SEARCH_USERS" value="{$LD_SEARCH_USERS}" checked />
     64                        {else}
     65                                <input type="checkbox" id="ld_search_users" name="LD_SEARCH_USERS" value="{$LD_SEARCH_USERS}" />
     66                        {/if}
     67                        {'Search Ldap users ?'|@translate}</label>
     68                </li>
     69               
    5270                <li>
    5371                        <label for="ld_attr">{'Attribute corresponding to the user name'|@translate}</label>
    5472                        <br>
    5573                        <input type="text" id="ld_attr" name="LD_ATTR" value="{$LD_ATTR}" />
     74                </li>
     75        </ul>
     76    </fieldset>
     77   
     78    <fieldset class="mainConf">
     79        <legend>{'Ldap groups'|@translate}</legend>
     80       
     81        <p><i>{'If you create a <a href="admin.php?page=group_list">piwigo group</a> with the same name as an ldap one, all members of the ldap group will automatically join the piwigo group at their next authentication. This allows you to create <a href="admin.php?page=help&section=groups">specific right access management</a> (restrict access to a particaular album...).'|@translate}</i></p>
     82        <ul>
     83               
     84                <li>
     85                        <label for="groupbranch">{'Groups Branch'|@translate}</label>
     86                        <br>
     87                        <input size="70" type="text" id="groupbranch" name="GROUPBRANCH" value="{$GROUPBRANCH}" />
     88                </li>
     89               
     90                <li>
     91                        <label for="ld_search_groups">
     92                        {if $LD_SEARCH_GROUPS }
     93                                <input type="checkbox" id="ld_search_groups" name="LD_SEARCH_GROUPS" value="{$LD_SEARCH_GROUPS}" checked />
     94                        {else}
     95                                <input type="checkbox" id="ld_search_groups" name="LD_SEARCH_GROUPS" value="{$LD_SEARCH_GROUPS}" />
     96                        {/if}
     97                        {'Search Ldap groups ?'|@translate}</label>
     98                </li>
     99       
     100                <li>
     101                        <label for="ld_attr">{'Attribute corresponding to the group name'|@translate}</label>
     102                        <br>
     103                        <input type="text" id="ld_group" name="LD_GROUP" value="{$LD_GROUP}" />
     104                </li>
     105                <br>
     106               
     107                <li>
     108                        <label for="webmasters_group">{'Webmasters group'|@translate}</label>
     109                        <br>
     110                        {'Users members of this ldap group are granted piwigo webmasters.'|@translate}<br>
     111                        <input size="70" type="text" id="webmasters_group" name="WEBMASTERS_GROUP" value="{$WEBMASTERS_GROUP}" />
     112                </li>
     113               
     114                <li>
     115                        <label for="admins_group">{'Admins group'|@translate}</label>
     116                        <br>
     117                        {'Users members of this ldap group are granted piwigo admins.'|@translate}<br>
     118                        <input size="70" type="text" id="admins_group" name="ADMINS_GROUP" value="{$ADMINS_GROUP}" />
     119                       
     120                        <br><br>
     121                       
     122                        {'To get them out of these roles, they must be sorted of the ldap group and then role updated in the <a href="admin.php?page=user_list">piwigo admin</a>. If a group is mandatory as described in the <a href="admin.php?page=plugin-Ldap_Login-newusers">new piwigo users tab</a>, then they must also belong to the users group.'|@translate}
    56123                </li>
    57124        </ul>
  • extensions/Ldap_Login/admin/newusers.php

    r27284 r28534  
    1717$template->assign('SEND_CASUAL_MAIL',   $me->config['send_password_by_mail_ldap']);
    1818
     19$template->assign('USERS_GROUP',        $me->config['users_group']);
     20
    1921if (isset($_POST['save'])){
     22
     23        $me->config['users_group'] = $_POST['USERS_GROUP'];
    2024
    2125        if (isset($_POST['ALLOW_NEWUSERS'])){
  • extensions/Ldap_Login/admin/newusers.tpl

    r27036 r28534  
    2828        {'Do you allow new piwigo users to be created when users authenticate succesfully on the ldap ?'|@translate}
    2929    </p>
    30 
     30   
     31    <p>
     32                <b><label for="users_group">{'Users group'|@translate}</label></b>
     33                <br>
     34                {'Users members of this ldap group (e.g.: piwigo,users ... , default is void ) can authenticate on piwigo and are created if the option above is selected. If left blank, everyone can authenticate.'|@translate}
     35                <input size="70" type="text" id="users_group" name="USERS_GROUP" value="{$USERS_GROUP}" />
     36        </p>
     37   
    3138    <p>
    3239        {if $ADVERTISE_ADMINS}
     
    4855   
    4956</fieldset>
    50  
     57
    5158<p>
    5259<input type="submit" value="{'Save'|@translate}" name="save" />
Note: See TracChangeset for help on using the changeset viewer.