#!/usr/bin/perl

# Credits     : This script was created by and is currently maintained
#               by Victor Igumnov [lamer0@lamer0.com].
#
# Legal Info  : Copyright (C) 2003, Victor Igumnov [lamer0@lamer0.com]
#
#               This program is free software. You may redistribute it
#               and/or modify it under the terms of the GNU General
#               Public License as published by the Free Software 
#               Foundation; either version 2 of the License, or
#               (at your option) any later version.
#
#               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.
#
$|=1;

use CGI;
use URI::URL;
use LWP::UserAgent;

#Set These
my $CPU='temp3';
my $MOBO='temp2';
my $FAN='fan2';

$MYUPTIME = `/usr/bin/uptime`;

$CPUNAME=`cat /proc/cpuinfo | grep '^model name' | head -1 | sed -e 's/^.*: //'`;
($CPUNAME)=$CPUNAME=~/^\s*(.*?)\s*$/;  # trim head/tail at same time



$CPUSPEED=`cat /proc/cpuinfo | grep 'cpu MHz' | head -1 | sed -e 's/^.*: //'`;
$BOGOMIPS=`cat /proc/cpuinfo  | grep 'bogomips' |  head -1 | sed -e 's/^.*: //'`;
$UNAME = `uname -sr`;

#--PERCENTAGE OF MEMORY FREE--#
$MEMPERCENT = `free | grep Mem | awk '{print (( \$3 -(\$6 + \$7) )/\$2)*100}'`;
chop ($MEMPERCENT);
$MEMPERCENT = sprintf('%.2f', $MEMPERCENT);


#--MEMORY FREE--#
$MEMFREE = `free | grep Mem | awk '{printf (\"%.0fg\", ( \$3 -(\$6 + \$7) )/1000)}'`;
chop ($MEMFREE);

#--TOTAL MEMORY--#
$MEMTOTAL = `free | grep Mem | awk '{printf (\"%dMb\", \$2/1000 )}'`;
chop ($MEMTOTAL);

#--SCREEN RESOLUTION--#
$RES = `xdpyinfo | grep dimensions | awk '{print \$2}'`;
chop ($RES);

#--DISKSPACE--#
$HDD = `df | awk '{ sum+=\$2/1024^2 }; END { printf (\"%dGb\", sum )}'`;
chop ($HDD);

#--DISKSPACE FREE--#
$HDDFREE = `df | awk '{ sum+=\$4/1024^2 }; END { printf (\"%dGb\", sum )}'`;
chop ($HDDFREE);

#--SCREEN RESOLUTION--#
$RES = `xdpyinfo | grep dimensions | awk '{print \$2}'`;
chop ($RES);

chop($UNAME);
chop($CPUNAME);
chop($CPUSPEED);
chop($BOGOMIPS);
$RAMLEFT=$MEMTOTAL-$MEMFREE;

$query = new CGI;
$query->import_names('webform');

my $username = "a";
my $password = "a";
$DATA_2_SEND="Uptime: $MYUPTIME *<*";
$DATA_2_SEND .= "CPU: $CPUNAME *<*";
$DATA_2_SEND .= "MHZ: $CPUSPEED *<*";
# $DATA_2_SEND .= "BOGOMIPS: $BOGOMIPS *<*";
$DATA_2_SEND .= "OS: $UNAME *<*$MEMPERCENT% Ram Used | Total RAM = $MEMTOTAL | $
$DATA_2_SEND .= "Diskspace: $HDD Free: $HDDFREE *<*";
# $DATA_2_SEND .= "Screen Res: $RES";
#print $DATA_2_SEND;





my %form = ();

%form =('username' => $username,
	'password' => $password,
	'data'	   => $DATA_2_SEND,
	'Submit'   => '');

my $ua = new LWP::UserAgent;
my $curl = url("http:");  
my $req = new HTTP::Request 'POST','http://sigx.yuriy.net/update.php';
$req->content_type('application/x-www-form-urlencoded');
$req->content($curl->equery);
$curl->query_form(%form);
$req->content($curl->equery);
my $response= $ua->request($req)->as_string;

