details.php
changeset 15 3ad193634e5d
parent 13 bfe0d3de2764
child 18 08b0c7b21035
equal deleted inserted replaced
14:e2ac834162fb 15:3ad193634e5d
     1 <?php 
     1 <?php 
     2 	function remove_http($url = '')
     2 function remove_http($url = '')
     3 	{
     3 {
     4 		if ($url == 'http://' OR $url == 'https://')
     4 	if ($url == 'http://' OR $url == 'https://')
     5 		{
     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;
     6 		return $url;
    20 	}
     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 
    21 
    22 	// 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)
       
    23         $currSID1 = $_COOKIE['sid1'];
       
    24 	$sid1 = $currSID1;
       
    25                 if (!isset($_COOKIE['sid1']))
       
    26                         {
       
    27                         $sid1 = '06D5VlLQTbM57LL7IBMW38yHkFpb1XVa';
       
    28                         $currSID1 = $sid1;
       
    29                         }
       
    30 
    23 	$currID = $_COOKIE['uid'];
    31 	$currID = $_COOKIE['uid'];
    24 	
    32 	$uid = $currID;
    25 	if ($currID == "") 
    33                 if (!isset($_COOKIE['uid']))
       
    34                         {
       
    35                         $uid = '1';
       
    36 			$currID = '1';
       
    37 	                $mysql = new mysqli("localhost", "www-data", "www-data", "members");
       
    38  #              $result = $mysql->query("SELECT sid, sid_dir FROM sessions WHERE ((uid = '$currID' or uid = 1) AND (expiration_date = DATE_ADD(NOW(), INTERVAL 24 HOUR)))");
       
    39 			$result = $mysql->query("SELECT sid_dir, enum FROM sessions WHERE ((uid = '$currID' or uid = 1) AND (sid = '$sid1') AND (expiration_date = DATE_ADD(NOW(), INTERVAL 1440 MINUTE)))");
       
    40                 	$row = $result->fetch_assoc();
       
    41                 	$tsid2 = $row["sid_dir"];
       
    42 			$enum = $row["enum"];
       
    43                 	$result->close();
       
    44 
       
    45                         }
       
    46 
       
    47 /*        if ($currID == "")
       
    48         {
       
    49                 $currID = "1";
       
    50 echo $currID;
       
    51 	}	
       
    52 */
       
    53 /*	if ($currID == "") 
    26 	{
    54 	{
    27 		$currID = 1;
    55 		$currID = 1;
    28 	}
    56 		$mysql = new mysqli("localhost", "www-data", "www-data", "members");
    29  	// read session IDs from cookie, if cookie doesn't exist, set to 1 (master)
    57  #       	$result = $mysql->query("SELECT sid, sid_dir FROM sessions WHERE ((uid = '$currID' or uid = 1) AND (expiration_date = DATE_ADD(NOW(), INTERVAL 24 HOUR)))");
       
    58 $result = $mysql->query("SELECT sid, sid_dir FROM sessions WHERE ((uid = '$currID' or uid = 1) AND (expiration_date = DATE_ADD(NOW(), INTERVAL 24 HOUR)))");
       
    59         	$row = $result->fetch_assoc();
       
    60         	$tsid1 = $row["sid"];
       
    61 		$tsid2 = $row["sid_dir"];
       
    62         	$result->close();
       
    63 
       
    64 
       
    65 	}
       
    66 */
       
    67  	// read session IDs from cookie, if cookie doesn't exist, set to 06D5VlLQTbM57LL7IBMW38yHkFpb1XVa (master)
       
    68 
       
    69 
    30 
    70 
    31 //echo $_COOKIE["sid1"];
    71 //echo $_COOKIE["sid1"];
    32         $currSID1 = $_COOKIE['sid1'];
    72         $currSID2 = $_COOKIE['sid2'];
       
    73 	$sid2 = $currSID2;
       
    74                 if (!isset($_COOKIE['sid2']))
       
    75                         {
       
    76 			$sid2 = $tsid2;
       
    77 //                        $sid2 = '06D5VlLQTbM57LL7IBMW38yHkFpb1XVa';
       
    78 			$currSID2 = $sid2;
       
    79                         }
       
    80 echo $uid;
       
    81 echo $sid1;
       
    82 echo $sid2;
       
    83 echo $enum;
       
    84 /*
    33 	if ($currSID1 == "")
    85 	if ($currSID1 == "")
    34         {
    86         {
    35                 $currSID1 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
    87                 $currSID1 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
       
    88 //		$currSID1 = $tsid1;
       
    89 
       
    90 echo $currSID1;
       
    91 
    36         }
    92         }
    37 
    93 
    38         $currSID2 = $_COOKIE['sid2'];
    94         $currSID2 = $_COOKIE['sid2'];
    39 	if ($currSID2 == "")
    95 	if ($currSID2 == "")
    40         {
    96         {
    41                 $currSID2 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
    97                 $currSID2 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
       
    98 //		$currSID2 = $tsid2;
       
    99 echo $currSID2;
    42         }
   100         }
    43 
   101 */
    44 //print_r($_COOKIE);
   102 print_r($_COOKIE);
    45 	
   103 	
    46 	$status = $_GET['alert'];
   104 	$status = $_GET['alert'];
    47 	$view_mode = $_GET['view_mode'];
   105 	$view_mode = $_GET['view_mode'];
    48 	$view_order = $_GET['view_order'];
   106 	$view_order = $_GET['view_order'];
    49 	
   107 	
    52 	$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
   110 	$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
    53 	mysql_select_db('members');
   111 	mysql_select_db('members');
    54 	
   112 	
    55 	// search server cache for received websites
   113 	// search server cache for received websites
    56 	// anonymous uid=1, sid1=06D5VlLQTbM57LL7IBMW38yHkFpb1XVa & sid2 =06D5VlLQTbM57LL7IBMW38yHkFpb1XVa
   114 	// anonymous uid=1, sid1=06D5VlLQTbM57LL7IBMW38yHkFpb1XVa & sid2 =06D5VlLQTbM57LL7IBMW38yHkFpb1XVa
    57 	if (($currID != 1) && ($currSID1 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa"))
   115 //	if (($currID != 1) && ($currSID1 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa"))
       
   116         if ($currID != 1) 
       
   117 
    58 	{
   118 	{
    59 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
   119 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
    60 	} 
   120 	} 
    61 	else 
   121 	else 
    62 	{
   122 	{
    63 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = 1)");
   123 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = 1)");
       
   124                         while ($db_fieldcache = mysql_fetch_assoc($query_cache))
       
   125                         {
       
   126                         // send command to squid and return value
       
   127     #                    $command2 = "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";
       
   128 #                    $command2 = "squidclient -m HEAD -p 8080" . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
       
   129 //                    $command2 = "squidclient -m HEAD -p 8080 -u {$db_fieldcache["req_ID"]} -w $currSID1 http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/ |grep X-Cache: |grep MISS";
       
   130 		    $curr_reqID = $db_fieldcache["req_ID"];
       
   131 #                    $http_proxy = "http://localhost:8080";
       
   132 #                    $staging = "/var/www/private/HTMLrequester/staging/";
       
   133 #                    $wget_options = " --delete-after -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d";
       
   134 #                    $strip_url_val = remove_http($db_fieldcache['req_val']);
       
   135 #                                        $command1 = "wget -P $staging $wget_options http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/ . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2";
       
   136 #                    exec($command1, $wget_results);
       
   137 
       
   138 $http_proxy = "http://localhost:8080";
       
   139                     $command2 = "squidclient -m HEAD -p 8080 -u www-data -w www-data http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/?uid=$uid'&'sid1=$sid1'&'sid2=$sid2 |grep X-Cache: |grep MISS";
       
   140                         exec($command2, $cache_results);
       
   141                         // find out if site is available and update the database
       
   142                                 if (strpos($cache_results, "HIT") == true)
       
   143                                         {
       
   144                                         $query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
       
   145                                         }
       
   146                                         else
       
   147                                         {
       
   148                 			$filename = "/var/www/private/HTMLrequester/router_stage/{$db_fieldcache["req_ID"]}/";
       
   149               				if (file_exists($filename))
       
   150                         		{
       
   151                                         $query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
       
   152                                        # $http_proxy = "http://localhost:8080";
       
   153 				#	$http_proxy = "http://localhost:8080";
       
   154                                         $staging = "/var/www/private/HTMLrequester/staging/";
       
   155                                        # $wget_options = "--dns-timeout=1 --proxy-user=www-data --proxy-password=www-data --cache=off -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d -I  http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/ -X   http://localhost/router_stage/{$db_fieldcache["req_ID"]}/";
       
   156                                         #$wget_options = "--dns-timeout=1 --proxy-user=www-data --proxy-password=www-data -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d -I  http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/ -X   http://localhost/router_stage/{$db_fieldcache["req_ID"]}/";
       
   157 					#$wget_options = "--no-cache --dns-timeout=1 --proxy-user=www-data --proxy-password=www-data -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d -I  http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/ -X   http://localhost/router_stage/{$db_fieldcache["req_ID"]}/ http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/";
       
   158                                         $wget_options = "--dns-timeout=1 --proxy-user=www-data --proxy-password=www-data -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d";
       
   159 
       
   160 
       
   161 
       
   162                                         $strip_url_val = remove_http($db_fieldcache['req_val']);
       
   163                                        # $command1 = "wget -P $staging $wget_options http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/?uid=$uid'&'sid1=$sid1'&'sid2=$sid2";
       
   164                                        # exec($command1, $wget_results);
       
   165 					
       
   166                                         $command1 = "wget -P $staging $wget_options http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/?uid=$uid'&'sid1=$sid1'&'sid2=$sid2";
       
   167                                        exec($command1, $wget_results);
       
   168 					}
       
   169 					else
       
   170 					{		
       
   171                                         $query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
       
   172 					}
       
   173                                         }
       
   174 
       
   175 			}
    64 	}
   176 	}
    65 	
   177 	
    66 	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
   178 	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
    67 	{
   179 	{
    68 		// send command to squid and return value
       
    69 		$curr_reqID = $db_fieldcache["req_ID"];
   180 		$curr_reqID = $db_fieldcache["req_ID"];
    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"];
       
    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/router_stage/{$db_fieldcache["req_ID"]}/";
   181 		$filename = "/var/www/private/HTMLrequester/router_stage/{$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);
       
    81 		
       
    82 		// find out if site is available and update the database
       
    83 //		if (strpos($cache_results, "HIT") == true)
       
    84 //		{
       
    85 //			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
       
    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)) 
   182 		if (file_exists($filename)) 
    92     			{
   183     			{
    93     			$query_update = mysql_query("UPDATE requests_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
   184     			$query_update = mysql_query("UPDATE requests_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
    94     			} 
   185     			} 
    95 		else 
   186 		else 
   231 					print "<span class='result_output_none'>Result pending</span>";
   322 					print "<span class='result_output_none'>Result pending</span>";
   232 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   323 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   233 				} else {
   324 				} else {
   234 //header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . dirname($db_fieldcache["req_ID"]));
   325 //header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . dirname($db_fieldcache["req_ID"]));
   235 //strip_tags($text, '<p><a>')
   326 //strip_tags($text, '<p><a>')
   236                                       print "<span class='result_output'><a href='". 'router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val']) ."' target='_blank'>View website</a></span>";
   327 if ($db_field['uid'] != 1)
       
   328 {
       
   329                 print "<span class='result_output'><a href='". 'router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2) ."' target='_blank'>View website</a></span>";
       
   330 }
       
   331 else
       
   332 {
       
   333 
       
   334 #$data = http_get('http://...')
       
   335 #$response = http_get("'http://localhost:8080'. '/router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2");
       
   336 print "<span class='result_output'><a href='". 'http://localhost'. '/router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2) ."' target='_blank'>View website</a></span>";
       
   337 #print "<span class='result_output'><a href='". 'http://localhost:8080'. '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2) ."' target='_blank'>View website</a></span>";
       
   338 
       
   339 #print "<span class='result_output'><a href='". $response ."' target='_blank'>View website</a></span>";
       
   340 
       
   341 }
       
   342 
       
   343                         //                print "<span class='result_output'><a href='". 'router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2) ."' target='_blank'>View website</a></span>";
       
   344 
       
   345 /////////////////////////////////////////////////////////////
       
   346 ////Uncomment this next section for Cookie in header if uid != 1  
       
   347 /*					if ($uid == 1) {
       
   348                                       	print "<span class='result_output'><a href='". 'router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2) ."' target='_blank'>View website</a></span>";
       
   349 					}
       
   350 					else
       
   351 					{
       
   352 					print "<span class='result_output'><a href='". 'router_stage/' . $db_field['req_ID'] . '/' . remove_http($db_field['req_val']) . "' target='_blank'>View website</a></span>";
       
   353 					}
       
   354 */
       
   355 //////////////////////////////////////////////////////////////
   237 //					print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>";
   356 //					print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>";
   238 					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   357 #					print "<a href='delete.php?req_id=" . $db_field['req_ID'] . '/' . remove_http($db_field['req_val'] . '?' . 'uid=' . $uid . '&'  . 'sid1=' . $sid1 . '&' . 'sid2=' . $sid2 . "'><img src='images/x.gif' width='14' height='20' /></a>";
   239 				}
   358                                        print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>";
   240                 print "<div class='clear'></div></div>";
   359 
   241 				
   360 					}
       
   361                 		print "<div class='clear'></div></div>";
   242 				$search_count++;
   362 				$search_count++;
   243             }
   363             }
   244             
   364             
   245             // if no requests, display message
   365             // if no requests, display message
   246             if (mysql_num_rows($query) < 1) 
   366             if (mysql_num_rows($query) < 1) 
   247             {
   367             {
   248                 print '<p>You have no previous searches please use the search form to create a new search.</p>';
   368                 print '<p>You have no previous searches please use the search form to create a new search.</p>';
   249             }
   369             }
   250             
   370             
   251             mysql_close();
   371             mysql_close();
       
   372 /* To submit a form using POST method through PHP, just add the data to be posted as header. This essentially saves one extra html page sent to the browser when user has to be redirected. 
       
   373 <?php
       
   374 $host = "www.example.com";
       
   375 $path = "/path/to/script.php";
       
   376 $data = "data1=value1&data2=value2";
       
   377 $data = urlencode($data);
       
   378 
       
   379 header("POST $path HTTP/1.1\r\n" );
       
   380 header("Host: $host\r\n" );
       
   381 header("Content-type: application/x-www-form-urlencoded\r\n" );
       
   382 header("Content-length: " . strlen($data) . "\r\n" );
       
   383 header("Connection: close\r\n\r\n" );
       
   384 header($data);
       
   385 ?>
       
   386 */
   252         ?>
   387         ?>
   253     </div>
   388     </div>
   254 </div>
   389 </div>
   255 </body>
   390 </body>
   256 </html>
   391 </html>
       
   392