11 $menu_link =
"https://www.homecu.net/hcuadm";
13 $monLibrary= dirname(__FILE__) .
"/../library";
14 require_once(
"$monLibrary/cu_top.i");
17 $dms_ok=array(
'username'=>
'string',
'user_password'=>
'string',
18 'btnLogin'=>
'string');
27 $return_address = urldecode($_COOKIE[
'Tx_hURI']);
29 $ip_address = $_SERVER[
'REMOTE_ADDR'];
35 if(isset($btnLogin)) {
45 if ($mode ==
"VALIDATE") {
49 $sql=
"SELECT user_name, passwd, ip_range, allowed_scripts, forcechange, failedremain, forceremain 51 WHERE user_name = '" . prep_save($username, 12) .
"' ";
55 $user_rs = db_query( $sql, $link);
61 $err_string =
"Invalid Username or Password";
66 if (!list($db_username, $saved_passwd, $db_ip_range,
67 $db_allowed_scripts, $db_forcechg, $db_failr, $db_forcer) =
68 db_fetch_array($user_rs)) {
72 $err_string =
"Invalid Username or Password";
75 $saved_passwd = preg_replace(
"/ +$/",
"", $saved_passwd);
79 if (!password_verify($user_password, $saved_passwd)) {
80 $err_string =
"Invalid Username or Password";
83 $sql =
"UPDATE dmsmonitorusers 85 CASE WHEN failedremain > 0 THEN failedremain - 1 86 WHEN failedremain is null THEN ({$default_retries} -1) 89 failedlogin = to_char(now(),'YYYY/MM/DD HH24:MI:SS') 90 WHERE user_name = '" . prep_save($username, 12) .
"' ";
91 $update_rs = db_query( $sql, $link);
93 if ($db_failr <= 1 || ($db_forcechg ==
'Y' && $db_forcer <= 0)) {
94 $err_string =
"Account is Locked";
100 $sql =
"UPDATE dmsmonitorusers 102 failedremain = '{$default_retries}', 103 priorlogin = lastlogin, 104 lastlogin = to_char(now(),'YYYY/MM/DD HH24:MI:SS') 105 WHERE user_name = '" . prep_save($username, 12) .
"' ";
107 $update_rs = db_query( $sql, $link);
110 db_free_result($user_rs);
112 if ($err_string ==
"") {
116 DMSBakeCookie($username, $db_forcechg,
'');
117 header(
"Location: " . $GLOBALS[
'return_address']);
128 if ($mode ==
"LOGIN") {
129 cu_header(
"HomeCU Monitor Login");
130 print
"<LINK REL=stylesheet HREF=\"/monitor/css/monitor.css\" TYPE=\"text/css\">";
138 <FONT SIZE=+1 COLOR=
"#FF0000">$err_string</FONT>
139 <FORM NAME=
"login" ACTION=
"hcu_login.prg" METHOD=
"post">
141 <table cellpadding=
"3" cellspacing=
"0" border=
"0" width=
"300" class=
'dmsbg'><tr><td>
142 <table cellpadding=
"1" cellspacing=
"0" border=
"0" width=
"100%" bgcolor=
"white">
144 <td colspan=
"2" class=
"bar" align=
"center">
149 <td nowrap align=
"right" class=
"hdr">
152 <td nowrap
class=
'dtl'>
153 <input type=
"text" name=
"username" size=
"15" maxlength=
"12" value=
"">
157 <td nowrap align=
"right" class=
"hdr">
160 <td nowrap
class=
'dtl'>
161 <input type=
"password" name=
"user_password" size=
"10" maxlength=
"12">
165 <td
class=
'dtl'> </td>
166 <td nowrap
class=
'dtl'>
167 <input type=
"submit" name=
"btnLogin" Value=
"Login">
173 <script language=
"javascript">
175 function field_focus() {
177 document.login.username.focus();
179 window.onload = field_focus;
188 function DMSBakeCookie ($username, $fchange, $lastupdate) {
200 $secret =
'xoiilh6RFoogeMb4';
205 $expires = $now + (86400 * 30);
206 $hash = MD5( $secret .
207 MD5(join (
':', array($secret, $now,
208 $expires, $username, $lastupdate)))
214 apache_note(
"user_name",
"M:${username}");
215 $mycookie=
"Ctime=$now&Hu=$username&Ch=$hash&Ce=$expires&Clu=$lastupdate";
219 HCU_setcookie_env($SYSENV,
"HCUTicket",
"$mycookie",0);
223 if ($fchange ==
"Y") {
226 header($menu_link .
"hcuusers.prg?act=1&un=" . urlencode($username));
228 echo
"Location: " . $GLOBALS[
'return_address'];
229 header(
"Location: " . $GLOBALS[
'return_address']);