2 require_once(
"$admLibrary/ck_aticket.i");
5 $HCUSMSFROM =
"noreply@homecu.net";
8 $dms_ok=array(
'action'=> array(
"filter" => FILTER_SANITIZE_STRING),
'use_to_send'=> array(
"filter" => FILTER_SANITIZE_STRING),
"code" => array(
"filter" => FILTER_SANITIZE_STRING));
10 HCU_ImportVars($SYSENV,
"LOGOUT", $dms_ok);
11 extract($SYSENV[
"LOGOUT"]);
14 $main_url = $menu_link;
15 $self=
"$menu_link?ft=$ft";
19 if ( isset($action) ) {
20 if ( $action ==
"send_out_of_band") {
22 require_once(dirname(__FILE__) .
'/../../shared/library/cu_sms.i');
23 require_once(dirname(__FILE__) .
'/../../banking/library/cu_credentials.i');
24 if ( $use_to_send ==
"sms" ) {
25 $sql =
"SELECT usersms FROM cuadminusers WHERE cu = '$Cu' AND user_name = '$Cn'";
27 }
else if ( $use_to_send ==
"email" ) {
28 $sql =
"SELECT email FROM cuadminusers WHERE cu = '$Cu' AND user_name = '$Cn'";
29 }
else if ( $use_to_send ==
"have_code" ) {
30 $action =
"wait_for_code";
32 $msg .=
"Invalid selection of how to send the access code.";
35 if ( empty( $msg ) && $action !=
"wait_for_code") {
36 $sth = db_query($sql,$dbh);
38 if ( list($sendTo) = db_fetch_array($sth,0) ) {
42 $msg .=
"Unable to read user record";
50 $authResp = generateAuthcode();
51 if (!$authResp[
'authcode'] || !$authResp[
'authexpires']) {
52 throw new Exception(
'Generate Access Code Failed');
55 if (!setAdminAuthcode($dbh, $Cu, $Cn, $authResp[
'authcode'])) {
56 throw new Exception(
'Save Access Code Failed');
59 if (!sendAdminAuthcode($dbh, $Cu, $authResp, $sendTo, $use_to_send)) {
60 throw new Exception(
'Send Access Code Failed');
63 $action =
"wait_for_code";
65 }
else if ( $action ==
"confirm_remote" ) {
68 $sql =
"SELECT cau.userconfirm, ca.retrylimit 70 INNER JOIN cuadmin ca ON ca.cu = cau.cu 72 AND cau.user_name = '$Cn'";
73 $sth = db_query( $sql, $dbh );
75 if ( list($savedConfirm, $retryLimit) = db_fetch_array($sth,0) ) {
77 $confirmParts = explode(
"|", $savedConfirm );
81 if ( ($now - $confirmParts[2]) > 60 * $HCUSTALETIME ) {
82 $msg .=
"Too much time has passed. Code expired.";
83 }
else if ( $_SERVER[
"REMOTE_ADDR"] != $confirmParts[1] ) {
84 $msg .=
"Access is from a different location. Please try again.";
85 }
else if ( $confirmParts[3] >= $retryLimit ) {
86 $msg .=
"Retry limit exceeded. Please start over.";
89 $contents.=
"<div class='row'>Retry limit exceeded. Please start over.</div>";
90 $contents.=
"<div class='hcu-edit-buttons k-state-default row'><a id='logoutBtn' class='k-button k-primary' href='\\\\#'>Logout</a></div>";
92 printKendoWindow($menu_link, $contents);
95 }
else if ( trim( $code ) != $confirmParts[0] ) {
96 $msg .=
"Invalid access code. Please retry.";
100 $confirmToUpdate = implode(
"|", $confirmParts );
102 $sql =
"UPDATE cuadminusers 103 SET userconfirm = '$confirmToUpdate' 104 WHERE user_name = '$Cn' AND 107 $save_rs = db_query( $sql, $dbh );
109 $action =
"wait_for_code";
112 $sql =
"UPDATE cuadminusers 113 SET userconfirm = '', 114 remoteip = '" . prep_save($confirmParts[1]) .
"' 115 WHERE user_name = '$Cn' AND 118 $save_rs = db_query( $sql, $dbh );
121 $sql =
"SELECT cau.email, ca.orgname FROM cuadminusers cau INNER JOIN cuadmin ca ON ca.cu = cau.cu WHERE cau.cu = '$Cu' AND cau.user_name = '$Cn'";
122 $sth = db_query($sql,$dbh);
124 if ( list($sendTo, $orgName) = db_fetch_array($sth,0) ) {
125 db_free_result($sth);
129 $notify->mailto=
"$sendTo";
130 $notify->mailfromname=
"$orgName";
131 $notify->subject=
'Updated remote access';
132 $notify->msgbody =
"The remote access for your HomeCU Admin account was changed. If you did not make this change please let your system administrator know immediately.\n";
133 $notify->callingfunction = __FUNCTION__;
134 $notify->file = __FILE__;
139 $returnAddress = urldecode($_COOKIE[
'Tx_aURI']);
140 if ( !strlen( trim( $returnAddress ) ) ) {
141 $returnAddress =
"/admbin/main.prg?ft=";
145 header(
"Location: " . $returnAddress);
149 $msg .=
"Unable to read confirmation information.";
154 $isAllowedRemoteAccess =
false;
156 if (isset($Cn) && isset($Cu)) {
159 $sql =
"select email, userflags, usersms 161 where user_name = '$Cn' 163 $sth = db_query($sql,$dbh);
164 if ( list( $email, $userflags, $sms ) = db_fetch_array( $sth, 0 ) ) {
165 $isAllowedRemoteAccess = ($userflags & GetAdminUserFlagsValue(
"ADM_REMOTE_ACCESS_ALLOWED")) > 0;
170 if ( $isAllowedRemoteAccess ) {
171 if (isset($action) && $action ==
"wait_for_code" ) {
174 $contents.=
"<form action='$self' method='POST' name='continue'><input type='hidden' name='action' value='confirm_remote' />";
175 $contents.=
"<div class='row'><label class='col-xs-5'>Enter Code:</label><div class='col-xs-7'><input type='text' name='code' class='k-input k-textbox hcu-all-100'></div></div></form>";
176 $contents.=
"<div class='hcu-edit-buttons k-state-default row'><a id='logoutBtn' href='\\\\#'>Logout</a> ";
177 $contents.=
"<a id='submitBtn' class='k-button k-primary' href='\\\\#'><i class='fa fa-check'></i>Submit</a></div>";
180 $email = trim( $email );
184 $emailParts = explode(
"@", $email );
187 if ( strlen( $emailParts[0] ) > 3 ) {
188 $maskedEmail .= substr( $email, 0, 3 ) . str_repeat(
"x", strlen( $emailParts[0] ) - 3 );
190 $maskedEmail .= $emailParts[0];
195 if ( strlen( $emailParts[1] ) > 7 ) {
196 $maskedEmail .= str_repeat(
"x", strlen( $emailParts[1] ) - 7 ) . substr( $email, -7 );
198 $maskedEmail .= $emailParts[1];
203 if ( strlen( $sms ) > 0 ) {
204 if ( strpos( $sms,
"@" ) > 0 ) {
205 $smsParts = explode(
"@", $sms );
206 $smsNumber = $smsParts[0];
210 $maskedSMS = substr( $smsNumber, 0, 4 ) .
"xxxx" . substr( $smsNumber, -2 );
213 $thisChecked = strlen( $maskedSMS ) == 0 ?
"checked" :
"";
216 $contents.=
"<form action='$self' method='POST' name='continue'><input type='hidden' name='action' value='send_out_of_band' />";
217 $contents.=
"<div class='row'>You are attempting to access this system from an unknown location. <br>";
218 $contents.=
"In order to obtain an access code, please select how you would like the access code to be sent. <br>";
219 $contents.=
"The access code will expire after 15 minutes.</div>";
220 $contents.= strlen($maskedSMS) > 0 ?
"<div class='radio'><input type='radio' name='use_to_send' value='sms' checked />Text to $maskedSMS</div>" :
"";
221 $contents.=
"<div class='radio'><input type='radio' name='use_to_send' value='email' $thisChecked />Email to $maskedEmail</div>";
222 $contents.=
"<div class='radio'><input type='radio' name='use_to_send' value='have_code' />Already have access code</div></form>";
223 $contents.=
"<div class='hcu-edit-buttons k-state-default row'><a id='logoutBtn' href='\\\\#'>Logout</a> ";
224 $contents.=
"<a id='submitBtn' class='k-button k-primary' href='\\\\#'><i class='fa fa-check'></i>Submit</a></div>";
234 $contents.=
"You do not have permissions for remote access.";
235 $contents.=
"<div class='hcu-edit-buttons k-state-default row'><a id='logoutBtn' class='k-button k-primary' href='\\\\#'>Logout</a></div>";
238 if (strlen($contents) > 0)
239 printKendoWindow($menu_link, $contents, $msg);
241 function printKendoWindow($menu_link, $contents, $msg=
"") {
242 $logoutForm=
"<form name='logout' action='$menu_link?ft=70' method='post'>";
244 $fullContents=
"<div id='permissionFormStatusField'></div><div class='container-fluid hcu-template'>";
245 $fullContents.= strlen($msg) > 0 ?
"<div class='row k-block k-error-colored hcuSpacer'>$msg</div>" :
"";
246 $fullContents.= $contents;
247 $fullContents.=
"</div>";
249 <script type=
"text/javascript">
251 $(document).ready(
function() {
252 var permissionsDialog= $(
"<div id='permissionsDialog'></div>").appendTo(
"body").kendoWindow({
257 title:
"HomeCU Remote Admin Permissions",
260 template:
"<?php echo $fullContents; ?>" 262 }).data(
"kendoWindow");
264 permissionsDialog.open().center();
266 $(
"#logoutBtn").click(
function() {
267 $(
"[name='logout']").submit();
269 $(
"#submitBtn").click(
function() {
270 $(
"[name='continue']").submit();