Esempio n. 1
0
 function DbInstall($autoInstall)
 {
     global $phpVersionMin, $mySqlVersionMin;
     $host = $autoInstall->hostName;
     if ($autoInstall->dbPort != "") {
         $host .= ":" . $autoInstall->dbPort;
     }
     if ($autoInstall->dbSocket != "") {
         $host .= ":" . $autoInstall->dbSocket;
     }
     $autoInstall->out("Connecting to database server");
     $ret = @mysql_connect($host, $autoInstall->dbUser, $autoInstall->dbUserPw);
     if (!DbInstall::checkComponentVersions($mySqlVersion, $phpVersion)) {
         $autoInstall->outDie("Required minimum MySql version is {$mySqlVersionMin}. The current one is {$mySqlVersion}. Required minimum MySql version is {$phpVersionMin}. The current one is {$phpVersion}. Installation failed.");
     }
     if (!$ret) {
         $autoInstall->outDie("Mysql connection failed with: Host: {$host}, Username: {$autoInstall->dbUser}, Password: {$autoInstall->dbUserPw}. Installation failed.");
     }
     $autoInstall->out("Selecting classifieds database: {$autoInstall->dbName}.");
     if (!@mysql_select_db($autoInstall->dbName)) {
         $autoInstall->out("Classifieds database doesn't exist - creating.");
         $query = "CREATE DATABASE {$autoInstall->dbName} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         if (!@mysql_query($query)) {
             $autoInstall->outDie("Couldn't create classifieds database. Installation failed.");
         }
         $autoInstall->out("Selecting classifieds database: {$autoInstall->dbName}.");
         if (!@mysql_select_db($autoInstall->dbName)) {
             $autoInstall->outDie("Couldn't select classifieds database: {$autoInstall->dbName}. Installation failed.");
         }
     }
     // Switch off strict mode:
     mysql_query("SET SESSION sql_mode=''");
     // checking if tables are already installed:
     $result = executeQuery("SHOW TABLES");
     $tables = array();
     for ($i = 0; $i < mysql_num_rows($result); $i++) {
         $row = mysql_fetch_array($result);
         $tables[] = $row[0];
     }
     if (!empty($autoInstall->withDrop)) {
         $autoInstall->out("Dropping existing tables");
         foreach ($tables as $table) {
             executeQuery("DROP TABLE {$table}");
         }
     } elseif (in_array($autoInstall->dbPrefix . "settings", $tables)) {
         $autoInstall->outDie("The program seems to be installed already. Exiting.");
     }
 }
Esempio n. 2
0
function installMain(&$s)
{
    global $lll;
    global $hostName, $dbUser, $dbUserPw, $dbName, $dbPort, $dbSocket;
    global $scriptName;
    global $cookiePath;
    global $phpVersionMin, $mySqlVersionMin;
    $s = "";
    showInstallHeader($s1);
    $s .= $s1;
    // Ezt azert kommentezem ki, mert gyakran ujrainstallalok ugy hogy elozoleg
    // john-kent be voltam jelentkezve. Ilyen esetben mindig john
    // id-jevel hozta letre eloszor az admint, majd amikor john
    // letrehozasara kerult a sor, akkor hibat adott az install mondvan,
    // hogy ilyen id-ju juzer mar letezik:
    //if (!isset($_COOKIE["globalUserId"]))
    //{
    mt_srand((double) microtime() * 1000000);
    global $randIdMax, $randIdMin;
    if (!isset($randIdMin)) {
        $randIdMin = 0;
    }
    if (!isset($randIdMax)) {
        $randIdMax = getrandmax();
    }
    $randomId = (int) mt_rand($randIdMin, $randIdMax);
    setcookie("globalUserId", $randomId, Loginlib_ExpirationDate, $cookiePath);
    $_COOKIE["globalUserId"] = $randomId;
    //}
    if (isset($_POST["edit"])) {
        $s .= showEditForm(TRUE);
        return;
    }
    //if( isset($_POST["submit"]) &&
    //    $_POST["submit"]==$lll["install"] )
    //{
    //check file creation
    $ret = checkFileCreate();
    if ($ret == ok) {
        iPrint($lll["create_file_ok"], "ok", $sp);
        $s .= $sp;
        $createconf = TRUE;
    } else {
        if (!isset($_POST["confirm"])) {
            iPrint($lll["create_file_nok_ext"], "warn", $sp);
        } else {
            iPrint($lll["create_file_nok"], "warn", $sp);
        }
        $s .= $sp;
        $createconf = FALSE;
    }
    //check mysql connection
    $db->hostName = $hostName;
    $db->user = $dbUser;
    $db->password = $dbUserPw;
    $db->port = $dbPort;
    $db->socket = $dbSocket;
    $connectRet = checkMysql($db, $s1);
    $s .= $s1;
    if ($connectRet == ok) {
        iPrint($lll["mysql_found"], "ok", $sp);
        $s .= $sp;
        $connectok = TRUE;
        $pwok = TRUE;
    } elseif ($connectRet == mysql_access_denied) {
        iPrint($lll["mysql_found"], "ok", $sp);
        $s .= $sp;
        if ($dbUserPw == "") {
            iPrint(sprintf($lll["need_pw"], $dbUser), "warn", $sp);
            $s .= $sp;
            $s .= showEditForm(TRUE);
            return ok;
        } else {
            iPrint(sprintf($lll["incorr_pw"], $dbUser), "warn", $sp);
            $s .= $sp;
            $s .= showEditForm(TRUE);
            return ok;
        }
    } else {
        iPrint($lll["mysql_not_found"] . " (" . mysql_error() . ")", "warn", $sp);
        $s .= $sp;
        $s .= showEditForm(TRUE);
        return ok;
    }
    if (!DbInstall::checkComponentVersions($mySqlVersion, $phpVersion)) {
        iPrint(sprintf($lll["versionTooLow"], $mySqlVersionMin, $mySqlVersion, $phpVersionMin, $phpVersion), "err", $sp);
        $s .= $sp;
        return ok;
    }
    if (!isset($_POST["confirm"])) {
        $s .= showAskConfirm();
        return ok;
    }
    if (isset($_COOKIE["globalUserId"])) {
        iPrint($lll["cookieok"], "ok", $sp);
        $s .= $sp;
    } else {
        iPrint($lll["cookienok"], "err", $sp);
        $s .= $sp;
        return;
    }
    //check if db exists
    $ret = mysql_select_db($dbName);
    if ($ret) {
        iPrint(sprintf($lll["db_installed"], $dbName), "ok", $sp);
        $s .= $sp;
    } else {
        $ret = createDb();
        if ($ret != ok) {
            $s1 = sprintf($lll["cantcreatedb"], $dbUser);
            iPrint($s1, "warn", $sp);
            $s .= $sp;
            return ok;
        } else {
            iPrint(sprintf($lll["db_created"], $dbName), "ok", $sp);
            $s .= $sp;
            //select db
            $ret = mysql_select_db($dbName);
        }
    }
    $ret = DbInstall::installCreateTables();
    if ($ret != ok) {
        iPrint($lll["inst_create_table_err"], "err", $sp);
        $s .= $sp;
        return $ret;
    } else {
        iPrint($lll["tables_installed"], "ok", $sp);
        $s .= $sp;
    }
    createFirstAdmin();
    appFillTables();
    iPrint($lll["tables_filled"], "ok", $sp);
    $s .= $sp;
    if ($createconf) {
        //config file can be generated
        $ret = writeConfigFile($s1);
        if ($ret != ok) {
            $s .= $s1;
            return;
        }
    } else {
        //config can't be created
        iPrint($lll["compare_conf"], "warn", $sp);
        $s .= $sp;
        showConfFileHtml($s1);
        $s .= $s1;
        iPrint($lll["afterwrconf"], "warn", $s1);
        $s .= $s1;
    }
    iPrint($lll["move_inst_file"], "warn", $s1);
    $s .= $s1;
    iPrint(sprintf($lll["congrat"], "Noah's Classifieds"), "hurra", $s1);
    $s .= $s1;
    iPrint($lll["inst_ch_pw"], "warn", $s1);
    $s .= $s1;
    //send him to the application:
    $s .= "<a href='{$scriptName}'>" . sprintf($lll["inst_click"], "Noah's Classifieds") . "</a>";
    return ok;
}