$tmp =~ s/[\'|\"],?\s*$//;
$tmp =~ s/[\'|\"]\);\s*$//;
$name = $tmp;
+ } elsif ( $tmp =~ /^\s*[\'|\"]binddn[\'|\"]/i ) {
+ $tmp =~ s/^\s*[\'|\"]binddn[\'|\"]\s*=>\s*[\'|\"]//i;
+ $tmp =~ s/[\'|\"],?\s*$//;
+ $tmp =~ s/[\'|\"]\);\s*$//;
+ $binddn = $tmp;
+ } elsif ( $tmp =~ /^\s*[\'|\"]bindpw[\'|\"]/i ) {
+ $tmp =~ s/^\s*[\'|\"]bindpw[\'|\"]\s*=>\s*[\'|\"]//i;
+ $tmp =~ s/[\'|\"],?\s*$//;
+ $tmp =~ s/[\'|\"]\);\s*$//;
+ $bindpw = $tmp;
+ } elsif ( $tmp =~ /^\s*[\'|\"]protocol[\'|\"]/i ) {
+ $tmp =~ s/^\s*[\'|\"]protocol[\'|\"]\s*=>\s*[\'|\"]?//i;
+ $tmp =~ s/[\'|\"]?,?\s*$//;
+ $tmp =~ s/[\'|\"]?\);\s*$//;
+ $protocol = $tmp;
}
}
$ldap_host[$sub] = $host;
$ldap_port[$sub] = $port;
$ldap_maxrows[$sub] = $maxrows;
$ldap_charset[$sub] = $charset;
+ $ldap_binddn[$sub] = $binddn;
+ $ldap_bindpw[$sub] = $bindpw;
+ $ldap_protocol[$sub] = $protocol;
} elsif ( $options[0] =~ /^(data_dir|attachment_dir|theme_css|org_logo|signout_page)$/ ) {
${ $options[0] } = &change_to_rel_path($options[1]);
} else {
if ( !$prefs_key_field ) {
$prefs_key_field = 'prefkey';
}
+if ( !$addrbook_global_table ) {
+ $addrbook_global_table = 'global_abook';
+}
+if ( !$addrbook_global_writeable ) {
+ $addrbook_global_writeable = 'false';
+}
+if ( !$addrbook_global_listing ) {
+ $addrbook_global_listing = 'false';
+}
if ( !$prefs_val_field ) {
$prefs_val_field = 'prefval';
}
print "6. Field for prefs key : $WHT$prefs_key_field$NRM\n";
print "7. Field for prefs value : $WHT$prefs_val_field$NRM\n";
print "\n";
+ print "8. DSN for Global Address Book : $WHT$addrbook_global_dsn$NRM\n";
+ print "9. Table for Global Address Book : $WHT$addrbook_global_table$NRM\n";
+ print "10. Allow writing into Global Address Book : $WHT$addrbook_global_writeable$NRM\n";
+ print "11. Allow listing of Global Address Book : $WHT$addrbook_global_listing$NRM\n";
+ print "\n";
print "R Return to Main Menu\n";
} elsif ( $menu == 10 ) {
print $WHT. "Language settings\n" . $NRM;
elsif ( $command == 5 ) { $prefs_user_field = command95(); }
elsif ( $command == 6 ) { $prefs_key_field = command96(); }
elsif ( $command == 7 ) { $prefs_val_field = command97(); }
+ elsif ( $command == 8 ) { $addrbook_global_dsn = command98(); }
+ elsif ( $command == 9 ) { $addrbook_global_table = command99(); }
+ elsif ( $command == 10 ) { $addrbook_global_writeable = command910(); }
+ elsif ( $command == 11 ) { $addrbook_global_listing = command911(); }
} elsif ( $menu == 10 ) {
if ( $command == 1 ) { $squirrelmail_default_language = commandA1(); }
elsif ( $command == 2 ) { $default_charset = commandA2(); }
print " Relative: ../data/\n";
print "Relative paths to directories outside of the SquirrelMail distribution\n";
print "will be converted to their absolute path equivalents in config.php.\n\n";
- print "Note: There are potential security risks with having a writable directory\n";
+ print "Note: There are potential security risks with having a writeable directory\n";
print "under the web server's root directory (ex: /home/httpd/html).\n";
print "For this reason, it is recommended to put the data directory\n";
print "in an alternate location of your choice. \n";
if ( $ldap_maxrows[$count] ) {
print " maxrows: $ldap_maxrows[$count]\n";
}
+ if ( $ldap_binddn[$count] ) {
+ print " binddn: $ldap_binddn[$count]\n";
+ if ( $ldap_bindpw[$count] ) {
+ print " bindpw: $ldap_bindpw[$count]\n";
+ }
+ }
+ if ( $ldap_protocol[$count] ) {
+ print " protocol: $ldap_protocol[$count]\n";
+ }
+
print "\n";
$count++;
}
print "\n";
+ print "If your LDAP server does not like anonymous logins, you can specify bind DN.\n";
+ print "Default is none, anonymous bind. Press ENTER for default.\n";
+ print "binddn: ";
+ $name = <STDIN>;
+ $name =~ s/[\r|\n]//g;
+ $ldap_binddn[$sub] = $name;
+
+ print "\n";
+
+ if ( $ldap_binddn[$sub] ne '' ) {
+
+ print "Now, please specify password for that DN.\n";
+ print "bindpw: ";
+ $name = <STDIN>;
+ $name =~ s/[\r|\n]//g;
+ $ldap_bindpw[$sub] = $name;
+
+ print "\n";
+ }
+
+ print "You can specify bind protocol version here.\n";
+ print "Default protocol version depends on your php ldap settings.\n";
+ print "Press ENTER for default.\n";
+ print "protocol: ";
+ $name = <STDIN>;
+ $name =~ s/[\r|\n]//g;
+ $ldap_protocol[$sub] = $name;
+
+ print "\n";
+
} elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
if ( $input =~ /[0-9]+\s*$/ ) {
$rem_num = $input;
@new_ldap_name = ();
@new_ldap_charset = ();
@new_ldap_maxrows = ();
+ @new_ldap_bindpw = ();
+ @new_ldap_binddn = ();
+ @new_ldap_protocol = ();
while ( $count <= $#ldap_host ) {
if ( $count != $rem_num ) {
@new_ldap_name = ( @new_ldap_name, $ldap_name[$count] );
@new_ldap_charset = ( @new_ldap_charset, $ldap_charset[$count] );
@new_ldap_maxrows = ( @new_ldap_maxrows, $ldap_maxrows[$count] );
+ @new_ldap_binddn = ( @new_ldap_binddn, $ldap_binddn[$count] );
+ @new_ldap_bindpw = ( @new_ldap_bindpw, $ldap_bindpw[$count] );
+ @new_ldap_protocol = ( @new_ldap_protocol, $ldap_protocol[$count] );
}
$count++;
}
@ldap_name = @new_ldap_name;
@ldap_charset = @new_ldap_charset;
@ldap_maxrows = @new_ldap_maxrows;
+ @ldap_binddn = @new_ldap_binddn;
+ @ldap_bindpw = @new_ldap_bindpw;
+ @ldap_protocol = @new_ldap_protocol;
+
} elsif ( $input =~ /^\s*\?\s*/ ) {
print ".-------------------------.\n";
print "| + (add host) |\n";
return $new_field;
}
+sub command98 {
+ print "If you want to store your global address book in a database then\n";
+ print "you need to set this DSN to a valid value. The format for this is:\n";
+ print "mysql://user:pass\@hostname/dbname\n";
+ print "Where mysql can be one of the databases PHP supports, the most common\n";
+ print "of these are mysql, msql and pgsql\n";
+ print "If the DSN is left empty (hit space and then return) the database\n";
+ print "related code for global SQL address book will not be used\n";
+ print "\n";
+
+ if ( $addrbook_global_dsn eq "" ) {
+ $default_value = "Disabled";
+ } else {
+ $default_value = $addrbook_global_dsn;
+ }
+ print "[$WHT$addrbook_global_dsn$NRM]: $WHT";
+ $new_dsn = <STDIN>;
+ if ( $new_dsn eq "\n" ) {
+ $new_dsn = "";
+ } else {
+ $new_dsn =~ s/[\r|\n]//g;
+ $new_dsn =~ s/^\s+$//g;
+ }
+ return $new_dsn;
+}
+
+sub command99 {
+ print "This is the name of the table you want to store the global address book\n";
+ print "data in, it defaults to 'global_address'\n";
+ print "\n";
+ print "[$WHT$addrbook_global_table$NRM]: $WHT";
+ $new_table = <STDIN>;
+ if ( $new_table eq "\n" ) {
+ $new_table = $addrbook_global_table;
+ } else {
+ $new_table =~ s/[\r|\n]//g;
+ }
+ return $new_table;
+}
+
+sub command910 {
+ print "This option controls users\' ability to add or modify records stored \n";
+ print "in global address book\n";
+
+ if ( lc($addrbook_global_writeable) eq "true" ) {
+ $default_value = "y";
+ } else {
+ $default_value = "n";
+ }
+ print "Allow writing into global address book? (y/n) [$WHT$default_value$NRM]: $WHT";
+ $addrbook_global_writeable = <STDIN>;
+ if ( ( $addrbook_global_writeable =~ /^y\n/i ) || ( ( $addrbook_global_writeable =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
+ $addrbook_global_writeable = "true";
+ } else {
+ $addrbook_global_writeable = "false";
+ }
+ return $addrbook_global_writeable;
+}
+
+sub command911 {
+ print "Enable this option if you want to see listing of addresses stored \n";
+ print "in global address book\n";
+
+ if ( lc($addrbook_global_listing) eq "true" ) {
+ $default_value = "y";
+ } else {
+ $default_value = "n";
+ }
+ print "Allow listing of global address book? (y/n) [$WHT$default_value$NRM]: $WHT";
+ $addrbook_global_listing = <STDIN>;
+ if ( ( $addrbook_global_listing =~ /^y\n/i ) || ( ( $addrbook_global_listing =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
+ $addrbook_global_listing = "true";
+ } else {
+ $addrbook_global_listing = "false";
+ }
+ return $addrbook_global_listing;
+}
+
+
# Default language
sub commandA1 {
print "SquirrelMail attempts to set the language in many ways. If it\n";
# integer
print CF " 'maxrows' => $ldap_maxrows[$count]";
}
+ if ( $ldap_binddn[$count] ) {
+ print CF ",\n";
+ # string
+ print CF " 'binddn' => '$ldap_binddn[$count]'";
+ if ( $ldap_bindpw[$count] ) {
+ print CF ",\n";
+ # string
+ print CF " 'bindpw' => '$ldap_bindpw[$count]'";
+ }
+ }
+ if ( $ldap_protocol[$count] ) {
+ print CF ",\n";
+ # integer
+ print CF " 'protocol' => $ldap_protocol[$count]";
+ }
print CF "\n";
print CF ");\n";
print CF "\n";
# string
print CF "\$prefs_key_field = '$prefs_key_field';\n";
# string
- print CF "\$prefs_val_field = '$prefs_val_field';\n";
+ print CF "\$prefs_val_field = '$prefs_val_field';\n\n";
+ # string
+ print CF "\$addrbook_global_dsn = '$addrbook_global_dsn';\n";
+ # string
+ print CF "\$addrbook_global_table = '$addrbook_global_table';\n";
+ # boolean
+ print CF "\$addrbook_global_writeable = $addrbook_global_writeable;\n\n";
+ # boolean
+ print CF "\$addrbook_global_listing = $addrbook_global_listing;\n\n";
# boolean
print CF "\$no_list_for_subscribe = $no_list_for_subscribe;\n";
* ? maxrows => Maximum # of rows in search result
* ? timeout => Timeout for LDAP operations (in seconds, default: 30)
* Might not work for all LDAP libraries or servers.
+ * ? binddn => LDAP Bind DN.
+ * ? bindpw => LDAP Bind Password.
+ * ? protocol => LDAP Bind protocol.
*
* NOTE. This class should not be used directly. Use the
* "AddressBook" class instead.
var $bound = false; /* True if LDAP server is bound */
var $maxrows = 250; /* Max rows in result */
var $timeout = 30; /* Timeout for LDAP operations (in seconds) */
+ var $binddn = ''; /* DN to bind to (non-anonymous bind) */
+ var $bindpw = ''; /* password to bind with (non-anonymous bind) */
+ var $protocol = ''; /* protocol used to connect to ldap server */
/* Constructor. Connects to database */
function abook_ldap_server($param) {
if(isset($param['timeout'])) {
$this->timeout = $param['timeout'];
}
+ if(isset($param['binddn'])) {
+ $this->binddn = $param['binddn'];
+ }
+ if(isset($param['bindpw'])) {
+ $this->bindpw = $param['bindpw'];
+ }
+ if(isset($param['protocol'])) {
+ $this->protocol = $param['protocol'];
+ }
if(empty($param['name'])) {
$this->sname = 'LDAP: ' . $param['host'];
}
return $this->set_error('ldap_connect failed');
}
}
-
- if(!@ldap_bind($this->linkid)) {
- if(function_exists('ldap_error')) {
- return $this->set_error(ldap_error($this->linkid));
- } else {
- return $this->set_error('ldap_bind failed');
- }
+
+ if(!empty($this->protocol)) {
+ if(!@ldap_set_option($this->linkid, LDAP_OPT_PROTOCOL_VERSION, $this->protocol)) {
+ if(function_exists('ldap_error')) {
+ return $this->set_error(ldap_error($this->linkid));
+ } else {
+ return $this->set_error('ldap_set_option failed');
+ }
+ }
+ }
+
+ if(!empty($this->binddn)) {
+ if(!@ldap_bind($this->linkid, $this->binddn, $this->bindpw)) {
+ if(function_exists('ldap_error')) {
+ return $this->set_error(ldap_error($this->linkid));
+ } else {
+ return $this->set_error('authenticated ldap_bind failed');
+ }
+ }
+ } else {
+ if(!@ldap_bind($this->linkid)) {
+ if(function_exists('ldap_error')) {
+ return $this->set_error(ldap_error($this->linkid));
+ } else {
+ return $this->set_error('anonymous ldap_bind failed');
+ }
+ }
}
-
+
$this->bound = true;
return true;
*/
-global $addrbook_dsn;
+global $addrbook_dsn, $addrbook_global_dsn;
/**
Create and initialize an addressbook object.
function addressbook_init($showerr = true, $onlylocal = false) {
global $data_dir, $username, $ldap_server, $address_book_global_filename;
global $addrbook_dsn, $addrbook_table;
+ global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
/* Create a new addressbook object */
$abook = new AddressBook;
}
}
+ /* Load global addressbook from SQL if configured */
+ if (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) {
+ /* Database configured */
+ if (!isset($addrbook_global_table) || empty($addrbook_global_table)) {
+ $addrbook_global_table = 'global_abook';
+ }
+ $r = $abook->add_backend('database',
+ Array('dsn' => $addrbook_global_dsn,
+ 'owner' => 'global',
+ 'name' => _("Global address book"),
+ 'writeable' => $addrbook_global_writeable,
+ 'listing' => $addrbook_global_listing,
+ 'table' => $addrbook_global_table));
+ }
+
if ($onlylocal) {
return $abook;
}
$alias = array(0 => $alias);
}
- /* Check that specified backend is writable */
+ /* Check that specified backend is writeable */
if (!$this->backends[$bnum]->writeable) {
$this->error = _("Addressbook is read-only");
return false;
$userdata['nickname'] = $userdata['email'];
}
- /* Check that specified backend is writable */
+ /* Check that specified backend is writeable */
if (!$this->backends[$bnum]->writeable) {
$this->error = _("Addressbook is read-only");;
return false;
}
/* Only load database backend if database is configured */
-if(isset($addrbook_dsn) && !empty($addrbook_dsn)) {
+if((isset($addrbook_dsn) && !empty($addrbook_dsn)) ||
+ (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) ) {
include_once(SM_PATH . 'functions/abook_database.php');
}
'$allow_charset_search' => array( 'name' => _("Allow server charset search"),
'type' => SMOPT_TYPE_BOOLEAN,
'default' => false ),
- '$uid_support' => array( 'name' => _("UID support"),
- 'type' => SMOPT_TYPE_BOOLEAN,
- 'default' => false ),
'$session_name' => array( 'name' => _("PHP session name"),
'type' => SMOPT_TYPE_HIDDEN ),
/* --------------------------------------------------------*/
'type' => SMOPT_TYPE_STRING,
'size' => 40,
'default' => 'prefval' ),
- /* --------------------------------------------------------*/
- 'Group7' => array( 'name' => _("Themes"),
- 'type' => SMOPT_TYPE_TITLE ),
- '$theme_css' => array( 'name' => _("Style Sheet URL (css)"),
- 'type' => SMOPT_TYPE_PATH,
- 'size' => 40 ),
- '$theme_default' => array( 'name' => _("Default theme"),
- 'type' => SMOPT_TYPE_INTEGER,
- 'default' => 0,
- 'comment' => _("Use index number of theme") ),
+ '$addrbook_global_dsn' => array( 'name' => _("Global address book DSN"),
+ 'type' => SMOPT_TYPE_STRING,
+ 'size' => 40 ),
+ '$addrbook_global_table' => array( 'name' => _("Global address book table"),
+ 'type' => SMOPT_TYPE_STRING,
+ 'size' => 40,
+ 'default' => 'global_abook' ),
+ '$addrbook_global_writable' => array( 'name' => _("Allow writing into global address book"),
+ 'type' => SMOPT_TYPE_BOOLEAN ),
+ '$addrbook_global_listing' => array( 'name' => _("Allow listing of global address book"),
+ 'type' => SMOPT_TYPE_BOOLEAN ),
'Group9' => array( 'name' => _("Language settings"),
'type' => SMOPT_TYPE_TITLE ),
'$squirrelmail_default_language' => array( 'name' => _("Default Language"),
'$use_php_iconv' => array( 'name' => _("Use php iconv functions"),
'type' => SMOPT_TYPE_BOOLEAN ),
/* --------------------------------------------------------*/
+ 'Group7' => array( 'name' => _("Themes"),
+ 'type' => SMOPT_TYPE_TITLE ),
+ '$theme_css' => array( 'name' => _("Style Sheet URL (css)"),
+ 'type' => SMOPT_TYPE_PATH,
+ 'size' => 40 ),
+ '$theme_default' => array( 'name' => _("Default theme"),
+ 'type' => SMOPT_TYPE_INTEGER,
+ 'default' => 0,
+ 'comment' => _("Use index number of theme") ),
+ /* --------------------------------------------------------*/
'$config_use_color' => array( 'name' => '',
'type' => SMOPT_TYPE_HIDDEN ),
'$no_list_for_subscribe' => array( 'name' => '',