
<!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">
		Cluster Storage Manager
    <div class="sub header">
		 Harddisk SMART
	</div>
	</div>
</div>
<div class="ts divider"></div>
<div class="ts segment">
	<div class="ts items">
		<div class="item">
			<i id="MessageIcon" class="large inverted info rounded checkmark icon"></i>
			<div class="content">
				<div class="header" id="MessageHeader">Operating normal.</div>
				<div class="extra" id="MessageContent">
					System working.
				</div>
			</div>
		</div>
	</div>
		
	<div class="ts fluid statistics">
		<div class="statistic">
			<div class="value" id="Cluster">0</div>
			<div class="label">Cluster online</div>
		</div>
		<div class="statistic">
			<div class="value" id="Installed">0</div>
			<div class="label">Disk installed</div>
		</div>
		<div class="statistic">
			<div class="value" id="Healthy">0</div>
			<div class="label">Disk healthy</div>
		</div>
		<div class="statistic">
			<div class="value" id="capacity">0 Byte</div>
			<div class="label">Total</div>
		</div>
	</div>

	<div class="ts divider"></div>

	<table class="ts very basic table">
		<thead>
			<tr>
				<th>IPs</th>
				<th>Model</th>
				<th>Mounted</th>
				<th>Capactiy</th>
				<th>SMART</th>
			</tr>
		</thead>
		<tbody id="SMARTtableBody">
		</tbody>
	</table>
</div>
<br>
</div>



<Script>
var capacity = 0;
var healthy = 0;
var totalDisk = 0;
var cluster = 0;

var template = "<tr><td>%ip%</td><td>%model%</td><td>%mount%</td><td>%capacity%</td><td>%smart%</td></tr>";
$.get( "../cluster/clusterList.config", function( raw ) {
	cluster = raw.split("\n").length - 1;
	$.each( raw.split("\n"), function( key, IP ) {
		$.get( "http://" + IP + "/AOB/SystemAOB/functions/drive/opr.php?opr=scan", function( raw ) {
			var Maindata = JSON.parse(raw);
			$.each( Maindata["devices"], function( key, value ) {
				$.get( "http://" + IP + "/AOB/SystemAOB/functions/drive/opr.php?opr=info&drive=" + value["name"], function( raw ) {
					var DiskData = JSON.parse(raw);
					var tmp = template;
					var smart = "OK";
					
					if(typeof DiskData["ata_smart_attributes"] === 'undefined'){
						smart = "Unknown";
						healthy = healthy - 1;
					}else{
						$.each( DiskData["ata_smart_attributes"]["table"], function( key, value ) {
							if(value["when_failed"] !== ""){
								smart = "Failed";
								healthy = healthy - 1;
								$("#MessageIcon").attr("class","large inverted negative rounded remove icon");
								$("#MessageHeader").text("Warning");
								$("#MessageContent").text("One or more disk on cluster have SMART warning.");
							}
						});
					}
		
					
					tmp = tmp.replace("%ip%",IP);													
					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("%smart%",smart);
					
					capacity = capacity + DiskData["user_capacity"]["bytes"];
					totalDisk = totalDisk + 1;
					healthy = healthy + 1;
					$("#Cluster").text(cluster);
					$("#Installed").text(totalDisk);
					$("#Healthy").text(healthy);
					$("#capacity").text(disksize(capacity));
					
					$("#SMARTtableBody").append(tmp);
				});
			  
			});
		});
	});
});

function disksize(size){
	if(size >= 1000000000000000){
		return Math.floor(size/1000000000000000*10)/10 + " PB";
	}else if(size >= 1000000000000){
		return Math.floor(size/1000000000000*10)/10 + " TB";
	}else if(size >= 1000000000){
		return Math.floor(size/1000000000*10)/10 + " GB";
	}else if(size >= 1000000){
		return Math.floor(size/1000000*10)/10 + " MB";
	}else if(size >= 1024){
		return Math.floor(size/1000*10)/10 + " 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>