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 ToolPostimer extends Tools_Abstract{
- private $tool;
- private $_api;
- 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'] = $user['charname'];
- $tooldata['userkey'] = $this->createRandomPassword();
- $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')";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- $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'])."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- $data = mysql_fetch_array($result);
- $id = $data['id'];
- $qry="insert into ".$this->tool['db_name'].".`profiles` (`user_id`,`subscribe`) VALUES ('".$id."',0)";
- $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'].".`users` SET `password` = md5('".$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){
- $newPass = $this->createRandomPassword();
- $usertooldataModel = new Model_Usertooldata();
- $uniqueID = $usertooldataModel->getUniqueID($toolID,$userID);
- $qry = "UPDATE ".$this->tool['db_name'].".`users` SET `password` = md5('".$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){
- $newPass = $this->createRandomPassword();
- $usertooldataModel = new Model_Usertooldata();
- $username = $usertooldataModel->getUniqueID( $toolid, $userData['ID']);
- $qry = "UPDATE ".$this->tool['db_name'].".`users` SET `password` = md5('".$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 = "SELECT id FROM ".$this->tool['db_name'].".`users` WHERE `username` = '".mysql_real_escape_string($uniqueid)."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- $data = mysql_fetch_array($result);
- $id = $data['id'];
- $qry = "DELETE FROM ".$this->tool['db_name'].".`users` WHERE `username` = '".mysql_real_escape_string($uniqueID)."'";
- $result = mysql_query($qry, $this->dblink);
- if ($result == false)
- return 0;
- $qry = "DELETE FROM ".$this->tool['db_name'].".`profiles` WHERE `user_id` = '".$id."'";
- $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 "POS-Timer - Deaktivated User: " . $user['ticker'] . " - " . $user['charname'] . PHP_EOL;
- }
- else
- echo "POS-Timer - 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 "POS-Timer - 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement