File: active_prods_graph.php

package info (click to toggle)
dtc 0.35.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 18,824 kB
  • sloc: php: 50,739; sh: 8,596; makefile: 572; perl: 148; xml: 25
file content (98 lines) | stat: -rw-r--r-- 3,130 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php

$panel_type="admin";
require_once("../shared/autoSQLconfig.php");
require_once("authme.php");
require_once("../shared/vars/lang.php");

$rrd = $conf_generated_file_path.'/stat_total_active_prods.rrd';
$xpoints = 400;
$ypoints = 160;
$vert_label = _("Active Products");

if( isset($_REQUEST["graph"]) ){

	switch($_REQUEST["graph"]){
		case "hour":
			$title = _('Hour graph');
			$steps = 3600;
			break;
		case "day":
			$title = _('Day Graph');
			$steps = 3600*24;
			break;
		case "week":
			$title = _('Week Graph');
			$steps = 3600*24*7;
			break;
		case "month":
			$title = _('Month Graph');
			$steps = 3600*24*31;
			break;
		case "year":
			$title = _('Year Graph');
			$steps = 3600*24*365;
			break;
		default:
			die("Nothing to do here...");
			break;
	}
	$range = - $steps;
	$filename = tempnam("/tmp","dtc_netgraph");
	$cmd = "rrdtool graph $filename --imgformat PNG --width $xpoints --height $ypoints --start $range --end now --vertical-label \"$vert_label\" --title \"$title\" --lazy --interlaced ";
	$cmd .= "DEF:vps=$rrd:vps:AVERAGE DEF:dedicated=$rrd:dedicated:AVERAGE DEF:shared=$rrd:shared:AVERAGE ";
	$cmd .= "\"AREA:shared#0000ff:" . _("Active Shared Accounts") . ":\" \"GPRINT:shared:MAX:" . _("Maximum") . "\: %0.0lf\" \"GPRINT:shared:AVERAGE:" . _("Average") . "\: %0.0lf/min\l\" ";
	$cmd .= "\"STACK:vps#00ff00:" . _("Active VPS") . ":\" \"GPRINT:vps:MAX:" . _("Maximum") . "\: %0.0lf\" \"GPRINT:vps:AVERAGE:" . _("Average") . "\: %0.0lf/min\\n\" ";
	$cmd .= "\"STACK:dedicated#ff0000:" . _("Active Dedicated Servers") . ":\" \"GPRINT:dedicated:MAX:" . _("Maximum") . "\: %0.0lf\" \"GPRINT:dedicated:AVERAGE:" . _("Average") . "\: %0.0lf/min\l\" ";
	exec($cmd,$output);

	$filesize = filesize($filename);

	if( ($fp = fopen($filename,"rb")) != NULL ){
		header("Content-Type: image/png");
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: $filesize");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: public", false);
		header("Expires: 0");
		while(!feof($fp) && connection_status() == 0){
			print(fread($fp,1024*8));
			flush();
		}
		fclose($fp);
	}
	unlink($filename);
}else{
	echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>' . _("Active Product Statistics for") . ' '.$_SERVER["SERVER_NAME"].'</TITLE>
<style type="text/css">
body{
	height:100%;
	margin:0;
	color: #000000;
}
h1 {
	font: 14px Arial, Helvetica, sans-serif;
	font-weight: bold;
	text-decoration: underline;
	color: #000000;
}
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1>' . _("Active Products Statistics for") . ' '.$_SERVER["SERVER_NAME"].'</H1>
<center>
<IMG BORDER="0" SRC="?graph=hour" ALT="' . _("Hour Sales Graph") . '"><br>
<IMG BORDER="0" SRC="?graph=day" ALT="' . _("Day Sales Graph") . '"><br>
<IMG BORDER="0" SRC="?graph=week" ALT="' . _("Week Sales Graph") . '"><br>
<IMG BORDER="0" SRC="?graph=month" ALT="' . _("Month Sales Graph") . '"><br>
<IMG BORDER="0" SRC="?graph=year" ALT="' . _("Year Sales Graph") . '">
</center>
</body>
</html>';
}

?>