You may know that at the start of the year I published with a friend an online dashboard to monitor your nodes and a place to see progression of your node.
Lots of you wanted a dashboard which is kept locally, so we worked hard to figure out how we could do this be implemented for multiple nodes or possibly multiple virtual machines running storj nodes.
Not something I’ve looked into just yet, it would be good if it’s possible to make a container with nginx/php/MySQL and the GitHub all in one… will take a look
Definitely will look into it, maybe look at a docker install method at minimum , will need to do some testing and then could possibly make a video guide
[TEST] SQL Database Check/Test (*storjdashboard*)
[FAIL] SQL Tables Do Not Match Expected > Create DB
The mysql user storjdashboard exists and has full permissions on the database with the same name. I tested it on the command line and can create tables.
When I click on “Create DB” the next window shows the credentials, after Next I’m asked for the Admin Usernam and password. I can only assume that I create an admin user here which I use later for logging into the dashboard. Your docs don’t say anything about this step.
After typing in a username and password I’m back to the error message from the beginning and turning in circles.
yes and I tried on the command line with -h localhost too.
When I do this, I get no errors. Everything looks ok.
Drop tables if exists
Created config
Created docker
Created login
Created nodes
Created paystubs
Flushed config
Flushed docker
Flushed login
Flushed nodes
Flushed paystubs
Admin Account Created
Config SQL Created
BUT, no tables get created
MariaDB [storjdashboard]> show tables;
Empty set (0.000 sec)
This is because there is no error message when connection to SQL is not working.
Afterwards I ran into another issue caused by empty lines being put into HTML. This time it was session initialization, which is also header information.
It was caused by 2 empty lines inbetween php blocks in cfg.php
Just regular MySQL, latest version. I used docker compose to deploy this dashboard.
Problem there is that you are just opening a connection and not catching errors, while supressing php errors so it silently fails.
Just test check for sql errors and test connection after mysqli_connect:
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (!mysqli_query($sql, "SET a=1")) {
printf("Error message: %s\n", mysqli_error($sql));
}
Best practice to avoid whitespaces is not to use multiple php blocks, just merge them all together. There is no benefit of having multiple ones like that.
For example in index.php:
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
// COUNTING PAGE TIME
// config
?>
<?php if(!isset($_GET['page']) && file_exists("install")){header("location: install");exit;}?>
<?php if(isset($_GET['page']) && $_GET['page']=='install' && isset($_GET['complete']) && $_GET['complete']==1) {
if(@rmdir("install")){header("location ./");}
if(file_exists('install')){ echo "<h2>Warning: Unable to remove install directory<br><br>You must remove INSTALL folder manually if there is no FAIL tasks.<br>Otherwise you will need to fix the FAIL tasks manually.</h2>"; }else{ header("location: ./"); } exit; }?>
<?php require_once("cfg.php"); ?>
<?php if($config_row['restrict']==1){ require_once($resitrct_file); } ?>
<?php require_once($sql_conn_file); ?>
<?php if($_SERVER['QUERY_STRING']==''){ header("location: ./?page=dashboard"); }; ?>
to
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
// COUNTING PAGE TIME
// config
if(!isset($_GET['page']) && file_exists("install")){header("location: install");exit;}
if(isset($_GET['page']) && $_GET['page']=='install' && isset($_GET['complete']) && $_GET['complete']==1) {
if(@rmdir("install")){header("location ./");}
if(file_exists('install')){ echo "<h2>Warning: Unable to remove install directory<br><br>You must remove INSTALL folder manually if there is no FAIL tasks.<br>Otherwise you will need to fix the FAIL tasks manually.</h2>"; }else{ header("location: ./"); }
exit;
}
require_once("cfg.php");
if($config_row['restrict']==1){ require_once($resitrct_file); }
require_once($sql_conn_file);
if($_SERVER['QUERY_STRING']==''){ header("location: ./?page=dashboard"); };
?>
This way you dont have to worry about whitespaces.
Only other problem I had was installer failed to delete install directory, but I didnt looked into code for that and just deleted it by hand. Everything works fine afterwards.
looking into making some changes to the /install/ directory files so that it can capture if there is no connection possible, it will go to the db_setup.php page
It should be right after mysqli_connect. can be in different file, but always after connect before any sql commands.
That way you can show an error when mysql breaks/crashes/permission are changed. Not just during setup.