<commit_before><?php

include(__DIR__."/../config.php"); //imports relative to "inc/functions.php"

###############################################################
# Page Password Protect 2.13
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
############################################################### 
#
# Usage:
# Set usernames / passwords below between SETTINGS START and SETTINGS END.
# Open it in browser with "help" parameter to get the code
# to add to all files being protected. 
#    Example: password_protect.php?help
# Include protection string which it gave you into every file that needs to be protected
#
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
#
###############################################################

/*
-------------------------------------------------------------------
SAMPLE if you only want to request login and password on login form.
Each row represents different user.

$LOGIN_INFORMATION = array(
  'zubrag' => 'root',
  'test' => 'testpass',
  'admin' => '<PASSWORD>'
);

--------------------------------------------------------------------
SAMPLE if you only want to request only password on login form.
Note: only passwords are listed

$LOGIN_INFORMATION = array(
  'root',
  'testpass',
  'passwd'
);

--------------------------------------------------------------------
*/

##################################################################
#  SETTINGS START
##################################################################

// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
  'refstats' => 'statsref'
);

// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);

// User will be redirected to this page after logout
define('LOGOUT_URL', 'http://library.wayne.edu');

// time out after NN minutes of inactivity. Set to 0 to not timeout
define('TIMEOUT_MINUTES', 60);

// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);

##################################################################
#  SETTINGS END
##################################################################


///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////

// show usage example
if(isset($_GET['help'])) {
  die('Include following code into every page you would like to protect, at the very beginning (first line):<br>&lt;?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?&gt;');
}

// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);

// logout?
if(isset($_GET['logout'])) {
  setcookie("verify", '', $timeout, '/'); // clear password;
  header('Location: ' . LOGOUT_URL);
  exit();
}

if (!function_exists('showLoginPasswordProtect')  ) {

// show login form
function showLoginPasswordProtect($error_msg) {

	// check if IP in range

?>
<html>
<head>
  <title>Please enter password to access this page</title>
  <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>

  <style>
    input { border: 1px solid black; }
  </style>
  <div style="width:640px; margin-left:auto; margin-right:auto; text-align:center">
  <form method="post">
  	<!-- <h2>WSU RefStats Tool</h2> -->
    <img src="inc/refstats_logo.png"/>
    <h3>Please enter username and password to access this page:</h3>
    <font color="red"><?php echo $error_msg; ?></font><br />
<?php if (USE_USERNAME) echo 'Username:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?>
    <input type="password" name="access_password" />
    <input type="hidden" name="login_refer" /><p></p>
    <input type="submit" name="Submit" value="Submit" />
  </form>
  <p>If you have any trouble logging into RefStats, please email <a href="mailto:<EMAIL>"><NAME></a>.</p>
  </div>
</body>
</html>

<?php
  // stop at this point
  die();
}
}

// else {
// 	// redirect to page that 
// 	echo "Let's go here: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// }

// user provided password
if (isset($_POST['access_password'])) {

  $login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
  $pass = $_POST['access_password'];
  if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
  || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) 
  ) {
    showLoginPasswordProtect("Incorrect password.");
  }
  else {
    // set cookie if password was validated
    setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
    
    // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
    // So need to clear password protector variables
    unset($_POST['access_login']);
    unset($_POST['access_password']);
    unset($_POST['Submit']);
  }

}

// renders page
else {


  if ( !in_array($_SERVER['REMOTE_ADDR'], $ip_white_list) ){
  	// check if password cookie is set
	  if (!isset($_COOKIE['verify'])) {
	    showLoginPasswordProtect("");
	  }

	  // check if cookie is good
	  $found = false;
	  foreach($LOGIN_INFORMATION as $key=>$val) {
	    $lp = (USE_USERNAME ? $key : '') .'%'.$val;
	    if ($_COOKIE['verify'] == md5($lp)) {
	      $found = true;
	      // prolong timeout
	      if (TIMEOUT_CHECK_ACTIVITY) {
	        setcookie("verify", md5($lp), $timeout, '/');
	      }
	      break;
	    }
	  }  
	  if (!$found) {
	    showLoginPasswordProtect("");
	  }	
  }

  

}

?>
<commit_msg>bumped timeout to 1440<commit_after><?php

include(__DIR__."/../config.php"); //imports relative to "inc/functions.php"

###############################################################
# Page Password Protect 2.13
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
############################################################### 
#
# Usage:
# Set usernames / passwords below between SETTINGS START and SETTINGS END.
# Open it in browser with "help" parameter to get the code
# to add to all files being protected. 
#    Example: password_protect.php?help
# Include protection string which it gave you into every file that needs to be protected
#
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
#
###############################################################

/*
-------------------------------------------------------------------
SAMPLE if you only want to request login and password on login form.
Each row represents different user.

$LOGIN_INFORMATION = array(
  'zubrag' => 'root',
  'test' => 'testpass',
  'admin' => '<PASSWORD>'
);

--------------------------------------------------------------------
SAMPLE if you only want to request only password on login form.
Note: only passwords are listed

$LOGIN_INFORMATION = array(
  'root',
  'testpass',
  '<PASSWORD>'
);

--------------------------------------------------------------------
*/

##################################################################
#  SETTINGS START
##################################################################

// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
  'refstats' => 'statsref'
);

// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);

// User will be redirected to this page after logout
define('LOGOUT_URL', 'http://library.wayne.edu');

// time out after NN minutes of inactivity. Set to 0 to not timeout
define('TIMEOUT_MINUTES', 1440);

// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);

##################################################################
#  SETTINGS END
##################################################################


///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////

// show usage example
if(isset($_GET['help'])) {
  die('Include following code into every page you would like to protect, at the very beginning (first line):<br>&lt;?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?&gt;');
}

// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);

// logout?
if(isset($_GET['logout'])) {
  setcookie("verify", '', $timeout, '/'); // clear password;
  header('Location: ' . LOGOUT_URL);
  exit();
}

if (!function_exists('showLoginPasswordProtect')  ) {

// show login form
function showLoginPasswordProtect($error_msg) {

	// check if IP in range

?>
<html>
<head>
  <title>Please enter password to access this page</title>
  <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>

  <style>
    input { border: 1px solid black; }
  </style>
  <div style="width:640px; margin-left:auto; margin-right:auto; text-align:center">
  <form method="post">
  	<!-- <h2>WSU RefStats Tool</h2> -->
    <img src="inc/refstats_logo.png"/>
    <h3>Please enter username and password to access this page:</h3>
    <font color="red"><?php echo $error_msg; ?></font><br />
<?php if (USE_USERNAME) echo 'Username:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?>
    <input type="password" name="access_password" />
    <input type="hidden" name="login_refer" /><p></p>
    <input type="submit" name="Submit" value="Submit" />
  </form>
  <p>If you have any trouble logging into RefStats, please email <a href="mailto:<EMAIL>"><NAME></a>.</p>
  </div>
</body>
</html>

<?php
  // stop at this point
  die();
}
}

// else {
// 	// redirect to page that 
// 	echo "Let's go here: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// }

// user provided password
if (isset($_POST['access_password'])) {

  $login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
  $pass = $_POST['access_password'];
  if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
  || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) 
  ) {
    showLoginPasswordProtect("Incorrect password.");
  }
  else {
    // set cookie if password was validated
    setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
    
    // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
    // So need to clear password protector variables
    unset($_POST['access_login']);
    unset($_POST['access_password']);
    unset($_POST['Submit']);
  }

}

// renders page
else {


  if ( !in_array($_SERVER['REMOTE_ADDR'], $ip_white_list) ){
  	// check if password cookie is set
	  if (!isset($_COOKIE['verify'])) {
	    showLoginPasswordProtect("");
	  }

	  // check if cookie is good
	  $found = false;
	  foreach($LOGIN_INFORMATION as $key=>$val) {
	    $lp = (USE_USERNAME ? $key : '') .'%'.$val;
	    if ($_COOKIE['verify'] == md5($lp)) {
	      $found = true;
	      // prolong timeout
	      if (TIMEOUT_CHECK_ACTIVITY) {
	        setcookie("verify", md5($lp), $timeout, '/');
	      }
	      break;
	    }
	  }  
	  if (!$found) {
	    showLoginPasswordProtect("");
	  }	
  }

  

}

?>

{'fraction_non_alphanumeric': 0.2719088130833402, 'fraction_numerical': 0.004295035929627488, 'mean_word_length': 2.824384080859128, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 110, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1273972', 'n_tokens_mistral': 3722, 'n_tokens_neox': 3506, 'n_words': 957}