mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 02:39:47 +02:00
fix 1201 and rewrite LDAP class
and ran php-cs-fixer as told in the wiki
This commit is contained in:
parent
b6a8e86f05
commit
6cbf700151
77 changed files with 105 additions and 143 deletions
|
@ -208,4 +208,3 @@ switch ($_REQUEST['action']) {
|
|||
require_once 'templates/show_install_lang.inc.php';
|
||||
break;
|
||||
} // end action switch
|
||||
|
||||
|
|
|
@ -249,4 +249,3 @@ class Ajax
|
|||
self::$include_override = false;
|
||||
} // end_container
|
||||
} // end Ajax class
|
||||
|
||||
|
|
|
@ -1085,4 +1085,3 @@ class Album extends database_object implements library_item
|
|||
return $results;
|
||||
}
|
||||
} //end of album class
|
||||
|
||||
|
|
|
@ -378,4 +378,3 @@ class Ampache_RSS
|
|||
return $element['date'];
|
||||
} // pubdate_recently_played
|
||||
} // end Ampache_RSS class
|
||||
|
||||
|
|
|
@ -143,4 +143,3 @@ class AmpError
|
|||
}
|
||||
} // auto_init
|
||||
} // Error
|
||||
|
||||
|
|
|
@ -1120,4 +1120,3 @@ class Api
|
|||
}
|
||||
} // friends_timeline
|
||||
} // API class
|
||||
|
||||
|
|
|
@ -1775,4 +1775,3 @@ class Art extends database_object
|
|||
return true;
|
||||
}
|
||||
} // Art
|
||||
|
||||
|
|
|
@ -917,4 +917,3 @@ class Artist extends database_object implements library_item
|
|||
return $deleted;
|
||||
}
|
||||
} // end of artist class
|
||||
|
||||
|
|
|
@ -86,4 +86,3 @@ class Artist_Event
|
|||
return false;
|
||||
}
|
||||
} // end of recommendation class
|
||||
|
||||
|
|
|
@ -153,4 +153,3 @@ class Bookmark extends database_object
|
|||
$f_user = $user->username;
|
||||
}
|
||||
} //end bookmark class
|
||||
|
||||
|
|
|
@ -423,4 +423,3 @@ class Broadcast extends database_object implements library_item
|
|||
return $oid;
|
||||
}
|
||||
} // end of broadcast class
|
||||
|
||||
|
|
|
@ -439,4 +439,3 @@ class Broadcast_Server implements MessageComponentInterface
|
|||
return $websocket_address . '/broadcast';
|
||||
}
|
||||
} // end of broadcast_server class
|
||||
|
||||
|
|
|
@ -587,4 +587,3 @@ class Browse extends Query
|
|||
return $css;
|
||||
}
|
||||
} // browse
|
||||
|
||||
|
|
|
@ -2409,4 +2409,3 @@ abstract class Catalog extends database_object
|
|||
}
|
||||
|
||||
// end of catalog class
|
||||
|
||||
|
|
|
@ -547,4 +547,3 @@ class Channel extends database_object implements media, library_item
|
|||
return($s);
|
||||
}
|
||||
} // end of channel class
|
||||
|
||||
|
|
|
@ -134,4 +134,3 @@ class Clip extends Video
|
|||
return null;
|
||||
}
|
||||
} // Clip class
|
||||
|
||||
|
|
|
@ -392,4 +392,3 @@ class Core
|
|||
return $tmp_dir;
|
||||
}
|
||||
} // Core
|
||||
|
||||
|
|
|
@ -139,4 +139,3 @@ abstract class database_object
|
|||
self::$_enabled = AmpConfig::get('memory_cache');
|
||||
} // _auto_init
|
||||
} // end database_object
|
||||
|
||||
|
|
|
@ -649,4 +649,3 @@ class Democratic extends Tmp_Playlist
|
|||
return $voters;
|
||||
} // get_voters
|
||||
} // Democratic class
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class LDAPException extends Exception
|
|||
*/
|
||||
public function __construct ($message)
|
||||
{
|
||||
if (is_int (message)) {
|
||||
if (is_int ($message)) {
|
||||
$message = 'LDAP error: [' . $message . '] ' . ldap_err2str($message);
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,98 @@ class LDAP
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Connect to the LDAP
|
||||
* Note: This does not open a connection. It checks whether
|
||||
* the given parameters are plausibe and can be used to open a
|
||||
* connection as soon as one is needed.
|
||||
*/
|
||||
private static function connect ()
|
||||
{
|
||||
if (! $url = AmpConfig::get('ldap_url')) {
|
||||
throw new LDAPException('Required configuration value missing: ldap_url');
|
||||
}
|
||||
|
||||
if (! $link = ldap_connect ($url)) {
|
||||
throw new LDAPException('Could not connect to ' . $url);
|
||||
}
|
||||
|
||||
$protocol_version = AmpConfig::get('ldap_protocol_version', 3);
|
||||
if (! ldap_set_option ($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version)) {
|
||||
throw new LDAPException('Could not set option PROTOCOL_VERSION to ' . $protocol_version);
|
||||
}
|
||||
|
||||
if (AmpConfig::get('ldap_start_tls', "false") != "false") {
|
||||
if (! ldap_start_tls ($link)) {
|
||||
throw new LDAPException('Could not use StartTLS');
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds to the LDAP
|
||||
*/
|
||||
private static function bind ($link, $username = null, $password = null)
|
||||
{
|
||||
if ($username === null && $password === null) {
|
||||
$username = AmpConfig::get('ldap_username', '');
|
||||
$password = AmpConfig::get('ldap_password', '');
|
||||
}
|
||||
|
||||
if (! ldap_bind ($link, $ampache_username, $ampache_password)) {
|
||||
throw new LDAPException("Could not bind to server using username `$username`");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds from the LDAP
|
||||
*/
|
||||
private static function unbind ($link)
|
||||
{
|
||||
ldap_unbind ($link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read attributes for a DN from the LDAP
|
||||
*/
|
||||
private static function read ($link, $dn, $attrs = [], $filter='objectClass=*')
|
||||
{
|
||||
if (! $result = ldap_read ($link, $dn, $filter, $attrs)) {
|
||||
$attrs = json_encode ($attrs);
|
||||
throw new LDAPException("Could not read attributes `$attrs` for dn `$dn`");
|
||||
}
|
||||
|
||||
if (! $infos = ldap_get_entries ($link, $result)) {
|
||||
throw new LDAPException("Empty search result for dn `$dn`");
|
||||
}
|
||||
|
||||
return $infos[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search for a DN in the LDAP
|
||||
*/
|
||||
private static function search ($link, $base_dn, $filter)
|
||||
{
|
||||
if (! $result = ldap_search ($link, $base_dn, $filter)) {
|
||||
throw new LDAPException(ldap_errno($link));
|
||||
}
|
||||
|
||||
if (! $entries = ldap_get_entries ($link, $result)) {
|
||||
throw new LDAPException("Empty search results for filter `$filter`");
|
||||
}
|
||||
|
||||
return $entries[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ldap_auth
|
||||
*
|
||||
|
@ -79,46 +171,8 @@ class LDAP
|
|||
public static function auth ($username, $password)
|
||||
{
|
||||
try {
|
||||
/* Connect to the LDAP
|
||||
Note: This does not open a connection. It checks whether
|
||||
the given parameters are plausibe and can be used to open a
|
||||
connection as soon as one is needed. */
|
||||
|
||||
if (! $url = AmpConfig::get('ldap_url')) {
|
||||
throw new LDAPException('Required configuration value missing: ldap_url');
|
||||
}
|
||||
|
||||
if (! $link = ldap_connect ($url)) {
|
||||
throw new LDAPException('Could not connect to ' . $url);
|
||||
}
|
||||
|
||||
/* Set the LDAP protocol version (default: 3) */
|
||||
|
||||
$protocol_version = AmpConfig::get('ldap_protocol_version', 3);
|
||||
if (! ldap_set_option ($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version)) {
|
||||
throw new LDAPException('Could not set option PROTOCOL_VERSION to ' . $protocol_version);
|
||||
}
|
||||
|
||||
/* Use StartTLS if asked */
|
||||
|
||||
if (AmpConfig::get('ldap_start_tls', "false") != "false") {
|
||||
if (! ldap_start_tls ($link)) {
|
||||
throw new LDAPException('Could not use StartTLS');
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect to the LDAP using the given username and password.
|
||||
If these parameters do not exist, an anonymous connection
|
||||
will be used */
|
||||
|
||||
$ampache_username = AmpConfig::get('ldap_username');
|
||||
$ampache_password = AmpConfig::get('ldap_password');
|
||||
|
||||
if (! ldap_bind ($link, $ampache_username, $ampache_password)) {
|
||||
throw new LDAPException('Could not bind to server using username `'
|
||||
. $ampache_username . '` and password `'
|
||||
. $ampache_password . '`');
|
||||
}
|
||||
$link = self::connect ();
|
||||
self::bind($link);
|
||||
|
||||
/* Search for the user with given base_dn, filter, objectclass and username */
|
||||
|
||||
|
@ -143,43 +197,25 @@ class LDAP
|
|||
throw new LDAPException('Required configuration value missing: ldap_search_dn');
|
||||
}
|
||||
|
||||
if (! $result = ldap_search ($link, $base_dn, $search)) {
|
||||
throw new LDAPException(ldap_errno($link));
|
||||
}
|
||||
|
||||
/* Bind with the user's DN and the password */
|
||||
|
||||
if (! $user_entry = ldap_first_entry ($link, $result)) {
|
||||
throw new LDAPException('Empty search result');
|
||||
}
|
||||
$user_entry = self::search ($link, $base_dn, $search);
|
||||
|
||||
if (! $user_dn = ldap_get_dn ($link, $user_entry)) {
|
||||
throw new LDAPException(ldap_errno($link));
|
||||
}
|
||||
|
||||
$user_entry = ldap_get_entries ($link, $result) [0];
|
||||
|
||||
if (! ldap_bind ($link, $user_dn, $password)) {
|
||||
throw new LDAPException('Wrong password');
|
||||
}
|
||||
self::bind ($link, $user_dn, $password);
|
||||
|
||||
/* Test if the user is in the required group (optional) */
|
||||
|
||||
if ($group_dn = AmpConfig::get('ldap_require_group')) {
|
||||
$member_attribute = AmpConfig::get('ldap_member_attribute', 'member');
|
||||
|
||||
if (! $group_result = ldap_read ($link, $group_dn, 'objectClass=*', [$member_attribute])) {
|
||||
throw new LDAPException("Could not read member attribute `$member_attribute`"
|
||||
. " for group `$group_dn`");
|
||||
}
|
||||
$group_infos = self::read ($link, $group_dn, [$member_attribute]);
|
||||
|
||||
if (! $group_infos = ldap_get_entries ($link, $group_result) [0]) {
|
||||
throw new LDAPException('Empty group search result');
|
||||
}
|
||||
|
||||
if (! in_array ($username, $group_infos[$member_attribute])) {
|
||||
throw new LDAPException("`$username` is not member of the group `$group_dn`");
|
||||
}
|
||||
/* if (! in_array ($username, $group_infos[$member_attribute])) { */
|
||||
if (! preg_grep("/^$user_dn\$/i", $group_infos[$member_attribute])) {
|
||||
throw new LDAPException("`$username` is not member of the group `$group_dn`");
|
||||
}
|
||||
}
|
||||
|
||||
/* Obtain name and email field. Reconstruct name field to allow
|
||||
|
@ -212,7 +248,9 @@ class LDAP
|
|||
];
|
||||
}
|
||||
|
||||
ldap_unbind ($link);
|
||||
if (isset ($link)) {
|
||||
self::unbind ($link);
|
||||
}
|
||||
|
||||
debug_event('LDAP', 'Return value of authentication: ' . json_encode($return_value), 6);
|
||||
|
||||
|
|
|
@ -43,4 +43,3 @@ interface library_item extends playable_item
|
|||
|
||||
public static function gc();
|
||||
} // end interface
|
||||
|
||||
|
|
|
@ -146,4 +146,3 @@ class License
|
|||
return $results;
|
||||
} // get_licenses
|
||||
} // License class
|
||||
|
||||
|
|
|
@ -344,4 +344,3 @@ class Live_Stream extends database_object implements media, library_item
|
|||
// Do nothing
|
||||
}
|
||||
} //end of radio class
|
||||
|
||||
|
|
|
@ -636,4 +636,3 @@ class Localplay
|
|||
return $track_name;
|
||||
} // get_user_playing
|
||||
} // end localplay class
|
||||
|
||||
|
|
|
@ -107,4 +107,3 @@ abstract class localplay_controller
|
|||
return $data;
|
||||
} // parse_url
|
||||
} // end localplay_controller interface
|
||||
|
||||
|
|
|
@ -208,4 +208,3 @@ class Mailer
|
|||
return $this->send($mail);
|
||||
}
|
||||
} // Mailer class
|
||||
|
||||
|
|
|
@ -63,4 +63,3 @@ interface media
|
|||
|
||||
public function set_played($user, $agent, $location);
|
||||
} // end interface
|
||||
|
||||
|
|
|
@ -157,4 +157,3 @@ class Movie extends Video
|
|||
return $deleted;
|
||||
}
|
||||
} // Movie class
|
||||
|
||||
|
|
|
@ -76,4 +76,3 @@ class Openid
|
|||
return $policies;
|
||||
}
|
||||
} // end of Openid class
|
||||
|
||||
|
|
|
@ -112,4 +112,3 @@ class Personal_Video extends Video
|
|||
return $deleted;
|
||||
}
|
||||
} // Personal_Video class
|
||||
|
||||
|
|
|
@ -79,4 +79,3 @@ interface playable_item
|
|||
*/
|
||||
public function get_catalogs();
|
||||
} // end interface
|
||||
|
||||
|
|
|
@ -535,4 +535,3 @@ class Playlist extends playlist_object
|
|||
return true;
|
||||
} // sort_tracks
|
||||
} // class Playlist
|
||||
|
||||
|
|
|
@ -202,4 +202,3 @@ abstract class playlist_object extends database_object implements library_item
|
|||
return array();
|
||||
}
|
||||
} // end playlist_object
|
||||
|
||||
|
|
|
@ -322,4 +322,3 @@ class Plugin
|
|||
return true;
|
||||
} // remove_plugin_version
|
||||
} //end plugin class
|
||||
|
||||
|
|
|
@ -503,4 +503,3 @@ class Preference extends database_object
|
|||
$_SESSION['userdata']['uid'] = $user_id;
|
||||
} // init
|
||||
} // end Preference class
|
||||
|
||||
|
|
|
@ -2438,4 +2438,3 @@ class Query
|
|||
$this->_state['ak'] = $ak;
|
||||
}
|
||||
} // query
|
||||
|
||||
|
|
|
@ -356,4 +356,3 @@ class Random
|
|||
}
|
||||
} // advanced
|
||||
} //end of random class
|
||||
|
||||
|
|
|
@ -281,4 +281,3 @@ class Rating extends database_object
|
|||
}
|
||||
} // show
|
||||
} //end rating class
|
||||
|
||||
|
|
|
@ -361,4 +361,3 @@ class Recommendation
|
|||
return $results;
|
||||
} // get_artist_info
|
||||
} // end of recommendation class
|
||||
|
||||
|
|
|
@ -136,4 +136,3 @@ Website: %s
|
|||
echo $data;
|
||||
} // show_agreement
|
||||
} // end registration class
|
||||
|
||||
|
|
|
@ -278,4 +278,3 @@ class scrobbler
|
|||
}
|
||||
} // love
|
||||
} // end audioscrobbler class
|
||||
|
||||
|
|
|
@ -384,4 +384,3 @@ class Share extends database_object
|
|||
echo "</ul>";
|
||||
}
|
||||
} // end of recommendation class
|
||||
|
||||
|
|
|
@ -347,4 +347,3 @@ class Shoutbox
|
|||
return $results;
|
||||
}
|
||||
} // Shoutbox class
|
||||
|
||||
|
|
|
@ -59,4 +59,3 @@ class Slideshow
|
|||
return $images;
|
||||
}
|
||||
} // end of Slideshow class
|
||||
|
||||
|
|
|
@ -2110,4 +2110,3 @@ class Song extends database_object implements media, library_item
|
|||
return $deleted;
|
||||
}
|
||||
} // end of song class
|
||||
|
||||
|
|
|
@ -351,4 +351,3 @@ class Song_Preview extends database_object implements media, playable_item
|
|||
return Dba::write($sql);
|
||||
}
|
||||
} // end of song_preview class
|
||||
|
||||
|
|
|
@ -462,4 +462,3 @@ class Stats
|
|||
return $items;
|
||||
} // get_newest
|
||||
} // Stats class
|
||||
|
||||
|
|
|
@ -498,4 +498,3 @@ class Stream
|
|||
return $url;
|
||||
} // get_base_url
|
||||
} //end of stream class
|
||||
|
||||
|
|
|
@ -834,4 +834,3 @@ class Tag extends database_object implements library_item
|
|||
return false;
|
||||
}
|
||||
} // end of Tag class
|
||||
|
||||
|
|
|
@ -347,4 +347,3 @@ class Tmp_Playlist extends database_object
|
|||
return true;
|
||||
} // delete_track
|
||||
} // class Tmp_Playlist
|
||||
|
||||
|
|
|
@ -431,4 +431,3 @@ class TVShow extends database_object implements library_item
|
|||
return $deleted;
|
||||
}
|
||||
} // end of tvshow class
|
||||
|
||||
|
|
|
@ -347,4 +347,3 @@ class TVShow_Season extends database_object implements library_item
|
|||
return Dba::write($sql, array($tvshow_id, $season_id));
|
||||
}
|
||||
} // end of tvshow_season class
|
||||
|
||||
|
|
|
@ -229,4 +229,3 @@ class Upload
|
|||
return $rootdir;
|
||||
}
|
||||
} // Upload class
|
||||
|
||||
|
|
|
@ -1597,4 +1597,3 @@ class User extends database_object
|
|||
return true;
|
||||
}
|
||||
} //end user class
|
||||
|
||||
|
|
|
@ -235,4 +235,3 @@ class Useractivity extends database_object
|
|||
echo '</div><br />';
|
||||
} // show
|
||||
} //end useractivity class
|
||||
|
||||
|
|
|
@ -270,4 +270,3 @@ class Userflag extends database_object
|
|||
require AmpConfig::get('prefix') . UI::find_template('show_object_userflag.inc.php');
|
||||
} // show
|
||||
} //end rating class
|
||||
|
||||
|
|
|
@ -1250,4 +1250,3 @@ class vainfo
|
|||
return $data;
|
||||
}
|
||||
} // end class vainfo
|
||||
|
||||
|
|
|
@ -1069,4 +1069,3 @@ class Video extends database_object implements media, library_item
|
|||
return true;
|
||||
} // _update_item
|
||||
} // end Video class
|
||||
|
||||
|
|
|
@ -543,4 +543,3 @@ class Wanted extends database_object
|
|||
return $results;
|
||||
}
|
||||
} // end of recommendation class
|
||||
|
||||
|
|
|
@ -335,4 +335,3 @@ class Waveform
|
|||
return Dba::write($sql, array($waveform, $song_id));
|
||||
}
|
||||
} // Waveform class
|
||||
|
||||
|
|
|
@ -867,4 +867,3 @@ class XML_Data
|
|||
}
|
||||
}
|
||||
} // XML_Data
|
||||
|
||||
|
|
|
@ -151,4 +151,3 @@ function debug_event($type, $message, $level, $file = '', $username = '')
|
|||
log_event($username, $type, $line, $file);
|
||||
}
|
||||
} // debug_event
|
||||
|
||||
|
|
|
@ -193,4 +193,3 @@ if (isset($auth) && $auth['success'] && isset($user)) {
|
|||
header('Location: ' . AmpConfig::get('web_path') . '/index.php');
|
||||
exit();
|
||||
} // auth success
|
||||
|
||||
|
|
|
@ -55,4 +55,3 @@ function get_rating_name($score)
|
|||
return T_("Off the Charts!");
|
||||
} // end switch
|
||||
} // get_rating_name
|
||||
|
||||
|
|
|
@ -115,4 +115,3 @@ function theme_exists($theme_name)
|
|||
|
||||
return true;
|
||||
} // theme_exists
|
||||
|
||||
|
|
|
@ -511,4 +511,3 @@ class Catalog_dropbox extends Catalog
|
|||
return null;
|
||||
}
|
||||
} // end of catalog class
|
||||
|
||||
|
|
|
@ -870,4 +870,3 @@ class Catalog_local extends Catalog
|
|||
return $media;
|
||||
}
|
||||
} // end of local catalog class
|
||||
|
||||
|
|
|
@ -381,4 +381,3 @@ class Catalog_remote extends Catalog
|
|||
return null;
|
||||
}
|
||||
} // end of catalog class
|
||||
|
||||
|
|
|
@ -452,4 +452,3 @@ class Catalog_soundcloud extends Catalog
|
|||
return null;
|
||||
}
|
||||
} // end of catalog class
|
||||
|
||||
|
|
|
@ -377,4 +377,3 @@ class Catalog_subsonic extends Catalog
|
|||
return null;
|
||||
}
|
||||
} // end of catalog class
|
||||
|
||||
|
|
|
@ -561,4 +561,3 @@ class AmpacheHttpq extends localplay_controller
|
|||
return false;
|
||||
} // connect
|
||||
} //end of AmpacheHttpq
|
||||
|
||||
|
|
|
@ -565,4 +565,3 @@ class AmpacheMpd extends localplay_controller
|
|||
return false;
|
||||
} // connect
|
||||
} //end of AmpacheMpd
|
||||
|
||||
|
|
|
@ -578,4 +578,3 @@ class AmpacheVlc extends localplay_controller
|
|||
return false;
|
||||
} // connect
|
||||
} //end of AmpacheVlc
|
||||
|
||||
|
|
|
@ -665,4 +665,3 @@ class AmpacheXbmc extends localplay_controller
|
|||
}
|
||||
} // connect
|
||||
} //end of AmpacheXbmc
|
||||
|
||||
|
|
|
@ -168,4 +168,3 @@ switch ($_REQUEST['action']) {
|
|||
require_once AmpConfig::get('prefix') . UI::find_template('show_user_registration.inc.php');
|
||||
break;
|
||||
} // end switch on action
|
||||
|
||||
|
|
|
@ -53,4 +53,3 @@ switch ($_REQUEST['action']) {
|
|||
echo "</div>";
|
||||
break;
|
||||
} // switch on the action
|
||||
|
||||
|
|
1
test.php
1
test.php
|
@ -41,4 +41,3 @@ switch ($action) {
|
|||
require_once $prefix . '/templates/show_test.inc.php';
|
||||
break;
|
||||
} // end switch on action
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue