Commits

Ethan Robish committed 6dc750b

moving database info to config file

Comments (0)

Files changed (2)

 
 	global $config;
 	$config = array(
+		// examples:
+		//    'mysql:host=localhost;dbname=weblabyrinth'
+		//    'sqlite:/opt/weblabyrinth/labyrinth.db'
+		'pdo_connection_string' => 'mysql:host=localhost;dbname=weblabyrinth',
+		
+		'db_username' => '',
+		
+		'db_password' => '',
+		
 		//Web Path where WebLabyrinth is installed
 		'web_path' => '/labyrinth',
 

labyrinth.inc.php

  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
+include_once('config.inc.php');
+ 
 class Labyrinth {
 	
 	var $dbhandle;
 	public function Labyrinth($ip,$useragent){
 		global $config;
 		mt_srand($this->MakeSeed());
-
-//		$this->dbhandle = new SQLiteDatabase($config['tracking_db']);
-		//$this->dbhandle = new PDO('sqlite:' . $config['tracking_db']);
-		$this->dbhandle = new PDO('mysql:host=localhost;dbname=weblabyrinth', 'dbusername', 'dbpassword');
 		
-//		$this->crawler_ip = sqlite_escape_string($ip);
+		if(empty($config['db_username'])){
+			$this->dbhandle = 
+				new PDO($config['pdo_connection_string']);
+		} else {
+			$this->dbhandle = 
+				new PDO($config['pdo_connection_string'], 
+					$config['db_username'], $config['db_password']);
+		}
+		
 		$this->crawler_ip = $this->dbhandle->quote($ip);
-//		$this->crawler_useragent = sqlite_escape_string($useragent);
 		$this->crawler_useragent = $this->dbhandle->quote($useragent);
 
 		$rows = $this->dbhandle->query("SELECT COUNT(*) FROM crawlers WHERE crawler_ip=" 
 		global $config;
 
 		//Have we seen this crawler recently?		
-//		$last_seen_query = $this->dbhandle->query("SELECT strftime('%s',datetime('now','localtime')) - strftime('%s',last_alert) FROM crawlers WHERE crawler_ip='" . $this->crawler_ip . "' AND crawler_useragent='" . $this->crawler_useragent . "'") or die(sqlite_error_string($this->dbhandle->lastError()));;
-
 		$query = "SELECT last_alert FROM crawlers WHERE crawler_ip=" 
 			. $this->crawler_ip . " AND crawler_useragent=" . $this->crawler_useragent . ";"; 
 		$last_seen_query = $this->dbhandle->query($query)
 			 or die(print_r($this->dbhandle->errorInfo(), true));
 		if ($last_seen_query) {
-//			$time = $last_seen_query->fetchSingle();
 			$last_alert_time = $last_seen_query->fetchColumn();
 			$time = time() - $last_alert_time;
 		}
 	function LogCrawler(){
 		global $config;
 
-//		if($this->crawler_info->numRows() > 0){
 		if($this->crawler_seen) {
 			$this->dbhandle->query("UPDATE crawlers SET last_seen = " . time() 
 				. ", num_hits=num_hits+1 WHERE crawler_ip=" . $this->crawler_ip 
 				. $this->crawler_useragent . ", "
 				. time() . ", " . time() . ", 1);")
 				or die(print_r($this->dbhandle->errorInfo(), true));
-			/*$this->dbhandle->query("INSERT INTO crawlers(crawler_ip, "
-				. "crawler_rdns, crawler_useragent, first_seen, last_seen, num_hits) "
-				. "VALUES (" . $this->dbhandle->quote($this->crawler_ip) . ", "
-				. $this->dbhandle->quote($crawler_rdns) . ", "
-				. $this->dbhandle->quote($this->crawler_useragent) . ", "
-				. time() . ", " . time() . ", 1)")
-				or die(print_r($this->dbhandle->errorInfo(), true));*/
-
 			$this->new = true;
 			if($config['alert_on_new']){
 				$this->GenerateAlert("New host logged!");