[763] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - Auth from Mail server * |
---|
| 4 | * This file written by Dan Kuykendall <seek3r@phpgroupware.org> * |
---|
| 5 | * Authentication based on mail server * |
---|
| 6 | * Copyright (C) 2000, 2001 Dan Kuykendall * |
---|
| 7 | * -------------------------------------------------------------------------* |
---|
| 8 | * This library is part of the eGroupWare API * |
---|
| 9 | * http://www.egroupware.org/api * |
---|
| 10 | * ------------------------------------------------------------------------ * |
---|
| 11 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 12 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 13 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 14 | * or any later version. * |
---|
| 15 | * This library is distributed in the hope that it will be useful, but * |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 18 | * See the GNU Lesser General Public License for more details. * |
---|
| 19 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 20 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 21 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 22 | \**************************************************************************/ |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | class auth_ |
---|
| 26 | { |
---|
| 27 | var $previous_login = -1; |
---|
| 28 | |
---|
| 29 | function authenticate($username, $passwd) |
---|
| 30 | { |
---|
| 31 | error_reporting(error_reporting() - 2); |
---|
| 32 | |
---|
| 33 | if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr') |
---|
| 34 | { |
---|
| 35 | $username = $username . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']; |
---|
| 36 | } |
---|
| 37 | if ($GLOBALS['phpgw_info']['server']['mail_server_type']=='imap') |
---|
| 38 | { |
---|
| 39 | $GLOBALS['phpgw_info']['server']['mail_port'] = '143'; |
---|
| 40 | } |
---|
| 41 | elseif ($GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3') |
---|
| 42 | { |
---|
| 43 | $GLOBALS['phpgw_info']['server']['mail_port'] = '110'; |
---|
| 44 | } |
---|
| 45 | elseif ($GLOBALS['phpgw_info']['server']['mail_server_type']=='imaps') |
---|
| 46 | { |
---|
| 47 | $GLOBALS['phpgw_info']['server']['mail_port'] = '993'; |
---|
| 48 | } |
---|
| 49 | elseif ($GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3s') |
---|
| 50 | { |
---|
| 51 | $GLOBALS['phpgw_info']['server']['mail_port'] = '995'; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | if( $GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3') |
---|
| 55 | { |
---|
| 56 | $mailauth = imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server'].'/pop3' |
---|
| 57 | .':'.$GLOBALS['phpgw_info']['server']['mail_port'].'}INBOX', $username , $passwd); |
---|
| 58 | } |
---|
| 59 | elseif ( $GLOBALS['phpgw_info']['server']['mail_server_type']=='imaps' ) |
---|
| 60 | { |
---|
| 61 | // IMAPS support: |
---|
| 62 | $mailauth = imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server']."/ssl/novalidate-cert" |
---|
| 63 | .':993}INBOX', $username , $passwd); |
---|
| 64 | } |
---|
| 65 | elseif ( $GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3s' ) |
---|
| 66 | { |
---|
| 67 | // POP3S support: |
---|
| 68 | $mailauth = imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server']."/ssl/novalidate-cert" |
---|
| 69 | .':995}INBOX', $username , $passwd); |
---|
| 70 | } |
---|
| 71 | else |
---|
| 72 | { |
---|
| 73 | /* assume imap */ |
---|
| 74 | $mailauth = imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server'] |
---|
| 75 | .':'.$GLOBALS['phpgw_info']['server']['mail_port'].'}INBOX', $username , $passwd); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | error_reporting(error_reporting() + 2); |
---|
| 79 | if ($mailauth == False) |
---|
| 80 | { |
---|
| 81 | return False; |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | imap_close($mailauth); |
---|
| 86 | return True; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | function change_password($old_passwd, $new_passwd) |
---|
| 91 | { |
---|
| 92 | return False; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // Since there account data will still be stored in SQL, this should be safe to do. (jengo) |
---|
| 96 | function update_lastlogin($account_id, $ip) |
---|
| 97 | { |
---|
| 98 | $GLOBALS['phpgw']->db->query("select account_lastlogin from phpgw_accounts where account_id='$account_id'",__LINE__,__FILE__); |
---|
| 99 | $GLOBALS['phpgw']->db->next_record(); |
---|
| 100 | $this->previous_login = $GLOBALS['phpgw']->db->f('account_lastlogin'); |
---|
| 101 | |
---|
| 102 | $GLOBALS['phpgw']->db->query("update phpgw_accounts set account_lastloginfrom='" |
---|
| 103 | . "$ip', account_lastlogin='" . time() |
---|
| 104 | . "' where account_id='$account_id'",__LINE__,__FILE__); |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | ?> |
---|