Odyssey
ck_aticket.i
1 <?php
2 
3 // BUG alert: IE needs at least 2 dots in the domain.
4 
5 function ReturnAddress($pSysEnv)
6 {
7  // Called when the cookie is missing, expired, or damaged. Sets return address to the name of the current script so cu_login knows where to go afterwards.
8  HCU_setcookie_env($pSysEnv, "Tx_aURI", $_SERVER['PHP_SELF'] . "?" . urlencode($_SERVER['QUERY_STRING']), 0);
9 }
10 
11 $result= true;
12 $tarr = array();
13 try
14 {
15  // Validate Ticket
16  if (empty($_COOKIE['aTicket']))
17  throw new exception("No ticket", 1);
18  $ticket = $_COOKIE['aTicket'];
19  if ($SYSENV['require_encryption'] && !HCU_http_encrypted()) {
20  throw new exception("Something is wrong not referencing https", 2);
21  }
22 
23  // parse_str puts all the cookie values as variables in this script. So now I have variables $Cu, $Cn, $Cip, etc., corresponding to everything I put in the Ticket cookie.
24  parse_str($ticket, $tarr);
25 
26  if (isset($skip_time) == false || (isset($skip_time) == true and $skip_time == false))
27  {
28  $now = time();
29  if ($tarr['Ce'] < $now)
30  {
31  throw new exception("Ticket has expired", 3);
32  }
33  }
34 
35  if (isset($cu) && $cu != $tarr['Cu'])
36  {
37  throw new exception("Different CU requested", 4);
38  }
39 
40  if (is_null($tarr['Ch']) || is_null($tarr['Cn']) || is_null($tarr['Ctime']) || is_null($tarr['Ce']) || is_null($tarr['Cu']) || is_null($tarr['Cip']) || is_null($tarr['Cl']) ||
41  is_null($tarr['Cd']) || is_null($tarr['Clu']))
42  {
43  throw new exception("Partial ticket, try again", 5);
44  }
45 
46  $secret = 'xogich6RFoogeid4';
47  if ($tarr['Ch'] != MD5($secret . MD5(join(':', array($secret, $tarr['Cip'], $tarr['Ctime'], $tarr['Ce'], $tarr['Cl'], $tarr['Cu'], $tarr['Cn'], $tarr['Cd'], urlencode($tarr['Clu']),
48  urlencode($tarr['Fplog']), urlencode($tarr['Fflog']), $tarr['Ffchg'], $tarr['Ffremain'], $tarr['Fset'], $tarr['Fset2'], $tarr['Fset3'])))))
49  {
50  throw new exception("hash doesn't match, someone is hacking", 6);
51  }
52 }
53 catch(exception $e)
54 {
55  $result= false;
56 }
57 
58 if (isset($tarr["Cu"]) && isset($tarr["Cn"])) // After log out and when re-signing on, there is a case where these are defined: hence a couple of E_NOTICEs in the console.
59  // apache_note sets variables for web server logging. Used later to split web logfiles by credit union
60  apache_note('user_name', "{$tarr['Cu']}:{$tarr['Cn']}");
61 
62 if (!$result && $frm_login == false)
63 {
64  // if any of the cookie tests failed set the return address, redirect to login, and then exit so the rest of the current script doesn't get executed.
65  ReturnAddress($SYSENV);
66  header("Location: ${menu_link}?ft=71");
67  exit;
68 }
69 // good cookie -- warm it up to extend the expiration timestamp.
70 else
71 {
72  $Ctime = time();
73  $expires = $Ctime + (array_key_exists('inactive', $SYSENV['ticket']) ? $SYSENV['ticket']['inactive'] : 600);
74  Set_aTicket($SYSENV, $_COOKIE['aTicket'], "&Ctime=$Ctime&Ce=$expires");
75 
76  $allowC = array('Ctime' => 'Time', 'Ce' => 'Expires', 'Cu' => 'CU', 'Cn' => 'Login Name', 'Clu' => 'Last Update', 'Cip' => 'IPaddr', 'Cd' => 'DB', 'Cl' => 'LiveBatch',
77  'Fplog' => 'Last Login', 'Fflog' => 'Failed Login', 'Ffchg' => 'Force Change', 'Ffremain' => 'Failed Remaining', 'Fset' => 'Flagset 1', 'Fset2' => 'Flagset 2', 'Fset3' => 'Flagset 3');
78  extract(array_intersect_key($tarr, $allowC), EXTR_OVERWRITE);
79 
80  $Clu = urldecode($Clu);
81  $Fflog = urldecode($Fflog);
82  $Fplog = urldecode($Fplog);
83 }