Advertisement
Guest User

Untitled

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