/dbhandler.php
PHP | 382 lines | 228 code | 66 blank | 88 comment | 5 complexity | 5e01373e663ad2c89cafa3cafd9db0d7 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-3.0
- <?php
-
- /**
- * This class contain all database related functions as utilities.
- * @author Mahesh Dhaduk
- */
- include_once ("config.php");
- class DbHandler
- {
- public $connection;
-
- function __construct()
- {
- $this->connection = mysql_connect(Config::$DBURL,Config::$DBUSERNAME,Config::$DBPASSWORD);
-
- if(!$this->connection)
- {
- echo mysql_error();
- }
- else
- {
- mysql_select_db(Config::$DBNAME,$this->connection);
- }
- }
-
- /**
- * Get MantisBt configuration which contain mantisconnect url for mantisbt server
- * and administrator's username and password
- * @return array
- */
- function GetMantisBtConfig()
- {
- $result = mysql_query("select url,admin_username,admin_password from mantisconfig",$this->connection);
- $config = mysql_fetch_array($result,MYSQL_ASSOC);
-
- return $config;
- }
-
- /**
- * Set MantisBt configuration which contain mantisconnect url for mantisbt server
- * and administrator's username and password
- * @param array $config associative array which contain url,admin_username,admin_password
- * @return boolean
- */
- function SetMantisBtConfig($config)
- {
- mysql_query('delete from mantisconfig',$this->connection);
-
- $insertSql = "insert into mantisconfig values ('".$config['url']."','".$config['admin_username']."','".$config['admin_password']."')";
-
- $config = mysql_query($insertSql,$this->connection);
-
- return $config;
- }
-
- /**
- * Get MantisBt Data which is useful to map username to userid
- * @return array It is array of associative arrays with userid,usename,realname,emailid
- */
- function GetMantisBtData()
- {
- $result = mysql_query("select userid,username,real_name,emailid from mantisbtdata",$this->connection);
-
- $mantisdata = array();
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($mantisdata,$row);
- }
-
- return $mantisdata;
- }
-
- /**
- * Set MantisBt Data which is useful to map username to userid
- * @param string $mantisbtData It is array of associative arrays with userid,usename,realname,emailid
- * @return boolean
- */
- function SetMantisBtData($mantisbtData)
- {
- mysql_query('delete from mantisbtdata',$this->connection);
-
- $ret;
-
- foreach ($mantisbtData as $row)
- {
- $insertSql = "insert into mantisbtdata values ('".$row['id']."','".$row['name']."','".
- $row['real_name']."','".$row['email']."')";
-
- $ret = mysql_query($insertSql,$this->connection);
- }
-
- return $ret;
- }
-
- /**
- * Get Mantisbt User Id from Mantisbt User Name
- * @param string $userName Mantisbt User Name for User
- * @return integer
- */
- function GetMantisBtUserId($userName)
- {
- $result = mysql_query("select userid from mantisbtdata where username ='".$userName."'",$this->connection);
- $userId = 0;
- if($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- $userId = $row['userid'];
- }
-
- return $userId;
- }
-
- /**
- * It return Bit Bucket User Names and Email Ids
- * @return array
- */
- function GetBitBucketData()
- {
- $result = mysql_query("select username,emailid from bitbucketdata",$this->connection);
-
- $bitbucketData = array();
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($bitbucketData,$row);
- }
-
- return $bitbucketData;
- }
-
- /**
- * Set User Names and User Ids
- * @param string $bitbucketData array of arrays which contais username and emailid
- * @return boolean
- */
- function SetBitBucketData($bitbucketData)
- {
- mysql_query('delete from bitbucketdata',$this->connection);
-
- $ret;
-
- foreach ($bitbucketData as $row)
- {
- $insertSql = "insert into bitbucketdata values ('".$row['username']."','".$row['emailid']."')";
- $ret = mysql_query($insertSql,$this->connection);
- }
-
- return $ret;
- }
-
- /**
- * Get Facebook Data which is useful to map username to userid
- * @return array It is array of associative arrays with userid,usename,realname,emailid
- */
- function GetFacebookData()
- {
- $result = mysql_query("select userid,username,realname,emailid from facebookdata",$this->connection);
-
- $facebookData = array();
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($facebookData,$row);
- }
-
- return $facebookData;
- }
-
- /**
- * Set Facebook Data which is useful to map username to userid
- * @param string $mantisbtData It is array of associative arrays with userid,usename,realname,emailid
- * @return boolean
- */
- function SetFacebookData($facebookData)
- {
- mysql_query('delete from facebookdata',$this->connection);
-
- $ret;
-
- foreach ($facebookData as $row)
- {
- $insertSql = "insert into facebookdata values (".$row['userid'].",'".$row['username']."','".
- $row['realname']."','".$row['emailid']."')";
-
- $ret = mysql_query($insertSql,$this->connection);
- }
-
- return $ret;
- }
-
- /**
- * It return You Tube User Names and Email Ids
- * @return array
- */
- function GetYouTubeData()
- {
- $result = mysql_query("select username,emailid from youtubedata",$this->connection);
-
- $youtubeData = array();
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($youtubeData,$row);
- }
-
- return $youtubeData;
- }
-
- /**
- * Set User Names and User Ids
- * @param string $youtubeData array of arrays which contais username and emailid
- * @return boolean
- */
- function SetYouTubeData($youtubeData)
- {
- mysql_query('delete from youtubedata',$this->connection);
-
- $ret;
-
- foreach ($youtubeData as $row)
- {
- $insertSql = "insert into youtubedata values ('".$row['username']."','".$row['emailid']."')";
- $ret = mysql_query($insertSql,$this->connection);
- }
-
- return $ret;
- }
-
- /**
- * It give user names of Bitbucket,Mantisbt,Facebook,Youtube according to Security Research username for all users
- * @return array
- */
- function GetSrData()
- {
- $result = mysql_query("select srusername,bbusername,mbusername,fbusername,ytusername from srdata",$this->connection);
-
- $srData = array();
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($srData,$row);
- }
-
- return $srData;
- }
-
- /**
- * Set user names of Bitbucket,Mantisbt,Facebook,Youtube according to Security Research username for all users
- * @param array $srData value of the name
- * @return boolean
- */
- function SetSrData($srData)
- {
- mysql_query('delete from srdata',$this->connection);
-
- $ret;
-
- foreach ($srData as $row)
- {
- $insertSql = "insert into srdata values ('".$row['srusername']."','".$row['bbusername']."','".
- $row['mbusername']."','".$row['fbusername']."','".$row['ytusername']."')";
- $ret = mysql_query($insertSql,$this->connection);
- }
-
- return $ret;
- }
-
- /**
- * It give list of Users and Repositories owned by him.
- * @return array
- */
- function GetBitBucketRepository()
- {
- $result = mysql_query("select username,repositoryname from bitbucketrepository",$this->connection);
-
- $repos = array();
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($repos,$row);
- }
-
- return $repos;
- }
-
- /**
- * Set Users and his Repositories
- * @return boolean
- */
- function SetBitBucketRepository($repos)
- {
- mysql_query('delete from bitbucketrepository',$this->connection);
-
- $ret;
-
- foreach ($repos as $row)
- {
- $insertSql = "insert into bitbucketrepository values ('".$row['username']."','".$row['repositoryname']."')";
- $ret = mysql_query($insertSql,$this->connection);
- }
-
- return $ret;
- }
-
- /**
- * This function gives user names of given user for Bitbucket,Mantisbt,Facebook,Youtube
- * @param string $userName Security Research User name
- * @return array
- */
- function GetAllUserId($userName)
- {
- $query="select fbusername,ytusername,mbusername,bbusername from srdata where srusername='".$userName."'";
- $result = mysql_query($query,$this->connection);
-
- $ret = array();
- if($result!=false)
- {
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($ret,$row);
- }
- }
- return $ret;
- }
-
- /**
- * Get Facebook user id Using Facebook user name
- * @param string $userName Facebook user name
- * @return array
- */
- function GetFBUserId($userName)
- {
- $query="select userid from facebookdata where username='".$userName."'";
- $result = mysql_query($query,$this->connection);
-
- $ret = array();
- if($result!=false)
- {
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($ret,$row);
- }
- }
- return $ret;
- }
-
- /**
- * Give possible matches for given keywords for user name
- * @param string $text value of the name
- * @return array
- */
- function GetSuggestion($text)
- {
- $query="SELECT srusername FROM srdata where srusername like '%".$text."%'";
- $result = mysql_query($query,$this->connection);
-
- $ret = array();
- if($result!=false)
- {
- while($row = mysql_fetch_array($result,MYSQL_ASSOC))
- {
- array_push($ret,$row);
- }
- }
- return $ret;
- }
-
- function InsertSRData($srUserName,$fbUserName,$ytUserName,$mbUserName,$bbUserName)
- {
- $ret;
- $insertsql = "insert into srdata values ('".$srUserName."','".$bbUserName."','".$mbUserName."','".$fbUserName."','".$ytUserName."')";
- $ret = mysql_query($insertsql,$this->connection);
-
- return $ret;
- }
-
- function UpdateSrData($srUserName,$fbUserName,$ytUserName,$mbUserName,$bbUserName)
- {
- mysql_query("delete from srdata where srusername = '".$srUserName."'",$this->connection);
-
- $ret;
- $insertSql = "insert into srdata values ('".$srUserName."','".$bbUserName."','".$mbUserName."','".$fbUserName."','".$ytUserName."')";
- $ret = mysql_query($insertSql,$this->connection);
- return $ret;
- }
- }
-
- ?>