Advertisement
Guest User

Membership.php

a guest
Sep 30th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.76 KB | None | 0 0
  1. <?php
  2.  
  3. class Membership extends ClassAbstract
  4. {
  5.     private $username;
  6.     private $remoteAddress;
  7.     private $status;
  8.     private $reseller;
  9.     private $permission;
  10.     private $serverallow;
  11.     private $profileallow;
  12.     private $totalUser;
  13.     private $activeUser;
  14.     private $currActiveTotalUser;
  15.     private $serverList;
  16.     private $groupList;
  17.     private $updateActiveTotalUser;
  18.     private $cspUpdateTime;
  19.    
  20.     function setSessionData()
  21.     {
  22.         $_SESSION['username']              = $this->getUsername();
  23.         $_SESSION['remote_address']        = $this->getRemoteAddress();
  24.         $_SESSION['status']                = $this->getStatus();
  25.         $_SESSION['reseller']              = $this->getReseller();
  26.         $_SESSION['permission']            = $this->getPersmission();
  27.         $_SESSION['serverallow']           = $this->getServerAllow();
  28.         $_SESSION['profileallow']          = $this->getProfileAllow();
  29.         $_SESSION['totalUser']             = $this->getTotalUser();
  30.         $_SESSION['activeUser']            = $this->getActiveUser();
  31.         $_SESSION['currActiveTotalUser']   = $this->getCurrActiveTotalUser();
  32.         $_SESSION['serverList']            = $this->getServerList();
  33.         $_SESSION['groupList']             = $this->getGroupList();
  34.         $_SESSION['updateActiveTotalUser'] = $this->getUpdateActiveTotalUser();
  35.         $_SESSION['cspUpdateTime']         = $this->cspUpdateTime;
  36.     }
  37.    
  38.     /*
  39.      *  Setter Functions
  40.      */
  41.    
  42.     function setUsername($un)
  43.     {
  44.         $this->username = $un;
  45.     }
  46.    
  47.     function setRemoteAddress($IP)
  48.     {
  49.         $this->remoteAddress = $IP;
  50.     }
  51.    
  52.     function setStatus($status)
  53.     {
  54.         $this->status = $status;
  55.     }
  56.    
  57.     function setReseller($reseller)
  58.     {
  59.         $this->reseller = $reseller;
  60.     }
  61.    
  62.     function setPersmission($permsission)
  63.     {
  64.         $this->permission = $permsission;
  65.     }
  66.    
  67.     function setServerAllow($serverallow)
  68.     {
  69.         $this->serverallow = $serverallow;
  70.     }
  71.    
  72.     function setProfileAllow($profileallow)
  73.     {
  74.         $this->profileallow = $profileallow;
  75.     }
  76.    
  77.     function setTotalUser($totaluser)
  78.     {
  79.         $this->totalUser = $totaluser;
  80.     }
  81.    
  82.     function setActiveUser($activeuser)
  83.     {
  84.         $this->activeUser = $activeuser;
  85.     }
  86.    
  87.     function setCurrActiveTotalUser($reseller)
  88.     {
  89.         global $mysql;
  90.         $this->currActiveTotalUser = $mysql->get_info($reseller);
  91.     }
  92.    
  93.     function setUpdateActiveTotalUser($updateActiveTotalUser)
  94.     {
  95.         $this->updateActiveTotalUser = $updateActiveTotalUser;
  96.     }
  97.    
  98.     function setServerList()
  99.     {
  100.         global $mysql;
  101.         $this->serverList = $mysql->serverList();
  102.     }
  103.    
  104.     function setGroupList()
  105.     {
  106.         global $mysql;
  107.         $this->groupList = $mysql->groupsList();
  108.     }
  109.    
  110.     /*
  111.      *  Getter Functions
  112.      */
  113.    
  114.     function getUsername()
  115.     {
  116.         return $this->username;
  117.     }
  118.    
  119.     function getRemoteAddress()
  120.     {
  121.         return $this->remoteAddress;
  122.     }
  123.    
  124.     function getStatus()
  125.     {
  126.         return $this->status;
  127.     }
  128.    
  129.     function getReseller()
  130.     {
  131.         return $this->reseller;
  132.     }
  133.    
  134.     function getPersmission()
  135.     {
  136.         return $this->permission;
  137.     }
  138.    
  139.     function getServerAllow()
  140.     {
  141.         return $this->serverallow;
  142.     }
  143.    
  144.     function getProfileAllow()
  145.     {
  146.         return $this->profileallow;
  147.     }
  148.    
  149.     function getTotalUser()
  150.     {
  151.         return $this->totalUser;
  152.     }
  153.    
  154.     function getActiveUser()
  155.     {
  156.         return $this->activeUser;
  157.     }
  158.    
  159.     function getCurrActiveTotalUser()
  160.     {
  161.         return $this->currActiveTotalUser;
  162.     }
  163.    
  164.     function getUpdateActiveTotalUser()
  165.     {
  166.         return $this->updateActiveTotalUser;
  167.     }
  168.    
  169.     function getServerList()
  170.     {
  171.         return $this->serverList;
  172.     }
  173.    
  174.     function getGroupList()
  175.     {
  176.         return $this->groupList;
  177.     }
  178.    
  179.     function validate_user($un, $pwd)
  180.     {
  181.         global $mysql;
  182.         global $log;
  183.         $error = "";
  184.        
  185.         $this->setUsername($un);
  186.         $this->setRemoteAddress($_SERVER['REMOTE_ADDR']);
  187.         if (preg_match('/^([A-Za-z1-90]+)$/', $un)) {
  188.             $clean_un = $un;
  189.         } else {
  190.             $error = "Bad Username";
  191.             $log->LogWarn('User [' . $this->getUsername() . '](' . $this->getRemoteAddress() . ') try to log in to system. Login Denied. BAD Username or Password.');
  192.         }
  193.        
  194.         if ($clean_pwd = preg_match('/^([A-Za-z0-9]+)$/', $pwd)) {
  195.             $clean_pwd = $pwd;
  196.         } else {
  197.             if ($error != "") {
  198.                 $error .= " And Bad Password";
  199.                 $log->LogWarn('User [' . $this->getUsername() . '](' . $this->getRemoteAddress() . ') try to log in to system. Login Denied. BAD Username or Password.');
  200.             } else {
  201.                 $error = "Bad Password";
  202.                 $log->LogWarn('User [' . $this->getUsername() . '](' . $this->getRemoteAddress() . ') try to log in to system. Login Denied. BAD Username or Password.');
  203.             }
  204.         }
  205.        
  206.         if ($error != "")
  207.             return $error;
  208.        
  209.         $ensure_credentials = $mysql->verify_Username_and_Pass($clean_un, md5($clean_pwd));
  210.         $reseller           = $mysql->get_reseller_id($un);
  211.         $permission         = $mysql->get_permission_id($un);
  212.        
  213.         if ($ensure_credentials) {
  214.             $this->setStatus('authorized');
  215.             $this->setReseller($mysql->get_reseller_id($un));
  216.             $this->setPersmission($mysql->get_permission_id($un));
  217.             $this->setServerAllow($mysql->get_member_serverallow($un));
  218.             $this->setProfileAllow($mysql->get_member_profileallow($un));
  219.             $this->setTotalUser($mysql->get_member_total_user($un));
  220.             $this->setActiveUser($mysql->get_member_active_user($un));
  221.             $this->setUpdateActiveTotalUser(1);
  222.             $this->setCurrActiveTotalUser($this->getReseller());
  223.             $this->setServerList();
  224.             $this->setGroupList();
  225.             $this->cspUpdateTime = "";
  226.            
  227.             /*
  228.              * Save all member data in session
  229.              */
  230.             $this->setSessionData();
  231.            
  232.             header("location: index.php");
  233.             $log->LogInfo('User [' . $this->getUsername() . '] (' . $this->getRemoteAddress() . ') Logged in Successfully.');
  234.         } else {
  235.             $log->LogWarn('User [' . $this->getUsername() . '](' . $this->getRemoteAddress() . ') Login Denied. Wrong Username or Password.');
  236.             return "Please enter a correct username and password";
  237.         }
  238.     }
  239.    
  240.     function log_User_Out()
  241.     {
  242.         global $log;
  243.         if (isset($_SESSION['status'])) {
  244.             unset($_SESSION['status']);
  245.             $log->LogInfo('User [' . $_SESSION['username'] . '] Logged Out Successfully.');
  246.             if (isset($_COOKIE[session_name()]))
  247.                 setcookie(session_name(), '', time() - 1000);
  248.             session_destroy();
  249.         }
  250.     }
  251.    
  252.     function confirm_Member()
  253.     {
  254.         //        session_start();
  255.         if ($_SESSION['status'] != 'authorized')
  256.             header("location: login.php");
  257.     }
  258.    
  259.     function confirm_permision($section_permission, $user_permission)
  260.     {
  261.         global $mysql;
  262.         if (!$mysql->bitwise_check($section_permission, $user_permission)) {
  263.             echo "Sorry... \nYou are not allow to enter this section. </br>";
  264.             echo '<a href=index.php>back to previous page</a>';
  265.             die();
  266.         }
  267.     }
  268.    
  269.    
  270.    
  271. }
  272.  
  273. $membership = new Membership();
  274. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement