January 24, 2008

 .htaccess password protection via MySQL

mod_auth_mysql (http://modauthmysql.sourceforge.net/), is a module for apache which allows you to password protect a webserver directory with usernames and passwords from a MySQL table.

This is ideal if you would like to password protect the Webmail URL of @Mail, if your organization requires extra security, and you would like to prevent access to the Webmail system for authorized IP's only.

Read below on how to setup Mod-Auth Mysql with Apache

Things to note:

-It is assumed that you are running a linux system with apache web server.
-Detailed instructions regarding the installation and configuration of mod_auth_mysql can be found here: http://modauthmysql.sourceforge.net/

Installing mod_auth_mysql

After building the module, you need to install it to your modules directory.

Apache 1.x:

apxs -i mod_auth_mysql.so

Apache 2.x:

apxs -i mod_auth_mysql.la

Next, add the following directive to httpd.conf:

LoadModule mysql_auth_module modules/mod_auth_mysql.so

Restart the apache webserver.

Once the webserver has restarted, mod_auth_mysql will be started as a module with apache.

Creating the user table

Login to mysql:

mysql -u root -p

The command line will prompt you for a password, and when you hit enter you should be presented with something like this:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2975 to server version: 5.0.22-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

You are now in a mysql shell!

First you must create a mysql database called auth with the following query:

CREATE DATABASE auth;

You must now create a mysql table as below:

CREATE TABLE `users` (
`id` int(5) NOT NULL auto_increment,
`user_name` char(30) NOT NULL,
`user_passwd` char(20) NOT NULL,
`ip_address` varchar(15) default NULL,
`DateAdded` datetime default NULL,
`Expire` int(1) default NULL,
PRIMARY KEY  (`id`)
)
  • The 'id' column simply serves as the PRIMARY KEY to satisfy MySQL requirements, you do not need to enter data into this field, it will enter itself a unique number.
  • The 'user_name' column will hold usernames under 30 characters.
  • The 'user_passwd' column will hold passwords under 20 characters, which should be encrypted.
  • The 'ip_address' column holds allowed ip addresses, this is optional, it will allow ip address based ACL.
  • The 'DateAdded' column will store the date that the user was added, this is optional, it can be used to allow expiry of a user, for this functionality you will also need to include the 'Expire' column.
  • The 'Expire' column holds either '1' or '0', it is also necessary for expiry of a user, but not mandatory for simple username/password authentication.
  • Adding users

    Users can be added into the MySQL table with the following command from the mysql shell.

    INSERT INTO users (user_name,user_passwd,ip_address,Expire) VALUES ('newuser','newpassword','computersip','1');

    NOTE: If you did not include the IP ACL or Expire options, you should use something more like this:

    INSERT INTO users (user_name,user_passwd) VALUES ('newuser','newpassword');

    Setting up .htaccess

    mod_auth_mysql uses the .htaccess file to know which directories need to be protected.

    Your .htaccess file should be located in /usr/local/webmail/atmail/ and should contain the following:

    AuthName "MySQL authenticated zone"
    AuthType Basic
    AuthMySQLEnable on
    AuthMySQLUser username_for_mysql_database
    AuthMySQLPassword password_for_mysql_database
    AuthMySQLDB auth
    AuthMySQLUserTable users
    AuthMySQLNameField user_name
    AuthMySQLPasswordField user_passwd
    AuthMySQLUserCondition "ip_address = '%a'"
    require valid-user

    NOTE:

    The AuthMySQLUserCondition "ip_address = '%a'" line should only be added if you have ip_address columns set up.

    To test your new configuration navigate to www.yourdomain.com/mail/

    If you get an error 500, then there is most likely something wrong with your .htaccess file, if you get a login box, then enter the username/password combination that you have stored in your mysql table, and it should take you straight to your mail.


    Filed under: Customization — info @ 2:47 pm

     

     LDAP Address Book and OpenLDAP

    If you receive an error when using the LDAP address book feature of @Mail:

    ldap_bind(): Unable to bind to server: Protocol error

    Some versions of OpenLDAP require you to specify the version you are connecting to. This needs to be done in two places in the @Mail code.
    Edit /path/to/atmail/webmail/ldap.php (add the line in bold):

    142     // Do LDAP search143     else
    
    144     {
    
    145         // Check for PHP LDAP extension
    
    146         if (!defined('LDAP_OPT_TIMELIMIT'))
    
    147         {
    
    148             if ( !$var['users'] )
    
    149                 $var['users'] = "
    The PHP LDAP extension must be
    
    150                 installed/enabled to use LDAP search with @Mail.";
    
    151
    
    152             print $atmail->parse("html/$atmail->Language/$atmail->LoginType/ldap_search.html", $var);
    
    153             exit;
    
    154         }
    
    155
    
    156         $var['servername'] = $_REQUEST['servername'];
    
    157         $var['FirstName']  = $_REQUEST['FirstName'];
    
    158         $var['LastName']   = $_REQUEST['LastName'];
    
    159         $var['mail']       = $_REQUEST['email'];
    
    160         $var['advanced']   = $_REQUEST['advanced'];
    
    161
    
    162         foreach ( array('FirstName', 'LastName', 'mail') as $field)
    
    163             $var[$field] = str_replace(' ', '', $var[$field]);
    
    164
    
    165         $ldap_config = array(
    
    166             'host'      => $var['servername'],
    
    167             'binddn'    => (!empty($_REQUEST['bind_dn']))     ? $_REQUEST['bind_dn']     : $pref['bind_dn'],
    
    168             'basedn'    => (!empty($_REQUEST['base_dn']))     ? $_REQUEST['base_dn']     : $pref['base_dn'],
    
    169             'bindpw'    => (!empty($_REQUEST['ldap_passwd'])) ? $_REQUEST['ldap_passwd'] : $pref['ldap_passwd']
    
    170         );
    
    171
    
    172
    
    173         $ldap = ldap_connect($ldap_config['host'], 389) or ldapError($ldap);
    
    174
    
    175         ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    
    176
    
    177         if (!ldap_bind($ldap, $ldap_config['binddn'], $ldap_config['bindpw']))
    
    178             ldapError($ldap);
    
    179
    
    180         if (!empty($var['mail']))
    
    181             $filter = "mail={$var['mail']}";
    
    182         else
    
    183             $filter = "(cn={$var['FirstName']} {$var['LastName']}*)";
    
    184
    
    185
    
    186         $result = ldap_search($ldap, $ldap_config['basedn'], $filter) or ldapError($ldap);

    Edit /path/to/atmail/webmail/libs/Atmail/Abook.class.php (add the line in bold):

    1912     // LDAP search functions1913     function _search_ldap($db)
    
    1914     {
    
    1915         // Check for PHP LDAP extension
    
    1916         if (!defined('LDAP_OPT_TIMELIMIT'))
    
    1917             return array();
    
    1918
    
    1919         global $atmail, $pref;
    
    1920
    
    1921         if (empty($db['Account']) && empty($db['FirstName']) && empty($db['LastName']))
    
    1922             return array();
    
    1923
    
    1924         if (!@$ldap = ldap_connect($pref['ldap_server'], 389))
    
    1925             return array();
    
    1926
    
    1927         if (!@ldap_bind($ldap, $pref['bind_dn'], $pref['ldap_password']))
    
    1928             return array();
    
    1929
    
    1930         $query = "(& ";
    
    1931
    
    1932         if (!empty($db['Account']))
    
    1933             $query .= "(mail={$db['Account']}*) ";
    
    1934
    
    1935         if (!empty($db['FirstName']) && !empty($db['LastName']))
    
    1936             $query .= "(cn={$db['FirstName']} {$db['LastName']}*) ";
    
    1937
    
    1938         if (!empty($db['FirstName']))
    
    1939             $query .= "(givenName={$db['FirstName']}*) ";
    
    1940
    
    1941         if (!empty($db['LastName']))
    
    1942             $query .= "(sn={$db['LastName']}*) ";
    
    1943
    
    1944         $query .= ")";
    
    1945
    
    1946          ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    
    1947         // Now we make our query to the LDAP server according to the users
    
    1948         // input via the form
    
    1949         $result = @ldap_search($ldap, $pref['base_dn'], $query );

    You can change the version to whatever version you are using in both files. The line numbers are taken from default files and should be close to the correct values.


    Filed under: Applications, PHP version — Jason Brown @ 8:57 am

     

    January 15, 2008

     Script error with IE, Advanced Interface, when trying to attach file with @mail 5.2

    This error does not appear when working with FireFox or simple/basic web interfaces.

    When composing a message and trying to attach a file, the attach window will come up just fine, but after selecting the file you wish to upload (and before you have the opportunity to click "Upload") the following script error appears:

    "An error has occurred in the script on this page.

    Line: 84
    Char: 1
    Error: Object doesn't support this property or method
    Code: 0
    URL: https://webmail.atmail.com/compose.php?
    func=attachmentmodalframe&unique=8249

    Do you want to continue running scripts on this page?"

    Note: the "...&unique=XXXX" number varies

    If you click YES, the page will stop working. If you click NO, you can continue to upload the file and proceed with your message.

    To resolve this error please do the following.

    1. Find attachment.html on your @mail server. This file is located at
      /usr/local/atmail/webmail/lang/html/xp/attachment.html

      for the server version or

      /{atmail-web-root}/lang/html/xp/attachment.html

      for webmail client only installs.

    2. Back up your old file and create a new attachment.html using this HTML source: New attachment.html for IE7
    3. From the web-root of your @Mail installation run this command (replace 'english' with your required language):
      php lang.php english lang/languages/english/english.lang

    If you have customized templates make sure you take the appropriate action to ensure they are not lost as lang.php will rebuild your templates from those found in lang/html/.

    You should now have successfully installed the new attachment.html that will resolve this issue.


    Filed under: User Questions, PHP version — Stewart Bazley @ 10:23 am

     

    January 1, 2008

     Having RBL checking on a per-domain basis

    Some users expressed the need to have the RBL-checking done on a per-domain basis. This can be done by running through the following steps:- locate the following line in your /usr/local/atmail/mailserver/configure file;

    MYSQL_CATCHALL = select AliasTo from MailAliases where AliasName='$domain'

    - add the following below:

    MYSQL_RBL = select Hostname from Domains where RBL='1'

    (more...)


    Filed under: Anti-Virus — info @ 12:00 pm

     

     Updating ClamAV to 0.90.2

    The 0.90.2 version of ClamAV fixes a lot of problems with the previous versions, including the stability problems for installations on non-Linux systems (Solaris, FreeBSD, Mac OS X, etc)You will need:

    - a backup of your clamav.conf and freshclam.conf file;
    - zlib-devel, or libz-devel libraries;
    - a post-3.2 version of GCC;

    (more...)


    Filed under: Anti-Virus — info @ 12:00 pm

     

     @Mail Source Tree API

    A new source-tree tutorial for the @Mail software has been created at: http://support.atmail.com/source-tree.htmlReference the document for details on the layout structure of @Mail, what each script does and the system modules used for the application.

    Details on the HTML template structure is also provided for ease of navigation when customizing the software.


    Filed under: API — info @ 12:00 pm

     

     Finding httpd.conf

    Having trouble with multiple copies of the httpd.conf file on your system?Try:

    httpd -V

    This will give you the following listing:

    (more...)


    Filed under: Applications — info @ 12:00 pm

     

     ZoneAlarm Pro Max Privacy Settings

    How to enable @Mail under ZoneAlarm Pro V5.5.062.000Double click the ZA icon in the taskbar

    Goto Privacy on the left menu:

    Set Cookie Control to High
    Set Ad Blocking to High
    Set Mobile Code Control to On

    (more...)


    Filed under: Applications — info @ 12:00 pm

     

     Expect Error installing Courier-IMAP

    When you get the error:

    --
    configure: WARNING: expect not found - will not be able to change passwds
    configure: WARNING: in webmail
    --

    Means that you are missing the component called "expect", that normally
    comes with tcl. Download the expect RPM, then install on your server
    this should resolve the problem

    (more...)


    Filed under: Applications — info @ 12:00 pm

     

     Compose page slow to load

    Under some browsers with McAfee installed on the system OS, the compose screen of @Mail can take up to 10 seconds to load.This is due to the "scriptscan" feature enabled via McAfee. This will search all java script as a security method.

    Disabling "scriptscan" will resolve the issue with the slow loading of @Mail.


    Filed under: Applications — info @ 12:00 pm