Skip to content

Commit

Permalink
Start removing protocol and path vars, rely on sRootPath (ChurchCRM#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 11, 2016
1 parent 17ed49d commit 8032006
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 212 deletions.
6 changes: 3 additions & 3 deletions churchinfo/AddEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@

require "Include/Header.php";
?>
<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script type="text/javascript" language="javascript" src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script type="text/javascript" language="javascript" src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>

This comment has been minimized.

Copy link
@dschwen

dschwen Feb 12, 2016

Author Owner

Every instance of $sURLPath should be replaceable by $sRootPath


<?php

Expand Down
174 changes: 72 additions & 102 deletions churchinfo/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,32 +116,35 @@
if ($iUserID > 0)
{
// Get the information for the selected user
$sSQL = "SELECT * FROM user_usr WHERE usr_per_ID ='$iUserID'";
$sSQL = "SELECT * FROM user_usr WHERE usr_per_ID = '$iUserID'";
extract(mysql_fetch_array(RunQuery($sSQL)));

$sSQL = "SELECT * FROM person_per WHERE per_ID ='$iUserID'";
$sSQL = "SELECT * FROM person_per WHERE per_ID = '$iUserID'";
extract(mysql_fetch_array(RunQuery($sSQL)));

$bPasswordMatch = FALSE;

// Check the user password
$sPasswordHashSha256 = hash ("sha256", $_POST['Password'].$iUserID);
$sPasswordHashSha256 = hash("sha256", $_POST['Password'].$iUserID);

// Block the login if a maximum login failure count has been reached
if ($iMaxFailedLogins > 0 && $usr_FailedLogins >= $iMaxFailedLogins) {

if ($iMaxFailedLogins > 0 && $usr_FailedLogins >= $iMaxFailedLogins)
{
$sErrorText = '<br>' . gettext('Too many failed logins: your account has been locked. Please contact an administrator.');
} // Does the password match?
elseif ($usr_Password != $sPasswordHashSha256) {
}
// Does the password match?
elseif ($usr_Password != $sPasswordHashSha256)
{
// Increment the FailedLogins
$sSQL = 'UPDATE user_usr SET usr_FailedLogins = usr_FailedLogins + 1 '.
"WHERE usr_per_ID ='$iUserID'";
RunQuery($sSQL);

// Set the error text
$sErrorText = '&nbsp;' . gettext('Invalid login or password');
} else {

}
else
{
// Set the LastLogin and Increment the LoginCount
$sSQL = "UPDATE user_usr SET usr_LastLogin = NOW(), usr_LoginCount = usr_LoginCount + 1, usr_FailedLogins = 0 WHERE usr_per_ID ='$iUserID'";
RunQuery($sSQL);
Expand All @@ -165,7 +168,8 @@
$_SESSION['sEmailAddress'] = $per_Email;

// If user has administrator privilege, override other settings and enable all permissions.
if ($usr_Admin) {
if ($usr_Admin)
{
$_SESSION['bAddRecords'] = true;
$_SESSION['bEditRecords'] = true;
$_SESSION['bDeleteRecords'] = true;
Expand All @@ -177,9 +181,9 @@
$_SESSION['bCanvasser'] = true;
$_SESSION['bAdmin'] = true;
}

// Otherwise, set the individual permissions.
else {
else
{
// Set the Add permission
$_SESSION['bAddRecords'] = $usr_AddRecords;

Expand Down Expand Up @@ -247,16 +251,12 @@
// Set the Root Path ... used in basic security check
$_SESSION['sRootPath'] = $sRootPath;

// Set the URL Path
$_SESSION['sURLPath'] = $_POST['sURLPath'];

This comment has been minimized.

Copy link
@dschwen

dschwen Feb 12, 2016

Author Owner

This session variable is gone. We do still store sRootPath in the session to perform the security check that looks if the PHP session matches the current installation (in case multiple CRMs are on the same server)


// If PHP's magic quotes setting is turned off, we want to use a workaround to ensure security.
if (function_exists('get_magic_quotes_gpc'))
$_SESSION['bHasMagicQuotes'] = get_magic_quotes_gpc();
else
$_SESSION['bHasMagicQuotes'] = 0;


// Pledge and payment preferences
$_SESSION['sshowPledges'] = $usr_showPledges;
$_SESSION['sshowPayments'] = $usr_showPayments;
Expand All @@ -280,42 +280,46 @@
$_SESSION['bSearchFamily'] = $usr_SearchFamily;

if (isset($bEnableMRBS) && $bEnableMRBS) {
$_SESSION["UserName"] = $UserName; // set the session variable recognized by MRBS
// Update the MRBS user record to match this ChurchInfo user
$iMRBSLevel = 0;
if ($usr_AddRecords)
$iMRBSLevel = 1;
if ($usr_Admin)
$iMRBSLevel = 2;
$sSQL = "INSERT INTO mrbs_users (id, level, name, email) VALUES ('$iUserID', '$iMRBSLevel', '$UserName', '$per_Email') ON DUPLICATE KEY UPDATE level='$iMRBSLevel', name='$UserName',email='$per_Email'";
RunQuery($sSQL);
}
// set the session variable recognized by MRBS
$_SESSION["UserName"] = $UserName;

if (isset($bEnableWebCalendar) && $bEnableWebCalendar) {
$sAdmin = ($usr_Admin ? 'Y' : 'N');
$GLOBALS['login'] = $UserName;
$GLOBALS['firstname'] = $per_FirstName;
$GLOBALS['lastname'] = $per_LastName;
$GLOBALS['is_admin'] = $sAdmin;
$GLOBALS['email'] = $per_Email;
$GLOBALS['fullname'] = "$per_FirstName $per_LastName";
$GLOBALS['enabled'] = 1;
// Update the MRBS user record to match this ChurchInfo user
$iMRBSLevel = 0;
if ($usr_AddRecords) $iMRBSLevel = 1;
if ($usr_Admin) $iMRBSLevel = 2;

$_SESSION['webcal_login'] = $UserName;
$sSQL = "INSERT INTO mrbs_users (id, level, name, email) VALUES ('$iUserID', '$iMRBSLevel', '$UserName', '$per_Email') ON DUPLICATE KEY UPDATE level='$iMRBSLevel', name='$UserName',email='$per_Email'";
RunQuery($sSQL);
}

$sSQL = "INSERT INTO webcal_user (cal_login, cal_firstname, cal_lastname, cal_is_admin, cal_email) VALUES ('$UserName', '". mysql_real_escape_string ($per_FirstName)." ', '".mysql_real_escape_string ($per_LastName)."', '$sAdmin', '$per_Email') ON DUPLICATE KEY UPDATE cal_login='$UserName', cal_firstname='".mysql_real_escape_string ($per_FirstName)."', cal_lastname='".mysql_real_escape_string ($per_LastName)."',cal_is_admin='$sAdmin', cal_email='$per_Email'";
RunQuery($sSQL);
if (isset($bEnableWebCalendar) && $bEnableWebCalendar)
{
$sAdmin = ($usr_Admin ? 'Y' : 'N');
$GLOBALS['login'] = $UserName;
$GLOBALS['firstname'] = $per_FirstName;
$GLOBALS['lastname'] = $per_LastName;
$GLOBALS['is_admin'] = $sAdmin;
$GLOBALS['email'] = $per_Email;
$GLOBALS['fullname'] = "$per_FirstName $per_LastName";
$GLOBALS['enabled'] = 1;

$_SESSION['webcal_login'] = $UserName;

$sSQL = "INSERT INTO webcal_user (cal_login, cal_firstname, cal_lastname, cal_is_admin, cal_email) VALUES ('$UserName', '". mysql_real_escape_string ($per_FirstName)." ', '".mysql_real_escape_string ($per_LastName)."', '$sAdmin', '$per_Email') ON DUPLICATE KEY UPDATE cal_login='$UserName', cal_firstname='".mysql_real_escape_string ($per_FirstName)."', cal_lastname='".mysql_real_escape_string ($per_LastName)."',cal_is_admin='$sAdmin', cal_email='$per_Email'";
RunQuery($sSQL);
}

// Redirect to the Menu
Redirect('CheckVersion.php');
exit;
}
}

// Turn ON output buffering
ob_start();
$sPageTitle = "ChurchCRM - Login";

// Set the page title and include HTML header
$sPageTitle = "ChurchCRM - Login";
require ("Include/HeaderNotLoggedIn.php");
?>

Expand All @@ -328,60 +332,21 @@
<p class="login-box-msg"><?= gettext('Please Login'); ?></p>

<?php
// Show the login screen if the URL protocol and path have been
// returned by the browser in a query string

if (empty($_GET['Proto']) || empty($_GET['Path'])) {

This comment has been minimized.

Copy link
@dschwen

dschwen Feb 12, 2016

Author Owner

This is all gone now. Reliance on Javascript was not a good idea here. You'll see below how this can all be done in PHP.

?><script language="javascript" type="text/javascript">
var error_page1="http://www.churchcrm.io";
var error_page2="http://www.churchcrm.io";

if (window.location.href.indexOf(":") == 5)
{
v_Proto = "https";
v_Path = window.location.href.substring(8);
}
else if (window.location.href.indexOf(":") == 4)
{
v_Proto = "http";
v_Path = window.location.href.substring(7);
}
else
window.location = error_page1;

v_index = v_Path.toLowerCase().indexOf("default.php") - 1;
if (v_index < 0)
window.location = error_page2;

v_Path=v_Path.substring(0, v_index);
v_Path=encodeURIComponent(v_Path);
v_QueryString = "Proto=" + v_Proto + "&Path=" + v_Path;

if (window.location.href.indexOf("?") < 0)
window.location = window.location.href + "?" + v_QueryString;
else
window.location = window.location.href + "&" + v_QueryString;
</script><?php
}

$loginPageMsg = '';
if (isset($_GET['Proto']) && isset($_GET['Path'])) {
if (isset($_GET['timeout'])) {
$loginPageMsg = "Your previous session timed out. Please login again.";
}
if ($sErrorText != '') {
$loginPageMsg = $sErrorText;
}
if (isset($_GET['timeout'])) {
$loginPageMsg = "Your previous session timed out. Please login again.";
}
if ($sErrorText != '') {
$loginPageMsg = $sErrorText;
}

if ($loginPageMsg != '') { ?>
<div class="alert alert-warning"><?= $loginPageMsg; ?></div><?php
}

?><form class="form-signin" role="form" method="post" name="LoginForm"
<?= "action=\"Default.php?Proto=".$_GET['Proto'].
"&amp;Path=".rawurlencode($_GET['Path'])."\"" ?> >
<div class="form-group has-feedback">
?><form class="form-signin" role="form" method="post" name="LoginForm" action="Default.php">
<div class="form-group has-feedback">
<input type="text" id="UserBox" name="User" class="form-control" placeholder="Email/Username" required autofocus>
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
Expand All @@ -402,19 +367,14 @@
<button type="submit" class="btn btn-primary btn-block btn-flat"><?= gettext('Login'); ?></button>
</div>
</div>
<?php
$sURLPath = $_GET['Proto'] . "://" . $_GET['Path'];
setcookie("URLPath", $sURLPath);
?>
<input type="hidden" name="sURLPath" value="<?= $sURLPath ?>">
</form>

<script language="JavaScript" type="text/JavaScript">
document.LoginForm.User.focus();
</script><?php

//
// Basic sercurity checks:
// Basic security checks:
//
// Check if https is required:
// Verify that page has an authorized URL in the browser address bar.
Expand All @@ -423,19 +383,29 @@
//
if (isset($bLockURL) && ($bLockURL === TRUE))
{
echo '
<script language="javascript" type="text/javascript">
v_test="FAIL"'; // Set "FAIL" to assume the URL is not allowed
// Set "PASS" if we learn it is allowed
foreach ($URL as $value) { // Default.php is 11 characters
$value = substr($value, 0, -11);
echo '
if (window.location.href.indexOf("'.$value.'") == 0) v_test="PASS";';
// get the URL of this page
$currentURL = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

This comment has been minimized.

Copy link
@dschwen

dschwen Feb 12, 2016

Author Owner

Rather than using JavaScript we can check the $_SERVER array here and redirect using headers.

This comment has been minimized.

Copy link
@DawoudIO

DawoudIO Feb 12, 2016

how does that effect server with multi domain


// chop off the query string
$currentURL = explode('?', $currentURL)[0];

// check if this matches any one of teh whitelisted login URLS
$validURL = false;
foreach ($URL as $value)
if ($value === $currentURL)
{
$validURL = true;
break;
}

// jump to the first whitelisted url (TODO: maybe pick a ranodm URL?)
if (!$validURL)
{
header('Location: '.$URL[0]);
exit;
}
echo '
if (v_test == "FAIL") window.location="'.$URL[0].'";
</script>';
}

//
// End of basic security checks
//
Expand Down
8 changes: 4 additions & 4 deletions churchinfo/FamilyEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,11 @@
echo "</td></tr></form></table>";
?>
<!-- InputMask -->
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>

<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>

<script type="text/javascript">
$(function() {
Expand Down
10 changes: 5 additions & 5 deletions churchinfo/FamilyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

?>

<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>


<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<script type="text/javascript" language="javascript" src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<script type="text/javascript" language="javascript" src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>


<div class="pull-right">
Expand Down
2 changes: 1 addition & 1 deletion churchinfo/GenerateSeedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</script>

<!-- PACE -->
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/pace/pace.min.js"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/pace/pace.min.js"></script>
<?php
require "Include/Footer.php";
?>
12 changes: 6 additions & 6 deletions churchinfo/GroupEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
require "Include/Header.php";

?>
<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>

<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<script type="text/javascript" language="javascript" src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<script type="text/javascript" language="javascript" src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>

<!-- GROUP SPECIFIC PROPERTIES MODAL-->
<div class="modal fade" id="groupSpecificPropertiesModal" tabindex="-1" role="dialog" aria-labelledby="deleteGroup" aria-hidden="true">
Expand Down Expand Up @@ -186,7 +186,7 @@
var roleCount = groupRoleData.length;
var groupID=<?php echo $iGroupID?>;
</script>
<script src="<?= $sURLPath; ?>/js/GroupEditor.js"></script>
<script src="<?= $sRootPath; ?>/js/GroupEditor.js"></script>
<?php
require "Include/Footer.php";
?>
10 changes: 5 additions & 5 deletions churchinfo/GroupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
$groupService = new GroupService();
require 'Include/Header.php';?>

<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.css">
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/dataTables.bootstrap.js"></script>


<link rel="stylesheet" type="text/css" href="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<script type="text/javascript" language="javascript" src="<?= $sURLPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<script type="text/javascript" language="javascript" src="<?= $sRootPath; ?>/vendor/almasaeed2010/adminlte/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>



Expand Down
Loading

0 comments on commit 8032006

Please sign in to comment.