[Comoblog-commit] comoblog/_install step_0.php, 1.2, 1.3 step_1.php, 1.6, 1.7
Status: Inactive
Brought to you by:
markwallis
From: iamdecal <iam...@us...> - 2006-11-17 00:50:54
|
Update of /cvsroot/comoblog/comoblog/_install In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29462/_install Modified Files: step_0.php step_1.php Log Message: Working version of captchas. not as feature complete as id like, but it works on the current version think we should sort out a may sort out a mini release? if so it needs add_comment.php list_comments.php templates/add_comment.tpl.htm templates/list_comments.tpl.htm captcha.php img/ttf/REVELMED.TTF and a bit of tidying of captcha.php tested on two systems, but i cant garentee it for everywhere Index: step_0.php =================================================================== RCS file: /cvsroot/comoblog/comoblog/_install/step_0.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- step_0.php 2 Sep 2005 01:06:14 -0000 1.2 +++ step_0.php 17 Nov 2006 00:50:45 -0000 1.3 @@ -40,6 +40,7 @@ $folder = str_replace(dirname(__FILE__).'/../','',$v); $errors[] = 'You need to set-up user permissions on the <font style="font-family: Courier New, Courier, mono;"><b>'.$folder.'</b></font> directory (it must be writable): <br />'; } + } if (count($errors) == 0) { Index: step_1.php =================================================================== RCS file: /cvsroot/comoblog/comoblog/_install/step_1.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- step_1.php 22 Oct 2006 11:44:02 -0000 1.6 +++ step_1.php 17 Nov 2006 00:50:45 -0000 1.7 @@ -1,239 +1,240 @@ -<?php -/* - database configuration - */ - -@ignore_user_abort(true); -@set_time_limit(300); -session_start(); -if ($_SESSION['step'] < 0) { - Header('Location: step_0.php'); - exit(); -} - -require ('../include/xtemplate.inc.php'); - -$tpl = @new XTemplate ('templates/step_1.tpl.htm'); - - -if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { - - // check form - foreach ($_POST as $k => $v) { - $_POST[$k] = trim($v); - } - - $errors = array(); - - if ($_POST['mysql_host'] == '') - $errors[] = 'mySQL host name required'; - - if ($_POST['mysql_username'] == '') - $errors[] = 'mySQL username required'; - - if ($_POST['mysql_password'] != $_POST['mysql_password_cfr']) - $errors[] = 'mySQL password mismatch'; - - if ($_POST['mysql_dbname'] == '') - $errors[] = 'mySQL database name required'; - - if ($_POST['mysql_tabprefix'] == '') - $errors[] = 'mySQL tab prefix required'; - - - if (count($errors) == 0) { // test db connection - - $_POST['mysql_tabprefix'] = eregi_replace(" +", "_", $_POST['mysql_tabprefix']); - $_POST['mysql_tabprefix'] = eregi_replace("\.+", "_", $_POST['mysql_tabprefix']); - $_POST['mysql_tabprefix'] = eregi_replace(";+", "_", $_POST['mysql_tabprefix']); - $_POST['mysql_tabprefix'] = eregi_replace(":+", "_", $_POST['mysql_tabprefix']); - - $dbconn = @mysql_connect ($_POST['mysql_host'], $_POST['mysql_username'], $_POST['mysql_password']); - if (!$dbconn) - { - $errors[] = 'Error connecting to mySQL server'; - $errors[] = 'error reported: ' . mysql_error(); - } - - $selectdb = @mysql_select_db ($_POST['mysql_dbname']); - if (!$selectdb) - $errors[] = 'Error selecting database (check database name)'; - - $query = "select pref_value from ".$_POST['mysql_tabprefix']."preferences where pref_name='CFG_VERSION'"; - $res = mysql_query($query); - if ($res) - { - // Upgrade detected - - $fp = fopen('param.inc.dist', 'r'); - $config = fread($fp, filesize('param.inc.dist')); - fclose($fp); - $config = str_replace('{##MYSQL_HOST##}', $_POST['mysql_host'], $config); - $config = str_replace('{##MYSQL_USERNAME##}', $_POST['mysql_username'], $config); - $config = str_replace('{##MYSQL_PASSWORD##}', $_POST['mysql_password'], $config); - $config = str_replace('{##MYSQL_DBNAME##}', $_POST['mysql_dbname'], $config); - $config = str_replace('{##MYSQL_TABPREFIX##}', $_POST['mysql_tabprefix'], $config); - - $fp = fopen(dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 'w'); - fwrite($fp, $config); - fclose($fp); - - @chmod (dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 0600); - - header ('Location: upgrade_0.php'); - exit; - } - } - - if (count($errors) == 0) { - require_once (dirname(__FILE__).'/../admin/include/xml2array.inc.php'); - - $xmlparse = &new ParseXML; - $xml = $xmlparse->GetXMLTree('comoblog_db.xml'); - - $queryerror = false; - - // generate queries - $tables = $xml['COMOBLOG_DB'][0]['TABLE']; - for ($c = 0; $c < count($tables); $c++) { - $table_name = $tables[$c]['ATTRIBUTES']['NAME']; - $table_name = str_replace('comoblog_', $_POST['mysql_tabprefix'], $table_name); - $query = "CREATE TABLE `".$table_name."` (\n"; - $fields = $tables[$c]['FIELD']; - for ($f = 0; $f < count($fields); $f++) { - $field_name = $fields[$f]['ATTRIBUTES']['NAME']; - $field_specs = $fields[$f]['ATTRIBUTES']['SPECS']; - $query .= "`".$field_name."` ".$field_specs . ",\n"; - } - $pk = $tables[$c]['PK'][0]['ATTRIBUTES']['NAME']; - $query .= "\nPRIMARY KEY (`".$pk."`)"; - if (isset($tables[$c]['UK'])) - $uks = $tables[$c]['UK']; - else - $uks = array(); - for ($u = 0; $u < count($uks); $u++) { - $uk = $uks[$u]['ATTRIBUTES']['NAME']; - $query .= ",\nUNIQUE KEY (`".$uk."`)"; - } - $query .= "\n) TYPE=MyISAM\n"; - - // execute CREATE TABLE query - $result = mysql_query($query); - - if (!$result) { - $queryerror = true; - } - if (isset($tables[$c]['ROW'])) - $rows = $tables[$c]['ROW']; - else - $rows = array(); - for ($r = 0; $r < count($rows); $r++) { - $query_fields = ''; - $query_values = ''; - $fields = $rows[$r]['FIELD']; - for ($f = 0; $f < count($fields); $f++) { - $field_name = $fields[$f]['ATTRIBUTES']['NAME']; - $query_fields .= $field_name; - if ($f < count($fields) - 1) { - $query_fields .= ",\n"; - } - $field_value = addslashes($fields[$f]['ATTRIBUTES']['VALUE']); - $query_values .= "'".$field_value."'"; - if ($f < count($fields) - 1) { - $query_values .= ",\n"; - } - } - $query = "INSERT INTO `".$table_name."`\n(".$query_fields.")\nVALUES\n(".$query_values.")"; - - // execute INSERT query - $result = mysql_query($query); - - if (!$result) { - $queryerror = true; - } - } - } - - // comoblog_preferences - unset ($xmlparse); - $xmlparse = &new ParseXML; - $xml = $xmlparse->GetXMLTree('comoblog_preferences.xml'); - $preferences = $xml['COMOBLOG_PREFERENCES'][0]['PARAM']; - for ($c = 0; $c < count($preferences); $c++) { - $pref_name = addslashes($preferences[$c]['ATTRIBUTES']['NAME']); - $pref_value = addslashes($preferences[$c]['ATTRIBUTES']['VALUE']); - $pref_description = addslashes($preferences[$c]['ATTRIBUTES']['DESCRIPTION']); - $pref_topic_id = addslashes($preferences[$c]['ATTRIBUTES']['TOPIC_ID']); - $pref_encrypt = addslashes($preferences[$c]['ATTRIBUTES']['ENCRYPT']); - $pref_type = addslashes($preferences[$c]['ATTRIBUTES']['TYPE']); - $pref_restrict_values = addslashes($preferences[$c]['ATTRIBUTES']['RESTRICT_VALUES']); - $pref_accept_null = addslashes($preferences[$c]['ATTRIBUTES']['ACCEPT_NULL']); - $pref_editable = addslashes($preferences[$c]['ATTRIBUTES']['EDITABLE']); - $pref_display_order = addslashes($preferences[$c]['ATTRIBUTES']['DISPLAY_ORDER']); - - $query = "INSERT INTO `".$_POST['mysql_tabprefix']."preferences` (pref_name,pref_value,pref_description,pref_topic_id,pref_encrypt,pref_type,pref_restrict_values,pref_accept_null,pref_editable,pref_display_order) VALUES ('".$pref_name."','".$pref_value."','".$pref_description."','".$pref_topic_id."','".$pref_encrypt."','".$pref_type."','".$pref_restrict_values."','".$pref_accept_null."','".$pref_editable."','".$pref_display_order."')"; - - $result = mysql_query($query); - - if (!$result) { - $queryerror = true; - } - } - - if ($queryerror === true) {// if query failed, delete all tables (prefixed by tab_prefix) and print error - $sql2 = 'show tables from '.$_POST['mysql_dbname']; - $res2 = mysql_query($sql2); - while ($row = mysql_fetch_row($res2)) { - if (substr($row[0],0,strlen($_POST['mysql_tabprefix'])) == $_POST['mysql_tabprefix']) - mysql_query('drop table '.$row[0]); - } - $errors[] = 'Error creating mySQL tables'; - - mysql_close(); - } - else { - // change values in param.inc.php - $fp = fopen('param.inc.dist', 'r'); - $config = fread($fp, filesize('param.inc.dist')); - fclose($fp); - $config = str_replace('{##MYSQL_HOST##}', $_POST['mysql_host'], $config); - $config = str_replace('{##MYSQL_USERNAME##}', $_POST['mysql_username'], $config); - $config = str_replace('{##MYSQL_PASSWORD##}', $_POST['mysql_password'], $config); - $config = str_replace('{##MYSQL_DBNAME##}', $_POST['mysql_dbname'], $config); - $config = str_replace('{##MYSQL_TABPREFIX##}', $_POST['mysql_tabprefix'], $config); - - $fp = fopen(dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 'w'); - fwrite($fp, $config); - fclose($fp); - - @chmod (dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 0600); - - // redirect to step 2 - $_SESSION['step'] = 1; - Header ('Location: step_2.php'); - exit(); - } - } -} - -$tpl->assign('ACTION', basename($_SERVER['PHP_SELF'])); - -if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { - - if (count($errors) > 0) { - foreach ($errors as $k => $v) { - $tpl->assign('ERROR', $v); - $tpl->parse('main.errors.error'); - } - $tpl->parse('main.errors'); - } - $tpl->assign('POST', $_POST); -} -else { - $_POST['mysql_tabprefix'] = 'comoblog_'; - $tpl->assign('POST', $_POST); -} - -$tpl->parse('main'); -$tpl->out('main'); -?> +<?php +/* + database configuration + */ + +@ignore_user_abort(true); +@set_time_limit(300); +session_start(); +if ($_SESSION['step'] < 0) { + Header('Location: step_0.php'); + exit(); +} + +require ('../include/xtemplate.inc.php'); + +$tpl = @new XTemplate ('templates/step_1.tpl.htm'); + + +if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { + + // check form + foreach ($_POST as $k => $v) { + $_POST[$k] = trim($v); + } + + $errors = array(); + + if ($_POST['mysql_host'] == '') + $errors[] = 'mySQL host name required'; + + if ($_POST['mysql_username'] == '') + $errors[] = 'mySQL username required'; + + if ($_POST['mysql_password'] != $_POST['mysql_password_cfr']) + $errors[] = 'mySQL password mismatch'; + + if ($_POST['mysql_dbname'] == '') + $errors[] = 'mySQL database name required'; + + if ($_POST['mysql_tabprefix'] == '') + $errors[] = 'mySQL tab prefix required'; + + + if (count($errors) == 0) { // test db connection + + $_POST['mysql_tabprefix'] = eregi_replace(" +", "_", $_POST['mysql_tabprefix']); + $_POST['mysql_tabprefix'] = eregi_replace("\.+", "_", $_POST['mysql_tabprefix']); + $_POST['mysql_tabprefix'] = eregi_replace(";+", "_", $_POST['mysql_tabprefix']); + $_POST['mysql_tabprefix'] = eregi_replace(":+", "_", $_POST['mysql_tabprefix']); + + $dbconn = @mysql_connect ($_POST['mysql_host'], $_POST['mysql_username'], $_POST['mysql_password']); + if (!$dbconn) + { + $errors[] = 'Error connecting to mySQL server'; + $errors[] = 'error reported: ' . mysql_error(); + } + + $selectdb = @mysql_select_db ($_POST['mysql_dbname']); + if (!$selectdb) + $errors[] = 'Error selecting database (check database name)'; + + $query = "select pref_value from ".$_POST['mysql_tabprefix']."preferences where pref_name='CFG_VERSION'"; + $res = mysql_query($query); + if ($res) + { + error_log("update detected"); + // Upgrade detected + + $fp = fopen('param.inc.dist', 'r'); + $config = fread($fp, filesize('param.inc.dist')); + fclose($fp); + $config = str_replace('{##MYSQL_HOST##}', $_POST['mysql_host'], $config); + $config = str_replace('{##MYSQL_USERNAME##}', $_POST['mysql_username'], $config); + $config = str_replace('{##MYSQL_PASSWORD##}', $_POST['mysql_password'], $config); + $config = str_replace('{##MYSQL_DBNAME##}', $_POST['mysql_dbname'], $config); + $config = str_replace('{##MYSQL_TABPREFIX##}', $_POST['mysql_tabprefix'], $config); + + $fp = fopen(dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 'w'); + fwrite($fp, $config); + fclose($fp); + + @chmod (dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 0600); + + header ('Location: upgrade_0.php'); + exit; + } + } + + if (count($errors) == 0) { + require_once (dirname(__FILE__).'/../admin/include/xml2array.inc.php'); + + $xmlparse = &new ParseXML; + $xml = $xmlparse->GetXMLTree('comoblog_db.xml'); + + $queryerror = false; + + // generate queries + $tables = $xml['COMOBLOG_DB'][0]['TABLE']; + for ($c = 0; $c < count($tables); $c++) { + $table_name = $tables[$c]['ATTRIBUTES']['NAME']; + $table_name = str_replace('comoblog_', $_POST['mysql_tabprefix'], $table_name); + $query = "CREATE TABLE `".$table_name."` (\n"; + $fields = $tables[$c]['FIELD']; + for ($f = 0; $f < count($fields); $f++) { + $field_name = $fields[$f]['ATTRIBUTES']['NAME']; + $field_specs = $fields[$f]['ATTRIBUTES']['SPECS']; + $query .= "`".$field_name."` ".$field_specs . ",\n"; + } + $pk = $tables[$c]['PK'][0]['ATTRIBUTES']['NAME']; + $query .= "\nPRIMARY KEY (`".$pk."`)"; + if (isset($tables[$c]['UK'])) + $uks = $tables[$c]['UK']; + else + $uks = array(); + for ($u = 0; $u < count($uks); $u++) { + $uk = $uks[$u]['ATTRIBUTES']['NAME']; + $query .= ",\nUNIQUE KEY (`".$uk."`)"; + } + $query .= "\n) TYPE=MyISAM\n"; + + // execute CREATE TABLE query + $result = mysql_query($query); + + if (!$result) { + $queryerror = true; + } + if (isset($tables[$c]['ROW'])) + $rows = $tables[$c]['ROW']; + else + $rows = array(); + for ($r = 0; $r < count($rows); $r++) { + $query_fields = ''; + $query_values = ''; + $fields = $rows[$r]['FIELD']; + for ($f = 0; $f < count($fields); $f++) { + $field_name = $fields[$f]['ATTRIBUTES']['NAME']; + $query_fields .= $field_name; + if ($f < count($fields) - 1) { + $query_fields .= ",\n"; + } + $field_value = addslashes($fields[$f]['ATTRIBUTES']['VALUE']); + $query_values .= "'".$field_value."'"; + if ($f < count($fields) - 1) { + $query_values .= ",\n"; + } + } + $query = "INSERT INTO `".$table_name."`\n(".$query_fields.")\nVALUES\n(".$query_values.")"; + + // execute INSERT query + $result = mysql_query($query); + + if (!$result) { + $queryerror = true; + } + } + } + + // comoblog_preferences + unset ($xmlparse); + $xmlparse = &new ParseXML; + $xml = $xmlparse->GetXMLTree('comoblog_preferences.xml'); + $preferences = $xml['COMOBLOG_PREFERENCES'][0]['PARAM']; + for ($c = 0; $c < count($preferences); $c++) { + $pref_name = addslashes($preferences[$c]['ATTRIBUTES']['NAME']); + $pref_value = addslashes($preferences[$c]['ATTRIBUTES']['VALUE']); + $pref_description = addslashes($preferences[$c]['ATTRIBUTES']['DESCRIPTION']); + $pref_topic_id = addslashes($preferences[$c]['ATTRIBUTES']['TOPIC_ID']); + $pref_encrypt = addslashes($preferences[$c]['ATTRIBUTES']['ENCRYPT']); + $pref_type = addslashes($preferences[$c]['ATTRIBUTES']['TYPE']); + $pref_restrict_values = addslashes($preferences[$c]['ATTRIBUTES']['RESTRICT_VALUES']); + $pref_accept_null = addslashes($preferences[$c]['ATTRIBUTES']['ACCEPT_NULL']); + $pref_editable = addslashes($preferences[$c]['ATTRIBUTES']['EDITABLE']); + $pref_display_order = addslashes($preferences[$c]['ATTRIBUTES']['DISPLAY_ORDER']); + + $query = "INSERT INTO `".$_POST['mysql_tabprefix']."preferences` (pref_name,pref_value,pref_description,pref_topic_id,pref_encrypt,pref_type,pref_restrict_values,pref_accept_null,pref_editable,pref_display_order) VALUES ('".$pref_name."','".$pref_value."','".$pref_description."','".$pref_topic_id."','".$pref_encrypt."','".$pref_type."','".$pref_restrict_values."','".$pref_accept_null."','".$pref_editable."','".$pref_display_order."')"; + + $result = mysql_query($query); + + if (!$result) { + $queryerror = true; + } + } + + if ($queryerror === true) {// if query failed, delete all tables (prefixed by tab_prefix) and print error + $sql2 = 'show tables from '.$_POST['mysql_dbname']; + $res2 = mysql_query($sql2); + while ($row = mysql_fetch_row($res2)) { + if (substr($row[0],0,strlen($_POST['mysql_tabprefix'])) == $_POST['mysql_tabprefix']) + mysql_query('drop table '.$row[0]); + } + $errors[] = 'Error creating mySQL tables'; + + mysql_close(); + } + else { + // change values in param.inc.php + $fp = fopen('param.inc.dist', 'r'); + $config = fread($fp, filesize('param.inc.dist')); + fclose($fp); + $config = str_replace('{##MYSQL_HOST##}', $_POST['mysql_host'], $config); + $config = str_replace('{##MYSQL_USERNAME##}', $_POST['mysql_username'], $config); + $config = str_replace('{##MYSQL_PASSWORD##}', $_POST['mysql_password'], $config); + $config = str_replace('{##MYSQL_DBNAME##}', $_POST['mysql_dbname'], $config); + $config = str_replace('{##MYSQL_TABPREFIX##}', $_POST['mysql_tabprefix'], $config); + + $fp = fopen(dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 'w'); + fwrite($fp, $config); + fclose($fp); + + @chmod (dirname(__FILE__).'/../include/param.inc.'. $_SERVER['SERVER_NAME'].'.php', 0600); + + // redirect to step 2 + $_SESSION['step'] = 1; + Header ('Location: step_2.php'); + exit(); + } + } +} + +$tpl->assign('ACTION', basename($_SERVER['PHP_SELF'])); + +if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { + + if (count($errors) > 0) { + foreach ($errors as $k => $v) { + $tpl->assign('ERROR', $v); + $tpl->parse('main.errors.error'); + } + $tpl->parse('main.errors'); + } + $tpl->assign('POST', $_POST); +} +else { + $_POST['mysql_tabprefix'] = 'comoblog_'; + $tpl->assign('POST', $_POST); +} + +$tpl->parse('main'); +$tpl->out('main'); +?> |