
<!DOCTYPE html>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=0.6, maximum-scale=0.6"/>
<html>
<head>
<meta charset="UTF-8">
<script type='text/javascript' charset='utf-8'>
    // Hides mobile browser's address bar when page is done loading.
      window.addEventListener('load', function(e) {
        setTimeout(function() { window.scrollTo(0, 1); }, 1);
      }, false);
</script>
<title>ArOZ Onlineβ</title>
<link rel="stylesheet" href="../../../script/tocas/tocas.css">
<script src="../../../script/tocas/tocas.js"></script>
<script src="../../../script/jquery.min.js"></script>
</head>
<body style="background-color: rgb(247, 247, 247);">
<div class="ts container">
<br>
<div class="ts segment">
	<div class="ts header">
    Harddisk S.M.A.R.T
    <div class="sub header">
			<div class="ts divider"></div>
			<button class="ts left icon label" onclick="showSMARTDetails()">
				<i class="notice icon"></i> View SMART
			</button>
	</div>
	</div>
</div>
<div class="ts divider"></div>
<div class="ts segment">
	<div class="ts divided items" id="diskFrame">

	</div>
</div>
<br><br><br>
</div>



<div class="ts modals dimmer">
    <dialog id="smartModals" class="ts closable modal">
	    <div class="header">
			S.M.A.R.T Information
		</div>
        <div class="content">
        <table class="ts very basic table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Attribute</th>
                    <th>Value</th>
                    <th>Worst</th>
                    <th>Threshold</th>
                    <th>State</th>
                </tr>
            </thead>
            <tbody id="SMARTtableBody">
            </tbody>
        </table>

        </div>
        <div class="actions">
            <button class="ts deny button">
                Close
            </button>
        </div>
    </dialog>
</div>

<Script>
var template = '<div class="item" device="%mount%" onclick="select(this)"><i class="large disk outline icon"></i><div class="content"><div class="header">%model% / %capacity% / %temp%℃</div><div class="extra">Model Family: %model_family%<br>Mount point: %mount%<br>Firmware version: %firmware_version%<br>Serial: %serial_number%<br>Power on: %hour% Hours<br>Speed: %speed%<br>Rotation speed: %rotation_rate% rpm<br>Protocol: %protocol%</div></div></div>';

$.get( "opr.php?opr=scan", function( raw ) {
	var Maindata = JSON.parse(raw);
	$.each( Maindata["devices"], function( key, value ) {
		$.get( "opr.php?opr=info&drive=" + value["name"], function( raw ) {
			var DiskData = JSON.parse(raw);
			var tmp = template;
			
			tmp = tmp.replace("%mount%",DiskData["device"]["info_name"]);
			
			tmp = tmp.replace("%model%",DiskData["model_name"]);
			tmp = tmp.replace("%capacity%",disksize(DiskData["user_capacity"]["bytes"]));
			tmp = tmp.replace("%temp%",DiskData["temperature"]["current"]);
			tmp = tmp.replace("%model_family%",DiskData["model_family"]);
			tmp = tmp.replace("%mount%",DiskData["device"]["info_name"]);
			tmp = tmp.replace("%firmware_version%",DiskData["firmware_version"]);
			tmp = tmp.replace("%serial_number%",DiskData["serial_number"]);
			tmp = tmp.replace("%hour%",DiskData["power_on_time"]["hours"]);
			tmp = tmp.replace("%speed%",DiskData["sata_version"]["string"] + " " + DiskData["interface_speed"]["current"]["string"]);
			tmp = tmp.replace("%rotation_rate%",DiskData["rotation_rate"]);
			tmp = tmp.replace("%protocol%",DiskData["device"]["protocol"]);
			$("#diskFrame").append(tmp);
		});
	  
	});
});

function select(div){
	$("div.item").find( "i" ).css( "background-color", "#f7f7f7" );
	$("div.item").find( "i" ).css( "color", "#919191" );
	$("div.item").find( "i" ).attr( "class", "large disk outline icon" );
	
	$(div).find( "i" ).css( "background-color", "#49af79" );
	$(div).find( "i" ).css( "color", "#ffffff" );
	$(div).find( "i" ).attr( "class", "large checkmark icon" );
}
function showSMARTDetails(){
	var mountpoint = $("div.item:has(i[class='large checkmark icon'])").attr("device");
	$.get( "opr.php?opr=info&drive=" + mountpoint, function( raw ) {
		var DiskData = JSON.parse(raw);
		$("#SMARTtableBody").html("");
		$.each( DiskData["ata_smart_attributes"]["table"], function( key, value ) {
			var tmp = tmp + "<tr>";
				tmp = tmp + "<td>" + value["id"] + "</td>";
				tmp = tmp + "<td>" + value["name"] + "</td>";
				tmp = tmp + "<td>" + value["value"] + "</td>";
				tmp = tmp + "<td>" + value["worst"] + "</td>";
				tmp = tmp + "<td>" + value["thresh"] + "</td>";
				if(value["when_failed"] == ""){
					tmp = tmp + "<td>OK</td>";
				}else{
					tmp = tmp + "<td>Failed</td>";
				}
				$("#SMARTtableBody").append(tmp);
		});
		ts('#smartModals').modal("show");
	});
}

function disksize(size){
	if(size >= 1000000000000){
		return Math.floor(size/1000000000000) + " TB";
	}else if(size >= 1000000000){
		return Math.floor(size/1000000000) + " GB";
	}else if(size >= 1000000){
		return Math.floor(size/1000000) + " MB";
	}else if(size >= 1024){
		return Math.floor(size/1000) + " KB";
	}else{
		return size + " Bytes";
	}
}

console.warn("%cSTOP!\n%cPlease beware not to copy and paste anything from the internet to this console as this might bring damage to your system.",'color: red;font-size: 76px','color: red');

console.info(`%c         !          ____ _____ ___  ____  
       !   !       / ___|_   _/ _ \\|  _ \\ 
      !  !  !      \\___ \\ | || | | | |_) | 
     !   !   !      ___) || || |_| |  __/ 
    !    !    !    |____/ |_| \\___/|_|    
   !     !     !     
  !             !      
 !       !       !  
!!!!!!!!!!!!!!!!!!! `,'color: red;');
</script>
</body>
</html>