Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'class.tools.php';
- /**
- * main class Tools_Abstract contains DB-Connection Settings from tools table
- * (To set-up via admin-area) $this->dblink and $this->toolid
- */
- class Jabberd2 extends Tools_Abstract{
- private $tool;
- private $_api;
- /**
- * the domain of the jabber server
- */
- private $realm;
- public function __construct($tool){
- $this->tool = $tool;
- parent::__construct($tool);
- }
- public function insertUser($usertooldata, $user){
- if ($user['positivecheck']) {
- $api = $this->getApi();
- $api->setup($user['userid'],$user['apikey']);
- if ($usertooldata->fetchToolData($this->toolid, $user['ID']))
- return ($this->editUser($usertooldata,$user));
- if (isset($this->toolid))
- $tooldata['toolid'] = intval($this->toolid);
- else
- return 0;
- if (isset($user['ID']))
- $tooldata['userid'] = intval($user['ID']);
- else
- return 0;
- $tooldata['uniqueid'] = this->escapeName($user['charname']);
- $tooldata['userkey'] = $this->createRandomPassword();
- // the authreg table is the
- $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']))."')";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- return $usertooldata->insertToolData($tooldata);
- }
- return null;
- }
- public function renewUser($user, $username, $password){
- $newPass = $this->createRandomPassword();
- $qry = "UPDATE ".$this->tool['db_name'].".`authreg` SET `password` = '".mysql_real_escape_string(crypt($newPass))."' WHERE `username` = '".mysql_real_escape_string($username)."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- else
- return $newPass;
- }
- /*
- * implements deactivation of a User if its API-Key turns invalid or otherwise inaccessible!
- */
- public function deactivateUser($toolID, $userID){
- // overwrites the password with a random password
- $newPass = $this->createRandomPassword();
- $usertooldataModel = new Model_Usertooldata();
- $uniqueID = $usertooldataModel->getUniqueID($toolID,$userID);
- $qry = "UPDATE ".$this->tool['db_name'].".`authreg` SET `password` = '".mysql_real_escape_string(crypt($newPass))."' WHERE `username` = '".mysql_real_escape_string($uniqueID)."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- else
- return 1;
- }
- /**
- *
- * @param int $toolid
- * @param array $userData
- * @param Model_Usertooldata $usertooldataModel
- */
- public function reactivateUser($toolid, $userData, $usertooldataModel){
- // adds a new password and returns it.
- $newPass = $this->createRandomPassword();
- $usertooldataModel = new Model_Usertooldata();
- $username = $usertooldataModel->getUniqueID( $toolid, $userData['ID']);
- $qry = "UPDATE ".$this->tool['db_name'].".`authreg` SET `password` = '".mysql_real_escape_string(crypt($newPass)."' WHERE `username` = '".mysql_real_escape_string($username)."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- else
- return $usertooldataModel->setUserKey($toolid, $userData['ID'], $newPass);
- }
- /*
- * Remove Client permissions and grouptoserver perms for deactivated clients. #
- * Logs won't be removed anymore. QueryConsole Usage again *meh*
- * @todo Error Messages and unit Tests
- */
- public function deleteUser($toolID, $userID){
- $usertooldataModel = new Model_Usertooldata();
- $uniqueID = $usertooldataModel->getUniqueID($toolID,$userID);
- $qry = "DELETE FROM ".$this->tool['db_name'].".`authreg` WHERE `username` = '".mysql_real_escape_string($uniqueID)."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- }
- public function editUser($usertooldata,$user){
- }
- /*
- * No Scheduled things to do for this mod...
- */
- public function cronJobs($_models){
- $_allUsers = $_models['user']->users();
- foreach ($_allUsers as $user){
- $isactive = $_models['usertooldata']->isActive($this->toolid, $user['ID']);
- if (!$user['positivecheck'] && $user['neg_counter'] > 100 && $isactive){
- if ($this->deactivateUser($this->toolid,$user['ID'])){
- $_models['usertooldata']->setInactive($this->toolid, $user['ID']);
- echo "Jabberd2 - Deaktivated User: " . $user['ticker'] . " - " . $user['charname'] . PHP_EOL;
- }
- else
- echo "Jabebrd2 - ERROR - Unable to deaktivate User: " . $user['ticker'] . " - " . $user['charname'] . PHP_EOL;
- }
- elseif ($user['positivecheck'] && isset($isactive) && $isactive == 0){
- $this->reactivateUser($this->toolid,$user, $_models['usertooldata']);
- $_models['usertooldata']->setActive($this->toolid, $user['ID']);
- echo "Jabberd2 - Reaktivated User: " . $user['ticker'] . " - " . $user['charname'] . "\n";
- }
- }
- }
- protected function getApi(){
- require_once(APPLICATION_PATH .'/../library/class.apiinterface.php');
- if ($this->_api == null)
- $this->_api = new apiinterface();
- return $this->_api;
- }
- /**
- * @return the name with the " " and "'" repalced with "_" and "-"
- */
- public function escapeName($name){
- $newname = str_replace(" ","_",$name);
- $newname = str_replace("'","-",$name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement