<?php
/*
* ConPortal - Pomona College ITS scheduling appplication
* Copyright (C) 2005-2006 Pomona College
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
function ldapAuth ($user, $pass, $domain)
{
if (empty($user) || empty($pass))
return false;
//connect to the ldap server
$ldapconn = ldap_connect(LDAP_SERVER);
if (!$ldapconn) {
echo "Failed to init LDAP connection.";
return false;
}
// set the ldap protocol
if (!ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
echo "Failed to set LDAP protocol version to 3";
return false;
}
// attempt to authenticate with $user and $pass
if(USE_ALBANY_LDAP == TRUE)
{
$auth_success = @ldap_bind($ldapconn, ALBANY_LDAP_USER_STRING , $pass);
}
else
{
$user = "$domain\\$user";
$auth_success = @ldap_bind($ldapconn, $user, $pass);
}
ldap_close($ldapconn);
if ($auth_success) {
$_SESSION['ldap'] = 1;
return true;
} else {
return false;
}
}
function check_auth()
{
if (!isset($_SESSION['pid']) or !isset($_SESSION['username']) or
!isset($_SESSION['ldap'])) {
header("Location: " . BASE_URL .
"index.php?page=" . basename($_SERVER['PHP_SELF']));
exit;
}
}
// FIXME : Remove references to domain?
function printLoginForm ($page = "index.php")
{
?>
<div align=center>
<?php
if(ALBANY_OPTIONS)
{
echo "<img src=\"images/itshdlogo1.png\" alt=\"HelpDesk Logo\" />";
}
if(BUCKNELL_OPTIONS)
{
?>
<div class="loginmain">
<div class="logintopBanner">
<img src="images/top.png" alt="Your work group" width="400" height="135" />
<br />
<?php
$random = (rand() % 11) + 1; //pics 1-12, skipping 0
echo "<img src=\"images/login" . $random . ".jpg\" alt=\"L&IT\" width=\"400\" height=\"300\" />";
?>
</div>
<form action="login.php" method="post" id='loginForm'>
<div class="loginleft">
<label for='user'>Username:</label>
<br />
<label for='pass'>Password:</label>
</div>
<div class="loginright">
<input type="text" name="user" id='user' />
<br />
<input type='password' name='pass' id='pass' />
<br />
<input type='submit' value='Login' />
</div>
<input type='hidden' name='domain' value='campus' />
<input type='hidden' name='page' value='index.php' />
<input type='hidden' name='fromWhere' value='FrontPage' />
<?
}
else
{
?>
<form action="login.php" method="post" id='loginForm'>
<label for='user'>Username</label>
<input type="text" name="user" id='user' />
<br /><label for='pass'>Password</label>
<input type='password' name='pass' id='pass' />
<input type='hidden' name='domain' value='campus' />
<input type='hidden' name='page' value='<?= $page ?>' />
<input type='hidden' name='fromWhere' value='FrontPage' />
<br /><input type='submit' value='Login' />
<?
}//end else
if(QUICK_PUNCH_ON_FRONT_PAGE)
{
echo "<br /><input type='submit' name='quickpunch' value='Quickpunch' />";
if(isset($_SESSION['frontPagePunchResult']))
{
echo " <div class='warn'>" . $_SESSION['frontPagePunchResult'] . "</div>\n";
//make sure there are no leftovers from the previous session
session_destroy();
}
}
?>
</div></form>
<?php
}
function printMobileLoginForm($page = "m/index.php") {
?>
<div align=center>
<form action="../login.php" method="post" id='loginForm'>
Username
<input type="text" name="user" id='user' /><br>
Password
<input type='password' name='pass' id='pass' />
<!--
<br /><label for='domain'>Domain</label>
<input type='text' name='domain' value='campus' />
-->
<input type='hidden' name='page' value='<?= $page ?>' />
<input type='hidden' name='fromWhere' value='FrontPage' />
<br /><input type='submit' value='Login' />
</div>
</div></form>
<?php
}
?>