2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2013-03-07 01:22:53 +04:00
|
|
|
* Copyright 2005-2013 the original author or authors.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2007-10-10 19:15:47 +04:00
|
|
|
*/
|
|
|
|
|
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) {
|
2011-03-05 01:34:00 +03:00
|
|
|
$errors[] = getlocal2("install.cannot_read", array("$webimroot/install/package"));
|
2011-03-05 01:01:24 +03:00
|
|
|
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)) {
|
2011-03-05 01:34:00 +03:00
|
|
|
$errors[] = getlocal2("install.cannot_read", array("$webimroot/$file"));
|
2011-03-05 01:01:24 +03:00
|
|
|
$errors[] = getlocal2("install.check_permissions", array(fpermissions($relativeName)));
|
|
|
|
} else {
|
2011-03-05 01:34:00 +03:00
|
|
|
$errors[] = getlocal2("install.no_file", array("$webimroot/$file"));
|
2011-03-05 01:01:24 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($sum != "-") {
|
|
|
|
$result = md5_file($relativeName);
|
|
|
|
if ($result != $sum) {
|
2011-03-05 01:34:00 +03:00
|
|
|
// try without \r
|
|
|
|
$result = md5(str_replace("\r", "", file_get_contents($relativeName)));
|
|
|
|
}
|
|
|
|
if ($result != $sum) {
|
|
|
|
$errors[] = getlocal2("install.bad_checksum", array("$webimroot/$file"));
|
2011-03-05 01:01:24 +03:00
|
|
|
$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)
|
|
|
|
{
|
2012-02-26 18:00:24 +04:00
|
|
|
global $dbtables, $dbtables_can_update, $dbtables_indexes, $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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-26 18:00:24 +04:00
|
|
|
$need_to_create_indexes = false;
|
|
|
|
foreach ($dbtables_indexes as $id => $indexes) {
|
|
|
|
$curr_indexes = get_indexes($id, $link);
|
|
|
|
if ($curr_indexes === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$tocreate = array_diff(array_keys($indexes), $curr_indexes);
|
|
|
|
if (count($tocreate) != 0) {
|
|
|
|
$need_to_create_indexes = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($need_to_create_columns || $need_to_create_indexes) {
|
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
|
|
|
}
|
|
|
|
|
2012-01-27 01:29:26 +04:00
|
|
|
function add_canned_messages($link){
|
|
|
|
global $mysqlprefix;
|
2012-01-29 01:52:44 +04:00
|
|
|
$localesresult = mysql_query("select locale from ${mysqlprefix}chatresponses", $link);
|
|
|
|
$existlocales = array();
|
|
|
|
for ($i = 0; $i < mysql_num_rows($localesresult); $i++) {
|
|
|
|
$existlocales[] = mysql_result($localesresult, $i, 'locale');
|
|
|
|
}
|
|
|
|
$result = array();
|
2012-01-27 01:29:26 +04:00
|
|
|
foreach (get_available_locales() as $locale) {
|
2012-01-29 01:52:44 +04:00
|
|
|
if (! in_array($locale, $existlocales)) {
|
|
|
|
foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
|
|
|
|
$result[] = array('locale' => $locale, 'vctitle' => cutstring($answer, 97, '...'), 'vcvalue' => $answer);
|
|
|
|
}
|
2012-01-27 01:29:26 +04:00
|
|
|
}
|
2012-01-29 01:52:44 +04:00
|
|
|
}
|
|
|
|
if (count($result) > 0) {
|
|
|
|
$updatequery = "insert into ${mysqlprefix}chatresponses (vctitle,vcvalue,locale,groupid) values ";
|
|
|
|
for ($i = 0; $i < count($result); $i++) {
|
|
|
|
if ($i > 0) {
|
|
|
|
$updatequery .= ", ";
|
2012-01-27 01:29:26 +04:00
|
|
|
}
|
2012-01-29 01:52:44 +04:00
|
|
|
$updatequery .= "('" . mysql_real_escape_string($result[$i]['vctitle'], $link) . "', "
|
|
|
|
. "'" . mysql_real_escape_string($result[$i]['vcvalue'], $link) . "', "
|
|
|
|
. "'" . mysql_real_escape_string($result[$i]['locale'], $link) . "', NULL)";
|
2012-01-27 01:29:26 +04:00
|
|
|
}
|
2012-01-29 01:52:44 +04:00
|
|
|
mysql_query($updatequery, $link);
|
2012-01-27 01:29:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function check_status()
|
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
global $page, $webimroot, $dbversion;
|
2011-02-26 16:57:23 +03:00
|
|
|
|
2011-03-05 01:34:00 +03:00
|
|
|
$page['done'][] = getlocal2("install.0.php", array(phpversion()));
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-27 01:29:26 +04:00
|
|
|
add_canned_messages($link);
|
|
|
|
|
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/"));
|
2012-03-15 01:18:54 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/operator/login.php?login=admin";
|
2011-03-05 01:01:24 +03:00
|
|
|
}
|
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
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
Settings::set('dbversion', $dbversion);
|
|
|
|
Settings::update();
|
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
|
|
|
?>
|