details.php
changeset 12 e7e70577ce6c
parent 4 2c829de4b83c
child 13 bfe0d3de2764
--- a/details.php	Fri May 22 15:42:33 2009 +0100
+++ b/details.php	Fri Jun 19 16:55:15 2009 +0100
@@ -1,4 +1,24 @@
 <?php 
+	function remove_http($url = '')
+	{
+		if ($url == 'http://' OR $url == 'https://')
+		{
+			return $url;
+		}
+		$matches = substr($url, 0, 7);
+		if ($matches=='http://') 
+		{
+			$url = substr($url, 7);		
+		}
+		else
+		{
+			$matches = substr($url, 0, 8);
+			if ($matches=='https://') 
+			$url = substr($url, 8);
+		}
+		return $url;
+	}
+
 	// read user ID from cookie, if cookie doesn't exist, set to 1 (master)
 	$currID = $_COOKIE['uid'];
 	
@@ -7,24 +27,21 @@
 		$currID = 1;
 	}
  	// read session IDs from cookie, if cookie doesn't exist, set to 1 (master)
+
+echo $_COOKIE["sid1"];
         $currSID1 = $_COOKIE['sid1'];
-	$currSID2 = $_COOKIE['sid2'];
-
-
-        if ($currID == "")
-        {
-                $currID = 1;
-        }
 	if ($currSID1 == "")
         {
-                $currSID1 = 1;
+                $currSID1 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
         }
+
+        $currSID2 = $_COOKIE['sid2'];
 	if ($currSID2 == "")
         {
-                $currSID2 = 1;
+                $currSID2 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
         }
 
-
+print_r($_COOKIE);
 	
 	$status = $_GET['alert'];
 	$view_mode = $_GET['view_mode'];
@@ -36,7 +53,8 @@
 	mysql_select_db('members');
 	
 	// search server cache for received websites
-	if (($currID != 1) && ($currSID1 != 1) && ($currSID2 != 1))
+	// anonymous uid=1, sid1=06D5VlLQTbM57LL7IBMW38yHkFpb1XVa & sid2 =06D5VlLQTbM57LL7IBMW38yHkFpb1XVa
+	if (($currID != 1) && ($currSID1 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa") && ($currSID2 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa"))
 	{
 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
 	} 
@@ -49,18 +67,35 @@
 	{
 		// send command to squid and return value
 		$curr_reqID = $db_fieldcache["req_ID"];
-#		$commandline = "squidclient -m HEAD -p 8080 -H \"Cache-Control: only-if-cached\n\" -u " . $db_fieldcache["req_ID"] . " -w " . $db_fieldcache["uid"] . " " . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
-#		exec($commandline, $cache_results);
+//$commandline = "wget --delete-after -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d http://localhost/staging/" " . $db_fieldcache["req_ID"] . " " . $db_fieldcache["req_val"];
+//echo $commandline;
+
+//                exec($commandline, $wget_results);
+//$commandline = "squidclient -m HEAD -p 8080 -H \"Cache-Control: only-if-cached\n\" -u " . $db_fieldcache["req_ID"] . " -w " . $db_fieldcache["uid"] . " " . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
+
+		$filename = "/var/www/private/HTMLrequester/staging/{$db_fieldcache["req_ID"]}/";
+
+//$commandline = "squidclient -m HEAD -p 8080 -H \"Cache-Control: only-if-cached\n\" -u " . $db_fieldcache["req_ID"] . " -w " . $db_fieldcache["uid"] . " " . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
+
+//		exec($commandline, $cache_results);
 		
 		// find out if site is available and update the database
-		if (strpos($cache_results, "HIT") == true)
-		{
-			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
-		} 
+//		if (strpos($cache_results, "HIT") == true)
+//		{
+//			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
+//		} 
+//		else 
+//		{
+//			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
+//		}
+		if (file_exists($filename)) 
+    			{
+    			$query_update = mysql_query("UPDATE requests_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
+    			} 
 		else 
-		{
-			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
-		}
+    			{
+   			$query_update = mysql_query("UPDATE requests_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
+			}  
 	}
 	
 	
@@ -196,7 +231,10 @@
 					print "<span class='result_output_none'>Result pending</span>";
 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
 				} else {
-					print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>";
+//header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . dirname($db_fieldcache["req_ID"]));
+//strip_tags($text, '<p><a>')
+                                      print "<span class='result_output'><a href='". 'staging/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val']) ."' target='_blank'>View website</a></span>";
+//					print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>";
 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
 				}
                 print "<div class='clear'></div></div>";