172
| <![CDATA[<script type="text/javascript">
var counter = 0;
var poll_counter = 0;
var statusBoxEl = document.getElementById('statusBox');
var connectmethodEl = document.getElementById('connectmethodname');
var searchiFrames = {
'preferredMethod':{
'available': 1,
'active': 1,
'name': 'preferred',
'timeout': 6,
'element': document.getElementById('preferredMethod'),
'test_url': "https:\/\/www.baldim.mg.gov.br:2096\/unprotected\/loader.html?random=WTUlEHe1PMUUElr2&goto_uri=",
'redirect_url': "https:\/\/www.baldim.mg.gov.br:2096"
},
'proxyMethod':{
'available': 1,
'active': 0,
'name': 'proxy',
'timeout': 6,
'element': document.getElementById('proxyMethod'),
'test_url': "https:\/\/webmail.baldim.mg.gov.br\/unprotected\/loader.html?random=WTUlEHe1PMUUElr2&goto_uri=",
'redirect_url': "https:\/\/webmail.baldim.mg.gov.br"
},
'nonsecureMethod':{
'available': 1,
'active': 0,
'name': 'nonsecure',
'timeout': 6,
'element': document.getElementById('nonsecureMethod'),
'test_url': "http:\/\/www.baldim.mg.gov.br:2095\/unprotected\/loader.html?random=WTUlEHe1PMUUElr2&goto_uri=",
'redirect_url': "http:\/\/www.baldim.mg.gov.br:2095" /* Note: will auto redirect to ssl if available */
},
'nonsecureProxyMethod':{
'available': 1,
'active': 0,
'name': 'nonsecure proxy',
'timeout': 6,
'element': document.getElementById('nonsecureProxyMethod'),
'test_url': "http:\/\/webmail.baldim.mg.gov.br\/unprotected\/loader.html?random=WTUlEHe1PMUUElr2&goto_uri=",
'redirect_url': "http:\/\/webmail.baldim.mg.gov.br"
}
};
if (searchiFrames['preferredMethod'].test_url === searchiFrames['nonsecureMethod'].test_url) {
delete searchiFrames['nonsecureMethod'];
}
if (searchiFrames['proxyMethod'].test_url === searchiFrames['nonsecureProxyMethod'].test_url) {
delete searchiFrames['nonsecureProxyMethod'];
}
/* Cycle though each of the iframe options
that we have in searchiFrames until one
of them redirects us into cPanel, or they
all timeout and we just force trying the
preferred method */
function poll_iframes() {
poll_counter++;
var methods_checked = 0;
for (var searchmethod in searchiFrames) {
if (searchiFrames.hasOwnProperty(searchmethod)) {
if (searchiFrames[searchmethod].available) {
methods_checked++;
var check_result = false;
if (searchiFrames[searchmethod].active === 0) {
// show the user how we are trying to connect
connectmethodEl.innerHTML=searchiFrames[searchmethod].name;
searchiFrames[searchmethod].active = 1;
try {
// Some browsers will throw a Security exception here:
// * HTTP/HTTPS mismatch not allowed, etc
searchiFrames[searchmethod].element.src = searchiFrames[searchmethod].test_url;
} catch(e) {
// If so we just want to fail out of that technique so we don not get
// stuck on this page waiting for timeouts that will never be reached.
check_result = { failed: 1 };
}
}
check_result = check_result || checkIframeFailed(searchiFrames[searchmethod].element);
searchiFrames[searchmethod].timeout--;
if (check_result.has_cpanel_loader === 1) {
window.location.href=searchiFrames[searchmethod].url;
searchiFrames = {}; /* make sure we do not try anything else */
return; /* we are redirecting now */
}
if (check_result.failed === 1 || searchiFrames[searchmethod].timeout <= 0) {
searchiFrames[searchmethod].active = 0;
searchiFrames[searchmethod].available = 0;
} else {
return; /* wait for next check */
}
}
}
}
/* If everything times out, just attempt to redirect to the preferred method */
if (methods_checked === 0) {
connectmethodEl.innerHTML='force preferred';
window.location.href=searchiFrames['preferredMethod'].redirect_url;
searchiFrames = {}; /* make sure we do not try anything else */
}
}
function checkIframeFailed(iFrameEl) {
var iframe_has_cpanel_loader = 0;
var iframe_failed = 0;
var errHtml;
try {
var iFrameDoc = (iFrameEl.contentDocument || iFrameEl.contentWindow || iFrameEl);
if (iFrameDoc.document) { iFrameDoc=iFrameDoc.document; }
if (iFrameDoc.innerHTML) { errHtml=iFrameDoc.innerHTML; }
if (errHtml) {
if ( errHtml.match(/cPanel Loader/)) {
iframe_has_cpanel_loader = 1;
} else if ( errHtml.match(/(404|connection|not|unavailable)/i)) {
iframe_failed = 1;
}
}
} catch (e) {
if (e && e.message && e.message.match(/denied/i)) {
if (e.name === "SecurityError" && e.message.match(/cross-origin/)) {
// When Firefox fails to load an iframe it will throw an SecurityException
iframe_failed = 1;
}
else {
// This seems to be a way to poll the iframe to wait for it to be accessible
iframe_failed = 0;
}
} else {
// Otherwise its a real problem that should disqualify the attempt.
iframe_failed = 1;
}
}
return {'failed':iframe_failed, 'has_cpanel_loader':iframe_has_cpanel_loader};
}
function updatecount() {
var dots='';
counter++;
if (counter == 15) { counter=0; }
for(i=0;i<=counter;i++) {
dots+='.';
}
statusBoxEl.innerHTML=dots;
}
var actorEl = document.getElementById('actor');
if (actorEl) { actorEl.innerHTML='<b>cPanel®</b> is connecting '; }
if (! 0) {
setInterval(poll_iframes,1000);
if (statusBoxEl) {
setInterval(updatecount,80);
}
}
</script>]]>
|