<%
include("language.html")

function in_array(domain,domainArray)
	for _,tempdomain in pairs(domainArray) do
		if tempdomain == domain then
			return true
		end
	end
	return false
end

if _SESSION["logined"] ~= nil then

local all_langs = {"english","french","german","italian","dutch","portuguese","spanish","schinese","tchinese","japanese","czech","romanian","turkish","korean","polish"}
local my_lang = nil
if _COOKIE["admin_lang"] ~= nil then
	for _,val in pairs(all_langs) do
		if _COOKIE["admin_lang"] == val then
			my_lang = val
			break
		end
	end

	if my_lang == nil then
		my_lang = "english"
	end
else
	my_lang = "english"
end

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Wing FTP Server</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
a,a:visited {color:#000;text-decoration:none;}
img {border:0px;}
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
body,td,span {margin:0;padding:0;font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {margin:0;padding:0;font:11px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>
.treemenu dl {padding:0;margin:0 0 0 12px;clear:both;}
.treemenu a {background:none;}
.treemenu dd {padding:3px;margin:0px;list-style:none;clear:both;}
.treemenu dd button {width:18px;height:10px;overflow:hidden;cursor:pointer;vertical-align:middle;border:none;background:url('images/treeview/opened.gif') no-repeat 3px 1px;}
.treemenu dd.folderClose dl {display:none;}
.treemenu dd.folderClose button {background:url('images/treeview/closed.gif') no-repeat 5px 0px;;}
.treemenu dd {background:url('images/treeview/elbow-line.gif') repeat-y 0 0;}
.treemenu dd.lastChild {background:url('images/treeview/folder-last.gif') no-repeat 0 0;}
.treemenu dt {margin:0px;padding:0 0 0 18px;overflow:hidden;background:url('images/treeview/elbow.gif') no-repeat 0 0;line-height:18px;}
.treemenu dt.lastChild {background:url('images/treeview/elbow-end.gif') no-repeat 0 0;}
.treemenu dd a, .treemenu dd a:visited {color:#000;font-weight:bold;}
.treemenu dt a, .treemenu dt a:visited {color:#000;font-weight:normal;}

.menuitem {background-color: #F5F5F5; padding:4px; width:150px;}
.menuitem a:hover{background-color: #3366CC;color: #FFF;}
</style>
</head>
<body style="overflow-x:hidden;">
<script language="javascript" src="include/common.js"></script>
<script language="javascript" src="include/treeview.js"></script>

<div id="menu_div" style="position:absolute; visibility:hidden; border:1px solid #999; background-color:#FFF;" onclick="return false;">
    <div class="menuitem"><a href="#" onclick="top.CreateDomain();"><img src="images/ico_adddomain.gif"> <%=LANG["left_createdomain"]%> </a></div>
	<div class="menuitem"><a href="#" onclick="DeleteDomain();"><img src="images/ico_deletedomain.gif"> <%=LANG["left_deletedomain"]%> </a></div>
	<div class="menuitem"><a href="#" onclick="StartDomain();"><img src="images/ico_domainonline.gif"> <%=LANG["left_domainonline"]%> </a></div>
    <div class="menuitem"><a href="#" onclick="StopDomain();"><img src="images/ico_domainoffline.gif"> <%=LANG["left_domainoffline"]%> </a></div>
</div>

<div id="menu_div2" style="position:absolute; visibility:hidden; border:1px solid #999; background-color:#FFF;" onclick="return false;">
    <div class="menuitem"><a href="#" onclick="top.CreateDomain();"><img src="images/ico_adddomain.gif"> <%=LANG["left_createdomain"]%> </a></div>
	<div class="menuitem"><a href="#" onclick="top.StartServer();"><img src="images/ico_serveronline.gif"> <%=LANG["left_serveronline"]%> </a></div>
	<div class="menuitem"><a href="#" onclick="top.StopServer();"><img src="images/ico_serveroffline.gif"> <%=LANG["left_serveroffline"]%> </a></div>
</div>

<div class="treemenu" style="width:100%;height:100%;overflow-y:auto;" id="leftmenu">
<dl>
	<dd id="node1"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('node1',1,this);"><img src="images/ico_logo.gif"> <%=LANG["left_rootnode"]%></span>
	<dl>
		<% if _SESSION["admin_domainadmin"] == 0 then %>
		<dd class="folderClose" id="node2"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('node2',0,this);"><img src="images/ico_adminstrator.gif"> <%=LANG["left_admnistrator"]%></span>
			<dl>
				<dt><a href="#" onclick="return changeLocation('admin_lua_term.html',this);"><img src="images/ico_console.gif"> <%=LANG["left_console"]%></a></dt>
				<dt><a href="#" onclick="return changeLocation('admin_adminlist.html',this);"><img src="images/ico_adminuser.gif"> <%=LANG["left_adminuser"]%></a></dt>
				<dt><a href="#" onclick="return changeLocation('admin_view_admlog.html',this);"><img src="images/ico_systemlog.gif"> <%=LANG["left_adminlog"]%></a></dt>
				<dt><a href="#" onclick="return changeLocation('admin_admin_setting.html',this);"><img src="images/ico_setting.gif"> <%=LANG["left_setting"]%></a></dt>
			</dl>
		</dd>
		<dd class="folderClose" id="node3"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('node3',0,this);"><img src="images/ico_ftpserver.gif"> <%=LANG["left_ftpserver"]%></span>
			<dl>
				<dd class="folderClose" id="systemlog"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('systemlog',0,this);"><img src="images/ico_list.gif"> <%=LANG["left_logstatus"]%></span>
					<dl>
						<dt><a href="#" onclick="return changeLocation('admin_view_sysstatus.html',this);"><img src="images/ico_systemstatus.gif"> <%=LANG["left_systemstatus"]%></a></dt>
						<dt><a href="#" onclick="return changeLocation('admin_view_syslog.html',this);"><img src="images/ico_systemlog.gif"> <%=LANG["left_systemlog"]%></a></dt>
					</dl>
				</dd>
				<dt><a href="#" onclick="return changeLocation('admin_license.html',this);"><img src="images/ico_lisence.gif"> <%=LANG["left_license"]%></a></dt>
				<dt><a href="#" onclick="return changeLocation('admin_tasklist.html',this);"><img src="images/ico_systemtask.gif"> <%=LANG["left_systemtask"]%></a></dt>
				<dt><a href="#" onclick="return changeLocation('admin_system_setting.html',this);"><img src="images/ico_setting.gif"> <%=LANG["left_setting"]%></a></dt>
			</dl>
		</dd>
		<% end %>
		<dd id="node4"><span style="cursor:pointer;font-weight:bold;" onclick="clickDomainRoot(this,0);" oncontextmenu="clickDomainRoot(this,1);"><img src="images/ico_domains.gif"> <%=LANG["left_domains"]%></span>
			<dl>
				
			<%
				local domainNum = 0
				local domain = ""
				local domainArray = Split(_SESSION["admin_domainlist"],",")
				local bContinue = false
				for _,domain in pairs(c_GetDomainList()) do
					local domain_online = c_IsDomainOnline(domain)
					bContinue = false
					if _SESSION["admin_domainadmin"] == 1 and in_array(domain,domainArray) == false then
						bContinue = true
					end
					if bContinue == false then
			%>
				<dd class="folderClose" id="domain<%=domainNum%>"><span style="cursor:pointer;font-weight:bold;" onclick="changeDomain('domain<%=domainNum%>',this,'<%=specialhtml_encode(urldecode(domain))%>',0,<%if domain_online == true then print("1") else print("0") end%>);" oncontextmenu="changeDomain('domain<%=domainNum%>',this,'<%=urldecode(domain)%>',1,<%if domain_online == true then print("1") else print("0") end%>);">
				<%if domain_online == true then print("<img src='images/ico_domain.gif'>") else print("<img src='images/ico_domainoff.gif'>") end%> <%=specialhtml_encode(urldecode(domain))%></span>
					<dl>
						<dd id="domainlog<%=domainNum%>"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('domainlog<%=domainNum%>',0,this);"><img src="images/ico_list.gif"> <%=LANG["left_logstatus"]%></span>
							<dl>
								<dt><a href="#" onclick="return changeLocation('admin_viewstatus.html?domain=<%=domain%>',this);"><img src="images/ico_domainstatus.gif"> <%=LANG["left_domainstatus"]%></a></dt>
								<dt><a href="#" onclick="return changeLocation('admin_viewlog.html?domain=<%=domain%>',this);"><img src="images/ico_domainlog.gif"> <%=LANG["left_domainlog"]%></a></dt>
								<dt><a href="#" onclick="return changeLocation('admin_loglist.html?domain=<%=domain%>',this);"><img src="images/ico_general.gif"> <%=LANG["str_auditing"]%></a></dt>
								<dt><a href="#" onclick="return changeLocation('admin_tempban_list.html?domain=<%=domain%>',this);"><img src="images/ico_tempban.gif"> <%=LANG["left_tempban"]%></a></dt>
								<dt><a href="#" onclick="return changeLocation('admin_connection_list.html?domain=<%=domain%>',this);"><img src="images/ico_activity.gif"> <%=LANG["left_activity"]%></a></dt>
								<dt><a href="#" onclick="return changeLocation('admin_graphic.html?domain=<%=domain%>',this);"><img src="images/ico_graphic.gif"> <%=LANG["left_graphs"]%></a></dt>
							</dl>
						</dd>
						<% if _SESSION["admin_domainadmin"] == 0 then %>
						<dd id="domainevent<%=domainNum%>"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('domainevent<%=domainNum%>',0,this);"><img src="images/ico_list.gif"> <%=LANG["left_eventmanager"]%></span>
						<dl>
							<dt><a href="#" onclick="return changeLocation('admin_event_list.html?type=ftp&domain=<%=domain%>',this);"><img src="images/ico_event.gif"> <%=LANG["left_ftpevent"]%></a></dt>
							<dt><a href="#" onclick="return changeLocation('admin_event_list.html?type=http&domain=<%=domain%>',this);"><img src="images/ico_event.gif"> <%=LANG["left_httpevent"]%></a></dt>
							<dt><a href="#" onclick="return changeLocation('admin_event_list.html?type=ssh&domain=<%=domain%>',this);"><img src="images/ico_event.gif"> <%=LANG["left_sshevent"]%></a></dt>
						</dl>
						</dd>
						<% end %>
						<% if _SESSION["admin_readonly"] == 0 then %>
						<dd id="weblink<%=domainNum%>"><span style="cursor:pointer;font-weight:bold;" onclick="changeState('weblink<%=domainNum%>',0,this);"><img src="images/ico_list.gif"> <%=LANG["str_weblink_manager"]%></span>
						<dl>
							<dt><a href="#" onclick="return changeLocation('admin_weblink.html?domain=<%=domain%>&is_uplink=0',this);"><img src="images/ico_weblink.png"> <%=LANG["str_download_link"]%></a></dt>
							<dt><a href="#" onclick="return changeLocation('admin_weblink.html?domain=<%=domain%>&is_uplink=1',this);"><img src="images/ico_uplink.png"> <%=LANG["str_upload_link"]%></a></dt>
						</dl>
						</dd>
						<% end %>
						<dt><a href="#" onclick="return changeLocation('admin_userlist.html?domain=<%=domain%>',this);"><img src="images/ico_user.gif"> <%=LANG["left_user"]%></a></dt>
						<dt><a href="#" onclick="return changeLocation('admin_grouplist.html?domain=<%=domain%>',this);"><img src="images/ico_group.gif"> <%=LANG["left_group"]%></a></dt>
						<% if _SESSION["admin_domainadmin"] == 0 then %>
						<dt><a href="#" onclick="return changeLocation('admin_domain_setting.html?domain=<%=domain%>',this);"><img src="images/ico_setting.gif"> <%=LANG["left_setting"]%></a></dt>
						<% end %>
					</dl>
				</dd>
			<%
					end
					domainNum = domainNum+1
				end
			%>

			</dl>
		</dd>
	</dl>
	</dd>
</dl>
</div>

<script type="text/javascript">
var lTree = new lTREE();
lTree.build("leftmenu");

var lastlinkobj = null;
var lastdomainname = null;
var lastdomainroot = null;
var domain_online = 0;
var domainNum = <%=domainNum%>;
var showalert = false;


var strInstalledVersion = "<%=c_GetVersion()%>";
var ajaxlock = false;
var xmlhttp,page,post;
xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

function ajaxRequest(pagename,poststring,method)
{
	if(ajaxlock == false)
	{	
		delete xmlhttp;
		xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

		ajaxlock = true;
		page = pagename;
		post = poststring;

		if(method == "GET")
			xmlhttp.open("GET",page+".html"+post);
		else
			xmlhttp.open("POST",page+".html");

		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = ajaxResponse;
		if(method != "GET")
			xmlhttp.send(post);
		else
			xmlhttp.send("");
	}
}

function ajaxResponse()
{
	if (xmlhttp.readyState == 4)
	{
		ajaxlock = false;
		if (xmlhttp.status == 200)
		{
			try
			{
				switch(page)
				{
					case 'admin_get_lastversion':	Lastversion_result();break;
				}
			}
			catch(e)
			{
			}
		}
		else
		{
		}
	}
}


function Update()
{
	<% if my_lang == "schinese" or my_lang == "tchinese" then %>
	window.open("https://www.wftpserver.com/zh/download.htm");
	<% elseif my_lang == "german" then %>
	window.open("https://www.wftpserver.com/de/download.htm");
	<% else %>
	window.open("https://www.wftpserver.com/download.htm");
	<% end %>

	top.closewindow();
}

function Lastversion_result()
{
	var result = trim(xmlhttp.responseText);
	if(result != "" && result != strInstalledVersion)
	{
		showMessagebox("<%=LANG['str_version_info']%>","<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0' style='background-color:#E7E6DA;padding:20px;'><tr><td height=90 align=left><div style='clear: none;'><div style='float: left;'><img src='images/vista_info2.gif' align='absmiddle'>&nbsp;&nbsp;</div><%=LANG['str_new_version']%>: v"+result+"</div></td></tr><tr><td><button id='btn_submit' type='submit' onclick='return Update();'><span><em><%=LANG['button_update']%></em></span></button>&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",callback_return2,350,200);

		top.$("btn_submit").onclick = function(){return Update();};
		top.$("btn_cancel").onclick = function(){top.closewindow();};
	}
}

function callback_return2(value)
{
	setCookie("installedVersion", strInstalledVersion);
	return true;
}

function DeleteDomain()
{
	if(lastdomainname == null || lastdomainname == "")
		return;
	else
		return top.DeleteDomain(lastdomainname);
}

function StartDomain()
{
	if(lastdomainname == null || lastdomainname == "" || domain_online == 1)
		return;
	else
		return top.StartDomain(lastdomainname);
}

function StopDomain()
{
	if(lastdomainname == null || lastdomainname == "" || domain_online == 0)
		return;
	else
		return top.StopDomain(lastdomainname);
}

function changeDomain(domain,linkobj,domainname,rightmouse,online)
{
	domain_online = online;
	if(rightmouse == 1)
	{
		changeLinkColor(linkobj);
		lastdomainname = domainname;

<% if _SESSION["admin_domainadmin"] == 0 and _SESSION["admin_readonly"] == 0 then %>
		var evt = getEvent();
		$("menu_div2").style.visibility = "hidden";
		$("menu_div").style.visibility = ""; 
		$("menu_div").style.top = evt.clientY + "px"; 
		$("menu_div").style.left = evt.clientX + "px"; 
<% end %>

		return;
	}

	if(lastdomainname == null || lastdomainname != domainname)
	{
		changeLinkColor(linkobj);
	}
	else
	{
		if(domain == "domain"+(domainNum-1) )
			changeState(domain,1,linkobj);
		else
			changeState(domain,0,linkobj);
	}
	lastdomainname = domainname;
}

function clickDomainRoot(linkobj,rightmouse)
{
	if(rightmouse == 1)
	{
		changeLinkColor(linkobj);

<% if _SESSION["admin_domainadmin"] == 0 and _SESSION["admin_readonly"] == 0 then %>
		var evt = getEvent();
		$("menu_div").style.visibility = "hidden";
		$("menu_div2").style.visibility = ""; 
		$("menu_div2").style.top = evt.clientY + "px"; 
		$("menu_div2").style.left = evt.clientX + "px";
<% end %>
		return;
	}
	
	if(lastdomainroot == null)
		changeLinkColor(linkobj);
	else
		changeState('node4',1,linkobj);

	lastdomainroot = "node4";
	parent.frames['main'].location = "admin_domainlist.html";
}

function closeAllDomain(domain)
{
	for(i=0;i<domainNum;i++)
	{
		if(domain != "domain"+i)
		{
			if(domain != "domain"+(domainNum-1) )
				$("domain"+i).className = "lastChild folderClose";
			else
				$("domain"+i).className = "folderClose";
		}
	}
}

function changeLinkColor(linkobj)
{
	if(linkobj != null)
	{
		if(lastlinkobj != null)
		{
			lastlinkobj.style.backgroundColor = "";
			lastlinkobj.style.color = "#000";
		}
		linkobj.style.backgroundColor = "#3366CC";
		linkobj.style.color = "#FFF";
		lastlinkobj = linkobj;
	}
	lastdomainname = null;
	lastdomainroot = null;
}

function changeLocation(url,linkobj)
{
	changeLinkColor(linkobj);

	parent.frames['main'].location = url;
	return false;
}

function changeState(obj,lastchild,linkobj)
{
	changeLinkColor(linkobj);

	if(lastchild == 1)
	{
		if($(obj).className.indexOf("folderClose") != -1)
			$(obj).className = "lastChild";
		else
			$(obj).className = "lastChild folderClose";
	}
	else
	{
		if($(obj).className.indexOf("folderClose") != -1)
			$(obj).className = "";
		else
			$(obj).className = "folderClose";
	}
}

document.onclick=function()
{
	$("menu_div").style.visibility = "hidden";
	$("menu_div2").style.visibility = "hidden";
}
top.document.onclick=function()
{
	top.left.$("menu_div").style.visibility = "hidden";
	top.left.$("menu_div2").style.visibility = "hidden";
}

if(domainNum == 0 || domainNum == "0")
{
	showMessagebox("Wing FTP Server","<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0' style='background-color:#E7E6DA;padding:10px;'><tr><td height=100 align=left><div style='clear: none;'><div style='float: left;'><img src='images/vista_info2.gif' align='absmiddle'>&nbsp;&nbsp;</div><%=LANG['str_createdomain_tip']%></div></td></tr><tr><td><button id='btn_submit' type='submit' onclick='top.closewindow();top.CreateDomain();'><span><em><%=LANG['button_submit']%></em></span></button>&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",null,300,170);

	if(isIE)
	{
		top.$("btn_submit").onclick = function(){top.closewindow();top.CreateDomain();};
		top.$("btn_cancel").onclick = function(){top.closewindow();};
	}
}
else
{
	<%
	local nType,strVersion,strUserName,strCopyNumber,strOS,nLeftDay = c_GetLicenseInfo()
	if nType >= LICENSE_FREE then
	%>
	var IconImage = "<img src='images/vista_info2.gif' align='absmiddle'>&nbsp;&nbsp;";
	var LicenseInfo = "Wing FTP Server <%=LANG['str_trial_version']%> <%=nLeftDay%> <%=LANG['str_days_left']%>.";

	<%if nType == LICENSE_EXPIRE then%>
	IconImage = "<img src='images/vista_warning.gif' align='absmiddle'>&nbsp;&nbsp;";
	LicenseInfo = "<%=LANG['str_evaluation_expired']%>";
	<%elseif nType == LICENSE_FAILED then%>
	IconImage = "<img src='images/vista_warning.gif' align='absmiddle'>&nbsp;&nbsp;";
	LicenseInfo = "<%=LANG['str_invalid_license']%>";
	<%elseif nType == LICENSE_FREE then%>
	IconImage = "<img src='images/vista_info2.gif' align='absmiddle'>&nbsp;&nbsp;";
	LicenseInfo = "Wing FTP Server <b><%=LANG['str_version_free']%></b> <br> <%=LANG['str_no_commerce']%>.";
	<%end%>

	function regAlert()
	{
		if(showalert == false)
		{
			showMessagebox("<%=LANG['str_license_info']%>","<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0' style='background-color:#E7E6DA;padding:10px;'><tr><td height=110 align=left><div style='clear: none;'><div style='float: left;'>"+IconImage+"</div>"+LicenseInfo+"</div></td></tr><tr><td><button id='btn_submit' type='submit' onclick='top.gotoRegister();'><span><em><%=LANG['button_register']%></em></span></button>&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",callback_return,350,200);
			showalert = true;
		}
	}

	function callback_return(value)
	{
		showalert = false;
	}

	<%if _SESSION["show_licenseinfo"] == nil then print("regAlert()") end%>
	setInterval("regAlert()",3600*1000);

	if(isIE)
	{
		try
		{
			top.$("btn_submit").onclick = function(){top.gotoRegister();};
			top.$("btn_cancel").onclick = function(){top.closewindow();};
		}
		catch(e){}
	}
	<%
		rawset(_SESSION,"show_licenseinfo","true")
		SessionModule.save(_SESSION_ID)
	else
	%>
	if(getCookie("installedVersion") != strInstalledVersion)
	{
		setTimeout("ajaxRequest('admin_get_lastversion', '')",20*1000);
	}
	<%
	end
	%>
}

</script>

</body>
</html>

<% 
	if _SESSION["show_upgrade_tip"] ~= nil and _SESSION["show_upgrade_tip"] == 1 then
		rawset(_SESSION, "show_upgrade_tip", nil)
		SessionModule.save(_SESSION_ID)
		print("<script>top.upgradeTip();</script>")
	end
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>top.location='admin_login.html';</script>")
end 
%>

<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>
