Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.86 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'class.tools.php';
  4.    
  5. /**
  6.  * main class Tools_Abstract contains DB-Connection Settings from tools table
  7.  * (To set-up via admin-area) $this->dblink and $this->toolid  
  8.  */
  9. class ToolPostimer extends Tools_Abstract{
  10.    
  11.     private $tool;
  12.     private $_api;
  13.    
  14.     public function __construct($tool){
  15.         $this->tool = $tool;
  16.         parent::__construct($tool);
  17.     }
  18.  
  19.     public function insertUser($usertooldata, $user){
  20.         if ($user['positivecheck']) {
  21.             $api = $this->getApi();
  22.             $api->setup($user['userid'],$user['apikey']);
  23.            
  24.             if ($usertooldata->fetchToolData($this->toolid, $user['ID']))
  25.                 return ($this->editUser($usertooldata,$user));
  26.            
  27.             if (isset($this->toolid))
  28.                 $tooldata['toolid'] = intval($this->toolid);
  29.             else
  30.                 return 0;
  31.            
  32.             if (isset($user['ID']))
  33.                 $tooldata['userid'] = intval($user['ID']);
  34.             else
  35.                 return 0;
  36.             $tooldata['uniqueid'] = $user['charname'];
  37.             $tooldata['userkey'] = $this->createRandomPassword();
  38.            
  39.             $qry="insert into ".$this->tool['db_name'].".`users` (`username`,`password`,`email`,`createtime`,`superuser`,`status`) VALUES ('".mysql_real_escape_string($tooldata['uniqueid'])."','".md5($tooldata['userkey'])."','".mysql_real_escape_string($user['email'])."', ".time().",'0','1')";
  40.             $result = mysql_query($qry, $this->dblink);
  41.             if ($result == false)
  42.                 return 0;
  43.             $qry = "SELECT id FROM ".$this->tool['db_name'].".`users` WHERE `username` = '".mysql_real_escape_string($tooldata['uniqueid'])."' and `email` = '".mysql_real_escape_string($user['email'])."'";
  44.             $result = mysql_query($qry, $this->dblink);
  45.             if ($result == false)
  46.                 return 0;
  47.             $data = mysql_fetch_array($result);
  48.             $id = $data['id'];
  49.             $qry="insert into ".$this->tool['db_name'].".`profiles` (`user_id`,`subscribe`) VALUES ('".$id."',0)";
  50.             $result = mysql_query($qry, $this->dblink);
  51.             if ($result == false)
  52.                 return 0;
  53.             return $usertooldata->insertToolData($tooldata);
  54.         }
  55.         return null;
  56.     }
  57.    
  58.     public function renewUser($user, $username, $password){
  59.         $newPass = $this->createRandomPassword();
  60.         $qry = "UPDATE ".$this->tool['db_name'].".`users` SET `password` = md5('".$newPass."') WHERE `username` = '".mysql_real_escape_string($username)."'";
  61.         $result = mysql_query($qry, $this->dblink);
  62.         if ($result == false)
  63.             return 0;
  64.         else
  65.             return $newPass;
  66.     }
  67.    
  68.    
  69.  
  70.     /*
  71.      * implements deactivation of a User if its API-Key turns invalid or otherwise inaccessible!
  72.      */
  73.     public function deactivateUser($toolID, $userID){
  74.         $newPass = $this->createRandomPassword();
  75.         $usertooldataModel = new Model_Usertooldata();
  76.         $uniqueID = $usertooldataModel->getUniqueID($toolID,$userID);
  77.         $qry = "UPDATE ".$this->tool['db_name'].".`users` SET `password` = md5('".$newPass."') WHERE `username` = '".mysql_real_escape_string($uniqueID)."'";
  78.         $result = mysql_query($qry, $this->dblink);
  79.         if ($result == false)
  80.             return 0;
  81.         else
  82.             return 1;
  83.     }
  84.    
  85.     /**
  86.      *
  87.      * @param int $toolid
  88.      * @param array $userData
  89.      * @param Model_Usertooldata $usertooldataModel
  90.      */
  91.     public function reactivateUser($toolid, $userData, $usertooldataModel){
  92.         $newPass = $this->createRandomPassword();
  93.         $usertooldataModel = new Model_Usertooldata();
  94.         $username = $usertooldataModel->getUniqueID( $toolid, $userData['ID']);
  95.         $qry = "UPDATE ".$this->tool['db_name'].".`users` SET `password` = md5('".$newPass."') WHERE `username` = '".mysql_real_escape_string($username)."'";
  96.         $result = mysql_query($qry, $this->dblink);
  97.         if ($result == false)
  98.             return 0;
  99.         else
  100.             return $usertooldataModel->setUserKey($toolid, $userData['ID'], $newPass);
  101.     }
  102.    
  103.     /*
  104.      * Remove Client permissions and grouptoserver perms for deactivated clients. #
  105.      * Logs won't be removed anymore. QueryConsole Usage again *meh*
  106.      * @todo Error Messages and unit Tests
  107.      */
  108.     public function deleteUser($toolID, $userID){
  109.         $usertooldataModel = new Model_Usertooldata();
  110.         $uniqueID = $usertooldataModel->getUniqueID($toolID,$userID);
  111.         $qry = "SELECT id FROM ".$this->tool['db_name'].".`users` WHERE `username` = '".mysql_real_escape_string($uniqueid)."'";
  112.         $result = mysql_query($qry, $this->dblink);
  113.         if ($result == false)
  114.             return 0;
  115.         $data = mysql_fetch_array($result);
  116.         $id = $data['id'];
  117.         $qry = "DELETE FROM ".$this->tool['db_name'].".`users` WHERE `username` = '".mysql_real_escape_string($uniqueID)."'";
  118.         $result = mysql_query($qry, $this->dblink);
  119.         if ($result == false)
  120.             return 0;
  121.         $qry = "DELETE FROM ".$this->tool['db_name'].".`profiles` WHERE `user_id` = '".$id."'";
  122.         $result = mysql_query($qry, $this->dblink);
  123.         if ($result == false)
  124.             return 0;
  125.        
  126.            
  127.        
  128.     }
  129.    
  130.     public function editUser($usertooldata,$user){
  131.     }
  132.  
  133.     /*
  134.      * No Scheduled things to do for this mod...
  135.      */
  136.     public function cronJobs($_models){
  137.         $_allUsers = $_models['user']->users();
  138.         foreach ($_allUsers as $user){
  139.             $isactive = $_models['usertooldata']->isActive($this->toolid, $user['ID']);
  140.             if (!$user['positivecheck']  && $user['neg_counter'] > 100 && $isactive){
  141.                 if ($this->deactivateUser($this->toolid,$user['ID'])){
  142.                     $_models['usertooldata']->setInactive($this->toolid, $user['ID']);
  143.                     echo "POS-Timer - Deaktivated User: " . $user['ticker'] . " - " . $user['charname'] . PHP_EOL;
  144.                 }
  145.                 else
  146.                     echo "POS-Timer - ERROR - Unable to deaktivate User: " . $user['ticker'] . " - " . $user['charname'] . PHP_EOL;
  147.             }
  148.             elseif ($user['positivecheck'] && isset($isactive) && $isactive == 0){
  149.                 $this->reactivateUser($this->toolid,$user, $_models['usertooldata']);
  150.                 $_models['usertooldata']->setActive($this->toolid, $user['ID']);
  151.                 echo "POS-Timer - Reaktivated User: " . $user['ticker'] . " - " . $user['charname'] . "\n";
  152.             }
  153.         }
  154.     }
  155.  
  156.    
  157.     protected function getApi(){
  158.         require_once(APPLICATION_PATH .'/../library/class.apiinterface.php');
  159.         if ($this->_api == null)
  160.             $this->_api = new apiinterface();
  161.         return $this->_api;
  162.     }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement