?><?php
/*
=====================================================
DataLife Engine - by SoftNews Media Group
-----------------------------------------------------
http://dle-news.ru/
-----------------------------------------------------
Copyright (c) 2004,2008 SoftNews Media Group
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: init.php
-----------------------------------------------------
Назначение: Инициализация
=====================================================
*/
function convert_unicode($t, $to = 'windows-1251')
{
$t = preg_replace( '#%u([0-9A-F]{1,4})#ie', "'&#' . hexdec('\\1') . ';'", $t );
$t = urldecode ($t);
$t = @html_entity_decode($t, ENT_NOQUOTES, $to);
return $t;
}
function send_activation ($query,$others=''){
$host='www.dle-news.ru';
$path='/extras/activate.php';
$post="POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n{$others}User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query";
$h=@fsockopen($host,80, $errno, $errstr, 30);
if (!$h) {
$r = @file_get_contents("http://".$host.$path."?".$query);
}
else
{
fwrite($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
}
if (stristr( $r, "antw:activated" )) return "1";
if (stristr( $r, "antw:denied" )) return "0";
return "-1";
}
function dle_activation($key, $domen_hash, $config){
include (ROOT_DIR.'/language/'.$config['langs'].'/adminpanel.lng');
$config['charset'] = ($lang['charset'] != '') ? $lang['charset'] : $config['charset'];
$domain = urlencode(strip_tags ($_SERVER['HTTP_HOST']));
$key = strip_tags ($key);
$buffer = send_activation ("domain={$domain}&key={$key}&site_key={$domen_hash}&c_id=3315");
switch ($buffer) {
case "-1" :
$buffer = $lang['trial_act1'];
break;
case "0" :
$buffer = $lang['trial_act2'];
break;
case "1" :
$config['key'] = $domen_hash;
$handler = fopen(ENGINE_DIR.'/data/config.php', "w");
fwrite($handler, "<?PHP \n\n//System Configurations\n\n\$config = array (\n\n");
foreach($config as $name => $value)
{
fwrite($handler, "'{$name}' => \"{$value}\",\n\n");
}
fwrite($handler, ");\n\n?>");
fclose($handler);
$buffer = $lang['trial_act3'];
break;
default:
$buffer = $lang['trial_act4'];
}
@header("Content-type: text/css; charset=".$config['charset']);
echo $buffer;
die ();
}
extract($_REQUEST, EXTR_SKIP);
require_once (ENGINE_DIR.'/data/config.php');
$domen_hash = explode('.', $_SERVER['HTTP_HOST']);
$count_key = count($domen_hash) - 1;
unset ($domen_hash[$count_key]);
if (end($domen_hash) == "com" OR end($domen_hash) == "net") $count_key --;
$domen_hash = $domen_hash[$count_key-1];
$domen_hash = md5(md5($domen_hash."780918"));
$lic_tr = true;
if ($domen_hash == $config['key']) $lic_tr = false;
if ($_REQUEST['activation'] == "yes") { dle_activation (convert_unicode($_REQUEST['dle_key']), $domen_hash, $config); exit;}
require_once(ENGINE_DIR.'/classes/mysql.php');
require_once(ENGINE_DIR.'/data/dbconfig.php');
require_once(ROOT_DIR.'/language/'.$config['langs'].'/adminpanel.lng');
$config['charset'] = ($lang['charset'] != '') ? $lang['charset'] : $config['charset'];
require_once(ENGINE_DIR.'/inc/functions.inc.php');
check_xss ();
$Timer = new microTimer;
$Timer->start();
if ($_SESSION['dle_log'] > 5) die("Hacking attempt!");
$is_loged_in = FALSE;
$member_db = array ();
$result = "";
$username = "";
$cmd5_password = "";
$allow_login = false;
$PHP_SELF = $_SERVER['PHP_SELF'];
$_IP = $db->safesql($_SERVER['REMOTE_ADDR']);
require_once(ENGINE_DIR.'/skins/default.skin.php');
if (isset ($_POST['action'])) $action = $_POST['action']; else $action = $_GET['action'];
if (isset ($_POST['mod'])) $mod = $_POST['mod']; else $mod = $_GET['mod'];
if (isset ($_COOKIE['lastusername'])) $lastusername = $_COOKIE['lastusername']; else $lastusername = "";
if (($mod != "editnews" AND $mod != "main" AND $mod != "") AND $lic_tr) {
$row = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_post");
$stats_news = $row['count'];
$row = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_comments");
$count_comments = $row['count'];
if ($stats_news > 100) msg("info","error", $lang['trial_limit']);
if ($count_comments > 200) msg("info","error", $lang['trial_limit']);
}
//################# Определение групп пользователей
$user_group = get_vars ("usergroup");
if (!$user_group) {
$user_group = array ();
$db->query("SELECT * FROM " . USERPREFIX . "_usergroups ORDER BY id ASC");
while($row = $db->get_row()){
$user_group[$row['id']] = array ();
foreach ($row as $key => $value)
{
$user_group[$row['id']][$key] = $value;
}
}
set_vars ("usergroup", $user_group);
$db->free();
}
//#################
//################# Определение категорий
$cat_info = get_vars ("category");
if (!is_array($cat_info)) {
$cat_info = array ();
$db->query("SELECT * FROM " . PREFIX . "_category ORDER BY posi ASC");
while($row = $db->get_row()){
$cat_info[$row['id']] = array ();
foreach ($row as $key => $value)
{
$cat_info[$row['id']][$key] = stripslashes($value);
}
}
set_vars ("category", $cat_info);
$db->free();
}
if (count($cat_info)) {
foreach($cat_info as $key) {
$cat[$key['id']] = $key['name'];
$cat_parentid[$key['id']]=$key['parentid'];
}
}
if ($_REQUEST['action'] == "logout") {
set_cookie("dle_name","", 0);
set_cookie("dle_password","", 0);
set_cookie("dle_skin","", 0);
set_cookie("dle_newpm", "", 0);
set_cookie("dle_hash", "", 0);
set_cookie(session_name(),"",0);
@session_unset();
@session_destroy();
if ($config['extra_login']) auth();
msg("info", $lang['index_msge'], $lang['index_exit']);
}
if ($check_referer) {
if ($_SERVER['HTTP_REFERER'] == '' AND $_REQUEST['subaction'] != 'dologin') $allow_login = true;
elseif (clean_url($_SERVER['HTTP_REFERER']) == clean_url($_SERVER['HTTP_HOST'])) $allow_login = true;
} else {
$allow_login = true;
}
if ($allow_login) {
if ($config['extra_login']) {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) auth();
$username = $_SERVER['PHP_AUTH_USER'];
$cmd5_password = md5($_SERVER['PHP_AUTH_PW']);
} elseif ($_SESSION['dle_name'] != "") {
$username = $_SESSION['dle_name'];
$cmd5_password = $_SESSION['dle_password'];
} elseif ($_COOKIE['dle_name'] != "") {
$username = $_COOKIE['dle_name'];
$cmd5_password = $_COOKIE['dle_password'];
}
if($_REQUEST['subaction'] == 'dologin'){
$username = $_POST['username'];
$cmd5_password = md5($_POST['password']);
}
}
if(check_login($username, $cmd5_password))
{
$is_loged_in = true;
$_SESSION['dle_log'] = 0;
$dle_login_hash = md5($_SERVER['HTTP_HOST'].$username.$cmd5_password.$config['key']);
}else{
$_SESSION['dle_log'] = intval($_SESSION['dle_log'])+1;
$dle_login_hash = "";
if($_REQUEST['subaction'] == 'dologin') {
$result = "<font color=red>".$lang['index_errpass']."</font>";
} else $result = "";
if ($config['extra_login']) auth();
$is_loged_in = false;
}
if ($is_loged_in AND !$_SESSION['dle_xtra'] AND $config['extra_login']) {$_SESSION['dle_xtra'] = true; $_REQUEST['subaction'] = 'dologin';}
###########################
if($is_loged_in AND $_REQUEST['subaction'] == 'dologin'){
$_SESSION['dle_name'] = $username;
$_SESSION['dle_password'] = $cmd5_password;
set_cookie ("lastusername", $username, 365);
set_cookie ("dle_name", $username, 365);
set_cookie ("dle_password", $cmd5_password, 365);
$time_now = time()+ ($config['date_adjust']*60);
if ($config['log_hash']) {
$salt = "abchefghjkmnpqrstuvwxyz0123456789"; $hash = '';
srand((double)microtime()*1000000);
for($i=0;$i < 9; $i++) {
$hash .= $salt{rand(0,33)};
}
$hash = md5 ( $hash );
set_cookie ("dle_hash", $hash, 365);
$_COOKIE['dle_hash'] = $hash;
$member_db[14] = $hash;
$db->query("UPDATE " . USERPREFIX . "_users set hash='" . $hash . "', lastdate='{$time_now}', logged_ip='".$_IP."' WHERE user_id='$member_db[10]'");
} else $db->query("UPDATE " . USERPREFIX . "_users set lastdate='{$time_now}', logged_ip='".$_IP."' WHERE user_id='$member_db[10]'");
}
if ($is_loged_in AND $config['log_hash'] AND (($_COOKIE['dle_hash'] != $member_db[14]) OR ($member_db[14] == "") )) {
$is_loged_in = FALSE;
}
if ($is_loged_in AND $config['ip_control'] == '1' AND $member_db[15] != $_IP AND $_REQUEST['subaction'] != 'dologin') $is_loged_in = FALSE;
if (!$is_loged_in) {
set_cookie("dle_name","", 0);
set_cookie("dle_password","", 0);
set_cookie("dle_skin","", 0);
set_cookie("dle_hash","", 0);
$_SESSION['dle_name'] = '';
$_SESSION['dle_password'] = '';
if ($config['extra_login']) auth();
}
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>