details.php_lessold
changeset 21 0bd6e7537154
parent 20 b7f8324faded
child 22 52aaf1a838bd
--- a/details.php_lessold	Wed Jun 16 13:28:45 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,278 +0,0 @@
-<?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'];
-	
-	if ($currID == "") 
-	{
-		$currID = 1;
-		$mysql = new mysqli("localhost", "www-data", "www-data", "members");
-        	$result = $mysql->query("SELECT sid, sid_dir FROM sessions WHERE ((uid = '$currID' or uid = 1) AND (expiration_date = DATE_ADD(NOW(), INTERVAL 24 HOUR)))");
-        	$row = $result->fetch_assoc();
-        	$tsid1 = $row["sid"];
-		$tsid2 = $row["sid_dir"];
-        	$result->close();
-
-
-	}
- 	// read session IDs from cookie, if cookie doesn't exist, set to 06D5VlLQTbM57LL7IBMW38yHkFpb1XVa (master)
-
-
-
-//echo $_COOKIE["sid1"];
-        $currSID1 = $_COOKIE['sid1'];
-	if ($currSID1 == "")
-        {
-       //         $currSID1 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
-		$currSID1 = $tsid1;
-echo $currSID1;
-
-        }
-
-        $currSID2 = $_COOKIE['sid2'];
-	if ($currSID2 == "")
-        {
-//                $currSID2 = "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa";
-		$currSID2 = $tsid2;
-echo $currSID2;
-        }
-
-print_r($_COOKIE);
-	
-	$status = $_GET['alert'];
-	$view_mode = $_GET['view_mode'];
-	$view_order = $_GET['view_order'];
-	
-	
-	// connect to the database
-	$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
-	mysql_select_db('members');
-	
-	// search server cache for received websites
-	// anonymous uid=1, sid1=06D5VlLQTbM57LL7IBMW38yHkFpb1XVa & sid2 =06D5VlLQTbM57LL7IBMW38yHkFpb1XVa
-//	if (($currID != 1) && ($currSID1 != "06D5VlLQTbM57LL7IBMW38yHkFpb1XVa"))
-        if ($currID != 1) 
-
-	{
-		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
-	} 
-	else 
-	{
-		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = 1)");
-                        while ($db_fieldcache = mysql_fetch_assoc($query_cache))
-                        {
-                        // send command to squid and return value
-    #                    $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";
-#                    $command2 = "squidclient -m HEAD -p 8080" . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
-//                    $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";
-                    $command2 = "squidclient -m HEAD -p 8080 -u www-data -w www-data http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/ |grep X-Cache: |grep MISS";
-                        exec($command2, $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'");
-                                        }
-/*                                        else
-                                        {
-                                        $query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
-                                        $curr_reqID = $db_fieldcache["req_ID"];
-                                        $http_proxy = "http://localhost:8080";
-                                        $staging = "/var/www/private/HTMLrequester/staging/";
-                                        $wget_options = "--delete-after -N -r -l 3 --no-remove-listing -p --max-redirect 10 -t 1 -d";
-                                        $strip_url_val = remove_http($db_fieldcache['req_val']);
-                                        $command1 = "wget -P $staging $wget_options http://localhost/router_stage/{$db_fieldcache["req_ID"]}/$strip_url_val/";
-                                        exec($command1, $wget_results);
-
-                                        }
-*/
-			}
-	}
-	
-	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
-	{
-		$filename = "/var/www/private/HTMLrequester/router_stage/{$db_fieldcache["req_ID"]}/";
-		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 requests_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'");
-			}  
-	}
-	
-	
-	// pick order to show (user specified)
-	
-	if ($view_order == "pend")
-	{
-		$order_sql = "req_response ASC";
-	}
-	else if ($view_order == "date_asc")
-	{
-		$order_sql = "req_created ASC";
-	}
-	else if ($view_order == "avail")
-	{
-		$order_sql = "req_response DESC";
-	}
-	else
-	{
-		$order_sql = "req_created DESC";
-	} 
-	
-	// pick relervant mySQl QUERY
-	if ($view_mode == "public")
-	{
-		$query = mysql_query("SELECT * FROM requests_tbl WHERE (uid = 1) ORDER BY " . $order_sql);
-	}
-	else if ($view_mode == "all")
-	{
-		$query = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1) ORDER BY " . $order_sql);
-	}
-	else 
-	{
-		$query = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID') ORDER BY " . $order_sql);
-	}
-	
-	
-	// Construct search information message
-	if ($view_mode == "public") 
-	{
-		$search_info = "There are " . mysql_num_rows($query) . " saved public searches.";
-	} else if ($view_mode == "private") {
-		$search_info = "You have " . mysql_num_rows($query) . " saved private searches.";
-	} else {
-		$search_info = "There are " . mysql_num_rows($query) . " saved searches.";
-	}
-?>
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>N4C - Welcome. <?php print $search_info; ?></title>
-<link href="files/n4c_main.css" rel="stylesheet" type="text/css" media="screen" />
-</head>
-
-<body>
-<div id="container">
-    <div id="header">
-        <h1><span>N4C</span></h1>
-    	<p id="credits">HTML Requester v. 1.00</p>
-    </div>
-    <?php 
-		// show status messages based on user interaction
-		if ($status == "del") 
-		{
-			print "<div id='delete_alert'><span>You have successfully deleted the selected search.</span><a href='details.php'><img class='img_right' src='images/x.gif' width='14' height='20' /></a><div class='clear'></div></div>";
-		} else if ($status == "add")
-		{
-			print "<div id='add_alert'><span>You have successfully added a new search.</span><a href='details.php'><img class='img_right' src='images/x.gif' width='14' height='20' /></a><div class='clear'></div></div>";
-		} else if ($status == "urlerror") 
-		{
-			print "<div id='delete_alert'><span>You have entered an malformed url. Please use this format: <em><strong>http://www.yourwebsite.com</strong></em></span><a href='details.php'><img class='img_right' src='images/x.gif' width='14' height='20' /></a><div class='clear'></div></div>";
-		}
-	?>
-    <div id="search">
-   	  <h2>Open a new search:</h2>
-        <form action="add_search.php" method="get" enctype="multipart/form-data" name="search" target="_parent">
-        <input name="search_term" type="text" value="http://www.yourwebsite.com" size="21" />
-        <?php
-			// 
-		  	if ($currID != 1)
-			{
-				print "<select name='search_type' size='1'>";
-          		print "<option value='public' selected>Public</option>";
-            	print "<option value='private'>Private</option></select>";	
-			}
-		  ?>
-          <input id="search_button" name="submit" type="submit" value="Search" />
-        </form>
-    </div>
-    <div id="results">
-    	<h2><?php print $search_info; ?></h2>
-		<?php
-            // customise view links based on view
-            
-			print "<div id='view_options'><form action='details.php' method='get' enctype='multipart/form-data' name='search' target='_parent'>";
-			
-			if ($currID != 1)
-            {
-                print "<select name='view_mode' size='1'>";
-                print "<option value='private' selected>Private searches</option>";
-                print "<option value='public'>Public searches</option>";
-                print "<option value='all'>All searches</option></select> ";
-            }
-			
-			print "<select name='view_order' size='1'>";
-            print "<option value='date_desc' selected>Newest &gt; Oldest</option>";
-            print "<option value='date_asc'>Oldest &gt; Newest</option>";
-            print "<option value='avail'>Available &gt; Pending</option> ";
-			print "<option value='pend'>Pending &gt; Available</option></select> ";
-            print "<input name='submit' type='submit' value='Update view' /></form></div>";
-        ?>
-		<?php
-            //display current search requests
-            $search_count = 1;
-			
-			while ($db_field = mysql_fetch_assoc($query)) 
-			{		 
-				if ($db_field['uid'] != 1 and $view_mode == "all")
-				{
-					print "<div class='search_result_private'><span class='result_no'>" . $search_count . "</span> ";
-					print "<span class='search_txt'>Search:</span><span class='search_input'><em>" . $db_field['req_val'] . "</em></span> ";
-				} else {
-					print "<div class='search_result'><span class='result_no'>" . $search_count . "</span> ";
-					print "<span class='search_txt'>Search:</span><span class='search_input'><em>" . $db_field['req_val'] . "</em></span> ";
-				}
-				
-  				print "<span class='results_txt'>Status:</span>";
-				
-				if ($db_field['req_response'] == 0)
-				{
-					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 {
-//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='". 'router_stage/' . $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>";
-				
-				$search_count++;
-            }
-            
-            // if no requests, display message
-            if (mysql_num_rows($query) < 1) 
-            {
-                print '<p>You have no previous searches please use the search form to create a new search.</p>';
-            }
-            
-            mysql_close();
-        ?>
-    </div>
-</div>
-</body>
-</html>