--- a/add_search.php Wed May 20 13:20:27 2009 +0100
+++ b/add_search.php Wed May 20 17:33:42 2009 +0100
@@ -6,7 +6,7 @@
}
// get user ID from cookie
- $currID = $_COOKIE['n4c_ID'];
+ $currID = $_COOKIE['uid'];
if ($currID == "")
{
@@ -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 Wed May 20 13:20:27 2009 +0100
+++ b/details.php Wed May 20 17:33:42 2009 +0100
@@ -1,11 +1,30 @@
<?php
// read user ID from cookie, if cookie doesn't exist, set to 1 (master)
- $currID = $_COOKIE['n4c_ID'];
+ $currID = $_COOKIE['uid'];
if ($currID == "")
{
$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 17:33:42 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/index.html Wed May 20 17:33:42 2009 +0100
@@ -0,0 +1,1 @@
+<html><body><h1>It works!</h1></body></html>
--- a/index.php Wed May 20 13:20:27 2009 +0100
+++ b/index.php Wed May 20 17:33:42 2009 +0100
@@ -1,34 +1,132 @@
<?php
+function genID($seed, $length)
+{
+ $ID = "";
+ srand($seed);
+ for($i = 0; $i < $length; $i++)
+ {
+ $chtype = rand(1, 3);
+ switch($chtype)
+ {
+ case 1: // 0-9
+ $ID .= chr(rand(48, 57));
+ break;
+ case 2: // A-Z
+ $ID .= chr(rand(65, 90));
+ break;
+ case 3: // a-z
+ $ID .= chr(rand(97, 122));
+ break;
+ }
+ }
+ return $ID;
+
+}
+function create_session($mysql, $uid, $password)
+{
+
+ //
+ // Build list of existing SIDs
+ //
+ $result = $mysql->query("SELECT sid FROM sessions");
+ $num_rows = $result->num_rows;
+ while($num_rows > 0)
+ {
+ $row = $result->fetch_assoc();
+ $sids[$row["sid"]] = TRUE;
+ $num_rows--;
+ }
+ $result->close();
+ //
+ // Generate main SID (making sure it is unique)
+ //
+ $max_attempts = 500000;
+ $seed = crc32($password);
+ do
+ {
+ $sid1 = genID($seed + time(), 32);
+ $max_attempts--;
+ } while(isset($sids[$sid1]) && $max_attempts > 0);
+ if($max_attempts <= 0) // NOT GOOD
+ return FALSE;
+ $sid2 = genID(crc32($sid1) + time(), 32);
+ //
+ // Create the session: set the UID and SID in both the client's cookies and
+ // the MySQL session table.
+ //
+
+#$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 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();
+
+ return TRUE;
+}
+
+
$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
mysql_select_db('members');
// retrieve cookie if it exists
- if (isset($_COOKIE['n4c_ID']))
+ if (isset($_COOKIE['uid']))
{
- $currID = $_COOKIE['n4c_ID'];
+ $currID = $_COOKIE['uid'];
+ $uid = $currID;
}
else
{
// SQL queries
$result = mysql_query("INSERT INTO creds (uid) VALUES ('')");
- $user_id = mysql_query("SELECT MAX(uid) as id FROM creds");
+ $uid = mysql_query("SELECT MAX(uid) as id FROM creds");
$expiry = time() + (3600 * 24 * 30 * 12);
//create cookies
- while ($db_field2 = mysql_fetch_assoc($user_id)) {
- setcookie('n4c_ID', $db_field2['id'] , $expiry, '/', '', 0);
+ while ($db_field2 = mysql_fetch_assoc($uid)) {
+ setcookie('uid', $db_field2['id'] , $expiry, '/', '', 0);
}
- if (!isset($_COOKIE['n4c_ID']))
+ if (!isset($_COOKIE['uid']))
{
$currID = 1;
+ $uid = $currID;
}
}
-
mysql_close();
-
- header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/details.php');
+ // retrieve session cookie if it exists
+# $real_password = password;
+ $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
+ {
+
+ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/login.html Wed May 20 17:33:42 2009 +0100
@@ -0,0 +1,9 @@
+<html>
+<head>
+N4C router
+</head>
+<body>
+ <form action="/index.php" method="post">
+ </form>
+</body>
+</html>