Odyssey
cu_fun.i
1 <?php
2 
3 function CheckPerm($pLink, $pUserName, $pScriptName, $pIPAddr) {
4  $PermPass = false; // Start with a FALSE assumption
5  $IPPass = false;
6  // ** RETURNS -- False if no permission -- True if user has permission
7  // ** Look up the Script with the user name and ensure they have permissions
8  $sql = "SELECT allowed_scripts, ip_range, altipaddress
9  FROM dmsmonitorusers
10  WHERE user_name = '" . prep_save($pUserName, 12) . "' ";
11 
12  $perm_rs = db_query($sql, $pLink);
13  $allowed_scripts = array();
14 
15  if ($perm_row = db_fetch_array($perm_rs)) {
16  // ** Validate the Script is allowed
17  $allowed_scripts = explode("\n", $perm_row['allowed_scripts']);
18  if (is_array($allowed_scripts)) {
19  foreach($allowed_scripts as $value) {
20  if ("$value" == "*") {
21  // ** They have a wildcard -- all forms pass -- return true
22  $PermPass = true;
23  break;
24  } elseif (trim($value) == trim($pScriptName) || trim($value) == str_replace(".prg", "", trim($pScriptName))) { // In Odyssey .prg endings are added to script names
25  // ** The form name matches -- return true
26  $PermPass = true;
27  break;
28  }
29  }
30 
31  // ** Validate the IP Range
32  $ip_range = array();
33  // ** MWS -- REMOVED the \r ^M character from the field, it may be causing intermediate issues
34  $perm_row['ip_range'] = str_replace(chr(13), "", $perm_row['ip_range']);
35  $ip_range = explode("\n", $perm_row['ip_range']);
36 
37  if (trim($perm_row['altipaddress']) != "") {
38  // ** If alternate IP Address is found, then add it here
39  array_push($ip_range, trim($perm_row['altipaddress']));
40  }
41  if (is_array($ip_range)) {
42  foreach ($ip_range as $value) {
43  if (substr($pIPAddr, 0, strlen(trim($value))) == trim($value)) {
44  $IPPass = true;
45  break;
46  }
47  }
48  }
49 
50  }
51  db_free_result($perm_rs);
52  }
53 
54  if (!($PermPass && $IPPass)) {
55  $sysenv = $GLOBALS['SYSENV'];
56 
57  if (HCU_array_key_exists("logger", $sysenv)) {
58  $logger = $sysenv['logger'];
59  // ** I am presuming this is the SYSENV object
60  $ERR_MSG = "\n-------------------------\n";
61  $ERR_MSG .= "Date: " . date('m/d/Y H:i:s') . "\n";
62  $ERR_MSG .= "Cookie: " . implode(",", $_COOKIE) . "\n";
63  $ERR_MSG .= "User: $pUserName\n";
64  $ERR_MSG .= "Access Script: $pScriptName\n";
65  $ERR_MSG .= "Access IP: $pIPAddr\n";
66  $ERR_MSG .= "Perm File: " . ($PermPass ? "True" : "False") . "\n";
67  $ERR_MSG .= "Perm IP: " . ($IPPass ? "True" : "False") . "\n";
68  $ERR_MSG .= "HAYSTACK\n";
69 
70  $ERR_MSG .= "-------------------------\n";
71 
72  $logger->debug($ERR_MSG);
73  }
74 
75 
76  }
77 
78  return ($PermPass && $IPPass);
79 }
80 
81 function int($val) {
82  // Purpose: to accept a numeric value and return the whole number portion
83 
84  for ($i=0; $i < strlen($val); $i++) {
85  $piece = substr($val,$i,1);
86  if ($piece >=0 && $piece <=9) {
87  //This is a number so add to concantenate on a string
88  $new_val .= $piece;
89  } else {
90  //Found a not integer so exit function
91  break;
92  }
93  }
94  if (strlen($new_val) == 0) $new_val = "0";
95  return (int) $new_val;
96 }
97 
98 function set_string($val) {
99  $val = htmlspecialchars(trim($val));
100  return $val;
101 }
102 
103 // save_date will format the date string (including surrounding "'"), but if the date string is empty it will return null
104 function save_date($date) {
105  if (strlen(trim($date)) == 0)
106  return "null";
107  else
108  return "'" . dateformat("Y-m-d", $date) . "'";
109 }
110 
111 // This function will strip all money formatting from the passed in string and return the result
112 function strip_money($money) {
113  $pat = "([\$, ])";
114  $repl = "";
115 
116  $ret_money = preg_replace("/$pat/", $repl, $money);
117 
118  return $ret_money;
119 }
120 
121 function printError($errormsg) {
122  printf("<br> %s <br>\n", $errormsg);
123 }
124 
125 function isMammothServer($wwwServer) {
126  $wwwList = array("www3", "www4", "www5", "www6");
127  return in_array($wwwServer, $wwwList);
128 }
129 
130 ?>