<?php
// Initialize server environment
error_reporting (E_ALL);
ignore_user_abort(true);
set_magic_quotes_runtime(0);
ob_start('ob_gzhandler');
set_time_limit(0);
function timer($st=0,$d=8){list($m,$s)=explode(' ',microtime());return round(floatval($s)+floatval($m)-$st,$d);}
$UPL['RUNTIME'] = timer ( );
if ( is_file ( 'install.php' ) )
{
header( 'Location: install.php?step=3' ) ;
//exit ( 'Install.php still exists. If this is your first time running the script, <a href="install.php">click here</a> to install. Otherwise delete it to resume normal operation.' );
}
// order matters
require_once 'constants.inc.php';
require_once 'functions.inc.php';
require_once 'configs.inc.php';
require_once 'template.class.php';
require_once 'db.class.php';
require_once 'messages.inc.php';
// clean GPC
if ( get_magic_quotes_gpc ( ) )
{
$_GET = strip_gpc ( $_GET );
$_POST = strip_gpc ( $_POST );
$_COOKIE = strip_gpc ( $_COOKIE );
}
// Load settings
$db = new DB;
if ( !$db->open ( UPLOADER_SETTINGS ) )
exit ( 'Unable to open settings file ' . UPLOADER_SETTINGS );
$UPL['SETTINGS'] = $db->all ( );
unset ( $db );
// check the template
if ( !is_dir ( 'templates/' . $UPL['SETTINGS']['tpl'] ) )
{
if ( !is_dir ( 'templates/default/' ) )
{
exit ( 'Unable to locate the template folder and an attempt to use the default template has failed.' );
}
print sprintf ( '<h1>Unabled to locate the template "%s", using the default template instead.</h1>', $UPL['SETTINGS']['tpl'] );
$UPL['SETTINGS']['tpl'] = 'default';
}
// global variables
$demo = 0;
define ( 'TPL_DIR', 'templates/' . $UPL['SETTINGS']['tpl'] . '/' );
// Initialize some common template objects
$tpl_uploader = new Template ( TPL_DIR . 'tpl_uploader.php' );
$tpl_message = new Template ( TPL_DIR . 'tpl_message.php' );
// get common user inputs
$action = gpc ( 'action', 'GP' );
$action = is_array ( $action ) ? trim ( key ( $action ) ) : trim ( $action );
$task = gpc ( 'task', 'GP' );
$task = is_array ( $task ) ? trim ( key ( $task ) ) : trim ( $task );
// authenticate user
$UPL['USER']['logged_in'] = false;
$UPL['USER']['id'] = -1;
$UPL['USER']['name'] = 'Guest';
$UPL['USER']['level'] = LEVEL_NORMAL;
// Auto login for returning user
$c_username = gpc ( 'uploader_username', 'C', false );
$c_password = gpc ( 'uploader_password', 'C', false );
$c_userid = gpc ( 'uploader_userid', 'C', false );
$c_session = gpc ( 'uploader_session', 'C', false );
if ( $c_password !== false && $c_userid !== false )
{
$c_userid = abs ( intval ( $c_userid ) );
$u = new User;
if ( $u->open ( $c_userid ) && $u->get ( 'password' ) == $c_password )
{
$UPL['USER'] = $u->all ( );
$UPL['USER']['logged_in'] = true;
// user just came back, set last login
if ( $c_session === false )
{
setcookie ( 'uploader_session', "uploader_session", 0, '/', $UPL['CONFIGS']['COOKIE_DOMAIN'], 0 );
$u->set('xtr_last_login_time',time());
$u->set('xtr_last_login_ip',$_SERVER['REMOTE_ADDR']);
$u->save();
}
}
unset($u);
}
// to template
$tpl_uploader->setr ( 'UPL', $UPL );
// Verify user
if ( !defined ( 'NO_AUTH_CHECK' ) )
{
$err = 'none';
if ( !$UPL['USER']['logged_in'] )
{
$err = $lang_commons['not_logged_in'];
}
elseif ( $UPL['USER']['level'] == LEVEL_NORMAL )
{
if ( $UPL['USER']['is_suspended'] ) $err = $lang_commons['account_suspended'];
elseif ( $UPL['SETTINGS']['activation_req'] && !$UPL['USER']['is_activated'] ) $err = $lang_commons['account_not_activated'];
elseif ( !$UPL['USER']['is_approved'] ) $err = $lang_commons['account_not_approved'];
}
if ( $err != 'none' )
{
$tpl_message->set ( 'message', $err );
$tpl_uploader->setr ( 'content', $tpl_message );
exit ( $tpl_uploader->display ( ) );
}
}
?>