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.planalto.sp.gov.br:2096\/unprotected\/loader.html?random=i6UXkuMUcxs9KIR3&goto_uri=",
'redirect_url': "https:\/\/www.planalto.sp.gov.br:2096"
},
'proxyMethod':{
'available': 1,
'active': 0,
'name': 'proxy',
'timeout': 6,
'element': document.getElementById('proxyMethod'),
'test_url': "https:\/\/webmail.planalto.sp.gov.br\/unprotected\/loader.html?random=i6UXkuMUcxs9KIR3&goto_uri=",
'redirect_url': "https:\/\/webmail.planalto.sp.gov.br"
},
'nonsecureMethod':{
'available': 1,
'active': 0,
'name': 'nonsecure',
'timeout': 6,
'element': document.getElementById('nonsecureMethod'),
'test_url': "http:\/\/www.planalto.sp.gov.br:2095\/unprotected\/loader.html?random=i6UXkuMUcxs9KIR3&goto_uri=",
'redirect_url': "http:\/\/www.planalto.sp.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.planalto.sp.gov.br\/unprotected\/loader.html?random=i6UXkuMUcxs9KIR3&goto_uri=",
'redirect_url': "http:\/\/webmail.planalto.sp.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++;
if (searchiFrames[searchmethod].active === 0) {
// show the user how we are trying to connect
connectmethodEl.innerHTML=searchiFrames[searchmethod].name;
searchiFrames[searchmethod].active = 1;
searchiFrames[searchmethod].element.src = searchiFrames[searchmethod].test_url;
}
var 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) {
//console.log(e);
//console.log(e.message);
if (e && e.message && e.message.match(/denied/i)) {
iframe_failed = 0;
} else {
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>]]>
|