예제 #1
0
 function _do_convert_cached_html(&$request, $args)
 {
     require_once "lib/upgrade.php";
     $dbh = $request->_dbi;
     _upgrade_db_init($dbh);
     $count = _upgrade_cached_html($dbh, false);
     if (!$count) {
         return _("No old _cached_html pagedata found.");
     } else {
         return HTML(fmt("Converted successfully %d pages", $count), HTML::div(array('align' => 'left'), $list));
     }
 }
예제 #2
0
/**
 * Update from ~1.3.4 to current.
 * Only session, user, pref and member
 * jeffs-hacks database api (around 1.3.2) later:
 *   people should export/import their pages if using that old versions.
 */
function CheckDatabaseUpdate(&$request)
{
    global $DBParams, $DBAuthParams;
    if (!in_array($DBParams['dbtype'], array('SQL', 'ADODB', 'PDO'))) {
        return;
    }
    echo "<h3>", _("check for necessary database updates"), " - ", $DBParams['dbtype'], "</h3>\n";
    $dbh = $request->getDbh();
    $dbadmin = $request->getArg('dbadmin');
    _upgrade_db_init($dbh);
    if (isset($dbadmin['cancel'])) {
        echo _("CANCEL"), " <br />\n";
        return;
    }
    $tables = $dbh->_backend->listOfTables();
    $backend_type = $dbh->_backend->backendType();
    echo "<h4>", _("Backend type: "), $backend_type, "</h4>\n";
    $prefix = isset($DBParams['prefix']) ? $DBParams['prefix'] : '';
    foreach (explode(':', 'session:user:pref:member') as $table) {
        echo sprintf(_("check for table %s"), $table), " ...";
        if (!in_array($prefix . $table, $tables)) {
            installTable($dbh, $table, $backend_type);
        } else {
            echo _("OK"), " <br />\n";
        }
    }
    if (ACCESS_LOG_SQL) {
        $table = "accesslog";
        echo sprintf(_("check for table %s"), $table), " ...";
        if (!in_array($prefix . $table, $tables)) {
            installTable($dbh, $table, $backend_type);
        } else {
            echo _("OK"), " <br />\n";
        }
    }
    if (class_exists("RatingsUserFactory") or $dbh->isWikiPage(_("RateIt"))) {
        $table = "rating";
        echo sprintf(_("check for table %s"), $table), " ...";
        if (!in_array($prefix . $table, $tables)) {
            installTable($dbh, $table, $backend_type);
        } else {
            echo _("OK"), " <br />\n";
        }
    }
    $backend =& $dbh->_backend->_dbh;
    extract($dbh->_backend->_table_names);
    // 1.3.8 added session.sess_ip
    if (phpwiki_version() >= 1030.08 and USE_DB_SESSION and isset($request->_dbsession)) {
        echo _("check for new session.sess_ip column"), " ... ";
        $database = $dbh->_backend->database();
        assert(!empty($DBParams['db_session_table']));
        $session_tbl = $prefix . $DBParams['db_session_table'];
        $sess_fields = $dbh->_backend->listOfFields($database, $session_tbl);
        if (!strstr(strtolower(join(':', $sess_fields)), "sess_ip")) {
            // TODO: postgres test (should be able to add columns at the end, but not in between)
            echo "<b>", _("ADDING"), "</b>", " ... ";
            $dbh->genericSqlQuery("ALTER TABLE {$session_tbl} ADD sess_ip CHAR(15) NOT NULL");
            $dbh->genericSqlQuery("CREATE INDEX sess_date ON {$session_tbl} (sess_date)");
        } else {
            echo _("OK");
        }
        echo "<br />\n";
        if (substr($backend_type, 0, 5) == 'mysql') {
            // upgrade to 4.1.8 destroyed my session table:
            // sess_id => varchar(10), sess_data => varchar(5). For others obviously also.
            echo _("check for mysql session.sess_id sanity"), " ... ";
            $result = $dbh->genericSqlQuery("DESCRIBE {$session_tbl}");
            if ($DBParams['dbtype'] == 'SQL') {
                $iter = new WikiDB_backend_PearDB_generic_iter($backend, $result);
            } elseif ($DBParams['dbtype'] == 'ADODB') {
                $iter = new WikiDB_backend_ADODB_generic_iter($backend, $result, array("Field", "Type", "Null", "Key", "Default", "Extra"));
            } elseif ($DBParams['dbtype'] == 'PDO') {
                $iter = new WikiDB_backend_PDO_generic_iter($backend, $result);
            }
            while ($col = $iter->next()) {
                if ($col["Field"] == 'sess_id' and !strstr(strtolower($col["Type"]), 'char(32)')) {
                    $dbh->genericSqlQuery("ALTER TABLE {$session_tbl} CHANGE sess_id" . " sess_id CHAR(32) NOT NULL");
                    echo "sess_id ", $col["Type"], " ", _("fixed"), " =&gt; CHAR(32) ";
                }
                if ($col["Field"] == 'sess_ip' and !strstr(strtolower($col["Type"]), 'char(15)')) {
                    $dbh->genericSqlQuery("ALTER TABLE {$session_tbl} CHANGE sess_ip" . " sess_ip CHAR(15) NOT NULL");
                    echo "sess_ip ", $col["Type"], " ", _("fixed"), " =&gt; CHAR(15) ";
                }
            }
            echo _("OK"), "<br />\n";
        }
    }
    // mysql >= 4.0.4 requires LOCK TABLE privileges
    if (substr($backend_type, 0, 5) == 'mysql') {
        echo _("check for mysql LOCK TABLE privilege"), " ...";
        $mysql_version = $dbh->_backend->_serverinfo['version'];
        if ($mysql_version > 400.4) {
            if (!empty($dbh->_backend->_parsedDSN)) {
                $parseDSN = $dbh->_backend->_parsedDSN;
            } elseif (function_exists('parseDSN')) {
                // ADODB or PDO
                $parseDSN = parseDSN($DBParams['dsn']);
            } else {
                // pear
                $parseDSN = DB::parseDSN($DBParams['dsn']);
            }
            $username = $dbh->_backend->qstr($parseDSN['username']);
            // on db level
            $query = "SELECT lock_tables_priv FROM mysql.db WHERE user='******'";
            //mysql_select_db("mysql", $dbh->_backend->connection());
            $db_fields = $dbh->_backend->listOfFields("mysql", "db");
            if (!strstr(strtolower(join(':', $db_fields)), "lock_tables_priv")) {
                echo join(':', $db_fields);
                die("lock_tables_priv missing. The DB Admin must run mysql_fix_privilege_tables");
            }
            $row = $dbh->_backend->getRow($query);
            if (isset($row[0]) and $row[0] == 'N') {
                $dbh->genericSqlQuery("UPDATE mysql.db SET lock_tables_priv='Y'" . " WHERE mysql.user='******'");
                $dbh->genericSqlQuery("FLUSH PRIVILEGES");
                echo "mysql.db user='******'", _("fixed"), "<br />\n";
            } elseif (!$row) {
                // or on user level
                $query = "SELECT lock_tables_priv FROM mysql.user WHERE user='******'";
                $row = $dbh->_backend->getRow($query);
                if ($row and $row[0] == 'N') {
                    $dbh->genericSqlQuery("UPDATE mysql.user SET lock_tables_priv='Y'" . " WHERE mysql.user='******'");
                    $dbh->genericSqlQuery("FLUSH PRIVILEGES");
                    echo "mysql.user user='******'", _("fixed"), "<br />\n";
                } elseif (!$row) {
                    echo " <b><font color=\"red\">", _("FAILED"), "</font></b>: ", "Neither mysql.db nor mysql.user has a user='******'" . " or the lock_tables_priv field", "<br />\n";
                } else {
                    echo _("OK"), "<br />\n";
                }
            } else {
                echo _("OK"), "<br />\n";
            }
            //mysql_select_db($dbh->_backend->database(), $dbh->_backend->connection());
        } else {
            echo sprintf(_("version <em>%s</em> not affected"), $mysql_version), "<br />\n";
        }
    }
    // 1.3.10 mysql requires page.id auto_increment
    // mysql, mysqli or mysqlt
    if (phpwiki_version() >= 1030.099 and substr($backend_type, 0, 5) == 'mysql' and $DBParams['dbtype'] != 'PDO') {
        echo _("check for mysql page.id auto_increment flag"), " ...";
        assert(!empty($page_tbl));
        $database = $dbh->_backend->database();
        $fields = mysql_list_fields($database, $page_tbl, $dbh->_backend->connection());
        $columns = mysql_num_fields($fields);
        for ($i = 0; $i < $columns; $i++) {
            if (mysql_field_name($fields, $i) == 'id') {
                $flags = mysql_field_flags($fields, $i);
                //DONE: something was wrong with ADODB here.
                if (!strstr(strtolower($flags), "auto_increment")) {
                    echo "<b>", _("ADDING"), "</b>", " ... ";
                    // MODIFY col_def valid since mysql 3.22.16,
                    // older mysql's need CHANGE old_col col_def
                    $dbh->genericSqlQuery("ALTER TABLE {$page_tbl} CHANGE id" . " id INT NOT NULL AUTO_INCREMENT");
                    $fields = mysql_list_fields($database, $page_tbl);
                    if (!strstr(strtolower(mysql_field_flags($fields, $i)), "auto_increment")) {
                        echo " <b><font color=\"red\">", _("FAILED"), "</font></b><br />\n";
                    } else {
                        echo _("OK"), "<br />\n";
                    }
                } else {
                    echo _("OK"), "<br />\n";
                }
                break;
            }
        }
        mysql_free_result($fields);
    }
    // Check for mysql 4.1.x/5.0.0a binary search problem.
    //   http://bugs.mysql.com/bug.php?id=4398
    // "select * from page where LOWER(pagename) like '%search%'" does not apply LOWER!
    // Confirmed for 4.1.0alpha,4.1.3-beta,5.0.0a; not yet tested for 4.1.2alpha,
    // On windows only, though utf8 would be useful elsewhere also.
    // Illegal mix of collations (latin1_bin,IMPLICIT) and
    // (utf8_general_ci, COERCIBLE) for operation '='])
    if (isWindows() and substr($backend_type, 0, 5) == 'mysql') {
        echo _("check for mysql 4.1.x/5.0.0 binary search on windows problem"), " ...";
        $mysql_version = $dbh->_backend->_serverinfo['version'];
        if ($mysql_version < 401.0) {
            echo sprintf(_("version <em>%s</em>"), $mysql_version), " ", _("not affected"), "<br />\n";
        } elseif ($mysql_version >= 401.6) {
            // FIXME: since which version?
            $row = $dbh->_backend->getRow("SHOW CREATE TABLE {$page_tbl}");
            $result = join(" ", $row);
            if (strstr(strtolower($result), "character set") and strstr(strtolower($result), "collate")) {
                echo _("OK"), "<br />\n";
            } else {
                //SET CHARACTER SET latin1
                $charset = CHARSET;
                if ($charset == 'iso-8859-1') {
                    $charset = 'latin1';
                }
                $dbh->genericSqlQuery("ALTER TABLE {$page_tbl} CHANGE pagename " . "pagename VARCHAR(100) " . "CHARACTER SET '{$charset}' COLLATE '{$charset}" . "_bin' NOT NULL");
                echo sprintf(_("version <em>%s</em>"), $mysql_version), " <b>", _("FIXED"), "</b>", "<br />\n";
            }
        } elseif ($DBParams['dbtype'] != 'PDO') {
            // check if already fixed
            extract($dbh->_backend->_table_names);
            assert(!empty($page_tbl));
            $database = $dbh->_backend->database();
            $fields = mysql_list_fields($database, $page_tbl, $dbh->_backend->connection());
            $columns = mysql_num_fields($fields);
            for ($i = 0; $i < $columns; $i++) {
                if (mysql_field_name($fields, $i) == 'pagename') {
                    $flags = mysql_field_flags($fields, $i);
                    // I think it was fixed with 4.1.6, but I tested it only with 4.1.8
                    if ($mysql_version > 401.0 and $mysql_version < 401.6) {
                        // remove the binary flag
                        if (strstr(strtolower($flags), "binary")) {
                            // FIXME: on duplicate pagenames this will fail!
                            $dbh->genericSqlQuery("ALTER TABLE {$page_tbl} CHANGE pagename" . " pagename VARCHAR(100) NOT NULL");
                            echo sprintf(_("version <em>%s</em>"), $mysql_version), "<b>", _("FIXED"), "</b>", "<br />\n";
                        }
                    }
                    break;
                }
            }
        }
    }
    if (ACCESS_LOG_SQL & 2) {
        echo _("check for ACCESS_LOG_SQL passwords in POST requests"), " ...";
        // Don't display passwords in POST requests (up to 2005-02-04 12:03:20)
        $result = $dbh->genericSqlQuery("UPDATE " . $prefix . "accesslog" . ' SET request_args=CONCAT(left(request_args, LOCATE("s:6:\\"passwd\\"",request_args)+12),"...")' . ' WHERE LOCATE("s:6:\\"passwd\\"", request_args)' . ' AND NOT(LOCATE("s:6:\\"passwd\\";s:15:\\"<not displayed>\\"", request_args))' . ' AND request_method="POST"');
        if (DATABASE_TYPE == 'SQL' and $backend->AffectedRows() or DATABASE_TYPE == 'ADODB' and $backend->Affected_Rows() or DATABASE_TYPE == 'PDO' and $result) {
            echo "<b>", _("FIXED"), "</b>", "<br />\n";
        } else {
            echo _("OK"), "<br />\n";
        }
    }
    _upgrade_cached_html($dbh);
    return;
}
예제 #3
0
 function _do_convert_cached_html(&$request, $args)
 {
     return $this->disabled("This action is blocked by administrator. Sorry for the inconvenience !");
     require_once "lib/upgrade.php";
     $dbh = $request->_dbi;
     _upgrade_db_init($dbh);
     $count = _upgrade_cached_html($dbh, false);
     if (!$count) {
         return _("No old _cached_html pagedata found.");
     } else {
         return HTML(fmt("Converted successfully %d pages", $count), HTML::div(array('align' => 'left'), $list));
     }
 }