diff --git a/src/webim/INSTALL.txt b/src/webim/INSTALL.txt index b60c5e80..2d734666 100644 --- a/src/webim/INSTALL.txt +++ b/src/webim/INSTALL.txt @@ -1,5 +1,5 @@ -Web Instant Messenger 1.0.7 +Web Instant Messenger 1.0.8 Copyright (c) 2005-2007 Internet Services Ltd. This program and the accompanying materials are made available under diff --git a/src/webim/install/dbinfo.php b/src/webim/install/dbinfo.php new file mode 100644 index 00000000..b4e303d0 --- /dev/null +++ b/src/webim/install/dbinfo.php @@ -0,0 +1,135 @@ + array( + "threadid" => "int NOT NULL auto_increment PRIMARY KEY", + "userName" => "varchar(64) NOT NULL", + "agentName" => "varchar(64)", + "agentId" => "int NOT NULL DEFAULT 0", + "dtmcreated" => "datetime DEFAULT 0", + "dtmmodified" => "datetime DEFAULT 0", + "lrevision" => "int NOT NULL DEFAULT 0", + "istate" => "int NOT NULL DEFAULT 0", + "ltoken" => "int NOT NULL", + "remote" => "varchar(255)", + "referer" => "text", + "locale" => "varchar(8)", + "lastpinguser" => "datetime DEFAULT 0", + "lastpingagent" => "datetime DEFAULT 0" + ), + + "chatmessage" => array( + "messageid" => "int NOT NULL auto_increment PRIMARY KEY", + "threadid" => "int NOT NULL references chatthread(threadid)", + "ikind" => "int NOT NULL", + "agentId" => "int NOT NULL DEFAULT 0", + "tmessage" => "text NOT NULL", + "dtmcreated" => "datetime DEFAULT 0", + "tname" => "varchar(64)" + ), + + "chatoperator" => array( + "operatorid" => "int NOT NULL auto_increment PRIMARY KEY", + "vclogin" => "varchar(64) NOT NULL", + "vcpassword" => "varchar(64) NOT NULL", + "vclocalename" => "varchar(64) NOT NULL", + "vccommonname" => "varchar(64) NOT NULL", + "dtmlastvisited" => "datetime DEFAULT 0", + ), + + "chatrevision" => array( + "id" => "INT NOT NULL" + ) +); + +$dbtables_can_update = array( + "chatthread" => array("agentId"), + "chatmessage" => array("agentId") +); + +function show_install_err($text) { + global $page, $version, $errors; + $page = array( + 'version' => $version, + 'localeLinks' => get_locale_links("/webim/install/index.php") + ); + $errors = array($text); + start_html_output(); + require('view_installerr.php'); + exit; +} + +function create_table($id,$link) { + global $dbtables, $dbencoding; + + if(!isset($dbtables[$id])) { + show_install_err("Unknown table: $id, ".mysql_error()); + } + + $query = + "CREATE TABLE $id\n". + "(\n"; + foreach( $dbtables[$id] as $k => $v ) { + $query .= " $k $v,\n"; + } + + $query = preg_replace("/,\n$/", "", $query); + $query .= ") charset $dbencoding\n"; + mysql_query($query,$link) + or show_install_err(' Query failed: '.mysql_error()); + + // post create + if( $id == 'chatoperator' ) { + create_operator_("admin", "", "Administrator", "Administrator", $link); + } else if( $id == 'chatrevision' ) { + perform_query("INSERT INTO chatrevision VALUES (1)",$link); + } +} + +function get_tables($link) { + global $mysqldb, $errors; + $result = mysql_query("SHOW TABLES FROM $mysqldb"); + if( $result ) { + $arr = array(); + while ($row = mysql_fetch_array($result, MYSQL_NUM)) { + $arr[] = $row[0]; + } + mysql_free_result($result); + return $arr; + + } else { + $errors[] = "Cannot get tables from database. Error: ".mysql_error(); + return false; + } +} + +function get_columns($tablename,$link) { + global $errors; + $result = mysql_query("SHOW COLUMNS FROM $tablename"); + if( $result ) { + $arr = array(); + while ($row = mysql_fetch_array($result, MYSQL_NUM)) { + $arr[] = $row[0]; + } + mysql_free_result($result); + return $arr; + + } else { + $errors[] = "Cannot get columns from table \"$tablename\". Error: ".mysql_error(); + return false; + } +} + +?> \ No newline at end of file diff --git a/src/webim/install/dbperform.php b/src/webim/install/dbperform.php new file mode 100644 index 00000000..e48245d0 --- /dev/null +++ b/src/webim/install/dbperform.php @@ -0,0 +1,80 @@ + $columns) { + $curr_columns = get_columns($id, $link); + if( $curr_columns === false ) { + show_install_err($errors[0]); + } + $tocreate = array_diff(array_keys($columns), $curr_columns); + foreach($tocreate as $v) { + $absent[] = "$id.$v"; + } + } + + if( in_array("chatmessage.agentId", $absent) ) { + runsql("ALTER TABLE chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link); + runsql("update chatmessage,chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link); + } + + if( in_array("chatthread.agentId", $absent) ) { + runsql("ALTER TABLE chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link); + runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); + } + } +} + +mysql_close($link); +header("Location: ".dirname($_SERVER['PHP_SELF'])."/index.php"); +exit; +?> \ No newline at end of file diff --git a/src/webim/install/index.php b/src/webim/install/index.php index 4a2cd1e5..4c19456c 100644 --- a/src/webim/install/index.php +++ b/src/webim/install/index.php @@ -13,7 +13,138 @@ */ require('../libs/common.php'); +require('dbinfo.php'); + +$page = array( + 'version' => $version, + 'localeLinks' => get_locale_links("/webim/install/index.php") +); + + +$page['done'] = array(); +$page['nextstep'] = false; +$page['nextnotice'] = false; +$errors = array(); + +function check_connection() { + global $mysqlhost,$mysqllogin,$mysqlpass, $page, $errors; + $link = @mysql_connect($mysqlhost,$mysqllogin,$mysqlpass); + if ($link) { + $result = mysql_query("SELECT VERSION() as c", $link); + if( $result && $ver = mysql_fetch_array($result, MYSQL_ASSOC)) { + $page['done'][] = getstring2("install.1.connected", array($ver['c'])); + mysql_free_result($result); + } else { + $errors[] = "Version of your SQL server is unknown. Please check. Error: ".mysql_error(); + mysql_close($link); + return null; + } + return $link; + } else { + $errors[] = getstring2("install.connection.error", array(mysql_error())); + return null; + } +} + +function check_database($link) { + global $mysqldb, $force_charset_in_connection, $dbencoding, $page; + if(mysql_select_db($mysqldb,$link)) { + $page['done'][] = getstring2("install.2.db_exists", array($mysqldb)); + if( $force_charset_in_connection ) { + mysql_query("SET character set $dbencoding", $link); + } + return true; + } else { + $page['nextstep'] = getstring2("install.2.create", array($mysqldb)); + $page['nextnotice'] = getstring("install.2.notice"); + $page['nextstepurl'] = "dbperform.php?act=createdb"; + } + return false; +} + +function check_tables($link) { + global $dbtables, $page; + $curr_tables = get_tables($link); + if( $curr_tables !== false) { + $tocreate = array_diff(array_keys($dbtables), $curr_tables); + if( count($tocreate) == 0 ) { + $page['done'][] = getstring("install.3.tables_exist"); + return true; + } else { + $page['nextstep'] = getstring("install.3.create"); + $page['nextstepurl'] = "dbperform.php?act=createtables"; + } + } + return false; +} + +function check_columns($link) { + global $dbtables, $dbtables_can_update, $errors, $page; + + $need_to_create_columns = false; + foreach( $dbtables as $id => $columns) { + $curr_columns = get_columns($id, $link); + if( $curr_columns === false ) { + return false; + } + $tocreate = array_diff(array_keys($columns), $curr_columns); + if( count($tocreate) != 0 ) { + $cannot_update = array_diff($tocreate, $dbtables_can_update[$id]); + if( count($cannot_update) != 0) { + $errors[] = "Key columns are absent in table `$id'. Unable to continue installation."; + $page['nextstep'] = getstring("install.kill_tables"); + $page['nextstepurl'] = "dbperform.php?act=droptables"; + $page['nextnotice'] = getstring("install.kill_tables.notice"); + return false; + } + $need_to_create_columns = true; + } + } + + if( $need_to_create_columns ) { + $page['nextstep'] = getstring("install.4.create"); + $page['nextstepurl'] = "dbperform.php?act=addcolumns"; + $page['nextnotice'] = getstring("install.4.notice"); + return false; + } + + $page['done'][] = getstring("install.4.done"); + return true; +} + +function check_status() { + global $page; + $link = check_connection(); + if(!$link) { + return; + } + + if( !check_database($link)) { + mysql_close($link); + return; + } + + if( !check_tables($link)) { + mysql_close($link); + return; + } + + if( !check_columns($link)) { + mysql_close($link); + return; + } + + $page['done'][] = getstring("installed.message"); + + $page['nextstep'] = getstring("installed.login_link"); + $page['nextnotice'] = getstring("installed.notice"); + $page['nextstepurl'] = "/webim/"; + + mysql_close($link); +} + +check_status(); start_html_output(); require('view_index.php'); -?> +?> \ No newline at end of file diff --git a/src/webim/install/install.php b/src/webim/install/install.php deleted file mode 100644 index cbdf2b68..00000000 --- a/src/webim/install/install.php +++ /dev/null @@ -1,98 +0,0 @@ - \ No newline at end of file diff --git a/src/webim/install/view_index.php b/src/webim/install/view_index.php index 461ad0c6..526b1b3b 100644 --- a/src/webim/install/view_index.php +++ b/src/webim/install/view_index.php @@ -39,15 +39,66 @@ -
-
+
+
+ 0 ) { ?> + + + + + + +
+ 0 ) { + print getstring("errors.header"); + foreach( $errors as $e ) { + print getstring("errors.prefix"); + print $e; + print getstring("errors.suffix"); + } + print getstring("errors.footer"); + } ?> - +
+ -
-
+ +
+ + + +
+ +
    + +
  • + +
+
+ +
    +
  • +

    + +
  • +
+
+ + + + + + + + + + + + +
+ +Web Messenger/ - diff --git a/src/webim/install/view_install.php b/src/webim/install/view_installerr.php similarity index 50% rename from src/webim/install/view_install.php rename to src/webim/install/view_installerr.php index 5633634a..49688073 100644 --- a/src/webim/install/view_install.php +++ b/src/webim/install/view_installerr.php @@ -22,7 +22,7 @@ - <?php echo getstring("app.title") ?> - <?php echo getstring("installed.title") ?> + <?php echo getstring("app.title") ?> - <?php echo getstring("install.err.title") ?> "> @@ -35,19 +35,47 @@ -

+

- -
-
+ 0 ) { ?> + + + + + + +
+ 0 ) { + print getstring("errors.header"); + foreach( $errors as $e ) { + print getstring("errors.prefix"); + print $e; + print getstring("errors.suffix"); + } + print getstring("errors.footer"); + } ?> - +
+
-
+ + + + + + + + + + + + +
+ +Web Messenger/ - diff --git a/src/webim/install/whatsnew.txt b/src/webim/install/whatsnew.txt index f30c4b9a..4b060a6f 100644 --- a/src/webim/install/whatsnew.txt +++ b/src/webim/install/whatsnew.txt @@ -1,4 +1,9 @@ + 1.0.8 + ----- + + [+] install/update wizard + 1.0.7 ----- diff --git a/src/webim/libs/common.php b/src/webim/libs/common.php index c9931e26..c8c0c1f9 100644 --- a/src/webim/libs/common.php +++ b/src/webim/libs/common.php @@ -18,6 +18,7 @@ require(dirname(__FILE__).'/converter.php'); require(dirname(__FILE__).'/config.php'); $webimroot = "/webim"; # absolute path on server +$version = 'v1.0.8 pre1'; function myiconv($in_enc, $out_enc, $string) { global $_utf8win1251, $_win1251utf8; @@ -120,6 +121,20 @@ function set_locale($locale) { $current_locale = get_locale(); $messages = array(); +function get_locale_links($href) { + global $available_locales, $current_locale; + $localeLinks = ""; + foreach($available_locales as $k) { + if( strlen($localeLinks) > 0 ) + $localeLinks .= " • "; + if( $k == $current_locale ) + $localeLinks .= $k; + else + $localeLinks .= "$k"; + } + return $localeLinks; +} + function load_messages($locale) { global $messages; $hash = array(); @@ -167,17 +182,18 @@ function getstring2($text,$params) { function connect() { global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection; - $link = mysql_connect($mysqlhost,$mysqllogin ,$mysqlpass ) + $link = @mysql_connect($mysqlhost,$mysqllogin ,$mysqlpass ) or die('Could not connect: ' . mysql_error()); - mysql_select_db($mysqldb) or die('Could not select database'); - if( $force_charset_in_connection ) + mysql_select_db($mysqldb,$link) or die('Could not select database'); + if( $force_charset_in_connection ) { mysql_query("SET character set $dbencoding", $link); + } return $link; } function perform_query($query,$link) { - mysql_query($query,$link) or die(' Query failed: ' . - mysql_error().": ".$query); + mysql_query($query,$link) + or die(' Query failed: '.mysql_error()/*.": ".$query*/); } function select_one_row($query,$link) { diff --git a/src/webim/libs/operator.php b/src/webim/libs/operator.php index 3282ef62..a3fd36a6 100644 --- a/src/webim/libs/operator.php +++ b/src/webim/libs/operator.php @@ -62,9 +62,7 @@ function update_operator($operatorid,$login,$password,$localename,$commonname) { mysql_close($link); } -function create_operator($login,$password,$localename,$commonname) { - $link = connect(); - +function create_operator_($login,$password,$localename,$commonname,$link) { $query = sprintf( "insert into chatoperator (vclogin,vcpassword,vclocalename,vccommonname) values ('%s','%s','%s','%s')", mysql_real_escape_string($login), @@ -75,7 +73,12 @@ function create_operator($login,$password,$localename,$commonname) { perform_query($query,$link); $id = mysql_insert_id($link); - $newop = select_one_row("select * from chatoperator where operatorid = $id", $link ); + return select_one_row("select * from chatoperator where operatorid = $id", $link ); +} + +function create_operator($login,$password,$localename,$commonname) { + $link = connect(); + $newop = create_operator_($login,$password,$localename,$commonname,$link); mysql_close($link); return $newop; } diff --git a/src/webim/operator/index.php b/src/webim/operator/index.php index cfa3ef61..1877ea8a 100644 --- a/src/webim/operator/index.php +++ b/src/webim/operator/index.php @@ -19,21 +19,10 @@ $operator = check_login(); $page = array( 'operator' => get_operator_name($operator), - 'version' => 'v1.0.7' + 'version' => $version, + 'localeLinks' => get_locale_links("/webim/operator/index.php") ); -$localeLinks = ""; -foreach($available_locales as $k) { - if( strlen($localeLinks) > 0 ) - $localeLinks .= " • "; - if( $k == $current_locale ) - $localeLinks .= $k; - else - $localeLinks .= "$k"; -} - -$page['localeLinks'] = $localeLinks; - start_html_output(); require('../view/menu.php'); ?> \ No newline at end of file diff --git a/src/webim/view/properties_en b/src/webim/view/properties_en index 5c06e5e9..0e2ebec9 100644 --- a/src/webim/view/properties_en +++ b/src/webim/view/properties_en @@ -131,13 +131,28 @@ content.history=Search the dialogs history content.logoff=Log out of the system. form.field.agent_commonname=International name (Latin) form.field.agent_commonname.description=This name will be seen by your visitors -install.create_db_link=Create tables in MySQL database +install.1.connected=You are connected to MySQL server version {0} +install.2.create=Create database "{0}" +install.2.db_exists=Database "{0}" is created. +install.2.notice=Database was not found on server. If you have permissions to create
it now, click on the following link. +install.3.create=Create required tables. +install.3.tables_exist=Requred tables are created. +install.4.create=Update tables +install.4.done=Tables structure is up to date. +install.4.notice=Structure of your tables should be adjusted for new version of Messenger. +install.connection.error=Could not connect, please check server settings in config.php. Error: {0} +install.done=Completed: +install.err.back=Resvole problem and try again. Press back to return to wizard. +install.err.title=Problem +install.kill_tables=Drop existing tables from database +install.kill_tables.notice=Impossible to update tables structure. Try to do it manually or recreate all tables (warning: all your data will be lost). install.license=Software license agreement -install.message=We are ready to complete installation by creating tables. -install.title=System setup +install.message=Follow the wizard to setup your database. +install.next=Next step: +install.title=Installation installed.login_link=Proceed to login page -installed.message=Tables were created successfully. You can logon as admin with empty password. For security reasons, please
change your password immediately and remove /webim/install folder from your server. -installed.title=Application installed successfully +installed.message=Application installed successfully. +installed.notice=You can logon as admin with empty password. For security reasons, please
change your password immediately and remove /webim/install folder from your server. menu.agents=Agents list menu.main=Main menu.operator=You are {0} diff --git a/src/webim/view/properties_ru b/src/webim/view/properties_ru index 43271c1a..3c37acb8 100644 --- a/src/webim/view/properties_ru +++ b/src/webim/view/properties_ru @@ -131,13 +131,28 @@ content.history= content.logoff=Покинуть систему. form.field.agent_commonname=Интернациональное имя (латиницей) form.field.agent_commonname.description=Под этим именем Вас увидят ваши посетители из других стран -install.create_db_link=Создать необходимые таблицы в базе данных +install.1.connected=Вы подсоединены к серверу MySQL версии {0}. +install.2.create=Создать базу данных "{0}" +install.2.db_exists=Создана база данных "{0}". +install.2.notice=База, которую вы выбрали не существует на сервере. Если у вас есть права
на ее создание, ее можно создать сейчас. +install.3.create=Создать необходимые таблицы. +install.3.tables_exist=Необходимые таблицы созданы. +install.4.create=Обновить +install.4.done=Структура таблиц готова к использованию. +install.4.notice=Необходимо обновить структуру таблиц для корректной работы Вэб Мессенджера. +install.connection.error=Нет доступа к MySQL серверу, проверьте настройки в config.php. Ошибка: {0} +install.done=Выполнено: +install.err.back=Исправьте проблему и попробуйте еще раз. Нажмите назад чтобы вернуться к мастеру установки. +install.err.title=Ошибка +install.kill_tables=Удалить существующие таблицы +install.kill_tables.notice=Невозможно обновить структуру таблиц. Попробуйте сделать это вручную или пересоздайте все таблицы заново. install.license=Лицензионное соглашение о программном обеспечении -install.message=Для окончания установки необходимо создать таблицы. +install.message=Следуйте указаниям мастера для правильной настройки базы данных. +install.next=Следующий шаг: install.title=Установка installed.login_link=Войти в систему -installed.message=Необходимые таблицы были созданы. Вы можете войти в систему как admin с пустым паролем.
В целях безопасности, удалите, пожалуйста, каталог /webim/install с вашего сервера и поменяйте пароль. -installed.title=Установка завершена +installed.message=Установка успешно завершена. +installed.notice=Вы можете войти в систему как admin с пустым паролем.
В целях безопасности, удалите, пожалуйста, каталог /webim/install с вашего сервера и поменяйте пароль. menu.agents=Список агентов menu.main=Главная menu.operator=Вы {0}