eustasy/phoenix

View on GitHub
admin.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
 
// This page is not secure.
// It should not be deployed in a production environment.
 
require_once __DIR__.'/_phoenix.php';
require_once $settings['onces'].'once.sanitize.admin.php';
require_once $settings['functions'].'function.mysqli.drop.table.php';
require_once $settings['functions'].'function.mysqli.create.database.php';
 
// Tables Exist
$tables = array('peers', 'tasks', 'torrents');
$actual = 0;
foreach ( $tables as $table ) {
$sql = 'SELECT TABLE_NAME '.
'FROM `information_schema`.`TABLES` '.
'WHERE TABLE_SCHEMA = \''.$settings['db_name'].'\' '.
'AND TABLE_NAME = \''.$settings['db_prefix'].$table.'\';';
 
$result = mysqli_query($connection, $sql);
$count = mysqli_num_rows($result);
if ( !$count ) {
} else {
$actual += $count;
}
}
if ( count($tables) == $actual ) {
$tables_installed = true;
} else {
$tables_installed = false;
}
 
if (
$Process == 'setup' &&
(
$settings['db_reset'] ||
!$tables_installed
)
) {
// MySQL Setup
$success = true;
 
if ( $tables_installed ) {
if (
!drop_table($connection, $settings, 'peers') ||
!drop_table($connection, $settings, 'tasks') ||
!drop_table($connection, $settings, 'torrents')
) {
$success = false;
}
}
 
// Create the databases.
if ( !create_database($connection, $settings) ) {
$success = false;
}
 
if ( $success ) {
$Message = 'Your MySQL Tracker Database has been setup.';
require_once $settings['functions'].'function.task.log.php';
$result = task_log($connection, $settings, 'install', $time);
$tables_installed = true;
} else {
$Message = 'Could not setup the MySQL Database.';
}
Blank line found at end of control structure
 
Usage of ELSE IF is discouraged; use ELSEIF instead
} else if ( $Process == 'clean' ) {
require_once $settings['functions'].'function.task.clean.php';
if ( task_clean($connection, $settings, $time) ) {
$Message = 'The peers list has been cleaned.';
} else {
$Message = 'Could not clean the peers list.';
}
Blank line found at end of control structure
 
Usage of ELSE IF is discouraged; use ELSEIF instead
} else if ( $Process == 'optimize' ) {
require_once $settings['functions'].'function.task.optimize.php';
if ( task_optimize($connection, $settings, $time) ) {
$Message = 'Your MySQL Tracker Database has been optimized.';
} else {
$Message = 'Could not optimize the MySQL Database.';
}
}
 
?><!DOCTYPE html>
<html lang="en">
<head>
<title>Phoenix Diagnostics and Utilities</title>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/gh/jquery/jquery@3/dist/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.mysql').submit(function() {
$('input[type="submit"]').attr('disabled','disabled');
});
});
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/combine/gh/eustasy/Colors.css@1/colors.min.css,gh/necolas/normalize.css@8/normalize.min.css">
<style>
body {
margin: 0 auto;
max-width: 600px;
padding: 1% 10%;
text-align: center;
width: 80%;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: normal;
}
a {
text-decoration: none;
}
input {
border: none;
}
input:disabled {
background: #ecf0f1;
color: #7f8c8d;
}
.box {
padding: 1em;
}
.button {
border-radius: .2em;
padding: .3em;
}
p .button {
margin-top: -.3em;
}
.button.p-like {
margin: 0.7em 0;
}
.clear {
clear: both;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
.text-center {
text-align: center;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
</style>
</head>
<body>
 
<?php
 
echo '
<h1>Compatibility Check</h1>
<p class="text-center color-9">'.$settings['phoenix_version'].'</p>';
 
// PHP Version
$php_version = PHP_VERSION;
 
// >= 5.3
Line indented incorrectly; expected 0 spaces, found 4
if ( version_compare(PHP_VERSION, '5.5.0', '>=') ) {
echo '
<p class="box background-green-sea color-clouds">Your PHP version is >= 5.5</td>
<p class="color-asbestos">PHP Version: '.$php_version.'</p>';
$php_compat = true;
 
// >= 5.0
Usage of ELSE IF is discouraged; use ELSEIF instead
Line indented incorrectly; expected 0 spaces, found 4
} else if ( version_compare(PHP_VERSION, '5.0.0', '>=') ) {
echo '
<p class="box background-sun-flower color-midnight-blue">Your PHP version is >= 5.0, but < 5.5.
We recommend updating to PHP >= 5.5</p]>
<p class="color-asbestos">PHP Version: '.$php_version.'</p>';
$php_compat = 'Partial';
 
// < 5
Line indented incorrectly; expected 0 spaces, found 4
} else {
echo '
<p class="box background-pomegranate color-clouds">Phoenix is unable to run. Your PHP version is < 5.0</td>
<p class="color-asbestos">PHP Version: '.$php_version.'</p>';
$php_compat = false;
Line indented incorrectly; expected 0 spaces, found 4
}
 
// No MySQL
Line indented incorrectly; expected 0 spaces, found 4
if ( !class_exists('mysqli') ) {
echo '
<p class="box background-pomegranate color-clouds">Your server does not support MySQL.</td>';
$mysql_compat = false;
 
// Yes MySQL
Line indented incorrectly; expected 0 spaces, found 4
} else {
// Version
$mysql_version = mysqli_get_client_info();
$mysql_version = trim(substr($mysql_version, 0, strpos($mysql_version, '-')), 'mysqlnd ');
echo '
<p class="box background-green-sea color-clouds">Your server supports MySQL.</td>
<p class="color-asbestos">MySQL Version: '.$mysql_version.'</p>';
$mysql_compat = true;
 
Line indented incorrectly; expected 4 spaces, found 8
if ( $tables_installed ) {
$table_size_query = 'SELECT `data_length` AS `Data`, `index_length` AS `Indexes`, SUM( `data_length` + `index_length` ) AS `Total`, SUM( `data_free` ) AS `Free` FROM `information_schema`.`TABLES` WHERE `table_schema` = \''.$settings['db_name'].'\' AND `table_name` = \'__TABLE_NAME__\' GROUP BY `table_schema`;';
Line indented incorrectly; expected 8 spaces, found 12
foreach ( $tables as $table ) {
$size = str_replace('__TABLE_NAME__', $settings['db_prefix'].$table, $table_size_query);
$size = mysqli_query($connection, $size, MYSQLI_STORE_RESULT);
Line indented incorrectly; expected 12 spaces, found 16
if ( $size ) {
$table_size[$table] = mysqli_fetch_assoc($size);
Line indented incorrectly; expected 12 spaces, found 16
}
Line indented incorrectly; expected 8 spaces, found 12
}
$database_size = 'SELECT `data_length` AS `Data`, `index_length` AS `Indexes`, SUM( `data_length` + `index_length` ) AS `Total`, SUM( `data_free` ) AS `Free` FROM `information_schema`.`TABLES` WHERE `table_schema` = \''.$settings['db_name'].'\' GROUP BY `table_schema`;';
$database_size = mysqli_query($connection, $database_size, MYSQLI_STORE_RESULT);
Line indented incorrectly; expected 8 spaces, found 12
if ( $database_size ) {
$database_size = mysqli_fetch_assoc($database_size);
Line indented incorrectly; expected 8 spaces, found 12
}
echo '
<p class="box background-green-sea color-clouds">All your tables are installed.';
Line indented incorrectly; expected 8 spaces, found 12
if ( $database_size ) {
echo ' Their current size is '.number_format($database_size['Total']).' bytes.';
Line indented incorrectly; expected 8 spaces, found 12
}
echo '</td>';
Line indented incorrectly; expected 4 spaces, found 8
} else {
echo '
<p class="box background-pomegranate color-clouds">Some or all of your tables are not installed.</p>';
Line indented incorrectly; expected 4 spaces, found 8
}
 
// Database Utilities
echo '
<br>
<h1>Utilities</h1>';
 
// $Messages
Line indented incorrectly; expected 4 spaces, found 8
if ( isset($Message) ) {
echo '
<div class="box background-wisteria color-clouds">
<h3>'.$Message.'</div></h3>
</div>';
Line indented incorrectly; expected 4 spaces, found 8
}
 
Line indented incorrectly; expected 4 spaces, found 8
if (
$settings['db_reset'] ||
!$tables_installed
) {
echo '
<form class="mysql" action="" method="POST">
<p class="box background-pomegranate color-clouds">You should set
<code>$settings[\'db_reset\']</code>
to false to disable resets,<br>
or delete <code>admin.php</code> when you\'re up and running.</p>
<p class="float-left text-left">Install, Upgrade, and Reset</p>
<input type="hidden" name="process" value="setup">
<input class="button background-belize-hole color-clouds float-right" type="submit" name="submit" value="Setup">
<div class="clear"></div>
</form>';
Line indented incorrectly; expected 4 spaces, found 8
} else {
echo '
<p class="text-left color-asbestos">Install, Upgrade, and Reset
<span class="button background-clouds float-right">Disabled</span></p>
<div class="clear"></div>';
Line indented incorrectly; expected 4 spaces, found 8
}
Line indented incorrectly; expected 4 spaces, found 8
if ( $tables_installed ) {
echo '
<form class="mysql" action="" method="POST">
<p class="float-left text-left">Clean out redundant peers</p>
<input type="hidden" name="process" value="clean">
<input class="button background-belize-hole color-clouds float-right p-like" type="submit" name="submit" value="Clean">
<div class="clear"></div>
</form>';
echo '
<form class="mysql" action="" method="POST">
<p class="float-left text-left">Check, Analyze, Repair, and Optimize</p>
<input type="hidden" name="process" value="optimize">
<input class="button background-belize-hole color-clouds float-right p-like" type="submit" name="submit" value="Optimize">
<div class="clear"></div>
</form>';
Line indented incorrectly; expected 4 spaces, found 8
}
Blank line found at end of control structure
 
Line indented incorrectly; expected 0 spaces, found 4
}
 
echo '
</body>
</html>';