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.

105 lines
5.3 KiB

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