Exemplo n.º 1
0
function checkInputValues()
{
    global $fdb;
    // Check connection
    $conn = @mysql_connect($_SESSION['hostname'], $_SESSION['username'], $_SESSION['password']);
    if (!$conn) {
        myerror('Unable to connect to MySQL server. Please check your settings again.<br><br><a href="?page=settings">Go back to settings</a>');
    }
    // Check databases
    if (!@mysql_select_db($_SESSION['php_db_clean'], $conn)) {
        // Fetch database list
        $list = '';
        $result = @mysql_query('SHOW databases', $conn);
        while ($ob = mysql_fetch_row($result)) {
            $list .= ' &nbsp <a href="?page=settings&newdb=' . $ob[0] . '">' . $ob[0] . '</a><br>' . "\n";
        }
        // Close connection and show message
        mysql_close($conn);
        myerror('Unable to select database.' . '<br><br>Found these databases:<br><font color="gray">' . $list . '</font>' . '<br><a href="?page=settings">Go back to settings</a>');
    }
    mysql_close($conn);
    // Include FORUM's config file
    include './' . $_SESSION['forum'] . '/_config.php';
    // Check prefix
    $fdb = new DBLayer($_SESSION['hostname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['php_db_clean'], $_SESSION['php_prefix'], false);
    $res = $fdb->query('SELECT count(*) FROM ' . $_SESSION['php'] . $tables['Users']);
    if (intval($fdb->result($res, 0)) == 0) {
        // Select a list of tables
        $list = array();
        $res = $fdb->query('SHOW TABLES IN ' . $_SESSION['php_db']);
        while ($ob = $fdb->fetch_row($res)) {
            $list[] = $ob[0];
        }
        // check list size
        sizeof($list) == 0 ? $list[] = 'None' : null;
        // Get list of "proabable" prefixes
        $prefix_list = '';
        $res = $fdb->query('SHOW TABLES FROM ' . $_SESSION['php_db'] . ' LIKE \'%' . $tables['Posts'] . '\'') or myerror('Unable to fetch table list', __FILE__, __LINE__, $fdb->error());
        //			$res = $fdb->query('SHOW TABLES FROM '.$_SESSION['php_db'].' LIKE \'%'.$tables['Users'].'\'') or myerror('Unable to fetch table list', __FILE__, __LINE__, $fdb->error());
        while ($ob = $fdb->fetch_row($res)) {
            $prefix = substr($ob[0], 0, strlen($ob[0]) - strlen($tables['Users']));
            $prefix_list .= ' &nbsp; <a href="?page=settings&newprefix=' . $prefix . '">' . $prefix . '</a><br>' . "\n";
        }
        // Print message
        $prefix = $_SESSION['php_prefix'] == '' ? 'no' : '\'' . $_SESSION['php_prefix'] . '\'';
        myerror('Unable to find ' . $_SESSION['forum'] . ' tables! (using prefix: <i>' . $prefix . '</i>)' . '<br><br>Go back to settings and choose another prefix, or select one of these prefixes:<br><font color="gray">' . $prefix_list . '</font>' . '<br>These are the tables in the selected database:<br><font color="gray"> &nbsp; ' . implode("<br> &nbsp; ", $list) . '</font>' . '<br><br><a href="?page=settings">Go back to settings</a>');
    }
}
Exemplo n.º 2
0
         }
     }
 }
 // Validate prefix
 if (strlen($db_prefix) > 0 && (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $db_prefix) || strlen($db_prefix) > 40)) {
     error(sprintf($lang_install['Invalid table prefix'], $db_prefix));
 }
 // Check SQLite prefix collision
 if (in_array($db_type, array('sqlite', 'sqlite3')) && strtolower($db_prefix) == 'sqlite_') {
     error($lang_install['SQLite prefix collision']);
 }
 // Make sure PunBB isn't already installed
 if ($forum_db->table_exists('users')) {
     $query = array('SELECT' => 'COUNT(id)', 'FROM' => 'users', 'WHERE' => 'id=1');
     $result = $forum_db->query_build($query);
     if ($forum_db->result($result) > 0) {
         error(sprintf($lang_install['PunBB already installed'], $db_prefix, $db_name));
     }
 }
 // Start a transaction
 $forum_db->start_transaction();
 // Create all tables
 $schema = array('FIELDS' => array('id' => array('datatype' => 'SERIAL', 'allow_null' => false), 'username' => array('datatype' => 'VARCHAR(200)', 'allow_null' => true), 'ip' => array('datatype' => 'VARCHAR(255)', 'allow_null' => true), 'email' => array('datatype' => 'VARCHAR(80)', 'allow_null' => true), 'message' => array('datatype' => 'VARCHAR(255)', 'allow_null' => true), 'expire' => array('datatype' => 'INT(10) UNSIGNED', 'allow_null' => true), 'ban_creator' => array('datatype' => 'INT(10) UNSIGNED', 'allow_null' => false, 'default' => '0')), 'PRIMARY KEY' => array('id'));
 $forum_db->create_table('bans', $schema);
 $schema = array('FIELDS' => array('id' => array('datatype' => 'SERIAL', 'allow_null' => false), 'cat_name' => array('datatype' => 'VARCHAR(80)', 'allow_null' => false, 'default' => '\'New Category\''), 'disp_position' => array('datatype' => 'INT(10)', 'allow_null' => false, 'default' => '0')), 'PRIMARY KEY' => array('id'));
 $forum_db->create_table('categories', $schema);
 $schema = array('FIELDS' => array('id' => array('datatype' => 'SERIAL', 'allow_null' => false), 'search_for' => array('datatype' => 'VARCHAR(60)', 'allow_null' => false, 'default' => '\'\''), 'replace_with' => array('datatype' => 'VARCHAR(60)', 'allow_null' => false, 'default' => '\'\'')), 'PRIMARY KEY' => array('id'));
 $forum_db->create_table('censoring', $schema);
 $schema = array('FIELDS' => array('conf_name' => array('datatype' => 'VARCHAR(255)', 'allow_null' => false, 'default' => '\'\''), 'conf_value' => array('datatype' => 'TEXT', 'allow_null' => true)), 'PRIMARY KEY' => array('conf_name'));
 $forum_db->create_table('config', $schema);
 $schema = array('FIELDS' => array('id' => array('datatype' => 'VARCHAR(150)', 'allow_null' => false, 'default' => '\'\''), 'title' => array('datatype' => 'VARCHAR(255)', 'allow_null' => false, 'default' => '\'\''), 'version' => array('datatype' => 'VARCHAR(25)', 'allow_null' => false, 'default' => '\'\''), 'description' => array('datatype' => 'TEXT', 'allow_null' => true), 'author' => array('datatype' => 'VARCHAR(50)', 'allow_null' => false, 'default' => '\'\''), 'uninstall' => array('datatype' => 'TEXT', 'allow_null' => true), 'uninstall_note' => array('datatype' => 'TEXT', 'allow_null' => true), 'disabled' => array('datatype' => 'TINYINT(1)', 'allow_null' => false, 'default' => '0'), 'dependencies' => array('datatype' => 'VARCHAR(255)', 'allow_null' => false, 'default' => '\'\'')), 'PRIMARY KEY' => array('id'));