<?php
require_once("/home/pugbot/public_html/dbconfig.php");
require_once("/home/pugbot/public_html/pugbot-func.php");
function geolocation2($ip) {
$result = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
$geo_a = array ('state' => $result['geoplugin_regionName'], 'country' => $result['geoplugin_countryName'], 'country_code' => $result['geoplugin_countryCode'] );
return $geo_a;
}
/*
require_once ('/home/pugbot/ircpug/Predis/Autoloader.php');
Predis\Autoloader::register();
*/
function kick_irc($params) {
$target = $params ['target'];
$nick = $params ['nick'];
$network = $params ['network'];
add_message ( '', $nick, 'kick', $network );
return true;
}
function add_message($target, $message, $type, $network = '') {
$message = mysql_real_escape_string ( $message );
$target = mysql_real_escape_string ( $target );
mysql_query ( " INSERT INTO `outgoing_messages`(`message`,`type`,`network`,`target`) VALUES('\"$message\"','$type','$network','$target') " );
}
/*
function check_proxy_ban($ip) {
$redis = new Predis\Client();
$banned = $redis->get('proxy_'.$ip);
if ($banned == 1){
return true;
}
else return false;
}
*/
$PUGClass = new PUGClass();
// connect to db
$connection = mysql_connect($db['host'], $db['user'], $db['pass']) or die ("Unable to connect!");
mysql_select_db($db['db']) or die ("Unable to select database!");
$token = mysql_real_escape_string($_GET['session']);
$ip = $_SERVER['REMOTE_ADDR'];
if ($token == '') {
echo "<div class='warning_box'><h3>You have not provided a token</h3></div>";
return;
}
// check token
$ip_match_q = mysql_query(" SELECT * FROM `session` WHERE `token`='$token' ");
if (mysql_num_rows($ip_match_q) == 0) {
echo "<div class='warning_box'><h3>Invalid token provided</h3></div>";
} else {
// geolcation
$geolocation = geolocation2($ip);
$country = $geolocation['country'];
$country_code = $geolocation['country_code'];
$state = $geolocation['state'];
echo "<div class='download_box'><h3>Please read the rules!</h3>";
while($ip_match_a = mysql_fetch_array($ip_match_q)) {
// Check if it's a proxy
/*
if ( check_proxy_ban($ip) ){
// kick user
kick_irc(
array( 'target' => $ip_match_a['chan'],
'nick' => $ip_match_a['nick'],
'network' => $ip_match_a['network'] )
);
};
*/
$reg_pref = $PUGClass->get_region($ip_match_a['chan'], $country_code);
//echo "<h5>Region: $reg_pref Channel: ".$ip_match_a['chan']."</h5>";
mysql_query("UPDATE session SET `reg_pref`='$reg_pref',`country_code`='$country_code',`ip`='$ip',`ipkey`='$playeripkey',`country`='$country',`state`='$state' WHERE `token`='$token' AND `chan`='".$ip_match_a['chan']."'");
echo "<h3>Token activated for $ip, in channel: ".$ip_match_a['chan']."</h3>";
//echo "<h3>Region: $reg_pref</h3>";
}
echo "<h3>Please read the rules!</h3></div>";
}
?>