Files
Kleeja/install/install.php

434 lines
14 KiB
PHP
Raw Normal View History

2018-01-09 02:09:07 +03:00
<?php
/**
*
* @package install
2020-04-11 22:45:48 +02:00
* @copyright (c) 2007 Kleeja.net
2018-01-09 02:09:07 +03:00
* @license ./docs/license.txt
*
*/
// Report all errors, except notices
@error_reporting(E_ALL ^ E_NOTICE);
/**
* include important files
*/
define('IN_COMMON', true);
2019-05-13 00:03:24 +03:00
define('STOP_PLUGINS', true);
define('PATH', '../');
2019-05-03 23:52:08 +03:00
2019-05-13 00:03:24 +03:00
if (file_exists(PATH . 'config.php'))
2018-01-09 02:09:07 +03:00
{
2019-05-13 00:03:24 +03:00
include_once PATH . 'config.php';
2018-01-09 02:09:07 +03:00
}
2019-05-13 00:03:24 +03:00
include_once PATH . 'includes/plugins.php';
include_once PATH . 'includes/functions_display.php';
include_once PATH . 'includes/functions_alternative.php';
include_once PATH . 'includes/functions.php';
2019-05-30 07:32:17 +03:00
if (isset($dbtype) && $dbtype == 'sqlite')
{
include PATH . 'includes/sqlite.php';
}
else
{
include PATH . 'includes/mysqli.php';
}
2018-01-09 02:09:07 +03:00
include_once 'includes/functions_install.php';
2019-05-04 00:36:05 +03:00
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
if (! ig('step'))
2018-01-09 02:09:07 +03:00
{
2019-05-03 23:52:08 +03:00
//if anyone request this file directly without passing index.php we will return him to index.php
header('Location: index.php');
exit;
2018-01-09 02:09:07 +03:00
}
//
// Kleeja must be safe ..
//
2019-05-03 23:52:08 +03:00
if (! empty($dbuser) && ! empty($dbname) && ! (ig('step') && in_array(g('step'), ['c','check', 'data', 'end', 'wizard'])))
2018-01-09 02:09:07 +03:00
{
2019-05-03 23:52:08 +03:00
$d = inst_get_config('language');
if (! empty($d))
{
2019-05-08 02:07:47 +03:00
header('Location: ./index.php');
2019-05-03 23:52:08 +03:00
exit;
}
2018-01-09 02:09:07 +03:00
}
/**
* Print header
*/
2019-05-13 00:03:24 +03:00
if (ip('dbsubmit') && ! is_writable(PATH))
2018-01-09 02:09:07 +03:00
{
2019-05-03 23:52:08 +03:00
// soon
2018-01-09 02:09:07 +03:00
}
else
{
2019-05-03 23:52:08 +03:00
echo gettpl('header.html');
2018-01-09 02:09:07 +03:00
}
2019-05-03 23:52:08 +03:00
// //navigate ..
2018-01-09 02:09:07 +03:00
switch (g('step'))
{
default:
case 'license':
2018-01-09 02:09:07 +03:00
$contentof_license = 'GPL version 2
2018-01-09 02:09:07 +03:00
GNU General Public License, Free Software Foundation
The GNU General Public License is a Free Software license. Like any Free Software license, it grants to you the four following freedoms:
1. The freedom to run the program for any purpose.
2. The freedom to study how the program works and adapt it to your needs.
3. The freedom to redistribute copies so you can help your neighbor.
4. The freedom to improve the program and release your improvements to the public, so that the whole community benefits.
You may exercise the freedoms specified here provided that you comply with the express conditions of this license. The principal conditions are:
You must conspicuously and appropriately publish on each copy distributed an appropriate copyright notice and disclaimer of warranty and keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of the GNU General Public License along with the Program. Any translation of the GNU General Public License must be accompanied by the GNU General Public License.
If you modify your copy or copies of the program or any portion of it, or develop a program based upon it, you may distribute the resulting work provided you do so under the GNU General Public License. Any translation of the GNU General Public License must be accompanied by the GNU General Public License.
If you copy or distribute the program, you must accompany it with the complete corresponding machine-readable source code or with a written offer, valid for at least three years, to furnish the complete corresponding machine-readable source code.
2019-05-03 23:52:08 +03:00
Any of the above conditions can be waived if you get permission from the copyright holder.';
$contentof_license = nl2br($contentof_license);
echo gettpl('license.html');
2018-01-09 02:09:07 +03:00
break;
2018-01-09 02:09:07 +03:00
case 'f':
2018-01-09 02:09:07 +03:00
$check_ok = true;
$advices = $ziparchive_lib = false;
2018-01-09 02:09:07 +03:00
if (! class_exists('ZipArchive'))
{
$ziparchive_lib = true;
}
2019-05-03 23:52:08 +03:00
if ($ziparchive_lib)
{
$advices = true;
}
2018-01-09 02:09:07 +03:00
echo gettpl('check.html');
2018-01-09 02:09:07 +03:00
break;
2019-05-03 23:52:08 +03:00
case 'c':
2018-01-09 02:09:07 +03:00
// after submit, generate config file
if (ip('dbsubmit'))
{
//create config file, or export it to browser on failure
do_config_export(p('db_server'), p('db_user'), p('db_pass'), p('db_name'), p('db_prefix'), p('db_type'));
}
2018-01-09 02:09:07 +03:00
$no_config = ! file_exists(PATH . 'config.php') || ig('force') ? false : true;
$writeable_path = is_writable(PATH) ? true : false;
$sqlite3_exists = class_exists('SQLite3');
2018-01-09 02:09:07 +03:00
echo gettpl('configs.html');
2018-01-09 02:09:07 +03:00
break;
2018-01-09 02:09:07 +03:00
case 'check':
2018-01-09 02:09:07 +03:00
$submit_disabled = $no_connection = $mysql_ver = false;
2018-01-09 02:09:07 +03:00
//config.php
if (! empty($dbname))
2019-05-30 19:55:49 +03:00
{
if (isset($dbtype) && $dbtype == 'sqlite')
{
@touch(PATH . $dbname);
}
2019-05-30 19:55:49 +03:00
//connect .. for check
$SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname, $dbprefix);
2018-01-09 02:09:07 +03:00
if (! $SQL->is_connected())
{
$no_connection = true;
}
else
2019-05-03 23:52:08 +03:00
{
if (defined('SQL_LAYER') && SQL_LAYER == 'mysqli')
2019-05-30 07:32:17 +03:00
{
if (! empty($SQL->version()) && version_compare($SQL->version(), MIN_MYSQL_VERSION, '<'))
{
$mysql_ver = $SQL->version();
}
2019-05-30 07:32:17 +03:00
}
2019-05-03 23:52:08 +03:00
}
}
//try to chmod them
if (function_exists('chmod'))
{
@chmod(PATH . 'cache', 0755);
@chmod(PATH . 'plugins', 0755);
@chmod(PATH . 'styles', 0755);
@chmod(PATH . 'uploads', 0755);
@chmod(PATH . 'uploads/thumbs', 0755);
}
2018-01-09 02:09:07 +03:00
echo gettpl('check_all.html');
2018-01-09 02:09:07 +03:00
break;
2018-01-09 02:09:07 +03:00
case 'data' :
2018-01-09 02:09:07 +03:00
if (ip('datasubmit'))
2019-05-03 23:52:08 +03:00
{
//check data ...
if (empty(p('sitename')) || empty(p('siteurl')) || empty(p('sitemail'))
|| empty(p('username')) || empty(p('password')) || empty(p('password2')) || empty(p('email')))
{
echo $lang['EMPTY_FIELDS'];
echo gettpl('footer.html');
2019-05-03 23:52:08 +03:00
exit();
}
2019-05-03 23:52:08 +03:00
//fix bug #r1777 (alta3rq revision)
if (! empty(p('password')) && ! empty(p('password2')) && p('password') != p('password2'))
{
echo $lang['PASS_NEQ_PASS2'];
echo gettpl('footer.html');
2019-05-03 23:52:08 +03:00
exit();
}
2018-01-09 02:09:07 +03:00
if (strpos(p('email'), '@') === false)
{
echo $lang['WRONG_EMAIL'];
echo gettpl('footer.html');
2019-05-03 23:52:08 +03:00
exit();
}
2019-05-03 23:52:08 +03:00
//connect .. for check
$SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname, $dbprefix);
2019-05-03 23:52:08 +03:00
include_once PATH . 'includes/usr.php';
include_once PATH . 'includes/functions_alternative.php';
$usrcp = new usrcp;
2019-05-03 23:52:08 +03:00
$user_salt = substr(base64_encode(pack('H*', sha1(mt_rand()))), 0, 7);
$user_pass = $usrcp->kleeja_hash_password(p('password') . $user_salt);
$user_name = $SQL->escape(p('username'));
$user_mail = $SQL->escape(p('email'));
$config_sitename = $SQL->escape(p('sitename'));
$config_siteurl = $SQL->escape(p('siteurl'));
$config_sitemail = $SQL->escape(p('sitemail'));
$config_time_zone = $SQL->escape(p('time_zone'));
//$config_style = ip('style') ? $SQL->escape(p('style')) : '';
$config_urls_type = in_array(p('urls_type'), ['id', 'filename', 'direct']) ? p('urls_type') : 'id';
$clean_name = $usrcp->cleanusername($SQL->escape($user_name));
2019-05-03 23:52:08 +03:00
/// ok .. we will get sqls now ..
include 'includes/install_sqls.php';
include 'includes/default_values.php';
2019-05-03 23:52:08 +03:00
$err = $dots = 0;
$errors = '';
2019-05-03 23:52:08 +03:00
//do important alter before
$SQL->query($install_sqls['ALTER_DATABASE_UTF']);
$sqls_done = $sql_err = [];
foreach ($install_sqls as $name=>$sql_content)
2019-05-03 23:52:08 +03:00
{
if ($name == 'DROP_TABLES' || $name == 'ALTER_DATABASE_UTF')
2019-05-03 23:52:08 +03:00
{
continue;
2019-05-03 23:52:08 +03:00
}
if ($SQL->query($sql_content))
2019-05-03 23:52:08 +03:00
{
if ($name == 'call')
{
$sqls_done[] = $lang['INST_CRT_CALL'];
}
elseif ($name == 'reports')
{
$sqls_done[] = $lang['INST_CRT_REPRS'];
}
elseif ($name == 'stats')
{
$sqls_done[] = $lang['INST_CRT_STS'];
}
elseif ($name == 'users')
{
$sqls_done[] = $lang['INST_CRT_USRS'];
}
elseif ($name == 'users')
{
$sqls_done[] = $lang['INST_CRT_ADM'];
}
elseif ($name == 'files')
{
$sqls_done[] = $lang['INST_CRT_FLS'];
}
elseif ($name == 'config')
{
$sqls_done[] = $lang['INST_CRT_CNF'];
}
elseif ($name == 'exts')
{
$sqls_done[] = $lang['INST_CRT_EXT'];
}
elseif ($name == 'online')
{
$sqls_done[] = $lang['INST_CRT_ONL'];
}
elseif ($name == 'hooks')
{
$sqls_done[] = $lang['INST_CRT_HKS'];
}
elseif ($name == 'plugins')
{
$sqls_done[] = $lang['INST_CRT_PLG'];
}
elseif ($name == 'lang')
{
$sqls_done[] = $lang['INST_CRT_LNG'];
}
else
{
$sqls_done[] = $name . '...';
}
2019-05-03 23:52:08 +03:00
}
else
2019-05-03 23:52:08 +03:00
{
$errors .= implode(':', $SQL->get_error()) . '' . "\n___\n";
$sql_err[] = $lang['INST_SQL_ERR'] . ' : ' . $name . '[basic]';
2019-05-03 23:52:08 +03:00
$err++;
}
}//for
2019-05-03 23:52:08 +03:00
if ($err == 0)
2019-05-03 23:52:08 +03:00
{
//add configs
foreach ($config_values as $cn)
2019-05-03 23:52:08 +03:00
{
if (empty($cn[6]))
{
$cn[6] = 0;
}
$sql = "INSERT INTO `{$dbprefix}config` (`name`, `value`, `option`, `display_order`, `type`, `plg_id`, `dynamic`) VALUES ('$cn[0]', '$cn[1]', '$cn[2]', '$cn[3]', '$cn[4]', '$cn[5]', '$cn[6]');";
if (! $SQL->query($sql))
{
$errors .= implode(':', $SQL->get_error()) . '' . "\n___\n";
$sql_err[] = $lang['INST_SQL_ERR'] . ' : [configs_values] ' . $cn;
$err++;
}
2019-05-03 23:52:08 +03:00
}
//add groups configs
foreach ($config_values as $cn)
2019-05-03 23:52:08 +03:00
{
if ($cn[4] != 'groups' or ! $cn[4])
{
continue;
}
$itxt = '';
foreach ([1, 2, 3] as $im)
{
$itxt .= ($itxt == '' ? '' : ',') . "($im, '$cn[0]', '$cn[1]')";
}
$sql = "INSERT INTO `{$dbprefix}groups_data` (`group_id`, `name`, `value`) VALUES " . $itxt . ';';
if (! $SQL->query($sql))
{
$errors .= implode(':', $SQL->get_error()) . '' . "\n___\n";
$sql_err[] = $lang['INST_SQL_ERR'] . ' : [groups_configs_values] ' . $cn;
$err++;
}
2019-05-03 23:52:08 +03:00
}
//add exts
foreach ($ext_values as $gid=>$exts)
2019-05-03 23:52:08 +03:00
{
$itxt = '';
2019-05-03 23:52:08 +03:00
foreach ($exts as $t=>$v)
{
$itxt .= ($itxt == '' ? '' : ',') . "('$t', $gid, $v)";
}
2019-05-03 23:52:08 +03:00
$sql = "INSERT INTO `{$dbprefix}groups_exts` (`ext`, `group_id`, `size`) VALUES " . $itxt . ';';
2019-05-03 23:52:08 +03:00
if (! $SQL->query($sql))
{
$errors .= implode(':', $SQL->get_error()) . '' . "\n___\n";
$sql_err[] = $lang['INST_SQL_ERR'] . ' : [ext_values] ' . $gid;
$err++;
}
2019-05-03 23:52:08 +03:00
}
//add acls
foreach ($acls_values as $cn=>$ct)
2019-05-03 23:52:08 +03:00
{
$it = 1;
$itxt = '';
2019-05-03 23:52:08 +03:00
foreach ($ct as $ctk)
{
$itxt .= ($itxt == '' ? '' : ',') . "('$cn', '$it', '$ctk')";
$it++;
}
2019-05-03 23:52:08 +03:00
$sql = "INSERT INTO `{$dbprefix}groups_acl` (`acl_name`, `group_id`, `acl_can`) VALUES " . $itxt . ';';
if (! $SQL->query($sql))
{
$errors .= implode(':', $SQL->get_error()) . '' . "\n___\n";
$sql_err[] = $lang['INST_SQL_ERR'] . ' : [acl_values] ' . $cn;
$err++;
}
$it++;
2019-05-03 23:52:08 +03:00
}
}
echo gettpl('sqls_done.html');
}
else
{
$urlsite = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('install', '', dirname($_SERVER['PHP_SELF']));
echo gettpl('data.html');
}
2018-01-09 02:09:07 +03:00
break;
2018-01-09 02:09:07 +03:00
case 'end' :
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
echo gettpl('end.html');
2019-05-03 23:52:08 +03:00
//for safe ..
//@rename("install.php", "install.lock");
break;
2018-01-09 02:09:07 +03:00
}
/**
* print footer
*/
echo gettpl('footer.html');