$(function () { var location = window.location.pathname; if (location != "/" && location != ("/Camera/CameraList.aspx")) return; $.getJSON("/api/camera/CheckIfIPBlocked.aspx", function (data) { //return; var retJson = eval(data); if (retJson.status == "-1") { //not logon } else if (retJson.status == "0") { //not blocked. } else if (retJson.status == "1") { //IP was blocked; /* { "status":"1", "result":"{\"IP\":\"192.168.2.137\",\"UnblockTime\":\"12\\\/18\\\/2017 8:43:24 AM\",\"BlockReason\":\"Account 'scamera' is past due\",\"BlockedUser\":\"[\\\"scamera\\\"]\"}" } */ var username = retJson.username; var blockResult = retJson.result; var blockReason = blockResult.BlockedReason; /* ServiceExpired, AccountDisabled, TooManyRequest, InvalidSFTPCommand */ var blockUser = blockResult.BlockedUser; var txtWarning = "
"; if (username + "" != "") { txtWarning += "
Your IP camera from the IP " + blockResult.IP + " "; txtWarning += "is blocked due to: "; } else { txtWarning += "
The IP camera from IP " + blockResult.IP + " in your network is blocked due to:"; } txtWarning += "
"; var message = ""; if (username == blockUser && blockUser!="") { if (blockReason == "ServiceExpired") { message = "Your account is past due."; } else if (blockReason == "AccountDisabled") { message = "Your account is disabled."; } else if (blockReason == "TooManyRequest") { message = "Too frequent requests from this IP address."; } else if (blockReason == "InvalidSFTPCommand") { message = "Sent invalid SFTP commands."; } else { message = blockReason; } } else { var secureName = blockUser; if (secureName.length <= 1) secureName = "*"; else if (secureName.length < 3) { secureName = secureName.substring(0, 1) + "***"; } else { secureName = secureName.substring(0, 3) + "******"; } if (blockReason == "ServiceExpired") { if (username == "") { message = "A CameraFTP account (username: " + secureName + ") on this IP is past due. "; } else { message = "Another camera account (username: " + secureName + ") on this IP is past due. "; } } else if (blockReason == "AccountDisabled") { if (username == "") { message = "A CameraFTP account (username: " + secureName + ") on this IP is disabled. "; } else { message = "Another camera account (username: " + secureName + ") on this IP is disabled. "; } } else if (blockReason == "TooManyRequest") { message = "Too frequent requests from this IP address. "; } else if (blockReason == "InvalidSFTPCommand") { message = "Sent invalid SFTP commands."; } else { message = blockReason; } } txtWarning += "
"; txtWarning += message; txtWarning += "
"; var unblockTimeUtc = new Date(Date.parse(blockResult.UnblockTime+" UTC")); var localTime = unblockTimeUtc.toLocaleDateString() + " " + unblockTimeUtc.toLocaleTimeString(); txtWarning += "
If the problem is resolved, it will automatically unblock at " + localTime + ". "; //txtWarning += "
"; //txtWarning += "
Check Configuration.   "; if (username + "" != "" && username != undefined) { txtWarning += "Unblock Now"; } else { txtWarning += "Contact CameraFTP Support"; } txtWarning += "
"; $(txtWarning).hide(); $(txtWarning).prependTo($("#header").find(".Transbox")); $(txtWarning).fadeIn('slow'); } else if (retJson.status == "2") { //account related warning. var txtWarning = "
"; txtWarning += "
Your camera has a problem.
"; var eventObj = result.events; var msg = ""; for (var i = 0; i < eventObj.length; i++) { msg += "" + eventObj[i].subject + "  " + ConvertToLTime(eventObj[i].messagedate) + ";  "; } txtWarning += ""; txtWarning += msg; txtWarning += ""; // txtWarning += "
Click here to verify your camera configuration.
"; txtWarning += ""; txtWarning += "
"; $(txtWarning).prependTo($("#header").find(".Transbox")); } else if (retJson.status == "3") { //motion detected; var txtWarning = "
"; txtWarning += "
New event detected.
"; var eventObj = eval(result.events); var msg = ""; for (var i = 0; i < eventObj.length; i++) { msg += "" + eventObj[i].subject + "  " + ConvertToLTime(eventObj[i].messagedate) + ";  "; } txtWarning += ""; txtWarning += msg; txtWarning += ""; txtWarning += ""; txtWarning += "
"; $(txtWarning).prependTo($("#header").find(".Transbox")); } else if (retJson.status == "4") { var ftpConn = retJson.result.ftpConn; var ftpConnTotalBlocked = ftpConn.TotalBlocked; var ftpConnDetails = ftpConn.Details; var camUpload = retJson.result.camUpload; var camUploadTotalBlocked = camUpload.TotalBlocked; var camUploadDetails = camUpload.Details; if (ftpConnTotalBlocked == 0 && camUploadTotalBlocked == 0) return; var solutionTag = "#SOLUTION#"; var txtWarning = "
"; txtWarning += "
"; if(ftpConnTotalBlocked>0 && camUploadTotalBlocked>0) { txtWarning += "" + ftpConnTotalBlocked + " FTP connection attempts were blocked "; txtWarning += "and " + camUploadTotalBlocked + " footage files were not uploaded in the past 24 hours."; } else if(ftpConnTotalBlocked>0) { txtWarning += "" + ftpConnTotalBlocked + " FTP connection attempts were blocked in the past 24 hours."; } else if(camUploadTotalBlocked>0) { txtWarning += "" + camUploadTotalBlocked + " footage files were not uploaded in the past 24 hours."; } else { return; } txtWarning += " " + solutionTag; txtWarning += "
"; var reason = ""; if (ftpConnDetails.length > 0) { txtWarning += "
"; txtWarning += "The most recent blocked FTP attempts:"; txtWarning += "
"; txtWarning += "Date Time"; txtWarning += "IP Address"; txtWarning += "Reason"; txtWarning += "
"; for (var i = 0; i < ftpConnDetails.length; i++) { var fConn = ftpConnDetails[i]; txtWarning += "
"; txtWarning += "" + getDateTime(fConn.Time) + ""; txtWarning += "" + fConn.IPAddress + ""; txtWarning += "" + fConn.Reason + ""; txtWarning += "
"; if (fConn.Reason.indexOf("expired") > 0) { reason = "expired"; } else if (fConn.Reason.indexOf("past") > 0) { reason = "pastdue"; } else if (fConn.Reason.indexOf("storage") > 0) { reason = "storage"; } } txtWarning += "
"; } if (camUploadDetails.length > 0) { txtWarning += "
"; txtWarning += "The most recent blocked upload attempts are:"; txtWarning += "
"; txtWarning += "Date Time"; txtWarning += "Reason"; txtWarning += "Camera Name"; txtWarning += "File Name"; txtWarning += "
"; for (var i = 0; i < camUploadDetails.length; i++) { var camUpload = camUploadDetails[i]; txtWarning += "
"; txtWarning += "" + getDateTime(camUpload.Time) + ""; txtWarning += "" + camUpload.Reason + ""; txtWarning += "" + camUpload.CamName + ""; txtWarning += "" + camUpload.FileName + ""; txtWarning += "
"; if (camUpload.Reason.indexOf("expired") > 0) { reason = "expired"; } else if (camUpload.Reason.indexOf("past") > 0) { reason = "pastdue"; } else if (camUpload.Reason.indexOf("storage") > 0) { reason = "storage"; } } txtWarning += "
"; } var htmlSolution = ""; if (reason == "pastdue") { htmlSolution = "Deposit" } else if (reason == "storage") { htmlSolution = "Upgrade" } else { htmlSolution = "Subscribe" } txtWarning = txtWarning.replace(solutionTag, htmlSolution); $(txtWarning).hide(); $(txtWarning).prependTo($("#header").find(".Transbox")); $(txtWarning).fadeIn('slow'); } $(".marquee").mouseover(function () { $(this)[0].stop(); }); $(".marquee").mouseleave(function () { $(this)[0].start(); }); var hideTimer; $(".NumOfBlockLink").mouseover(function () { clearTimeout(hideTimer); $(".warningMsgDetailsBlockedFTPConns, .warningMsgDetailsBlockedCamUploads").hide(); var target = $(this).data("target"); $("." + target).show(); }); $(".warningMsgDetailsBlockedFTPConns, .warningMsgDetailsBlockedCamUploads").mouseover(function () { clearTimeout(hideTimer); $(".warningMsgDetailsBlockedFTPConns, .warningMsgDetailsBlockedCamUploads").hide(); $(this).show(); }); $(".warningMsgDetailsBlockedFTPConns, .warningMsgDetailsBlockedCamUploads").mouseleave(function () { var target = this; hideTimer = setTimeout(function () { $(target).hide("slow"); }, 4000); }); }); function getDateTime(d) { return new Date(d).toLocaleString(); } });