1<?php
2/**
3 * ThunderSnarf
4 *
5 * @author Ricardo H.F. Sette P. <ricardohfsp@gmail.com>
6 * @link http://www.freebsdbrasil.com.br/
7 * @copyright Copyright &copy; 2010 - FreeBSD Brasil LTDA
8 * @license licença GNU/GPL v2.0 http://www.gnu.org/licenses/gpl-2.0.html
9 */
10
11$array_discos = array();
12$xml_thunder = Yii::app()->user->getState('xml_thunder',array("vazio"));
13if((int)$xml_thunder["THUNDER_CACHEDIRS"]["@attributes"]["quantidade"]>0){
14	if((int)$xml_thunder["THUNDER_CACHEDIRS"]["@attributes"]["quantidade"]==1){
15		$array_disco = array();
16		exec('df '.$xml_thunder["THUNDER_CACHEDIRS"]["CACHEDIR"]["DIR"], $array_disco);
17		if(isset($array_disco[1])){
18			$array_discos[] = $array_disco[1];
19		}
20	}else{
21		foreach($xml_thunder["THUNDER_CACHEDIRS"]["CACHEDIR"] as $key=>$value){
22			$array_disco = array();
23			exec('df '.$value["DIR"], $array_disco);
24			if(isset($array_disco[1])){
25				$array_discos[] = $array_disco[1];
26			}
27		}
28	}
29}else{
30	echo "Não foi possível mapear unidade de disco, reveja a configuração do Painel de controle no Site do ThunderCache";
31}
32if(count($array_discos)==0){
33	echo "Não foi possível mapear unidade de disco do Thunder, reveja a configuração do Painel de controle no Site do ThunderCache";
34	$array_discos = array('xxx xxx xxx xxx xxx /usr');
35}
36foreach($array_discos as $key=>$value){
37	$value = preg_replace('/\s\s+/', ' ', $value);
38	$array_cache_dir = explode(" ", $value);
39	//if($cache_dir == $array_cache_dir[5] OR substr($array_cache_dir[5]."/",0,strlen($cache_dir."/")) == $cache_dir."/"){
40		?>
41 	<table>
42		<tr>
43			<td style="text-align:center;">
44		<?php
45		$totalDiskSpace = round(disk_total_space($array_cache_dir[5]),2);
46		$totalDiskFree = round(disk_free_space($array_cache_dir[5]),2);
47		if($totalDiskFree<0) $totalDiskFree=0;
48                $retornoTipoFileSystem = "";
49                exec('mount | grep "'.$array_cache_dir[5].' ("', $retornoTipoFileSystem);
50                $tipoFileSystem = explode(" ", $retornoTipoFileSystem[0]);
51                if(isset($tipoFileSystem[3]))
52                    $tipoFileSystem = substr($tipoFileSystem[3],1,-1);
53                else
54                    $tipoFileSystem = "ufs";
55		if($tipoFileSystem=="ufs")
56                    $totalDiskUsed = ($totalDiskSpace)*0.92-$totalDiskFree;
57                else
58                    $totalDiskUsed = $totalDiskSpace-$totalDiskFree;
59$format_func = <<<EOD
60js:function(label, series){
61    return '<div style="font-size:12px;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';}
62EOD;
63
64$format_label = <<<EOD
65js:function(label, series){
66    return '<div style="background-color:#000;opacity:0.5;font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';}
67EOD;
68		$this->widget('application.extensions.EFlot.EFlotGraphWidget',
69		    array(
70		    	'idAjax'=>"DiscoCache",
71		        'data'=>array(
72		            array('label'=>'Usado', 'data'=>$totalDiskUsed, ),
73		            array('label'=>'Livre', 'data'=>$totalDiskFree, 'color'=>'#AFD8F8'),
74		        ),
75		        'options'=>array(
76		            'series'=> array('pie'=>array(
77		                'show'=>true,
78		                'radius'=> 3/4,
79		                'tilt'=> 0.7,
80		                'stroke'=>array('width'=>'5'),
81		                'formatter'=> $format_func,
82			            'label'=>array(
83			                'show'=>true,
84			                'radius'=> 3/4,
85			                'formatter'=>$format_label,
86			            	),
87		                ),
88		            ),
89		            'combine'=>array('color'=>'#999', 'threshold'=>0.9),
90		            'legend'=> array('show'=>false),
91		        ),
92		        'htmlOptions'=>array('style'=>'width:250px;height:250px;')
93		    )
94		);
95
96                echo $array_cache_dir[5];
97                echo '<br><span style="font-size: 8pt">FileSystem '.strtoupper($tipoFileSystem).'</span>';
98		?>
99			</td>
100			<td style='width:70%;vertical-align:top'>
101				<table style="border:1px solid #c1c1c1">
102					<tr>
103						<td style='border:1px solid #c1c1c1;text-align:center;background-color:#f1f1f1' >TAMANHO DISCO</td>
104						<td style='border:1px solid #c1c1c1;text-align:center;background-color:#f1f1f1' >USADO</td>
105						<td style='border:1px solid #c1c1c1;text-align:center;background-color:#f1f1f1' >LIVRE</td>
106					</tr>
107						<td style="border:1px solid #c1c1c1;text-align:center;" ><?php echo $this->sizeFormat($totalDiskSpace);?></td>
108						<td style="border:1px solid #c1c1c1;text-align:center;" ><?php echo $this->sizeFormat($totalDiskUsed);?></td>
109						<td style="border:1px solid #c1c1c1;text-align:center;" ><?php echo $this->sizeFormat($totalDiskFree);?></td>
110					</tr>
111				</table>
112				<br><br>
113				<span style="padding: 2px; background-color: rgb(0, 0, 0); opacity: 0.5; font-size: 8pt; text-align: center; color: white;">&nbsp;&nbsp;<?php echo $array_cache_dir[5];?>&nbsp;&nbsp;</span>
114			</td>
115		</tr>
116	</table>
117		<?php
118	//}
119}