sr-analytics /dbhandler.php

Language PHP Lines 383
MD5 Hash 5e01373e663ad2c89cafa3cafd9db0d7 Estimated Cost $5,668 (why?)
Repository https://bitbucket.org/MaheshDhaduk/sr-analytics View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?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;
	}	
}

?>
Back to Top