Your Database passwords do not match.";
}
//Validate admin password
if ($adminpass1 != $adminpass2) {
$validerror .= "
Your Administrator account passwords do not match.";
}
echo "Success!
";
flush();
//Validate DB connectivity
echo "Checking DB connectivity...";
flush();
$con=mysqli_connect($servername,$dbuser,$dbpass1);
if (mysqli_connect_errno())
{
$validerror .= "
Cannot connect the the database using the supplied information.";
}
echo "Success!
";
flush();
//Validate that the config directories are writable
echo "Checking config folder permissions...";
flush();
if (!is_writable(dirname('../../includes/functions.php')))
{
$validerror .= "
Cannot write the configuration files. Please check the /includes/ folder permissions. See the RPints Installation page on www.raspberrypints.com.";
}
if (!is_writable(dirname('../../admin/includes/checklogin.php')))
{
$validerror .= "
Cannot write the configuration files. Please check the /admin/includes/ folder permissions. See the RPints Installation page on www.raspberrypints.com.";
}
echo "Success!
";
flush();
//##TODO## Check if administrator account already exists
//Display errors and die
if ($validerror !='')
{
echo "";
echo $validerror;
echo "
Please press the back button on your browser to fix these errors";
echo "";
die();
}
// CLEAR INSTALLATION DATA ROUTINES
if ($action == 'remove')
{
echo "Deleting raspberrypints database...";
flush();
$con=mysqli_connect($servername,$dbuser,$dbpass1);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "DROP database raspberrypints;";
$result = mysqli_query($con,$sql);
mysqli_close($con);
echo "Success!
";
flush();
echo "Removing configuration files...";
flush();
try {
unlink('../../includes/config.php');
unlink('../../admin/includes/conn.php');
unlink('../../admin/includes/configp.php');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
//unlink('../../includes/config.php');
//unlink('../../admin/includes/conn.php');
//unlink('../../admin/includes/configp.php');
echo "Success!
";
flush();
}
if ($action == 'install')
{
require_once __DIR__.'/config_files.php';
//-----------------Create the main config file-----------------
echo "Update config files...";
flush();
file_put_contents('../../includes/config.php', $mainconfigstring);
echo "Success!
";
flush();
// -----------------Create the admin files----------------------
echo "Update admin config files...";
flush();
file_put_contents('../../admin/includes/conn.php', $adminconfig1);
file_put_contents('../../admin/includes/configp.php', $adminconfig2);
echo "Success!
";
flush();
//-----------------Create RPints User--------------------------
echo "Creating RPints database user...";
flush();
$con=mysqli_connect($servername,$dbuser,$dbpass1);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "GRANT ALL ON *.* TO '" . $dbuser . "'@'" . $servername . "' IDENTIFIED BY '" . $dbpass1 . "' WITH GRANT OPTION;";
$result = mysqli_query($con,$sql);
mysqli_close($con);
echo "Success!
";
flush();
//-----------------Run The Schema File-------------------------
echo "Running Database Script...";
flush();
$dbms_schema = "../../sql/schema.sql";
$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die('Cannot find SQL schema file. ');
$sql_query = remove_remarks($sql_query);
$sql_query = remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, ';');
mysqli_connect($servername,$dbuser,$dbpass1) or die('error connection');
$i=1;
foreach($sql_query as $sql){
//echo $i++;
//echo " ";
//echo $sql;
//echo "
";
mysqli_query($sql) or die('error in query');
}
echo "Success!
";
flush();
//-----------------Add the admin user to the Users DB----------
echo "Adding new admin user...";
flush();
$con=mysqli_connect($servername,$dbuser,$dbpass1,"raspberrypints");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$currentdate = Date('Y-m-d H:i:s');
$sql = "INSERT INTO users (username, password, name, email, createdDate, modifiedDate) VALUES ('" . $adminuser . "','" . $adminhash . "','" . $adminname . "','" . $adminemail . "','" . $currentdate . "','" . $currentdate . "');";
$result = mysqli_query($con,$sql);
mysqli_close($con);
echo "Success!
";
flush();
//-----------------Delete the index.html page-----------------
echo "Deleting default index.html page...";
flush();
if (!unlink("../../index.html"))
{
echo ("File already deleted");
}
else
{
echo ("Success!");
}
flush();
//-----------------Load the sample data if requested-----------
if(!empty($_POST['sampledata']))
{
echo "Adding sample data...";
flush();
$dbms_schema = "../../sql/test_data.sql";
$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die('Cannot find SQL schema file. ');
$sql_query = remove_remarks($sql_query);
$sql_query = remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, ';');
mysqli_connect($servername,$dbuser,$dbpass1) or die('error connection');
$i=1;
foreach($sql_query as $sql){
//echo $i++;
//echo " ";
mysqli_query($sql) or die('error in query');
}
echo "Success!
";
flush();
}
}
if ($action != 'remove')
{
##TODO## Add better error handling before showing the Success message
echo '
Congratulations! Your Raspberry Pints has been setup successfully.
';
echo 'Click for - Tap List
';
echo 'Click for - Administration
';
}
?>