mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix coding style part 2
This commit is contained in:
+132
-167
@@ -3,10 +3,9 @@
|
||||
$stage = $_POST['stage'];
|
||||
|
||||
// Before we do anything, if we see config.php, redirect back to the homepage.
|
||||
if(file_exists('../config.php') && $stage != "6")
|
||||
{
|
||||
header("Location: /");
|
||||
exit;
|
||||
if(file_exists('../config.php') && $stage != "6") {
|
||||
header("Location: /");
|
||||
exit;
|
||||
}
|
||||
|
||||
// List of php modules we expect to see
|
||||
@@ -20,76 +19,65 @@ $add_user = $_POST['add_user'] ?: '';
|
||||
$add_pass = $_POST['add_pass'] ?: '';
|
||||
$add_email = $_POST['add_email'] ?: '';
|
||||
|
||||
if($stage == "4" || $stage == "3")
|
||||
{
|
||||
// Ok now let's set the db connection up
|
||||
$config['db_host']=$dbhost;
|
||||
$config['db_user']=$dbuser;
|
||||
$config['db_pass']=$dbpass;
|
||||
$config['db_name']=$dbname;
|
||||
if($stage == "4" || $stage == "3") {
|
||||
// Ok now let's set the db connection up
|
||||
$config['db_host']=$dbhost;
|
||||
$config['db_user']=$dbuser;
|
||||
$config['db_pass']=$dbpass;
|
||||
$config['db_name']=$dbname;
|
||||
}
|
||||
|
||||
include("../includes/defaults.inc.php");
|
||||
require '../includes/defaults.inc.php';
|
||||
// Work out the install directory
|
||||
$cur_dir = explode('/',$_SERVER['DOCUMENT_ROOT']);
|
||||
$check = end($cur_dir);
|
||||
if( empty($check) ) {
|
||||
$install_dir = array_pop($cur_dir);
|
||||
$install_dir = array_pop($cur_dir);
|
||||
}
|
||||
unset($check);
|
||||
$install_dir = array_pop($cur_dir);
|
||||
$install_dir = implode('/',$cur_dir);
|
||||
$config['install_dir'] = $install_dir;
|
||||
$config['log_dir'] = $install_dir.'/logs';
|
||||
if($_POST['stage'] == "3" || $_POST['stage'] == "4")
|
||||
{
|
||||
include_once("../includes/definitions.inc.php");
|
||||
if($_POST['stage'] == "3" || $_POST['stage'] == "4") {
|
||||
require_once '../includes/definitions.inc.php';
|
||||
}
|
||||
include("../includes/functions.php");
|
||||
include("includes/functions.inc.php");
|
||||
require '../includes/functions.php';
|
||||
require 'includes/functions.inc.php';
|
||||
|
||||
// Check we can connect to MySQL DB, if not, back to stage 1 :)
|
||||
if($stage == 2)
|
||||
{
|
||||
$test_db = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
|
||||
if(mysqli_connect_error())
|
||||
{
|
||||
$stage = 1;
|
||||
$msg = "Couldn't connect to the database, please check your details<br /> " . mysqli_connect_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT * FROM users LIMIT 1";
|
||||
if(mysqli_query($test_db,$sql))
|
||||
{
|
||||
$stage = 3;
|
||||
$msg = "It appears that the database is already setup so have moved onto stage $stage";
|
||||
if($stage == 2) {
|
||||
$test_db = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
|
||||
if(mysqli_connect_error()) {
|
||||
$stage = 1;
|
||||
$msg = "Couldn't connect to the database, please check your details<br /> " . mysqli_connect_error();
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT * FROM users LIMIT 1";
|
||||
if(mysqli_query($test_db,$sql)) {
|
||||
$stage = 3;
|
||||
$msg = "It appears that the database is already setup so have moved onto stage $stage";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($stage == "4")
|
||||
{
|
||||
// Now check we have a username, password and email before adding new user
|
||||
if(empty($add_user) || empty($add_pass) || empty($add_email))
|
||||
{
|
||||
$stage = 4;
|
||||
$msg = "You haven't entered enough information to add the user account, please check below and re-try";
|
||||
}
|
||||
elseif($stage == "4") {
|
||||
// Now check we have a username, password and email before adding new user
|
||||
if(empty($add_user) || empty($add_pass) || empty($add_email)) {
|
||||
$stage = 4;
|
||||
$msg = "You haven't entered enough information to add the user account, please check below and re-try";
|
||||
}
|
||||
}
|
||||
elseif($stage == "6")
|
||||
{
|
||||
// If we get here then let's do some final checks.
|
||||
if(!file_exists("../config.php"))
|
||||
{
|
||||
// config.php file doesn't exist. go back to that stage
|
||||
$msg = "config.php still doesn't exist";
|
||||
$stage = "5";
|
||||
}
|
||||
elseif($stage == "6") {
|
||||
// If we get here then let's do some final checks.
|
||||
if(!file_exists("../config.php")) {
|
||||
// config.php file doesn't exist. go back to that stage
|
||||
$msg = "config.php still doesn't exist";
|
||||
$stage = "5";
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($stage))
|
||||
{
|
||||
$stage = '0';
|
||||
if(empty($stage)) {
|
||||
$stage = '0';
|
||||
}
|
||||
|
||||
$total_stages = 6;
|
||||
@@ -138,8 +126,8 @@ $complete = 1;
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if(!empty($msg))
|
||||
{
|
||||
|
||||
if(!empty($msg)) {
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
@@ -172,8 +160,7 @@ if(!empty($msg))
|
||||
|
||||
<?php
|
||||
|
||||
if($stage == 0)
|
||||
{
|
||||
if($stage == 0) {
|
||||
|
||||
?>
|
||||
|
||||
@@ -198,57 +185,51 @@ if($stage == 0)
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
foreach ($modules as $extension)
|
||||
{
|
||||
if (extension_loaded("$extension"))
|
||||
{
|
||||
$ext_loaded = 'yes';
|
||||
$row_class = 'success';
|
||||
} else {
|
||||
$ext_loaded = 'no';
|
||||
$row_class = 'danger';
|
||||
$complete = 0;
|
||||
}
|
||||
foreach ($modules as $extension) {
|
||||
if (extension_loaded("$extension")) {
|
||||
$ext_loaded = 'yes';
|
||||
$row_class = 'success';
|
||||
}
|
||||
else {
|
||||
$ext_loaded = 'no';
|
||||
$row_class = 'danger';
|
||||
$complete = 0;
|
||||
}
|
||||
|
||||
echo(" <tr class='$row_class'>
|
||||
<td>$extension</td>
|
||||
<td>$ext_loaded</td>");
|
||||
if($ext_loaded == 'no')
|
||||
{
|
||||
echo("<td>apt-get install php5-$extension / yum install php-$extension</td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("<td></td>");
|
||||
}
|
||||
echo("</tr>");
|
||||
}
|
||||
echo(" <tr class='$row_class'>
|
||||
<td>$extension</td>
|
||||
<td>$ext_loaded</td>");
|
||||
if($ext_loaded == 'no') {
|
||||
echo("<td>apt-get install php5-$extension / yum install php-$extension</td>");
|
||||
}
|
||||
else {
|
||||
echo("<td></td>");
|
||||
}
|
||||
echo("</tr>");
|
||||
}
|
||||
|
||||
// Check for pear install
|
||||
include_once 'System.php';
|
||||
if(class_exists('System')===true)
|
||||
{
|
||||
$ext_loaded = 'yes';
|
||||
$row_class = 'success';
|
||||
}
|
||||
else
|
||||
{
|
||||
$ext_loaded = 'no';
|
||||
$row_class = 'danger';
|
||||
}
|
||||
// Check for pear install
|
||||
require_once 'System.php';
|
||||
|
||||
echo(" <tr class='$row_class'>
|
||||
<td>pear</td>
|
||||
<td>$ext_loaded</td>");
|
||||
if($ext_loaded == 'no')
|
||||
{
|
||||
echo("<td>apt-get install php5-$extension / yum install php-$extension</td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("<td></td>");
|
||||
}
|
||||
echo("</tr>");
|
||||
if(class_exists('System') === true) {
|
||||
$ext_loaded = 'yes';
|
||||
$row_class = 'success';
|
||||
}
|
||||
else {
|
||||
$ext_loaded = 'no';
|
||||
$row_class = 'danger';
|
||||
}
|
||||
|
||||
echo(" <tr class='$row_class'>
|
||||
<td>pear</td>
|
||||
<td>$ext_loaded</td>");
|
||||
if($ext_loaded == 'no') {
|
||||
echo("<td>apt-get install php5-$extension / yum install php-$extension</td>");
|
||||
}
|
||||
else {
|
||||
echo("<td></td>");
|
||||
}
|
||||
echo("</tr>");
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
@@ -261,7 +242,7 @@ else
|
||||
<div class="col-md-6">
|
||||
<form class="form-inline" role="form" method="post">
|
||||
<input type="hidden" name="stage" value="1">
|
||||
<button type="submit" class="btn btn-success" <?php if($complete == '0') { echo "disabled='disabled'"; } ?>>Next Stage</button>
|
||||
<button type="submit" class="btn btn-success" <?php if($complete == '0') echo "disabled='disabled'"; ?>>Next Stage</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
@@ -270,8 +251,7 @@ else
|
||||
|
||||
<?php
|
||||
}
|
||||
elseif($stage == 1)
|
||||
{
|
||||
elseif($stage == 1) {
|
||||
|
||||
?>
|
||||
|
||||
@@ -315,8 +295,7 @@ elseif($stage == 1)
|
||||
<?php
|
||||
|
||||
}
|
||||
elseif($stage == "2")
|
||||
{
|
||||
elseif($stage == "2") {
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
@@ -325,12 +304,12 @@ elseif($stage == "2")
|
||||
<h5 class="text-center">Importing MySQL DB</h5>
|
||||
<?php
|
||||
// Ok now let's set the db connection up
|
||||
$config['db_host']=$dbhost;
|
||||
$config['db_user']=$dbuser;
|
||||
$config['db_pass']=$dbpass;
|
||||
$config['db_name']=$dbname;
|
||||
$sql_file = '../build.sql';
|
||||
require('../build-base.php');
|
||||
$config['db_host']=$dbhost;
|
||||
$config['db_user']=$dbuser;
|
||||
$config['db_pass']=$dbpass;
|
||||
$config['db_name']=$dbname;
|
||||
$sql_file = '../build.sql';
|
||||
require('../build-base.php');
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
@@ -355,8 +334,7 @@ require('../build-base.php');
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
elseif($stage == "5")
|
||||
{
|
||||
elseif($stage == "5") {
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
@@ -410,27 +388,24 @@ $config_file = <<<"EOD"
|
||||
#\$config\['update'\] = 0;
|
||||
EOD;
|
||||
|
||||
if(!file_exists("../config.php"))
|
||||
{
|
||||
if(!file_exists("../config.php")) {
|
||||
$conf = fopen("../config.php", 'w');
|
||||
if ($conf != false)
|
||||
{
|
||||
if(fwrite($conf, "<?php\n") === FALSE)
|
||||
{
|
||||
echo("<div class='alert alert-danger'>We couldn't create the config.php file, please create this manually before continuing by copying the below into a config.php in the root directory of your install (typically /opt/librenms/)</div>");
|
||||
echo("<pre><?php\n".stripslashes($config_file)."</pre>");
|
||||
}
|
||||
else
|
||||
{
|
||||
$config_file = stripslashes($config_file);
|
||||
fwrite($conf,$config_file);
|
||||
echo("<div class='alert alert-success'>The config file has been created</div>");
|
||||
}
|
||||
} else {
|
||||
if ($conf != false) {
|
||||
if(fwrite($conf, "<?php\n") === FALSE) {
|
||||
echo("<div class='alert alert-danger'>We couldn't create the config.php file, please create this manually before continuing by copying the below into a config.php in the root directory of your install (typically /opt/librenms/)</div>");
|
||||
echo("<pre><?php\n".stripslashes($config_file)."</pre>");
|
||||
}
|
||||
else {
|
||||
$config_file = stripslashes($config_file);
|
||||
fwrite($conf,$config_file);
|
||||
echo("<div class='alert alert-success'>The config file has been created</div>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo("<div class='alert alert-danger'>We couldn't create the config.php file, please create this manually before continuing by copying the below into a config.php in the root directory of your install (typically /opt/librenms/)</div>");
|
||||
echo("<pre><?php\n".stripslashes($config_file)."</pre>");
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form class="form-horizontal" role="form" method="post">
|
||||
<input type="hidden" name="stage" value="6">
|
||||
@@ -450,8 +425,7 @@ EOD;
|
||||
<?php
|
||||
|
||||
}
|
||||
elseif($stage == "3")
|
||||
{
|
||||
elseif($stage == "3") {
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
@@ -489,39 +463,32 @@ elseif($stage == "3")
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
elseif($stage == "4")
|
||||
{
|
||||
$proceed = 1;
|
||||
elseif($stage == "4") {
|
||||
$proceed = 1;
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<?php
|
||||
include("includes/authenticate.inc.php");
|
||||
if (auth_usermanagement())
|
||||
{
|
||||
if (!user_exists($add_user))
|
||||
{
|
||||
if (adduser($add_user,$add_pass,'10',$add_email))
|
||||
{
|
||||
echo("<div class='alert alert-success'>User has been added successfully</div>");
|
||||
$proceed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("<div class='alert alert-danger'>User hasn't been added, please try again</div>");
|
||||
}
|
||||
require 'includes/authenticate.inc.php';
|
||||
if (auth_usermanagement()) {
|
||||
if (!user_exists($add_user)) {
|
||||
if (adduser($add_user,$add_pass,'10',$add_email)) {
|
||||
echo("<div class='alert alert-success'>User has been added successfully</div>");
|
||||
$proceed = 0;
|
||||
}
|
||||
else {
|
||||
echo("<div class='alert alert-danger'>User hasn't been added, please try again</div>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo("<div class='alert alert-danger'>User $add_user already exists!</div>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("<div class='alert alert-danger'>User $add_user already exists!</div>");
|
||||
else {
|
||||
echo("<div class='alert alert-danger'>Auth module isn't loaded</div>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("<div class='alert alert-danger'>Auth module isn't loaded</div>");
|
||||
}
|
||||
|
||||
?>
|
||||
<form class="form-horizontal" role="form" method="post">
|
||||
@@ -530,7 +497,7 @@ $proceed = 1;
|
||||
<input type="hidden" name="dbuser" value="<?php echo $dbuser; ?>">
|
||||
<input type="hidden" name="dbpass" value="<?php echo $dbpass; ?>">
|
||||
<input type="hidden" name="dbname" value="<?php echo $dbname; ?>">
|
||||
<button type="submit" class="btn btn-success" <?php if($proceed == "1") { echo "disabled='disabled'"; } ?>>Generate Config</button>
|
||||
<button type="submit" class="btn btn-success" <?php if($proceed == "1") echo "disabled='disabled'"; ?>>Generate Config</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
@@ -538,8 +505,7 @@ $proceed = 1;
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
elseif($stage == "6")
|
||||
{
|
||||
elseif($stage == "6") {
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
@@ -556,4 +522,3 @@ elseif($stage == "6")
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user