Skip to content

Commit

Permalink
Added error messages (and config.php) (fuzzymannerz#5)
Browse files Browse the repository at this point in the history
* Code cleanup as preperation
 - removed all query functions to system.php
 - swmp.php is now main file to get system information
 - moved additional util functions in utils.php (from mainclass.php)
 - added gitignore (with entries for intellij and normal default values)

* Added error messages for failed commands

* added config.php with a few settings (mainly to disable errors)

* Added new themes to config.php comment
  • Loading branch information
Mikescher authored and fuzzymannerz committed Sep 1, 2016
1 parent 77201ea commit 70b7053
Show file tree
Hide file tree
Showing 9 changed files with 821 additions and 722 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Thumbs.db
*~
*.DS_Store
#*
.idea/*
web.config

config.local.php
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ Simply run `bash <(curl -s -L https://getswmp.thefuzz.xyz)` from your Linux comm
### The Manual Way
1. [Download the Zip file](https://github.com/fuzzymannerz/swmp/archive/master.zip).
2. Extract the files to the web server. (You might want to secure access somehow, [.htpasswd](http://www.htaccesstools.com/htpasswd-generator/) maybe?)
3. That's it! (Unless you want to change the theme, in which case, read on!)
3. Optionally copy the file `config.php` to `config.local.php` and adjust the settings for your web server.
4. That's it! (Unless you want to change the theme, in which case, read on!)

## Themes
SWMP includes a selection of themes. The default being **simplex**. (The red and white one above)
![](http://i.imgur.com/vlw9NyV.png)
To choose another theme, edit **index.php** and change line **41** to the theme of your choice.
The choices of theme stylesheets are located in **~/css/themes/**.
To choose another theme, edit **config.local.php** and change line `"theme" => "slate"` to the theme of your choice. The choices are:
_cerulean, cosmo, lumen, paper, readable, sandstone, simplex, slate, spacelab, superhero, united_ and _yeti_.
All theme stylesheets are located in **~/css/themes/**.

## Show Some Love <3
If you make use of SWMP in some way, please consider a donation.
Expand Down
23 changes: 23 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*******************************************************************************/
/** to configure swmp copy this file to config.local.php and change the values */
/*******************************************************************************/

return array
(
// all themes are files in the /css/ folder
// available themes are:
// "cerulean", "cosmo", "lumen", "paper", "readable", "sandstone",
// "simplex", "slate", "spacelab", "superhero", "united", "yeti",
// "darkplex", "rose", "terminal"
"theme" => "simplex",

// if set to true errors are shown for system information that could not be recieved
// after the server is set up it is recommended to set this to false
"show_errors" => true,

// the windowtitle
// available replacements are {hostname}, {ip}, {os} and {kernel}
"window_title" => "SWMP | {hostname}",
);
425 changes: 232 additions & 193 deletions index.php

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions js/swmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@


// Get vars from system.php and set them for use
var jsonramdata = JSON.parse(ramdata);
var jsoncpudata = JSON.parse(cpudata);
var jsonbootupdata = JSON.parse(bootupdata);
var jsonswapdata = JSON.parse(swapdata);
var jsonnetworkdata = JSON.parse(networkdata);
var jsondiskdata = JSON.parse(diskdata);
var jsonramdata = ramdata;
var jsoncpudata = cpudata;
var jsonbootupdata = bootupdata;
var jsonswapdata = swapdata;
var jsonnetworkdata = networkdata;
var jsondiskdata = diskdata;

// Set the RAM percentage used
var ramdef = jsonramdata.percent_used;
Expand Down
214 changes: 0 additions & 214 deletions php/class.php

This file was deleted.

72 changes: 72 additions & 0 deletions php/swmp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*///////////////////////////////////////////////
/// ///
/// SWMP - Server Web Monitoring Page ///
/// By Fuzzy - thefuzz.xyz - 2016 ///
/// ///
/////////////////////////////////////////////////
/// ///
/// Credits, downloads and usage info: ///
/// https://github.com/fuzzymannerz/swmp ///
/// ///
////////////////////////////////////////////////////////////
/// ///
/// If you make use of SWMP please consider to ///
/// show some love via PayPal, Flattr or BTC. <3 ///
/// (Details are on the GitHub page or my website.) ///
/// ///
//////////////////////////////////////////////////////////*/

// ================ Load settings ================

$config = require "config.php";
if(file_exists('config.local.php')){
$config = array_merge($config, require 'config.local.php');
};

//===================================================

require 'php/system.php';

$all_errors = array();

// ================ Get system info ================

$hostname = getSystemHostname($all_errors);
$ip = getLanIp($all_errors);
$cores = getCpuCoresNumber($all_errors);
$os = getOperatingSystem($all_errors);
$kernel = getKernel($all_errors);
$uptime = getUptime($all_errors);
$bootTime = getBootupTime($all_errors);

$cpumodel = getCpuModel($all_errors);
$cpufrequency = getCpuFrequency($all_errors);
$cpucache = getCpuCacheSize($all_errors);
$cputemp = getCpuTemperature($all_errors);

$cpudata = getCpuLoadData($all_errors);

$ramdata = getRamInfo($all_errors);


$swap = getSwapData($all_errors);
$network = getNetworkData($all_errors);
$disk = getDiskData($all_errors);

//===================================================

// Limit shown errors to max 8

$error_count = count($all_errors);
if ($error_count > 8) {
$all_errors = array_slice($all_errors, 0, 7);
$all_errors[] = "There were " . ($error_count - 7) . " more errors that are currently not shown";
}

$wtitle = $config["window_title"];
$wtitle = str_replace("{hostname}", $hostname, $wtitle);
$wtitle = str_replace("{ip}", $ip, $wtitle);
$wtitle = str_replace("{os}", $os, $wtitle);
$wtitle = str_replace("{kernel}", $kernel, $wtitle);
Loading

0 comments on commit 70b7053

Please sign in to comment.