<?php
/*
* imap.php
*
* Developed by Ondrej Jombik <nepto@platon.sk>
* Copyright (c) 2005 Platon Group, http://platon.sk/
* Licensed under terms of GNU General Public License.
* All rights reserved.
*
* Changelog:
* 2005-12-17 - created
*
*/
/* $Platon: $ */
$fm_imap_options = array(
'host' => 'localhost',
'port' => 143,
'baseDSN' => '/imap/notls',
'timeout' => 5,
'session' => 900 /* 15 minutes */
);
/*
* phpWebFileManager initialization
*
* Config file is read from init.inc.php file.
*/
$fm_init_file = dirname(__FILE__)
. (strlen(dirname(__FILE__)) > 0 ? '/' : '')
. '../init.inc.php';
if (! @file_exists($fm_init_file)) {
exit;
}
require_once $fm_init_file;
require_once $PN_PathPrefix . 'functions.inc.php';
if (!extension_loaded('imap')) {
die('Cannot use IMAP authentication, IMAP extension not loaded!');
}
session_start();
$logged = false;
$dsn = '{'.$fm_imap_options['host'].':'.$fm_imap_options['port'].$fm_imap_options['baseDSN'].'}';
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
if ($_SESSION['timestamp'] > time() - $fm_imap_options['session']) {
$logged = true;
}
if (strlen($username) > 0 && strlen($password) > 0) { /* {{{ */
/*
* Check server
*/
$fp = @fsockopen ($fm_imap_options['host'], $fm_imap_options['port'],
$errno, $errstr, $fm_imap_options['timeout']);
if (is_resource($fp)) {
@fclose($fp);
} else {
$message = "Error connecting to IMAP server "
. $fm_imap_options['host'].':'.$fm_imap_options['port'];
die($message);
}
/*
* Check username & password
*/
$conn = @imap_open($dsn, $username, $password);
if (is_resource($conn)) {
@imap_close($conn);
$logged = true;
} else {
echo '<center><h1>Bad username or password</h1></center>';
exit;
}
} /* }}} */
if (! $logged) {
if (function_exists('fm_header')) {
fm_header();
}
?>
<span class="fm-login">
<table border="0" align="center" cellpadding="0" cellspacing="5" class="fm-login">
<form method="post">
<tr>
<td class="fm-login">Username</td>
<td class="fm-login"><input type="text" name="username" size="20" maxlength="30"></td>
</tr>
<tr>
<td class="fm-login">Password</td>
<td class="fm-login"><input type="password" name="password" size="20" maxlength="30"></td>
</tr>
<tr>
<td class="fm-login">
<input type="hidden" name="action" value="login">
<input type="submit" value=" Login ">
</td>
</tr>
</form>
</table>
</span>
<?php
if (function_exists('fm_footer')) {
fm_footer();
}
}
if (! $logged) {
exit;
}
$_SESSION['timestamp'] = time();
/* Modeline for ViM {{{
* vim: set ts=4:
* vim600: fdm=marker fdl=0 fdc=0:
* }}} */
?>
Platon Group <platon@platon.sk> http://platon.sk/
|