Skip to content

Commit

Permalink
Merge pull request #951 from wrongecho/debug-assistance
Browse files Browse the repository at this point in the history
Debugging help
  • Loading branch information
johnnyq authored May 5, 2024
2 parents 0f6a781 + cd66824 commit 4069dc9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 50 deletions.
96 changes: 47 additions & 49 deletions admin_debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function countFilesInDirectory($dir) {
// Function to compare two arrays recursively and return the differences
function arrayDiffRecursive($array1, $array2) {
$diff = array();

foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!isset($array2[$key]) || !is_array($array2[$key])) {
Expand All @@ -56,25 +56,25 @@ function arrayDiffRecursive($array1, $array2) {
}
}
}

return $diff;
}

// Function to load the table structures from an SQL dump file URL
function loadTableStructuresFromSQLDumpURL($fileURL) {
$context = stream_context_create(array('http' => array('header' => 'Accept: application/octet-stream')));
$fileContent = file_get_contents($fileURL, false, $context);

if ($fileContent === false) {
return null;
}

$structure = array();
$queries = explode(";", $fileContent);

foreach ($queries as $query) {
$query = trim($query);

if (!empty($query)) {
if (preg_match("/^CREATE TABLE `(.*)` \((.*)\)$/s", $query, $matches)) {
$tableName = $matches[1];
Expand All @@ -83,39 +83,39 @@ function loadTableStructuresFromSQLDumpURL($fileURL) {
}
}
}

return $structure;
}

// Function to fetch the database structure from the MySQL server
function fetchDatabaseStructureFromServer() {

global $mysqli;

$tables = array();

// Fetch table names
$result = $mysqli->query("SHOW TABLES");

if ($result->num_rows > 0) {
while ($row = $result->fetch_row()) {
$tableName = $row[0];
$tables[$tableName] = array();
}
}

// Fetch table structures
foreach ($tables as $tableName => &$table) {
$result = $mysqli->query("SHOW CREATE TABLE `$tableName`");

if ($result->num_rows > 0) {
$row = $result->fetch_row();
$table['structure'] = $row[1];
}
}

//$mysqli->close();

return $tables;
}

Expand Down Expand Up @@ -185,11 +185,12 @@ function get_crontab() {
//Get loaded PHP modules
$loadedModules = get_loaded_extensions();

//Get Versions
//Get Server Info / Service versions
$phpVersion = phpversion();
$mysqlVersion = $mysqli->server_version;
$operatingSystem = shell_exec('uname -a');
$operatingSystem = php_uname();
$webServer = $_SERVER['SERVER_SOFTWARE'];
$errorLog = ini_get('error_log');

?>

Expand All @@ -198,20 +199,43 @@ function get_crontab() {
<h3 class="card-title"><i class="fas fa-fw fa-bug mr-2"></i>Debug</h3>
</div>
<div class="card-body">

<h3>Database Structure Check</h3>


<h3>Server Info</h3>

<?php
echo "PHP version: " . $phpVersion . "<br>";
echo "MySQL Version: " . $mysqlVersion . "<br>";
echo "Operating System: " . $operatingSystem . "<br>";
echo "Web Server: " . $webServer . "<br>";
echo "PHP Error Log: " . $errorLog
?>

<hr>

<h3>File System</h3>
<?php
$result = countFilesInDirectory($folderPath);

$totalFiles = $result['count'];
$totalSizeMB = round($result['size'] / (1024 * 1024), 2);

echo "Total number of files in $folderPath and its subdirectories: " . $totalFiles . "<br>";
echo "Total size of files in $folderPath and its subdirectories: " . $totalSizeMB . " MB";
?>

<hr>

<h3>Database Structure Check</h3>

<h4>Database stats</h4>

<?php
echo "Number of tables: " . $numTables . "<br>";
echo "Total number of fields: " . $numFields . "<br>";
echo "Total number of rows: " . $numRows . "<br>";
echo "Current Database Version: " . CURRENT_DATABASE_VERSION . "<br>";
?>

<hr>

<h4>Table Stats</h4>
Expand Down Expand Up @@ -255,34 +279,8 @@ function get_crontab() {

<hr>

<h3>Versions</h3>

<?php
echo "PHP version: " . $phpVersion . "<br>";
echo "MySQL Version: " . $mysqlVersion . "<br>";
echo "Operating System: " . $operatingSystem . "<br>";
echo "Web Server: " . $webServer;


?>

<hr>

<h3>File System</h3>
<?php
$result = countFilesInDirectory($folderPath);

$totalFiles = $result['count'];
$totalSizeMB = round($result['size'] / (1024 * 1024), 2);

echo "Total number of files in $folderPath and its subdirectories: " . $totalFiles . "<br>";
echo "Total size of files in $folderPath and its subdirectories: " . $totalSizeMB . " MB";
?>

<hr>

<h3>PHP Modules Installed</h3>

<?php
foreach ($loadedModules as $module) {
echo $module . "<br>";
Expand Down Expand Up @@ -311,7 +309,7 @@ function get_crontab() {
//Output the result
echo $phpinfo;
?>

<hr>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,9 @@
<ul>
<li>Please take a look over the install <a href="https://docs.itflow.org/installation">docs</a>, if you haven't already</li>
<li>Don't hesitate to reach out on the <a href="https://forum.itflow.org/t/support" target="_blank">forums</a> if you need any assistance</li>
<li><i>Your PHP Error log is at: <?php echo ini_get('error_log') ?></i></li>
</ul>
<br><p>A database must be created before proceeding - click on the button below to get started</p>
<br><p>A database must be created before proceeding - click on the button below to get started.</p>
<br><hr>
<p class="text-muted">ITFlow is <b>free software</b>: you can redistribute and/or modify it under the terms of the <a href="https://www.gnu.org/licenses/gpl-3.0.en.html" target="_blank">GNU General Public License</a>. <br> It is distributed in the hope that it will be useful, but <b>without any warranty</b>; without even the implied warranty of merchantability or fitness for a particular purpose.</p>
<?php
Expand Down

0 comments on commit 4069dc9

Please sign in to comment.