/* Enjoy!!! Dino Ciuffetti - dam2k@users.sourceforge.net
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program (COPYING); if not, go to http://www.fsf.org/ or write
* to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/* GENERAL PORPOSE */
/**
* General purpose class.
* Very poor class, it contains general purpose methods.
* Class instance: $cms->general
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
class cmsdam_general
{
// Normally false, true if the cmsdam output buffering has been cleaned with cmsdam_ob_clean()
var $cmsdam_ob_cleaned;
// Absolute url path
var $url_path;
// Are we using smartlink? It's a way to create dynamic links appearing like static links.
// They are useful for example with search engines like google
var $smartlink;
function cmsdam_general() { // Constructor
$this->cmsdam_ob_cleaned = false;
$this->smartlink = false;
return true;
}
/**
* This is the machine uptime string.
* Useful if you want the "uptime" string into your section, seldom needed.
* NOTE: It only runs on UNIX systems, with uptime command on the php path!
* @return str The system uptime string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function general_uptime () {
// This method returns the system uptime string. We use shell escaping for this!
$uptime = `uptime`;
return $uptime;
}
/**
* This is the machine uptime string without Load Average.
* Useful if you want the "uptime" string without the Load Average into your section, seldom needed.
* NOTE: It only runs on UNIX systems, with uptime command on the php path!
* @return str The system uptime string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function uptime () {
// This method returns the system uptime string without the Load Average. We use shell escaping for this!
$uptime = `uptime | awk -F',' '{print $1 "," $2}'`;
return $uptime;
}
/**
* This is the machine memory usage.
* Useful if you want the system memory usage, seldom needed.
* NOTE: It only runs on UNIX systems, with free command on the php path!
* @return str The system memory usage
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function memfree ($usage="") {
if (($usage == "") || ($usage < 0) || ($usage > 3)) {
$usage = 1;
}
// Incolonnate the free command --> "-/+ buffers/cache: 823 1150"
if ($usage < 3) {
$usage += 2;
$free = `free -m | tail -n 3 | grep '/+ ' | awk '{print \$$usage}'`;
return $free;
}
if ($usage == 3) {
$free = `free -m | tail -n 3 | awk '{print $2}' | head -1`;
}
return $free;
}
/**
* This is the linux load average string.
* Useful if you want the load average of your linux system, seldom needed.
* NOTE: It only runs on LINUX systems because of the linux /proc/loadavg facility!
* @return str The system load average string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function loadavg () {
$uptime = `cat /proc/loadavg | awk '{print $1 ", " $2 ", " $3}'`;
return $uptime;
}
/**
* This is the linux disk usage in megabytes.
* Useful if you want the disk usage of your linux filesystem, seldom needed.
* NOTE: It only runs on LINUX systems because of the linux "du -sh" facility!
* @return str The system load average string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function diskusage ($mntpoint="") {
if ($mntpoint == "") {
$mntpoint = ".";
}
$du = `du -sm $mntpoint`;
return $du;
}
/**
* This is the linux disk free in megabytes.
* $usage == 1 --> Total MB, $usage == 2 --> Used MB, $usage == 3 --> Free MB, $usage == 4 --> Perc used,
* $usage == 5 --> FS Mount Point. WARNING: Only tested on Debian SID!!
* Useful if you want the disk free space of your linux filesystem in megabytes, seldom needed.
* NOTE: It only runs on LINUX systems because of the linux "df -h" facility!
* @return str The system load average string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function diskfree ($usage="", $mntpoint="") {
if (($usage == "") || ($usage < 1) || ($usage > 5)) {
$usage = 3;
}
if ($mntpoint == "") {
$mntpoint = ".";
}
/*
$usage == 1 --> Total MB
$usage == 2 --> Used MB
$usage == 3 --> Free MB
$usage == 4 --> Perc used
$usage == 5 --> FS Mount Point
*/
$usage2 = $usage + 1;
$df = `h=0; for i in $(df -m $mntpoint | sed 's/ /£/g'); do i=$(echo \$i | sed 's/£/ /g'); if [ "x$(echo \$i | awk '{print $2}')" != "x" ] && [ \$h -ne 0 ]; then if [ "x$(echo \$i | awk '{print $6}')" = "x" ]; then echo \$i | awk '{print \$$usage }'; else echo \$i | awk '{print \$$usage2 }'; fi; else h=1; fi; done`;
return $df;
}
/**
* Get the number of processes in the system.
* It's seldom needed.
* NOTE: It only runs on UNIX systems, with ps command on the php path!
* @return str The system uptime string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function nproc () {
$nproc = `ps fxa | wc -l`;
$nproc --;
return $nproc;
}
/**
* Get the number of processes in RUNNING STATE in the system.
* It's seldom needed.
* NOTE: It only runs on UNIX systems, with ps command on the php path!
* @return str The system uptime string
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function nprocrun () {
$nproc = `ps fxa | awk '{print $3}' | grep R | wc -l`;
$nproc --;
return $nproc;
}
/**
* Clean the cmsdam output buffer. Use this, instead of cleaning the output buffer yourself from
* your section! NOTE: Calling this method prevents cmsdam from ending the html page itself!
* Remember to use exit() as your last line in your section if you use this method to avoid
* html code injected from index section.
* @return bool true
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function cmsdam_ob_clean () {
// We must turn off output buffering due to a bug in ob_clean that parse out spurius characters!
ob_end_clean();
$this->cmsdam_ob_cleaned = true;
return true;
}
/**
* Write to the browser the cmsdam HTML header. It get picked from /index_header.php.
* This method must be called from your section before any character is sent to the browser!!
* @return bool true
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function flush_html_header_block($page_title="") {
if ($page_title == "") {
$page_title = $this->conf->site_title;
}
$this->logs->log_note(6, "NOTE: Sending HTML header to the browser");
require ("index_header.php");
return true;
}
}
?>