Файл: adultscript-2.0.3-pro/files/install/install.php
Строк: 413
<?php
define('_VALID', true);
define('_INSTALL', true);
require '../libraries/defines.php';
require '../libraries/framework.php';
require '../libraries/framework/functions.php';
require 'functions.php';
error_reporting(E_ALL);
ini_set('display_errors', 0);
if (ini_get('date.timezone') == '') {
date_default_timezone_set('Europe/Helsinki');
}
VF::load('framework.compat.enviroment.magic_quotes_gpc_off');
VF::load('framework.compat.enviroment.register_globals_off');
spl_autoload_register(array('VF', 'auto_load'));
$uri = get_uri();
define('BASE_URL', $uri['base_url']);
define('CURRENT_URL', $uri['current_url']);
define('RELATIVE_URL', $uri['relative_url']);
define('ADMIN_URL', $uri['admin_url']);
define('INSTALL_URL', BASE_URL.'/install');
$errors = array();
$finished = false;
$cfg = true;
$test = VF::factory('test');
$required = $test->get_required_results();
$optional = $test->get_optional_results();
$recommended = $test->get_recommended_results();
$config = array(
'db_host' => '',
'db_username' => '',
'db_password' => '',
'db_name' => '',
'db_prefix' => '',
'admin_user' => '',
'admin_pass' => '',
'admin_email' => '',
'base_url' => BASE_URL,
'relative_url' => RELATIVE_URL,
);
$secret = VText::random();
if (isset($_POST['submit-install'])) {
$filter = VF::factory('filter');
$db_host = trim($_POST['db_host']);
$db_username = trim($_POST['db_username']);
$db_password = trim($_POST['db_password']);
$db_name = $filter->get('db_name');
$db_prefix = $filter->get('db_prefix');
$admin_user = $filter->get('admin_user');
$admin_pass = $filter->get('admin_pass');
$admin_email = $filter->get('admin_email');
$base_url = $filter->get('base_url');
$relative_url = $filter->get('relative_url');
if ($db_host == '') {
$errors[] = 'Please enter a valid database server!';
} else {
$config['db_host'] = $db_host;
}
if ($db_username == '') {
$errors[] = 'Please specify a database username!';
} else {
$config['db_username'] = $db_username;
}
if ($db_name == '') {
$errors[] = 'Please specify a database name!';
} else {
$config['db_name'] = $db_name;
}
$config['db_password'] = $db_password;
$config['db_prefix'] = $db_prefix;
if ($admin_user == '') {
$errors[] = 'Please specify your administrator username!';
} elseif (!VValid::aldash($admin_user)) {
$errors[] = 'Administrator username can contain only letters, numbers and dashes!';
} else {
$config['admin_user'] = $admin_user;
}
if ($admin_pass == '') {
$errors[] = 'Administrator password cannot be left blank!';
} else {
$config['admin_pass'] = $admin_pass;
}
if ($admin_email == '') {
$errors[] = 'Administrator email cannot be left blank!';
} elseif (!VValid::email($admin_email)) {
$errors[] = 'Administrator email is not a valid email address!';
} else {
$config['admin_email'] = $admin_email;
}
if ($base_url == '') {
$errors[] = 'Please enter you site's URL address!';
} elseif (!VValid::url($base_url)) {
$errors[] = 'Site's URL is not a valid url address!';
} else {
$config['base_url'] = $base_url;
}
$config['db_password'] = $db_password;
$config['db_prefix'] = $db_prefix;
$config['relative_url'] = $relative_url;
if (!$errors) {
require 'db.php';
$db = new VInstall_db($db_host, $db_name, $db_username, $db_password, $db_prefix);
if ($db->is_error()) {
$errors[] = $db->get_error();
}
if (!$errors) {
// lets make sure UTF8 is supported
$db->query("ALTER DATABASE ".$db_name."
CHARACTER SET utf8
DEFAULT CHARACTER SET utf8
COLLATE utf8_general_ci
DEFAULT COLLATE utf8_general_ci");
$db->load_file(BASE_DIR.'/install/sqls/asp.sql');
if ($db->is_error()) {
$errors[] = $db->get_error();
}
$db->query("SHOW TABLES");
$tables = $db->fetch_rows();
foreach ($tables as $table) {
$name = $table['0'];
$db->query("ALTER TABLE ".$name."
DEFAULT CHARACTER SET utf8
COLLATE utf8_general_ci");
}
if (!$errors) {
$db->query("INSERT INTO #__user
SET group_id = 1,
username = '".$db->escape($admin_user)."',
password = '".$db->escape(VHash::encrypt($admin_pass))."',
email = '".$db->escape($admin_email)."',
join_date = '".date('Y-m-d h:i:s')."',
join_ip = ".VServer::ip(true).",
verified = '1',
status = '1'");
if (!$db->is_error() && $db->affected_rows()) {
$user_id = (int) $db->get_last_insert_id('#__user');
$db->query("INSERT INTO #__user_activity SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_notifications SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_preferences SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_profile SET user_id = ".$user_id);
$db->query("INSERT INTO #__user
SET group_id = 5,
username = 'anonymous',
password = '".$db->escape(VHash::encrypt(VText::random()))."',
email = 'anonymous@yourdomain.com',
join_date = '".date('Y-m-d h:i:s')."',
join_ip = ".VServer::ip(true).",
verified = '1',
status = '1'");
$user_id = (int) $db->get_last_insert_id('#__user');
$db->query("INSERT INTO #__user_activity SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_notifications SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_preferences SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_profile SET user_id = ".$user_id);
$db->query("UPDATE #__module SET add_date = '".date('Y-m-d h:i:s')."'");
$license_domain = get_domain(str_replace('http://', '', $base_url));
$license_key = generate_license();
$r = array(
'k' => $license_key,
'd' => $license_domain,
's' => $secret
);
$u = 'http://www.adultscriptpro.com/register.php?'.http_build_query($r);
ini_set('default_socket_timeout', 10);
if (!$retval = @file_get_contents($u)) {
$retval = @VCurl::string($u, null, null, 10);
}
$driver = (function_exists('mysqli_connect')) ? 'mysqli' : 'mysql';
$cfg_file = array();
$cfg_file[] = "<?php";
$cfg_file[] = "defined('_VALID') or die('Restricted Access!');";
$cfg_file[] = "return array(";
$cfg_file[] = "'db_driver' => '".$driver."',";
$cfg_file[] = "'db_host' => '".$db_host."',";
$cfg_file[] = "'db_name' => '".$db_name."',";
$cfg_file[] = "'db_username' => '".$db_username."',";
$cfg_file[] = "'db_password' => '".$db_password."',";
$cfg_file[] = "'db_prefix' => '".$db_prefix."',";
$cfg_file[] = "'license_key' => '".$license_key."',";
$cfg_file[] = "'license_domain' => '".$license_domain."',";
$cfg_file[] = "'secret' => '".$secret."',";
$cfg_file[] = "'default' => 'adultscriptpro',";
$cfg_file[] = "'base_url' => '".$base_url."',";
$cfg_file[] = "'mobile_url' => '".$base_url."',";
$cfg_file[] = "'relative' => '".$relative_url."'";
$cfg_file[] = ");";
$cfg_file[] = "?>";
if (!@file_put_contents(BASE_DIR.'/config.php', implode("n", $cfg_file))) {
$cfg = FALSE;
}
$finished = TRUE;
} else {
$errors[] = 'Failed to create the Administrator username database entry! Aborting...';
}
}
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Adult Script Pro Installation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?php echo INSTALL_URL ?>/css/style.css?v1" type="text/css" media="all" />
<script type="text/javascript">
var base_url = "<?php echo BASE_URL; ?>";
</script>
</head>
<script type="text/javascript" src="<?php echo INSTALL_URL; ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("img[id^='help_']").click(function() {
var id = $(this).attr('id').match(/help_(.*)/)[1];
if ($("p[id='test_" + id + "']").is(':visible')) {
$("p[id='test_" + id + "']").slideUp();
} else {
$("p[id='test_" + id + "']").slideDown();
}
});
});
</script>
<body>
<div id="container">
<?php if (!$finished): ?>
<?php if ($errors): ?>
<div class="errors">
<?php foreach ($errors as $error): ?>
<span><?php echo htmlspecialchars($error),'<br />'; ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="left width-475">
<h2>Testing Requirements</h2>
<div class="box-content">
<h3>Required Items</h3>
<?php foreach ($required as $id => $values): if (!isset($values['system'])): ?>
<span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
<span class="value">
<?php if ($values['status'] === true): ?>
<img src="<?php echo INSTALL_URL; ?>/images/accept.png" alt="accept.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/help.png" id="help_<?php echo $id; ?>" class="help" alt="help.png" />
<?php if (isset($values['warning']) && $values['warning'] == '1'): ?>
<img src="<?php echo INSTALL_URL; ?>/images/error.png" alt="error.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/delete.png" alt="delete.png" />
<?php endif; endif; ?>
</span>
<div class="clear"></div>
<p id="test_<?php echo $id; ?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
<?php endif; endforeach; ?>
<h3>Required PHP Settings</h3>
<?php foreach ($recommended as $id => $values): if (!isset($values['system'])): ?>
<span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
<span class="value">
<?php if ($values['status'] === true): ?>
<img src="<?php echo INSTALL_URL; ?>/images/accept.png" alt="accept.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/help.png" id="help_<?php echo $id; ?>" class="help" alt="help.png" />
<?php if ($values['warning'] == '1'): ?>
<img src="<?php echo INSTALL_URL; ?>/images/error.png" alt="error.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/delete.png" alt="delete.png" />
<?php endif; endif; ?>
</span>
<div class="clear"></div>
<p id="test_<?php echo $id; ?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
<?php endif; endforeach; ?>
<h3>Optional Items</h3>
<?php foreach ($optional as $id => $values): if (!isset($values['system'])): ?>
<span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
<span class="value">
<?php if ($values['status'] === true): ?>
<img src="<?php echo INSTALL_URL; ?>/images/accept.png" alt="accept.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/help.png" id="help_<?php echo $id; ?>" class="help" alt="help.png" />
<img src="<?php echo INSTALL_URL; ?>/images/error.png" alt="error.png" />
<?php endif; ?>
</span>
<div class="clear"></div>
<p id="test_<?php echo $id; ?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
<?php endif; endforeach; ?>
<form name="test-form" method="post" action="<?php echo BASE_URL; ?>/install/install.php?a=test">
<div class="submit">
<input name="submit-test" type="submit" id="submit-test" class="submit" value="Run Tests Again" />
</div>
</form>
</div>
</div>
<div class="right width-475">
<h2>Installation Options</h2>
<div class="box-content">
<form name="install-form" method="post" action="<?php echo BASE_URL; ?>/install/install.php?a=install">
<h3>Database Configuration</h3>
<div>
<label for="db_host">Server</label>
<input name="db_host" type="text" id="db_host" value="<?php echo $config['db_host']; ?>" />
</div>
<div class="clear-left">
<label for="db_username">Username</label>
<input name="db_username" type="text" id="db_username" value="<?php echo $config['db_username']; ?>" />
</div>
<div class="clear-left">
<label for="db_password">Password</label>
<input name="db_password" type="password" id="db_password" value="<?php echo $config['db_password']; ?>" />
</div>
<div class="clear-left">
<label for="db_name">Database Name</label>
<input name="db_name" type="text" id="db_name" value="<?php echo $config['db_name']; ?>" />
</div>
<div class="clear-left">
<label for="db_prefix">Table Prefix</label>
<input name="db_prefix" type="text" id="db_prefix" value="<?php echo $config['db_prefix']; ?>" />
</div>
<h3>Script Configuration</h3>
<div>
<label for="base_url">Site URL</label>
<input name="base_url" type="text" id="base_url" value="<?php echo $config['base_url']; ?>" />
</div>
<?php if ($config['relative_url'] != ''): ?>
<div class="clear-left">
<label for="relative_url">Relative URL</label>
<input name="relative_url" type="text" id="relative_url" value="<?php echo $config['relative_url']; ?>" />
</div>
<?php endif; ?>
<div class="clear-left">
<label for="admin_user">Administrator Username</label>
<input name="admin_user" type="text" id="admin_user" value="<?php echo $config['admin_user']; ?>" />
</div>
<div class="clear-left">
<label for="admin_pass">Administrator Password</label>
<input name="admin_pass" type="password" id="admin_pass" value="<?php echo $config['admin_pass']; ?>" />
</div>
<div class="clear-left">
<label for="admin_email">Administrator Email</label>
<input name="admin_email" type="text" id="admin_email" value="<?php echo $config['admin_email']; ?>" />
</div>
<div class="submit clear-left">
<input name="submit-install" type="submit" id="submit-install" class="submit" value="Install >"<?php if ($test->is_error() === true): echo ' disabled="1"'; endif; ?> />
</div>
</form>
</div>
</div>
<div class="clear"></div>
<?php else: ?>
<div class="box">
<h1>Congratulations! Adult Script Pro is now installed!</h1>
Click on the 'Site' button to view your site or 'Administrator' button to start the site configuration!
<div class="links">
<a href="<?php echo BASE_URL; ?>">Site</a>
<a href="<?php echo ADMIN_URL; ?>/index.php">Administrator</a>
</div>
<?php if (!$cfg): ?>
<br /><br />Your configuration file or directory is not writable or there was a problem creating the configuration file. You will have to upload the following code by hand. Click in the text area to highlight all of the code and then paste into a new text file. Name this file 'config.php' and upload it to your site root folder.
<form name="install-form" method="post" action="<?php echo BASE_URL; ?>/install/install.php">
<textarea name="config" id="config" cols="70" rows="10" onclick="this.form.config.focus();this.form.config.select();"><?php echo htmlspecialchars(implode("n", $cfg_file), ENT_QUOTES, 'UTF-8'); ?></textarea>
</form>
<br /><br />
<?php endif; ?>
<div class="install">
Please completly remove the installation directory (/install). This is a security feature!
</div>
</div>
<?php endif; ?>
</div>
</body>
</html>