Plugin Directory

Changeset 1896164


Ignore:
Timestamp:
06/21/2018 12:34:21 AM (8 years ago)
Author:
george_michael
Message:

Adding version 1.0.2. Upgrade strongly suggested.

Location:
lock-by-ldap-query
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • lock-by-ldap-query/tags/1.0.2/lock-by-ldap-query.php

    r1217309 r1896164  
    22/**
    33 * @package Lock-By-LDAP-Query
    4  * @version 1.0.1
     4 * @version 1.0.2
    55 */
    66/*
     
    99Description: Lock a page down so that it can only be viewed by certain LDAP groups
    1010Author: Michael George
    11 Version: 1.0.1
     11Version: 1.0.2
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    106106                            }
    107107                            if ( $bind ) {
    108                                 $sr = ldap_search( $ldap, $devOptions['searchbase'], $ldapquery[0], array( $devOptions['loginfield'] ), 0, 2000 );
     108                                //If query is already enclosed in parenthesis, only modify enough to add username to search for
     109                                if ( strpos( $ldapquery[0], "(" ) === 0 ) {
     110                                    $query = "(&" . $ldapquery[0] . "(" . $devOptions['loginfield'] . "=" . $wpUser->user_login . "))";
     111                                }
     112                                //Otherwise add parens and username
     113                                else {
     114                                    $query = "(&(" . $ldapquery[0] . ")(" . $devOptions['loginfield'] . "=" . $wpUser->user_login . "))";
     115                                }
     116                                $sr = ldap_search( $ldap, $devOptions['searchbase'], $query, array( $devOptions['loginfield'] ), 0, 1 );
    109117                                if ( $sr === false ) {
    110118                                    $content = "<h3>Access Denied</h3>\r";
     
    114122                                    $info = ldap_get_entries( $ldap, $sr );
    115123                                    if ( $info['count'] != 0 ) {
    116                                         foreach ( $info as $user ) {
    117                                             if ( isset( $user[strtolower( $devOptions['loginfield'] )][0] ) ) {
    118                                                 if ( strtolower( $user[strtolower( $devOptions['loginfield'] )][0] ) == strtolower( $wpUser->user_login ) ) {
    119                                                     return $content;
    120                                                 }
    121                                             }
    122                                         }
     124                                        return $content;
     125                                    } else {
    123126                                        $content = "<h3>Access Denied</h3>\r";
    124                                         $content .= "<p>Access to this document is limited to certain users. You, however, are not one of them.</p>\r";
     127                                        $content .= "<p>Access to this document is limited to certain users. However, no users met the LDAP search criteria.</p>\r";
    125128                                        if ( count( $optionaltext ) > 0 ) {
    126129                                            $content .= $optionaltext[0];
    127130                                        }
    128                                     } else {
    129                                         $content = "<h3>Access Denied</h3>\r";
    130                                         $content .= "<p>Access to this document is limited to certain users. However, no users met the LDAP search criteria.</p>\r";
    131131                                    }
    132132                                }
     
    184184?>
    185185<div id="lock-by-ldap-query_option_page" style="width:80%">
    186 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
    187 <input type='hidden' name='update_lblqSettings' value='1'>
    188 <h2>Lock By LDAP Query Settings</h2><?php
    189             echo "<h3 style='margin-bottom: -5px;'>LDAP Host</h3>\r";
    190             echo "<p><input id='lockByLDAPQuery_bindhost' type='text' name='lockByLDAPQuery_bindhost' value='" . $devOptions['bindhost'] . "' style='width: 250px;'><br>\r";
    191             echo "The name or IP address of the LDAP server. The protocol should be left out. (e.g., ldap.example.com)</p>\r";
    192             echo "<h3 style='margin-bottom: -5px;'>Search Base</h3>\r";
    193             echo "<p><input id='lockByLDAPQuery_searchbase' type='text' name='lockByLDAPQuery_searchbase' value='" . $devOptions['searchbase'] . "' style='width: 250px;'><br>\r";
    194             echo "The base DN in which to carry out LDAP searches.</p>\r";
    195             echo "<h3 style='margin-bottom: -5px;'>Login Field</h3>\r";
    196             echo "<p><input id='lockByLDAPQuery_loginfield' type='text' name='lockByLDAPQuery_loginfield' value='" . $devOptions['loginfield'] . "' style='width: 250px;'><br>\r";
    197             echo "The attribute in LDAP that needs to match the WP login name. (e.g., sAMAccountName if using AD)</p>\r";
    198             echo "<h3 style='margin-bottom: -5px;'>LDAP Bind User</h3>\r";
    199             echo "<p><input id='lockByLDAPQuery_binduser' type='text' name='lockByLDAPQuery_binduser' value='" . $devOptions['binduser'] . "' style='width: 250px;'><br>\r";
    200             echo "Leave blank for anonymous bind. Should be in DN format.</p>\r";
    201             echo "<h3 style='margin-bottom: -5px;'>LDAP Bind Password</h3>\r";
    202             echo "<p><input id='lockByLDAPQuery_bindpassword' type='password' name='lockByLDAPQuery_bindpassword' value='" . $devOptions['bindpassword'] . "' style='width: 250px;'><br>\r";
    203             echo "The password for the user above.</p>\r";
    204             echo "<h3 style='margin-bottom: -5px;'>Use SSL</h3>\r";
    205             echo "<p><input id='lockByLDAPQuery_usessl' type='checkbox' name='lockByLDAPQuery_usessl' value='true'". ( $devOptions['usessl'] ? " checked" : "" ) . "> Enabled<br>\r";
    206             echo "Default is disabled (no SSL).</p>\r";
    207             echo "<h3 style='margin-bottom: -5px;'>Use LDAP_OPT_REFERRALS = 1</h3>\r";
    208             echo "<p><input id='lockByLDAPQuery_referrals' type='checkbox' name='lockByLDAPQuery_referrals' value='true'". ( $devOptions['referrals'] ? " checked" : "" ) . "> Enabled<br>\r";
    209             echo "Setting to disabled is often necessary when using Active Directory.</p>\r";
    210             echo "<h3 style='margin-bottom: -5px;'>Use LDAP V3</h3>\r";
    211             echo "<p><input id='lockByLDAPQuery_protocolversion3' type='checkbox' name='lockByLDAPQuery_protocolversion3' value='true'". ( $devOptions['protocolversion3'] ? " checked" : "" ) . "> Enabled<br>\r";
    212             echo "Default is enabled.</p>\r";
    213             echo "<input type='submit' value='Save'>\r";
    214 ?></form>
    215 </div><?php
     186    <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
     187        <input type='hidden' name='update_lblqSettings' value='1'>
     188        <h2>Lock By LDAP Query Settings</h2>
     189        <p>
     190            <label for='lockByLDAPQuery_bindhost' style='font-size: larger; font-weight: bold;'>LDAP Host</label>
     191            <br />
     192            <input id='lockByLDAPQuery_bindhost' type='text' name='lockByLDAPQuery_bindhost' value='<?php echo $devOptions['bindhost'];?>' style='width: 250px;'>
     193            <br />
     194            The name or IP address of the LDAP server. The protocol should be left out. (e.g., ldap.example.com)
     195        </p>
     196        <p>
     197            <label for='lockByLDAPQuery_searchbase' style='font-size: larger; font-weight: bold;'>Search Base</label>
     198            <br />
     199            <input id='lockByLDAPQuery_searchbase' type='text' name='lockByLDAPQuery_searchbase' value='<?php echo $devOptions['searchbase'];?>' style='width: 250px;'>
     200            <br />
     201            The base DN in which to carry out LDAP searches.
     202        </p>
     203        <p>
     204            <label for='lockByLDAPQuery_loginfield' style='font-size: larger; font-weight: bold;'>Login Attribute</label>
     205            <br />
     206            <input id='lockByLDAPQuery_loginfield' type='text' name='lockByLDAPQuery_loginfield' value='<?php echo $devOptions['loginfield'];?>' style='width: 250px;'>
     207            <br />
     208            The attribute in LDAP that needs to match the WP login name. (e.g., sAMAccountName if using AD)
     209        </p>
     210        <p>
     211            <label for='lockByLDAPQuery_binduser' style='font-size: larger; font-weight: bold;'>LDAP Bind User</label>
     212            <br />
     213            <input id='lockByLDAPQuery_binduser' type='text' name='lockByLDAPQuery_binduser' value='<?php echo $devOptions['binduser'];?>' style='width: 250px;'>
     214            <br />
     215            Leave blank for anonymous bind. Should be in DN format.
     216        </p>
     217        <p>
     218            <label for='lockByLDAPQuery_bindpassword' style='font-size: larger; font-weight: bold;'>LDAP Bind Password</label>
     219            <br />
     220            <input id='lockByLDAPQuery_bindpassword' type='password' name='lockByLDAPQuery_bindpassword' value='<?php echo $devOptions['bindpassword'];?>' style='width: 250px;'>
     221            <br />
     222            The password for the user above.
     223        </p>
     224        <p>
     225            <label for='lockByLDAPQuery_usessl' style='font-size: larger; font-weight: bold;'>Use SSL</label>
     226            <br />
     227            <input id='lockByLDAPQuery_usessl' type='checkbox' name='lockByLDAPQuery_usessl' value='true'<?php echo ( $devOptions['usessl'] ? " checked" : "" );?>> Enabled
     228            <br />
     229            Default is disabled (no SSL).
     230        </p>
     231        <p>
     232            <label for='lockByLDAPQuery_referrals' style='font-size: larger; font-weight: bold;'>Use LDAP_OPT_REFERRALS = 1</label>
     233            <br />
     234            <input id='lockByLDAPQuery_referrals' type='checkbox' name='lockByLDAPQuery_referrals' value='true'<?php echo ( $devOptions['referrals'] ? " checked" : "" );?>> Enabled
     235            <br />
     236            Setting to disabled is often necessary when using Active Directory.
     237        </p>
     238        <p>
     239            <label for='lockByLDAPQuery_protocolversion3' style='font-size: larger; font-weight: bold;'>Use LDAP V3</label>
     240            <br />
     241            <input id='lockByLDAPQuery_protocolversion3' type='checkbox' name='lockByLDAPQuery_protocolversion3' value='true'<?php echo ( $devOptions['protocolversion3'] ? " checked" : "" );?>> Enabled
     242            <br />
     243            Default is enabled.
     244        </p>
     245        <input type='submit' value='Save'>
     246    </form>
     247</div>
     248<?php
    216249        } //End function lblqPrintAdminPage()
    217250
  • lock-by-ldap-query/tags/1.0.2/readme.txt

    r1217309 r1896164  
    44Tags:
    55Requires at least: 3.5.2
    6 Tested up to: 4.3.0
    7 Stable tag: 1.0.1
     6Tested up to: 4.9.6
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636== Changelog ==
    3737
     38= 1.0.2 =
     39* Re-worked internal query mechanism to fix a bug when large result sets were returned. Should increase performance, too.
     40
    3841= 1.0.1 =
    3942* Removed PHP4 constructor from class as WP 4.3 deprecated that type of constructor.
     
    4447== Upgrade Notice ==
    4548
     49= 1.0.2 =
     50* All users should upgrade.
     51
    4652= 1.0.1 =
    4753* Required upgrade if using WP 4.3.
  • lock-by-ldap-query/trunk/lock-by-ldap-query.php

    r1217309 r1896164  
    22/**
    33 * @package Lock-By-LDAP-Query
    4  * @version 1.0.1
     4 * @version 1.0.2
    55 */
    66/*
     
    99Description: Lock a page down so that it can only be viewed by certain LDAP groups
    1010Author: Michael George
    11 Version: 1.0.1
     11Version: 1.0.2
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    106106                            }
    107107                            if ( $bind ) {
    108                                 $sr = ldap_search( $ldap, $devOptions['searchbase'], $ldapquery[0], array( $devOptions['loginfield'] ), 0, 2000 );
     108                                //If query is already enclosed in parenthesis, only modify enough to add username to search for
     109                                if ( strpos( $ldapquery[0], "(" ) === 0 ) {
     110                                    $query = "(&" . $ldapquery[0] . "(" . $devOptions['loginfield'] . "=" . $wpUser->user_login . "))";
     111                                }
     112                                //Otherwise add parens and username
     113                                else {
     114                                    $query = "(&(" . $ldapquery[0] . ")(" . $devOptions['loginfield'] . "=" . $wpUser->user_login . "))";
     115                                }
     116                                $sr = ldap_search( $ldap, $devOptions['searchbase'], $query, array( $devOptions['loginfield'] ), 0, 1 );
    109117                                if ( $sr === false ) {
    110118                                    $content = "<h3>Access Denied</h3>\r";
     
    114122                                    $info = ldap_get_entries( $ldap, $sr );
    115123                                    if ( $info['count'] != 0 ) {
    116                                         foreach ( $info as $user ) {
    117                                             if ( isset( $user[strtolower( $devOptions['loginfield'] )][0] ) ) {
    118                                                 if ( strtolower( $user[strtolower( $devOptions['loginfield'] )][0] ) == strtolower( $wpUser->user_login ) ) {
    119                                                     return $content;
    120                                                 }
    121                                             }
    122                                         }
     124                                        return $content;
     125                                    } else {
    123126                                        $content = "<h3>Access Denied</h3>\r";
    124                                         $content .= "<p>Access to this document is limited to certain users. You, however, are not one of them.</p>\r";
     127                                        $content .= "<p>Access to this document is limited to certain users. However, no users met the LDAP search criteria.</p>\r";
    125128                                        if ( count( $optionaltext ) > 0 ) {
    126129                                            $content .= $optionaltext[0];
    127130                                        }
    128                                     } else {
    129                                         $content = "<h3>Access Denied</h3>\r";
    130                                         $content .= "<p>Access to this document is limited to certain users. However, no users met the LDAP search criteria.</p>\r";
    131131                                    }
    132132                                }
     
    184184?>
    185185<div id="lock-by-ldap-query_option_page" style="width:80%">
    186 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
    187 <input type='hidden' name='update_lblqSettings' value='1'>
    188 <h2>Lock By LDAP Query Settings</h2><?php
    189             echo "<h3 style='margin-bottom: -5px;'>LDAP Host</h3>\r";
    190             echo "<p><input id='lockByLDAPQuery_bindhost' type='text' name='lockByLDAPQuery_bindhost' value='" . $devOptions['bindhost'] . "' style='width: 250px;'><br>\r";
    191             echo "The name or IP address of the LDAP server. The protocol should be left out. (e.g., ldap.example.com)</p>\r";
    192             echo "<h3 style='margin-bottom: -5px;'>Search Base</h3>\r";
    193             echo "<p><input id='lockByLDAPQuery_searchbase' type='text' name='lockByLDAPQuery_searchbase' value='" . $devOptions['searchbase'] . "' style='width: 250px;'><br>\r";
    194             echo "The base DN in which to carry out LDAP searches.</p>\r";
    195             echo "<h3 style='margin-bottom: -5px;'>Login Field</h3>\r";
    196             echo "<p><input id='lockByLDAPQuery_loginfield' type='text' name='lockByLDAPQuery_loginfield' value='" . $devOptions['loginfield'] . "' style='width: 250px;'><br>\r";
    197             echo "The attribute in LDAP that needs to match the WP login name. (e.g., sAMAccountName if using AD)</p>\r";
    198             echo "<h3 style='margin-bottom: -5px;'>LDAP Bind User</h3>\r";
    199             echo "<p><input id='lockByLDAPQuery_binduser' type='text' name='lockByLDAPQuery_binduser' value='" . $devOptions['binduser'] . "' style='width: 250px;'><br>\r";
    200             echo "Leave blank for anonymous bind. Should be in DN format.</p>\r";
    201             echo "<h3 style='margin-bottom: -5px;'>LDAP Bind Password</h3>\r";
    202             echo "<p><input id='lockByLDAPQuery_bindpassword' type='password' name='lockByLDAPQuery_bindpassword' value='" . $devOptions['bindpassword'] . "' style='width: 250px;'><br>\r";
    203             echo "The password for the user above.</p>\r";
    204             echo "<h3 style='margin-bottom: -5px;'>Use SSL</h3>\r";
    205             echo "<p><input id='lockByLDAPQuery_usessl' type='checkbox' name='lockByLDAPQuery_usessl' value='true'". ( $devOptions['usessl'] ? " checked" : "" ) . "> Enabled<br>\r";
    206             echo "Default is disabled (no SSL).</p>\r";
    207             echo "<h3 style='margin-bottom: -5px;'>Use LDAP_OPT_REFERRALS = 1</h3>\r";
    208             echo "<p><input id='lockByLDAPQuery_referrals' type='checkbox' name='lockByLDAPQuery_referrals' value='true'". ( $devOptions['referrals'] ? " checked" : "" ) . "> Enabled<br>\r";
    209             echo "Setting to disabled is often necessary when using Active Directory.</p>\r";
    210             echo "<h3 style='margin-bottom: -5px;'>Use LDAP V3</h3>\r";
    211             echo "<p><input id='lockByLDAPQuery_protocolversion3' type='checkbox' name='lockByLDAPQuery_protocolversion3' value='true'". ( $devOptions['protocolversion3'] ? " checked" : "" ) . "> Enabled<br>\r";
    212             echo "Default is enabled.</p>\r";
    213             echo "<input type='submit' value='Save'>\r";
    214 ?></form>
    215 </div><?php
     186    <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
     187        <input type='hidden' name='update_lblqSettings' value='1'>
     188        <h2>Lock By LDAP Query Settings</h2>
     189        <p>
     190            <label for='lockByLDAPQuery_bindhost' style='font-size: larger; font-weight: bold;'>LDAP Host</label>
     191            <br />
     192            <input id='lockByLDAPQuery_bindhost' type='text' name='lockByLDAPQuery_bindhost' value='<?php echo $devOptions['bindhost'];?>' style='width: 250px;'>
     193            <br />
     194            The name or IP address of the LDAP server. The protocol should be left out. (e.g., ldap.example.com)
     195        </p>
     196        <p>
     197            <label for='lockByLDAPQuery_searchbase' style='font-size: larger; font-weight: bold;'>Search Base</label>
     198            <br />
     199            <input id='lockByLDAPQuery_searchbase' type='text' name='lockByLDAPQuery_searchbase' value='<?php echo $devOptions['searchbase'];?>' style='width: 250px;'>
     200            <br />
     201            The base DN in which to carry out LDAP searches.
     202        </p>
     203        <p>
     204            <label for='lockByLDAPQuery_loginfield' style='font-size: larger; font-weight: bold;'>Login Attribute</label>
     205            <br />
     206            <input id='lockByLDAPQuery_loginfield' type='text' name='lockByLDAPQuery_loginfield' value='<?php echo $devOptions['loginfield'];?>' style='width: 250px;'>
     207            <br />
     208            The attribute in LDAP that needs to match the WP login name. (e.g., sAMAccountName if using AD)
     209        </p>
     210        <p>
     211            <label for='lockByLDAPQuery_binduser' style='font-size: larger; font-weight: bold;'>LDAP Bind User</label>
     212            <br />
     213            <input id='lockByLDAPQuery_binduser' type='text' name='lockByLDAPQuery_binduser' value='<?php echo $devOptions['binduser'];?>' style='width: 250px;'>
     214            <br />
     215            Leave blank for anonymous bind. Should be in DN format.
     216        </p>
     217        <p>
     218            <label for='lockByLDAPQuery_bindpassword' style='font-size: larger; font-weight: bold;'>LDAP Bind Password</label>
     219            <br />
     220            <input id='lockByLDAPQuery_bindpassword' type='password' name='lockByLDAPQuery_bindpassword' value='<?php echo $devOptions['bindpassword'];?>' style='width: 250px;'>
     221            <br />
     222            The password for the user above.
     223        </p>
     224        <p>
     225            <label for='lockByLDAPQuery_usessl' style='font-size: larger; font-weight: bold;'>Use SSL</label>
     226            <br />
     227            <input id='lockByLDAPQuery_usessl' type='checkbox' name='lockByLDAPQuery_usessl' value='true'<?php echo ( $devOptions['usessl'] ? " checked" : "" );?>> Enabled
     228            <br />
     229            Default is disabled (no SSL).
     230        </p>
     231        <p>
     232            <label for='lockByLDAPQuery_referrals' style='font-size: larger; font-weight: bold;'>Use LDAP_OPT_REFERRALS = 1</label>
     233            <br />
     234            <input id='lockByLDAPQuery_referrals' type='checkbox' name='lockByLDAPQuery_referrals' value='true'<?php echo ( $devOptions['referrals'] ? " checked" : "" );?>> Enabled
     235            <br />
     236            Setting to disabled is often necessary when using Active Directory.
     237        </p>
     238        <p>
     239            <label for='lockByLDAPQuery_protocolversion3' style='font-size: larger; font-weight: bold;'>Use LDAP V3</label>
     240            <br />
     241            <input id='lockByLDAPQuery_protocolversion3' type='checkbox' name='lockByLDAPQuery_protocolversion3' value='true'<?php echo ( $devOptions['protocolversion3'] ? " checked" : "" );?>> Enabled
     242            <br />
     243            Default is enabled.
     244        </p>
     245        <input type='submit' value='Save'>
     246    </form>
     247</div>
     248<?php
    216249        } //End function lblqPrintAdminPage()
    217250
  • lock-by-ldap-query/trunk/readme.txt

    r1217309 r1896164  
    44Tags:
    55Requires at least: 3.5.2
    6 Tested up to: 4.3.0
    7 Stable tag: 1.0.1
     6Tested up to: 4.9.6
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636== Changelog ==
    3737
     38= 1.0.2 =
     39* Re-worked internal query mechanism to fix a bug when large result sets were returned. Should increase performance, too.
     40
    3841= 1.0.1 =
    3942* Removed PHP4 constructor from class as WP 4.3 deprecated that type of constructor.
     
    4447== Upgrade Notice ==
    4548
     49= 1.0.2 =
     50* All users should upgrade.
     51
    4652= 1.0.1 =
    4753* Required upgrade if using WP 4.3.
Note: See TracChangeset for help on using the changeset viewer.