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.

117 lines
3.7 KiB

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