function createAdmin()
{
    global $CONFIG, $config, $language;
    if (!isset($config['admin_username']) || $config['admin_username'] == '') {
        $GLOBALS['error'] = $language['no_admin_username'];
        return false;
    }
    if (!isset($config['admin_password']) || $config['admin_password'] == '') {
        $GLOBALS['error'] = $language['no_admin_password'];
        return false;
    }
    if (!isset($config['admin_email']) || $config['admin_email'] == '') {
        $GLOBALS['error'] = $language['no_admin_email'];
        return false;
    }
    require 'include/passwordhash.inc.php';
    $password_params = explode(':', cpg_password_create_hash($config['admin_password']));
    // Insert the admin account
    $sql_query = "INSERT INTO {$config['db_prefix']}users " . "(user_group, user_active, user_name, user_password, user_password_salt, " . " user_password_hash_algorithm, user_password_iterations, user_lastvisit, " . " user_regdate, user_group_list, user_email, user_profile1, user_profile2, " . " user_profile3, user_profile4, user_profile5, user_profile6, user_actkey) " . "VALUES " . "(1, 'YES', '{$config['admin_username']}', '{$password_params[HASH_PBKDF2_INDEX]}', " . " '{$password_params[HASH_SALT_INDEX]}', '{$password_params[HASH_ALGORITHM_INDEX]}', '{$password_params[HASH_ITERATION_INDEX]}', " . " NOW(), NOW(), '', '{$config['admin_email']}', '', '', '', '', '', '', '');\n";
    // Set gallery admin mail
    $sql_query .= "REPLACE INTO CPG_config VALUES ('gallery_admin_email', '{$config['admin_email']}');\n";
    // Update table prefix
    $sql_query = preg_replace('/CPG_/', $config['db_prefix'], $sql_query);
    require_once 'include/sql_parse.php';
    $sql_query = remove_remarks($sql_query);
    $sql_query = split_sql_file($sql_query, ';');
    // Get a connection with the db.
    if (!checkSqlConnection()) {
        return false;
    }
    foreach ($sql_query as $q) {
        if (!mysql_query($q, $GLOBALS['mysql_connection'])) {
            $GLOBALS['error'] = $language['mysql_error'] . mysql_error($GLOBALS['mysql_connection']) . ' ' . $language['on_q'] . " '{$q}'";
            return false;
        }
    }
    return true;
}
Example #2
0
function createAdmin()
{
    global $config, $language;
    if (!isset($config['admin_username']) || $config['admin_username'] == '') {
        $GLOBALS['error'] = $language['no_admin_username'];
        return false;
    }
    if (!isset($config['admin_password']) || $config['admin_password'] == '') {
        $GLOBALS['error'] = $language['no_admin_password'];
        return false;
    }
    if (!isset($config['admin_email']) || $config['admin_email'] == '') {
        $GLOBALS['error'] = $language['no_admin_email'];
        return false;
    }
    // Insert the admin account
    $sql_query = "INSERT INTO {$config['db_prefix']}users " . "(user_group, user_active, user_name, user_password, user_lastvisit, " . " user_regdate, user_group_list, user_email, user_profile1, user_profile2, user_profile3, " . " user_profile4, user_profile5, user_profile6, user_actkey ) " . "VALUES " . "(1, 'YES', '{$config['admin_username']}', " . " md5('{$config['admin_password']}'), NOW(), NOW(), '', " . " '{$config['admin_email']}', '', '', '', '', '', '', '');\n";
    // Set gallery admin mail
    $sql_query .= "REPLACE INTO CPG_config VALUES ('gallery_admin_email', '{$config['admin_email']}');\n";
    // Update table prefix
    $sql_query = preg_replace('/CPG_/', $config['db_prefix'], $sql_query);
    require_once 'include/sql_parse.php';
    $sql_query = remove_remarks($sql_query);
    $sql_query = split_sql_file($sql_query, ';');
    // Get a connection with the db.
    if (!checkSqlConnection()) {
        return false;
    }
    foreach ($sql_query as $q) {
        if (!mysql_query($q, $GLOBALS['mysql_connection'])) {
            $GLOBALS['error'] = $language['mysql_error'] . mysql_error($GLOBALS['mysql_connection']) . ' ' . $language['on_q'] . " '{$q}'";
            return false;
        }
    }
    return true;
}
Example #3
0
function createMysqlDb($db_name)
{
    global $language;
    // Get a connection with the db
    if (!checkSqlConnection()) {
        return false;
    }
    $query = 'CREATE DATABASE ' . $db_name;
    // try to create new db
    if (!mysql_query($query, $GLOBALS['mysql_connection'])) {
        $GLOBALS['error'] = $language['dbase_no_create_db'] . '<br />' . $language['dbase_error'] . '<br />' . mysql_error($GLOBALS['mysql_connection']);
        return false;
    } else {
        setTmpConfig('db_name', $db_name);
    }
    return true;
}