Odyssey
hcuEnv.i
1 <?php
2 // vim: tabstop=2 expandtab syn=php
3 /**
4  * Definitions used throughout the products
5  */
6 define( "FEATURE_LIMIT_MAX_AMOUNT", 99999999.99 ); // 99,999,999.99
7 define( "FEATURE_LIMIT_MAX_COUNT", 99999 ); // 99,999
8 
9 /*
10  * Location of the ca-certificates dir, this is used to store common public cert, eg ca files
11  */
12 define ("HOMECU_CACERT_DIR", "/home/homecu/ssl/ca-certficates/");
13 /*
14  * Directory on the container where the cert will be saved
15  */
16 define ("HOMECU_DOCK_CERT_DIR", "/tmp/odyssey/");
17 /*
18  * Directory on file system where the encrypted files are saved
19  */
20 define ("HOMECU_ENC_CERT_DIR", "/home/homecu/ssl/");
21 /**
22  * Example.. If the path of the secret-id is 'test/certs/rdc/Sample.pem'
23  *
24  * The encrypted file contents should exist at
25  * /home/homecu/ssl/test/certs/rdc/Sample.pem
26  *
27  * The cert file will be created at
28  * /tmp/odyssey/test/certs/rdc/Sample.pem
29  */
30 
31 /**
32  * Functions required to load the current environment
33  *
34  */
35 
36 require_once 'logging.i';
37 
38 /**
39  *
40  * This function will evaluate if a string exists as a key in the _ENV
41  * If it does, then it will return the value from _ENV
42  * If it does not, then it will use the value in $default
43  *
44  * @param string $envkey This is the key value being sought in _ENV
45  * @param mixed $default (default: NULL) This is the default value to use when the key is not found
46  *
47  * @return mixed Value to set for the envkey in question
48  */
49 function GetEnvSetting($envkey, $default=NULL) {
50 
51  if (array_key_exists($envkey, $_ENV)) {
52  $value = $_ENV[$envkey];
53  if (is_numeric($value)) {
54  $value = (float) $value;
55  }
56  } else {
57  $value = $default;
58  }
59  return $value;
60 }
61 
62 
63 /**
64  *
65  * Loads the environment settings along with creating the logger class
66  *
67  * @param string pLoggerName Name attached to the logger instance
68  *
69  *
70  *
71  */
72 function LoadSystemEnv($pLoggerName) {
73  $logger = getLogger($pLoggerName, GetEnvSetting('DEVMODE', 0));
74 
75  $retVal = [
76  'devmode' => GetEnvSetting('DEVMODE', 0),
77  'db' => [
78  'host' => GetEnvSetting('DATABASE_HOST', 'localhost'),
79  'port' => GetEnvSetting('DATABASE_PORT', 5342),
80  'dbname' => GetEnvSetting('DATABASE_NAME', 'homecu_prod1'),
81  'user' => GetEnvSetting('DATABASE_USER', 'postgres'),
82  'password' => GetEnvSetting('DATABASE_PASSWORD'),
83  'connect_timeout' => GetEnvSetting('DATABASE_CONNECT_TIMEOUT'),
84  'platform' => GetEnvSetting('DATABASE_PLATFORM', 'postgres')
85  ],
86  'ticket' => [
87  'domain' => GetEnvSetting('TICKET_DOMAIN', 'homecu.net'),
88  'expires' => GetEnvSetting('TICKET_EXPIRES', 900),
89  'persists' => GetEnvSetting('TICKET_PERSISTS', 94 * 86400),
90  'inactive' => GetEnvSetting('TICKET_INACTIVE', 1800)
91  ],
92  'site_path' => GetEnvSetting('SITE_PATH', '/var/www/site'), // Where the code lives for the webpage
93  'file_path' => GetEnvSetting('FILE_PATH', '/home'), // Where the filesystem lives
94  'server_host' => GetEnvSetting('SERVER_HOST', 'localhost'),
95  'require_encryption' => GetEnvSetting('REQUIRE_ENCRYPTION', 1),
96  'admin' => [
97  'ip_acl' => GetEnvSetting('ADMIN_IP_ACL', '199.184.207.194;67.42.72.111')
98  ],
99  'logger' => $logger
100  ];
101 
102  /*
103  * Ticket Domain
104  * Should ONLY be the domain e.g. 'homecu.net' 'homecu.io'
105  * ** Remove the sub-domain
106  */
107  if (substr_count($retVal['ticket']['domain'], '.') > 1) {
108  // * If we find more than one '.' then the string looks like
109  // * my.homecu.net, alpha.homecu.io or .homecu.net
110  // ONLY keep the string after the second to last '.'
111  // * homecu.net, homecu.io or homecu.net
112 
113  // ** Find Last position of the '.' in the ['ticket']['domain']
114  // ** Use this last position as the starting point for the next search for a '.'
115  // ** Use the position of the second to last '.' + 1 as the starting point for the sub string
116  // ** Idea stolen from php document page for strrpos
117  $lastPos = strrpos($retVal['ticket']['domain'], '.');
118  if ($lastPos !== false) {
119  $secondLastPos = strrpos($retVal['ticket']['domain'], '.', $lastPos - strlen($retVal['ticket']['domain']) - 1);
120  if ($secondLastPos !== false) {
121  $retVal['ticket']['domain'] = substr($retVal['ticket']['domain'], $secondLastPos + 1);
122  }
123  }
124  }
125  return $retVal;
126 }
127 
128 // Set up static environmental information. These should not be overridden by anyone later.
129 function SetEnvStatic( &$pEnv ) {
130 
131  $pEnv['defaultScript'] = 'hcuAccounts.prg';
132 
133  $pEnv['homebanking_status'] = GetServerStatus();
134 
135  $pEnv['secret'] = GetSecretKeyString();
136  $pEnv['2factorkey'] = Get2FactorKeyString();
137  // ** The following key will be used to hash the account key for use on the URL
138  $pEnv['historyHash'] = GetHistoryKeyString();
139  $pEnv['hcuViewNoticeKey'] = GetViewNoticeKey();
140 
141  $pEnv['livePacketStatusCookie'] = '_hlc';
142 
143  $pEnv['cloudfrontDomainName'] = GetCloudFrontDomainName();
144  $pEnv['homecuKendoVersion'] = GetHomecuKendoVersion();
145  $pEnv['bootstrapVersion'] = GetHomecuBootstrapVersion();
146  $pEnv['fontawesomeVersion'] = GetFontawesomeVersion();
147 } // end SetEnvStatic
148 
149 // Get the dbh value. Caller needs to verify it is set.
150 function GetDBH( $dbName ) {
151  $dbh = db_pconnect( $dbName ) ;
152 
153  return $dbh;
154 } // end GetDBH
155 
156 // This sets the Flang value. Assumes "cu" has been set up already.
157 function SetLanguageEnv( &$pEnv ) {
158 
159  // ** SET the language -- FROM THE GET
160  // ** At this time, I am going to try and change this so it will only evaluate
161  // ** Flang from the cookie for Flang. It will only get value from there
162  $cookieName = $pEnv['cu'] . '_lang';
163  if ( HCU_array_key_exists( $cookieName, $_COOKIE ) ) {
164  $pEnv['Flang'] = $_COOKIE[$cookieName];
165  } else {
166  $pEnv["Flang"] = "en_US";
167  }
168 
169 } // SetLanguageEnv
170 
171 /**
172  * Return the secret key to be added to hashed values
173  *
174  * @return string
175  */
176 function GetSecretKeyString() {
177  return 'xogich6RFoogeid4';
178 }
179 
180 /**
181  * Return the 2 factor key used in the cookie
182  *
183  * @return string
184  */
185 function Get2FactorKeyString(){
186  return "Tu0geethSaith7ch";
187 }
188 
189 /**
190  * Return the string that is hashed and stored
191  * in the device cookie. The key used for hashing
192  * contains sensitive member info, so don't store them
193  * (even hashed) on the client.
194  *
195  * @return string
196  */
197 function GetDeviceCookieContentString(){
198  return 'HomeCU_Home Banking for Credit Unions';
199 }
200 
201 /**
202  * Return the History Hash Key
203  *
204  * @return string
205  */
206 function GetHistoryKeyString() {
207  // ** The following key will be used to hash the account key for use on the URL
208  return '3I20kOxgojS8XDjyPi2vQXLs3m9m0Us9';
209 }
210 
211  /**
212  * Return the View Notice Key
213  *
214  * @return string
215  */
216 function GetViewNoticeKey() {
217  return 'EN!L(2cOYy4U|9o-2]Jc8X=G6h+sr3';
218 }
219 
220 function GetServerStatus() {
221  /*
222  * homebanking_status
223  *
224  * This flag can be used to turn off an entire home banking server without
225  * the need of turning off apache.
226  * At this time, the flag must be made by modifying this file
227  * Accepted values
228  * L - Live
229  * O - OFFLINE !Important, By changing to O home banking scripts should report an
230  * error and will NOT try to connect to database
231  */
232  return "L";
233 }
234 /**
235  * Return the cloudfront domain that points to our S3 buckets
236  *
237  * @return string
238  */
239 function GetCloudFrontDomainName() {
240  return 'd1kryjpwpzirc7.cloudfront.net';
241 }
242 /**
243  * Return the Kendo Version Product
244  * -- Currently this assumes that any application that calls this function
245  * will use the same version. eg Minotaur / Phoenix / Homer
246  * If there is a need to pass back different versions, then an optional
247  * "product" could be passed into the function
248  *
249  * @param string $pApp - The application making the request. This will allow the different
250  * applications to have different versions if need be
251  * expected values are {banking, admin, monitor}
252  * @return string
253  */
254 function GetHomecuKendoVersion ($pApp = "default") {
255  $retVal = "";
256  switch ($pApp) {
257  case "monitor";
258  $retVal = "v2018.2.516";
259  break;
260  default:
261  $retVal = "v2017.3.913";
262  }
263 
264  return $retVal;
265 }
266 /**
267  * Return the system bootstrap version
268  *
269  * @return string
270  */
271 function GetHomecuBootstrapVersion () {
272  return 'v3.3.7';
273 }
274 /**
275  * Return the system fontawesome version
276  *
277  * @return string
278  */
279 function GetFontawesomeVersion () {
280  return 'v4.7.0';
281 }
282 
283 /**
284  * Used for broadcast emails and marketing messages in admin. Custom Content in monitor and probably a couple of more places.
285  */
286 function GetTinyMCEVersion () {
287  return 'v4.7.9';
288 }
289 
290 /**
291  * Get the default value which is "silver" now.
292  * @return string
293  */
294 function GetAdminDefaultKendoStyle() {
295  return "silver";
296 }
297 
298 /**
299  * Get the default value which is "silver" now.
300  * @return string
301  */
302 function GetMonitorDefaultKendoStyle() {
303  return "silver";
304 }
305 
306 /**
307  * GetPayloadKey:
308  * @uses return a string of random characters for use in encrypting/decrypting data
309  */
310 function GetOpenSSLKeyBilbo() {
311 
312  return "VXVtbYOrbt5avJme6ihbeS9MznYMPe9a";
313 }
314 
315 function GetOpenSSLKeyBugs() {
316  return "w0ki5QwpYWkM2FpitNEsosG9HGL9uogS";
317 }
318 
319 function GetValidationKey() {
320  return "obl1vi0u5";
321 }
322 
323 function GetPayloadGlue() {
324  return "|*|*|*|";
325 }
326 
327 /**
328  * GetPayloadEncryptionKey
329  * Return a 128 bit (16 byte) or 256 bit (32 byte) key for use in 128-bit encryption (AES) in the apps.
330  * The default is 16 bits.
331  * BIG NOTE: CHANGING THIS KEY WILL BREAK ANYTHING THAT USES IT FOR STORED ENCRYPTED
332  * STRINGS. CHECK FIRST (e.g. Apps).
333  *
334  * @uses return a string of random characters for apps to use in encrypting/decrypting data.
335  */
336 function GetPayloadEncryptionKey($pKeySizeBytes = 32) {
337  $keyString = "QtjWSJOtd02rKAm6xbxKipsRpXkUCuSf";
338 
339  $pKeySizeBytes = intval( $pKeySizeBytes ) < 16 ? 16 : $pKeySizeBytes;
340  $pKeySizeBytes = intval( $pKeySizeBytes ) > strlen( $keyString ) ? strlen( $keyString ) : $pKeySizeBytes;
341  $appKey = substr( $keyString, 0, $pKeySizeBytes );
342 
343  return $appKey;
344 }
345 
346 // Used in hcuActivate.prg
347 // Similar functionality in hcuEnv.pi for perl scripts.
348 /*
349  * Get google Recpatcha Site Key
350  *
351  * @return string -- Returns the Google recaptcha site key
352  *
353  */
354 function GetCaptchaSiteKey() {
355 
356  /**
357  * Registered under phil.homecu.com
358  * https://www.google.com/recaptcha/admin
359  */
360  $retKey = '6Ld5QyQUAAAAAB-irRU5xGHndWNtB31RDIWQ4nPE';
361 
362  return $retKey;
363 }
364 
365 /**
366  * function GetCreditUnionKey()
367  * For getting the key for the credit union. Used in scripts admLogin.prg and admFunctions.i
368  */
369 function GetCreditUnionKey() {
370  return '$¢®3d1tUn10nK3`/';
371 }
372 
373 /**
374  * function GetCreditUnionCookie()
375  * For getting the key for the credit union. Used in scripts admLogin.prg and admFunctions.i
376  */
377 function GetCreditUnionCookie() {
378  return "_userc";
379 }
380 
381 /*
382  * Get google Recpatcha Secret Key
383  *
384  * @return string -- Returns the Google recaptcha secret key
385  *
386  */
387 function GetCaptchaSecret($pDomain='') {
388 
389  $retKey = "6Ld5QyQUAAAAAKIO8aPwhHSf9T2oAzj7KfyJxjj_";
390 
391  return $retKey;
392 
393 }
394 
395 /*
396  * Get credentials file for google play store service account
397  *
398  * @return string -- Returns address/path of credentials file
399  *
400  */
401 function GetGPStatsCredentialsPath() {
402  return "test/secrets/homecu/google/gpstats/credentials.json";
403 }
404 
405 /**
406  * GetScriptDir()
407  * @return the directory running the processing of the estatement.
408  */
409 function GetScriptDir() {
410  return "/opt/odyssey/tools/bin";
411 }
412 
413 /**
414  * function GetCCConfig($home_path)
415  * @return The path for configuration of the credit card.
416  */
417 function GetCCConfig($home_path) {
418  return "$home_path/bin/ccardload.cfg";
419 }
420 
421 /**
422  * function GetCCName()
423  * @return The text to use in the front of the credit card periods.
424  */
425 function GetCCName() {
426  return "CREDIT CARD";
427 }
428 
429 // Build an environment cookie so the system knows what kind of app is being used.
430 // Returns a cookie string in the form (so different platforms can use it): name|content|expire
431 function BuildEnvironmentInfoCookie($pHBEnv, $pVersionCode) {
432 
433  // the environment depends on the version code
434  switch ($pVersionCode) {
435  case '2':
436  $environment = "Pegasus";
437  break;
438 
439  case '1':
440  default:
441  $environment = "Odyssey";
442  break;
443  }
444 
445  $until = time() + $pHBEnv['SYSENV']['ticket']['expires'];
446  $hashedValue = sha1( $environment . $until . $pVersionCode . $pHBEnv["secret"] );
447  $profileCookie = "env=$environment&version=$pVersionCode&until=$until&check=$hashedValue";
448 
449  return "envinfo|$profileCookie|$until";
450 }
451 
452 // Verify the environment info cookie content is valid by breaking it up and checking the hash.
453 // Returns boolean with false = failure.
454 function VerifyEnvironmentInfoCookie($pHBEnv, $pEnvInfoCookie) {
455 
456  if ( strlen( $pEnvInfoCookie ) == 0 ) {
457  return false;
458  }
459 
460  $testArr = array();
461  parse_str( $pEnvInfoCookie, $testArr );
462 
463  $now = time();
464  if ( $testArr['until'] < $now ) {
465  // cookie has expired
466  return false;
467  }
468 
469  // same order as original hash creation
470  $hashedValue = sha1( $testArr['env'] . $testArr['until'] . $testArr['version'] . $pHBEnv["secret"] );
471 
472  if ( $testArr['check'] != $hashedValue ) {
473  // cookie has been changed
474  return false;
475  }
476 
477  return true;
478 }
479 
480 /**
481  * Load the Environment Info into the HB_ENV array. Just need to know if Pegasus.
482  *
483  * @param $hb_env array Reference to HB_ENV to allow easy changes to values
484  * @param $ticket string The session string from the ticket cookie or appcode
485  * @return array Associative array of results:
486  * [
487  * 'result'=>value, // 1 = ticket is valid, 0 = ticket failed
488  * 'resdesc'=>value, // failure reason or '' if ticket is valid
489  * ]
490  */
491 function LoadClientEnvInfo(&$pHBEnv, $pEnvInfoCookieString) {
492  if ( VerifyEnvironmentInfoCookie( $pHBEnv, $pEnvInfoCookieString) ) {
493  $valueArr = array();
494  parse_str( $pEnvInfoCookieString, $valueArr );
495 
496  $pHBEnv["envinfo"] = $valueArr["env"];
497  } else {
498  $pHBEnv["envinfo"] = "Unknown";
499  }
500 }