Пример #1
0
    public function RunChecks($postVar) 
    {
        $this->firstTime = (count($postVar) < 1);
        
        if($this->firstTime)
            return null;

        if(!key_exists("host", $postVar) || strlen($postVar["host"]) == 0)
            $this->errors[] = "You haven't written the host down.";

        if(!key_exists("username", $postVar) || strlen($postVar["username"]) == 0)
            $this->errors[] = "You haven't written the username down.";

        if(!key_exists("password", $postVar) || strlen($postVar["password"]) == 0)
            $this->errors[] = "You haven't written the password down.";

        if(!key_exists("database", $postVar) || strlen($postVar["database"]) == 0)
            $this->errors[] = "You haven't written the database name down.";

        if(count($this->errors) > 0)
            return false;

        $host = $postVar["host"];
        $username = $postVar["username"];
        $password = $postVar["password"];
        $database = $postVar["database"];

        try
        {
            include_once(dirname(__FILE__)."/../../core/Configuration/ConfigurationHandlers/BaseConfigurationHandler.php");
            include_once(dirname(__FILE__)."/../../core/Modules/DataContext/MySql_V1/DataContextConfigurationHandler.php");
            $configFile = dirname(__FILE__)."/../../core/Modules/DataContext/MySql_V1/Configuration.xml";
            $config = new \Swiftriver\Core\Modules\DataContext\MySql_V1\DataContextConfigurationHandler($configFile);
            $xml = $config->xml;
            $xml->properties->property[0]["value"] = $host;
            $xml->properties->property[1]["value"] = $username;
            $xml->properties->property[2]["value"] = $password;
            $xml->properties->property[3]["value"] = $database;
            $config->xml = $xml;
            $config->Save();
        }
        catch(\Exception $e)
        {
            $this->errors[] = "There was an issue saving the details to the configuration file ".
                              "I use. Please ensure you have completed the permissions step of ".
                              "this installer. If you're interested, the error was:" . $e;
            return false;
        }

        try
        {
            $filename = dirname(__FILE__)."/../../web/modules/riverid/classes/riveridconfig.php";
            $file = file($filename);
            $handle = fopen($filename, "w");
            foreach($file as $lineNumber => $line)
            {
                if(strpos($line, "\$databaseurl") != 0)
                    $lineToWrite = "    public static \$databaseurl = '$host';\n";
                elseif(strpos($line, "\$username") != 0)
                    $lineToWrite = "    public static \$username = '******';\n";
                elseif(strpos($line, "\$password") != 0)
                    $lineToWrite = "    public static \$password = '******';\n";
                elseif(strpos($line, "\$database") != 0)
                    $lineToWrite = "    public static \$database = '$database';\n";
                else
                    $lineToWrite = $line;

                fwrite($handle, $lineToWrite);
            }
            fclose($handle);

            $filename = dirname(__FILE__)."/../../web/modules/swiftrivertheming/classes/themingconfig.php";
            $file = file($filename);
            $handle = fopen($filename, "w");
            foreach($file as $lineNumber => $line)
            {
                if(strpos($line, "\$databaseurl") != 0)
                    $lineToWrite = "    public static \$databaseurl = '$host';\n";
                elseif(strpos($line, "\$username") != 0)
                    $lineToWrite = "    public static \$username = '******';\n";
                elseif(strpos($line, "\$password") != 0)
                    $lineToWrite = "    public static \$password = '******';\n";
                elseif(strpos($line, "\$database") != 0)
                    $lineToWrite = "    public static \$database = '$database';\n";
                else
                    $lineToWrite = $line;

                fwrite($handle, $lineToWrite);
            }
            fclose($handle);

        }
        catch (\Exception $e)
        {
            $this->errors[] = "There was an issue saving the details to the configuration file ".
                              "I use. Please ensure you have completed the permissions step of ".
                              "this installer. If your interested, the error was:" . $e;
            return false;
        }

        try
        {
            $link = mysql_connect($postVar["host"], $postVar["username"], $postVar["password"]);

            if(!$link)
            {
                $this->errors[] = "I tried to connect to the database using the 'mysql_connect' ".
                                  "function and the details you gave me but it didn't work.";
                return false;
            }

            $dbconnect = mysql_select_db($postVar["database"], $link);

            if(!$dbconnect)
            {
                $this->errors[] = "I connected to the database server ok but when I tried to ".
                                  "select the database you told me about, using 'mysql_select_db', ".
                                  "it didn't work.";
                return false;
            }
        }
        catch(\Exception $e)
        {
            $this->errors[] = "Something went wrong while I was trying to connect to the database. ".
                              "Here are the details: " . $e;
            return false;
        }

        return true;
    }
Пример #2
0
        $state = "error";
        $errors->dbuser = "******";
    }
    $dbpassword = $_POST["dbpassword"];
    if (trim($dbpassword) == "") {
        $state = "error";
        $errors->dbpassword = "******";
    }
    if (isset($errors)) {
        $state = "inputerror";
    } else {
        //now try to write the lot the config file.
        include_once dirname(__FILE__) . "/../Core/Configuration/ConfigurationHandlers/BaseConfigurationHandler.php";
        include_once dirname(__FILE__) . "/../Core/Modules/DataContext/MySql_V1/DataContextConfigurationHandler.php";
        $configFile = dirname(__FILE__) . "/../Core/Modules/DataContext/MySql_V1/Configuration.xml";
        $config = new \Swiftriver\Core\Modules\DataContext\MySql_V1\DataContextConfigurationHandler($configFile);
        $xml = $config->xml;
        $xml->properties->property[0]["value"] = $dbserver;
        $xml->properties->property[1]["value"] = $dbuser;
        $xml->properties->property[2]["value"] = $dbpassword;
        $xml->properties->property[3]["value"] = $dbname;
        $config->xml = $xml;
        $config->Save();
        $state = "finished";
    }
}
$welcomeMessage = "Ok, time to setup the database. Before you fill in the details " . "here, you should have created a database, user, and given " . "that user full rights to the database. If you haven't done that already, " . "do it before continuing.";
$errorMessage = "There were some issues with the data you entered. Can you check it " . "for me and try again?";
$finishedMessage = "That wasn't that bad now was it? I think were done here. As I said " . "I'm now going to hand you over to my old friend the Ushahidi installer so it " . "can walk you though the final bits of the installation, then you're done! " . "Oh, one last thing before I go...In future builds, I'll be handle all " . "the setup tasks. Thanks and see you on the other side!";
?>
<div id="index">