2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2009-06-04 02:44:32 +04:00
|
|
|
* This file is part of Mibew Messenger project.
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2011-02-16 03:22:22 +03:00
|
|
|
* Copyright (c) 2005-2011 Mibew Messenger Community
|
2009-08-04 19:03:27 +04:00
|
|
|
* All rights reserved. The contents of this file are subject to the terms of
|
|
|
|
* the Eclipse Public License v1.0 which accompanies this distribution, and
|
|
|
|
* is available at http://www.eclipse.org/legal/epl-v10.html
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2009-08-04 17:38:37 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* the GNU General Public License Version 2 or later (the "GPL"), in which case
|
|
|
|
* the provisions of the GPL are applicable instead of those above. If you wish
|
|
|
|
* to allow use of your version of this file only under the terms of the GPL, and
|
|
|
|
* not to allow others to use your version of this file under the terms of the
|
|
|
|
* EPL, indicate your decision by deleting the provisions above and replace them
|
|
|
|
* with the notice and other provisions required by the GPL.
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2007-10-10 19:15:47 +04:00
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('../libs/common.php');
|
2009-02-04 03:31:26 +03:00
|
|
|
require_once('../libs/settings.php');
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('dbinfo.php');
|
2007-10-17 14:43:34 +04:00
|
|
|
|
|
|
|
$page = array(
|
|
|
|
'version' => $version,
|
2007-10-30 15:13:04 +03:00
|
|
|
'localeLinks' => get_locale_links("$webimroot/install/index.php")
|
2007-10-17 14:43:34 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
$page['done'] = array();
|
|
|
|
$page['nextstep'] = false;
|
|
|
|
$page['nextnotice'] = false;
|
2011-02-27 03:54:27 +03:00
|
|
|
$page['soundcheck'] = false;
|
2007-10-17 14:43:34 +04:00
|
|
|
$errors = array();
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_webimroot()
|
|
|
|
{
|
2011-02-16 03:33:09 +03:00
|
|
|
global $page, $errors, $webimroot;
|
|
|
|
$requestUri = $_SERVER["REQUEST_URI"];
|
2011-02-26 16:57:23 +03:00
|
|
|
if (!preg_match('/^(.*)\\/install(\\/[^\\/\\\\]*)?$/', $requestUri, $matches)) {
|
2011-02-16 03:33:09 +03:00
|
|
|
$errors[] = "Cannot detect application location: $requestUri";
|
2011-02-26 16:57:23 +03:00
|
|
|
return false;
|
2011-02-16 03:33:09 +03:00
|
|
|
}
|
|
|
|
$applocation = $matches[1];
|
2011-02-26 16:57:23 +03:00
|
|
|
|
|
|
|
if ($applocation != $webimroot) {
|
2011-02-16 03:33:09 +03:00
|
|
|
$errors[] = "Please, check file ${applocation}/libs/config.php<br/>Wrong value of \$webimroot variable, should be \"$applocation\"";
|
|
|
|
$webimroot = $applocation;
|
2011-02-26 16:57:23 +03:00
|
|
|
return false;
|
2011-02-16 03:33:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$page['done'][] = getlocal2("install.0.app", array($applocation));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-05 01:01:24 +03:00
|
|
|
function fpermissions($file)
|
|
|
|
{
|
|
|
|
$perms = fileperms($file);
|
|
|
|
if (($perms & 0x8000) == 0x8000) {
|
|
|
|
$info = '-';
|
|
|
|
} elseif (($perms & 0x4000) == 0x4000) {
|
|
|
|
$info = 'd';
|
|
|
|
} else {
|
|
|
|
$info = '?';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Owner
|
|
|
|
$info .= (($perms & 0x0100) ? 'r' : '-');
|
|
|
|
$info .= (($perms & 0x0080) ? 'w' : '-');
|
|
|
|
$info .= (($perms & 0x0040) ?
|
|
|
|
(($perms & 0x0800) ? 's' : 'x') :
|
|
|
|
(($perms & 0x0800) ? 'S' : '-'));
|
|
|
|
|
|
|
|
// Group
|
|
|
|
$info .= (($perms & 0x0020) ? 'r' : '-');
|
|
|
|
$info .= (($perms & 0x0010) ? 'w' : '-');
|
|
|
|
$info .= (($perms & 0x0008) ?
|
|
|
|
(($perms & 0x0400) ? 's' : 'x') :
|
|
|
|
(($perms & 0x0400) ? 'S' : '-'));
|
|
|
|
|
|
|
|
// World
|
|
|
|
$info .= (($perms & 0x0004) ? 'r' : '-');
|
|
|
|
$info .= (($perms & 0x0002) ? 'w' : '-');
|
|
|
|
$info .= (($perms & 0x0001) ?
|
|
|
|
(($perms & 0x0200) ? 't' : 'x') :
|
|
|
|
(($perms & 0x0200) ? 'T' : '-'));
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_files()
|
|
|
|
{
|
|
|
|
global $page, $errors, $webimroot;
|
|
|
|
|
|
|
|
$packageFile = dirname(__FILE__) . "/package";
|
|
|
|
$fp = @fopen($packageFile, "r");
|
|
|
|
if ($fp === FALSE) {
|
|
|
|
$errors[] = "Cannot open file $webimroot/install/package";
|
|
|
|
if (file_exists($packageFile)) {
|
|
|
|
$errors[] = getlocal2("install.check_permissions", array(fpermissions($packageFile)));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$knownFiles = array();
|
|
|
|
while (!feof($fp)) {
|
|
|
|
$line = fgets($fp, 4096);
|
|
|
|
$keyval = preg_split("/ /", $line, 2);
|
|
|
|
if (isset($keyval[1])) {
|
|
|
|
$knownFiles[$keyval[0]] = trim($keyval[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
foreach ($knownFiles as $file => $sum) {
|
|
|
|
$relativeName = dirname(__FILE__) . "/../$file";
|
|
|
|
if (!is_readable($relativeName)) {
|
|
|
|
if (file_exists($relativeName)) {
|
|
|
|
$errors[] = "Cannot read file $webimroot/$file";
|
|
|
|
$errors[] = getlocal2("install.check_permissions", array(fpermissions($relativeName)));
|
|
|
|
} else {
|
|
|
|
$errors[] = "File is absent: $webimroot/$file";
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($sum != "-") {
|
|
|
|
$result = md5_file($relativeName);
|
|
|
|
if ($result != $sum) {
|
|
|
|
$errors[] = "Checksum differs for $webimroot/$file";
|
|
|
|
$errors[] = getlocal("install.check_files");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page['done'][] = getlocal("install.0.package");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_connection()
|
|
|
|
{
|
|
|
|
global $mysqlhost, $mysqllogin, $mysqlpass, $page, $errors, $webimroot;
|
|
|
|
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass);
|
2007-10-17 14:43:34 +04:00
|
|
|
if ($link) {
|
|
|
|
$result = mysql_query("SELECT VERSION() as c", $link);
|
2011-02-26 16:57:23 +03:00
|
|
|
if ($result && $ver = mysql_fetch_array($result, MYSQL_ASSOC)) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal2("install.1.connected", array($ver['c']));
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_free_result($result);
|
|
|
|
} else {
|
2011-02-26 16:57:23 +03:00
|
|
|
$errors[] = "Version of your SQL server is unknown. Please check. Error: " . mysql_error($link);
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_close($link);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $link;
|
|
|
|
} else {
|
2008-05-06 15:14:48 +04:00
|
|
|
$errors[] = getlocal2("install.connection.error", array(mysql_error()));
|
2007-10-17 14:43:34 +04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_database($link)
|
|
|
|
{
|
2008-09-30 02:59:58 +04:00
|
|
|
global $mysqldb, $force_charset_in_connection, $dbencoding, $page, $webimroot;
|
2011-02-26 16:57:23 +03:00
|
|
|
if (mysql_select_db($mysqldb, $link)) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
|
2011-02-26 16:57:23 +03:00
|
|
|
if ($force_charset_in_connection) {
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_query("SET character set $dbencoding", $link);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal2("install.2.create", array($mysqldb));
|
|
|
|
$page['nextnotice'] = getlocal("install.2.notice");
|
2008-09-30 02:59:58 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=createdb";
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_tables($link)
|
|
|
|
{
|
2008-09-30 02:59:58 +04:00
|
|
|
global $dbtables, $page, $webimroot;
|
2007-10-17 14:43:34 +04:00
|
|
|
$curr_tables = get_tables($link);
|
2011-02-26 16:57:23 +03:00
|
|
|
if ($curr_tables !== false) {
|
2007-10-17 14:43:34 +04:00
|
|
|
$tocreate = array_diff(array_keys($dbtables), $curr_tables);
|
2011-02-26 16:57:23 +03:00
|
|
|
if (count($tocreate) == 0) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal("install.3.tables_exist");
|
2007-10-17 14:43:34 +04:00
|
|
|
return true;
|
|
|
|
} else {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("install.3.create");
|
2009-05-31 19:29:55 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=ct";
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_columns($link)
|
|
|
|
{
|
2008-09-30 02:59:58 +04:00
|
|
|
global $dbtables, $dbtables_can_update, $errors, $page, $webimroot;
|
2007-10-17 14:43:34 +04:00
|
|
|
|
|
|
|
$need_to_create_columns = false;
|
2011-02-26 16:57:23 +03:00
|
|
|
foreach ($dbtables as $id => $columns) {
|
2007-10-17 14:43:34 +04:00
|
|
|
$curr_columns = get_columns($id, $link);
|
2011-02-26 16:57:23 +03:00
|
|
|
if ($curr_columns === false) {
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$tocreate = array_diff(array_keys($columns), $curr_columns);
|
2011-02-26 16:57:23 +03:00
|
|
|
if (count($tocreate) != 0) {
|
2007-10-17 14:43:34 +04:00
|
|
|
$cannot_update = array_diff($tocreate, $dbtables_can_update[$id]);
|
2011-02-26 16:57:23 +03:00
|
|
|
if (count($cannot_update) != 0) {
|
2007-10-17 14:43:34 +04:00
|
|
|
$errors[] = "Key columns are absent in table `$id'. Unable to continue installation.";
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("install.kill_tables");
|
2009-05-31 19:29:55 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=dt";
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextnotice'] = getlocal("install.kill_tables.notice");
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$need_to_create_columns = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
if ($need_to_create_columns) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("install.4.create");
|
2008-09-30 02:59:58 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=addcolumns";
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextnotice'] = getlocal("install.4.notice");
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal("install.4.done");
|
2007-10-17 14:43:34 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-05 01:01:24 +03:00
|
|
|
function check_sound()
|
|
|
|
{
|
2011-02-27 03:54:27 +03:00
|
|
|
global $page;
|
|
|
|
|
|
|
|
$page['soundcheck'] = true;
|
|
|
|
$page['done'][] = getlocal2("install.5.text", array(
|
2011-03-05 01:01:24 +03:00
|
|
|
"<a id='check-nv' href='javascript:void(0)'>" . getlocal("install.5.newvisitor") . "</a>",
|
|
|
|
"<a id='check-nm' href='javascript:void(0)'>" . getlocal("install.5.newmessage") . "</a>"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_admin($link)
|
|
|
|
{
|
|
|
|
global $mysqlprefix;
|
|
|
|
$result = mysql_query("select * from ${mysqlprefix}chatoperator where vclogin = 'admin'", $link);
|
|
|
|
if ($result) {
|
|
|
|
$line = mysql_fetch_array($result, MYSQL_ASSOC);
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $line['vcpassword'] != md5('');
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-02-27 03:54:27 +03:00
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_status()
|
|
|
|
{
|
2009-02-04 03:31:26 +03:00
|
|
|
global $page, $webimroot, $settings, $dbversion;
|
2011-02-26 16:57:23 +03:00
|
|
|
|
|
|
|
if (!check_webimroot()) {
|
2011-02-16 03:33:09 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-02-26 16:57:23 +03:00
|
|
|
|
2011-03-05 01:01:24 +03:00
|
|
|
if (!check_files()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
$link = check_connection();
|
2011-02-26 16:57:23 +03:00
|
|
|
if (!$link) {
|
2007-10-17 14:43:34 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
if (!check_database($link)) {
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_close($link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
if (!check_tables($link)) {
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_close($link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
if (!check_columns($link)) {
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_close($link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-27 03:54:27 +03:00
|
|
|
check_sound();
|
|
|
|
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal("installed.message");
|
2007-10-17 14:43:34 +04:00
|
|
|
|
2011-03-05 01:01:24 +03:00
|
|
|
if (!check_admin($link)) {
|
|
|
|
$page['nextstep'] = getlocal("installed.login_link");
|
|
|
|
$page['nextnotice'] = getlocal2("installed.notice", array("${webimroot}/install/"));
|
|
|
|
$page['nextstepurl'] = "$webimroot/";
|
|
|
|
}
|
2011-02-26 16:57:23 +03:00
|
|
|
|
2009-03-13 03:52:37 +03:00
|
|
|
$page['show_small_login'] = true;
|
2007-10-17 14:43:34 +04:00
|
|
|
|
|
|
|
mysql_close($link);
|
2009-02-04 03:31:26 +03:00
|
|
|
|
|
|
|
loadsettings();
|
|
|
|
$settings['dbversion'] = $dbversion;
|
|
|
|
update_settings();
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
check_status();
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
start_html_output();
|
2009-03-12 04:07:35 +03:00
|
|
|
require('../view/install_index.php');
|
2007-10-17 14:43:34 +04:00
|
|
|
?>
|