details.php
changeset 12 e7e70577ce6c
parent 4 2c829de4b83c
child 13 bfe0d3de2764
equal deleted inserted replaced
11:022ee48c7409 12:e7e70577ce6c
     1 <?php 
     1 <?php 
       
     2 	function remove_http($url = '')
       
     3 	{
       
     4 		if ($url == 'http://' OR $url == 'https://')
       
     5 		{
       
     6 			return $url;
       
     7 		}
       
     8 		$matches = substr($url, 0, 7);
       
     9 		if ($matches=='http://') 
       
    10 		{
       
    11 			$url = substr($url, 7);		
       
    12 		}
       
    13 		else
       
    14 		{
       
    15 			$matches = substr($url, 0, 8);
       
    16 			if ($matches=='https://') 
       
    17 			$url = substr($url, 8);
       
    18 		}
       
    19 		return $url;
       
    20 	}
       
    21 
     2 	// read user ID from cookie, if cookie doesn't exist, set to 1 (master)
    22 	// read user ID from cookie, if cookie doesn't exist, set to 1 (master)
     3 	$currID = $_COOKIE['uid'];
    23 	$currID = $_COOKIE['uid'];
     4 	
    24 	
     5 	if ($currID == "") 
    25 	if ($currID == "") 
     6 	{
    26 	{
     7 		$currID = 1;
    27 		$currID = 1;
     8 	}
    28 	}
     9  	// read session IDs from cookie, if cookie doesn't exist, set to 1 (master)
    29  	// read session IDs from cookie, if cookie doesn't exist, set to 1 (master)
       
    30 
       
    31 echo $_COOKIE["sid1"];
    10         $currSID1 = $_COOKIE['sid1'];
    32         $currSID1 = $_COOKIE['sid1'];
    11 	$currSID2 = $_COOKIE['sid2'];
       
    12 
       
    13 
       
    14         if ($currID == "")
       
    15         {
       
    16                 $currID = 1;
       
    17         }
       
    18 	if ($currSID1 == "")
    33 	if ($currSID1 == "")
    19         {
    34         {
    20                 $currSID1 = 1;
    35                 $currSID1 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
    21         }
    36         }
       
    37 
       
    38         $currSID2 = $_COOKIE['sid2'];
    22 	if ($currSID2 == "")
    39 	if ($currSID2 == "")
    23         {
    40         {
    24                 $currSID2 = 1;
    41                 $currSID2 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
    25         }
    42         }
    26 
    43 
    27 
    44 print_r($_COOKIE);
    28 	
    45 	
    29 	$status = $_GET['alert'];
    46 	$status = $_GET['alert'];
    30 	$view_mode = $_GET['view_mode'];
    47 	$view_mode = $_GET['view_mode'];
    31 	$view_order = $_GET['view_order'];
    48 	$view_order = $_GET['view_order'];
    32 	
    49 	
    34 	// connect to the database
    51 	// connect to the database
    35 	$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
    52 	$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
    36 	mysql_select_db('members');
    53 	mysql_select_db('members');
    37 	
    54 	
    38 	// search server cache for received websites
    55 	// search server cache for received websites
    39 	if (($currID != 1) && ($currSID1 != 1) && ($currSID2 != 1))
    56 	// anonymous uid=1, sid1=06D5VlLQTbM57LL7IBMW38yHkFpb1XVa & sid2 =06D5VlLQTbM57LL7IBMW38yHkFpb1XVa
       
    57 	if (($currID != 1) && ($currSID1 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa") && ($currSID2 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa"))
    40 	{
    58 	{
    41 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
    59 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
    42 	} 
    60 	} 
    43 	else 
    61 	else 
    44 	{
    62 	{
    47 	
    65 	
    48 	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
    66 	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
    49 	{
    67 	{
    50 		// send command to squid and return value
    68 		// send command to squid and return value
    51 		$curr_reqID = $db_fieldcache["req_ID"];
    69 		$curr_reqID = $db_fieldcache["req_ID"];
    52 #		$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";
    70 //$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"];
    53 #		exec($commandline, $cache_results);
    71 //echo $commandline;
       
    72 
       
    73 //                exec($commandline, $wget_results);
       
    74 //$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";
       
    75 
       
    76 		$filename = "/var/www/private/HTMLrequester/staging/{$db_fieldcache["req_ID"]}/";
       
    77 
       
    78 //$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";
       
    79 
       
    80 //		exec($commandline, $cache_results);
    54 		
    81 		
    55 		// find out if site is available and update the database
    82 		// find out if site is available and update the database
    56 		if (strpos($cache_results, "HIT") == true)
    83 //		if (strpos($cache_results, "HIT") == true)
    57 		{
    84 //		{
    58 			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
    85 //			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
    59 		} 
    86 //		} 
       
    87 //		else 
       
    88 //		{
       
    89 //			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
       
    90 //		}
       
    91 		if (file_exists($filename)) 
       
    92     			{
       
    93     			$query_update = mysql_query("UPDATE requests_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
       
    94     			} 
    60 		else 
    95 		else 
    61 		{
    96     			{
    62 			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
    97    			$query_update = mysql_query("UPDATE requests_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
    63 		}
    98 			}  
    64 	}
    99 	}
    65 	
   100 	
    66 	
   101 	
    67 	// pick order to show (user specified)
   102 	// pick order to show (user specified)
    68 	
   103 	
   194 				if ($db_field['req_response'] == 0)
   229 				if ($db_field['req_response'] == 0)
   195 				{
   230 				{
   196 					print "<span class='result_output_none'>Result pending</span>";
   231 					print "<span class='result_output_none'>Result pending</span>";
   197 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   232 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   198 				} else {
   233 				} else {
   199 					print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>";
   234 //header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . dirname($db_fieldcache["req_ID"]));
       
   235 //strip_tags($text, '<p><a>')
       
   236                                       print "<span class='result_output'><a href='". 'staging/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val']) ."' target='_blank'>View website</a></span>";
       
   237 //					print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>";
   200 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   238 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   201 				}
   239 				}
   202                 print "<div class='clear'></div></div>";
   240                 print "<div class='clear'></div></div>";
   203 				
   241 				
   204 				$search_count++;
   242 				$search_count++;