88 if (!isset(
$db)){
$db = new \YAWK\db(); }
89 if (isset($_SESSION[
'username']))
91 $this->loadProperties(
$db, $_SESSION[
'username']);
104 $code =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
105 $code.=
"abcdefghijklmnopqrstuvwxyz";
106 $code.=
"0123456789";
107 $max = strlen($code);
109 for (
$i=0;
$i < $length;
$i++)
111 $token .= $code[random_int(0, $max-1)];
114 if (is_string($token))
134 if (isset($token) && (is_string($token)))
137 $token = strip_tags($token);
140 if (
$res =
$db->query(
"SELECT id FROM {users} WHERE hashValue = '".$token.
"'"))
143 if ($row = mysqli_fetch_row(
$res))
173 echo
"<form action=\"index.php?setNewPassword=true\" method=\"POST\" role=\"form\">";
174 echo
"<label for=\"newPassword1\">$lang[PASSWORD]</label>";
175 echo
"<input type=\"password\" class=\"form-control\" name=\"newPassword1\" id=\"newPassword1\">";
176 echo
"<label for=\"newPassword2\">$lang[PASSWORD_REPEAT]</label>";
177 echo
"<input type=\"password\" class=\"form-control\" name=\"newPassword2\" id=\"newPassword2\">";
178 echo
"<input type=\"hidden\" value=\"$uid\" class=\"form-control\" name=\"uid\" id=\"uid\">";
179 echo
"<button type=\"submit\" style=\"margin-top:5px;\" class=\"btn btn-success\">$lang[PASSWORD_SET_NEW]</button>";
192 if (isset($newPassword) && (!empty($newPassword)) && (is_string($newPassword)))
194 if (isset(
$uid) && (!empty(
$uid)) && (is_numeric(
$uid)))
197 $newPassword = md5($newPassword);
200 if (
$res =
$db->query(
"UPDATE {users} SET password = '".$newPassword.
"' WHERE id = '".
$uid.
"'"))
202 \YAWK\sys::setSyslog(
$db, 9, 0,
"user $uid changed his password",
$uid, 0, 0, 0);
207 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to update password of user $uid ",
$uid, 0, 0, 0);
213 \YAWK\sys::setSyslog(
$db, 11, 1,
"uid not set, empty or wrong datatype",
$uid, 0, 0, 0);
219 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to update user password: new password not set, empty or not valid",
$uid, 0, 0, 0);
264 if (empty(
$uid) || (!is_numeric(
$uid)))
274 if (
$res =
$db->query(
"UPDATE {users} SET hashValue = '".$token.
"' WHERE id = '".
$uid.
"'"))
293 if (filter_var($to, FILTER_VALIDATE_EMAIL))
299 $firstCharOfUrl = mb_substr(
$url, 0,-1);
300 if ($firstCharOfUrl ===
"/")
302 $tokenLink =
$url.
"/index.php?resetPassword=true&token=$token";
306 $tokenLink =
$url.
"index.php?resetPassword=true&token=$token";
309 $mailBody =
"$lang[HELLO] $username!\n\r$lang[PASSWORD_RESET_REQUESTED]\n\r$lang[PASSWORD_RESET_MAILBODY]\n\r".$tokenLink.
"\n\r$lang[PASSWORD_RESET_REQUEST_WARNING].";
312 \YAWK\sys::setSyslog(
$db, 9, 0,
"reset password email requested from $username ($to)",
$uid, 0, 0, 0);
313 $_SESSION[
'passwordFail'] = 0;
318 \YAWK\alert::draw(
"warning",
$lang[
'ERROR'],
"$lang[EMAIL_NOT_SENT] <br>(from: $from)<br>(to: $to)",
"", 3800);
319 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to send reset password email to $username ($to)",
$uid, 0, 0, 0);
326 \YAWK\sys::setSyslog(
$db, 11, 1,
"invalid email address $to",
$uid, 0, 0, 0);
332 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to update hash value in database",
$uid, 0, 0, 0);
346 if (isset($_SESSION[
'username']))
348 return $_SESSION[
'username'];
352 return $lang[
'GUEST'];
364 if (isset($_SESSION))
367 if (isset($_SESSION[
'username']) && isset($_SESSION[
'uid']))
369 if ($_SESSION[
'logged_in'] ==
true)
371 if (!empty($_SESSION[
'username']) && (is_string($_SESSION[
'username'])))
373 return $_SESSION[
'username'];
391 else if (isset(
$_GET))
393 if (isset(
$_GET[
'user']) && (!empty(
$_GET[
'user']) && (is_string(
$_GET[
'user']))))
395 if (self::isLoggedIn(
$db,
$_GET[
'user']))
397 return $_GET[
'user'];
427 if (
$res =
$db->query(
"SELECT templateID FROM {users} WHERE id = $uid"))
429 if ($row = mysqli_fetch_row(
$res))
435 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to get templateID from user db ",
$uid, 0, 0, 0);
441 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to query templateID from user db ",
$uid, 0, 0, 0);
454 if (
$res =
$db->query(
"SELECT overrideTemplate FROM {users} WHERE id = $uid"))
456 if ($row = mysqli_fetch_row(
$res))
469 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to get overrideTemplate status from user db ", 0, 0, 0, 0);
497 if (!isset(
$uid) && (!is_numeric(
$uid)))
502 if (
$res =
$db->query(
"UPDATE {users} SET overrideTemplate = $overrideTemplate, templateID = $userTemplateID WHERE id = $uid"))
508 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to update user template override - template ID: $userTemplateID",
$uid, 0, 0, 0);
542 if (isset($user) && (!empty($user)))
544 if (self::hasLoggedIn(
$db, $user))
546 $sqlStr =
"WHERE username='$user'";
547 \YAWK\alert::draw(
"success",
"showing login data for user: $user",
" ",
"",2400);
552 \YAWK\alert::draw(
"warning",
"Error!",
"<h4>No login data available.</h4> Could not get data for user <b>$user</b>. Displaying all data instead.",
"",5000);
559 if (
$res =
$db->query(
"SELECT * FROM {logins} $sqlStr"))
561 while ($row =
$res->fetch_assoc())
563 $loginsArray[] = $row;
565 if (isset($loginsArray) && (!empty($loginsArray)))
576 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to query login data of $user ", 0, 0, 0, 0);
587 static function isRegistered(
$db, $user)
589 if (
$res =
$db->query(
"SELECT username FROM {users} WHERE username='$user'"))
591 if ($row =
$res->fetch_assoc())
612 static function hasLoggedIn(
$db, $user)
614 if (
$res =
$db->query(
"SELECT username FROM {logins} WHERE username='$user'"))
616 if ($row =
$res->fetch_assoc())
637 static function isAdmin(
$db)
640 if (isset($_SESSION))
642 if (isset($_SESSION[
'gid']) && (!empty($_SESSION[
'gid'])))
644 if ($_SESSION[
'gid'] > 0)
646 if (
$res =
$db->query(
"SELECT backend_allowed FROM {user_groups} WHERE id ='".$_SESSION[
'gid'].
"'"))
648 if ($row =
$res->fetch_row())
693 if (
$result =
$db->query(
"SELECT cu.*, cg.value as gid FROM {users} as cu
694 JOIN {user_groups} as cg on cu.gid = cg.id ORDER BY id"))
696 $userDataArray = array();
698 while ($row =
$result->fetch_assoc())
700 $userDataArray[] = $row;
707 echo \YAWK\alert::draw(
"danger",
"Error",
"Sorry, database error: fetch getUserArray failed.",
"page=users",
"4800");
709 return $userDataArray;
729 if (
$result =
$db->query(
"SELECT cu.*, cg.value as gid FROM {users} as cu
730 JOIN {user_groups} as cg on cu.gid = cg.id ORDER BY id LIMIT $limit"))
732 $userDataArray = array();
734 while ($row =
$result->fetch_assoc())
736 $userDataArray[] = $row;
743 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to fetch user list", 0, 0, 0, 0);
744 echo \YAWK\alert::draw(
"danger",
"Error",
"Sorry, database error: fetch getLatestUsers failed.",
"page=users",
"4800");
746 return $userDataArray;
757 if (
$result =
$db->query(
"SELECT count(id) FROM {users}"))
764 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to count user db ", 0, 0, 0, 0);
778 if (
$res =
$db->query(
"SELECT * FROM {users}
781 if ($row =
$res->fetch_assoc())
783 $this->
id = $row[
'id'];
784 $this->blocked = $row[
'blocked'];
785 $this->privacy = $row[
'privacy'];
786 $this->online = $row[
'online'];
787 $this->
gid = $row[
'gid'];
788 $this->terms = $row[
'terms'];
789 $this->username = $row[
'username'];
790 $this->password = $row[
'password'];
791 $this->date_created = $row[
'date_created'];
792 $this->date_changed = $row[
'date_changed'];
793 $this->date_expired = $row[
'date_expired'];
794 $this->date_lastlogin = $row[
'date_lastlogin'];
795 $this->login_count = $row[
'login_count'];
796 $this->
email = $row[
'email'];
797 $this->url = $row[
'url'];
798 $this->twitter = $row[
'twitter'];
799 $this->facebook = $row[
'facebook'];
800 $this->firstname = $row[
'firstname'];
801 $this->lastname = $row[
'lastname'];
802 $this->street = $row[
'street'];
803 $this->zipcode = $row[
'zipcode'];
804 $this->city = $row[
'city'];
805 $this->country = $row[
'country'];
806 $this->logged_in = $row[
'logged_in'];
807 $this->public_email = $row[
'public_email'];
808 $this->job = $row[
'job'];
809 $this->likes = $row[
'likes'];
811 $this->templateID = $row[
'templateID'];
815 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to load settings of $username", $this->
id, 0, 0, 0);
822 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to query settings of $username", $this->
id, 0, 0, 0);
836 function getProperty(
$db, $property,
$uid)
838 if (
$res =
$db->query(
"SELECT $property FROM {users}
839 WHERE id = '" .
$uid .
"'"))
841 $row =
$res->fetch_row();
846 \YAWK\sys::setSyslog(
$db, 11, 1,
"Unable to get property <b>$property</b> of user ID <b>$uid</b> ", 0, 0, 0, 0);
860 static function setProperty(
$db,
$id, $property,
$value)
862 if (isset($property) && isset(
$value) && isset(
$id) && is_numeric(
$id))
864 $property =
$db->quote($property);
867 if (
$res =
$db->query(
"UPDATE {users}
868 SET $property = '".$value.
"'
869 WHERE id = '" .
$id .
"'"))
876 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to set value <b>$value</b> of property <b>$property</b>", 0, 0, 0, 0);
883 \YAWK\alert::draw(
"danger",
"Error!",
"Parameters failed or wrong type! You shall not manipulate vars, yoda said!",
"",
"4800");
894 static function getGroupNameFromID(
$db,
$gid)
897 if (
$res =
$db->query(
"SELECT value
901 $row =
$res->fetch_row();
914 static function getUserNameFromID(
$db,
$uid)
917 if (
$res =
$db->query(
"SELECT username
921 $row =
$res->fetch_row();
939 static function getUserIdFromName(
$db, $user)
942 if (
$res =
$db->query(
"SELECT id
944 WHERE username = '".$user.
"'"))
946 $row =
$res->fetch_row();
947 if (!empty($row[0])){
964 static function getUserIdFromEmail(
$db,
$email)
967 if (
$res =
$db->query(
"SELECT id
969 WHERE email = '".$email.
"'"))
971 $row =
$res->fetch_row();
983 static function getAllGroupIDs(
$db)
985 if (
$res =
$db->query(
"SELECT id, value FROM {user_groups}"))
987 while ($row = mysqli_fetch_row(
$res))
997 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to fetch id from user_groups db", 0, 0, 0, 0);
998 \YAWK\alert::draw(
"warning",
"Warning",
"Could not fetch id and/or value from user groups database.",
"",
"4800");
1004 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to query id from user_groups db", 0, 0, 0, 0);
1005 \YAWK\alert::draw(
"warning",
"Warning",
"Could not select id and/or value from user groups database.",
"",
"4800");
1018 if (
$res =
$db->query(
"SELECT id, logged_in FROM {users} WHERE username = '" .
$username .
"'"))
1020 $row = mysqli_fetch_row(
$res);
1022 if ($row[1] ===
'1') {
1024 if (isset($_SESSION[
'username']) ==
$username)
1026 if (isset($_SESSION[
'uid']) == $row[0] && $_SESSION[
'logged_in'] ==
true)
1056 static function getGroup(
$db)
1058 if (isset($_SESSION[
'gid']))
1060 $gid = $_SESSION[
'gid'];
1061 $sql =
$db->query(
"SELECT id,value,signup_allowed,backend_allowed FROM {user_groups} WHERE id = '".
$gid.
"'");
1062 $row = mysqli_fetch_array(
$sql);
1066 return "Group ID not set.";
1081 if (isset($w) && isset($h))
1089 $width =
"width=\"$w\" ";
1097 $height =
"height=\"$h\" ";
1105 if (isset($cssClass))
1107 $css =
"class=\"$cssClass\"";
1114 if (isset($location))
1116 if ($location ==
"frontend"){
1117 $imageJpg =
"media/images/users/".$user.
".jpg";
1118 $imagePng =
"media/images/users/".$user.
".png";
1119 $defaultPic =
"<img src=\"media/images/users/avatar.png\" $width $height $css>";
1126 $defaultPic =
"<img src=\"media/images/users/avatar.png\" $width $height $css>";
1128 if ($location ==
"backend"){
1129 $imageJpg =
"../media/images/users/".$user.
".jpg";
1130 $imagePng =
"../media/images/users/".$user.
".png";
1132 if ($cssClass ==
"img-circle")
1134 $defaultPic =
"<img src=\"../media/images/users/avatar.png\" $width $height $css>";
1136 elseif ($cssClass ==
"img-circle sidebar-toggle")
1138 $defaultPic =
"<img src=\"../media/images/users/avatar-light.png\" $width $height $css>";
1140 if ($cssClass ==
"user-image")
1142 $defaultPic =
"<img src=\"../media/images/users/avatar.png\" $width $height $css>";
1144 if ($cssClass ==
"profile-user-img img-responsive img-circle")
1146 $defaultPic =
"<img src=\"../media/images/users/avatar.png\" $width $height $css>";
1153 $defaultPic =
"<img src=\"media/images/users/avatar.png\" $width $height $css>";
1160 $defaultPic =
"<img src=\"media/images/users/avatar.png\" $width $height $css>";
1164 if (file_exists($imageJpg)){
1165 return "<img src=\"".$imageJpg.
"\" $width $height $css>";
1167 elseif (file_exists($imagePng)){
1168 return "<img src=\"".$imagePng.
"\" $width $height $css>";
1185 $this->username = mb_strtolower($this->username);
1187 if (
$res =
$db->query(
"UPDATE {users} SET
1188 blocked = '" . $this->blocked .
"',
1189 privacy = '" . $this->privacy .
"',
1191 username = '" . $this->username .
"',
1192 password = '" . $this->password .
"',
1193 email = '" . $this->email .
"',
1194 url = '" . $this->url .
"',
1195 twitter = '" . $this->twitter .
"',
1196 facebook = '" . $this->facebook .
"',
1197 firstname = '" . $this->firstname .
"',
1198 lastname = '" . $this->lastname .
"',
1199 street = '" . $this->street .
"',
1200 zipcode = '" . $this->zipcode .
"',
1201 city = '" . $this->city .
"',
1202 country = '" . $this->country .
"',
1203 job = '" . $this->job .
"',
1204 overrideTemplate = '" . $this->overrideTemplate .
"',
1205 templateID = '" . $this->templateID .
"',
1206 gid = '" . $this->gid .
"'
1207 WHERE id = '" . $this->id .
"'"))
1209 \YAWK\alert::draw(
"success",
"Success!",
"User $this->username updated.",
"",
"1200");
1214 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to update status of $this->username", 0, 0, 0, 0);
1215 \YAWK\alert::draw(
"warning",
"Error!",
"User status could not be saved, please try again.",
"",
"4800");
1232 }
else { $status =
"undefined - \$blocked not set"; }
1233 if (!
$res =
$db->query(
"UPDATE {users}
1235 WHERE id = '" .
$id .
"'"))
1238 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to toggle user ID <b>$id</b> to status <b>$status</b> ", 0, 0, 0, 0);
1243 \YAWK\sys::setSyslog(
$db, 9, 0,
"toggled user id <b>#$id</b> to status <b>$status</b> ", 0, 0, 0, 0);
1256 if (
$res =
$db->query(
"SELECT email
1258 WHERE username = '" . $user.
"'"))
1260 $row =
$res->fetch_row();
1265 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to get email address of <b>$user</b> ", 0, 0, 0, 0);
1292 static function create(
$db,
$username,
$password1,
$password2,
$email,
$url,
$twitter,
$facebook,
$firstname,
$lastname,
$street,
$zipcode,
$city,
$country,
$blocked,
$privacy,
$job,
$gid)
1296 if (
$res =
$db->query(
"SELECT MAX(id) FROM {users}"))
1298 $row = mysqli_fetch_row(
$res);
1312 \YAWK\sys::setSyslog(
$db, 11, 2,
"somebody tried to register as <b>$username</b>", 0, 0, 0, 0);
1325 if (
$res =
$db->query(
"SELECT username FROM {users} WHERE username='" .
$username .
"'"))
1327 $row = mysqli_fetch_row(
$res);
1328 if (is_array($row) && !is_null($row[0])) {
1330 \YAWK\alert::draw(
"warning",
"Warning!",
"Please choose another username!",
"",
"4800");
1346 if (isset($_POST[
'twitter']) && (!empty($_POST[
'twitter']))) {
$twitter = htmlentities($_POST[
'twitter']); }
1347 if (isset($_POST[
'facebook']) && (!empty($_POST[
'facebook']))) {
$facebook = htmlentities($_POST[
'facebook']); }
1348 if (isset($_POST[
'firstname']) && (!empty($_POST[
'firstname']))) {
$firstname = htmlentities($_POST[
'firstname']); }
1349 if (isset($_POST[
'lastname']) && (!empty($_POST[
'lastname']))) {
$lastname = htmlentities($_POST[
'lastname']); }
1350 if (isset($_POST[
'street']) && (!empty($_POST[
'street']))) {
$street = htmlentities($_POST[
'street']); }
1351 if (isset($_POST[
'zipcode']) && (!empty($_POST[
'zipcode']))) {
$zipcode = htmlentities($_POST[
'zipcode']); }
1352 if (isset($_POST[
'city']) && (!empty($_POST[
'city']))) {
$city = htmlentities($_POST[
'city']); }
1353 if (isset($_POST[
'country']) && (!empty($_POST[
'country']))) {
$country = htmlentities($_POST[
'country']); }
1354 if (isset($_POST[
'job']) && (!empty($_POST[
'job']))) {
$job = htmlentities($_POST[
'job']); }
1361 if (
$res =
$db->query(
"INSERT INTO {users}
1362 (id,username,password,date_created,email,url,twitter,facebook,firstname,lastname,street,zipcode,city,country,blocked,privacy,job,gid)
1363 VALUES('" .
$id .
"',
1393 \YAWK\alert::draw(
"warning",
"Warning!",
"Passwords do not match!",
"",
"4000");
1412 echo \YAWK\alert::draw(
"danger",
"Error!",
"Missing Data. Please fill out the complete form.",
"",4200);
1413 echo \YAWK\PLUGINS\SIGNUP\signup::signUp(
$db);
1414 echo
"</div></div><!-- <div style=\"background-image: url(media/images/bottom.png); height: 150px;\"></div> -->";
1419 if (
$res =
$db->query(
"SELECT MAX(id) FROM {users}"))
1421 $row = mysqli_fetch_row(
$res);
1425 $password1 = htmlentities($_POST[
'password1']);
1426 $password2 = htmlentities($_POST[
'password2']);
1435 if (
$res =
$db->query(
"SELECT username FROM {users} WHERE username='" .
$username .
"'"))
1437 $row = mysqli_fetch_row(
$res);
1440 \YAWK\alert::draw(
"danger",
"Error!",
"Please choose another user name!",
"",
"");
1441 echo \YAWK\PLUGINS\SIGNUP\signup::signUp(
$db);
1446 if (
$res =
$db->query(
"SELECT email FROM {users} WHERE email='" .
$email .
"'"))
1448 $row = mysqli_fetch_row(
$res);
1452 echo \YAWK\PLUGINS\SIGNUP\signup::signUp(
$db);
1458 \YAWK\alert::draw(
"danger",
"Error!",
"Hey c'mon... those kind of names are not allowed! Please choose another username!",
"",
"");
1459 echo \YAWK\PLUGINS\SIGNUP\signup::signUp(
$db);
1466 if (
$res =
$db->query(
"INSERT INTO {users} (id,username,password,date_created,email,blocked,privacy,gid)
1467 VALUES('" .
$id .
"',
1480 \YAWK\sys::setSyslog(
$db, 12, 2,
"failed to register user from frontend: signup of <b>$username</b> failed",
$id, 0, 0, 0);
1481 \YAWK\alert::draw(
"danger",
"Error!",
"Error registering username. Exit with empty result.",
"",
"");
1482 echo \YAWK\PLUGINS\SIGNUP\signup::signUp(
$db);
1488 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to signup user: <b>$username</b> - passwords mismatch", 0, 0, 0, 0);
1489 \YAWK\alert::draw(
"danger",
"Error!",
"Passwords mismatch! Please try again.",
"",
"");
1490 echo \YAWK\PLUGINS\SIGNUP\signup::signUp(
$db);
1493 echo \YAWK\alert::draw(
"danger",
"Error!",
"Something strange has happend. Code (000)",
"",
"");
1503 static function delete(
$db, $user)
1505 if (
$res =
$db->query(
"DELETE FROM {users} WHERE username = '" . $user .
"'"))
1511 \YAWK\sys::setSyslog(
$db, 11, 2,
"failed to delete <b>$user</b> ", 0, 0, 0, 0);
1530 $sql =
$db->query(
"SELECT blocked, terminatedByUser FROM {users} WHERE
1534 if(isset(
$res[
'blocked'])){
1535 if (
$res[
'blocked']===
'1')
1539 \YAWK\sys::setSyslog(
$db, 12, 2,
"<b>blocked user $username</b> tried to login",
$uid, 0, 0, 0);
1540 echo
"<div class=\"container bg-danger\"><br><h2>We're Sorry! <small>Your Account is blocked.</h2><b>If you think
1541 this is a mistake, contact the admin via email: </b>(<a class=\"text-danger\" href=\"mailto:$adminEmail\">$adminEmail</a>)
1542 <b>for further information.</b><br><small>You will be redirected to <a class=\"small\" href=\"$host\">$host</a> in 30 seconds.</small><br><br></div>";
1547 if(isset(
$res[
'terminatedByUser'])){
1548 if (
$res[
'terminatedByUser']===
'1'){
1550 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to login <b>$username</b> user has deleted his account before - it does not exist anymore",
$uid, 0, 0, 0);
1551 echo
"<div class=\"container bg-danger\"><br><h2>We're Sorry! <small>This account does not exist.</h2><b>If you think
1552 this is a mistake, contact the admin via email: </b>(<a class=\"text-danger\" href=\"mailto:$adminEmail\">$adminEmail</a>)
1553 <b>.</b><br><small>You will be redirected to <a class=\"small\" href=\"$host\">$host</a> in 30 seconds.</small><br><br></div>";
1564 \YAWK\sys::setSyslog(
$db, 11, 1,
"login failed due wrong credentials from <b>".
$username.
"</b>", 0, 0, 0, 0);
1580 function checkGroupId(
$db,
$gid)
1583 $sql =
$db->query(
"SELECT backend_allowed FROM {user_groups} WHERE id='".
$gid.
"'");
1585 if (
$res[0] ===
'1')
1591 \YAWK\sys::setSyslog(
$db, 11, 1,
"user group ID <b>$gid</b> is not allowed to login into backend", 0, 0, 0, 0);
1601 static function checkLogin(
$db)
1604 $user = new \YAWK\user(
$db);
1605 if(isset($_POST[
'user']) && isset($_POST[
'password'])) {
1606 if($user->login(
$db, $_POST[
'user'],$_POST[
'password']))
1608 $user->storeLogin(
$db, 0,
"backend", $_POST[
'user'], $_POST[
'password']);
1609 \YAWK\sys::setSyslog(
$db, 10, 0,
"backend login <b>$_POST[user]</b> successful", 0, 0, 0, 0);
1614 $user->storeLogin(
$db, 1,
"backend", $_POST[
'user'], $_POST[
'password']);
1615 \YAWK\sys::setSyslog(
$db, 12, 2,
"failed backend login <b>$_POST[user]</b> username or password wrong", 0, 0, 0, 0);
1622 \YAWK\sys::setSyslog(
$db, 11, 1,
"somebody $_POST[user] tried to login, but username or password was not set.", 0, 0, 0, 0);
1630 $userClass = new \YAWK\user(
$db);
1633 if (isset($user) && (!empty($user) && (is_string($user)
1637 if (self::isLoggedIn(
$db, $user) ===
false)
1642 $userClass->storeLogin(
$db, 0,
"frontend", $user,
$password);
1648 $userClass->storeLogin(
$db, 1,
"frontend", $user,
$password);
1693 $res =
$db->query(
"SELECT id, login_count, gid FROM {users} WHERE username='" .
$username .
"'");
1694 $row = mysqli_fetch_row(
$res);
1696 $_SESSION[
'uid'] = $row[0];
1698 $_SESSION[
'gid'] = $row[2];
1702 $date_now =
date(
"Y-m-d G:i:s");
1704 if (!
$res =
$db->query(
"UPDATE {users} SET
1705 date_lastlogin = '" . $date_now .
"',
1711 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to update login counter ($login_count) of <b>$username</b> .", $_SESSION[
'uid'], 0, 0, 0);
1717 @session_regenerate_id();
1721 $_SESSION[
'logged_in'] =
true;
1723 \YAWK\sys::setSyslog(
$db, 10, 0,
"login <b>$username</b> successful", $_SESSION[
'uid'], 0, 0, 0);
1731 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to login <b>$username</b>",
$uid, 0, 0, 0);
1819 $date_now =
date(
"Y-m-d G:i:s");
1826 if ($this->checkPassword(
$db, $this->username,
$password)) {
1828 $res =
$db->query(
"SELECT id, login_count, gid FROM {users} WHERE username='" .
$username .
"'");
1829 $row = mysqli_fetch_row(
$res);
1830 $_SESSION[
'uid'] = $row[0];
1831 $_SESSION[
'gid'] = $row[2];
1837 if ($this->checkGroupId(
$db, $_SESSION[
'gid'])) {
1838 if(!
$res =
$db->query(
"UPDATE {users} SET
1839 date_lastlogin = '" . $date_now .
"',
1843 WHERE username = '" . $this->username .
"'"))
1846 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to login <b>$username</b>",
$uid, 0, 0, 0);
1847 echo \YAWK\alert::draw(
"warning",
"Error!",
"Could not log user into database. Expect some errors.",
"",
"3800");
1851 @session_regenerate_id();
1852 $_SESSION[
'logged_in'] =
true;
1860 \YAWK\sys::setSyslog(
$db, 12, 2,
"failed to login <b>$username</b> user aint got sufficient rights to login. .",
$uid, 0, 0, 0);
1861 \YAWK\alert::draw(
"danger",
"Login failed!",
"You are not allowed to login here.",
"", 10000);
1866 if (!isset($_SESSION[
'failed']))
1868 $_SESSION[
'failed'] = 0;
1869 $_SESSION[
'failed']++;
1873 $_SESSION[
'failed']++;
1875 if ($_SESSION[
'failed'] >= $maxAttempts) {
1876 $_SESSION[
'lockout_until'] = time() + ($lockoutTime * 60);
1880 function disableButtons(delay)
1882 // Disable the buttons
1883 $('#loginButton').removeClass().addClass('btn btn-success disabled').attr('id', 'LOGIN_FORBIDDEN');
1884 $('#resetPasswordButton').removeClass().addClass('btn btn-danger disabled');
1886 // Enable the buttons after the specified delay
1887 setTimeout(function() {
1888 $('#LOGIN_FORBIDDEN').attr('id', 'loginButton').removeClass().addClass('btn btn-success');
1889 $('#resetPasswordButton').removeClass().addClass('btn btn-danger');
1892 // add document ready
1893 $(document).ready(function() {
1894 disableButtons(10000);
1898 $('div *').prop('disabled', true);
1900 var counter = setInterval(timer, 1000); // 1000 will run it every 1 second
1907 clearInterval(counter);
1908 //counter ended, do something here
1909 $('div *').prop('disabled', false);
1910 // $(timer).empty();
1911 // $(timer).append(\"a few\").fadeIn();
1914 //Do code for showing the number of seconds here
1915 // document.getElementById(\"timer\").innerHTML=count; // watch for spelling
1920 \YAWK\alert::draw(
"danger",
"Login failed!",
"Please check your login data and try to re-login in a few seconds!",
"",
"3500");
1925 if ($_SESSION[
'failed'] == 3){
1926 \YAWK\alert::draw(
"warning",
"ATTENTION!",
"This is the 3rd failed login tryout. - <b>The next failed login will be logged for security reasons!</b>",
"",
"6800");
1929 else if ($_SESSION[
'failed'] >= 5)
1931 $hostname = gethostname();
1932 \YAWK\sys::setSyslog(
$db, 11, 1,
"possible brute force attack: <b>$username</b> : $password",
$uid, 0, 0, 0);
1933 \YAWK\alert::draw(
"danger",
"DO NOT BRUTE FORCE HERE!",
"failed tryouts: $_SESSION[failed]</h3><br><b>You are not allowed to login here. You have been warned.<br>The Admin is informed. Remember: BruteForce Attacks are against the law. <i style=\"text-decoration: underline\"><br><br>All of your actions will be logged and prosecuted. - <b>The network operation centre was informed.</b></i></b><br><br>Date: $date_now<br>Your IP: $_SERVER[REMOTE_ADDR]<br>Browser: $_SERVER[HTTP_USER_AGENT]</b><br>",
"",
"0");
1936 $from =
"script@".$domain.
" ";
1937 $ip = $_SERVER[
'HTTP_USER_AGENT'];
1938 $userAgent = $_SERVER[
'HTTP_USER_AGENT'];
1939 $message =
"FAILED LOGIN ATTEMPT!\n\r
1941 Message : User tried a Backend Login more than 5 times!\n
1942 User : $this->username\n
1943 Password : $this->password\n
1945 UserAgent : $userAgent\n";
1956 \YAWK\alert::draw(
"danger",
"Login failed!",
"Please check your credentials!",
"", 6000);
1971 if (!isset($location)){
1976 $atm =
date(
"Y-m-d H:i:s");
1977 if (!isset($failed))
1981 if (!isset($state) || (empty($state)))
1985 $ip = $_SERVER[
'REMOTE_ADDR'];
1987 $res =
$db->query(
"INSERT INTO {logins}
1988 (datetime, location, failed, ip, useragent, username, password)
1990 if (
$res){
return true; }
1991 else {
return false; }
2004 <form name=\"login\" id=\"loginForm\" role=\"form\" method=\"POST\">
2005 <input type=\"text\" id=\"user\" name=\"user\" value=\"".$username.
"\" class=\"form-control animated fadeIn\" placeholder=\"Benutzername\">
2006 <input type=\"password\" id=\"password\" name=\"password\" value=\"".
$password.
"\" class=\"form-control animated fadeIn\" placeholder=\"Passwort\">
2007 <input type=\"hidden\" name=\"login\" value=\"login\">
2008 <input type=\"submit\" id=\"submitBtn\" value=\"Login\" style=\"margin-top:5px;\" name=\"Login\" class=\"btn btn-success animated fadeIn\">
2009 <div id=\"captchaNode\"></div>
2023 if (!isset($style) || (empty($style)))
2030 if ($style ==
"light")
2034 elseif ($style ==
"dark")
2036 $input_style =
"style=\"color: #ccc; border-color: #000; background-color: #444;\"";
2044 $html =
"<form name=\"login\" id=\"loginForm\" class=\"navbar-form navbar-right\" role=\"form\" action=\"welcome.html\" method=\"POST\">
2045 <div class=\"form-group\">
2046 <input type=\"text\" id=\"user\" name=\"user\" value=\"".$username.
"\" class=\"form-control\" $input_style placeholder=\"Benutzername\">
2047 <input type=\"password\" id=\"password\" name=\"password\" value=\"".
$password.
"\" class=\"form-control\" $input_style placeholder=\"Passwort\">
2048 <input type=\"hidden\" name=\"login\" value=\"login\">
2049 <input type=\"hidden\" name=\"LOCK\" value=\"1\">
2050 <input type=\"hidden\" name=\"include\" value=\"login\">
2051 <input type=\"submit\" value=\"Login\" name=\"Login\" class=\"btn btn-success\">
2062 public function logout(
$db)
2065 if (isset($_SESSION[
'username']))
2067 if (!
$res =
$db->query(
"UPDATE {users}
2069 WHERE username = '".$_SESSION[
'username'].
"'"))
2071 \YAWK\sys::setSyslog(
$db, 11, 1,
"failed to logout <b>$_SESSION[username]</b> .", 0, 0, 0, 0);
2072 \YAWK\alert::draw(
"danger",
"Error!",
"Could not logout ".$_SESSION[
'username'].
" Please try again!",
"",
"3800");
2074 $_SESSION[
'failed']=0;
2075 $_SESSION[
'logged_in']=0;
2081 $_SESSION[
'failed']=0;
2082 $_SESSION[
'logged_in']=0;
2084 \YAWK\sys::setSyslog(
$db, 9, 0,
"logout <b>".$_SESSION[
'username'].
"</b>", 0, 0, 0, 0);
2090 if (isset(
$_GET[
'user'])
2091 && (!empty(
$_GET[
'user'])
2092 && (is_string(
$_GET[
'user']))))
2095 if (!
$res =
$db->query(
"UPDATE {users}
2097 WHERE username = '".$_GET[
'username'].
"'"))
2099 \YAWK\sys::setSyslog(
$db, 11, 1,
"unable to logout <b>".
$_GET[
'username'].
"</b>", 0, 0, 0, 0);
2100 \YAWK\alert::draw(
"danger",
"Error!",
"Could not logout ".
$_GET[
'username'].
" Please try again!",
"",
"3800");
2102 $_SESSION[
'failed']=0;
2103 $_SESSION[
'logged_in']=0;
2109 $_SESSION[
'failed']=0;
2110 $_SESSION[
'logged_in']=0;
2112 \YAWK\sys::setSyslog(
$db, 9, 0,
"logout <b>".
$_GET[
'username'].
"</b>", 0, 0, 0, 0);
2117 $_SESSION[
'failed']=0;
2118 $_SESSION[
'logged_in']=0;
2134 $res =
$db->query(
"SELECT username, email, public_email, online FROM {users} WHERE privacy != 1");
2135 while ($row = mysqli_fetch_assoc(
$res)){
2139 if ($row[
'email'] && $row[
'public_email'] ===
'0'){
2144 if ($row[
'online'] ===
'0') {
2145 $color =
"text-danger";
2148 $color =
"text-success";
2150 echo
"<ul class=\"list-group\">
2151 <li class=\"list-group-item\"><span class=\"".$color.
"\"><strong>".
$username.
" <small>".
$email.
"</strong></small></span></li>
2166 if (
$sql =
$db->query(
"SELECT id FROM {follower} WHERE follower='$uid' AND hunted = '".$hunted.
"'"))
2168 if (mysqli_fetch_row(
$sql))
2179 \YAWK\sys::setSyslog(
$db, 19, 1,
"failed to get status from follower db",
$uid, 0, 0, 0);
2193 if (
$sql =
$db->query(
"SELECT id FROM {friends}
2194 WHERE confirmed='1' AND friendA='$uid' AND friendB = '".$hunted.
"'
2195 OR confirmed='1' AND friendA='$hunted' AND friendB = '$uid'"))
2197 if (mysqli_fetch_row(
$sql))
2208 \YAWK\sys::setSyslog(
$db, 19, 1,
"failed to query friendship status of user ID <b>$uid</b> .", 0, 0, 0, 0);
2222 if (
$sql =
$db->query(
"SELECT id, friendA, friendB, confirmed, aborted FROM {friends}
2223 WHERE confirmed='0' AND friendA='$uid' AND friendB = '".$hunted.
"'
2224 OR confirmed='0' AND friendA='$hunted' AND friendB = '$uid'"))
2227 while ($row = mysqli_fetch_assoc(
$sql))
2235 \YAWK\sys::setSyslog(
$db, 19, 1,
"failed to query friendship request status of uid <b>#$uid</b> .", 0, 0, 0, 0);
2245 static function countNotifications(
$db)
2247 if (
$sql =
$db->query(
"SELECT count(log_id) FROM {syslog}
2250 $row = mysqli_fetch_row(
$sql);
2255 \YAWK\sys::setSyslog(
$db, 3, 1,
"failed to count admin notifications", 0, 0, 0, 0);
2266 static function countMyNotifications(
$db,
$uid)
2268 if (
$sql =
$db->query(
"SELECT count(toUID) FROM {notifications}
2269 WHERE toUID = '".$uid.
"' AND seen = '0'"))
2271 $row = mysqli_fetch_row(
$sql);
2276 \YAWK\sys::setSyslog(
$db, 3, 1,
"failed to count personal notifications of UID <b>$uid</b> .", 0, 0, 0, 0);
2286 static function getAllNotifications(
$db)
2289 if (
$sql =
$db->query(
"SELECT * FROM {syslog} AS log
2290 LEFT JOIN {syslog_categories} AS category ON log.log_category=category.id
2291 LEFT JOIN {users} AS u ON log.fromUID=u.id
2292 WHERE log.seen = '0'
2294 ORDER BY log.log_date DESC"))
2296 $all_notifications = array();
2297 while ($row = mysqli_fetch_assoc(
$sql))
2299 $all_notifications[] = $row;
2301 return $all_notifications;
2305 \YAWK\sys::setSyslog(
$db, 3, 1,
"unable to get syslog entries", 0, 0, 0, 0);
2316 static function getMyNotifications(
$db,
$uid)
2318 if (
$sql =
$db->query(
"SELECT * FROM {notifications} AS log
2319 LEFT JOIN {syslog_categories} AS category ON log.log_category=category.id
2320 LEFT JOIN {notifications_msg} AS msg ON log.msg_id=msg.id
2321 LEFT JOIN {users} AS u ON log.fromUID=u.id
2322 WHERE log.toUID = '".$uid.
"'
2325 ORDER BY log.log_date DESC"))
2327 $my_notifications = array();
2328 while ($row = mysqli_fetch_assoc(
$sql))
2330 $my_notifications[] = $row;
2332 return $my_notifications;
2336 \YAWK\sys::setSyslog(
$db, 3, 1,
"failed to get notifications.",
$uid, 0, 0, 0);
2347 static function countMyFollowers(
$db,
$uid)
2349 if (
$sql =
$db->query(
"SELECT count(id) FROM {follower} WHERE hunted = '".$uid.
"'"))
2351 $row = mysqli_fetch_row(
$sql);
2356 \YAWK\sys::setSyslog(
$db, 19,1,
"failed to count followers of user ID<b>$uid</b>", 0, 0, 0, 0);
2367 static function countMyFriends(
$db,
$uid)
2369 if (
$sql =
$db->query(
"SELECT count(id) FROM {friends}
2370 WHERE confirmed = '1' AND friendA = '".$uid.
"'
2371 OR friendB = '".
$uid.
"' AND confirmed = '1'
2372 AND aborted NOT LIKE '1'"))
2374 $row = mysqli_fetch_row(
$sql);
2379 \YAWK\sys::setSyslog(
$db, 19, 1,
"failed to count friends of user ID <b>$uid</b>", 0, 0, 0, 0);
2392 static function getMyFriends(
$db,
$uid, $confirmed,
$lang)
2395 if (isset($confirmed) && $confirmed === 0)
2403 if (
$sql =
$db->query(
"SELECT * FROM {friends} AS friends
2404 WHERE confirmed = '".$confirmed.
"' AND friendA = '".
$uid.
"'
2405 OR confirmed = '".$confirmed.
"' AND friendB = '".
$uid.
"'
2406 AND aborted NOT LIKE '1'"))
2409 while ($row = mysqli_fetch_assoc(
$sql))
2417 \YAWK\sys::setSyslog(
$db, 19, 1,
"failed to get friends of user ID <b>$uid</b>", 0, 0, 0, 0);
2428 static function getMyFollower(
$db,
$uid)
2446 if (
$sql =
$db->query(
"SELECT * FROM {follower} AS f
2447 LEFT JOIN {users} AS u ON f.follower=u.id
2448 WHERE hunted = '".$currentuser.
"'"))
2450 $follower = array();
2451 while ($row = mysqli_fetch_assoc(
$sql))
2459 \YAWK\sys::setSyslog(
$db, 3, 1,
"failed to get followers of user ID <b>$uid</b> .", 0, 0, 0, 0);
2470 static function countNewMessages(
$db,
$uid)
2473 if (
$sql =
$db->query(
"SELECT msg_id FROM {plugin_msg} WHERE msg_read ='0' AND spam IS NOT NULL AND trash IS NOT NULL AND toUID = '".$uid.
"'"))
2475 while ($row = mysqli_fetch_assoc(
$sql))
2483 \YAWK\sys::setSyslog(
$db, 3, 1,
"failed to count new messages of user ID <b>$uid</b> .", 0, 0, 0, 0);
2494 static function getNewMessages(
$db,
$uid)
2497 if (
$sql =
$db->query(
"SELECT * FROM {plugin_msg} WHERE msg_read ='0' AND toUID = '".$uid.
"' ORDER by msg_date DESC"))
2499 $newMessages = array();
2500 while ($row = mysqli_fetch_assoc(
$sql))
2502 $newMessages[] = $row;
2504 return $newMessages;
2508 \YAWK\sys::setSyslog(
$db, 3, 1,
"failed to get new messages of user ID <b>#$uid</b> .", 0, 0, 0, 0);
print $lang['FILEMAN_UPLOAD']
static draw($type, $title, $text, $redirect, $delay)
Email class serve function sendEmail() to send email.
static sendEmail($email_from, $email_to, $email_cc, $email_subject, $email_message)
send an email
static getSetting($db, $property)
Get and return value for property from settings database.
static setTimeout($location, $wait)
set a timeout and force page reload via JS
static getHost($db)
get hostname (url where yawk is installed) from database
static iStatusToString($i, $on, $off)
convert a integer status to string variable (0|1) to online / offline
The default user class. Provide all functions to handle the user object.
static getUserTemplateID($db, $uid)
template ID for given user ID
static getLoginData($db, $user)
return an array with all login data
static setNewPassword($db, $newPassword, $uid)
Set a new user password.
setUserTemplate($db, $overrideTemplate, $userTemplateID, $uid)
set status and override template for this user ID
__construct($db)
user constructor.
static drawLoginBox($username, $password)
return the html for a default login box
static isAnybodyThere($db)
check, if a session username is set and if user is logged in
static getUserImage($location, $user, $cssClass, $w, $h)
return and output user image
static getToken($length)
Generate a safe token for password reset.
static countUsers($db)
count and return all users
static drawPasswordResetForm($db, $lang, $uid)
Draw the form where users can reset their password.
static getUserList($db)
output a list of all users (who have not activated privacy switch)
isTemplateEqual($db, $userTemplateID)
check if user template equals selected (active) template
isAllowedToOverrideTemplate($db, $uid)
check if user ID is allowed to override template
static getUserEmail($db, $user)
return email address of $user
static getLatestUsers($db, $count)
get latest users and return as array
static getCurrentUserName($lang)
return current username
static ajaxLogin($db, $user, $password)
getUserArray($db)
return user data as an array
static drawMenuLoginBox($username, $password, $style)
return the html for a menu login box
static sendResetEmail($db, $username, $email, $lang)
Send password change request email.
static checkResetToken($db, $token)
Check if password reset token matches and return uid.
This class serves methods to create backup from files.