n4c_sid changed to sid and code integreated with apache mod_auth_form
authorAlex McMahon <alex.mcmahon@cs.tcd.ie>
Wed, 20 May 2009 15:46:51 +0100
changeset 4 2c829de4b83c
parent 3 ad69d332e9dc
child 5 e4238b7321b4
n4c_sid changed to sid and code integreated with apache mod_auth_form
add_search.php
delete.php
details.php
files/n4c_main.css
index.php
login.html
--- a/add_search.php	Tue May 19 18:41:47 2009 +0100
+++ b/add_search.php	Wed May 20 15:46:51 2009 +0100
@@ -51,7 +51,7 @@
 		$message = "#" . $currID . "#" . $reqID . "#" . $search_term;
 		
 		$host="localhost";
-		$port = 8080;
+		$port = 9090;
 		$timeout = 30;
 	
 		$sk=fsockopen($host,$port,$errnum,$errstr,$timeout);
--- a/details.php	Tue May 19 18:41:47 2009 +0100
+++ b/details.php	Wed May 20 15:46:51 2009 +0100
@@ -6,6 +6,25 @@
 	{
 		$currID = 1;
 	}
+ 	// read session IDs from cookie, if cookie doesn't exist, set to 1 (master)
+        $currSID1 = $_COOKIE['sid1'];
+	$currSID2 = $_COOKIE['sid2'];
+
+
+        if ($currID == "")
+        {
+                $currID = 1;
+        }
+	if ($currSID1 == "")
+        {
+                $currSID1 = 1;
+        }
+	if ($currSID2 == "")
+        {
+                $currSID2 = 1;
+        }
+
+
 	
 	$status = $_GET['alert'];
 	$view_mode = $_GET['view_mode'];
@@ -17,7 +36,7 @@
 	mysql_select_db('members');
 	
 	// search server cache for received websites
-	if ($currID != 1)
+	if (($currID != 1) && ($currSID1 != 1) && ($currSID2 != 1))
 	{
 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
 	} 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/files/n4c_main.css	Wed May 20 15:46:51 2009 +0100
@@ -0,0 +1,212 @@
+@charset "utf-8";
+/* CSS Document by Darren McCready for Intel 2009.*/
+
+* {
+	border:none;
+	margin:0;
+	padding:0;
+}
+
+body {
+	background:#fff;
+	color:#000;
+	font-family:Trebuchet MS, Geneva, Arial, Helvetica, sans-serif;
+	font-size:0.8em;
+	background:url(../images/bg.gif) top center repeat-y;
+}
+
+#container {
+	width:760px;
+	margin:0 auto;
+}
+
+#header {
+	display:block;
+	width:760px;
+	height:66px;
+	background:#3b495d;
+	color:#fff;
+	border-bottom:3px solid #fff;
+}
+
+#credits {
+	display:block;
+	width:140px;
+	float:right;
+	text-align:right;
+	padding:10px;
+	font-size:0.85em;
+}
+
+h1 {
+	float:left;
+	background:url(../images/logo.gif) center no-repeat;
+	width:205px;
+	height:66px;
+}
+
+h1 span {
+	display:none;
+}
+
+h2 {
+	font-size:1.2em;
+	padding:5px;
+	color:#fff;
+	font-weight:500;
+}
+
+#search h2 {
+	background:#77ACA1;
+}
+
+#results h2 {
+	background:#BB9F71;
+}
+
+#search {
+	float:left;
+	width:170px;
+	background:#D6E6E3;
+	padding:5px;
+}
+
+#results {
+	float:right;
+	width:570px;
+	background:#EEE7DB;
+	padding:5px;
+}
+
+.search_result {
+	display:block;
+	padding:10px;
+	border-bottom:1px solid #D4C3A6;
+}
+
+.search_result_private {
+	display:block;
+	padding:10px;
+	background:#ffc;
+	border-bottom:1px solid #D4C3A6;
+}
+
+.result_no {
+	display:block;
+	width:32px;
+	background:#fff;
+	border:1px solid #BB9F71;
+	float:left;
+	text-align:center;
+}
+
+.search_txt {
+	display:block;
+	width:60px;
+	float:left;
+	text-align:center;
+}
+
+.search_input {
+	display:block;
+	width:225px;
+	background:#fff;
+	border:1px solid #BB9F71;
+	float:left;
+	text-align:center;
+	margin:0 5px;
+	overflow:hidden;
+}
+
+.results_txt {
+	display:block;
+	width:55px;
+	float:left;
+	text-align:center;
+}
+
+.clear {
+	clear:both;
+}
+
+.result_output a {
+	display:block;
+	width:120px;
+	border:1px solid #005338;
+	background:#349E69;
+	color:#fff;
+	float:left;
+	text-align:center;
+	margin:0 5px;
+}
+
+.result_output a:hover {
+	text-decoration:none;
+	background:#4DC488;
+	border:1px solid #096;
+}
+
+.result_output_none {
+	display:block;
+	width:120px;
+	background:#c66;
+	border:1px solid #933;
+	color:#fff;
+	float:left;
+	text-align:center;
+	margin:0 5px;
+}
+
+form {
+	padding:9px 5px;
+}
+
+#search_button {
+	float:right;
+	margin-right:5px;
+}
+
+#delete_alert, #add_alert {
+	display:block;
+	width:740px;
+	padding:10px;
+	color:#fff;
+	text-align:center !important;
+}
+
+#delete_alert {
+	background:#c00;
+}
+
+#add_alert {
+	background:#090;
+}
+
+.img_right {
+	float:right;
+	display:block;
+}
+
+#delete_alert span, #add_alert span {
+	float:left;
+}
+
+#view_options {
+	display:block;
+	padding:5px;
+	background:#E4D9C6;
+}
+
+#view_options a,{
+	padding-right:10px;
+	color:#000;
+}
+
+#view_options span {
+	padding-right:10px;
+	color:#A6854F;
+}
+
+#view_options a:hover {
+	text-decoration:none;
+}
\ No newline at end of file
--- a/index.php	Tue May 19 18:41:47 2009 +0100
+++ b/index.php	Wed May 20 15:46:51 2009 +0100
@@ -24,6 +24,7 @@
 }
 function create_session($mysql, $uid, $password)
 {
+
         //
         // Build list of existing SIDs
         //
@@ -54,12 +55,22 @@
         // the MySQL session table.
         //
 
-$uid = (string)$uid;
+#$uid = (string)$uid;
         $mysql->query("INSERT INTO sessions (sid, sid_dir, uid, signature, timeout_date, expiration_date)
-                VALUES ('$sid1', '$sid2', '$uid', 'members', DATE_ADD(NOW(), INTERVAL 30 MINUTE),
-                DATE_ADD(NOW(), INTERVAL 8 HOUR))");
+                VALUES ('$sid1', '$sid2', '$uid', 'members', DATE_ADD(NOW(), INTERVAL 43200 MINUTE),
+                DATE_ADD(NOW(), INTERVAL 720 HOUR))");
         setcookie("sid1", $sid1, time() + 964224000);
         setcookie("sid2", $sid2, time() + 964224000);
+ 	if (!isset($_COOKIE['sid1']))
+                {
+                        $currSID1 = 1;
+                }
+	if (!isset($_COOKIE['sid2']))
+                {
+                        $currSID2 = 1;
+                }
+
+
 	#setcookie("uid", $uid, time() + 964224000);
     	exit();
 
@@ -92,34 +103,29 @@
 		if (!isset($_COOKIE['uid'])) 
 		{
 			$currID = 1;
+			$uid = $currID;
 		}
 	}
 	mysql_close();
 	// retrieve session cookie if it exists
 #	$real_password = password;
-$mysql = new mysqli("localhost", "www-data", "www-data", "members");
-/* check connection */
-#if (mysqli_connect_errno()) {
-#    printf("Connect failed: %s\n", mysqli_connect_error());
-#    exit();
-#}
-$result = $mysql->query("SELECT uid,password_md5 FROM creds WHERE username='$username'");
-$row = $result->fetch_assoc();
-$real_password = $row["password_md5"];
+	$mysql = new mysqli("localhost", "www-data", "www-data", "members");
+	$result = $mysql->query("SELECT uid,password_md5 FROM creds WHERE username='$username'");
+	$row = $result->fetch_assoc();
+	$real_password = $row["password_md5"];
+	if ((isset($_COOKIE['sid1'])) && (isset($_COOKIE['sid2'])))
+       		{
+                $sid1 = $_COOKIE['sid1'];
+		$sid2 = $_COOKIE['sid2'];
+		header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php');
+        	}
+        else
+        	{
 
-	#print $uid;
- 	#if ((isset($_COOKIE['sid1'])) && (isset($_COOKIE['sid2'])))
-        #{
-        #        $sid1 = $_COOKIE['sid1'];
-        #        $sid2 = $_COOKIE['sid2'];
-	#	print $sid1;
-	#	print $sid2;
-        #}
-
-	$mysql = new mysqli("localhost", "www-data", "www-data", "members");
-	create_session($mysql, $uid, $real_password);
-       	header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php');
-$result->close();
+		create_session($mysql, $uid, $real_password);
+       		header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php');
+		}
+	$result->close();
 
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/login.html	Wed May 20 15:46:51 2009 +0100
@@ -0,0 +1,9 @@
+<html>
+<head>
+N4C router
+</head>
+<body>
+	<form action="/index.php" method="post">
+	</form>
+</body>
+</html>