Skip to content

Commit

Permalink
added new search method, added phpbb auth method, fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas K committed Aug 26, 2011
1 parent e654b42 commit e554e94
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 122 deletions.
19 changes: 17 additions & 2 deletions web/auth.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

require_once("config.php");
require("config.php");
require_once("phpbb.php");
require("config.php"); //include config again, because phpbb overwrote $config

function authenticate($username=null,$password=null)
{
global $config;
global $user;

switch($config["auth_method"])
{
Expand Down Expand Up @@ -58,6 +60,19 @@ function authenticate($username=null,$password=null)
}
else die("you have set a non valid password hash method (db)");
break;
case "phpbb":
if(empty($config["phpbb"]["users"]) && empty($config["phpbb"]["groups"]))
die("do you really want to give access to nobody? (phpbb)");
else
{
if(in_array($user->data["username"],$config["phpbb"]["users"]))
return true;
if(in_array($user->data["group_id"],$config["phpbb"]["groups"]) || in_array($user->data["user_type"],$config["phpbb"]["groups"]))
return true;

return false;
}
break;
case "none":
return true;
break;
Expand Down
9 changes: 7 additions & 2 deletions web/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
- none (make it public)
- file (just save the username/password within $config["file"])
- db (authenticate via mysql)
- phpbb (authenticate using phpbb usernames/group ids)
--- */


// depening on which auth method you choose, you have to edit $config[your_auth_method]

$config["file"] = array("AI-team" => "test",
$config["file"] = array("test" => "test",
"password_hash_method" => "none" //this has to be either "none" or "md5"
);
// you can add more users by adding another entry to the array
Expand All @@ -27,6 +28,10 @@
"user_row" => "user",
"password_row" => "password",
"password_hash_method" => "none" // this has to be either "none" or "md5"
);
);

$config["phpbb"] = array("path" => "/path/to/your/forum/"); // must end with a slash
$config["phpbb"]["users"] = array(); // just the you can add users by adding entrys to the array
$config["phpbb"]["groups"] = array() // i.e. group id 3 means all administrators can access the ip-lookup

?>
180 changes: 69 additions & 111 deletions web/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function ip_form()
<input type='text' name='ip' /><br />
Player:<br />
<input type='text' name='player' /><br />
<input type='submit' onclick='alert('This might take some time.\nPlease be patient!') />
<input type='submit' onClick=\"alert('This might take some time.\\nPlease be patient!')\"/>
</form></div>";
}

Expand All @@ -51,138 +51,96 @@ function validate_ip($ip)
return false;
}

function search($ip=null,$player=null)
function search($ip=null,$player=null)
{
global $config;
global $display_names;
global $gids;
$last_ips = array();
global $config, $display_names,$gids;
$ips = array();

if(!$ip && !$player)
return false;

if(!$player && isset($ip))
$condition = "(strpos($line,$ip) !== false)";
elseif(isset($player) && !$ip)
$condition = "(strpos($line,$player) !== false)";
elseif(isset($player) && isset($ip))
$condition = "(strpos($line,$ip) !== false && strpos($line,$player) !== false)";

foreach(file($config["ip_log"]) as $line)
{
// search for IP only
foreach(file($config["ip_log"]) as $line)
eval("\$ok = \"$condition)\";");
if($ok)
{
if(strpos($line,$ip) !== false)
$line = explode(" ",$line);

if(count($line) == 3)
{
$line = explode(" ",$line);

if(count($line) == 3)
{
// PLAYER_ENTERED
if(!in_array($line[2],$display_names))
array_push($display_names,$line[2]);
}
elseif(count($line) == 5)
{
// PLAYER_RENAMED
if(strpos($line[1],"@") !== false && !in_array($line[1],$gids))
array_push($gids,$line[1]);
if(!in_array($line[4],$display_names))
array_push($display_names,$line[4]);
}
$match = true;
}
}
}

if(!$ip && isset($player))
{
// search for player name only
foreach(file($config["ip_log"]) as $line)
{
if(strpos($line,$player) !== false)
// PLAYER_ENTERED
if(!in_array($line[2],$display_names))
array_push($display_names,$line[2]);

if(!in_array($line[1],$ips))
array_push($ips,$line[1]);
}
elseif(count($line) == 5 && ($line[3] == "1" || $line[3] == "0"))
{
$line = explode(" ",$line);

if(count($line) == 3)
{
// PLAYER_ENTERED
if(!in_array($line[2],$display_names))
array_push($display_names,$line[2]);

array_push($last_ips,$line[1]); // remember the last known IP for later use

}
elseif(count($line) == 5)
// PLAYER_RENAMED
if(strpos($line[1],"@") !== false && !in_array($line[1],$gids))
array_push($gids,$line[1]);
if(!in_array($line[4],$display_names))
array_push($display_names,$line[4]);

if(!in_array($line[2],$ips))
array_push($ips,$line[2]);
}
else
{
// Player's name has spaces in it
if(strpos($line[3],"1") !== false || strpos($line[3],"0") !== false)
{
// PLAYER_RENAMED
if(strpos($line[1],"@") !== false && !in_array($line[1],$gids))
array_push($gids,$line[1]);
if(!in_array($line[4],$display_names))
array_push($display_names,$line[4]);

array_push($last_ips,$line[2]); // remember the last known IP for later use
}
$match = true;
}
}

if(empty($last_ips))
return false;
if(!in_array($line[2],$ips))
array_push($ips,$line[2]);

$name = "";
foreach((array_slice($line,4)) as $part)
{
$name .= "$part ";
}
if(!in_array(trim($name),$display_names))
array_push($display_names,trim($name));

// search for entries matching the player's IP
foreach(file($config["ip_log"]) as $line)
{
if(array_walk($last_ips,create_function('$ip' , 'return (strpos($line,$ip) !== false)?true:false;')))
{
$line = explode(" ",$line);

if(count($line) == 3)
{
// PLAYER_ENTERED
if(!in_array($line[2],$display_names))
array_push($display_names,$line[2]);
}
elseif(count($line) == 5)
else
{
// PLAYER_RENAMED
if(strpos($line[1],"@") !== false && !in_array($line[1],$gids))
array_push($gids,$line[1]);
if(!in_array($line[4],$display_names))
array_push($display_names,$line[4]);
// PLAYER_ENTERED
if(!in_array($line[1],$ips))
array_push($ips,$line[1]);

$name = "";
foreach((array_slice($line,2)) as $part)
{
$name .= "$part ";
}
if(!in_array(trim($name),$display_names))
array_push($display_names,trim($name));

}
$match = true;
}
}

}
$match = true;
}
}

if(isset($player) && isset($ip))
if(isset($player) && !$ip)
{
// search for entries matching both, the IP and the player's name
foreach(file($config["ip_log"]) as $line)
{
if(strpos($line,$ip) !== false && strpos($line,$player) !== false)
{
$line = explode(" ",$line);

if(count($line) == 3)
{
// PLAYER_ENTERED
if(!in_array($line[2],$display_names))
array_push($display_names,$line[2]);
}
elseif(count($line) == 5)
{
// PLAYER_RENAMED
if(strpos($line[1],"@") !== false && !in_array($line[1],$gids))
array_push($gids,$line[1]);
if(!in_array($line[4],$display_names))
array_push($display_names,$line[4]);
}
$match = true;
}
}
}

foreach($ips as $ip)
search($ip,null);
}

if($match != true)
return false;
else
return true;
return true;
}


Expand Down
17 changes: 10 additions & 7 deletions web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
if(isset($_SESSION["logged_in"]) && $_SESSION["logged_in"] == true)
{
$result = true;
}
elseif($config["auth_method"] == "phpbb") {
// --- PHPBB Workaround ---
$result = authenticate();
if(!$result)
{
print_error_message("Access denied!");
html_footer();
}
} elseif($config["auth_method"] == "none") {
$result = true;
} elseif((!$username || !$password)) {
Expand Down Expand Up @@ -78,12 +87,6 @@
}

format_output($display_names,$gids);
html_footer();






html_footer();

?>
12 changes: 12 additions & 0 deletions web/phpbb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
define('IN_PHPBB', TRUE);
$phpbb_root_path = $config["phpbb"]["path"];
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// Include needed files
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Initialize phpBB user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>

0 comments on commit e554e94

Please sign in to comment.