<%+header%>
<script>
var SRVURL = "";
function runscript(url) {
	var script = document.createElement('script');  
	script.setAttribute('src', url);
	document.getElementsByTagName('head')[0].appendChild(script);  
}
function getUrlPara(name) {
   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
   var r = window.location.search.substr(1).match(reg);
   if (r != null) {
   	return decodeURIComponent(r[2]); 
   }
   return null;
}

function doAcitvate() {
	runscript('/cgi-bin/luci/admin/oplus/oplus_activate/?_r='+ Math.random());
}
function doActiveM() {
	var actcode = document.getElementById('txtActCode').value;
	runscript('/cgi-bin/luci/admin/oplus/oplus_activate_m/?actcode='+ encodeURIComponent(actcode) +'&_r='+ Math.random());
}
function loadData() {
	runscript('/cgi-bin/luci/admin/oplus/oplus_loaddata/?_r='+ Math.random());
}
function showData(devcode, verify, lic_date, srvurl, target, ver) {
	document.getElementById('devcode').value = devcode;
	document.getElementById('spDevcode').innerHTML = devcode;

	if(verify == 'license_ok') {
		document.getElementById('spVerify').innerHTML = "<font color='#008800'><b><%:Validated %></b></font>";
	} else {
		document.getElementById('spActivate').style.display = '';

		if(verify == 'license_expired') {
			document.getElementById('spVerify').innerHTML = "<font color='#ff0000'><%:Expired %></font>";
		}
		if(verify == 'license_error') {
			document.getElementById('spVerify').innerHTML = "<font color='#ff0000'><%:Invalid %></font>";
		}
	}

	if(lic_date == '*') {
		document.getElementById('spLicDate').innerHTML = "<font color='#008800'><b><%:Unlimited %></font>";
	} else {
		document.getElementById('spLicDate').innerHTML = lic_date;
	}
	
	SRVURL = srvurl;

	document.getElementById('ver').value = ver;
	document.getElementById('spVer').innerHTML = ver;

	document.getElementById('target').value = target;
	document.getElementById('spTarget').innerHTML = target;

	var error = getUrlPara('error');
	if(error != null) {
		document.getElementById('dvMsg').innerHTML = "<%:There is not a valid license on this device. Please activate your license. %>";
	}
}

function onActivateM(result) {
	//license_expired, license_ok, license_error
	if(result == 'license_ok') {
		// loadData();
		alert("<%:Activation Successful %>");
		location.reload();
	} else if(result == 'license_expired') {
		alert("<%:Your license has expired. Please renew your license. %>");
	} else if(result == 'license_error') {
		alert("<%:Invalid Activation Code. Please check your activation code. %>");
	} else {
		alert("<%:Unknown Error %>");
	}
}
function onActivate(result) {
	if(result == 'ok') {
		// loadData();
		location.reload();
	} else if(result == 'error') {
		document.getElementById('dvMsg').innerHTML = "<%:Activation Failed, please check your network %><br>"+
			"<%:If you have an Activation Code, please activate your license manually. %><br>"+
			"<input type='text' id='txtActCode' style='width:500px' placeholder='<%:Enter Activation Code %>' /><br>"+
			"<input type='button' value='<%:Activate Maually%>' onclick='doActiveM();' style='background-color: #0055ff; color: #fff; width:100px; height: 40px;' /><br><br>";
	} else if(result == 'no_license') {
		document.getElementById('dvMsg').innerHTML = "<%:No license. Please place an order for a license. %>";
	}
}

function doBuy() {
	window.open( SRVURL +"/ppwf/oplusbuy/?devcode="+ document.getElementById('devcode').value +
		"&target="+ encodeURIComponent(document.getElementById('target').value) +
		"&ver="+ encodeURIComponent(document.getElementById('ver').value)
	) ;
}
</script>

<br><br>

<b><%:OPlus License Management %></b>
<br>
<%:OPlus is a bundle of useful tools for optimizing openwrt. %><br>

<%= translate("Before use it, you need to understand and agree with our <a href='http://www.wiwiz.com/pinpinwifi/oplus/eua.htm' target='_blank'>End User Agreement</a>.") %>
<br><br>
<center>
<div id="dvMsg" style="color:#ff0000"></div><br>

<input type="hidden" id="devcode" value="" />
<input type="hidden" id="target" value="" />
<input type="hidden" id="ver" value="" />

<table>
	<tr style="height:50px">
		<td> <%:Device Code %> : </td>
		<td> <span id="spDevcode"></span> </td>
	</tr>
	<tr style="height:50px">
		<td> <%:License Date %> : </td>
		<td> <span id="spLicDate"></span> </td>
	</tr>
	<tr style="height:50px">
		<td> <%:License Status %> : </td>
		<td> 
			<span id="spVerify"></span> 
			<span id="spActivate" style="display:none"> 
				<input type="button" value="<%:Activate %>" onclick="doAcitvate();" style="background-color: #0055ff; font-weight: bold; color: #fff; width:100px; height: 40px;" />
				<input type="button" value="<%:Buy a license %>" onclick="doBuy();" style=" color: #0033aa; font-weight: bold; width:100px; height: 40px; width:150px" />
			</span> 
		</td>
	</tr>
	<tr style="height:50px">
		<td> <%:Version %> : </td>
		<td> <span id="spVer"></span> </td>
	</tr>
	<tr style="height:50px">
		<td> <%:Target Platform %> : </td>
		<td> <span id="spTarget"></span> </td>
	</tr>

</table>

<br><br>
<a href="http://www.wiwiz.com/pinpinwifi/oplus/help.htm" target="_blank"><%:Docs %></a>
<br><br>
Copyright &copy; 2025-<script>document.write(new Date().getFullYear());</script> <a href="http://www.wiwiz.com/pinpinwifi" target='_blank'>www.PinPinWiFi.com</a>. All rights reserved.
<br>
<%: We reserve the right to pursue legal responsibility for any unauthorized copying, distribution, cracking, reverse engineering, unauthorized use, etc. %>
<br>
</center>

<script>
	loadData();


</script>

<%+footer%>