13 function Set2FactorAdmin($pSysEnv, $p_pwd, $p_email, $p_conf_word, $challengeArray, $Cn, $setCookieIfNotExists=
false)
15 $p_pwd = trim($p_pwd);
16 $p_email = trim($p_email);
17 $p_conf_word = trim($p_conf_word);
19 $cookiename = sha1(
"HCUAdminTu0geethSaith7ch" . $Cn);
21 if (!$setCookieIfNotExists && !isset($_COOKIE[$cookiename]))
25 if (
sizeof($_COOKIE) > 23)
28 $persists = (time() - 3600);
29 foreach ($_COOKIE as $thisCookiename => $cookiecontent)
31 if (!preg_match(
"/^(Tx_aURI|aTicket|webconnect|_userc.*)/",$thisCookiename))
33 HCU_setcookie_env($pSysEnv, $thisCookiename,
"", $persists);
38 $addToCookie = array();
39 $challengeArray = HCU_array_key_value(
"answers", $challengeArray);
40 $challengeArray = $challengeArray ===
false ? array() : $challengeArray;
42 if (isset($challengeArray))
44 ksort($challengeArray, SORT_NUMERIC);
45 $find= array(
"\n",
"\\",
"=",
"|");
46 $replace= array(
"",
"\\\\",
"\\=",
"\\|");
47 foreach($challengeArray as $questId => $questValue)
49 $questId= intval($questId);
50 $questValue= trim(str_replace($find, $replace, $questValue));
51 $addToCookie[]=
"$questId=$questValue";
54 $addToCookie= implode(
"|", $addToCookie);
56 $cookiecontent=sha1($p_pwd . $p_email . $p_conf_word . $addToCookie);
58 $persists = time() + $pSysEnv[
'ticket'][
'persists'];
59 HCU_setcookie_env($pSysEnv,
"$cookiename",
"$cookiecontent", $persists);
69 function showProductName($pName) {
71 <script type=
'text/javascript'>
73 <?php
if ($pName ==
"NONE" || $pName ==
"") { ?>
74 $(
"#logo-bar p.navbar-title").html(
" ");
76 $(
"#logo-bar p.navbar-title").text(
"<?php echo $pName ?>");
90 function checkOrgName($cu) {
93 $sqlSelect =
"SELECT orgname FROM cuadmin a WHERE cu = '$cu'";
94 $sqlSelectRs = db_query($sqlSelect, $dbh);
95 $sqlData = db_fetch_assoc($sqlSelectRs, 0);
97 $orgname = isset($sqlData[
'orgname']) ? $sqlData[
'orgname'] :
null;
98 $orgname = $orgname ==
null ?
"" : trim($orgname);
116 function checkPerm($user, $script, $cu_name)
118 global $logger, $SYSENV, $dbh;
124 $sth = db_query(
"select trim(user_name), ip_acl from cuadmin where cu='$cu_name';",$dbh);
125 list($master, $ipACL) = db_fetch_array($sth,0);
128 $ipCheckPassed =
false;
129 if ( strlen( $ipACL ) > 0 ) {
131 $ipACL =
" " . trim( $ipACL );
134 $ipACL .=
";{$settings['admin']['ip_acl']}";
137 $ipAddress = trim( $_SERVER[
"REMOTE_ADDR"] );
139 if ( strpos( $ipACL, $ipAddress ) > 0 ) {
141 $ipCheckPassed =
true;
144 $sql =
"select userflags, remoteip 146 where lower(user_name) = '" . strtolower(prep_save($user)) .
"' 147 and cu = '$cu_name' ";
148 $sth = db_query( $sql, $dbh );
149 list( $userFlags, $remoteIP ) = db_fetch_array( $sth, 0 );
151 if ( ($userFlags & GetAdminUserFlagsValue(
"ADM_REMOTE_ACCESS_ALLOWED")) > 0 ) {
152 if ( trim( $remoteIP ) == $ipAddress ) {
153 $ipCheckPassed =
true;
158 if (!$ipCheckPassed) {
159 $logger->info(
"Invalid IP Address for service: {$ipAddress}");
162 $ipCheckPassed =
true;
165 if ($master ==
"$user") {
169 where cuadminexclude.program = '$script' 170 and cuadminexclude.cu = '$cu_name' ";
171 $ovr_rs = db_query($sql, $dbh);
174 if (db_num_rows($ovr_rs) > 0) {
179 db_free_result($ovr_rs);
183 $sql =
"select a.user_name 185 where lower(a.user_name) = '" . strtolower(prep_save($user)) .
"' 186 and program = '$script' and a.cu = '$cu_name' 187 and not exists (select * 189 where cuadminexclude.program = a.program 190 and cuadminexclude.cu = '$cu_name') ";
191 $sth = db_query($sql,$dbh);
192 $num = db_num_rows($sth);
194 if (db_num_rows($sth) > 0) {
198 $sql =
"select userflags from cuadminusers 199 where lower(user_name) = '" . strtolower(prep_save($user)) .
"' 200 and cu = '$cu_name'";
201 $sth = db_query($sql,$dbh);
202 list($ret_su) = db_fetch_array($sth,0);
203 $ret_su = ($ret_su & 4);
205 db_free_result($sth);
208 return array ($master, $ret_pass, $ret_su, $ipCheckPassed);
219 function getVariablesForMenu($dbh, &$menuVariables, $Cu)
221 $menuVariables[
"secureDocumentsText"] =
"Secure Documents";
222 getNewMessageCount($dbh, $menuVariables, $Cu);
223 getAdmCount($dbh, $menuVariables, $Cu);
224 getLoanCount($dbh, $menuVariables, $Cu);
225 getExtCounts($dbh, $menuVariables, $Cu);
227 $docCount = $menuVariables[
"secureFormCount"] + $menuVariables[
"messageCount"];
228 $docCount = $docCount > 0 ? ($docCount > 9 ?
"9+" :
"$docCount") :
"";
229 $menuVariables[
"secureDocumentsText"]=
"Secure Documents" . ($docCount ==
"" ?
"" :
" <span class='badge'>$docCount</span>");
238 function getNewMessageCount($dbh, &$menuVariables, $Cu)
242 $sql =
"select count(*) from cuadmeco where cu = '$Cu' and origination = 1 and unread and not admdeleted";
243 $sth = db_query($sql, $dbh);
244 list($messageCount) = db_fetch_array($sth,0);
246 $text=
"Secure Messages";
247 $menuVariables[
"messageCount"] = intval($messageCount);
248 $messageCount= $messageCount > 0 ? ($messageCount > 9 ?
"9+" :
"$messageCount") :
"";
249 $menuVariables[
"messageText"] =
"Secure Messages" . ($messageCount ==
"" ?
"" :
" <span class='badge'>$messageCount</span>");
253 $menuVariables[
"messageCount"] = 0;
254 $menuVariables[
"messageText"] =
"Secure Messages";
264 function getAdmCount($dbh, &$menuVariables, $Cu)
268 $secpath =
"/home/" . strtolower($Cu) .
"/sslforms";
269 $secforms =
sizeof(glob(
"$secpath/*.html"));
270 $menuVariables[
"secureFormCount"] = $secforms;
271 $secformCount = $secforms > 0 ? ($secforms > 9 ?
"9+" :
"$secforms") :
"";
272 $menuVariables[
"secureFormText"] =
"Secure Forms" . ($secformCount ==
"" ?
"" :
" <span class='badge'>$secformCount</span>");
276 $menuVariables[
"secureFormCount"] = 0;
277 $menuVariables[
"secureFormText"] =
"Secure Forms";
287 function getLoanCount($dbh, &$menuVariables, $Cu)
289 $sql =
"select count(*) from lnappconfig where cu = '$Cu'";
290 $sth = db_query($sql, $dbh);
291 list ($loanCount) = db_fetch_array($sth, 0);
292 $menuVariables[
"loanCount"] = intval($loanCount);
301 function getExtCounts($dbh, &$menuVariables, $Cu)
305 include_once(dirname(__FILE__) .
"/../../shared/library/cutrusted.i");
306 # check if this client uses local EZCARD settings 307 $trustedIds= array(
"hasEZ" =>
"HcuEZCARD",
"hasDMI" =>
"HcuDMI",
"hasMIR" =>
"HcuMIR");
308 $parms = array(
'Cu' => $Cu,
"trustedids" => $trustedIds);
309 $return = cutd_list($dbh, $parms);
311 foreach($trustedIds as $key => $value)
313 $menuVariables[$key] = isset($return[
'data'][
"$Cu|$value"]);
319 $menuVariables[
"hasEZ"] =
false;
320 $menuVariables[
"hasDMI"] =
false;
321 $menuVariables[
"hasMIR"] =
false;
338 function getAdmChallengeQuestions($dbh, $cuCode, $username, $mode, $actuallyUser=
false)
342 $challengeQuestions= array();
343 $challengeQuestionDDL= array();
347 $noChallengeQuestions=
false;
348 $forceChallengeQuestions=
false;
349 $forcePassword=
false;
350 $username= strtolower($username);
352 global $CU2_RANDOM_CHAL;
353 $bitValue= intval($CU2_RANDOM_CHAL);
357 $sql =
"select au.mfaquest, coalesce(a.flagset2,0) & $bitValue, coalesce(au.userflags, 0) & 2, au.forcechange from cuadminusers au inner join cuadmin a on au.cu = a.cu 358 and lower(au.user_name) = '" . prep_save($username, 50) .
"' and au.cu = '" . prep_save($cuCode, 10) .
"'";
360 $sql =
"select au.mfaquest, coalesce(a.flagset2,0) & $bitValue, coalesce(au.userflags, 0) & 2, au.forcechange from ${cuCode}user au inner join cuadmin a on lower(au.user_name)='" 361 . prep_save($username, 50) .
"' and a.cu = '" . prep_save($cuCode, 10) .
"'";
364 $sth = db_query($sql, $dbh);
366 throw new Exception(
"mfaquest query failed.", 1);
367 if (db_num_rows($sth) == 0)
374 case "login display":
375 $sql =
"select quest_id, quest_text, example_text from cuquestmaster where quest_lang = 'en_US' order by random() limit 3";
378 $sth = db_query($sql, $dbh);
380 throw new Exception(
"master question query failed.", 2);
381 for($i = 0; $array = db_fetch_assoc($sth, $i); $i++)
383 $array[
"answer"] =
"";
384 $challengeQuestions[] = $array;
388 throw new Exception (
"Username record doesn't exist.", 3);
394 $row = db_fetch_row($sth, 0);
395 $encodedAnswers = trim($row[0]);
396 $decodedAnswers = HCU_MFADecode(HCU_JsonDecode($encodedAnswers));
397 unset($encodedAnswers);
398 $isRandom= intval($row[1]) != 0;
399 $forceChallengeQuestions = intval($row[2]) != 0 && in_array($mode, array(
"login verify",
"login display"));
400 $forcePassword= trim($row[3]) ==
"Y";
402 if (!$forceChallengeQuestions)
407 case "login display":
408 case "admin display":
409 if ($decodedAnswers[
"mfacount"] > 0)
411 $sql =
"select quest_id, quest_text, example_text from cuquestmaster where quest_lang = 'en_US' and quest_id in (" . implode(
", ", array_keys($decodedAnswers[
"answers"]))
412 .
") order by quest_id";
415 $sth = db_query($sql, $dbh);
417 throw new Exception(
"master question query failed.", 4);
418 for($i = 0; $array = db_fetch_assoc($sth, $i); $i++)
420 $answer = $decodedAnswers[
"answers"][$array[
"quest_id"]];
421 $array[
"answer"] = $answer ==
null ?
"" : $answer;
422 $challengeQuestions[$array[
"quest_id"]] = $array;
425 if ($isRandom && $mode !=
"admin display")
427 if (intval($decodedAnswers[
"challenge"]) == 0)
430 $decodedAnswers[
"challenge"] = array_rand($decodedAnswers[
"answers"]);
431 $sql=
"update cuadminusers set mfaquest = '" . prep_save(PrepareMfaQuestString($decodedAnswers))
432 .
"' where lower(user_name) = '" . prep_save($username, 50)
433 .
"'" . (trim($cuCode) !=
"" ?
" and cu = '" . prep_save($cuCode, 10) .
"'" :
"");
435 $sth = db_query($sql, $dbh);
437 throw new Exception(
"update challenge query failed.", 5);
440 if (intval($decodedAnswers[
"challenge"]) > 0)
442 $challengeQuestions= isset($challengeQuestions[$decodedAnswers[
"challenge"]]) ? array($challengeQuestions[$decodedAnswers[
"challenge"]]) : array();
447 $challengeQuestions = array_values($challengeQuestions);
450 else $noChallengeQuestions =
true;
452 case "security display":
453 $sql =
"select quest_id, quest_text, example_text from cuquestmaster where quest_lang = 'en_US' order by quest_id";
455 $sth = db_query($sql, $dbh);
457 throw new Exception(
"master question query failed.", 6);
458 for($i = 0; $array = db_fetch_assoc($sth, $i); $i++)
460 $id = HCU_array_key_exists(
"quest_id", $array) ? intval($array[
"quest_id"]) : 0;
461 $answer = HCU_array_key_exists($id, $decodedAnswers[
"answers"]) ? $decodedAnswers[
"answers"][$id] :
null;
462 $challengeQuestionDDL[] = $array;
465 $array[
"answer"] = $answer;
466 $challengeQuestions[] = $array;
476 $returnArray= array(
"code" =>
"$code",
"errors" => $errors,
"data" => $challengeQuestions,
"noRecord" => $noRecord,
"sqls" => $sqls,
477 "requireChallengeQuestions" => $noChallengeQuestions || $forceChallengeQuestions,
"forcePassword" => $forcePassword);
478 if ($mode ==
"security display")
479 $returnArray[
"ddl"] = $challengeQuestionDDL;
490 function loginPrintButtons($isLogin =
false, $showStartOver =
true)
492 $continueLabel = $isLogin ?
"Log In" :
"Continue";
494 <div
class=
"form-group hcuSpacer">
495 <div
class=
"col-xs-12 col-sm-6 col-md-4">
496 <button tabindex=
"0" id=
"submitBtn" class=
"k-button k-primary hcu-all-100 hcu-xs-btn-margin-top hcu-xs-btn-pad"><i
class=
"fa fa-lock fa-lg"></i><?php echo $continueLabel; ?></button>
498 <?php
if ($showStartOver) { ?>
499 <div
class=
"col-xs-12 col-sm-6 col-md-4">
500 <button tabindex=
"0" id=
"clearBtn" class=
"k-button hcu-all-100 hcu-xs-btn-margin-top hcu-xs-btn-pad"><i
class=
"fa fa-refresh fa-lg"></i>Start Over</button>
513 function printButtons($buttonArray, $inModal =
false, $inTemplate =
false)
516 $buttonString .=
"<div class=\"row form-group hcuSpacer hcu-sm-auto-width\">";
517 $buttonFound =
false;
518 foreach($buttonArray as $record)
520 if (HCU_array_key_exists(
"isLink", $record) && $record[
"isLink"] !==
true)
526 foreach($buttonArray as $record)
528 $primary = HCU_array_key_exists(
"primary", $record) ? $record[
"primary"] :
false;
529 $primaryClass = $primary ===
true ?
"k-primary" :
"";
530 $iconClasses = $primary ===
true ?
"class=\"fa fa-lock fa-lg\"" :
"";
540 $sizeClass = HCU_array_key_exists(
"sizeClass", $record) ? trim($record[
"sizeClass"]) :
"col-md-$sz3";
541 $href = HCU_array_key_exists(
"href", $record) ? trim($record[
"href"]) :
"";
542 $href = $href ==
"" ? ($inTemplate ?
'href="\\\\#"' :
"href=\"#\"") :
"href=\"$href\"";
543 $type = HCU_array_key_exists(
"isFormSubmit", $record) ? $record[
"isFormSubmit"] :
false;
544 $type = $type ===
true ?
"type=\"submit\"" :
"";
545 $disabledClass = HCU_array_key_exists(
"disabled", $record) ? $record[
"disabled"] :
false;
546 $disabledClass = $disabledClass ===
true ?
"k-state-disabled" :
"";
547 $class = HCU_array_key_exists(
"class", $record) ? trim($record[
"class"]) :
"";
548 $isLink = HCU_array_key_exists(
"isLink", $record) ? $record[
"isLink"] :
false;
549 $id = HCU_array_key_exists(
"id", $record) ? trim($record[
"id"]) :
"";
550 $text = HCU_array_key_exists(
"text", $record) ? trim($record[
"text"]) :
"";
551 $additionalClasses = HCU_array_key_exists(
"additionalClasses", $record) ? trim($record[
"additionalClasses"]) :
"";
553 $buttonString .=
"<div class=\"col-xs-$sz1 col-sm-$sz2 $sizeClass\">";
554 if ($isLink ===
true)
556 $buttonString .=
"<a $href id=\"$id\" class=\"linkLikeButton $primaryClass $disabledClass $class hcu-xs-100-only hcu-all-100 hcu-xs-btn-margin-top" 557 .
" hcu-xs-btn-pad $additionalClasses\">$text</a>";
562 $buttonString .=
"<button $type tabindex=\"0\" id=\"$id\" class=\"k-button $primaryClass $disabledClass $class hcu-xs-100-only hcu-all-100 hcu-xs-btn-margin-top";
563 $buttonString .=
" hcu-xs-btn-pad $additionalClasses\"><i $iconClasses></i>$text</button>";
565 $buttonString .=
"</div>";
567 $buttonString .=
"</div>";
577 function printHubLabelBlock($labelArray)
579 <?php
foreach($labelArray as $label => $value) { ?>
580 <div
class=
"col-xs-12 col-sm-6">
581 <label><?php echo $label; ?> </label><?php echo trim(str_replace(
'\\',
'\\\\', $value)); ?>
592 function loginPrintLabelBlock($labelArray)
594 <div
class=
"form-group col-xs-12"><div
class=
"k-block hcu-login-block"><div
class=
"hcu-summary-block"><div
class=
"summary-desc">
595 <?php
foreach($labelArray as $label => $value) { ?>
596 <?php
if (trim($value) !=
"") { ?>
597 <div
class=
"form-group col-xs-12">
598 <label
class=
"col-xs-12"><?php echo $label; ?> </label>
599 <div
class=
"col-xs-12 admIndent"><?php echo trim(str_replace(
'\\',
'\\\\', $value)); ?></div>
603 </div></div></div></div>
620 function loginPrintInputLine($label, $value, $name, $maxlength=0, $autofocus=
false, $hasSpacer=
true, $type=
"text", $requiredMsg=
"", $additionalClasses=
"", $deliminated=
false)
622 $requiredMsg = trim($requiredMsg);
623 $requiredText = $requiredMsg ==
"" ?
"" :
"required data-required-msg=\"$requiredMsg\"";
624 $autofocusText = $autofocus ===
true ?
"autofocus" : ($autofocus ===
false ?
"" : $autofocus);
625 $spacerText = $hasSpacer ?
"hcuSpacer" :
"";
626 $maxlengthText = $maxlength == 0 ?
"" :
"maxlength=\"$maxlength\"";
627 $classes = array(
"hcu-all-100");
628 $typeText =
"type=\"$type\"";
629 $delimStart = $deliminated ?
"+ '" :
"";
630 $delimEnd = $deliminated ?
"'" :
"";
632 <?php echo $delimEnd; ?><div
class=
"row form-group <?php echo $spacerText; ?>"><?php echo $delimEnd; ?>
633 <?php echo $delimStart; ?><label
class=
"col-xs-12 col-md-8"><?php echo $label; ?> </label><?php echo $delimEnd; ?>
634 <?php echo $delimStart; ?><div
class=
"col-xs-12 col-md-8"><?php echo $delimEnd; ?>
635 <?php echo $delimStart; ?><input name=
"<?php echo $name; ?>" class=<?php echo chr(34);
if ($type !=
'checkbox') { ?>hcu-all-100 k-input k-textbox<?php }?><?php echo $delimEnd; ?>
636 <?php echo $delimStart; ?><?php echo $additionalClasses . chr(34)
637 <?php echo $delimStart; ?><?php echo $typeText; ?> <?php echo $maxlengthText; ?>>
639 <p data-
for=<?php echo chr(34) . $name . chr(34); ?>
class=
"k-invalid-msg"></p></div></div><?php echo $delimEnd; ?>
642 function dialogPrintInputLine($label, $value, $name, $maxlength = 0, $autofocus =
false, $type =
"text", $padding=
false, $additionalClasses =
"", $delimiter =
true, $usePlus =
true,
643 $thankYouSirMayIHaveAnother =
false)
645 $delimiter = $delimiter ===
true ?
"'" : ($delimiter ===
false ?
"" : $delimiter);
646 $usePlus = !$delimiter || !$usePlus ?
"" :
"+";
647 $padding = !$padding ?
"hcu-no-padding" :
"";
648 $spacingA = !$thankYouSirMayIHaveAnother ?
"col-xs-4" :
"col-xs-3";
649 $spacingB = !$thankYouSirMayIHaveAnother ?
"col-xs-8" :
"col-xs-9";
650 print
"$usePlus $delimiter<div class=\"row hcuSpacer\"><label class=\"$spacingA $padding\">$label</label><div class=\"$spacingB $padding\">" 651 .
"<input value=\"$value\" id=\"$name\" name=\"$name\" type=\"$type\" " . ($maxlength != 0 ?
"maxlength=\"$maxlength\"" :
"") .
"$autofocus class=\"hcu-all-100 k-input k-textbox $additionalClasses\">" 652 .
"</div></div>$delimiter";
655 function dialogPrintCheckboxLine($name, $text, $checked=
true, $additionalClasses =
"", $offset =
true, $padding =
true, $delimiter =
true, $usePlus =
true,
656 $thankYouSirMayIHaveAnother =
false)
658 $delimiter = $delimiter ===
true ?
"'" : ($delimiter ===
false ?
"" : $delimiter);
659 $usePlus = !$delimiter || !$usePlus ?
"" :
"+";
660 $checked = $checked ===
true ?
"checked" : ($checked ===
false ?
"" : $checked);
661 $padding = $padding ?
"" :
"hcu-no-padding";
662 $spacingA = !$thankYouSirMayIHaveAnother ?
"col-xs-4" :
"col-xs-3";
663 $spacingB = !$thankYouSirMayIHaveAnother ?
"col-xs-8" :
"col-xs-9";
664 $offset = $offset ?
"<label class=\"$spacingA $padding\"> </label>" :
"";
665 print
"$usePlus $delimiter<div class=\"row hcuSpacer\">$offset" 666 .
"<div class=\"$spacingB checkbox $padding $additionalClasses\"><label><input name=\"$name\" type=\"checkbox\" $checked>$text</label></div></div>$delimiter";
679 function printCheckboxLine($label, $name, $checked=
false, $hasSpacer=
true, $additionalClasses=
"")
681 $spacerText = $hasSpacer ?
"hcuSpacer" :
"";
682 $checkedText = $checked ===
true ?
"checked" : ($checked ===
false ?
"" : $checked);
684 <div
class=
"row form-group <?php echo $spacerText; ?>">
685 <label
class=
"col-xs-10 col-md-10"><?php echo $label; ?> </label>
686 <div
class=
"col-xs-1 col-md-1">
687 <input name=
"<?php echo $name; ?>" type=
"checkbox" <?php echo $checkedText; ?>
class=
"<?php echo $additionalClasses; ?>">
701 function loginPrintDivLine($label, $id, $hasSpacer=
true, $classes=
"hcu-all-100")
703 <div
class=
"row form-group <?php echo $hasSpacer ? 'hcuSpacer' : ''; ?>">
704 <?php
if (trim($label) !=
"") { ?>
705 <label
class=
"col-xs-12 col-md-8"><?php echo $label; ?> </label>
707 <div
class=
"col-xs-12 col-md-8">
708 <div
id=
"<?php echo $id; ?>" class=
"<?php echo $classes; ?>"></div>
720 function printHeader($message, $isModal=
false)
722 printSimple(
"<h4 class=\"h4 hcuSpacerx\">$message</h4>", $isModal);
732 function printMessage($message, $isModal=
false)
734 printSimple($message, $isModal);
744 function printGridDiv($id, $isModal=
false)
746 printSimple(
"<div id='$id'></div>", $isModal);
756 function printSimple($line, $isModal=
false)
758 $sz = $isModal ? 11 : 12;
760 <div
class=
"row form-group"><div
class=
"col-xs-<?php echo $sz; ?>"><?php echo $line; ?></div></div>
775 function checkPass($pSysEnv, $dbh, $username, $password, $cu, $chksecure, $creditUnionCookieName =
"", $creditUnionCookieKey =
"", $accessCheck =
false, $email =
"",
776 $doUnionStuff =
true, $isSkip =
false, $setCookieIfNotExists =
true)
781 global $MEM_FORCE_RESET;
785 $TicketExpires = (array_key_exists(
'expires', $pSysEnv[
'ticket']) ? $pSysEnv[
'ticket'][
'expires'] : 900);
787 $username = strtolower(trim($username));
788 $sql =
"select trim(a.pname), trim(au.passwd), trim(au.cu), db, lastupdate, livebatch, au.failedremain, au.forceremain, au.forcechange, au.pwchange, au.lastlogin, au.failedlogin, a.flagset, a.flagset2, a.flagset3, trim(au.email), trim(au.confidence), au.userflags & {$MEM_FORCE_RESET}::int4, au.mfaquest from cuadmin a join cuadminusers au on a.cu = au.cu 789 where lower(au.user_name)='" . prep_save($username) .
"' and au.cu= '" . prep_save($cu) .
"' limit 1";
791 $sth = db_query($sql,$dbh);
793 throw new exception(
"User query failed.", 4);
794 if (db_num_rows($sth) == 0)
795 throw new Exception(
"User not found.", 3);
796 list($savename, $savepass,$cu, $db, $lastupdate, $lb, $failedremain, $fremain, $fchange, $pchange, $llog, $flog, $flagset, $flagset2, $flagset3,
797 $savemail,$saveword, $freset, $mfa) = db_fetch_array($sth,0);
799 $failedremain = (is_null($failedremain) ? 5 : $failedremain);
800 $fremain = (is_null($fremain) ? 5 : $fremain);
801 $fchange = (is_null($fchange) ?
'N' : $fchange);
802 $db = (trim($db)==
"" ?
"_" : strtoupper(rtrim($db)));
803 $lastupdate = (trim(
"$lastupdate")==
"" ?
"Unknown" : urlencode(trim($lastupdate)));
804 $lb = (is_null($lb) ?
"B" : strtoupper(rtrim($lb)));
805 $flagset = (is_null($flagset) ? 0 : $flagset);
806 $flagset2 = (is_null($flagset2) ? 0 : $flagset2);
807 $flagset3 = (is_null($flagset3) ? 0 : $flagset3);
811 if ($failedremain <= 0 || (($fchange ==
'Y' || $freset != 0) && $fremain <=0))
812 throw new Exception(
"Account is Locked", 1);
814 $email = trim($email);
815 if ($accessCheck && strtolower(trim($savemail)) != strtolower($email) && trim($savemail) !=
'')
816 throw new exception(
"Email doesn't match.", 5);
818 if (!password_verify($password, $savepass))
819 throw new Exception(
"Password doesn't match.", 2);
822 $pchange = (is_null($pchange) ? date(
'Ymd') : $pchange);
823 $llog = (trim(
"$llog")==
"" ?
"None" : urlencode(trim($llog)));
824 $flog = (trim(
"$flog")==
"" ?
"None" : urlencode(trim($flog)));
827 $expires = $now + $TicketExpires;
828 $ip_address = $_SERVER[
'REMOTE_ADDR'];
830 $mycookie =
"Cip=$ip_address&Ctime=$now&Cu=$cu&Cn=$username&Cname=$savename&Cd=$db&Ch=hash&Ce=$expires&Cl=$lb&Clu=$lastupdate&Fplog=$llog&Fflog=$flog&Ffchg=$fchange" 831 .
"&Ffremain=$fremain&Fset=$flagset&Fset2=$flagset2&Fset3=$flagset3";
833 Set_aTicket($pSysEnv,
"",
"$mycookie");
835 apache_note(
'user_name',
"${cu}:${username}");
837 $mfa = HCU_JsonDecode($mfa);
839 $mfa = array(
"answers" => array());
840 $mfa[
"challenge"] = 0;
842 if (!$accessCheck && $chksecure ==
'Y')
843 Set2FactorAdmin($pSysEnv, $savepass, $savemail, $saveword, $mfa, $username, $setCookieIfNotExists);
845 $sql =
"select admtrackmfa('$cu','$username', '" . ($isSkip ? $fchange :
"N") .
"','$pchange', '" . prep_save(PrepareMfaQuestString($mfa)) .
"')";
847 $sth = db_query($sql,$dbh);
849 $expired = $doUnionStuff && $fchange ==
'Y';
852 $persists = time() + $pSysEnv[
'ticket'][
'persists'];
853 $ticketContents = hcuOpenSSLEncrypt($cu,
"NONE");
855 HCU_setcookie_env($pSysEnv, $creditUnionCookieName, $ticketContents[
"message"], $persists);
856 HCU_setcookie_env($pSysEnv,
"${creditUnionCookieName}Hash", $ticketContents[
"hash"], $persists);
862 if ($e->getCode() != 1)
864 $sql =
"select admfailmfa('$cu', '$username',32, '$mfa')";
866 $sth = db_query($sql, $dbh);
867 throw new Exception(
"Invalid User Name or Password.", 1);
871 $answers = HCU_array_key_value(
"answers", $mfa);
872 $hasAnswers = $answers ===
false ? false : count($answers) > 0;
873 $returnArray = array(
"code" =>
"$code",
"error" =>
"$error",
"expired" => $expired,
"cookie" => $mycookie,
"forceSecurity" => $freset != 0 || !$hasAnswers,
874 "forcePassword" => $fchange ==
"Y");
882 function printCaptureEnter()
884 $(
"body").on(
"keypress",
"input,.k-button",
function(e) {
885 if ([10, 13].indexOf(e.which) != -1)
886 $(
this).hasClass(
"k-button") ? $(
this).click() : $(
this).closest(
"form").submit();
900 function printCheckboxEvents($gridSelector, $deleteBtnSelector=
"", $closest=
"", $allCheckbox=
".allCheckbox", $rowCheckbox=
".rowCheckbox", $rowMethod=
"")
904 $closestCommand =
"";
905 $rcSelector =
"$gridSelector $rowCheckbox:enabled";
906 $rcCheckedSelector =
"\$(\"$rcSelector:checked\")";
907 $rcNotCheckedSelector =
"\$(\"$rcSelector:not(:checked)\")";
908 $acSelector =
"\$(\"$gridSelector $allCheckbox\")";
909 $rcSelector =
"\$(\"$rcSelector\")";
913 $closestCommand =
"var intermediate= \$(this).closest(\"$closest\");";
914 $rcSelector =
"\$(intermediate).find(\"$rowCheckbox";
915 $rcCheckedSelector =
"$rcSelector:checked\")";
916 $rcNotCheckedSelector =
"$rcSelector:not(:checked)\")";
917 $acSelector =
"\$(intermediate).find(\"$allCheckbox\")";
918 $rcSelector =
"$rcSelector\")";
921 $(
"<?php echo $gridSelector; ?>").on(
"click",
"<?php echo $allCheckbox; ?>",
function() {
922 var checked = $(
this).prop(
"checked");
923 var data = $(
"<?php echo $gridSelector; ?>").data(
"kendoGrid").dataSource.view(); <?php
924 for(var i = 0; i != data.length; i++)
926 data[i].checked = checked;
929 <?php
if ($rowMethod !=
"") { ?>
930 if (typeof(<?php echo $rowMethod; ?>) ==
"function")
934 <?php echo $rcNotCheckedSelector; ?>.each(
function() {
935 (<?php echo $rowMethod; ?>)(checked, $(
this));
940 <?php echo $rcCheckedSelector; ?>.each(
function() {
941 (<?php echo $rowMethod; ?>)(checked, $(
this));
947 <?php echo $closestCommand; ?>
948 <?php echo $rcSelector; ?>.prop(
"checked", checked);
950 <?php
if ($deleteBtnSelector !=
"") { ?>
951 if (<?php echo $rcCheckedSelector; ?>.length > 0)
952 $(
"<?php echo $deleteBtnSelector; ?>").removeClass(
"k-state-disabled vsgDisabled");
954 $(
"<?php echo $deleteBtnSelector; ?>").addClass(
"k-state-disabled vsgDisabled");
958 $(
"<?php echo $gridSelector; ?>").on(
"click",
"<?php echo $rowCheckbox; ?>",
function() {
959 var checked = $(
this).prop(
"checked");
960 var dataItem = $(
"<?php echo $gridSelector; ?>").data(
"kendoGrid").dataItem($(
this).closest(
"tr"));
961 dataItem.checked = checked;
963 <?php echo $closestCommand; ?>
964 if (checked && <?php echo $rcNotCheckedSelector; ?>.length == 0)
965 <?php echo $acSelector; ?>.prop(
"checked",
true);
967 <?php echo $acSelector; ?>.prop(
"checked",
false);
969 <?php
if ($deleteBtnSelector !=
"") { ?>
970 if (<?php echo $rcCheckedSelector; ?>.length > 0)
971 $(
"<?php echo $deleteBtnSelector; ?>").removeClass(
"k-state-disabled vsgDisabled");
973 $(
"<?php echo $deleteBtnSelector; ?>").addClass(
"k-state-disabled vsgDisabled");
976 <?php
if ($rowMethod !=
"") { ?>
977 if (typeof(<?php echo $rowMethod; ?>) ==
"function")
978 (<?php echo $rowMethod; ?>)(checked, $(
this));
982 <?php
if ($closest ==
"") { ?>
983 var setAllCheckbox = <?php echo $rcSelector; ?>.length > 0 && <?php echo $rcNotCheckedSelector; ?>.length == 0;
984 <?php echo $acSelector; ?>.prop(
"checked", setAllCheckbox);
986 $(
"<?php echo "$gridSelector $closest
"; ?>").each(
function() {
987 var intermediate = $(
this);
988 var setAllCheckbox = <?php echo $rcSelector; ?>.length > 0 && <?php echo $rcNotCheckedSelector; ?>.length == 0;
989 <?php echo $acSelector; ?>.prop(
"checked", setAllCheckbox);
993 var thisParticularGrid= $(
"<?php echo $gridSelector; ?>").data(
"kendoGrid");
994 thisParticularGrid.bind(
"filter",
function(e) {
995 if (!$(
"<?php echo $gridSelector; ?>").data(
"inFilter"))
997 $(
"<?php echo $gridSelector; ?>").data(
"inFilter",
true);
999 thisParticularGrid.dataSource.filter(e.filter);
1001 <?php
if ($closest ==
"") { ?>
1002 var setAllCheckbox = <?php echo $rcSelector; ?>.length > 0 && <?php echo $rcNotCheckedSelector; ?>.length == 0;
1003 <?php echo $acSelector; ?>.prop(
"checked", setAllCheckbox);
1005 $(
"<?php echo "$gridSelector $closest
"; ?>").each(
function() {
1006 var intermediate = $(
this);
1007 var setAllCheckbox = <?php echo $rcSelector; ?>.length > 0 && <?php echo $rcNotCheckedSelector; ?>.length == 0;
1008 <?php echo $acSelector; ?>.prop(
"checked", setAllCheckbox);
1012 <?php
if ($deleteBtnSelector !=
"") { ?>
1013 if (<?php echo $rcCheckedSelector; ?>.length > 0)
1014 $(
"<?php echo $deleteBtnSelector; ?>").removeClass(
"k-state-disabled");
1016 $(
"<?php echo $deleteBtnSelector; ?>").addClass(
"k-state-disabled");
1019 $(
"<?php echo $gridSelector; ?>").data(
"inFilter",
false);
1041 function validatePasswordRules($dbh, $cuCode, $showSQL, $password, $addRuleErrors)
1046 $validForAdmin =
true;
1047 $forceChange =
false;
1049 $sql =
"select pwdconfig from cuadmin where cu='$cuCode'";
1051 if (($sth = db_query($sql, $dbh)) ===
false)
1054 $errors[] = db_last_error();
1058 $rules = trim(db_fetch_row($sth, 0)[0]);
1061 $rules = HCU_JsonDecode($rules);
1062 if (!is_array($rules))
1065 $errors[] =
"Password rules is not a valid json array.";
1069 if (!isset($rules[
"use"]) || $rules[
"use"] != 1)
1070 $rules = array(
"len" => 6,
"letter" => 1,
"digit" => 1);
1072 if (isset($rules[
"len"]) && strlen($password) < $rules[
"len"])
1075 $errors[] =
"Password is too short.";
1076 $forceChange =
true;
1079 preg_match(
'/\d/', $password, $numDigits);
1080 preg_match(
'/[[:lower:]]/', $password, $numLower);
1081 preg_match(
'/[[:upper:]]/', $password, $numUpper);
1082 preg_match(
'/[!#@$%^&*?_~()-]/', $password, $numSpec);
1083 preg_match(
'/[\'"]/', $password, $numInvalid);
1085 if (isset($rules[
"digit"]) && $numDigits < $rules[
"digit"])
1090 $errors[] =
"Password needs " . $rules[
"digit"] .
" digits.";
1092 $forceChange =
true;
1095 if (isset($rules[
"lower"]) && $numLower < $rules[
"lower"])
1100 $errors[] =
"Password needs " . $rules[
"lower"] .
" lower letters.";
1102 $forceChange =
true;
1105 if (isset($rules[
"upper"]) && $numUpper < $rules[
"upper"])
1110 $errors[] =
"Password needs " . $rules[
"upper"] .
" upper letters.";
1112 $forceChange =
true;
1115 if (isset($rules[
"spec"]) && $numUpper < $rules[
"spec"])
1120 $errors[] =
"Password needs " . $rules[
"spec"] .
" special characters.";
1122 $forceChange =
true;
1125 if ($numInvalid > 0)
1127 $errors[] =
"Password has illegal characters.";
1128 $validForAdmin =
false;
1134 db_free_result($sth);
1135 $returnArray= array(
"code" =>
"$code",
"errors" => $errors,
"validForAdmin" => $validForAdmin,
"forceChange" => $forceChange);
1137 $returnArray[
"sqls"]= $sqls;
1138 return $returnArray;
1146 function printJavascriptHashCode()
1148 String.prototype.hashCode =
function()
1151 if (this.length == 0)
return hash;
1152 for (i = 0; i < this.length; i++)
1154 char = this.charCodeAt(i);
1155 hash = ((hash << 5)-hash)+char;
1178 function userDeletion($dbh, $Cu, $userId, &$sqls)
1180 $sql =
"delete from ${Cu}extaccount where user_id= $userId";
1182 $sth = db_query($sql, $dbh);
1184 throw new exception(
"extaccount delete failed.", 106);
1186 $sql =
"delete from ${Cu}transdtl where id in (select dtl.id from ${Cu}transdtl dtl inner join ${Cu}transhdr hdr on dtl.transhdr_id = hdr.id and hdr.posted_by = $userId)";
1188 $sth = db_query($sql, $dbh);
1190 throw new exception(
"dtl delete failed.", 107);
1192 $sql =
"delete from ${Cu}transhdr where posted_by = $userId";
1194 $sth = db_query($sql, $dbh);
1196 throw new exception(
"hdr delete failed.", 108);
1198 $sql =
"delete from cu_alerts where user_id= $userId and cu= '$Cu'";
1200 $sth = db_query($sql, $dbh);
1202 throw new exception(
"cu_alerts delete failed.", 110);
1204 $sql =
"delete from ${Cu}userrights where user_id= $userId";
1206 $sth = db_query($sql, $dbh);
1208 throw new exception(
"userrights delete failed.", 112);
1210 $sql =
"delete from ${Cu}usercontact where contact_id in (select contact from ${Cu}user where user_id= $userId)";
1212 $sth = db_query($sql, $dbh);
1214 throw new exception(
"usercontact delete failed.", 113);
1216 $sql =
"delete from ${Cu}useraccounts where user_id= $userId";
1218 $sth = db_query($sql, $dbh);
1220 throw new exception(
"useraccounts delete failed.", 114);
1222 $sql =
"delete from ${Cu}memberacctrights where user_id= $userId";
1224 $sth = db_query($sql, $dbh);
1226 throw new exception(
"memberacctrights delete failed.", 115);
1228 $sql =
"delete from ${Cu}user where user_id= $userId";
1230 $sth = db_query($sql, $dbh);
1232 throw new exception(
"user delete failed.", 116);
1234 $sql =
"delete from ${Cu}extkey where user_id= $userId";
1236 $sth = db_query($sql, $dbh);
1238 throw new exception(
"extkey failed.", 139);
1240 $sql =
"delete from cusmstransaction where user_id= $userId and cu='$Cu'";
1242 $sth = db_query($sql, $dbh);
1244 throw new exception(
"cusmstransaction failed.", 140);
1246 $sql =
"delete from cuadmeco where user_id= $userId and cu='$Cu'";
1248 $sth = db_query($sql, $dbh);
1250 throw new exception(
"cuadmeco failed.", 141);
1252 $sql =
"delete from cucmsresponse where user_id= $userId and cu='$Cu'";
1254 $sth = db_query($sql, $dbh);
1256 throw new exception(
"cucmsresponse failed.", 142);
1258 $sql =
"delete from cusmstrack where user_id= $userId and cu='$Cu'";
1260 $sth = db_query($sql, $dbh);
1262 throw new exception(
"cusmstrack failed.", 143);
1264 $sql =
"delete from cusms where user_id= $userId and cu='$Cu'";
1266 $sth = db_query($sql, $dbh);
1268 throw new exception(
"cusms failed.", 144);
1270 $sql =
"delete from cu_scheduledtxn where user_id= $userId and cu='$Cu'";
1272 $sth = db_query($sql, $dbh);
1274 throw new exception(
"cu_scheduledtxn failed.", 145);
1288 function groupDeletion($dbh, $Cu, $groupId, &$sqls)
1290 $sql =
"delete from ${Cu}grouprights where group_id= $groupId";
1292 $sth = db_query($sql, $dbh);
1294 throw new exception(
"grouprights delete failed.", 117);
1296 $sql =
"delete from ${Cu}achpartner where group_id= $groupId";
1298 $sth = db_query($sql, $dbh);
1300 throw new exception(
"achpartner delete failed.", 118);
1302 $sql =
"delete from ${Cu}usercontact where contact_id in (select contact from ${Cu}group where group_id= $groupId)";
1304 $sth = db_query($sql, $dbh);
1306 throw new exception(
"usercontact delete failed.", 131);
1308 $sql =
"delete from ${Cu}group where group_id= $groupId";
1310 $sth = db_query($sql, $dbh);
1312 throw new exception(
"group delete failed.", 121);
1327 function accountDeletion($dbh, $Cu, $accountnumber, &$sqls, $allMeansAll=
false)
1333 $sql =
"delete from ${Cu}extkey where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1335 $sth = db_query($sql, $dbh);
1337 throw new exception(
"extkey delete failed.", 124);
1339 $sql =
"delete from cu_alerts where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu= '$Cu'";
1341 $sth = db_query($sql, $dbh);
1343 throw new exception(
"cu_alerts delete failed.", 111);
1345 $sql =
"delete from cusmstransaction where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu= '$Cu'";
1347 $sth = db_query($sql, $dbh);
1349 throw new exception(
"cusmstransaction delete failed.", 126);
1351 $sql =
"delete from cucmsresponse where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu='$Cu'";
1353 $sth = db_query($sql, $dbh);
1355 throw new exception(
"cucmsresponse delete failed.", 128);
1357 $sql =
"delete from cusmstrack where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu='$Cu'";
1359 $sth = db_query($sql, $dbh);
1361 throw new exception(
"cusmstrack delete failed.", 129);
1363 $sql =
"delete from cusms where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu='$Cu'";
1365 $sth = db_query($sql, $dbh);
1367 throw new exception(
"cusms delete failed.", 130);
1369 $sql =
"delete from ${Cu}memberacctrights where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1371 $sth = db_query($sql, $dbh);
1373 throw new exception(
"memberacctrights delete failed.", 132);
1375 $sql =
"delete from ${Cu}useraccounts where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1377 $sth = db_query($sql, $dbh);
1379 throw new exception(
"useraccounts delete failed.", 136);
1381 $sql =
"delete from ${Cu}transdtl where id in (select dtl.id from ${Cu}memorizeddtl dtl inner join ${Cu}transhdr hdr 1382 on dtl.transhdr_id = hdr.id and hdr.accountnumber= '" . prep_save($accountnumber, 12) .
"')";
1384 $sth = db_query($sql, $dbh);
1386 throw new exception(
"dtl delete failed.", 137);
1388 $sql =
"delete from ${Cu}transhdr where accountnumber = '" . prep_save($accountnumber, 12) .
"'";
1390 $sth = db_query($sql, $dbh);
1392 throw new exception(
"hdr delete failed.", 138);
1394 $sql =
"delete from ${Cu}useraccounts where accountnumber = '" . prep_save($accountnumber, 12) .
"'";
1396 $sth = db_query($sql, $dbh);
1398 throw new exception(
"useraccounts delete failed.", 139);
1402 $sql =
"delete from cusmstransaction where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu= '$Cu' and user_id is null";
1404 $sth = db_query($sql, $dbh);
1406 throw new exception(
"cusmstransaction delete failed.", 145);
1409 $sql =
"delete from cuovermicr where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu= '$Cu'";
1411 $sth = db_query($sql, $dbh);
1413 throw new exception(
"cuovermicr delete failed.", 109);
1415 $sql =
"delete from ${Cu}holds where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1417 $sth = db_query($sql, $dbh);
1419 throw new exception(
"holds delete failed.", 125);
1421 $sql =
"delete from ${Cu}memberacct where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1423 $sth = db_query($sql, $dbh);
1425 throw new exception(
"memberacct delete failed.", 133);
1427 deleteAccountHistory($dbh, $Cu, $accountnumber, $sqls);
1429 $sql =
"delete from ${Cu}accountbalance where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1431 $sth = db_query($sql, $dbh);
1433 throw new exception(
"accountbalance delete failed.", 134);
1435 $sql =
"delete from ${Cu}loanbalance where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1437 $sth = db_query($sql, $dbh);
1439 throw new exception(
"loanbalance delete failed.", 135);
1441 $sql =
"delete from ${Cu}crossaccounts where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1443 $sth = db_query($sql, $dbh);
1445 throw new exception(
"crossaccounts delete failed.", 136);
1459 function deleteAccountHistory($dbh, $Cu, $accountnumber, &$sqls)
1461 $sql =
"delete from ${Cu}accounthistory where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1463 $sth = db_query($sql, $dbh);
1465 throw new exception(
"Account history delete failed.", 102);
1467 $sql =
"delete from ${Cu}loanhistory where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"'";
1469 $sth = db_query($sql, $dbh);
1471 throw new exception(
"Loan history delete failed.", 103);
1488 function checkAccountUsage($dbh, $Cu, $userId, $accountnumber, &$sqls)
1490 $sql =
"select 'FOUND' from ${Cu}extkey where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id <> $userId";
1492 $sth = db_query($sql, $dbh);
1494 throw new exception(
"extkey failed.", 108);
1495 if (db_num_rows($sth) > 0)
1498 $sql =
"select 'FOUND' from cu_alerts where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and cu = '$Cu' and user_id <> $userId";
1500 $sth = db_query($sql, $dbh);
1502 throw new exception(
"cu_alerts failed.", 109);
1503 if (db_num_rows($sth) > 0)
1506 $sql =
"select 'FOUND' from ${Cu}useraccounts where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id <> $userId";
1508 $sth = db_query($sql, $dbh);
1510 throw new exception(
"useraccounts failed.", 100);
1511 if (db_num_rows($sth) > 0)
1514 $sql =
"select 'FOUND' from ${Cu}memberacctrights where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id <> $userId";
1516 $sth = db_query($sql, $dbh);
1518 throw new exception(
"memberacctrights failed.", 110);
1519 if (db_num_rows($sth) > 0)
1522 $sql =
"select 'FOUND' from cusmstransaction where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id is not null and user_id <> $userId and cu='$Cu'";
1524 $sth = db_query($sql, $dbh);
1526 throw new exception(
"cusmstransaction failed.", 120);
1527 if (db_num_rows($sth) > 0)
1530 $sql =
"select 'FOUND' from cucmsresponse where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id <> $userId and cu='$Cu'";
1532 $sth = db_query($sql, $dbh);
1534 throw new exception(
"cucmsresponse failed.", 140);
1535 if (db_num_rows($sth) > 0)
1538 $sql =
"select 'FOUND' from cusmstrack where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id is not null and user_id <> $userId and cu='$Cu'";
1540 $sth = db_query($sql, $dbh);
1542 throw new exception(
"cusmstrack failed.", 150);
1543 if (db_num_rows($sth) > 0)
1546 $sql =
"select 'FOUND' from cusms where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and user_id is not null and user_id <> $userId and cu='$Cu'";
1548 $sth = db_query($sql, $dbh);
1550 throw new exception(
"cusms failed.", 160);
1551 if (db_num_rows($sth) > 0)
1554 $sql =
"select 'FOUND' from ${Cu}transhdr where trim(accountnumber) = '" . prep_save($accountnumber, 12) .
"' and posted_by is not null and posted_by <> $userId";
1556 $sth = db_query($sql, $dbh);
1558 throw new exception(
"transhdr failed.", 170);
1559 if (db_num_rows($sth) > 0)
1576 function PrintGAScript($pServName, $pCu, $pScript) {
1579 if (strrpos($pScript,
".") !==
false) {
1580 $pScript = substr($pScript, 0, strrpos($pScript,
"."));
1585 if (typeof ga ===
'function') {
1588 ga(
'set',
'dimension1',
'$pServName' );
1589 ga(
'set',
'dimension2',
'$pScript' );
1590 ga(
'set',
'dimension3',
'$pCu' );
1591 ga(
'send',
'pageview');
1619 function ReadUser($dbh, $cuCode, $username, $getPrograms, $getChallengeQuestions, $getAllChallengeQuestions, $getAuditRecords, $logger) {
1622 $privilegeRecords = array();
1623 $username = mb_strtolower($username);
1625 $sql =
"select au.*, au.user_name as username, coalesce(a.retrylimit,5) as retry, coalesce(a.gracelimit,5) as grace, a.pwdconfig, a.ip_acl, a.user_name as ismaster 1626 from cuadminusers au inner join cuadmin a on au.cu = a.cu where au.cu='$cuCode' and lower(au.user_name)='" . prep_save($username, 50) .
"' limit 1";
1627 $sth = db_query($sql, $dbh);
1629 throw new exception(
"Read query failed.", 1);
1631 if (db_num_rows($sth) == 0) {
1632 throw new exception(
"No user found.", 3);
1634 for($i = 0; $oldArray = db_fetch_assoc($sth, $i); $i++) {
1635 foreach($oldArray as $key => $value) {
1636 if ($key ==
"pwdconfig") {
1637 $value = HCU_JsonDecode($value);
1638 if (!is_array($value)) {
1639 throw new exception(
"Password array is malformed.", 4);
1641 $array[$key] = $value;
1642 }
else if ($key ==
"ismaster") {
1643 $array[$key] = trim($value) == trim($oldArray[
"username"]);
1645 $array[$key] = trim($value);
1651 if ($array[
"usersms"] ==
"") {
1652 $array[
"smsNumber"] =
"";
1655 $sms = explode(
"@", $array[
"usersms"]);
1656 $array[
"smsNumber"] = $sms[0];
1659 if ($array[
"remoteip"] !=
"") {
1660 $validate = explode(
".", $array[
"remoteip"]);
1661 if (count($validate) != 4) {
1662 throw new exception(
"Remote address is not valid.", 9);
1664 foreach($validate as $num) {
1665 if (!is_numeric($num)) {
1666 throw new exception(
"Remote address are not valid.", 10);
1668 if ($num < 0 || $num > 256) {
1669 throw new exception(
"Remote address are not valid.", 11);
1674 if ($array[
"ip_acl"] ==
"") {
1675 $array[
"cuIps"] = array();
1677 $cuIps = explode(
";", $array[
"ip_acl"]);
1678 foreach($cuIps as $ip) {
1679 $validate = explode(
".", $ip);
1680 if (count($validate) != 4) {
1681 throw new exception(
"Cu IP addresses are not valid.", 6);
1683 foreach($validate as $num) {
1684 if (!is_numeric($num)) {
1685 throw new exception(
"Cu IP addresses are not valid.", 7);
1687 if ($num < 0 || $num > 256) {
1688 throw new exception(
"Cu IP addresses are not valid.", 8);
1692 $array[
"cuIps"] = $cuIps;
1695 unset($array[
"usersms"]);
1696 unset($array[
"passwd"]);
1697 unset($array[
"ip_acl"]);
1699 $array[
"booleanForceChange"]= $array[
"forcechange"] ==
"Y";
1701 $userflags = intval($array[
"userflags"]);
1702 $array[
"booleanForceSecurity"] = ($userflags & 2) != 0;
1703 $array[
"booleanMasterPrivileges"] = ($userflags & 4) != 0;
1704 $array[
"booleanRemotePrivileges"] = ($userflags & 64) != 0;
1705 $array[
"booleanLockAccount"] = $array[
"failedremain"] < 1 || (($array[
"booleanForceChange"] || $array[
"booleanForceSecurity"]) && $array[
"forceremain"] < 1);
1706 $array[
"textLockout"] = $array[
"failedremain"] == -1 ?
"Locked By CU" : $array[
"failedremain"];
1707 $array[
"numRemaining"] = $array[
"forceremain"];
1708 $array[
"cuRemoteEnabled"] = count($array[
"cuIps"]) > 0;
1710 $array[
"failReason"] = ($userflags & 8) != 0 ?
"Email" : (($userflags & 16) != 0 ?
"Challenge Response" : (($userflags & 32) != 0 ?
"Password" :
""));
1711 $records[] = $array;
1715 $sql =
"select ap.program, ap.displaytext, ap.description, a.program as checked from cuadminprogs ap 1716 left join cuadminallow a on ap.program = a.program and lower(a.user_name) = '" . prep_save($username, 50) .
"' and a.cu = '$cuCode' 1717 order by ap.sort_order, ap.program";
1718 $sth = db_query($sql, $dbh);
1720 throw new exception(
"Program query failed.", 2);
1722 for($i = 0; $oldArray = db_fetch_assoc($sth, $i); $i++) {
1723 foreach($oldArray as $key => $value) {
1724 $thisArray[$key] = trim($value);
1727 $thisArray[
"checked"] = $thisArray[
"checked"] !=
"";
1728 $thisArray[
"prevChecked"] = $thisArray[
"checked"];
1729 $privilegeRecords[] = $thisArray;
1731 $records[0][
"programs"] = $privilegeRecords;
1734 if ($getChallengeQuestions) {
1735 $challengeQuestions = getAdmChallengeQuestions($dbh, $cuCode, $username, $getAllChallengeQuestions ?
"security display" :
"admin display");
1736 $records[0][
"mfaquest"] = $challengeQuestions[
"data"];
1737 $records[0][
"mfaddl"] = $challengeQuestions[
"ddl"];
1740 if ($getAuditRecords) {
1741 $records[0][
"auditRecords"] = GetAuditRecords($dbh, $cuCode, $username, $logger);
1744 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"record" => $records);
1746 }
catch (exception $e) {
1747 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
1749 return $returnArray;
1781 function saveUser($pSysEnv, $dbh, $cuCode, $parameters, $loggedInUser, $securityMode, $createCookieIfNotExists=
false, $isSkip=
false, $passwordRequired=
false)
1786 $updateTable = array();
1787 $adminTicketString =
"";
1788 $serverIPFound =
false;
1789 $serverIPFoundRelevant =
false;
1790 $serverIP = trim( $_SERVER[
"REMOTE_ADDR"] );
1794 $chkSecure = HCU_array_key_value(
"chksecure", $parameters);
1795 $chkSecure = $chkSecure ===
false ? false : trim($chkSecure) ==
"Y";
1796 $username = mb_strtolower(isset($parameters[
"username"]) ? trim($parameters[
"username"]) : $loggedInUser);
1797 $isLogInUser = $username == $loggedInUser;
1798 $parameters[
"username"] = $username;
1800 $sql =
"select userflags from cuadminusers where lower(user_name)= '$username' and cu = '$cuCode'";
1802 $sth = db_query($sql, $dbh);
1804 throw new exception(
"Userflags query failed.", 43);
1805 $row = db_fetch_row($sth);
1806 $userFlags = intval($row[0]);
1807 $previousUserFlags = $userFlags;
1809 if ($securityMode ==
"none")
1811 if ($username ==
"")
1812 throw new exception(
"Username is required.", 1);
1813 if(preg_match(
'/[\'";+]/',$username))
1814 throw new exception(
"Invalid Characters in Username.", 15);
1817 $username = mb_strtolower($loggedInUser);
1819 $remoteAccess = HCU_array_key_exists(
"remoteAccess", $parameters) ? trim($parameters[
"remoteAccess"]) :
"U";
1820 $remoteAccessSet = HCU_array_key_exists(
"remoteAccessSet", $parameters) ? trim($parameters[
"remoteAccessSet"]) :
"N";
1822 $sql =
"select email, passwd, confidence, mfaquest, remoteip from cuadminusers where lower(user_name)= '" . mb_strtolower($loggedInUser) .
"' and cu= '$cuCode'";
1824 $sth = db_query($sql, $dbh);
1826 throw new exception(
"Email query failed.", 9);
1828 $row = db_fetch_assoc($sth);
1829 $email = trim($row[
"email"]);
1830 $currentPassword = trim($row[
"passwd"]);
1831 $confidence = trim($row[
"confidence"]);
1832 $remoteipSet = isset($row[
"remoteip"]) ? trim($row[
"remoteip"]) :
"";
1833 $challengeArray = HCU_JsonDecode(trim($row[
"mfaquest"]));
1834 $emailAddress = HCU_array_key_exists(
"emailAddress", $parameters) ? trim($parameters[
"emailAddress"]) :
"";
1835 $password = HCU_array_key_exists(
"password", $parameters) ? trim($parameters[
"password"]) :
"";
1838 if (in_array($securityMode, array(
"noneWithConfidence",
"setup",
"combined")))
1840 $confidence = HCU_array_key_exists(
"confidence", $parameters) ? trim($parameters[
"confidence"]) :
"";
1842 if ($confidence !=
"")
1843 $updateTable[
"confidence"] = $confidence;
1844 else if ($securityMode !=
"combined")
1845 throw new exception(
"Confidence word is required.", 30);
1848 $questIds = HCU_array_key_exists(
"questIds", $parameters) ? trim($parameters[
"questIds"]) : array_keys($challengeArray[
"answers"]);
1849 $questResponses = HCU_array_key_exists(
"questResponses", $parameters) ? trim($parameters[
"questResponses"]) :
"";
1850 if ($questIds ==
"" || $questResponses ==
"")
1852 if ($securityMode !=
"combined")
1853 throw new exception(
"Challenge questions are required.", 31);
1857 $questIds = HCU_JsonDecode($questIds);
1858 if (!is_array($questIds))
1859 throw new exception(
"Question ids are not valid.", 32);
1860 $questResponses = HCU_JsonDecode($questResponses);
1861 if (!is_array($questResponses))
1862 throw new exception(
"Question responses are not valid.", 33);
1863 if (count($questIds) != 3)
1864 throw new exception(
"Question ids are not valid.", 34);
1865 if (count($questResponses) != 3)
1866 throw new exception(
"Question responses are not valid.", 35);
1867 foreach($questIds as $id)
1869 if (!is_numeric($id) || $id == 0)
1870 throw new exception(
"Question ids are not valid.", 36);
1872 foreach($questResponses as $response)
1874 if (!isset($response))
1875 throw new exception(
"Question responses are not valid.", 39);
1879 $sql =
"select 'FOUND' from cuquestmaster where quest_lang = 'en_US' and quest_id in (" . implode(
",", $questIds) .
")";
1881 $sth = db_query($sql, $dbh);
1883 throw new exception(
"Master sql failed.", 37);
1884 if (db_num_rows($sth) != 3)
1885 throw new exception(
"Question ids are not valid.", 38);
1886 $challengeArray = array(
"answers" => array(),
"challenge" => 0);
1887 reset($questResponses);
1888 foreach($questIds as $id)
1890 $challengeArray[
"answers"][
"$id"] = current($questResponses);
1891 next($questResponses);
1894 $updateTable[
"mfaquest"] = PrepareMfaQuestString($challengeArray);
1900 if (in_array($securityMode, array(
"setup",
"combined")))
1902 $oldPassword = HCU_array_key_exists(
"oldPassword", $parameters) ? trim($parameters[
"oldPassword"]) :
"";
1903 if ($passwordRequired || $password !=
"")
1905 if ($passwordRequired && $password ==
"")
1906 throw new exception(
"You must enter your new password.", 45);
1908 if ($oldPassword ==
"")
1909 throw new exception(
"You must enter your current password.", 27);
1911 if (!password_verify($oldPassword, $currentPassword))
1912 throw new exception(
"Invalid username or password.", 29);
1913 if (trim($password) == $oldPassword)
1914 throw new exception(
"New password cannot be the same as the old password.", 42);
1915 $updateTable[
"forcechange"] =
"N";
1917 if ($emailAddress !=
"")
1918 $adminTicketString .=
"Ffchg=N&Ml=" . urlencode($emailAddress) .
"&";
1921 if (in_array($securityMode, array(
"none",
"noneWithConfidence",
"setup",
"combined")))
1923 if ($password !=
"")
1925 $thisReturnArray = validatePasswordRules($dbh, $cuCode,
true, $password,
true);
1926 array_merge($sqls, $thisReturnArray[
"sqls"]);
1927 if ($thisReturnArray[
"code"] != 0)
1928 throw new exception(
"Password doesn't conform to the rules.", 5);
1930 $hash = password_hash($password, PASSWORD_DEFAULT);
1931 $updateTable[
"passwd"] =
"$hash";
1932 $updateTable[
"pwchange"] = DBTIMESTAMP_USENOW;
1935 if ($emailAddress !=
"")
1937 if ($emailAddress !=
"" && !(preg_match(
"/^[A-Za-z0-9\.\-_]*\@[A-Za-z0-9\.\-_]*\.[A-Za-z0-9\-_]*/",$emailAddress)))
1938 throw new exception(
"Email address appears to be invalid.", 17);
1939 $updateTable[
"email"] = $emailAddress;
1943 if (in_array($securityMode, array(
"combined"))) {
1944 $remoteAccessSet = ($userFlags & 64) != 0 ?
"Y" :
"N";
1945 $remoteAccess =
"U";
1948 if (!isset($remoteAccess) || trim($remoteAccess) ==
"")
1949 $remoteAccess =
"U";
1952 if (in_array($securityMode, array(
"none",
"noneWithConfidence",
"combined")))
1955 if ($remoteAccessSet ==
"Y" || ($remoteAccessSet ==
"N" && $remoteAccess ==
"N"))
1959 if ($remoteAccess ==
"N") {
1961 $ipAddress =
"NONE";
1962 $serverIPFoundRelevant = $isLogInUser;
1967 $smsNumber = HCU_array_key_exists(
"smsNumber", $parameters) ? trim($parameters[
"smsNumber"]) :
"";
1968 $ipAddress = HCU_array_key_exists(
"ipAddress", $parameters) ? trim($parameters[
"ipAddress"]) :
"";
1971 $valid = $smsNumber ==
"" ? $smsNumber ==
"" : $smsNumber !=
"";
1975 throw new exception(
"SMS number must be defined.", 28);
1976 if ($smsNumber !=
"") {
1977 if (!preg_match(
'/[2-9][0-9]{9}/', $smsNumber))
1978 throw new exception(
"SMS Number is invalid.", 23);
1979 $updateTable[
"usersms"] =
"$smsNumber";
1982 if ($ipAddress !=
"")
1984 $serverIPFoundRelevant = $isLogInUser;
1985 if ($ipAddress ==
"NONE")
1986 $updateTable[
"remoteip"] =
"";
1989 $ips = explode(
";", $ipAddress);
1991 foreach($ips as $ip)
1993 $validIp = $validIp ? filter_var($ip, FILTER_VALIDATE_IP) : false;
1994 $serverIPFound = $serverIPFound || $serverIP == trim($ip);
1997 throw new exception(
"IP Address isn't formatted correctly.", 21);
1998 $updateTable[
"remoteip"] = $ipAddress;
2001 else if ($isLogInUser) {
2002 $ips = explode(
";", $remoteipSet);
2003 $serverIPFound = $serverIPFound || in_array($serverIP, $ips);
2009 if (in_array($securityMode, array(
"none",
"noneWithConfidence",
"combined")))
2011 $realName = HCU_array_key_exists(
"realName", $parameters) ? trim($parameters[
"realName"]) :
"";
2012 if ($realName !=
"")
2014 $updateTable[
"realname"] = $realName;
2015 if (preg_match(
'/[\'"@;]/',$realName))
2016 throw new exception(
"Invalid Characters in Real Name.", 16);
2019 $forceChangesAmount = HCU_array_key_exists(
"forceChangesAmount", $parameters) ? trim($parameters[
"forceChangesAmount"]) :
"";
2020 if ($forceChangesAmount !=
"")
2022 if (!is_numeric($forceChangesAmount))
2023 throw new exception(
"Force Changes Amount is not numeric.", 2);
2024 if ($forceChangesAmount < 0 || $forceChangesAmount > 99)
2025 throw new exception(
"Force Changes needs to be in the range 0-99.", 3);
2026 $updateTable[
"forceremain"] = intval($forceChangesAmount);
2029 $masterPrivileges = HCU_array_key_exists(
"masterPrivileges", $parameters) ? trim($parameters[
"masterPrivileges"]) :
"";
2030 if ($masterPrivileges !=
"")
2032 if ($masterPrivileges ==
"Y")
2037 $forceSecurity = HCU_array_key_exists(
"forceSecurity", $parameters) ? trim($parameters[
"forceSecurity"]) :
"";
2038 if ($forceSecurity !=
"")
2040 if ($forceSecurity ==
"Y")
2045 $forcePassword = HCU_array_key_exists(
"forcePassword", $parameters) ? trim($parameters[
"forcePassword"]) :
"";
2046 if ($forcePassword !=
"")
2048 $updateTable[
"forcechange"] = $forcePassword ==
"Y" ?
"Y" :
"N";
2051 $remoteAccess ==
"U" ? null : ($remoteAccess ==
"Y" ? $userFlags|= 64 : $userFlags&= ~64);
2053 $lockAccount = HCU_array_key_exists(
"lockAccount", $parameters) ? trim($parameters[
"lockAccount"]) :
"";
2054 if ($lockAccount !=
"")
2056 $sql =
"select retrylimit from cuadmin where cu= '$cuCode' limit 1";
2058 $sth = db_query($sql,$dbh);
2060 throw new exception(
"Lock Account query failed.", 6);
2061 $retry = trim(db_fetch_row($sth)[0]);
2062 $retry = $retry ==
"" ? 5 : $retry;
2063 $updateTable[
"failedremain"] = trim($lockAccount) ==
"Y" ? -1 : $retry;
2066 $sql =
"select user_name, ip_acl from cuadmin where cu= '$cuCode' limit 1";
2068 $sth = db_query($sql, $dbh);
2070 throw new exception(
"username query failed.", 18);
2071 $row = db_fetch_assoc($sth,0);
2073 $masterIpAddress = HCU_array_key_exists(
"masterIpAddress", $parameters) ? trim($parameters[
"masterIpAddress"]) :
"";
2074 if ($masterIpAddress !=
"")
2076 if (trim($row[
"user_name"]) != $username)
2077 throw new exception(
"Only the Cu Master user can edit Allowed IP Addresses.", 19);
2079 $serverIPFoundRelevant = $isLogInUser;
2081 if ($masterIpAddress !=
"NONE")
2083 $ips = explode(
";", $masterIpAddress);
2086 foreach($ips as $ip)
2088 $validIp = $validIp ? filter_var($ip, FILTER_VALIDATE_IP) : false;
2089 $serverIPFound = $serverIPFound || $serverIP == trim($ip);
2092 throw new exception(
"Master IP Address isn't formatted correctly.", 7);
2095 $masterIpAddress =
"";
2096 $ipUpdate = array(
"cuadmin" => array(array(
"_action" =>
"update",
"ip_acl" => $masterIpAddress,
"cu" => $cuCode)));
2098 else if ($isLogInUser) {
2099 $ips = explode(
";", trim($row[
"ip_acl"]));
2100 $serverIPFound = $serverIPFound || in_array($serverIP, $ips);
2103 $permTemp = array(
"cu" => $cuCode,
"user_name" => $username);
2105 $addPermissions = HCU_array_key_exists(
"addPermissions", $parameters) ? trim($parameters[
"addPermissions"]) :
"";
2106 if ($addPermissions !=
"")
2108 $addPermissions = HCU_JsonDecode($addPermissions);
2109 if (!is_array($addPermissions))
2110 throw new exception(
"Add Permissions is not formatted correctly.", 10);
2111 if (count($addPermissions) > 0)
2113 $permUpdate1 = array();
2114 foreach($addPermissions as $perm)
2116 $record = $permTemp;
2117 $record[
"_action"] =
"create";
2118 $record[
"program"] = $perm;
2119 $permUpdate1[] = $record;
2122 $permUpdate1 = array(
"cuadminallow" => $permUpdate1);
2126 $removePermissions = HCU_array_key_exists(
"removePermissions", $parameters) ? trim($parameters[
"removePermissions"]) :
"";
2127 if ($removePermissions !=
"")
2129 $removePermissions = HCU_JsonDecode($removePermissions);
2130 if (!is_array($removePermissions))
2131 throw new exception(
"Remove Permissions is not formatted correctly.", 11);
2132 if (count($removePermissions) > 0)
2134 $permUpdate2 = array();
2135 foreach($removePermissions as $perm)
2137 $record = $permTemp;
2138 $record[
"_action"] =
"delete";
2139 $record[
"program"] = $perm;
2140 $permUpdate2[] = $record;
2142 $permUpdate2 = array(
"cuadminallow" => $permUpdate2);
2146 else if ($securityMode ==
"setup")
2148 if (trim($parameters[
"forcechange"]) ==
"Y" && !isset($password))
2149 throw new exception(
"Password is required.", 40);
2150 if (!isset($emailAddress))
2151 throw new exception(
"Email Address is required.", 41);
2153 $updateTable[
"forcechange"] =
"N";
2156 $envVars = array(
"cu" => $cuCode);
2158 if ($previousUserFlags != $userFlags)
2159 $updateTable[
"userflags"] = $userFlags;
2162 if (count($updateTable) > 0)
2164 $updateTable[
"user_name"] = $username;
2165 $updateTable[
"cu"] = $cuCode;
2166 $updateTable[
"_action"] =
"update";
2168 if ($securityMode ==
"setup")
2170 $shortAction =
"USER_STP";
2171 $longAction =
"User Security Setup";
2173 else if ($securityMode ==
"combined")
2175 $shortAction =
"USER_SU";
2176 $longAction =
"Security Update";
2178 else if (trim($parameters[
"isAdd"]) ==
"Y")
2180 $updateTable[
"_action"] =
"create";
2181 $shortAction =
"USER_A";
2182 $longAction =
"User Added";
2184 $sql =
"select 'FOUND' from cuadminusers where cu = '$cuCode' and lower(user_name) = '" . prep_save($username) .
"'";
2186 $sth = db_query($sql, $dbh);
2188 throw new exception(
"Found query failed.", 25);
2189 if (db_num_rows($sth) > 0)
2190 throw new exception(
"Username is duplicated.", 26);
2194 $updateTable[
"_action"] =
"update";
2195 $shortAction =
"USER_U";
2196 $longAction =
"User Updated";
2199 $updateTable= array(
"cuadminusers" => array($updateTable));
2201 if (DataAdminTableUpdate($dbh, $envVars, $updateTable, $username, $shortAction,
"AdmUsrMaint.prg",
"A", $longAction, $loggedInUser, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
2202 throw new exception(
"User update failed.", 12);
2205 if (isset($ipUpdate)
2206 && DataAdminTableUpdate($dbh, $envVars, $ipUpdate, $username,
"RIP_U",
"AdmUsrMaint.prg",
"A",
"Remote IP Update", $loggedInUser, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
2207 throw new exception(
"IP update failed.", 20);
2208 if (isset($permUpdate1)
2209 && DataAdminTableUpdate($dbh, $envVars, $permUpdate1, $username,
"PROGS_A",
"AdmUsrMaint.prg",
"A",
"Add Programs", $loggedInUser, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
2210 throw new exception(
"Add programs update failed.", 13);
2211 if (isset($permUpdate2)
2212 && DataAdminTableUpdate($dbh, $envVars, $permUpdate2, $username,
"PROGS_D",
"AdmUsrMaint.prg",
"A",
"Delete Programs", $loggedInUser, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
2213 throw new exception(
"Remove programs update failed.", 14);
2215 $cookieExists = HCU_array_key_exists(
"aTicket", $_COOKIE) && trim($_COOKIE[
"aTicket"]) !=
"";
2216 if ($createCookieIfNotExists || $cookieExists) {
2217 $theseResults = checkPass($pSysEnv, $dbh, $loggedInUser, $password, $cuCode, $chkSecure,
null,
null,
false, $emailAddress,
false, $isSkip, $createCookieIfNotExists);
2218 $cookie= $theseResults[
"cookie"];
2219 if ($theseResults[
"code"] != 0)
2220 throw new exception(
"Check password failed.", 44);
2226 return array(
"code" => $e->getCode(),
"error" => array($e->getMessage()),
"sql" => $sqls,
"serverIPFound" => $serverIPFound,
"serverIPFoundRelevant" => $serverIPFoundRelevant);
2229 return array(
"code" => 0,
"error" => array(),
"sql" => $sqls,
"serverIPFound" => $serverIPFound,
"serverIPFoundRelevant" => $serverIPFoundRelevant);
2232 function getUsePhonesInsteadOfMFA($dbh, $Cu)
2234 global $CU3_MFA_AUTHCODE;
2237 $sql=
"select flagset3 & $CU3_MFA_AUTHCODE from cuadmin where cu = '$Cu'";
2238 $sth= db_query($sql, $dbh);
2240 throw new exception(
"Query failed.");
2241 $value= db_fetch_row($sth, 0)[0];
2242 return isset($value) ? $value != 0 :
false;
2259 function ParseAuditRow($row, $Cu, $dbh) {
2261 $before = HCU_JsonDecode($row[
"before"]);
2262 if (!isset($before) || !is_array($before)) {
2263 throw new exception(
"Before JSON is not valid.", 13);
2265 $after = HCU_JsonDecode($row[
"after"]);
2266 if (!isset($before) || !is_array($after)) {
2267 throw new exception(
"After JSON is not valid.", 14);
2271 foreach($before as $table => $changedRows) {
2272 $afterTable = HCU_array_key_value($table, $after) ? $after[$table] :
null;
2274 if (!isset($afterTable)) {
2275 throw new exception(
"Table mismatch.", 15);
2277 $tableDefinition = GetTableDefinition (array(
"cu" => $Cu), $table)[$table];
2279 $label = isset($tableDefinition[
"_label"]) ? $tableDefinition[
"_label"] : $table;
2280 $newTableRow = array(
"table" => $table,
"label" => $label,
"rows" => array());
2281 $tableTypeMap = array();
2282 $passwordMask =
"********";
2284 if (!isset($changedRows) || !is_array($changedRows)) {
2285 throw new exception (
"Changed rows is not valid.", 1);
2287 foreach($changedRows as $j => $beforeRow) {
2288 $afterRow = $afterTable[$j];
2290 if (!isset($afterRow)) {
2291 throw new exception(
"Table mismatch.", 16);
2293 $beforeEmpty = count($beforeRow) == 0;
2294 $afterEmpty = count($afterRow) == 0;
2295 $combinedRow = array();
2300 if (!isset($afterRow) || !is_array($afterRow)) {
2301 throw new exception (
"After row is not an array.", 21);
2303 foreach($afterRow as $colName => $colValue) {
2304 $colDef = $tableDefinition[
"_cols"][$colName];
2305 if (!isset($colDef)) {
2306 throw new exception(
"Table mismatch.", 17);
2308 $label = isset($colDef[
"label"]) ? $colDef[
"label"] : $colName;
2310 $afterValue = !isset($colValue) || trim($colValue) ==
"" ? true : $colValue;
2314 $beforeValue =
"--";
2315 $afterValue = $afterValue ===
true ?
"--" : (trim($colName) ==
"passwd" && $afterValue !=
"" ? $passwordMask : trim($afterValue));
2319 switch($colDef[
"type"]) {
2321 $beforeValue = GetAuditTime($dbh, $beforeValue, $Cu,
false, $tz);
2322 $afterValue = GetAuditTime($dbh, $afterValue, $Cu,
false, $tz);
2324 case DBTYPE_TIMESTAMPTZ:
2325 case DBTYPE_TIMESTAMP:
2326 case DBTIMESTAMP_USENOW:
2327 $beforeValue = GetAuditTime($dbh, $beforeValue, $Cu,
true, $tz);
2328 $afterValue = GetAuditTime($dbh, $afterValue, $Cu,
true, $tz);
2332 $combinedRow[] = array(
"col" => trim($colName),
"before" => $beforeValue,
"after" => $afterValue,
"label" => trim($label),
"same" =>
false);
2334 $combinedRow = array(
"type" =>
"add",
"values" => $combinedRow);
2335 $tableTypeMap[
"add"] =
"add";
2338 if (!isset($beforeRow) || !is_array($beforeRow)) {
2339 throw new exception (
"before row is invalid.", 2);
2341 foreach($beforeRow as $colName => $colValue) {
2342 $colDef = $tableDefinition[
"_cols"][$colName];
2343 if (!isset($colDef)) {
2344 throw new exception(
"Table mismatch.", 18);
2347 $label = isset($colDef[
"label"]) ? $colDef[
"label"] : $colName;
2348 $afterValue = $afterEmpty || !HCU_array_key_exists($colName, $afterRow) ? false :
2349 (!isset($afterRow[$colName]) || trim($afterRow[$colName]) ==
"" ? true : $afterRow[$colName]);
2350 $beforeValue = !isset($colValue) || trim($colValue) ==
"" ? true : $colValue;
2352 if (!$afterEmpty && ($afterValue ===
false || $beforeValue === $afterValue)) {
2359 $beforeValue = $beforeValue ===
true ?
"--" : (trim($colName) ==
"passwd" ? $passwordMask : trim($beforeValue));
2360 $afterValue = $afterValue ===
true ?
"--" : (trim($colName) ==
"passwd" && $afterValue !=
"" ? $passwordMask : trim($afterValue));
2365 switch($colDef[
"type"]) {
2367 $beforeValue = GetAuditTime($dbh, $beforeValue, $Cu,
false, $tz);
2368 $afterValue = GetAuditTime($dbh, $afterValue, $Cu,
false, $tz);
2370 case DBTYPE_TIMESTAMPTZ:
2371 case DBTYPE_TIMESTAMP:
2372 case DBTIMESTAMP_USENOW:
2373 $beforeValue = GetAuditTime($dbh, $beforeValue, $Cu,
true, $tz);
2374 $afterValue = GetAuditTime($dbh, $afterValue, $Cu,
true, $tz);
2378 $combinedRow[] = array(
"col" => trim($colName),
"before" => $beforeValue,
"after" => $afterValue,
"label" => trim($label),
"same" => $same);
2381 if (!isset($afterRow) || !is_array($afterRow)) {
2382 throw new exception (
"After row is not an array.", 20);
2384 foreach($afterRow as $colName => $colValue) {
2385 $colDef = $tableDefinition[
"_cols"][$colName];
2386 if (isset($beforeRow[$colName])) {
2389 if (!isset($colDef)) {
2390 throw new exception(
"Table mismatch.", 19);
2393 $label = isset($colDef[
"label"]) ? $colDef[
"label"] : $colName;
2394 $afterValue = !isset($colValue) || trim($colValue) ==
"" ? true : $colValue;
2395 $beforeValue = !HCU_array_key_exists($colName, $beforeRow) ? false :
2396 (!isset($beforeRow[$colName]) || trim($beforeRow[$colName]) ==
"" ? true : $beforeRow[$colName]);
2400 $beforeValue = $beforeValue ===
true ?
"--" : (trim($colName) ==
"passwd" ? $passwordMask : trim($beforeValue));
2401 $afterValue = $afterValue ===
true ?
"--" : (trim($colName) ==
"passwd" && $afterValue !=
"" ? $passwordMask : trim($afterValue));
2405 switch($colDef[
"type"]) {
2407 $beforeValue = GetAuditTime($dbh, $beforeValue, $Cu,
false, $tz);
2408 $afterValue = GetAuditTime($dbh, $afterValue, $Cu,
false, $tz);
2410 case DBTYPE_TIMESTAMPTZ:
2411 case DBTYPE_TIMESTAMP:
2412 case DBTIMESTAMP_USENOW:
2413 $beforeValue = GetAuditTime($dbh, $beforeValue, $Cu,
true, $tz);
2414 $afterValue = GetAuditTime($dbh, $afterValue, $Cu,
true, $tz);
2418 $combinedRow[] = array(
"col" => trim($colName),
"before" => $beforeValue,
"after" => $afterValue,
"label" => trim($label),
"same" => $same);
2421 $type = $afterEmpty ?
"remove" :
"update";
2422 $combinedRow = array(
"type" => $type,
"values" => $combinedRow);
2423 $tableTypeMap[$type] = $type;
2426 $newTableRow[
"rows"][] = $combinedRow;
2427 $newTableRow[
"type"] = count($tableTypeMap) > 1 ?
"mixed" : current($tableTypeMap);
2430 $details[] = $newTableRow;
2433 unset($row[
"before"]);
2434 unset($row[
"after"]);
2435 $row[
"details"] = $details;
2437 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"row" => $row);
2438 }
catch (exception $e) {
2440 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
2443 return $returnArray;
2453 function FindHeaderSent($header) {
2454 $headers = headers_list();
2455 $header = trim($header,
': ');
2458 if (count($headers) > 0) {
2459 foreach ($headers as $hdr) {
2460 if (stripos($hdr, $header) !==
false) {
2480 function AdminHasMasterAccess($pAdmEnv) {
2482 SELECT userflags FROM cuadminusers 2483 WHERE user_name = '{$pAdmEnv['Cn']}' 2484 AND cu = '{$pAdmEnv['Cu']}' ";
2485 $sqlRs = db_query($sql, $pAdmEnv[
'dbh']);
2487 throw new Exception(
"Failed to read user access", 20);
2490 $userFlagsAry = db_fetch_array($sqlRs, 0);
2491 $userFlags = $userFlagsAry[
'userflags'];
2493 $hasMasterFlag = ($userFlags & GetAdminUserFlagsValue(
"ADM_MASTER_PRIV")) == GetAdminUserFlagsValue(
"ADM_MASTER_PRIV");
2494 $hasSuperPrivillages = (strtolower($pAdmEnv[
'Cu']) == strtolower($pAdmEnv[
'Cn']));
2496 return ($hasSuperPrivillages || $hasMasterFlag);