
<fieldset class="cbi-section">

	<table>
	  <tr><td width="100%" colspan="4" align="center" id="update_tip"><b> 注意：如内核下载失败可前往 https://github.com/vernesong/OpenClash/releases/tag/Clash 手动下载并上传 </b></td></tr>
		<tr><td width="25%"> 处理器架构（PROC） </td><td width="25%" align="left" id="CPU_MODEL"><%:Collecting data...%></td><td width="25%"> 处理器架构（OPKG） </td><td width="25%" align="left" id="CPU_MODEL2"><%:Collecting data...%></td></tr>
		<tr><td width="25%"> 当前内核版本 </td><td width="25%" align="left" id="CORE_CV"><%:Collecting data...%></td><td width="25%"> 当前客户端版本 </td><td width="25%" align="left" id="OP_CV"><%:Collecting data...%></td></tr>
		<tr><td width="25%"> 最新内核版本 </td><td width="25%" align="left" id="CORE_LV"><%:Collecting data...%></td><td width="25%"> 最新客户端版本 </td><td width="25%" align="left" id="OP_LV"><%:Collecting data...%></td></tr>
	  <tr><td width="25%"> 更新内核</td><td width="25%" align="left" id="core_up"><%:Collecting data...%></td><td width="25%"> 更新客户端 </td><td width="25%" align="left" id="op_up"><%:Collecting data...%></td></tr>
	</table>

</fieldset>

<script type="text/javascript">//<![CDATA[
	var cpu_model = document.getElementById('CPU_MODEL');
	var cpu_model2 = document.getElementById('CPU_MODEL2');
	var core_cv = document.getElementById('CORE_CV');
	var core_lv = document.getElementById('CORE_LV');
	var op_cv = document.getElementById('OP_CV');
	var op_lv = document.getElementById('OP_LV');
	var core_up = document.getElementById('core_up');
	var op_up = document.getElementById('op_up');
	var update_tip = document.getElementById('update_tip');
	XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
		if ( x && x.status == 200 ) {
		  cpu_model.innerHTML = status.coremodel ? "<b><font color=green>+status.coremodel+</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
      cpu_model2.innerHTML = status.coremodel2 ? "<b><font color=green>"+status.coremodel2+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
      if ( status.corecv == "0" ) {
         core_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
      }
      else if (status.corecv != "") {
         core_cv.innerHTML = "<b><font color=green>"+status.corecv+"</font></b>";
      }
      else {
         core_cv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
      }
			if ( status.corelv != "" && status.corelv != status.corecv && status.corecv != "" ) {
			   core_lv.innerHTML = "<b><font color=green>"+status.corelv+"<%:<New>%></font></b>";
			}
			else if (status.corelv != "") {
			   core_lv.innerHTML = "<b><font color=green>"+status.corelv+"</font></b>";
			}
			else {
			   core_lv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
			}
			op_cv.innerHTML = status.opcv ? "<b><font color=green>"+status.opcv+"</font></b>" : "<b><font color=red><%:Unknown%></font></b>";
			if ( status.oplv != "" && status.oplv != status.opcv && status.opcv != "" ) {
			   op_lv.innerHTML = "<b><font color=green>"+status.oplv+"<%:<New>%></font></b>";
			}
			else if (status.oplv != "") {
			   op_lv.innerHTML = "<b><font color=green>"+status.oplv+"</font></b>";
			}
			else {
			   op_lv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
			}
		}
	});
	XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
		if ( x && x.status == 200 ) {
		  cpu_model.innerHTML = status.coremodel ? "<b><font color=green>+status.coremodel+</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
      cpu_model2.innerHTML = status.coremodel2 ? "<b><font color=green>"+status.coremodel2+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
      if ( status.corecv == "0" ) {
         core_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
      }
      else if (status.corecv != "") {
         core_cv.innerHTML = "<b><font color=green>"+status.corecv+"</font></b>";
      }
      else {
         core_cv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
      }
			if ( status.corelv != "" && status.corelv != status.corecv && status.corecv != "" ) {
			   core_lv.innerHTML = "<b><font color=green>"+status.corelv+"<%:<New>%></font></b>";
			}
			else if (status.corelv != "") {
			   core_lv.innerHTML = "<b><font color=green>"+status.corelv+"</font></b>";
			}
			else {
			   core_lv.innerHTML = "<b><font color=green><%:Unknown%></font></b>";
			}
			op_cv.innerHTML = status.opcv ? "<b><font color=green>"+status.opcv+"</font></b>" : "<b><font color=red><%:Unknown%></font></b>";
			if ( status.oplv != "" && status.oplv != status.opcv && status.opcv != "" ) {
			   op_lv.innerHTML = "<b><font color=green>"+status.oplv+"<%:<New>%></font></b>";
			}
			else if (status.oplv != "") {
			   op_lv.innerHTML = "<b><font color=green>"+status.oplv+"</font></b>";
			}
			else {
			   op_lv.innerHTML = "<b><font color=green><%:Unknown%></font></b>";
			}
		}
	});
	
	core_up.innerHTML = '<input type="button" class="cbi-button cbi-button-reload" value="<%:检查并更新%>" onclick="return core_update(this)"/>';
	op_up.innerHTML = '<input type="button" class="cbi-button cbi-button-reload" value="<%:检查并更新%>" onclick="return op_update(this)"/>';
	
	function core_update(btn)
    {
        XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "coreupdate")%>', status.coreup, function(x, status) {
        btn.disabled = false;
        btn.value    = '<%:检查并更新%>';
        return false;
        });
    }
	
	function op_update(btn)
    {
        XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "opupdate")%>', status.opup, function(x, status) {
        btn.disabled = false;
        btn.value    = '<%:检查并更新%>';
        return false;
        });
    }
    
    XHR.poll(7, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "startlog")%>', status.startlog, function(x, status) {
	  if ( x && x.status == 200 ) {
		   if ( status.startlog == "\n" || status.startlog == "" ) {
		      var rdmdl=Math.floor(Math.random()*2)+1;
		      if(rdmdl==1)
          {
             update_tip.innerHTML = '<b><font><%: 注意：如内核下载失败可前往 https://github.com/vernesong/OpenClash/releases/tag/Clash 手动下载并上传 %></font></b>';
          }
          if(rdmdl==2)
          {
             update_tip.innerHTML = '<b><font><%: 注意：客户端只支持通过IPK安装的版本进行更新，因为随系统编译的版本更新后不会释放旧版本的闪存空间 %></font></b>';
          }
       }
    }
	});
	XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "startlog")%>', status.startlog, function(x, status) {
	  if ( x && x.status == 200 ) {
		   if ( status.startlog != "\n" && status.startlog != "" ) {
	     update_tip.innerHTML = '<b><font color="green">'+status.startlog+'</font></b>';
	     }
	  }
	});

//]]></script>
      