<?php
require_once"./includes/functions/gzip.php";
list($msec, $sec) = explode(chr(32), microtime());
$headtime = $sec + $msec;
$configs = file("configs.dat");
$reg_status = $configs[0];
$computer = $configs[2];
$img = $configs[3];
if(isset($_POST['action']))
{
session_id("".$_POST['sid']."");
session_start();
}
else
{
session_start();
$number = rand(1000, 9999);
$_SESSION['code'] = $number;
}
error_reporting(0);
include("config.php");
include("./includes/constants/registration");
include("./includes/".$ver."/banned");
$nocache = rand(1000, 9999);
$mobile = strtok(getenv('HTTP_USER_AGENT'), "/");
$ip = getenv('REMOTE_ADDR');
$ua = mysql_escape_string(htmlspecialchars(getenv('HTTP_USER_AGENT')));
switch($ver)
{
case 'wml':
///////////////////////////////////////////////////////
//WML VERSION
///////////////////////////////////////////////////////
header("Content-type: text/vnd.wap.wml; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"><wml>\n";
if($reg_status == 0)
{
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
echo "<card id=\"error\" title=\"Error\"><p align=\"left\">\n";
echo "<small>Registration is temporarily closed.</small><br/>\n";
list($msec, $sec) = explode(chr(32), microtime());
echo "<small>[".round(($sec + $msec) - $headtime, 5)."]</small><br/>\n";
require_once "includes/functions/gzip_foot.php";
echo "</p></card></wml>";
ob_end_flush();
exit();
}
if(((strpos($ua, "Opera") !== false) or (strpos($ua, "Mozilla") !== false) or (strpos($ua, "MSIE") !== false) or (strpos($ua, "Netscape") !== false)) && $computer == 1)
{
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
echo "<card id=\"error\" title=\"Error\"><p align=\"left\">\n";
echo "<small>Registration with the computer is prohibited.</small><br/>\n";
list($msec, $sec) = explode(chr(32), microtime());
echo "<small>[".round(($sec + $msec) - $headtime, 5)."]</small><br/>\n";
echo "</p></card></wml>";
exit();
}
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
echo "<card id=\"registration\" title=\"".TITLE."\"><p align=\"left\">\n";
echo "<!-- Registration -->\n";
if(!isset($_POST['action']))
{
echo "Nickname*:<br/>\n";
echo "<input type=\"text\" name=\"nickname\" maxlength=\"15\"/><br/>\n";
echo "Password*:<br/>\n";
echo "<input type=\"text\" name=\"password\" maxlength=\"20\"/><br/>\n";
echo "Name:<br/>\n";
echo "<input type=\"text\" name=\"name\" maxlength=\"15\"/><br/>\n";
echo "Gender:<br/>\n";
echo "<select name=\"sex\" value=\"0\">\n";
echo "<option value=\"0\">Male</option>\n";
echo "<option value=\"1\">Female</option>\n";
echo "<option value=\"2\">Unknown :)</option>\n";
echo "</select><br/>\n";
echo "Date of Birth:<br/>";
echo "<input type=\"text\" name=\"day\" format=\"*N\" maxlength=\"2\" size=\"2\"/>-\n";
echo "<input type=\"text\" name=\"month\" format=\"*N\" maxlength=\"2\" size=\"2\"/>-\n";
echo "<input type=\"text\" name=\"year\" format=\"*N\" maxlength=\"4\" size=\"4\"/><br/>\n";
//echo "Location:<br/>\n";
//echo "<input type=\"text\" name=\"from\" maxlength=\"20\"/><br/>\n";
//echo "Mobile:<br/>\n";
//echo "<input type=\"text\" name=\"mobile\" maxlength=\"20\" value=\"$mobile\"/><br/>\n";
//echo "eMail:<br/>\n";
//echo "<input type=\"text\" name=\"email\" maxlength=\"30\"/><br/>\n";
//echo "About:<br/>\n";
//echo "<input type=\"text\" name=\"about\" maxlength=\"250\"/><br/>\n";
if($img == 1){
echo "<img src=\"img.php?sid=".session_id()."\" alt=\"kartinka\"/><br/>\n";
echo "Captcha:<br/>\n";
echo "<input type=\"text\" name=\"ref\" maxlength=\"4\" value=\"\"/><br/>\n";
}
echo "<anchor>[Register]<go href=\"registration.php?ver=wml&nocache=$nocache\" method=\"post\">\n";
echo "<postfield name=\"nickname\" value=\"$(nickname)\"/>\n";
echo "<postfield name=\"password\" value=\"$(password)\"/>\n";
echo "<postfield name=\"ref\" value=\"$(ref)\"/>\n";
echo "<postfield name=\"name\" value=\"$(name)\"/>\n";
echo "<postfield name=\"sex\" value=\"$(sex)\"/>\n";
echo "<postfield name=\"day\" value=\"$(day)\"/>\n";
echo "<postfield name=\"month\" value=\"$(month)\"/>\n";
echo "<postfield name=\"year\" value=\"$(year)\"/>\n";
echo "<postfield name=\"from\" value=\"$(from)\"/>\n";
echo "<postfield name=\"mobile\" value=\"$(mobile)\"/>\n";
echo "<postfield name=\"email\" value=\"$(email)\"/>\n";
echo "<postfield name=\"about\" value=\"$(about)\"/>\n";
echo "<postfield name=\"number\" value=\"$number\"/>\n";
echo "<postfield name=\"sid\" value=\"".session_id()."\"/>\n";
echo "<postfield name=\"action\" value=\"registration\"/>\n";
echo "</go></anchor><br/>\n";
echo "<a href=\"rules.php?ver=wml&action=registration&nocache=$nocache\">Rules</a><br/>\n";
echo "<a href=\"index.php?ver=wml&nocache=$nocache\">Index</a><br/><br/>\n";
}
else
{
$nickname = trim(htmlspecialchars(mysql_escape_string($_POST['nickname'])));
$nickname = str_replace('$', '$$', $nickname);
$password = trim(htmlspecialchars(mysql_escape_string($_POST['password'])));
$name = trim(htmlspecialchars(mysql_escape_string($_POST['name'])));
$name = str_replace('$', '$$', $name);
$sex = intval($_POST['sex']);
if($sex != 0 && $sex != 1) $sex = 2;
$day = substr(intval($_POST['day']), 0, 2);
$month = substr(intval($_POST['month']), 0, 2);
$year = substr(intval($_POST['year']), 0, 4);
$birthday = "$day-$month-$year";
$from = trim(htmlspecialchars(mysql_escape_string($_POST['from'])));
$from = str_replace('$', '$$', $from);
$mobile = trim(htmlspecialchars(mysql_escape_string($_POST['mobile'])));
$mobile = str_replace('$', '$$', $mobile);
$email = trim(htmlspecialchars(mysql_escape_string($_POST['email'])));
$email = str_replace('$', '$$', $email);
$site = strtolower(trim(htmlspecialchars(mysql_escape_string($_POST['site']))));
$site = str_replace('http://', '', $site);
$site = str_replace('$', '$$', $site);
$about = trim(htmlspecialchars(mysql_escape_string($_POST['about'])));
$about = str_replace('$', '$$', $about);
$number = intval($_POST['number']);
$error = "";
if(($img == 1) && ($_POST['ref'] != $_SESSION['ref'])) $error .= "Captcha error!<br/>\n";
if($number != $_SESSION['code']) $error .= BAD_SID."<br/>\n";
if(empty($nickname)) $error .= "Do not put nickname!<br/>\n";
if(empty($password)) $error .= "Do not put password!<br/>\n";
if(strlen($nickname) > 45) $error .= "too big nickname!<br/>\n";
if(strlen($password) > 20) $error .= "too big password!<br/>\n";
if((preg_match("/[^A-Za-z1-9\@\*\(\)\?\!\-\~\_\[\]\=]+/",$nickname))&&(!preg_match("!^[@\\*\\)\\(\\?\\!\\-_\\]\\|\\[=~]+$!i",$bak))) $error .= "Nickname contains illegal characters!<br/>\n";
if(preg_match("/[^0-9a-zA-Z_]+/", $password)) $error .= "Password contains illegal characters символы!<br/>\n";
if(!empty($email))
{
if (!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $email)) $error .= "not valid email!<br/>\n";
}
if(!empty($error))
{
echo $error;
echo "<a href=\"registration.php?ver=wml&nocache=$nocache\">Register</a><br/><br/>\n";
list($msec, $sec) = explode(chr(32), microtime());
echo "<small>[".round(($sec + $msec) - $headtime, 5)."]</small><br/>\n";
echo "</p></card></wml>";
session_destroy();
exit();
}
$q = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$nickname."';");
if(mysql_num_rows($q) != 0)
{
echo "<b>".$nickname."</b> already exist.<br/>\n";
echo "<a href=\"registration.php?ver=wml&nocache=$nocache\">Register</a><br/><br/>\n";
list($msec, $sec) = explode(chr(32), microtime());
echo "<small>[".round(($sec + $msec) - $headtime, 5)."]</small><br/>\n";
require_once "includes/functions/gzip_foot.php";
echo "</p></card></wml>";
ob_end_flush();
session_destroy();
exit();
}
$q = mysql_query("SELECT * FROM `chat_banned_nicknames` WHERE `nickname` = '".$nickname."';");
if(mysql_affected_rows() != 0)
{
echo "<b>".$nickname."</b> not allowed!<br/>\n";
echo "<a href=\"registration.php?ver=wml&nocache=$nocache\">Register</a><br/><br/>\n";
list($msec, $sec) = explode(chr(32), microtime());
echo "<small>[".round(($sec + $msec) - $headtime, 5)."]</small><br/>\n";
require_once "includes/functions/gzip_foot.php";
echo "</p></card></wml>";
ob_end_flush();
session_destroy();
exit();
}
$registration = mysql_query("INSERT INTO `chat_users` SET `nickname` = '".$nickname."', `password` = '".md5($password)."', `status` = 'Newbie', `name` = '".$name."', `sex` = ".$sex.", `birthday` = '".$birthday."', `from` = '".$from."', `mobile` = '".$mobile."', `email` = '".$email."', `site` = '".$site."', `about` = '".$about."', `ip` = '".$ip."', `ua` = '".$ua."', `time` = ".time().", `key` = '', `regdate` = '".date('d-m-y')."';");
if($registration)
{
$id = mysql_insert_id();
mysql_query("INSERT INTO `chat_letters` VALUES(0, '".$id."', '".$id."', 1, '".LETTER_TITLE."', '".LETTER_BODY."', '".date("d-m-Y")."', '".time()."', 0);");
echo REGISTRATION_SUCCESS."<br/>\n";
echo "Nick: <u>".$nickname."</u><br/>\n";
echo "Password: <u>".$password."</u><br/>\n";
echo "<anchor>[Continue]<go href=\"menu.php?ver=wml&nocache=$nocache\" method=\"post\">\n";
echo "<postfield name=\"nickname\" value=\"$nickname\"/>\n";
echo "<postfield name=\"password\" value=\"$password\"/>\n";
echo "<postfield name=\"action\" value=\"auth\"/>\n";
echo "</go></anchor><br/>\n";
echo "<a href=\"index.php?ver=wml&nocache=$nocache\">Index</a><br/><br/>\n";
}
else
{
echo REGISTRATION_ERROR."<br/>\n";
echo mysql_error()."<br/>\n";
}
session_destroy();
}
list($msec, $sec) = explode(chr(32), microtime());
echo "<small>[".round(($sec + $msec) - $headtime, 5)."]</small><br/>\n";
require_once "includes/functions/gzip_foot.php";
echo "</p></card></wml>";
ob_end_flush();
break;
case 'html':
///////////////////////////////////////////////////////
//HTML VERSION
///////////////////////////////////////////////////////
$my_title = "Register";
if(!isset($_COOKIE['theme'])) $_COOKIE['theme'] = 1;
include_once "themes/".intval($_COOKIE['theme'])."/index.php";
if($reg_status == 0)
{
echo "Registration is temporarily closed.<br/>\n";
include_once "themes/".intval($_COOKIE['theme'])."/foot.php";
exit();
}
if(((strpos($ua, "Opera") !== false) or (strpos($ua, "Mozilla") !== false) or (strpos($ua, "MSIE") !== false) or (strpos($ua, "Netscape") !== false)) && $computer == 1)
{
echo "Registration with the computer is prohibited.<br/>\n";
include_once "themes/".intval($_COOKIE['theme'])."/foot.php";
exit();
}
echo "<!-- Registration -->\n";
if(!isset($_POST['action']))
{
echo "<form action=\"registration.php?ver=html&nocache=$nocache\" method=\"post\">\n";
echo "NIck*:<br/>\n";
echo "<input type=\"text\" name=\"nickname\" maxlength=\"15\"/><br/>\n";
echo "Password*:<br/>\n";
echo "<input type=\"text\" name=\"password\" maxlength=\"20\"/><br/>\n";
echo "Name:<br/>\n";
echo "<input type=\"text\" name=\"name\" maxlength=\"15\"/><br/>\n";
echo "Gender:<br/>\n";
echo "<select name=\"sex\">\n";
echo "<option value=\"0\" selected=\"selected\">Male</option>\n";
echo "<option value=\"1\">Female</option>\n";
echo "<option value=\"2\">Unknown :)</option>\n";
echo "</select><br/>\n";
echo "Date of Birth:<br/>";
echo "<input type=\"text\" name=\"day\" format=\"*N\" maxlength=\"2\" size=\"2\"/>-\n";
echo "<input type=\"text\" name=\"month\" format=\"*N\" maxlength=\"2\" size=\"2\"/>-\n";
echo "<input type=\"text\" name=\"year\" format=\"*N\" maxlength=\"4\" size=\"4\"/><br/>\n";
/*echo "Location:<br/>\n";
echo "<input type=\"text\" name=\"from\" maxlength=\"20\"/><br/>\n";
echo "Mobile:<br/>\n";
echo "<input type=\"text\" name=\"mobile\" maxlength=\"20\" value=\"$mobile\"/><br/>\n";
echo "eMail:<br/>\n";
echo "<input type=\"text\" name=\"email\" maxlength=\"30\"/><br/>\n";
echo "Сайт:<br/>\n";
echo "<input type=\"text\" name=\"site\" maxlength=\"50\" value=\"http://\"/><br/>\n";
echo "About:<br/>\n";
echo "<input type=\"text\" name=\"about\" maxlength=\"250\"/><br/>\n";*/
if($img == 1){
echo "<img src=\"img.php?sid=".session_id()."\" alt=\"kartinka\"/><br/>\n";
echo "Captcha:<br/>\n";
echo "<input type=\"text\" name=\"ref\" maxlength=\"4\" value=\"\"/><br/>\n";
}
echo "<input type=\"hidden\" name=\"number\" value=\"$number\" />\n";
echo "<input type=\"hidden\" name=\"sid\" value=\"".session_id()."\" />\n";
echo "<input type=\"hidden\" name=\"action\" value=\"registration\" />\n";
echo "<input type=\"submit\" value=\"Register\" /></form>\n";
echo "<a href=\"rules.php?ver=html&action=registration&nocache=$nocache\">Rules</a><br/>\n";
echo "<a href=\"index.php?ver=html&nocache=$nocache\">Index</a><br/><br/>\n";
}
else
{
$nickname = trim(htmlspecialchars(mysql_escape_string($_POST['nickname'])));
$nickname = str_replace('$', '$$', $nickname);
$password = trim(htmlspecialchars(mysql_escape_string($_POST['password'])));
$name = trim(htmlspecialchars(mysql_escape_string($_POST['name'])));
$name = str_replace('$', '$$', $name);
$sex = intval($_POST['sex']);
if($sex != 0 && $sex != 1) $sex = 2;
$day = substr(intval($_POST['day']), 0, 2);
$month = substr(intval($_POST['month']), 0, 2);
$year = substr(intval($_POST['year']), 0, 4);
$birthday = "$day-$month-$year";
$from = trim(htmlspecialchars(mysql_escape_string($_POST['from'])));
$from = str_replace('$', '$$', $from);
$mobile = trim(htmlspecialchars(mysql_escape_string($_POST['mobile'])));
$mobile = str_replace('$', '$$', $mobile);
$email = trim(htmlspecialchars(mysql_escape_string($_POST['email'])));
$email = str_replace('$', '$$', $email);
$site = strtolower(trim(htmlspecialchars(mysql_escape_string($_POST['site']))));
$site = str_replace('http://', '', $site);
$site = str_replace('$', '$$', $site);
$about = trim(htmlspecialchars(mysql_escape_string($_POST['about'])));
$about = str_replace('$', '$$', $about);
$number = intval($_POST['number']);
$error = "";
if(($img == 1) && ($_POST['ref'] != $_SESSION['ref'])) $error .= "ne pravilnoe 4islo!<br/>\n";
if($number != $_SESSION['code']) $error .= BAD_SID."<br/>\n";
if(empty($nickname)) $error .= "Do not put nickname!<br/>\n";
if(empty($password)) $error .= "Do not put password!<br/>\n";
if(strlen($nickname) > 45) $error .= "too big nickname!<br/>\n";
if(strlen($password) > 20) $error .= "too big password!<br/>\n";
if((preg_match("/[^A-Za-z1-9\@\*\(\)\?\!\-\~\_\[\]\=]+/",$nickname))&&(!preg_match("!^[@\\*\\)\\(\\?\\!\\-_\\]\\|\\[=~]+$!i",$bak))) $error .= "Nickname contains illegal characters<br/>\n";
if(preg_match("/[^0-9a-zA-Z_]+/",$password)) $error .= "Password contains illegal characters!<br/>\n";
if(!empty($email))
{
if (!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $email)) $error .= "not valid email!<br/>\n";
}
if(!empty($error))
{
echo $error;
echo "<a href=\"registration.php?ver=html&nocache=$nocache\">Register</a><br/><br/>\n";
include_once "themes/".intval($_COOKIE['theme'])."/foot.php";
session_destroy();
exit();
}
$q = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$nickname."';");
if(mysql_num_rows($q) != 0)
{
echo "<b>".$nickname."</b> already exist.<br/>\n";
echo "<a href=\"registration.php?ver=html&nocache=$nocache\">Register</a><br/><br/>\n";
include_once "themes/".intval($_COOKIE['theme'])."/foot.php";
session_destroy();
exit();
}
$q = mysql_query("SELECT * FROM `chat_banned_nicknames` WHERE `nickname` = '".$nickname."';");
if(mysql_affected_rows() != 0)
{
echo "<b>".$nickname."</b> Cnt register!<br/>\n";
echo "<a href=\"registration.php?ver=html&nocache=$nocache\">Register</a><br/><br/>\n";
include_once "themes/".intval($_COOKIE['theme'])."/foot.php";
session_destroy();
exit();
}
$registration = mysql_query("INSERT INTO `chat_users` SET `nickname` = '".$nickname."', `password` = '".md5($password)."', `status` = 'Newbie', `name` = '".$name."', `sex` = ".$sex.", `birthday` = '".$birthday."', `from` = '".$from."', `mobile` = '".$mobile."', `email` = '".$email."', `site` = '".$site."', `about` = '".$about."', `ip` = '".$ip."', `ua` = '".$ua."', `time` = ".time().", `key` = '', `regdate` = '".date('d-m-y')."';");
if($registration)
{
$id = mysql_insert_id();
mysql_query("INSERT INTO `chat_letters` VALUES(0, '".$id."', '".$id."', 1, '".LETTER_TITLE."', '".LETTER_BODY."', '".date("d-m-Y")."', '".time()."', 0);");
echo REGISTRATION_SUCCESS."<br/>\n";
echo "Nick: <u>".$nickname."</u><br/>\n";
echo "Password: <u>".$password."</u><br/>\n";
echo "<br/><form action=\"menu.php?ver=html&nocache=$nocache\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"password\" value=\"$password\" />\n";
echo "<input type=\"hidden\" name=\"nickname\" value=\"$nickname\" />\n";
echo "<input type=\"hidden\" name=\"action\" value=\"auth\" />\n";
echo "<input type=\"submit\" value=\"Login\" /></form>\n";
echo "<a href=\"index.php?ver=html&nocache=$nocache\">Index</a><br/><br/>\n";
}
else
{
echo REGISTRATION_ERROR."<br/>\n";
echo mysql_error()."<br/>\n";
}
session_destroy();
}
include_once "themes/".intval($_COOKIE['theme'])."/foot.php";
break;
}
?>