hwmon.php 1019 Bytes
Newer Older
1 2 3 4 5 6 7 8
<?php

if (isset($_GET['cmd']))
	$cmd = $_GET['cmd'];
else
	$cmd = "t";

if ($cmd=="t"){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
9 10
	$t_cpu = file_get_contents("/tmp/core_temp");
	$t_10389 = "";
11 12
	$t_sda = "";
	$t_sdb = "";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
13 14 15 16 17 18 19 20
	
	$temp1_input = "/sys/devices/soc0/amba@0/e0004000.ps7-i2c/i2c-0/0-001a/hwmon/hwmon0/temp1_input";
	
	if (is_file($temp1_input)){
		$t_10389 = trim(file_get_contents($temp1_input));
		$t_10389 = intval($t_10389)/1000;
	}
	
21
	$t_sda = exec("smartctl -A /dev/sda | egrep ^194 | awk '{print $10}'");
22 23 24
	if ($t_sda=="") $t_sda = "-";
	else            $t_sda = intval($t_sda);
	
25
	$t_sdb = exec("smartctl -A /dev/sdb | egrep ^194 | awk '{print $10}'");
26 27 28 29
	if ($t_sdb=="") $t_sdb = "-";
	else            $t_sdb = intval($t_sdb);
	
	echo "$t_cpu $t_10389 $t_sda $t_sdb";
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
}

if ($cmd=="read"){
	echo file_get_contents("/tmp/core_temp_params");
}

if ($cmd=="write"){
	$cstr = "";
	foreach($_GET as $key => $val){
		if(strpos($key,"temp")===0){
			$cstr .= "$key:$val\n";
		}
	}
	file_put_contents("/tmp/core_temp_params",$cstr);
	echo "$cstr";
}

?>